aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/DefaultVirtualPortTest.java
blob: 81d8b14d43c323ce77adcecc126bf50ac0370932 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
 * Copyright 2015 Open Networking Laboratory
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.onosproject.vtnrsc;

import java.util.Map;
import java.util.Set;

import org.junit.Test;
import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
import org.onosproject.net.DeviceId;

import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.common.testing.EqualsTester;

import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;

/**
 * Unit tests for DefaultVirtualPort class.
 */
public class DefaultVirtualPortTest {

    private Set<FixedIp> fixedIps;
    private Map<String, String> propertyMap;
    private Set<AllowedAddressPair> allowedAddressPairs;
    private Set<SecurityGroup> securityGroups;
    private VirtualPortId id1;
    private VirtualPortId id2;
    private String macAddressStr = "fa:12:3e:56:ee:a2";
    private String ipAddress = "10.1.1.1";
    private String deviceStr = "of:000000000000001";
    private String tenantIdStr = "123";
    private String portId1 = "1241";
    private String portId2 = "1242";
    private String tenantNetworkId = "1234567";
    private String subnet = "1212";
    private String hostIdStr = "fa:e2:3e:56:ee:a2";

    private void initVirtualPortId() {
        id1 = VirtualPortId.portId(portId1);
        id2 = VirtualPortId.portId(portId2);
    }

    private void initFixedIpSet() {
        FixedIp fixedIp = FixedIp.fixedIp(SubnetId.subnetId(subnet),
                                          IpAddress.valueOf(ipAddress));
        fixedIps = Sets.newHashSet();
        fixedIps.add(fixedIp);
    }

    private void initPropertyMap() {
        String deviceOwner = "james";
        propertyMap = Maps.newHashMap();
        propertyMap.putIfAbsent("deviceOwner", deviceOwner);
    }

    private void initAddressPairSet() {
        allowedAddressPairs = Sets.newHashSet();
        AllowedAddressPair allowedAddressPair = AllowedAddressPair
                .allowedAddressPair(IpAddress.valueOf(ipAddress),
                                    MacAddress.valueOf(macAddressStr));
        allowedAddressPairs.add(allowedAddressPair);
    }

    private void initSecurityGroupSet() {
        securityGroups = Sets.newHashSet();
    }

    /**
     * Checks that the DefaultVirtualPort class is immutable.
     */
    @Test
    public void testImmutability() {
        assertThatClassIsImmutable(SecurityGroup.class);
    }

    /**
     * Checks the operation of equals().
     */
    @Test
    public void testEquals() {
        initVirtualPortId();
        initFixedIpSet();
        initPropertyMap();
        initAddressPairSet();
        initSecurityGroupSet();
        TenantNetworkId networkId = TenantNetworkId.networkId(tenantNetworkId);
        MacAddress macAddress = MacAddress.valueOf(macAddressStr);
        TenantId tenantId = TenantId.tenantId(tenantIdStr);
        DeviceId deviceId = DeviceId.deviceId(deviceStr);
        BindingHostId bindingHostId = BindingHostId.bindingHostId(hostIdStr);

        VirtualPort d1 = new DefaultVirtualPort(id1, networkId, true,
                                                propertyMap,
                                                VirtualPort.State.ACTIVE,
                                                macAddress, tenantId, deviceId,
                                                fixedIps, bindingHostId,
                                                allowedAddressPairs,
                                                securityGroups);
        VirtualPort d2 = new DefaultVirtualPort(id1, networkId, true,
                                                propertyMap,
                                                VirtualPort.State.ACTIVE,
                                                macAddress, tenantId, deviceId,
                                                fixedIps, bindingHostId,
                                                allowedAddressPairs,
                                                securityGroups);
        VirtualPort d3 = new DefaultVirtualPort(id2, networkId, true,
                                                propertyMap,
                                                VirtualPort.State.ACTIVE,
                                                macAddress, tenantId, deviceId,
                                                fixedIps, bindingHostId,
                                                allowedAddressPairs,
                                                securityGroups);
        new EqualsTester().addEqualityGroup(d1, d2).addEqualityGroup(d3)
                .testEquals();
    }
}