blob: e9cde673c97257b382cb07a0cd1935b958fe6176 [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 Chan3ed34d82017-06-22 18:03:14 -070054import org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig;
Charles Chand66d6712018-03-29 16:03:41 -070055import org.onosproject.store.service.StorageService;
56import org.onosproject.store.service.TestConsistentMap;
pierf331a492020-01-07 15:39:39 +010057import org.onosproject.store.service.TestConsistentMultimap;
Charles Chan114aec72017-06-19 14:00:53 -070058
59import java.util.Map;
Charles Chan114aec72017-06-19 14:00:53 -070060import java.util.Set;
Charles Chan12a8a842020-02-14 13:23:57 -080061import java.util.concurrent.CompletableFuture;
Charles Chan114aec72017-06-19 14:00:53 -070062
Charles Chand66d6712018-03-29 16:03:41 -070063import static org.easymock.EasyMock.createMock;
Charles Chanbd84dd52018-06-21 19:07:12 -070064import static org.easymock.EasyMock.createNiceMock;
Charles Chand66d6712018-03-29 16:03:41 -070065import static org.easymock.EasyMock.expect;
Charles Chanbd84dd52018-06-21 19:07:12 -070066import static org.easymock.EasyMock.expectLastCall;
Charles Chand66d6712018-03-29 16:03:41 -070067import static org.easymock.EasyMock.replay;
Charles Chanbd84dd52018-06-21 19:07:12 -070068import static org.easymock.EasyMock.reset;
69import static org.easymock.EasyMock.verify;
Charles Chan114aec72017-06-19 14:00:53 -070070import static org.junit.Assert.*;
piercf557922019-05-17 20:47:06 +020071import static org.onlab.util.Tools.groupedThreads;
Charles Chan114aec72017-06-19 14:00:53 -070072
piercf557922019-05-17 20:47:06 +020073/**
Charles Chan114aec72017-06-19 14:00:53 -070074 * Unit test for {@link HostHandler}.
75 */
76public class HostHandlerTest {
Charles Chan114aec72017-06-19 14:00:53 -070077 private HostHandler hostHandler;
78
79 // Mocked routing and bridging tables
Charles Chan6c624992017-08-18 17:11:34 -070080 private static final Map<MockBridgingTableKey, MockBridgingTableValue> BRIDGING_TABLE =
81 Maps.newConcurrentMap();
82 private static final Map<MockRoutingTableKey, MockRoutingTableValue> ROUTING_TABLE =
83 Maps.newConcurrentMap();
Charles Chan910be6a2017-08-23 14:46:43 -070084 private static final Map<ConnectPoint, Set<IpPrefix>> SUBNET_TABLE = Maps.newConcurrentMap();
Charles Chan114aec72017-06-19 14:00:53 -070085 // Mocked Next Id
Charles Chan6c624992017-08-18 17:11:34 -070086 private static final Map<Integer, TrafficTreatment> NEXT_TABLE = Maps.newConcurrentMap();
Charles Chan114aec72017-06-19 14:00:53 -070087
Charles Chand9265a32017-06-16 15:19:24 -070088 // Host Mac, VLAN
Charles Chan114aec72017-06-19 14:00:53 -070089 private static final ProviderId PROVIDER_ID = ProviderId.NONE;
90 private static final MacAddress HOST_MAC = MacAddress.valueOf("00:00:00:00:00:01");
91 private static final VlanId HOST_VLAN_UNTAGGED = VlanId.NONE;
92 private static final HostId HOST_ID_UNTAGGED = HostId.hostId(HOST_MAC, HOST_VLAN_UNTAGGED);
93 private static final VlanId HOST_VLAN_TAGGED = VlanId.vlanId((short) 20);
94 private static final HostId HOST_ID_TAGGED = HostId.hostId(HOST_MAC, HOST_VLAN_TAGGED);
Charles Chand9265a32017-06-16 15:19:24 -070095 // Host IP
96 private static final IpAddress HOST_IP11 = IpAddress.valueOf("10.0.1.1");
97 private static final IpAddress HOST_IP21 = IpAddress.valueOf("10.0.2.1");
98 private static final IpAddress HOST_IP12 = IpAddress.valueOf("10.0.1.2");
99 private static final IpAddress HOST_IP13 = IpAddress.valueOf("10.0.1.3");
100 private static final IpAddress HOST_IP14 = IpAddress.valueOf("10.0.1.4");
Charles Chan6e90fbb2018-07-23 15:27:34 -0700101 private static final IpAddress HOST_IP33 = IpAddress.valueOf("10.0.3.3");
Charles Chand9265a32017-06-16 15:19:24 -0700102 // Device
103 private static final DeviceId DEV1 = DeviceId.deviceId("of:0000000000000001");
104 private static final DeviceId DEV2 = DeviceId.deviceId("of:0000000000000002");
Charles Chanabfe7e02017-08-09 16:50:15 -0700105 private static final DeviceId DEV3 = DeviceId.deviceId("of:0000000000000003");
106 private static final DeviceId DEV4 = DeviceId.deviceId("of:0000000000000004");
107 private static final DeviceId DEV5 = DeviceId.deviceId("of:0000000000000005");
108 private static final DeviceId DEV6 = DeviceId.deviceId("of:0000000000000006");
Charles Chand9265a32017-06-16 15:19:24 -0700109 // Port
110 private static final PortNumber P1 = PortNumber.portNumber(1);
111 private static final PortNumber P2 = PortNumber.portNumber(2);
112 private static final PortNumber P3 = PortNumber.portNumber(3);
Charles Chan3ed34d82017-06-22 18:03:14 -0700113 private static final PortNumber P9 = PortNumber.portNumber(9);
Charles Chand9265a32017-06-16 15:19:24 -0700114 // Connect Point
115 private static final ConnectPoint CP11 = new ConnectPoint(DEV1, P1);
116 private static final HostLocation HOST_LOC11 = new HostLocation(CP11, 0);
117 private static final ConnectPoint CP12 = new ConnectPoint(DEV1, P2);
118 private static final HostLocation HOST_LOC12 = new HostLocation(CP12, 0);
119 private static final ConnectPoint CP13 = new ConnectPoint(DEV1, P3);
120 private static final HostLocation HOST_LOC13 = new HostLocation(CP13, 0);
121 private static final ConnectPoint CP21 = new ConnectPoint(DEV2, P1);
122 private static final HostLocation HOST_LOC21 = new HostLocation(CP21, 0);
123 private static final ConnectPoint CP22 = new ConnectPoint(DEV2, P2);
124 private static final HostLocation HOST_LOC22 = new HostLocation(CP22, 0);
Charles Chan3ed34d82017-06-22 18:03:14 -0700125 // Connect Point for dual-homed host failover
126 private static final ConnectPoint CP31 = new ConnectPoint(DEV3, P1);
127 private static final HostLocation HOST_LOC31 = new HostLocation(CP31, 0);
Charles Chanceb2a2e2017-09-12 18:57:47 -0700128 private static final ConnectPoint CP32 = new ConnectPoint(DEV3, P2);
129 private static final HostLocation HOST_LOC32 = new HostLocation(CP32, 0);
Charles Chan6e90fbb2018-07-23 15:27:34 -0700130 private static final ConnectPoint CP33 = new ConnectPoint(DEV3, P3);
131 private static final HostLocation HOST_LOC33 = new HostLocation(CP33, 0);
Charles Chan3ed34d82017-06-22 18:03:14 -0700132 private static final ConnectPoint CP41 = new ConnectPoint(DEV4, P1);
133 private static final HostLocation HOST_LOC41 = new HostLocation(CP41, 0);
Charles Chan6e90fbb2018-07-23 15:27:34 -0700134 private static final ConnectPoint CP42 = new ConnectPoint(DEV4, P2);
135 private static final HostLocation HOST_LOC42 = new HostLocation(CP42, 0);
Charles Chan3ed34d82017-06-22 18:03:14 -0700136 private static final ConnectPoint CP39 = new ConnectPoint(DEV3, P9);
137 private static final ConnectPoint CP49 = new ConnectPoint(DEV4, P9);
Charles Chanabfe7e02017-08-09 16:50:15 -0700138 // Conenct Point for mastership test
139 private static final ConnectPoint CP51 = new ConnectPoint(DEV5, P1);
140 private static final HostLocation HOST_LOC51 = new HostLocation(CP51, 0);
141 private static final ConnectPoint CP61 = new ConnectPoint(DEV6, P1);
142 private static final HostLocation HOST_LOC61 = new HostLocation(CP61, 0);
Charles Chand9265a32017-06-16 15:19:24 -0700143 // Interface VLAN
Charles Chan114aec72017-06-19 14:00:53 -0700144 private static final VlanId INTF_VLAN_UNTAGGED = VlanId.vlanId((short) 10);
Charles Chan868c9572018-06-15 18:54:18 -0700145 private static final VlanId INTF_VLAN_TAGGED_1 = VlanId.vlanId((short) 20);
146 private static final Set<VlanId> INTF_VLAN_TAGGED = Sets.newHashSet(INTF_VLAN_TAGGED_1);
Charles Chan114aec72017-06-19 14:00:53 -0700147 private static final VlanId INTF_VLAN_NATIVE = VlanId.vlanId((short) 30);
Charles Chan3ed34d82017-06-22 18:03:14 -0700148 private static final Set<VlanId> INTF_VLAN_PAIR = Sets.newHashSet(VlanId.vlanId((short) 10),
149 VlanId.vlanId((short) 20), VlanId.vlanId((short) 30));
Charles Chanceb2a2e2017-09-12 18:57:47 -0700150 private static final VlanId INTF_VLAN_OTHER = VlanId.vlanId((short) 40);
Charles Chand9265a32017-06-16 15:19:24 -0700151 // Interface subnet
152 private static final IpPrefix INTF_PREFIX1 = IpPrefix.valueOf("10.0.1.254/24");
153 private static final IpPrefix INTF_PREFIX2 = IpPrefix.valueOf("10.0.2.254/24");
Charles Chanceb2a2e2017-09-12 18:57:47 -0700154 private static final IpPrefix INTF_PREFIX3 = IpPrefix.valueOf("10.0.3.254/24");
Charles Chand9265a32017-06-16 15:19:24 -0700155 private static final InterfaceIpAddress INTF_IP1 =
156 new InterfaceIpAddress(INTF_PREFIX1.address(), INTF_PREFIX1);
157 private static final InterfaceIpAddress INTF_IP2 =
158 new InterfaceIpAddress(INTF_PREFIX2.address(), INTF_PREFIX2);
Charles Chanceb2a2e2017-09-12 18:57:47 -0700159 private static final InterfaceIpAddress INTF_IP3 =
160 new InterfaceIpAddress(INTF_PREFIX3.address(), INTF_PREFIX3);
Charles Chan6c624992017-08-18 17:11:34 -0700161 // Interfaces
162 private static final Interface INTF11 =
163 new Interface(null, CP11, Lists.newArrayList(INTF_IP1), MacAddress.NONE, null,
164 INTF_VLAN_UNTAGGED, null, null);
165 private static final Interface INTF12 =
166 new Interface(null, CP12, Lists.newArrayList(INTF_IP1), MacAddress.NONE, null,
167 INTF_VLAN_UNTAGGED, null, null);
168 private static final Interface INTF13 =
169 new Interface(null, CP13, Lists.newArrayList(INTF_IP2), MacAddress.NONE, null,
170 null, INTF_VLAN_TAGGED, INTF_VLAN_NATIVE);
171 private static final Interface INTF21 =
172 new Interface(null, CP21, Lists.newArrayList(INTF_IP1), MacAddress.NONE, null,
173 INTF_VLAN_UNTAGGED, null, null);
174 private static final Interface INTF22 =
175 new Interface(null, CP22, Lists.newArrayList(INTF_IP1), MacAddress.NONE, null,
176 INTF_VLAN_UNTAGGED, null, null);
177 private static final Interface INTF31 =
178 new Interface(null, CP31, Lists.newArrayList(INTF_IP1), MacAddress.NONE, null,
179 INTF_VLAN_UNTAGGED, null, null);
Charles Chanceb2a2e2017-09-12 18:57:47 -0700180 private static final Interface INTF32 =
Charles Chan6e90fbb2018-07-23 15:27:34 -0700181 new Interface(null, CP32, Lists.newArrayList(INTF_IP1), MacAddress.NONE, null,
182 INTF_VLAN_UNTAGGED, null, null);
183 private static final Interface INTF33 =
184 new Interface(null, CP33, Lists.newArrayList(INTF_IP3), MacAddress.NONE, null,
Charles Chanceb2a2e2017-09-12 18:57:47 -0700185 INTF_VLAN_OTHER, null, null);
Charles Chan6c624992017-08-18 17:11:34 -0700186 private static final Interface INTF39 =
187 new Interface(null, CP39, Lists.newArrayList(INTF_IP1), MacAddress.NONE, null,
188 null, INTF_VLAN_PAIR, null);
189 private static final Interface INTF41 =
190 new Interface(null, CP41, Lists.newArrayList(INTF_IP1), MacAddress.NONE, null,
191 INTF_VLAN_UNTAGGED, null, null);
Charles Chan6e90fbb2018-07-23 15:27:34 -0700192 private static final Interface INTF42 =
193 new Interface(null, CP42, Lists.newArrayList(INTF_IP1), MacAddress.NONE, null,
194 INTF_VLAN_UNTAGGED, null, null);
Charles Chan6c624992017-08-18 17:11:34 -0700195 private static final Interface INTF49 =
196 new Interface(null, CP49, Lists.newArrayList(INTF_IP1), MacAddress.NONE, null,
197 null, INTF_VLAN_PAIR, null);
Charles Chand9265a32017-06-16 15:19:24 -0700198 // Host
199 private static final Host HOST1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC,
200 HOST_VLAN_UNTAGGED, Sets.newHashSet(HOST_LOC11, HOST_LOC21), Sets.newHashSet(HOST_IP11),
201 false);
Charles Chan114aec72017-06-19 14:00:53 -0700202
Charles Chan6c624992017-08-18 17:11:34 -0700203 // A set of hosts
204 private static final Set<Host> HOSTS = Sets.newHashSet(HOST1);
205 // A set of devices of which we have mastership
206 private static final Set<DeviceId> LOCAL_DEVICES = Sets.newHashSet(DEV1, DEV2, DEV3, DEV4);
207 // A set of interfaces
208 private static final Set<Interface> INTERFACES = Sets.newHashSet(INTF11, INTF12, INTF13, INTF21,
Charles Chan6e90fbb2018-07-23 15:27:34 -0700209 INTF22, INTF31, INTF32, INTF33, INTF39, INTF41, INTF42, INTF49);
Charles Chan6c624992017-08-18 17:11:34 -0700210
Charles Chanc6bcdf92018-06-01 16:33:48 -0700211 private MockHostProbingService mockLocationProbingService;
Charles Chan873661e2017-11-30 15:37:50 -0800212
Charles Chan114aec72017-06-19 14:00:53 -0700213 @Before
Charles Chan6e90fbb2018-07-23 15:27:34 -0700214 public void setUp() {
Charles Chan6c624992017-08-18 17:11:34 -0700215 // Initialize pairDevice and pairLocalPort config
216 ObjectMapper mapper = new ObjectMapper();
217 ConfigApplyDelegate delegate = config -> { };
218
219 SegmentRoutingDeviceConfig dev3Config = new SegmentRoutingDeviceConfig();
220 JsonNode dev3Tree = mapper.createObjectNode();
221 dev3Config.init(DEV3, "host-handler-test", dev3Tree, mapper, delegate);
222 dev3Config.setPairDeviceId(DEV4).setPairLocalPort(P9);
223
224 SegmentRoutingDeviceConfig dev4Config = new SegmentRoutingDeviceConfig();
225 JsonNode dev4Tree = mapper.createObjectNode();
226 dev4Config.init(DEV4, "host-handler-test", dev4Tree, mapper, delegate);
227 dev4Config.setPairDeviceId(DEV3).setPairLocalPort(P9);
228
229 MockNetworkConfigRegistry mockNetworkConfigRegistry = new MockNetworkConfigRegistry();
230 mockNetworkConfigRegistry.applyConfig(dev3Config);
231 mockNetworkConfigRegistry.applyConfig(dev4Config);
232
233 // Initialize Segment Routing Manager
Charles Chanfab61472021-06-14 23:31:23 -0700234 SegmentRoutingManager srManager = new MockSegmentRoutingManager(NEXT_TABLE, Maps.newHashMap());
Charles Chand66d6712018-03-29 16:03:41 -0700235 srManager.storageService = createMock(StorageService.class);
236 expect(srManager.storageService.consistentMapBuilder()).andReturn(new TestConsistentMap.Builder<>()).anyTimes();
pierf331a492020-01-07 15:39:39 +0100237 expect(srManager.storageService.consistentMultimapBuilder()).andReturn(
238 new TestConsistentMultimap.Builder<>()).anyTimes();
Charles Chand66d6712018-03-29 16:03:41 -0700239 replay(srManager.storageService);
Charles Chan114aec72017-06-19 14:00:53 -0700240 srManager.cfgService = new NetworkConfigRegistryAdapter();
241 srManager.deviceConfiguration = new DeviceConfiguration(srManager);
Charles Chan6c624992017-08-18 17:11:34 -0700242 srManager.flowObjectiveService = new MockFlowObjectiveService(BRIDGING_TABLE, NEXT_TABLE);
243 srManager.routingRulePopulator = new MockRoutingRulePopulator(srManager, ROUTING_TABLE);
Charles Chanc4d68882018-03-15 16:41:10 -0700244 srManager.defaultRoutingHandler = new MockDefaultRoutingHandler(srManager, SUBNET_TABLE, ROUTING_TABLE);
Charles Chan6c624992017-08-18 17:11:34 -0700245 srManager.interfaceService = new MockInterfaceService(INTERFACES);
246 srManager.mastershipService = new MockMastershipService(LOCAL_DEVICES);
247 srManager.hostService = new MockHostService(HOSTS);
248 srManager.cfgService = mockNetworkConfigRegistry;
Charles Chanc6bcdf92018-06-01 16:33:48 -0700249 mockLocationProbingService = new MockHostProbingService();
Charles Chan873661e2017-11-30 15:37:50 -0800250 srManager.probingService = mockLocationProbingService;
Saurav Dase6c448a2018-01-18 12:07:33 -0800251 srManager.linkHandler = new MockLinkHandler(srManager);
Charles Chan114aec72017-06-19 14:00:53 -0700252
Charles Chanbd84dd52018-06-21 19:07:12 -0700253 // Not important for most of the HostHandler test case. Simply return an empty set here
254 srManager.routeService = createNiceMock(RouteService.class);
255 expect(srManager.routeService.getRouteTables()).andReturn(Sets.newHashSet()).anyTimes();
256 replay(srManager.routeService);
257
Charles Chan114aec72017-06-19 14:00:53 -0700258 hostHandler = new HostHandler(srManager);
piercf557922019-05-17 20:47:06 +0200259 hostHandler.hostWorkers = new PredictableExecutor(
260 0, groupedThreads("onos/sr", "h-worker-%d"), true);
Charles Chan114aec72017-06-19 14:00:53 -0700261
Charles Chan6c624992017-08-18 17:11:34 -0700262 ROUTING_TABLE.clear();
263 BRIDGING_TABLE.clear();
Charles Chan114aec72017-06-19 14:00:53 -0700264 }
265
266 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700267 public void init() {
Charles Chand9265a32017-06-16 15:19:24 -0700268 hostHandler.init(DEV1);
Charles Chan6c624992017-08-18 17:11:34 -0700269 assertEquals(1, ROUTING_TABLE.size());
270 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
271 assertEquals(1, BRIDGING_TABLE.size());
272 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chand9265a32017-06-16 15:19:24 -0700273
274 hostHandler.init(DEV2);
Charles Chan6c624992017-08-18 17:11:34 -0700275 assertEquals(2, ROUTING_TABLE.size());
276 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
277 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())));
278 assertEquals(2, BRIDGING_TABLE.size());
279 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
280 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chand9265a32017-06-16 15:19:24 -0700281 }
282
283 @Test(expected = IllegalArgumentException.class)
Charles Chan6e90fbb2018-07-23 15:27:34 -0700284 public void testHostAddedAtWrongLocation() {
Charles Chand9265a32017-06-16 15:19:24 -0700285 hostHandler.processHostAddedAtLocation(HOST1, HOST_LOC13);
286 }
287
288
289 @Test()
Charles Chan6e90fbb2018-07-23 15:27:34 -0700290 public void testHostAddedAtCorrectLocation() {
Charles Chand9265a32017-06-16 15:19:24 -0700291 hostHandler.processHostAddedAtLocation(HOST1, HOST_LOC11);
Charles Chan6c624992017-08-18 17:11:34 -0700292 assertEquals(1, ROUTING_TABLE.size());
293 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
294 assertEquals(1, BRIDGING_TABLE.size());
295 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chan114aec72017-06-19 14:00:53 -0700296 }
297
298 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700299 public void testHostAdded() {
Charles Chan114aec72017-06-19 14:00:53 -0700300 Host subject;
301
302 // Untagged host discovered on untagged port
303 // Expect: add one routing rule and one bridging rule
304 subject = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
Charles Chand9265a32017-06-16 15:19:24 -0700305 Sets.newHashSet(HOST_LOC11), Sets.newHashSet(HOST_IP11), false);
Charles Chan114aec72017-06-19 14:00:53 -0700306 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, subject));
Charles Chan6c624992017-08-18 17:11:34 -0700307 assertEquals(1, ROUTING_TABLE.size());
308 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
309 assertEquals(1, BRIDGING_TABLE.size());
310 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chan114aec72017-06-19 14:00:53 -0700311
312 // Untagged host discovered on tagged/native port
313 // Expect: add one routing rule and one bridging rule
314 subject = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
Charles Chand9265a32017-06-16 15:19:24 -0700315 Sets.newHashSet(HOST_LOC13), Sets.newHashSet(HOST_IP21), false);
Charles Chan114aec72017-06-19 14:00:53 -0700316 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, subject));
Charles Chan6c624992017-08-18 17:11:34 -0700317 assertEquals(2, ROUTING_TABLE.size());
318 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP21.toIpPrefix())));
319 assertEquals(2, BRIDGING_TABLE.size());
320 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_NATIVE)));
Charles Chan114aec72017-06-19 14:00:53 -0700321
322 // Tagged host discovered on untagged port
323 // Expect: ignore the host. No rule is added.
324 subject = new DefaultHost(PROVIDER_ID, HOST_ID_TAGGED, HOST_MAC, HOST_VLAN_TAGGED,
Charles Chand9265a32017-06-16 15:19:24 -0700325 Sets.newHashSet(HOST_LOC11), Sets.newHashSet(HOST_IP11), false);
Charles Chan114aec72017-06-19 14:00:53 -0700326 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, subject));
Charles Chan6c624992017-08-18 17:11:34 -0700327 assertEquals(2, ROUTING_TABLE.size());
328 assertEquals(2, BRIDGING_TABLE.size());
Charles Chan114aec72017-06-19 14:00:53 -0700329
330 // Tagged host discovered on tagged port with the same IP
331 // Expect: update existing route, add one bridging rule
332 subject = new DefaultHost(PROVIDER_ID, HOST_ID_TAGGED, HOST_MAC, HOST_VLAN_TAGGED,
Charles Chand9265a32017-06-16 15:19:24 -0700333 Sets.newHashSet(HOST_LOC13), Sets.newHashSet(HOST_IP21), false);
Charles Chan114aec72017-06-19 14:00:53 -0700334 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, subject));
Charles Chan6c624992017-08-18 17:11:34 -0700335 assertEquals(2, ROUTING_TABLE.size());
336 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP21.toIpPrefix())));
337 assertEquals(HOST_VLAN_TAGGED, ROUTING_TABLE.get(new MockRoutingTableKey(HOST_LOC13.deviceId(),
Charles Chand9265a32017-06-16 15:19:24 -0700338 HOST_IP21.toIpPrefix())).vlanId);
Charles Chan6c624992017-08-18 17:11:34 -0700339 assertEquals(3, BRIDGING_TABLE.size());
340 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, HOST_VLAN_TAGGED)));
Charles Chand9265a32017-06-16 15:19:24 -0700341 }
342
343 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700344 public void testDualHomedHostAdded() {
Charles Chand9265a32017-06-16 15:19:24 -0700345 // Add a dual-homed host that has 2 locations
346 // Expect: add two routing rules and two bridging rules
347 Host subject = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
348 Sets.newHashSet(HOST_LOC11, HOST_LOC21), Sets.newHashSet(HOST_IP11), false);
349 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, subject));
Charles Chan6c624992017-08-18 17:11:34 -0700350 assertEquals(2, ROUTING_TABLE.size());
351 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
352 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())));
353 assertEquals(2, BRIDGING_TABLE.size());
354 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
355 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chan114aec72017-06-19 14:00:53 -0700356 }
357
358 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700359 public void testSingleHomedHostAddedOnPairLeaf() {
Charles Chanceb2a2e2017-09-12 18:57:47 -0700360 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
Charles Chan6e90fbb2018-07-23 15:27:34 -0700361 Sets.newHashSet(HOST_LOC33), Sets.newHashSet(HOST_IP33), false);
Charles Chanceb2a2e2017-09-12 18:57:47 -0700362
363 // Add a single-homed host with one location
364 // Expect: the pair link should not be utilized
365 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
366 assertEquals(1, ROUTING_TABLE.size());
Charles Chan6e90fbb2018-07-23 15:27:34 -0700367 assertEquals(P3, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP33.toIpPrefix())).portNumber);
Charles Chanceb2a2e2017-09-12 18:57:47 -0700368 assertEquals(1, BRIDGING_TABLE.size());
Charles Chan6e90fbb2018-07-23 15:27:34 -0700369 assertEquals(P3, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_OTHER)).portNumber);
Charles Chanceb2a2e2017-09-12 18:57:47 -0700370 }
371
372 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700373 public void testDualHomedHostAddedOneByOne() {
Charles Chanceb2a2e2017-09-12 18:57:47 -0700374 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
375 Sets.newHashSet(HOST_LOC31), Sets.newHashSet(HOST_IP11), false);
376 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
377 Sets.newHashSet(HOST_LOC31, HOST_LOC41), Sets.newHashSet(HOST_IP11), false);
378
379 // Add a dual-homed host with one location
380 // Expect: the pair link is utilized temporarily before the second location is discovered
381 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
382 assertEquals(2, ROUTING_TABLE.size());
383 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP11.toIpPrefix())).portNumber);
384 assertEquals(P9, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
385 assertEquals(2, BRIDGING_TABLE.size());
386 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
387 assertEquals(P9, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chan873661e2017-11-30 15:37:50 -0800388 // Expect probe to be sent out on pair device
Charles Chanc6bcdf92018-06-01 16:33:48 -0700389 assertTrue(mockLocationProbingService.verifyProbe(host1, CP41, ProbeMode.DISCOVER));
Charles Chanceb2a2e2017-09-12 18:57:47 -0700390
391 // Add the second location of dual-homed host
392 // Expect: no longer use the pair link
393 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host1));
394 assertEquals(2, ROUTING_TABLE.size());
395 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP11.toIpPrefix())).portNumber);
Charles Chanfbcb8812018-04-18 18:41:05 -0700396 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
Charles Chanceb2a2e2017-09-12 18:57:47 -0700397 assertEquals(2, BRIDGING_TABLE.size());
398 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
399 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
400 }
401
402 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700403 public void testHostRemoved() {
Charles Chan114aec72017-06-19 14:00:53 -0700404 Host subject = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
Charles Chand9265a32017-06-16 15:19:24 -0700405 Sets.newHashSet(HOST_LOC11), Sets.newHashSet(HOST_IP11), false);
Charles Chan114aec72017-06-19 14:00:53 -0700406
407 // Add a host
408 // Expect: add one routing rule and one bridging rule
409 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, subject));
Charles Chan6c624992017-08-18 17:11:34 -0700410 assertEquals(1, ROUTING_TABLE.size());
411 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
412 assertEquals(1, BRIDGING_TABLE.size());
413 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chan114aec72017-06-19 14:00:53 -0700414
415 // Remove the host
416 // Expect: add the routing rule and the bridging rule
Charles Chand9265a32017-06-16 15:19:24 -0700417 hostHandler.processHostRemovedEvent(new HostEvent(HostEvent.Type.HOST_REMOVED, subject));
Charles Chan6c624992017-08-18 17:11:34 -0700418 assertEquals(0, ROUTING_TABLE.size());
419 assertEquals(0, BRIDGING_TABLE.size());
Charles Chand9265a32017-06-16 15:19:24 -0700420 }
421
422 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700423 public void testDualHomedHostRemoved() {
Charles Chand9265a32017-06-16 15:19:24 -0700424 // Add a dual-homed host that has 2 locations
425 // Expect: add two routing rules and two bridging rules
426 Host subject = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
427 Sets.newHashSet(HOST_LOC11, HOST_LOC21), Sets.newHashSet(HOST_IP11), false);
428 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, subject));
Charles Chan6c624992017-08-18 17:11:34 -0700429 assertEquals(2, ROUTING_TABLE.size());
430 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
431 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())));
432 assertEquals(2, BRIDGING_TABLE.size());
433 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
434 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chand9265a32017-06-16 15:19:24 -0700435
436 // Remove a dual-homed host that has 2 locations
437 // Expect: all routing and bridging rules are removed
438 hostHandler.processHostRemovedEvent(new HostEvent(HostEvent.Type.HOST_REMOVED, subject));
Charles Chan6c624992017-08-18 17:11:34 -0700439 assertEquals(0, ROUTING_TABLE.size());
440 assertEquals(0, BRIDGING_TABLE.size());
Charles Chan114aec72017-06-19 14:00:53 -0700441 }
442
443 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700444 public void testHostMoved() {
Charles Chan114aec72017-06-19 14:00:53 -0700445 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
Charles Chand9265a32017-06-16 15:19:24 -0700446 Sets.newHashSet(HOST_LOC11), Sets.newHashSet(HOST_IP11), false);
Charles Chan114aec72017-06-19 14:00:53 -0700447 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
Charles Chand9265a32017-06-16 15:19:24 -0700448 Sets.newHashSet(HOST_LOC21), Sets.newHashSet(HOST_IP11), false);
Charles Chan114aec72017-06-19 14:00:53 -0700449 Host host3 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
Charles Chand9265a32017-06-16 15:19:24 -0700450 Sets.newHashSet(HOST_LOC13), Sets.newHashSet(HOST_IP11), false);
Charles Chan114aec72017-06-19 14:00:53 -0700451
452 // Add a host
Charles Chan3ed34d82017-06-22 18:03:14 -0700453 // Expect: add one new routing rule, one new bridging rule
Charles Chan114aec72017-06-19 14:00:53 -0700454 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
Charles Chan6c624992017-08-18 17:11:34 -0700455 assertEquals(1, ROUTING_TABLE.size());
456 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
457 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP21.toIpPrefix())));
458 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP13.toIpPrefix())));
459 assertEquals(1, BRIDGING_TABLE.size());
460 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
461 assertNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chan114aec72017-06-19 14:00:53 -0700462
Charles Chand9265a32017-06-16 15:19:24 -0700463 // Move the host to CP13, which has different subnet setting
Charles Chan114aec72017-06-19 14:00:53 -0700464 // Expect: remove routing rule. Change vlan in bridging rule.
Charles Chand9265a32017-06-16 15:19:24 -0700465 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host3, host1));
Charles Chan6c624992017-08-18 17:11:34 -0700466 assertEquals(0, ROUTING_TABLE.size());
467 assertEquals(1, BRIDGING_TABLE.size());
468 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_NATIVE)));
469 assertNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chan114aec72017-06-19 14:00:53 -0700470
Charles Chand9265a32017-06-16 15:19:24 -0700471 // Move the host to CP21, which has same subnet setting
Charles Chan114aec72017-06-19 14:00:53 -0700472 // Expect: add a new routing rule. Change vlan in bridging rule.
Charles Chand9265a32017-06-16 15:19:24 -0700473 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host3));
Charles Chan6c624992017-08-18 17:11:34 -0700474 assertEquals(1, ROUTING_TABLE.size());
475 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
476 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
477 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())));
478 assertEquals(1, BRIDGING_TABLE.size());
479 assertNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
480 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chand9265a32017-06-16 15:19:24 -0700481 }
482
483 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700484 public void testDualHomedHostMoved() {
Charles Chand9265a32017-06-16 15:19:24 -0700485 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
486 Sets.newHashSet(HOST_LOC11, HOST_LOC21), Sets.newHashSet(HOST_IP11, HOST_IP12), false);
487 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
488 Sets.newHashSet(HOST_LOC12, HOST_LOC22), Sets.newHashSet(HOST_IP11, HOST_IP12), false);
489 Host host3 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
490 Sets.newHashSet(HOST_LOC11, HOST_LOC21), Sets.newHashSet(HOST_IP13, HOST_IP14), false);
491 Host host4 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
492 Sets.newHashSet(HOST_LOC11, HOST_LOC22), Sets.newHashSet(HOST_IP12, HOST_IP13), false);
Charles Chan4b5769a2018-04-25 18:51:46 -0400493 Host host5 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
494 Sets.newHashSet(HOST_LOC12, HOST_LOC21), Sets.newHashSet(HOST_IP11, HOST_IP12), false);
495
Charles Chand9265a32017-06-16 15:19:24 -0700496
497 // Add a host with IP11, IP12 and LOC11, LOC21
498 // Expect: 4 routing rules and 2 bridging rules
499 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
Charles Chan6c624992017-08-18 17:11:34 -0700500 assertEquals(4, ROUTING_TABLE.size());
501 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())).portNumber);
502 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP12.toIpPrefix())).portNumber);
503 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())).portNumber);
504 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP12.toIpPrefix())).portNumber);
505 assertEquals(2, BRIDGING_TABLE.size());
506 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
507 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chand9265a32017-06-16 15:19:24 -0700508
Charles Chan4b5769a2018-04-25 18:51:46 -0400509 // Move the host to LOC12, LOC21 and keep the IP
510 // Expect: 4 routing rules and 2 bridging rules all at the new location
511 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host5, host1));
512 assertEquals(4, ROUTING_TABLE.size());
513 assertEquals(P2, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())).portNumber);
514 assertEquals(P2, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP12.toIpPrefix())).portNumber);
515 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())).portNumber);
516 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP12.toIpPrefix())).portNumber);
517 assertEquals(2, BRIDGING_TABLE.size());
518 assertEquals(P2, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
519 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
520
Charles Chand9265a32017-06-16 15:19:24 -0700521 // Move the host to LOC12, LOC22 and keep the IP
522 // Expect: 4 routing rules and 2 bridging rules all at the new location
Charles Chan4b5769a2018-04-25 18:51:46 -0400523 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host5));
Charles Chan6c624992017-08-18 17:11:34 -0700524 assertEquals(4, ROUTING_TABLE.size());
525 assertEquals(P2, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())).portNumber);
526 assertEquals(P2, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP12.toIpPrefix())).portNumber);
527 assertEquals(P2, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())).portNumber);
528 assertEquals(P2, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP12.toIpPrefix())).portNumber);
529 assertEquals(2, BRIDGING_TABLE.size());
530 assertEquals(P2, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
531 assertEquals(P2, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chand9265a32017-06-16 15:19:24 -0700532
533 // Move the host to LOC11, LOC21 and change the IP to IP13, IP14 at the same time
534 // Expect: 4 routing rules and 2 bridging rules all at the new location
535 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host3, host2));
Charles Chan6c624992017-08-18 17:11:34 -0700536 assertEquals(4, ROUTING_TABLE.size());
537 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP13.toIpPrefix())).portNumber);
538 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP14.toIpPrefix())).portNumber);
539 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP13.toIpPrefix())).portNumber);
540 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP14.toIpPrefix())).portNumber);
541 assertEquals(2, BRIDGING_TABLE.size());
542 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
543 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chand9265a32017-06-16 15:19:24 -0700544
545 // Move the host to LOC11, LOC22 and change the IP to IP12, IP13 at the same time
546 // Expect: 4 routing rules and 2 bridging rules all at the new location
547 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host4, host3));
Charles Chan6c624992017-08-18 17:11:34 -0700548 assertEquals(4, ROUTING_TABLE.size());
549 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP12.toIpPrefix())).portNumber);
550 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP13.toIpPrefix())).portNumber);
551 assertEquals(P2, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP12.toIpPrefix())).portNumber);
552 assertEquals(P2, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP13.toIpPrefix())).portNumber);
553 assertEquals(2, BRIDGING_TABLE.size());
554 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
555 assertEquals(P2, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chan114aec72017-06-19 14:00:53 -0700556 }
557
558 @Test
Charles Chan6d43c162018-10-11 12:35:36 -0700559 public void testDualHomedHostMoveTransient() {
560 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
561 Sets.newHashSet(HOST_LOC31, HOST_LOC41), Sets.newHashSet(HOST_IP11), false);
562 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
563 Sets.newHashSet(HOST_LOC32, HOST_LOC41), Sets.newHashSet(HOST_IP11), false);
564 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
565
566 // Mock DefaultRoutingHandler
567 DefaultRoutingHandler mockDefaultRoutingHandler = createMock(DefaultRoutingHandler.class);
568 hostHandler.srManager.defaultRoutingHandler = mockDefaultRoutingHandler;
569
570 // Host moved from [1A/1, 1B/1] to [1A/2, 1B/1]
571 // We should expect only one bridging flow and one routing flow programmed on 1A
Charles Chan12a8a842020-02-14 13:23:57 -0800572
573 expect(mockDefaultRoutingHandler.populateBridging(DEV3, P2, HOST_MAC, HOST_VLAN_UNTAGGED))
574 .andReturn(CompletableFuture.completedFuture(null)).once();
575 expect(mockDefaultRoutingHandler.populateRoute(DEV3, HOST_IP11.toIpPrefix(),
576 HOST_MAC, HOST_VLAN_UNTAGGED, P2, true))
577 .andReturn(CompletableFuture.completedFuture(null)).once();
Charles Chan6d43c162018-10-11 12:35:36 -0700578 replay(mockDefaultRoutingHandler);
579
580 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host1));
581 verify(mockDefaultRoutingHandler);
582 }
583
584 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700585 public void testHostMoveToInvalidLocation() {
Charles Chanabfe7e02017-08-09 16:50:15 -0700586 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
587 Sets.newHashSet(HOST_LOC11), Sets.newHashSet(HOST_IP11), false);
588 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
589 Sets.newHashSet(HOST_LOC51), Sets.newHashSet(HOST_IP11), false);
590
591 // Add a host
592 // Expect: add one new routing rule, one new bridging rule
593 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
Charles Chan6c624992017-08-18 17:11:34 -0700594 assertEquals(1, ROUTING_TABLE.size());
595 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
596 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP21.toIpPrefix())));
597 assertEquals(1, BRIDGING_TABLE.size());
598 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
599 assertNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chanabfe7e02017-08-09 16:50:15 -0700600
601 // Move the host to an invalid location
602 // Expect: Old flow is removed. New flow is not created
603 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host1));
Charles Chan6c624992017-08-18 17:11:34 -0700604 assertEquals(0, ROUTING_TABLE.size());
605 assertEquals(0, BRIDGING_TABLE.size());
Charles Chanabfe7e02017-08-09 16:50:15 -0700606
607 // Move the host to a valid location
608 // Expect: add one new routing rule, one new bridging rule
609 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host1, host2));
Charles Chan6c624992017-08-18 17:11:34 -0700610 assertEquals(1, ROUTING_TABLE.size());
611 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
612 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP21.toIpPrefix())));
613 assertEquals(1, BRIDGING_TABLE.size());
614 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
615 assertNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chanabfe7e02017-08-09 16:50:15 -0700616 }
617
618 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700619 public void testDualHomedHostMoveToInvalidLocation() {
Charles Chanabfe7e02017-08-09 16:50:15 -0700620 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
621 Sets.newHashSet(HOST_LOC11, HOST_LOC21), Sets.newHashSet(HOST_IP11), false);
622 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
623 Sets.newHashSet(HOST_LOC11, HOST_LOC51), Sets.newHashSet(HOST_IP11), false);
624 Host host3 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
625 Sets.newHashSet(HOST_LOC61, HOST_LOC51), Sets.newHashSet(HOST_IP11), false);
626
627 // Add a host
628 // Expect: add two new routing rules, two new bridging rules
629 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
Charles Chan6c624992017-08-18 17:11:34 -0700630 assertEquals(2, ROUTING_TABLE.size());
631 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())).portNumber);
632 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())).portNumber);
633 assertEquals(2, BRIDGING_TABLE.size());
634 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
635 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chanabfe7e02017-08-09 16:50:15 -0700636
637 // Move first host location to an invalid location
638 // Expect: One routing and one bridging flow
639 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host1));
Charles Chan6c624992017-08-18 17:11:34 -0700640 assertEquals(1, ROUTING_TABLE.size());
641 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())).portNumber);
642 assertEquals(1, BRIDGING_TABLE.size());
643 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chanabfe7e02017-08-09 16:50:15 -0700644
645 // Move second host location to an invalid location
646 // Expect: No routing or bridging rule
647 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host3, host2));
Charles Chan6c624992017-08-18 17:11:34 -0700648 assertEquals(0, ROUTING_TABLE.size());
649 assertEquals(0, BRIDGING_TABLE.size());
Charles Chanabfe7e02017-08-09 16:50:15 -0700650
651 // Move second host location back to a valid location
652 // Expect: One routing and one bridging flow
653 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host3));
Charles Chan6c624992017-08-18 17:11:34 -0700654 assertEquals(1, ROUTING_TABLE.size());
655 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())).portNumber);
656 assertEquals(1, BRIDGING_TABLE.size());
657 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chanabfe7e02017-08-09 16:50:15 -0700658
659 // Move first host location back to a valid location
660 // Expect: Two routing and two bridging flow
661 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host1, host2));
Charles Chan6c624992017-08-18 17:11:34 -0700662 assertEquals(2, ROUTING_TABLE.size());
663 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())).portNumber);
664 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())).portNumber);
665 assertEquals(2, BRIDGING_TABLE.size());
666 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
667 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chanabfe7e02017-08-09 16:50:15 -0700668 }
669
670 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700671 public void testDualHomingSingleLocationFail() {
Charles Chan3ed34d82017-06-22 18:03:14 -0700672 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
673 Sets.newHashSet(HOST_LOC31, HOST_LOC41), Sets.newHashSet(HOST_IP11, HOST_IP12), false);
674 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
675 Sets.newHashSet(HOST_LOC31), Sets.newHashSet(HOST_IP11, HOST_IP12), false);
676
677 // Add a host
678 // Expect: add four new routing rules, two new bridging rules
679 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
Charles Chan6c624992017-08-18 17:11:34 -0700680 assertEquals(4, ROUTING_TABLE.size());
681 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP11.toIpPrefix())).portNumber);
682 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP12.toIpPrefix())).portNumber);
683 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
684 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP12.toIpPrefix())).portNumber);
685 assertEquals(2, BRIDGING_TABLE.size());
686 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
687 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chan3ed34d82017-06-22 18:03:14 -0700688
689 // Host becomes single-homed
690 // Expect: redirect flows from host location to pair link
691 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host1));
Charles Chan6c624992017-08-18 17:11:34 -0700692 assertEquals(4, ROUTING_TABLE.size());
693 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP11.toIpPrefix())).portNumber);
694 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP12.toIpPrefix())).portNumber);
695 assertEquals(P9, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
696 assertEquals(P9, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP12.toIpPrefix())).portNumber);
697 assertEquals(2, BRIDGING_TABLE.size());
698 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
699 assertEquals(P9, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chan3ed34d82017-06-22 18:03:14 -0700700
701 // Host becomes dual-homed again
702 // Expect: Redirect flows from pair link back to host location
703 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host1, host2));
Charles Chan6c624992017-08-18 17:11:34 -0700704 assertEquals(4, ROUTING_TABLE.size());
705 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP11.toIpPrefix())).portNumber);
706 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP12.toIpPrefix())).portNumber);
Charles Chan873661e2017-11-30 15:37:50 -0800707 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
708 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP12.toIpPrefix())).portNumber);
Charles Chanfbcb8812018-04-18 18:41:05 -0700709 assertEquals(2, BRIDGING_TABLE.size());
710 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chan6c624992017-08-18 17:11:34 -0700711 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chan3ed34d82017-06-22 18:03:14 -0700712 }
713
714 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700715 public void testDualHomingBothLocationFail() {
Charles Chan3ed34d82017-06-22 18:03:14 -0700716 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
717 Sets.newHashSet(HOST_LOC31, HOST_LOC41), Sets.newHashSet(HOST_IP11, HOST_IP12), false);
718 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
719 Sets.newHashSet(HOST_LOC31), Sets.newHashSet(HOST_IP11, HOST_IP12), false);
720
721 // Add a host
722 // Expect: add four new routing rules, two new bridging rules
723 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
Charles Chan6c624992017-08-18 17:11:34 -0700724 assertEquals(4, ROUTING_TABLE.size());
725 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP11.toIpPrefix())).portNumber);
726 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP12.toIpPrefix())).portNumber);
727 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
728 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP12.toIpPrefix())).portNumber);
729 assertEquals(2, BRIDGING_TABLE.size());
730 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
731 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chan3ed34d82017-06-22 18:03:14 -0700732
733 // Host becomes single-homed
734 // Expect: redirect flows from host location to pair link
735 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host1));
Charles Chan6c624992017-08-18 17:11:34 -0700736 assertEquals(4, ROUTING_TABLE.size());
737 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP11.toIpPrefix())).portNumber);
738 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP12.toIpPrefix())).portNumber);
739 assertEquals(P9, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
740 assertEquals(P9, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP12.toIpPrefix())).portNumber);
741 assertEquals(2, BRIDGING_TABLE.size());
742 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
743 assertEquals(P9, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chan3ed34d82017-06-22 18:03:14 -0700744
745 // Host loses both locations
746 // Expect: Remove last location and all previous redirection flows
747 hostHandler.processHostRemovedEvent(new HostEvent(HostEvent.Type.HOST_REMOVED, host2));
Charles Chan6c624992017-08-18 17:11:34 -0700748 assertEquals(0, ROUTING_TABLE.size());
749 assertEquals(0, BRIDGING_TABLE.size());
Charles Chan3ed34d82017-06-22 18:03:14 -0700750 }
751
752 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700753 public void testHostUpdated() {
Charles Chan114aec72017-06-19 14:00:53 -0700754 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
Charles Chand9265a32017-06-16 15:19:24 -0700755 Sets.newHashSet(HOST_LOC11), Sets.newHashSet(HOST_IP11), false);
Charles Chan114aec72017-06-19 14:00:53 -0700756 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
Charles Chand9265a32017-06-16 15:19:24 -0700757 Sets.newHashSet(HOST_LOC11), Sets.newHashSet(HOST_IP21), false);
Charles Chan114aec72017-06-19 14:00:53 -0700758 Host host3 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
Charles Chand9265a32017-06-16 15:19:24 -0700759 Sets.newHashSet(HOST_LOC11), Sets.newHashSet(HOST_IP12), false);
Charles Chan114aec72017-06-19 14:00:53 -0700760
761 // Add a host
Charles Chand9265a32017-06-16 15:19:24 -0700762 // Expect: add one new routing rule. Add one new bridging rule.
Charles Chan114aec72017-06-19 14:00:53 -0700763 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
Charles Chan6c624992017-08-18 17:11:34 -0700764 assertEquals(1, ROUTING_TABLE.size());
765 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
766 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP21.toIpPrefix())));
767 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP12.toIpPrefix())));
768 assertEquals(1, BRIDGING_TABLE.size());
769 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(HOST_LOC11.deviceId(), HOST_MAC,
770 INTF_VLAN_UNTAGGED)));
Charles Chan114aec72017-06-19 14:00:53 -0700771
772 // Update the host IP to same subnet
773 // Expect: update routing rule with new IP. No change to bridging rule.
774 hostHandler.processHostUpdatedEvent(new HostEvent(HostEvent.Type.HOST_UPDATED, host3, host1));
Charles Chan6c624992017-08-18 17:11:34 -0700775 assertEquals(1, ROUTING_TABLE.size());
776 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
777 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP21.toIpPrefix())));
778 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP12.toIpPrefix())));
779 assertEquals(1, BRIDGING_TABLE.size());
780 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chan114aec72017-06-19 14:00:53 -0700781
782 // Update the host IP to different subnet
783 // Expect: Remove routing rule. No change to bridging rule.
784 hostHandler.processHostUpdatedEvent(new HostEvent(HostEvent.Type.HOST_UPDATED, host2, host3));
Charles Chan6c624992017-08-18 17:11:34 -0700785 assertEquals(0, ROUTING_TABLE.size());
786 assertEquals(1, BRIDGING_TABLE.size());
787 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chand9265a32017-06-16 15:19:24 -0700788 }
789
790 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700791 public void testDelayedIpAndLocation() {
Charles Chanb3c1faf2017-11-20 08:46:24 -0800792 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
793 Sets.newHashSet(HOST_LOC31), Sets.newHashSet(), false);
794 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
795 Sets.newHashSet(HOST_LOC31), Sets.newHashSet(HOST_IP11), false);
796 Host host3 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
797 Sets.newHashSet(HOST_LOC31, HOST_LOC41), Sets.newHashSet(HOST_IP11), false);
798
799 // Add a dual-home host with only one location and no IP
800 // Expect: only bridging redirection works
801 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
802 assertEquals(0, ROUTING_TABLE.size());
803 assertEquals(2, BRIDGING_TABLE.size());
804 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
805 assertEquals(P9, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
806
807 // Discover IP
808 // Expect: routing redirection should also work
Charles Chan873661e2017-11-30 15:37:50 -0800809 hostHandler.processHostUpdatedEvent(new HostEvent(HostEvent.Type.HOST_UPDATED, host2, host1));
Charles Chanb3c1faf2017-11-20 08:46:24 -0800810 assertEquals(2, ROUTING_TABLE.size());
811 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP11.toIpPrefix())).portNumber);
812 assertEquals(P9, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
813 assertEquals(2, BRIDGING_TABLE.size());
814 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
815 assertEquals(P9, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chan873661e2017-11-30 15:37:50 -0800816 // Expect probe to be sent out on pair device
Charles Chanc6bcdf92018-06-01 16:33:48 -0700817 assertTrue(mockLocationProbingService.verifyProbe(host2, CP41, ProbeMode.DISCOVER));
Charles Chanb3c1faf2017-11-20 08:46:24 -0800818
819 // Discover location
820 // Expect: cancel all redirections
Charles Chan873661e2017-11-30 15:37:50 -0800821 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host3, host2));
Charles Chanb3c1faf2017-11-20 08:46:24 -0800822 assertEquals(2, ROUTING_TABLE.size());
823 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP11.toIpPrefix())).portNumber);
Charles Chanfbcb8812018-04-18 18:41:05 -0700824 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
Charles Chanb3c1faf2017-11-20 08:46:24 -0800825 assertEquals(2, BRIDGING_TABLE.size());
826 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chanfbcb8812018-04-18 18:41:05 -0700827 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chan873661e2017-11-30 15:37:50 -0800828 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
Charles Chanb3c1faf2017-11-20 08:46:24 -0800829 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
830 }
831
832 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700833 public void testDelayedIpAndLocation2() {
Charles Chanb3c1faf2017-11-20 08:46:24 -0800834 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
835 Sets.newHashSet(HOST_LOC31), Sets.newHashSet(), false);
836 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
837 Sets.newHashSet(HOST_LOC31, HOST_LOC41), Sets.newHashSet(), false);
838 Host host3 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
839 Sets.newHashSet(HOST_LOC31, HOST_LOC41), Sets.newHashSet(HOST_IP11), false);
840
841 // Add a dual-home host with only one location and no IP
842 // Expect: only bridging redirection works
843 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
844 assertEquals(0, ROUTING_TABLE.size());
845 assertEquals(2, BRIDGING_TABLE.size());
846 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
847 assertEquals(P9, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
848
849 // Discover Location
850 // Expect: cancel bridging redirections
851 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host1));
852 assertEquals(0, ROUTING_TABLE.size());
853 assertEquals(2, BRIDGING_TABLE.size());
854 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
855 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
856
857 // Discover IP
858 // Expect: add IP rules to both location
859 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_UPDATED, host3, host2));
860 assertEquals(2, ROUTING_TABLE.size());
861 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP11.toIpPrefix())).portNumber);
862 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
863 assertEquals(2, BRIDGING_TABLE.size());
864 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
865 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
866 }
867
868 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700869 public void testDualHomedHostUpdated() {
Charles Chand9265a32017-06-16 15:19:24 -0700870 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
871 Sets.newHashSet(HOST_LOC11, HOST_LOC21), Sets.newHashSet(HOST_IP11, HOST_IP12), false);
872 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
873 Sets.newHashSet(HOST_LOC11, HOST_LOC21), Sets.newHashSet(HOST_IP11, HOST_IP21), false);
874 Host host3 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
875 Sets.newHashSet(HOST_LOC11, HOST_LOC21), Sets.newHashSet(HOST_IP13, HOST_IP14), false);
876
877 // Add a dual-homed host with two locations and two IPs
878 // Expect: add four new routing rules. Add two new bridging rules
879 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
Charles Chan6c624992017-08-18 17:11:34 -0700880 assertEquals(4, ROUTING_TABLE.size());
881 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
882 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP12.toIpPrefix())));
883 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())));
884 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP12.toIpPrefix())));
885 assertEquals(2, BRIDGING_TABLE.size());
886 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
887 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chand9265a32017-06-16 15:19:24 -0700888
889 // Update both host IPs
890 // Expect: update routing rules with new IP. No change to bridging rule.
891 hostHandler.processHostUpdatedEvent(new HostEvent(HostEvent.Type.HOST_UPDATED, host3, host1));
Charles Chan6c624992017-08-18 17:11:34 -0700892 assertEquals(4, ROUTING_TABLE.size());
893 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
894 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP12.toIpPrefix())));
895 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP13.toIpPrefix())));
896 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP14.toIpPrefix())));
897 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())));
898 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP12.toIpPrefix())));
899 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP13.toIpPrefix())));
900 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP14.toIpPrefix())));
901 assertEquals(2, BRIDGING_TABLE.size());
902 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
903 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chand9265a32017-06-16 15:19:24 -0700904
905 // Update one of the host IP to different subnet
906 // Expect: update routing rule with new IP. No change to bridging rule.
907 hostHandler.processHostUpdatedEvent(new HostEvent(HostEvent.Type.HOST_UPDATED, host2, host3));
Charles Chan6c624992017-08-18 17:11:34 -0700908 assertEquals(2, ROUTING_TABLE.size());
909 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
910 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP21.toIpPrefix())));
911 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP12.toIpPrefix())));
912 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())));
913 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP21.toIpPrefix())));
914 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP12.toIpPrefix())));
915 assertEquals(2, BRIDGING_TABLE.size());
916 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
917 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chand9265a32017-06-16 15:19:24 -0700918 }
Charles Chan868c9572018-06-15 18:54:18 -0700919
920 @Test
921 public void testVlanForPairPort() {
922 assertEquals(INTF_VLAN_UNTAGGED, hostHandler.vlanForPairPort(VlanId.NONE, CP11));
923 assertEquals(INTF_VLAN_NATIVE, hostHandler.vlanForPairPort(VlanId.NONE, CP13));
924 assertEquals(INTF_VLAN_TAGGED_1, hostHandler.vlanForPairPort(INTF_VLAN_TAGGED_1, CP13));
925 assertNull(hostHandler.vlanForPairPort(INTF_VLAN_UNTAGGED, CP11));
926 assertNull(hostHandler.vlanForPairPort(INTF_VLAN_UNTAGGED, CP13));
927 assertNull(hostHandler.vlanForPairPort(VlanId.NONE, CP51));
928 assertNull(hostHandler.vlanForPairPort(INTF_VLAN_UNTAGGED, CP51));
929 }
Charles Chanbd84dd52018-06-21 19:07:12 -0700930
931 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700932 public void testHostRemovedWithRouteRemoved() {
Charles Chanbd84dd52018-06-21 19:07:12 -0700933 Host subject = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
934 Sets.newHashSet(HOST_LOC11), Sets.newHashSet(HOST_IP11), false);
935
936 // Add a host
937 // Expect: add one routing rule and one bridging rule
938 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, subject));
939 assertEquals(1, ROUTING_TABLE.size());
940 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
941 assertEquals(1, BRIDGING_TABLE.size());
942 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
943
944 IpPrefix prefix = IpPrefix.valueOf("55.55.55.0/24");
945
946 // Setting up mock route service
947 RouteService routeService = hostHandler.srManager.routeService;
948 reset(routeService);
949
950 IpAddress nextHopIp2 = IpAddress.valueOf("20.0.0.1");
951 MacAddress nextHopMac2 = MacAddress.valueOf("00:22:33:44:55:66");
952 VlanId nextHopVlan2 = VlanId.NONE;
953
954 Route r1 = new Route(Route.Source.STATIC, prefix, HOST_IP11);
955 ResolvedRoute rr1 = new ResolvedRoute(r1, HOST_MAC, VlanId.NONE);
956 Route r2 = new Route(Route.Source.STATIC, prefix, nextHopIp2);
957 ResolvedRoute rr2 = new ResolvedRoute(r2, nextHopMac2, nextHopVlan2);
958 RouteInfo routeInfo = new RouteInfo(prefix, rr1, Sets.newHashSet(rr1, rr2));
959 RouteTableId routeTableId = new RouteTableId("ipv4");
960
961 expect(routeService.getRouteTables()).andReturn(Sets.newHashSet(routeTableId));
962 expect(routeService.getRoutes(routeTableId)).andReturn(Sets.newHashSet(routeInfo));
963 replay(routeService);
964
965 // Setting up mock device configuration
966 hostHandler.srManager.deviceConfiguration = EasyMock.createNiceMock(DeviceConfiguration.class);
967 DeviceConfiguration deviceConfiguration = hostHandler.srManager.deviceConfiguration;
968 expect(deviceConfiguration.inSameSubnet(CP11, HOST_IP11)).andReturn(true);
969 deviceConfiguration.removeSubnet(CP11, prefix);
970 expectLastCall();
971 replay(deviceConfiguration);
972
973 // Remove the host
974 // Expect: add the routing rule and the bridging rule
975 hostHandler.processHostRemovedEvent(new HostEvent(HostEvent.Type.HOST_REMOVED, subject));
976 assertEquals(0, ROUTING_TABLE.size());
977 assertEquals(0, BRIDGING_TABLE.size());
978
979 // Expect: subnet is removed from device config
980 verify(deviceConfiguration);
981 }
Charles Chan6e90fbb2018-07-23 15:27:34 -0700982
983 @Test
984 public void testHostProbing() {
985 // Case: [1A/1, 1B/1] -> [1A/2, 1B/1]
986 // Expect: DISCOVER probe should be sent to every port on 1B that has the same VLAN as 1A/2
987 // VERIFY probe should be sent to 1B/1
988 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
989 Sets.newHashSet(HOST_LOC31, HOST_LOC41), Sets.newHashSet(HOST_IP11), false);
990 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
991 Sets.newHashSet(HOST_LOC32, HOST_LOC41), Sets.newHashSet(HOST_IP11), false);
992 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
993
994 hostHandler.srManager.probingService = createMock(HostProbingService.class);
995 hostHandler.srManager.probingService.probeHost(host2, CP41, ProbeMode.DISCOVER);
996 expectLastCall();
997 hostHandler.srManager.probingService.probeHost(host2, CP42, ProbeMode.DISCOVER);
998 expectLastCall();
999 hostHandler.srManager.probingService.probeHost(host2, CP41, ProbeMode.VERIFY);
1000 expectLastCall();
1001 replay(hostHandler.srManager.probingService);
1002
1003 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host1));
1004
1005 verify(hostHandler.srManager.probingService);
1006 }
Charles Chana2ccb582019-11-25 09:47:22 -08001007
1008 @Test
1009 public void testEffectiveLocations() {
1010 Host regularHost = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_TAGGED,
1011 Sets.newHashSet(HOST_LOC11, HOST_LOC12), Sets.newHashSet(HOST_IP11), false);
1012 Host auxHost = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_TAGGED,
1013 Sets.newHashSet(HOST_LOC11, HOST_LOC12), Sets.newHashSet(HOST_LOC21, HOST_LOC22),
1014 Sets.newHashSet(HOST_IP11), VlanId.NONE, EthType.EtherType.UNKNOWN.ethType(), false, false);
1015
1016 assertEquals(Sets.newHashSet(HOST_LOC11, HOST_LOC12), hostHandler.effectiveLocations(regularHost));
1017 assertEquals(Sets.newHashSet(HOST_LOC21, HOST_LOC22), hostHandler.effectiveLocations(auxHost));
1018 }
Ray Milkeyc2d43be2017-08-03 11:58:29 -07001019}