blob: 77f5be365d89ae656903451360ca1e4999b83aff [file] [log] [blame]
samueljcca3d9b252015-10-28 15:58:45 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
samueljcca3d9b252015-10-28 15:58:45 -07003 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
Ray Milkey6c1bac32015-11-13 14:40:40 -080017package org.onosproject.vtnrsc;
samueljcca3d9b252015-10-28 15:58:45 -070018
19import java.util.Map;
20import java.util.Set;
21
22import org.junit.Test;
23import org.onlab.packet.IpAddress;
24import org.onlab.packet.MacAddress;
25import org.onosproject.net.DeviceId;
samueljcca3d9b252015-10-28 15:58:45 -070026
27import com.google.common.collect.Maps;
28import com.google.common.collect.Sets;
29import com.google.common.testing.EqualsTester;
30
Ray Milkey6c1bac32015-11-13 14:40:40 -080031import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
32
samueljcca3d9b252015-10-28 15:58:45 -070033/**
34 * Unit tests for DefaultVirtualPort class.
35 */
36public class DefaultVirtualPortTest {
37
38 private Set<FixedIp> fixedIps;
39 private Map<String, String> propertyMap;
40 private Set<AllowedAddressPair> allowedAddressPairs;
41 private Set<SecurityGroup> securityGroups;
42 private VirtualPortId id1;
43 private VirtualPortId id2;
44 private String macAddressStr = "fa:12:3e:56:ee:a2";
45 private String ipAddress = "10.1.1.1";
46 private String deviceStr = "of:000000000000001";
47 private String tenantIdStr = "123";
48 private String portId1 = "1241";
49 private String portId2 = "1242";
50 private String tenantNetworkId = "1234567";
51 private String subnet = "1212";
52 private String hostIdStr = "fa:e2:3e:56:ee:a2";
53
54 private void initVirtualPortId() {
55 id1 = VirtualPortId.portId(portId1);
56 id2 = VirtualPortId.portId(portId2);
57 }
58
59 private void initFixedIpSet() {
60 FixedIp fixedIp = FixedIp.fixedIp(SubnetId.subnetId(subnet),
61 IpAddress.valueOf(ipAddress));
62 fixedIps = Sets.newHashSet();
63 fixedIps.add(fixedIp);
64 }
65
66 private void initPropertyMap() {
67 String deviceOwner = "james";
68 propertyMap = Maps.newHashMap();
69 propertyMap.putIfAbsent("deviceOwner", deviceOwner);
70 }
71
72 private void initAddressPairSet() {
73 allowedAddressPairs = Sets.newHashSet();
74 AllowedAddressPair allowedAddressPair = AllowedAddressPair
75 .allowedAddressPair(IpAddress.valueOf(ipAddress),
76 MacAddress.valueOf(macAddressStr));
77 allowedAddressPairs.add(allowedAddressPair);
78 }
79
80 private void initSecurityGroupSet() {
81 securityGroups = Sets.newHashSet();
82 }
83
84 /**
85 * Checks that the DefaultVirtualPort class is immutable.
86 */
87 @Test
88 public void testImmutability() {
89 assertThatClassIsImmutable(SecurityGroup.class);
90 }
91
92 /**
93 * Checks the operation of equals().
94 */
95 @Test
96 public void testEquals() {
97 initVirtualPortId();
98 initFixedIpSet();
99 initPropertyMap();
100 initAddressPairSet();
101 initSecurityGroupSet();
102 TenantNetworkId networkId = TenantNetworkId.networkId(tenantNetworkId);
103 MacAddress macAddress = MacAddress.valueOf(macAddressStr);
104 TenantId tenantId = TenantId.tenantId(tenantIdStr);
105 DeviceId deviceId = DeviceId.deviceId(deviceStr);
106 BindingHostId bindingHostId = BindingHostId.bindingHostId(hostIdStr);
107
108 VirtualPort d1 = new DefaultVirtualPort(id1, networkId, true,
109 propertyMap,
110 VirtualPort.State.ACTIVE,
111 macAddress, tenantId, deviceId,
112 fixedIps, bindingHostId,
113 allowedAddressPairs,
114 securityGroups);
115 VirtualPort d2 = new DefaultVirtualPort(id1, networkId, true,
116 propertyMap,
117 VirtualPort.State.ACTIVE,
118 macAddress, tenantId, deviceId,
119 fixedIps, bindingHostId,
120 allowedAddressPairs,
121 securityGroups);
122 VirtualPort d3 = new DefaultVirtualPort(id2, networkId, true,
123 propertyMap,
124 VirtualPort.State.ACTIVE,
125 macAddress, tenantId, deviceId,
126 fixedIps, bindingHostId,
127 allowedAddressPairs,
128 securityGroups);
129 new EqualsTester().addEqualityGroup(d1, d2).addEqualityGroup(d3)
130 .testEquals();
131 }
132}