2 * Copyright 2015 Open Networking Laboratory
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onosproject.vtnrsc.virtualport;
19 import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
24 import org.junit.Test;
25 import org.onlab.packet.IpAddress;
26 import org.onlab.packet.MacAddress;
27 import org.onosproject.net.DeviceId;
28 import org.onosproject.vtnrsc.AllowedAddressPair;
29 import org.onosproject.vtnrsc.BindingHostId;
30 import org.onosproject.vtnrsc.DefaultVirtualPort;
31 import org.onosproject.vtnrsc.FixedIp;
32 import org.onosproject.vtnrsc.SecurityGroup;
33 import org.onosproject.vtnrsc.SubnetId;
34 import org.onosproject.vtnrsc.TenantId;
35 import org.onosproject.vtnrsc.TenantNetworkId;
36 import org.onosproject.vtnrsc.VirtualPort;
37 import org.onosproject.vtnrsc.VirtualPortId;
39 import com.google.common.collect.Maps;
40 import com.google.common.collect.Sets;
41 import com.google.common.testing.EqualsTester;
44 * Unit tests for DefaultVirtualPort class.
46 public class DefaultVirtualPortTest {
48 private Set<FixedIp> fixedIps;
49 private Map<String, String> propertyMap;
50 private Set<AllowedAddressPair> allowedAddressPairs;
51 private Set<SecurityGroup> securityGroups;
52 private VirtualPortId id1;
53 private VirtualPortId id2;
54 private String macAddressStr = "fa:12:3e:56:ee:a2";
55 private String ipAddress = "10.1.1.1";
56 private String deviceStr = "of:000000000000001";
57 private String tenantIdStr = "123";
58 private String portId1 = "1241";
59 private String portId2 = "1242";
60 private String tenantNetworkId = "1234567";
61 private String subnet = "1212";
62 private String hostIdStr = "fa:e2:3e:56:ee:a2";
64 private void initVirtualPortId() {
65 id1 = VirtualPortId.portId(portId1);
66 id2 = VirtualPortId.portId(portId2);
69 private void initFixedIpSet() {
70 FixedIp fixedIp = FixedIp.fixedIp(SubnetId.subnetId(subnet),
71 IpAddress.valueOf(ipAddress));
72 fixedIps = Sets.newHashSet();
73 fixedIps.add(fixedIp);
76 private void initPropertyMap() {
77 String deviceOwner = "james";
78 propertyMap = Maps.newHashMap();
79 propertyMap.putIfAbsent("deviceOwner", deviceOwner);
82 private void initAddressPairSet() {
83 allowedAddressPairs = Sets.newHashSet();
84 AllowedAddressPair allowedAddressPair = AllowedAddressPair
85 .allowedAddressPair(IpAddress.valueOf(ipAddress),
86 MacAddress.valueOf(macAddressStr));
87 allowedAddressPairs.add(allowedAddressPair);
90 private void initSecurityGroupSet() {
91 securityGroups = Sets.newHashSet();
95 * Checks that the DefaultVirtualPort class is immutable.
98 public void testImmutability() {
99 assertThatClassIsImmutable(SecurityGroup.class);
103 * Checks the operation of equals().
106 public void testEquals() {
110 initAddressPairSet();
111 initSecurityGroupSet();
112 TenantNetworkId networkId = TenantNetworkId.networkId(tenantNetworkId);
113 MacAddress macAddress = MacAddress.valueOf(macAddressStr);
114 TenantId tenantId = TenantId.tenantId(tenantIdStr);
115 DeviceId deviceId = DeviceId.deviceId(deviceStr);
116 BindingHostId bindingHostId = BindingHostId.bindingHostId(hostIdStr);
118 VirtualPort d1 = new DefaultVirtualPort(id1, networkId, true,
120 VirtualPort.State.ACTIVE,
121 macAddress, tenantId, deviceId,
122 fixedIps, bindingHostId,
125 VirtualPort d2 = new DefaultVirtualPort(id1, networkId, true,
127 VirtualPort.State.ACTIVE,
128 macAddress, tenantId, deviceId,
129 fixedIps, bindingHostId,
132 VirtualPort d3 = new DefaultVirtualPort(id2, networkId, true,
134 VirtualPort.State.ACTIVE,
135 macAddress, tenantId, deviceId,
136 fixedIps, bindingHostId,
139 new EqualsTester().addEqualityGroup(d1, d2).addEqualityGroup(d3)