blob: 0fa92170f82175362af78014fb33215163e12bcd [file] [log] [blame]
Charles Chan114aec72017-06-19 14:00:53 -07001/*
Brian O'Connor0947d7e2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Charles Chan114aec72017-06-19 14:00:53 -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
17package org.onosproject.segmentrouting;
18
Charles Chan3ed34d82017-06-22 18:03:14 -070019import com.fasterxml.jackson.databind.JsonNode;
20import com.fasterxml.jackson.databind.ObjectMapper;
Charles Chan114aec72017-06-19 14:00:53 -070021import com.google.common.collect.Lists;
22import com.google.common.collect.Maps;
23import com.google.common.collect.Sets;
Charles Chanbd84dd52018-06-21 19:07:12 -070024import org.easymock.EasyMock;
Charles Chan114aec72017-06-19 14:00:53 -070025import org.junit.Before;
26import org.junit.Test;
Charles Chana2ccb582019-11-25 09:47:22 -080027import org.onlab.packet.EthType;
Charles Chan114aec72017-06-19 14:00:53 -070028import org.onlab.packet.IpAddress;
29import org.onlab.packet.IpPrefix;
30import org.onlab.packet.MacAddress;
31import org.onlab.packet.VlanId;
piercf557922019-05-17 20:47:06 +020032import org.onlab.util.PredictableExecutor;
Charles Chan6c624992017-08-18 17:11:34 -070033import org.onosproject.net.config.ConfigApplyDelegate;
Charles Chan6e90fbb2018-07-23 15:27:34 -070034import org.onosproject.net.host.HostProbingService;
Charles Chanc6bcdf92018-06-01 16:33:48 -070035import org.onosproject.net.host.ProbeMode;
Ray Milkeyc2d43be2017-08-03 11:58:29 -070036import org.onosproject.net.intf.Interface;
Charles Chan114aec72017-06-19 14:00:53 -070037import org.onosproject.net.ConnectPoint;
38import org.onosproject.net.DefaultHost;
39import org.onosproject.net.DeviceId;
40import org.onosproject.net.Host;
41import org.onosproject.net.HostId;
42import org.onosproject.net.HostLocation;
43import org.onosproject.net.PortNumber;
44import org.onosproject.net.config.NetworkConfigRegistryAdapter;
Charles Chan114aec72017-06-19 14:00:53 -070045import org.onosproject.net.flow.TrafficTreatment;
Charles Chan114aec72017-06-19 14:00:53 -070046import org.onosproject.net.host.HostEvent;
47import org.onosproject.net.host.InterfaceIpAddress;
48import org.onosproject.net.provider.ProviderId;
Charles Chanbd84dd52018-06-21 19:07:12 -070049import org.onosproject.routeservice.ResolvedRoute;
50import org.onosproject.routeservice.Route;
51import org.onosproject.routeservice.RouteInfo;
52import org.onosproject.routeservice.RouteService;
53import org.onosproject.routeservice.RouteTableId;
Charles Chan114aec72017-06-19 14:00:53 -070054import org.onosproject.segmentrouting.config.DeviceConfiguration;
Charles Chan3ed34d82017-06-22 18:03:14 -070055import org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig;
Charles Chand66d6712018-03-29 16:03:41 -070056import org.onosproject.store.service.StorageService;
57import org.onosproject.store.service.TestConsistentMap;
Charles Chan114aec72017-06-19 14:00:53 -070058
59import java.util.Map;
Charles Chan114aec72017-06-19 14:00:53 -070060import java.util.Set;
Charles Chan114aec72017-06-19 14:00:53 -070061
Charles Chand66d6712018-03-29 16:03:41 -070062import static org.easymock.EasyMock.createMock;
Charles Chanbd84dd52018-06-21 19:07:12 -070063import static org.easymock.EasyMock.createNiceMock;
Charles Chand66d6712018-03-29 16:03:41 -070064import static org.easymock.EasyMock.expect;
Charles Chanbd84dd52018-06-21 19:07:12 -070065import static org.easymock.EasyMock.expectLastCall;
Charles Chand66d6712018-03-29 16:03:41 -070066import static org.easymock.EasyMock.replay;
Charles Chanbd84dd52018-06-21 19:07:12 -070067import static org.easymock.EasyMock.reset;
68import static org.easymock.EasyMock.verify;
Charles Chan114aec72017-06-19 14:00:53 -070069import static org.junit.Assert.*;
piercf557922019-05-17 20:47:06 +020070import static org.onlab.util.Tools.groupedThreads;
Charles Chan114aec72017-06-19 14:00:53 -070071
piercf557922019-05-17 20:47:06 +020072/**
Charles Chan114aec72017-06-19 14:00:53 -070073 * Unit test for {@link HostHandler}.
74 */
75public class HostHandlerTest {
Charles Chan114aec72017-06-19 14:00:53 -070076 private HostHandler hostHandler;
77
78 // Mocked routing and bridging tables
Charles Chan6c624992017-08-18 17:11:34 -070079 private static final Map<MockBridgingTableKey, MockBridgingTableValue> BRIDGING_TABLE =
80 Maps.newConcurrentMap();
81 private static final Map<MockRoutingTableKey, MockRoutingTableValue> ROUTING_TABLE =
82 Maps.newConcurrentMap();
Charles Chan910be6a2017-08-23 14:46:43 -070083 private static final Map<ConnectPoint, Set<IpPrefix>> SUBNET_TABLE = Maps.newConcurrentMap();
Charles Chan114aec72017-06-19 14:00:53 -070084 // Mocked Next Id
Charles Chan6c624992017-08-18 17:11:34 -070085 private static final Map<Integer, TrafficTreatment> NEXT_TABLE = Maps.newConcurrentMap();
Charles Chan114aec72017-06-19 14:00:53 -070086
Charles Chand9265a32017-06-16 15:19:24 -070087 // Host Mac, VLAN
Charles Chan114aec72017-06-19 14:00:53 -070088 private static final ProviderId PROVIDER_ID = ProviderId.NONE;
89 private static final MacAddress HOST_MAC = MacAddress.valueOf("00:00:00:00:00:01");
90 private static final VlanId HOST_VLAN_UNTAGGED = VlanId.NONE;
91 private static final HostId HOST_ID_UNTAGGED = HostId.hostId(HOST_MAC, HOST_VLAN_UNTAGGED);
92 private static final VlanId HOST_VLAN_TAGGED = VlanId.vlanId((short) 20);
93 private static final HostId HOST_ID_TAGGED = HostId.hostId(HOST_MAC, HOST_VLAN_TAGGED);
Charles Chand9265a32017-06-16 15:19:24 -070094 // Host IP
95 private static final IpAddress HOST_IP11 = IpAddress.valueOf("10.0.1.1");
96 private static final IpAddress HOST_IP21 = IpAddress.valueOf("10.0.2.1");
97 private static final IpAddress HOST_IP12 = IpAddress.valueOf("10.0.1.2");
98 private static final IpAddress HOST_IP13 = IpAddress.valueOf("10.0.1.3");
99 private static final IpAddress HOST_IP14 = IpAddress.valueOf("10.0.1.4");
Charles Chan6e90fbb2018-07-23 15:27:34 -0700100 private static final IpAddress HOST_IP33 = IpAddress.valueOf("10.0.3.3");
Charles Chand9265a32017-06-16 15:19:24 -0700101 // Device
102 private static final DeviceId DEV1 = DeviceId.deviceId("of:0000000000000001");
103 private static final DeviceId DEV2 = DeviceId.deviceId("of:0000000000000002");
Charles Chanabfe7e02017-08-09 16:50:15 -0700104 private static final DeviceId DEV3 = DeviceId.deviceId("of:0000000000000003");
105 private static final DeviceId DEV4 = DeviceId.deviceId("of:0000000000000004");
106 private static final DeviceId DEV5 = DeviceId.deviceId("of:0000000000000005");
107 private static final DeviceId DEV6 = DeviceId.deviceId("of:0000000000000006");
Charles Chand9265a32017-06-16 15:19:24 -0700108 // Port
109 private static final PortNumber P1 = PortNumber.portNumber(1);
110 private static final PortNumber P2 = PortNumber.portNumber(2);
111 private static final PortNumber P3 = PortNumber.portNumber(3);
Charles Chan3ed34d82017-06-22 18:03:14 -0700112 private static final PortNumber P9 = PortNumber.portNumber(9);
Charles Chand9265a32017-06-16 15:19:24 -0700113 // Connect Point
114 private static final ConnectPoint CP11 = new ConnectPoint(DEV1, P1);
115 private static final HostLocation HOST_LOC11 = new HostLocation(CP11, 0);
116 private static final ConnectPoint CP12 = new ConnectPoint(DEV1, P2);
117 private static final HostLocation HOST_LOC12 = new HostLocation(CP12, 0);
118 private static final ConnectPoint CP13 = new ConnectPoint(DEV1, P3);
119 private static final HostLocation HOST_LOC13 = new HostLocation(CP13, 0);
120 private static final ConnectPoint CP21 = new ConnectPoint(DEV2, P1);
121 private static final HostLocation HOST_LOC21 = new HostLocation(CP21, 0);
122 private static final ConnectPoint CP22 = new ConnectPoint(DEV2, P2);
123 private static final HostLocation HOST_LOC22 = new HostLocation(CP22, 0);
Charles Chan3ed34d82017-06-22 18:03:14 -0700124 // Connect Point for dual-homed host failover
125 private static final ConnectPoint CP31 = new ConnectPoint(DEV3, P1);
126 private static final HostLocation HOST_LOC31 = new HostLocation(CP31, 0);
Charles Chanceb2a2e2017-09-12 18:57:47 -0700127 private static final ConnectPoint CP32 = new ConnectPoint(DEV3, P2);
128 private static final HostLocation HOST_LOC32 = new HostLocation(CP32, 0);
Charles Chan6e90fbb2018-07-23 15:27:34 -0700129 private static final ConnectPoint CP33 = new ConnectPoint(DEV3, P3);
130 private static final HostLocation HOST_LOC33 = new HostLocation(CP33, 0);
Charles Chan3ed34d82017-06-22 18:03:14 -0700131 private static final ConnectPoint CP41 = new ConnectPoint(DEV4, P1);
132 private static final HostLocation HOST_LOC41 = new HostLocation(CP41, 0);
Charles Chan6e90fbb2018-07-23 15:27:34 -0700133 private static final ConnectPoint CP42 = new ConnectPoint(DEV4, P2);
134 private static final HostLocation HOST_LOC42 = new HostLocation(CP42, 0);
Charles Chan3ed34d82017-06-22 18:03:14 -0700135 private static final ConnectPoint CP39 = new ConnectPoint(DEV3, P9);
136 private static final ConnectPoint CP49 = new ConnectPoint(DEV4, P9);
Charles Chanabfe7e02017-08-09 16:50:15 -0700137 // Conenct Point for mastership test
138 private static final ConnectPoint CP51 = new ConnectPoint(DEV5, P1);
139 private static final HostLocation HOST_LOC51 = new HostLocation(CP51, 0);
140 private static final ConnectPoint CP61 = new ConnectPoint(DEV6, P1);
141 private static final HostLocation HOST_LOC61 = new HostLocation(CP61, 0);
Charles Chand9265a32017-06-16 15:19:24 -0700142 // Interface VLAN
Charles Chan114aec72017-06-19 14:00:53 -0700143 private static final VlanId INTF_VLAN_UNTAGGED = VlanId.vlanId((short) 10);
Charles Chan868c9572018-06-15 18:54:18 -0700144 private static final VlanId INTF_VLAN_TAGGED_1 = VlanId.vlanId((short) 20);
145 private static final Set<VlanId> INTF_VLAN_TAGGED = Sets.newHashSet(INTF_VLAN_TAGGED_1);
Charles Chan114aec72017-06-19 14:00:53 -0700146 private static final VlanId INTF_VLAN_NATIVE = VlanId.vlanId((short) 30);
Charles Chan3ed34d82017-06-22 18:03:14 -0700147 private static final Set<VlanId> INTF_VLAN_PAIR = Sets.newHashSet(VlanId.vlanId((short) 10),
148 VlanId.vlanId((short) 20), VlanId.vlanId((short) 30));
Charles Chanceb2a2e2017-09-12 18:57:47 -0700149 private static final VlanId INTF_VLAN_OTHER = VlanId.vlanId((short) 40);
Charles Chand9265a32017-06-16 15:19:24 -0700150 // Interface subnet
151 private static final IpPrefix INTF_PREFIX1 = IpPrefix.valueOf("10.0.1.254/24");
152 private static final IpPrefix INTF_PREFIX2 = IpPrefix.valueOf("10.0.2.254/24");
Charles Chanceb2a2e2017-09-12 18:57:47 -0700153 private static final IpPrefix INTF_PREFIX3 = IpPrefix.valueOf("10.0.3.254/24");
Charles Chand9265a32017-06-16 15:19:24 -0700154 private static final InterfaceIpAddress INTF_IP1 =
155 new InterfaceIpAddress(INTF_PREFIX1.address(), INTF_PREFIX1);
156 private static final InterfaceIpAddress INTF_IP2 =
157 new InterfaceIpAddress(INTF_PREFIX2.address(), INTF_PREFIX2);
Charles Chanceb2a2e2017-09-12 18:57:47 -0700158 private static final InterfaceIpAddress INTF_IP3 =
159 new InterfaceIpAddress(INTF_PREFIX3.address(), INTF_PREFIX3);
Charles Chan6c624992017-08-18 17:11:34 -0700160 // Interfaces
161 private static final Interface INTF11 =
162 new Interface(null, CP11, Lists.newArrayList(INTF_IP1), MacAddress.NONE, null,
163 INTF_VLAN_UNTAGGED, null, null);
164 private static final Interface INTF12 =
165 new Interface(null, CP12, Lists.newArrayList(INTF_IP1), MacAddress.NONE, null,
166 INTF_VLAN_UNTAGGED, null, null);
167 private static final Interface INTF13 =
168 new Interface(null, CP13, Lists.newArrayList(INTF_IP2), MacAddress.NONE, null,
169 null, INTF_VLAN_TAGGED, INTF_VLAN_NATIVE);
170 private static final Interface INTF21 =
171 new Interface(null, CP21, Lists.newArrayList(INTF_IP1), MacAddress.NONE, null,
172 INTF_VLAN_UNTAGGED, null, null);
173 private static final Interface INTF22 =
174 new Interface(null, CP22, Lists.newArrayList(INTF_IP1), MacAddress.NONE, null,
175 INTF_VLAN_UNTAGGED, null, null);
176 private static final Interface INTF31 =
177 new Interface(null, CP31, Lists.newArrayList(INTF_IP1), MacAddress.NONE, null,
178 INTF_VLAN_UNTAGGED, null, null);
Charles Chanceb2a2e2017-09-12 18:57:47 -0700179 private static final Interface INTF32 =
Charles Chan6e90fbb2018-07-23 15:27:34 -0700180 new Interface(null, CP32, Lists.newArrayList(INTF_IP1), MacAddress.NONE, null,
181 INTF_VLAN_UNTAGGED, null, null);
182 private static final Interface INTF33 =
183 new Interface(null, CP33, Lists.newArrayList(INTF_IP3), MacAddress.NONE, null,
Charles Chanceb2a2e2017-09-12 18:57:47 -0700184 INTF_VLAN_OTHER, null, null);
Charles Chan6c624992017-08-18 17:11:34 -0700185 private static final Interface INTF39 =
186 new Interface(null, CP39, Lists.newArrayList(INTF_IP1), MacAddress.NONE, null,
187 null, INTF_VLAN_PAIR, null);
188 private static final Interface INTF41 =
189 new Interface(null, CP41, Lists.newArrayList(INTF_IP1), MacAddress.NONE, null,
190 INTF_VLAN_UNTAGGED, null, null);
Charles Chan6e90fbb2018-07-23 15:27:34 -0700191 private static final Interface INTF42 =
192 new Interface(null, CP42, Lists.newArrayList(INTF_IP1), MacAddress.NONE, null,
193 INTF_VLAN_UNTAGGED, null, null);
Charles Chan6c624992017-08-18 17:11:34 -0700194 private static final Interface INTF49 =
195 new Interface(null, CP49, Lists.newArrayList(INTF_IP1), MacAddress.NONE, null,
196 null, INTF_VLAN_PAIR, null);
Charles Chand9265a32017-06-16 15:19:24 -0700197 // Host
198 private static final Host HOST1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC,
199 HOST_VLAN_UNTAGGED, Sets.newHashSet(HOST_LOC11, HOST_LOC21), Sets.newHashSet(HOST_IP11),
200 false);
Charles Chan114aec72017-06-19 14:00:53 -0700201
Charles Chan6c624992017-08-18 17:11:34 -0700202 // A set of hosts
203 private static final Set<Host> HOSTS = Sets.newHashSet(HOST1);
204 // A set of devices of which we have mastership
205 private static final Set<DeviceId> LOCAL_DEVICES = Sets.newHashSet(DEV1, DEV2, DEV3, DEV4);
206 // A set of interfaces
207 private static final Set<Interface> INTERFACES = Sets.newHashSet(INTF11, INTF12, INTF13, INTF21,
Charles Chan6e90fbb2018-07-23 15:27:34 -0700208 INTF22, INTF31, INTF32, INTF33, INTF39, INTF41, INTF42, INTF49);
Charles Chan6c624992017-08-18 17:11:34 -0700209
Charles Chanc6bcdf92018-06-01 16:33:48 -0700210 private MockHostProbingService mockLocationProbingService;
Charles Chan873661e2017-11-30 15:37:50 -0800211
Charles Chan114aec72017-06-19 14:00:53 -0700212 @Before
Charles Chan6e90fbb2018-07-23 15:27:34 -0700213 public void setUp() {
Charles Chan6c624992017-08-18 17:11:34 -0700214 // Initialize pairDevice and pairLocalPort config
215 ObjectMapper mapper = new ObjectMapper();
216 ConfigApplyDelegate delegate = config -> { };
217
218 SegmentRoutingDeviceConfig dev3Config = new SegmentRoutingDeviceConfig();
219 JsonNode dev3Tree = mapper.createObjectNode();
220 dev3Config.init(DEV3, "host-handler-test", dev3Tree, mapper, delegate);
221 dev3Config.setPairDeviceId(DEV4).setPairLocalPort(P9);
222
223 SegmentRoutingDeviceConfig dev4Config = new SegmentRoutingDeviceConfig();
224 JsonNode dev4Tree = mapper.createObjectNode();
225 dev4Config.init(DEV4, "host-handler-test", dev4Tree, mapper, delegate);
226 dev4Config.setPairDeviceId(DEV3).setPairLocalPort(P9);
227
228 MockNetworkConfigRegistry mockNetworkConfigRegistry = new MockNetworkConfigRegistry();
229 mockNetworkConfigRegistry.applyConfig(dev3Config);
230 mockNetworkConfigRegistry.applyConfig(dev4Config);
231
232 // Initialize Segment Routing Manager
233 SegmentRoutingManager srManager = new MockSegmentRoutingManager(NEXT_TABLE);
Charles Chand66d6712018-03-29 16:03:41 -0700234 srManager.storageService = createMock(StorageService.class);
235 expect(srManager.storageService.consistentMapBuilder()).andReturn(new TestConsistentMap.Builder<>()).anyTimes();
236 replay(srManager.storageService);
Charles Chan114aec72017-06-19 14:00:53 -0700237 srManager.cfgService = new NetworkConfigRegistryAdapter();
238 srManager.deviceConfiguration = new DeviceConfiguration(srManager);
Charles Chan6c624992017-08-18 17:11:34 -0700239 srManager.flowObjectiveService = new MockFlowObjectiveService(BRIDGING_TABLE, NEXT_TABLE);
240 srManager.routingRulePopulator = new MockRoutingRulePopulator(srManager, ROUTING_TABLE);
Charles Chanc4d68882018-03-15 16:41:10 -0700241 srManager.defaultRoutingHandler = new MockDefaultRoutingHandler(srManager, SUBNET_TABLE, ROUTING_TABLE);
Charles Chan6c624992017-08-18 17:11:34 -0700242 srManager.interfaceService = new MockInterfaceService(INTERFACES);
243 srManager.mastershipService = new MockMastershipService(LOCAL_DEVICES);
244 srManager.hostService = new MockHostService(HOSTS);
245 srManager.cfgService = mockNetworkConfigRegistry;
Charles Chanc6bcdf92018-06-01 16:33:48 -0700246 mockLocationProbingService = new MockHostProbingService();
Charles Chan873661e2017-11-30 15:37:50 -0800247 srManager.probingService = mockLocationProbingService;
Saurav Dase6c448a2018-01-18 12:07:33 -0800248 srManager.linkHandler = new MockLinkHandler(srManager);
Charles Chan114aec72017-06-19 14:00:53 -0700249
Charles Chanbd84dd52018-06-21 19:07:12 -0700250 // Not important for most of the HostHandler test case. Simply return an empty set here
251 srManager.routeService = createNiceMock(RouteService.class);
252 expect(srManager.routeService.getRouteTables()).andReturn(Sets.newHashSet()).anyTimes();
253 replay(srManager.routeService);
254
Charles Chan114aec72017-06-19 14:00:53 -0700255 hostHandler = new HostHandler(srManager);
piercf557922019-05-17 20:47:06 +0200256 hostHandler.hostWorkers = new PredictableExecutor(
257 0, groupedThreads("onos/sr", "h-worker-%d"), true);
Charles Chan114aec72017-06-19 14:00:53 -0700258
Charles Chan6c624992017-08-18 17:11:34 -0700259 ROUTING_TABLE.clear();
260 BRIDGING_TABLE.clear();
Charles Chan114aec72017-06-19 14:00:53 -0700261 }
262
263 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700264 public void init() {
Charles Chand9265a32017-06-16 15:19:24 -0700265 hostHandler.init(DEV1);
Charles Chan6c624992017-08-18 17:11:34 -0700266 assertEquals(1, ROUTING_TABLE.size());
267 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
268 assertEquals(1, BRIDGING_TABLE.size());
269 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chand9265a32017-06-16 15:19:24 -0700270
271 hostHandler.init(DEV2);
Charles Chan6c624992017-08-18 17:11:34 -0700272 assertEquals(2, ROUTING_TABLE.size());
273 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
274 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())));
275 assertEquals(2, BRIDGING_TABLE.size());
276 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
277 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chand9265a32017-06-16 15:19:24 -0700278 }
279
280 @Test(expected = IllegalArgumentException.class)
Charles Chan6e90fbb2018-07-23 15:27:34 -0700281 public void testHostAddedAtWrongLocation() {
Charles Chand9265a32017-06-16 15:19:24 -0700282 hostHandler.processHostAddedAtLocation(HOST1, HOST_LOC13);
283 }
284
285
286 @Test()
Charles Chan6e90fbb2018-07-23 15:27:34 -0700287 public void testHostAddedAtCorrectLocation() {
Charles Chand9265a32017-06-16 15:19:24 -0700288 hostHandler.processHostAddedAtLocation(HOST1, HOST_LOC11);
Charles Chan6c624992017-08-18 17:11:34 -0700289 assertEquals(1, ROUTING_TABLE.size());
290 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
291 assertEquals(1, BRIDGING_TABLE.size());
292 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chan114aec72017-06-19 14:00:53 -0700293 }
294
295 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700296 public void testHostAdded() {
Charles Chan114aec72017-06-19 14:00:53 -0700297 Host subject;
298
299 // Untagged host discovered on untagged port
300 // Expect: add one routing rule and one bridging rule
301 subject = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
Charles Chand9265a32017-06-16 15:19:24 -0700302 Sets.newHashSet(HOST_LOC11), Sets.newHashSet(HOST_IP11), false);
Charles Chan114aec72017-06-19 14:00:53 -0700303 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, subject));
Charles Chan6c624992017-08-18 17:11:34 -0700304 assertEquals(1, ROUTING_TABLE.size());
305 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
306 assertEquals(1, BRIDGING_TABLE.size());
307 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chan114aec72017-06-19 14:00:53 -0700308
309 // Untagged host discovered on tagged/native port
310 // Expect: add one routing rule and one bridging rule
311 subject = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
Charles Chand9265a32017-06-16 15:19:24 -0700312 Sets.newHashSet(HOST_LOC13), Sets.newHashSet(HOST_IP21), false);
Charles Chan114aec72017-06-19 14:00:53 -0700313 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, subject));
Charles Chan6c624992017-08-18 17:11:34 -0700314 assertEquals(2, ROUTING_TABLE.size());
315 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP21.toIpPrefix())));
316 assertEquals(2, BRIDGING_TABLE.size());
317 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_NATIVE)));
Charles Chan114aec72017-06-19 14:00:53 -0700318
319 // Tagged host discovered on untagged port
320 // Expect: ignore the host. No rule is added.
321 subject = new DefaultHost(PROVIDER_ID, HOST_ID_TAGGED, HOST_MAC, HOST_VLAN_TAGGED,
Charles Chand9265a32017-06-16 15:19:24 -0700322 Sets.newHashSet(HOST_LOC11), Sets.newHashSet(HOST_IP11), false);
Charles Chan114aec72017-06-19 14:00:53 -0700323 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, subject));
Charles Chan6c624992017-08-18 17:11:34 -0700324 assertEquals(2, ROUTING_TABLE.size());
325 assertEquals(2, BRIDGING_TABLE.size());
Charles Chan114aec72017-06-19 14:00:53 -0700326
327 // Tagged host discovered on tagged port with the same IP
328 // Expect: update existing route, add one bridging rule
329 subject = new DefaultHost(PROVIDER_ID, HOST_ID_TAGGED, HOST_MAC, HOST_VLAN_TAGGED,
Charles Chand9265a32017-06-16 15:19:24 -0700330 Sets.newHashSet(HOST_LOC13), Sets.newHashSet(HOST_IP21), false);
Charles Chan114aec72017-06-19 14:00:53 -0700331 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, subject));
Charles Chan6c624992017-08-18 17:11:34 -0700332 assertEquals(2, ROUTING_TABLE.size());
333 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP21.toIpPrefix())));
334 assertEquals(HOST_VLAN_TAGGED, ROUTING_TABLE.get(new MockRoutingTableKey(HOST_LOC13.deviceId(),
Charles Chand9265a32017-06-16 15:19:24 -0700335 HOST_IP21.toIpPrefix())).vlanId);
Charles Chan6c624992017-08-18 17:11:34 -0700336 assertEquals(3, BRIDGING_TABLE.size());
337 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, HOST_VLAN_TAGGED)));
Charles Chand9265a32017-06-16 15:19:24 -0700338 }
339
340 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700341 public void testDualHomedHostAdded() {
Charles Chand9265a32017-06-16 15:19:24 -0700342 // Add a dual-homed host that has 2 locations
343 // Expect: add two routing rules and two bridging rules
344 Host subject = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
345 Sets.newHashSet(HOST_LOC11, HOST_LOC21), Sets.newHashSet(HOST_IP11), false);
346 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, subject));
Charles Chan6c624992017-08-18 17:11:34 -0700347 assertEquals(2, ROUTING_TABLE.size());
348 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
349 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())));
350 assertEquals(2, BRIDGING_TABLE.size());
351 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
352 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chan114aec72017-06-19 14:00:53 -0700353 }
354
355 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700356 public void testSingleHomedHostAddedOnPairLeaf() {
Charles Chanceb2a2e2017-09-12 18:57:47 -0700357 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
Charles Chan6e90fbb2018-07-23 15:27:34 -0700358 Sets.newHashSet(HOST_LOC33), Sets.newHashSet(HOST_IP33), false);
Charles Chanceb2a2e2017-09-12 18:57:47 -0700359
360 // Add a single-homed host with one location
361 // Expect: the pair link should not be utilized
362 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
363 assertEquals(1, ROUTING_TABLE.size());
Charles Chan6e90fbb2018-07-23 15:27:34 -0700364 assertEquals(P3, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP33.toIpPrefix())).portNumber);
Charles Chanceb2a2e2017-09-12 18:57:47 -0700365 assertEquals(1, BRIDGING_TABLE.size());
Charles Chan6e90fbb2018-07-23 15:27:34 -0700366 assertEquals(P3, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_OTHER)).portNumber);
Charles Chanceb2a2e2017-09-12 18:57:47 -0700367 }
368
369 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700370 public void testDualHomedHostAddedOneByOne() {
Charles Chanceb2a2e2017-09-12 18:57:47 -0700371 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
372 Sets.newHashSet(HOST_LOC31), Sets.newHashSet(HOST_IP11), false);
373 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
374 Sets.newHashSet(HOST_LOC31, HOST_LOC41), Sets.newHashSet(HOST_IP11), false);
375
376 // Add a dual-homed host with one location
377 // Expect: the pair link is utilized temporarily before the second location is discovered
378 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
379 assertEquals(2, ROUTING_TABLE.size());
380 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP11.toIpPrefix())).portNumber);
381 assertEquals(P9, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
382 assertEquals(2, BRIDGING_TABLE.size());
383 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
384 assertEquals(P9, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chan873661e2017-11-30 15:37:50 -0800385 // Expect probe to be sent out on pair device
Charles Chanc6bcdf92018-06-01 16:33:48 -0700386 assertTrue(mockLocationProbingService.verifyProbe(host1, CP41, ProbeMode.DISCOVER));
Charles Chanceb2a2e2017-09-12 18:57:47 -0700387
388 // Add the second location of dual-homed host
389 // Expect: no longer use the pair link
390 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host1));
391 assertEquals(2, ROUTING_TABLE.size());
392 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP11.toIpPrefix())).portNumber);
Charles Chanfbcb8812018-04-18 18:41:05 -0700393 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
Charles Chanceb2a2e2017-09-12 18:57:47 -0700394 assertEquals(2, BRIDGING_TABLE.size());
395 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
396 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
397 }
398
399 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700400 public void testHostRemoved() {
Charles Chan114aec72017-06-19 14:00:53 -0700401 Host subject = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
Charles Chand9265a32017-06-16 15:19:24 -0700402 Sets.newHashSet(HOST_LOC11), Sets.newHashSet(HOST_IP11), false);
Charles Chan114aec72017-06-19 14:00:53 -0700403
404 // Add a host
405 // Expect: add one routing rule and one bridging rule
406 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, subject));
Charles Chan6c624992017-08-18 17:11:34 -0700407 assertEquals(1, ROUTING_TABLE.size());
408 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
409 assertEquals(1, BRIDGING_TABLE.size());
410 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chan114aec72017-06-19 14:00:53 -0700411
412 // Remove the host
413 // Expect: add the routing rule and the bridging rule
Charles Chand9265a32017-06-16 15:19:24 -0700414 hostHandler.processHostRemovedEvent(new HostEvent(HostEvent.Type.HOST_REMOVED, subject));
Charles Chan6c624992017-08-18 17:11:34 -0700415 assertEquals(0, ROUTING_TABLE.size());
416 assertEquals(0, BRIDGING_TABLE.size());
Charles Chand9265a32017-06-16 15:19:24 -0700417 }
418
419 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700420 public void testDualHomedHostRemoved() {
Charles Chand9265a32017-06-16 15:19:24 -0700421 // Add a dual-homed host that has 2 locations
422 // Expect: add two routing rules and two bridging rules
423 Host subject = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
424 Sets.newHashSet(HOST_LOC11, HOST_LOC21), Sets.newHashSet(HOST_IP11), false);
425 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, subject));
Charles Chan6c624992017-08-18 17:11:34 -0700426 assertEquals(2, ROUTING_TABLE.size());
427 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
428 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())));
429 assertEquals(2, BRIDGING_TABLE.size());
430 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
431 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chand9265a32017-06-16 15:19:24 -0700432
433 // Remove a dual-homed host that has 2 locations
434 // Expect: all routing and bridging rules are removed
435 hostHandler.processHostRemovedEvent(new HostEvent(HostEvent.Type.HOST_REMOVED, subject));
Charles Chan6c624992017-08-18 17:11:34 -0700436 assertEquals(0, ROUTING_TABLE.size());
437 assertEquals(0, BRIDGING_TABLE.size());
Charles Chan114aec72017-06-19 14:00:53 -0700438 }
439
440 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700441 public void testHostMoved() {
Charles Chan114aec72017-06-19 14:00:53 -0700442 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
Charles Chand9265a32017-06-16 15:19:24 -0700443 Sets.newHashSet(HOST_LOC11), Sets.newHashSet(HOST_IP11), false);
Charles Chan114aec72017-06-19 14:00:53 -0700444 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
Charles Chand9265a32017-06-16 15:19:24 -0700445 Sets.newHashSet(HOST_LOC21), Sets.newHashSet(HOST_IP11), false);
Charles Chan114aec72017-06-19 14:00:53 -0700446 Host host3 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
Charles Chand9265a32017-06-16 15:19:24 -0700447 Sets.newHashSet(HOST_LOC13), Sets.newHashSet(HOST_IP11), false);
Charles Chan114aec72017-06-19 14:00:53 -0700448
449 // Add a host
Charles Chan3ed34d82017-06-22 18:03:14 -0700450 // Expect: add one new routing rule, one new bridging rule
Charles Chan114aec72017-06-19 14:00:53 -0700451 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
Charles Chan6c624992017-08-18 17:11:34 -0700452 assertEquals(1, ROUTING_TABLE.size());
453 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
454 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP21.toIpPrefix())));
455 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP13.toIpPrefix())));
456 assertEquals(1, BRIDGING_TABLE.size());
457 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
458 assertNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chan114aec72017-06-19 14:00:53 -0700459
Charles Chand9265a32017-06-16 15:19:24 -0700460 // Move the host to CP13, which has different subnet setting
Charles Chan114aec72017-06-19 14:00:53 -0700461 // Expect: remove routing rule. Change vlan in bridging rule.
Charles Chand9265a32017-06-16 15:19:24 -0700462 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host3, host1));
Charles Chan6c624992017-08-18 17:11:34 -0700463 assertEquals(0, ROUTING_TABLE.size());
464 assertEquals(1, BRIDGING_TABLE.size());
465 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_NATIVE)));
466 assertNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chan114aec72017-06-19 14:00:53 -0700467
Charles Chand9265a32017-06-16 15:19:24 -0700468 // Move the host to CP21, which has same subnet setting
Charles Chan114aec72017-06-19 14:00:53 -0700469 // Expect: add a new routing rule. Change vlan in bridging rule.
Charles Chand9265a32017-06-16 15:19:24 -0700470 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host3));
Charles Chan6c624992017-08-18 17:11:34 -0700471 assertEquals(1, ROUTING_TABLE.size());
472 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
473 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
474 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())));
475 assertEquals(1, BRIDGING_TABLE.size());
476 assertNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
477 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chand9265a32017-06-16 15:19:24 -0700478 }
479
480 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700481 public void testDualHomedHostMoved() {
Charles Chand9265a32017-06-16 15:19:24 -0700482 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
483 Sets.newHashSet(HOST_LOC11, HOST_LOC21), Sets.newHashSet(HOST_IP11, HOST_IP12), false);
484 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
485 Sets.newHashSet(HOST_LOC12, HOST_LOC22), Sets.newHashSet(HOST_IP11, HOST_IP12), false);
486 Host host3 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
487 Sets.newHashSet(HOST_LOC11, HOST_LOC21), Sets.newHashSet(HOST_IP13, HOST_IP14), false);
488 Host host4 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
489 Sets.newHashSet(HOST_LOC11, HOST_LOC22), Sets.newHashSet(HOST_IP12, HOST_IP13), false);
Charles Chan4b5769a2018-04-25 18:51:46 -0400490 Host host5 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
491 Sets.newHashSet(HOST_LOC12, HOST_LOC21), Sets.newHashSet(HOST_IP11, HOST_IP12), false);
492
Charles Chand9265a32017-06-16 15:19:24 -0700493
494 // Add a host with IP11, IP12 and LOC11, LOC21
495 // Expect: 4 routing rules and 2 bridging rules
496 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
Charles Chan6c624992017-08-18 17:11:34 -0700497 assertEquals(4, ROUTING_TABLE.size());
498 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())).portNumber);
499 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP12.toIpPrefix())).portNumber);
500 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())).portNumber);
501 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP12.toIpPrefix())).portNumber);
502 assertEquals(2, BRIDGING_TABLE.size());
503 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
504 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chand9265a32017-06-16 15:19:24 -0700505
Charles Chan4b5769a2018-04-25 18:51:46 -0400506 // Move the host to LOC12, LOC21 and keep the IP
507 // Expect: 4 routing rules and 2 bridging rules all at the new location
508 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host5, host1));
509 assertEquals(4, ROUTING_TABLE.size());
510 assertEquals(P2, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())).portNumber);
511 assertEquals(P2, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP12.toIpPrefix())).portNumber);
512 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())).portNumber);
513 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP12.toIpPrefix())).portNumber);
514 assertEquals(2, BRIDGING_TABLE.size());
515 assertEquals(P2, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
516 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
517
Charles Chand9265a32017-06-16 15:19:24 -0700518 // Move the host to LOC12, LOC22 and keep the IP
519 // Expect: 4 routing rules and 2 bridging rules all at the new location
Charles Chan4b5769a2018-04-25 18:51:46 -0400520 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host5));
Charles Chan6c624992017-08-18 17:11:34 -0700521 assertEquals(4, ROUTING_TABLE.size());
522 assertEquals(P2, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())).portNumber);
523 assertEquals(P2, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP12.toIpPrefix())).portNumber);
524 assertEquals(P2, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())).portNumber);
525 assertEquals(P2, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP12.toIpPrefix())).portNumber);
526 assertEquals(2, BRIDGING_TABLE.size());
527 assertEquals(P2, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
528 assertEquals(P2, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chand9265a32017-06-16 15:19:24 -0700529
530 // Move the host to LOC11, LOC21 and change the IP to IP13, IP14 at the same time
531 // Expect: 4 routing rules and 2 bridging rules all at the new location
532 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host3, host2));
Charles Chan6c624992017-08-18 17:11:34 -0700533 assertEquals(4, ROUTING_TABLE.size());
534 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP13.toIpPrefix())).portNumber);
535 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP14.toIpPrefix())).portNumber);
536 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP13.toIpPrefix())).portNumber);
537 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP14.toIpPrefix())).portNumber);
538 assertEquals(2, BRIDGING_TABLE.size());
539 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
540 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chand9265a32017-06-16 15:19:24 -0700541
542 // Move the host to LOC11, LOC22 and change the IP to IP12, IP13 at the same time
543 // Expect: 4 routing rules and 2 bridging rules all at the new location
544 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host4, host3));
Charles Chan6c624992017-08-18 17:11:34 -0700545 assertEquals(4, ROUTING_TABLE.size());
546 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP12.toIpPrefix())).portNumber);
547 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP13.toIpPrefix())).portNumber);
548 assertEquals(P2, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP12.toIpPrefix())).portNumber);
549 assertEquals(P2, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP13.toIpPrefix())).portNumber);
550 assertEquals(2, BRIDGING_TABLE.size());
551 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
552 assertEquals(P2, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chan114aec72017-06-19 14:00:53 -0700553 }
554
555 @Test
Charles Chan6d43c162018-10-11 12:35:36 -0700556 public void testDualHomedHostMoveTransient() {
557 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
558 Sets.newHashSet(HOST_LOC31, HOST_LOC41), Sets.newHashSet(HOST_IP11), false);
559 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
560 Sets.newHashSet(HOST_LOC32, HOST_LOC41), Sets.newHashSet(HOST_IP11), false);
561 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
562
563 // Mock DefaultRoutingHandler
564 DefaultRoutingHandler mockDefaultRoutingHandler = createMock(DefaultRoutingHandler.class);
565 hostHandler.srManager.defaultRoutingHandler = mockDefaultRoutingHandler;
566
567 // Host moved from [1A/1, 1B/1] to [1A/2, 1B/1]
568 // We should expect only one bridging flow and one routing flow programmed on 1A
569 mockDefaultRoutingHandler.populateBridging(DEV3, P2, HOST_MAC, HOST_VLAN_UNTAGGED);
570 expectLastCall().times(1);
Ruchi Sahota71bcb4e2019-01-28 01:08:18 +0000571 mockDefaultRoutingHandler.populateRoute(DEV3, HOST_IP11.toIpPrefix(), HOST_MAC, HOST_VLAN_UNTAGGED, P2, true);
Charles Chan6d43c162018-10-11 12:35:36 -0700572 expectLastCall().times(1);
573 replay(mockDefaultRoutingHandler);
574
575 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host1));
576 verify(mockDefaultRoutingHandler);
577 }
578
579 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700580 public void testHostMoveToInvalidLocation() {
Charles Chanabfe7e02017-08-09 16:50:15 -0700581 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
582 Sets.newHashSet(HOST_LOC11), Sets.newHashSet(HOST_IP11), false);
583 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
584 Sets.newHashSet(HOST_LOC51), Sets.newHashSet(HOST_IP11), false);
585
586 // Add a host
587 // Expect: add one new routing rule, one new bridging rule
588 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
Charles Chan6c624992017-08-18 17:11:34 -0700589 assertEquals(1, ROUTING_TABLE.size());
590 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
591 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP21.toIpPrefix())));
592 assertEquals(1, BRIDGING_TABLE.size());
593 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
594 assertNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chanabfe7e02017-08-09 16:50:15 -0700595
596 // Move the host to an invalid location
597 // Expect: Old flow is removed. New flow is not created
598 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host1));
Charles Chan6c624992017-08-18 17:11:34 -0700599 assertEquals(0, ROUTING_TABLE.size());
600 assertEquals(0, BRIDGING_TABLE.size());
Charles Chanabfe7e02017-08-09 16:50:15 -0700601
602 // Move the host to a valid location
603 // Expect: add one new routing rule, one new bridging rule
604 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host1, host2));
Charles Chan6c624992017-08-18 17:11:34 -0700605 assertEquals(1, ROUTING_TABLE.size());
606 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
607 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP21.toIpPrefix())));
608 assertEquals(1, BRIDGING_TABLE.size());
609 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
610 assertNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chanabfe7e02017-08-09 16:50:15 -0700611 }
612
613 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700614 public void testDualHomedHostMoveToInvalidLocation() {
Charles Chanabfe7e02017-08-09 16:50:15 -0700615 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
616 Sets.newHashSet(HOST_LOC11, HOST_LOC21), Sets.newHashSet(HOST_IP11), false);
617 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
618 Sets.newHashSet(HOST_LOC11, HOST_LOC51), Sets.newHashSet(HOST_IP11), false);
619 Host host3 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
620 Sets.newHashSet(HOST_LOC61, HOST_LOC51), Sets.newHashSet(HOST_IP11), false);
621
622 // Add a host
623 // Expect: add two new routing rules, two new bridging rules
624 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
Charles Chan6c624992017-08-18 17:11:34 -0700625 assertEquals(2, ROUTING_TABLE.size());
626 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())).portNumber);
627 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())).portNumber);
628 assertEquals(2, BRIDGING_TABLE.size());
629 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
630 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chanabfe7e02017-08-09 16:50:15 -0700631
632 // Move first host location to an invalid location
633 // Expect: One routing and one bridging flow
634 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host1));
Charles Chan6c624992017-08-18 17:11:34 -0700635 assertEquals(1, ROUTING_TABLE.size());
636 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())).portNumber);
637 assertEquals(1, BRIDGING_TABLE.size());
638 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chanabfe7e02017-08-09 16:50:15 -0700639
640 // Move second host location to an invalid location
641 // Expect: No routing or bridging rule
642 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host3, host2));
Charles Chan6c624992017-08-18 17:11:34 -0700643 assertEquals(0, ROUTING_TABLE.size());
644 assertEquals(0, BRIDGING_TABLE.size());
Charles Chanabfe7e02017-08-09 16:50:15 -0700645
646 // Move second host location back to a valid location
647 // Expect: One routing and one bridging flow
648 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host3));
Charles Chan6c624992017-08-18 17:11:34 -0700649 assertEquals(1, ROUTING_TABLE.size());
650 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())).portNumber);
651 assertEquals(1, BRIDGING_TABLE.size());
652 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chanabfe7e02017-08-09 16:50:15 -0700653
654 // Move first host location back to a valid location
655 // Expect: Two routing and two bridging flow
656 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host1, host2));
Charles Chan6c624992017-08-18 17:11:34 -0700657 assertEquals(2, ROUTING_TABLE.size());
658 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())).portNumber);
659 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())).portNumber);
660 assertEquals(2, BRIDGING_TABLE.size());
661 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
662 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chanabfe7e02017-08-09 16:50:15 -0700663 }
664
665 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700666 public void testDualHomingSingleLocationFail() {
Charles Chan3ed34d82017-06-22 18:03:14 -0700667 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
668 Sets.newHashSet(HOST_LOC31, HOST_LOC41), Sets.newHashSet(HOST_IP11, HOST_IP12), false);
669 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
670 Sets.newHashSet(HOST_LOC31), Sets.newHashSet(HOST_IP11, HOST_IP12), false);
671
672 // Add a host
673 // Expect: add four new routing rules, two new bridging rules
674 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
Charles Chan6c624992017-08-18 17:11:34 -0700675 assertEquals(4, ROUTING_TABLE.size());
676 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP11.toIpPrefix())).portNumber);
677 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP12.toIpPrefix())).portNumber);
678 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
679 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP12.toIpPrefix())).portNumber);
680 assertEquals(2, BRIDGING_TABLE.size());
681 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
682 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chan3ed34d82017-06-22 18:03:14 -0700683
684 // Host becomes single-homed
685 // Expect: redirect flows from host location to pair link
686 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host1));
Charles Chan6c624992017-08-18 17:11:34 -0700687 assertEquals(4, ROUTING_TABLE.size());
688 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP11.toIpPrefix())).portNumber);
689 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP12.toIpPrefix())).portNumber);
690 assertEquals(P9, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
691 assertEquals(P9, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP12.toIpPrefix())).portNumber);
692 assertEquals(2, BRIDGING_TABLE.size());
693 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
694 assertEquals(P9, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chan3ed34d82017-06-22 18:03:14 -0700695
696 // Host becomes dual-homed again
697 // Expect: Redirect flows from pair link back to host location
698 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host1, host2));
Charles Chan6c624992017-08-18 17:11:34 -0700699 assertEquals(4, ROUTING_TABLE.size());
700 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP11.toIpPrefix())).portNumber);
701 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP12.toIpPrefix())).portNumber);
Charles Chan873661e2017-11-30 15:37:50 -0800702 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
703 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP12.toIpPrefix())).portNumber);
Charles Chanfbcb8812018-04-18 18:41:05 -0700704 assertEquals(2, BRIDGING_TABLE.size());
705 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chan6c624992017-08-18 17:11:34 -0700706 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chan3ed34d82017-06-22 18:03:14 -0700707 }
708
709 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700710 public void testDualHomingBothLocationFail() {
Charles Chan3ed34d82017-06-22 18:03:14 -0700711 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
712 Sets.newHashSet(HOST_LOC31, HOST_LOC41), Sets.newHashSet(HOST_IP11, HOST_IP12), false);
713 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
714 Sets.newHashSet(HOST_LOC31), Sets.newHashSet(HOST_IP11, HOST_IP12), false);
715
716 // Add a host
717 // Expect: add four new routing rules, two new bridging rules
718 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
Charles Chan6c624992017-08-18 17:11:34 -0700719 assertEquals(4, ROUTING_TABLE.size());
720 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP11.toIpPrefix())).portNumber);
721 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP12.toIpPrefix())).portNumber);
722 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
723 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP12.toIpPrefix())).portNumber);
724 assertEquals(2, BRIDGING_TABLE.size());
725 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
726 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chan3ed34d82017-06-22 18:03:14 -0700727
728 // Host becomes single-homed
729 // Expect: redirect flows from host location to pair link
730 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host1));
Charles Chan6c624992017-08-18 17:11:34 -0700731 assertEquals(4, ROUTING_TABLE.size());
732 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP11.toIpPrefix())).portNumber);
733 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP12.toIpPrefix())).portNumber);
734 assertEquals(P9, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
735 assertEquals(P9, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP12.toIpPrefix())).portNumber);
736 assertEquals(2, BRIDGING_TABLE.size());
737 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
738 assertEquals(P9, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chan3ed34d82017-06-22 18:03:14 -0700739
740 // Host loses both locations
741 // Expect: Remove last location and all previous redirection flows
742 hostHandler.processHostRemovedEvent(new HostEvent(HostEvent.Type.HOST_REMOVED, host2));
Charles Chan6c624992017-08-18 17:11:34 -0700743 assertEquals(0, ROUTING_TABLE.size());
744 assertEquals(0, BRIDGING_TABLE.size());
Charles Chan3ed34d82017-06-22 18:03:14 -0700745 }
746
747 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700748 public void testHostUpdated() {
Charles Chan114aec72017-06-19 14:00:53 -0700749 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
Charles Chand9265a32017-06-16 15:19:24 -0700750 Sets.newHashSet(HOST_LOC11), Sets.newHashSet(HOST_IP11), false);
Charles Chan114aec72017-06-19 14:00:53 -0700751 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
Charles Chand9265a32017-06-16 15:19:24 -0700752 Sets.newHashSet(HOST_LOC11), Sets.newHashSet(HOST_IP21), false);
Charles Chan114aec72017-06-19 14:00:53 -0700753 Host host3 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
Charles Chand9265a32017-06-16 15:19:24 -0700754 Sets.newHashSet(HOST_LOC11), Sets.newHashSet(HOST_IP12), false);
Charles Chan114aec72017-06-19 14:00:53 -0700755
756 // Add a host
Charles Chand9265a32017-06-16 15:19:24 -0700757 // Expect: add one new routing rule. Add one new bridging rule.
Charles Chan114aec72017-06-19 14:00:53 -0700758 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
Charles Chan6c624992017-08-18 17:11:34 -0700759 assertEquals(1, ROUTING_TABLE.size());
760 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
761 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP21.toIpPrefix())));
762 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP12.toIpPrefix())));
763 assertEquals(1, BRIDGING_TABLE.size());
764 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(HOST_LOC11.deviceId(), HOST_MAC,
765 INTF_VLAN_UNTAGGED)));
Charles Chan114aec72017-06-19 14:00:53 -0700766
767 // Update the host IP to same subnet
768 // Expect: update routing rule with new IP. No change to bridging rule.
769 hostHandler.processHostUpdatedEvent(new HostEvent(HostEvent.Type.HOST_UPDATED, host3, host1));
Charles Chan6c624992017-08-18 17:11:34 -0700770 assertEquals(1, ROUTING_TABLE.size());
771 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
772 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP21.toIpPrefix())));
773 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP12.toIpPrefix())));
774 assertEquals(1, BRIDGING_TABLE.size());
775 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chan114aec72017-06-19 14:00:53 -0700776
777 // Update the host IP to different subnet
778 // Expect: Remove routing rule. No change to bridging rule.
779 hostHandler.processHostUpdatedEvent(new HostEvent(HostEvent.Type.HOST_UPDATED, host2, host3));
Charles Chan6c624992017-08-18 17:11:34 -0700780 assertEquals(0, ROUTING_TABLE.size());
781 assertEquals(1, BRIDGING_TABLE.size());
782 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chand9265a32017-06-16 15:19:24 -0700783 }
784
785 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700786 public void testDelayedIpAndLocation() {
Charles Chanb3c1faf2017-11-20 08:46:24 -0800787 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
788 Sets.newHashSet(HOST_LOC31), Sets.newHashSet(), false);
789 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
790 Sets.newHashSet(HOST_LOC31), Sets.newHashSet(HOST_IP11), false);
791 Host host3 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
792 Sets.newHashSet(HOST_LOC31, HOST_LOC41), Sets.newHashSet(HOST_IP11), false);
793
794 // Add a dual-home host with only one location and no IP
795 // Expect: only bridging redirection works
796 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
797 assertEquals(0, ROUTING_TABLE.size());
798 assertEquals(2, BRIDGING_TABLE.size());
799 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
800 assertEquals(P9, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
801
802 // Discover IP
803 // Expect: routing redirection should also work
Charles Chan873661e2017-11-30 15:37:50 -0800804 hostHandler.processHostUpdatedEvent(new HostEvent(HostEvent.Type.HOST_UPDATED, host2, host1));
Charles Chanb3c1faf2017-11-20 08:46:24 -0800805 assertEquals(2, ROUTING_TABLE.size());
806 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP11.toIpPrefix())).portNumber);
807 assertEquals(P9, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
808 assertEquals(2, BRIDGING_TABLE.size());
809 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
810 assertEquals(P9, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chan873661e2017-11-30 15:37:50 -0800811 // Expect probe to be sent out on pair device
Charles Chanc6bcdf92018-06-01 16:33:48 -0700812 assertTrue(mockLocationProbingService.verifyProbe(host2, CP41, ProbeMode.DISCOVER));
Charles Chanb3c1faf2017-11-20 08:46:24 -0800813
814 // Discover location
815 // Expect: cancel all redirections
Charles Chan873661e2017-11-30 15:37:50 -0800816 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host3, host2));
Charles Chanb3c1faf2017-11-20 08:46:24 -0800817 assertEquals(2, ROUTING_TABLE.size());
818 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP11.toIpPrefix())).portNumber);
Charles Chanfbcb8812018-04-18 18:41:05 -0700819 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
Charles Chanb3c1faf2017-11-20 08:46:24 -0800820 assertEquals(2, BRIDGING_TABLE.size());
821 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chanfbcb8812018-04-18 18:41:05 -0700822 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chan873661e2017-11-30 15:37:50 -0800823 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
Charles Chanb3c1faf2017-11-20 08:46:24 -0800824 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
825 }
826
827 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700828 public void testDelayedIpAndLocation2() {
Charles Chanb3c1faf2017-11-20 08:46:24 -0800829 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
830 Sets.newHashSet(HOST_LOC31), Sets.newHashSet(), false);
831 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
832 Sets.newHashSet(HOST_LOC31, HOST_LOC41), Sets.newHashSet(), false);
833 Host host3 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
834 Sets.newHashSet(HOST_LOC31, HOST_LOC41), Sets.newHashSet(HOST_IP11), false);
835
836 // Add a dual-home host with only one location and no IP
837 // Expect: only bridging redirection works
838 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
839 assertEquals(0, ROUTING_TABLE.size());
840 assertEquals(2, BRIDGING_TABLE.size());
841 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
842 assertEquals(P9, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
843
844 // Discover Location
845 // Expect: cancel bridging redirections
846 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host1));
847 assertEquals(0, ROUTING_TABLE.size());
848 assertEquals(2, BRIDGING_TABLE.size());
849 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
850 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
851
852 // Discover IP
853 // Expect: add IP rules to both location
854 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_UPDATED, host3, host2));
855 assertEquals(2, ROUTING_TABLE.size());
856 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP11.toIpPrefix())).portNumber);
857 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
858 assertEquals(2, BRIDGING_TABLE.size());
859 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
860 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
861 }
862
863 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700864 public void testDualHomedHostUpdated() {
Charles Chand9265a32017-06-16 15:19:24 -0700865 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
866 Sets.newHashSet(HOST_LOC11, HOST_LOC21), Sets.newHashSet(HOST_IP11, HOST_IP12), false);
867 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
868 Sets.newHashSet(HOST_LOC11, HOST_LOC21), Sets.newHashSet(HOST_IP11, HOST_IP21), false);
869 Host host3 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
870 Sets.newHashSet(HOST_LOC11, HOST_LOC21), Sets.newHashSet(HOST_IP13, HOST_IP14), false);
871
872 // Add a dual-homed host with two locations and two IPs
873 // Expect: add four new routing rules. Add two new bridging rules
874 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
Charles Chan6c624992017-08-18 17:11:34 -0700875 assertEquals(4, ROUTING_TABLE.size());
876 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
877 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP12.toIpPrefix())));
878 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())));
879 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP12.toIpPrefix())));
880 assertEquals(2, BRIDGING_TABLE.size());
881 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
882 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chand9265a32017-06-16 15:19:24 -0700883
884 // Update both host IPs
885 // Expect: update routing rules with new IP. No change to bridging rule.
886 hostHandler.processHostUpdatedEvent(new HostEvent(HostEvent.Type.HOST_UPDATED, host3, host1));
Charles Chan6c624992017-08-18 17:11:34 -0700887 assertEquals(4, ROUTING_TABLE.size());
888 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
889 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP12.toIpPrefix())));
890 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP13.toIpPrefix())));
891 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP14.toIpPrefix())));
892 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())));
893 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP12.toIpPrefix())));
894 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP13.toIpPrefix())));
895 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP14.toIpPrefix())));
896 assertEquals(2, BRIDGING_TABLE.size());
897 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
898 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chand9265a32017-06-16 15:19:24 -0700899
900 // Update one of the host IP to different subnet
901 // Expect: update routing rule with new IP. No change to bridging rule.
902 hostHandler.processHostUpdatedEvent(new HostEvent(HostEvent.Type.HOST_UPDATED, host2, host3));
Charles Chan6c624992017-08-18 17:11:34 -0700903 assertEquals(2, ROUTING_TABLE.size());
904 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
905 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP21.toIpPrefix())));
906 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP12.toIpPrefix())));
907 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())));
908 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP21.toIpPrefix())));
909 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP12.toIpPrefix())));
910 assertEquals(2, BRIDGING_TABLE.size());
911 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
912 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chand9265a32017-06-16 15:19:24 -0700913 }
Charles Chan868c9572018-06-15 18:54:18 -0700914
915 @Test
916 public void testVlanForPairPort() {
917 assertEquals(INTF_VLAN_UNTAGGED, hostHandler.vlanForPairPort(VlanId.NONE, CP11));
918 assertEquals(INTF_VLAN_NATIVE, hostHandler.vlanForPairPort(VlanId.NONE, CP13));
919 assertEquals(INTF_VLAN_TAGGED_1, hostHandler.vlanForPairPort(INTF_VLAN_TAGGED_1, CP13));
920 assertNull(hostHandler.vlanForPairPort(INTF_VLAN_UNTAGGED, CP11));
921 assertNull(hostHandler.vlanForPairPort(INTF_VLAN_UNTAGGED, CP13));
922 assertNull(hostHandler.vlanForPairPort(VlanId.NONE, CP51));
923 assertNull(hostHandler.vlanForPairPort(INTF_VLAN_UNTAGGED, CP51));
924 }
Charles Chanbd84dd52018-06-21 19:07:12 -0700925
926 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700927 public void testHostRemovedWithRouteRemoved() {
Charles Chanbd84dd52018-06-21 19:07:12 -0700928 Host subject = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
929 Sets.newHashSet(HOST_LOC11), Sets.newHashSet(HOST_IP11), false);
930
931 // Add a host
932 // Expect: add one routing rule and one bridging rule
933 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, subject));
934 assertEquals(1, ROUTING_TABLE.size());
935 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
936 assertEquals(1, BRIDGING_TABLE.size());
937 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
938
939 IpPrefix prefix = IpPrefix.valueOf("55.55.55.0/24");
940
941 // Setting up mock route service
942 RouteService routeService = hostHandler.srManager.routeService;
943 reset(routeService);
944
945 IpAddress nextHopIp2 = IpAddress.valueOf("20.0.0.1");
946 MacAddress nextHopMac2 = MacAddress.valueOf("00:22:33:44:55:66");
947 VlanId nextHopVlan2 = VlanId.NONE;
948
949 Route r1 = new Route(Route.Source.STATIC, prefix, HOST_IP11);
950 ResolvedRoute rr1 = new ResolvedRoute(r1, HOST_MAC, VlanId.NONE);
951 Route r2 = new Route(Route.Source.STATIC, prefix, nextHopIp2);
952 ResolvedRoute rr2 = new ResolvedRoute(r2, nextHopMac2, nextHopVlan2);
953 RouteInfo routeInfo = new RouteInfo(prefix, rr1, Sets.newHashSet(rr1, rr2));
954 RouteTableId routeTableId = new RouteTableId("ipv4");
955
956 expect(routeService.getRouteTables()).andReturn(Sets.newHashSet(routeTableId));
957 expect(routeService.getRoutes(routeTableId)).andReturn(Sets.newHashSet(routeInfo));
958 replay(routeService);
959
960 // Setting up mock device configuration
961 hostHandler.srManager.deviceConfiguration = EasyMock.createNiceMock(DeviceConfiguration.class);
962 DeviceConfiguration deviceConfiguration = hostHandler.srManager.deviceConfiguration;
963 expect(deviceConfiguration.inSameSubnet(CP11, HOST_IP11)).andReturn(true);
964 deviceConfiguration.removeSubnet(CP11, prefix);
965 expectLastCall();
966 replay(deviceConfiguration);
967
968 // Remove the host
969 // Expect: add the routing rule and the bridging rule
970 hostHandler.processHostRemovedEvent(new HostEvent(HostEvent.Type.HOST_REMOVED, subject));
971 assertEquals(0, ROUTING_TABLE.size());
972 assertEquals(0, BRIDGING_TABLE.size());
973
974 // Expect: subnet is removed from device config
975 verify(deviceConfiguration);
976 }
Charles Chan6e90fbb2018-07-23 15:27:34 -0700977
978 @Test
979 public void testHostProbing() {
980 // Case: [1A/1, 1B/1] -> [1A/2, 1B/1]
981 // Expect: DISCOVER probe should be sent to every port on 1B that has the same VLAN as 1A/2
982 // VERIFY probe should be sent to 1B/1
983 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
984 Sets.newHashSet(HOST_LOC31, HOST_LOC41), Sets.newHashSet(HOST_IP11), false);
985 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
986 Sets.newHashSet(HOST_LOC32, HOST_LOC41), Sets.newHashSet(HOST_IP11), false);
987 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
988
989 hostHandler.srManager.probingService = createMock(HostProbingService.class);
990 hostHandler.srManager.probingService.probeHost(host2, CP41, ProbeMode.DISCOVER);
991 expectLastCall();
992 hostHandler.srManager.probingService.probeHost(host2, CP42, ProbeMode.DISCOVER);
993 expectLastCall();
994 hostHandler.srManager.probingService.probeHost(host2, CP41, ProbeMode.VERIFY);
995 expectLastCall();
996 replay(hostHandler.srManager.probingService);
997
998 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host1));
999
1000 verify(hostHandler.srManager.probingService);
1001 }
Charles Chana2ccb582019-11-25 09:47:22 -08001002
1003 @Test
1004 public void testEffectiveLocations() {
1005 Host regularHost = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_TAGGED,
1006 Sets.newHashSet(HOST_LOC11, HOST_LOC12), Sets.newHashSet(HOST_IP11), false);
1007 Host auxHost = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_TAGGED,
1008 Sets.newHashSet(HOST_LOC11, HOST_LOC12), Sets.newHashSet(HOST_LOC21, HOST_LOC22),
1009 Sets.newHashSet(HOST_IP11), VlanId.NONE, EthType.EtherType.UNKNOWN.ethType(), false, false);
1010
1011 assertEquals(Sets.newHashSet(HOST_LOC11, HOST_LOC12), hostHandler.effectiveLocations(regularHost));
1012 assertEquals(Sets.newHashSet(HOST_LOC21, HOST_LOC22), hostHandler.effectiveLocations(auxHost));
1013 }
Ray Milkeyc2d43be2017-08-03 11:58:29 -07001014}