blob: d67cb07006d7cebb6348e2c2b68bffce1043351b [file] [log] [blame]
Charles Chan2e2e3402017-06-19 14:00:53 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Charles Chan2e2e3402017-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 Chan65238242017-06-22 18:03:14 -070019import com.fasterxml.jackson.databind.JsonNode;
20import com.fasterxml.jackson.databind.ObjectMapper;
Charles Chan2e2e3402017-06-19 14:00:53 -070021import com.google.common.collect.Lists;
22import com.google.common.collect.Maps;
23import com.google.common.collect.Sets;
Charles Chan4d639392018-06-21 19:07:12 -070024import org.easymock.EasyMock;
Charles Chan2e2e3402017-06-19 14:00:53 -070025import org.junit.Before;
26import org.junit.Test;
Charles Chand7e62142019-11-25 09:47:22 -080027import org.onlab.packet.EthType;
Charles Chan2e2e3402017-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;
pierb84e9192019-05-17 20:47:06 +020032import org.onlab.util.PredictableExecutor;
Charles Chan1a3b02a2017-08-18 17:11:34 -070033import org.onosproject.net.config.ConfigApplyDelegate;
Charles Chanf82d1552018-07-23 15:27:34 -070034import org.onosproject.net.host.HostProbingService;
Charles Chanff79dd92018-06-01 16:33:48 -070035import org.onosproject.net.host.ProbeMode;
Ray Milkeyfacf2862017-08-03 11:58:29 -070036import org.onosproject.net.intf.Interface;
Charles Chan2e2e3402017-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 Chan2e2e3402017-06-19 14:00:53 -070045import org.onosproject.net.flow.TrafficTreatment;
Charles Chan2e2e3402017-06-19 14:00:53 -070046import org.onosproject.net.host.HostEvent;
47import org.onosproject.net.host.InterfaceIpAddress;
48import org.onosproject.net.provider.ProviderId;
Charles Chan4d639392018-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 Chan2e2e3402017-06-19 14:00:53 -070054import org.onosproject.segmentrouting.config.DeviceConfiguration;
Charles Chan65238242017-06-22 18:03:14 -070055import org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig;
Charles Chan2ff1bac2018-03-29 16:03:41 -070056import org.onosproject.store.service.StorageService;
57import org.onosproject.store.service.TestConsistentMap;
pier41d389a2020-01-07 15:39:39 +010058import org.onosproject.store.service.TestConsistentMultimap;
Charles Chan2e2e3402017-06-19 14:00:53 -070059
60import java.util.Map;
Charles Chan2e2e3402017-06-19 14:00:53 -070061import java.util.Set;
Charles Chan9797ebb2020-02-14 13:23:57 -080062import java.util.concurrent.CompletableFuture;
Charles Chan2e2e3402017-06-19 14:00:53 -070063
Charles Chan2ff1bac2018-03-29 16:03:41 -070064import static org.easymock.EasyMock.createMock;
Charles Chan4d639392018-06-21 19:07:12 -070065import static org.easymock.EasyMock.createNiceMock;
Charles Chan2ff1bac2018-03-29 16:03:41 -070066import static org.easymock.EasyMock.expect;
Charles Chan4d639392018-06-21 19:07:12 -070067import static org.easymock.EasyMock.expectLastCall;
Charles Chan2ff1bac2018-03-29 16:03:41 -070068import static org.easymock.EasyMock.replay;
Charles Chan4d639392018-06-21 19:07:12 -070069import static org.easymock.EasyMock.reset;
70import static org.easymock.EasyMock.verify;
Charles Chan2e2e3402017-06-19 14:00:53 -070071import static org.junit.Assert.*;
pierb84e9192019-05-17 20:47:06 +020072import static org.onlab.util.Tools.groupedThreads;
Charles Chan2e2e3402017-06-19 14:00:53 -070073
pierb84e9192019-05-17 20:47:06 +020074/**
Charles Chan2e2e3402017-06-19 14:00:53 -070075 * Unit test for {@link HostHandler}.
76 */
77public class HostHandlerTest {
Charles Chan2e2e3402017-06-19 14:00:53 -070078 private HostHandler hostHandler;
79
80 // Mocked routing and bridging tables
Charles Chan1a3b02a2017-08-18 17:11:34 -070081 private static final Map<MockBridgingTableKey, MockBridgingTableValue> BRIDGING_TABLE =
82 Maps.newConcurrentMap();
83 private static final Map<MockRoutingTableKey, MockRoutingTableValue> ROUTING_TABLE =
84 Maps.newConcurrentMap();
Charles Chan2fde6d42017-08-23 14:46:43 -070085 private static final Map<ConnectPoint, Set<IpPrefix>> SUBNET_TABLE = Maps.newConcurrentMap();
Charles Chan2e2e3402017-06-19 14:00:53 -070086 // Mocked Next Id
Charles Chan1a3b02a2017-08-18 17:11:34 -070087 private static final Map<Integer, TrafficTreatment> NEXT_TABLE = Maps.newConcurrentMap();
Charles Chan2e2e3402017-06-19 14:00:53 -070088
Charles Chanf9a52702017-06-16 15:19:24 -070089 // Host Mac, VLAN
Charles Chan2e2e3402017-06-19 14:00:53 -070090 private static final ProviderId PROVIDER_ID = ProviderId.NONE;
91 private static final MacAddress HOST_MAC = MacAddress.valueOf("00:00:00:00:00:01");
92 private static final VlanId HOST_VLAN_UNTAGGED = VlanId.NONE;
93 private static final HostId HOST_ID_UNTAGGED = HostId.hostId(HOST_MAC, HOST_VLAN_UNTAGGED);
94 private static final VlanId HOST_VLAN_TAGGED = VlanId.vlanId((short) 20);
95 private static final HostId HOST_ID_TAGGED = HostId.hostId(HOST_MAC, HOST_VLAN_TAGGED);
Charles Chanf9a52702017-06-16 15:19:24 -070096 // Host IP
97 private static final IpAddress HOST_IP11 = IpAddress.valueOf("10.0.1.1");
98 private static final IpAddress HOST_IP21 = IpAddress.valueOf("10.0.2.1");
99 private static final IpAddress HOST_IP12 = IpAddress.valueOf("10.0.1.2");
100 private static final IpAddress HOST_IP13 = IpAddress.valueOf("10.0.1.3");
101 private static final IpAddress HOST_IP14 = IpAddress.valueOf("10.0.1.4");
Charles Chanf82d1552018-07-23 15:27:34 -0700102 private static final IpAddress HOST_IP33 = IpAddress.valueOf("10.0.3.3");
Charles Chanf9a52702017-06-16 15:19:24 -0700103 // Device
104 private static final DeviceId DEV1 = DeviceId.deviceId("of:0000000000000001");
105 private static final DeviceId DEV2 = DeviceId.deviceId("of:0000000000000002");
Charles Chan9f08b102017-08-09 16:50:15 -0700106 private static final DeviceId DEV3 = DeviceId.deviceId("of:0000000000000003");
107 private static final DeviceId DEV4 = DeviceId.deviceId("of:0000000000000004");
108 private static final DeviceId DEV5 = DeviceId.deviceId("of:0000000000000005");
109 private static final DeviceId DEV6 = DeviceId.deviceId("of:0000000000000006");
Charles Chanf9a52702017-06-16 15:19:24 -0700110 // Port
111 private static final PortNumber P1 = PortNumber.portNumber(1);
112 private static final PortNumber P2 = PortNumber.portNumber(2);
113 private static final PortNumber P3 = PortNumber.portNumber(3);
Charles Chan65238242017-06-22 18:03:14 -0700114 private static final PortNumber P9 = PortNumber.portNumber(9);
Charles Chanf9a52702017-06-16 15:19:24 -0700115 // Connect Point
116 private static final ConnectPoint CP11 = new ConnectPoint(DEV1, P1);
117 private static final HostLocation HOST_LOC11 = new HostLocation(CP11, 0);
118 private static final ConnectPoint CP12 = new ConnectPoint(DEV1, P2);
119 private static final HostLocation HOST_LOC12 = new HostLocation(CP12, 0);
120 private static final ConnectPoint CP13 = new ConnectPoint(DEV1, P3);
121 private static final HostLocation HOST_LOC13 = new HostLocation(CP13, 0);
122 private static final ConnectPoint CP21 = new ConnectPoint(DEV2, P1);
123 private static final HostLocation HOST_LOC21 = new HostLocation(CP21, 0);
124 private static final ConnectPoint CP22 = new ConnectPoint(DEV2, P2);
125 private static final HostLocation HOST_LOC22 = new HostLocation(CP22, 0);
Charles Chan65238242017-06-22 18:03:14 -0700126 // Connect Point for dual-homed host failover
127 private static final ConnectPoint CP31 = new ConnectPoint(DEV3, P1);
128 private static final HostLocation HOST_LOC31 = new HostLocation(CP31, 0);
Charles Chan8e786b52017-09-12 18:57:47 -0700129 private static final ConnectPoint CP32 = new ConnectPoint(DEV3, P2);
130 private static final HostLocation HOST_LOC32 = new HostLocation(CP32, 0);
Charles Chanf82d1552018-07-23 15:27:34 -0700131 private static final ConnectPoint CP33 = new ConnectPoint(DEV3, P3);
132 private static final HostLocation HOST_LOC33 = new HostLocation(CP33, 0);
Charles Chan65238242017-06-22 18:03:14 -0700133 private static final ConnectPoint CP41 = new ConnectPoint(DEV4, P1);
134 private static final HostLocation HOST_LOC41 = new HostLocation(CP41, 0);
Charles Chanf82d1552018-07-23 15:27:34 -0700135 private static final ConnectPoint CP42 = new ConnectPoint(DEV4, P2);
136 private static final HostLocation HOST_LOC42 = new HostLocation(CP42, 0);
Charles Chan65238242017-06-22 18:03:14 -0700137 private static final ConnectPoint CP39 = new ConnectPoint(DEV3, P9);
138 private static final ConnectPoint CP49 = new ConnectPoint(DEV4, P9);
Charles Chan9f08b102017-08-09 16:50:15 -0700139 // Conenct Point for mastership test
140 private static final ConnectPoint CP51 = new ConnectPoint(DEV5, P1);
141 private static final HostLocation HOST_LOC51 = new HostLocation(CP51, 0);
142 private static final ConnectPoint CP61 = new ConnectPoint(DEV6, P1);
143 private static final HostLocation HOST_LOC61 = new HostLocation(CP61, 0);
Charles Chanf9a52702017-06-16 15:19:24 -0700144 // Interface VLAN
Charles Chan2e2e3402017-06-19 14:00:53 -0700145 private static final VlanId INTF_VLAN_UNTAGGED = VlanId.vlanId((short) 10);
Charles Chanf76de302018-06-15 18:54:18 -0700146 private static final VlanId INTF_VLAN_TAGGED_1 = VlanId.vlanId((short) 20);
147 private static final Set<VlanId> INTF_VLAN_TAGGED = Sets.newHashSet(INTF_VLAN_TAGGED_1);
Charles Chan2e2e3402017-06-19 14:00:53 -0700148 private static final VlanId INTF_VLAN_NATIVE = VlanId.vlanId((short) 30);
Charles Chan65238242017-06-22 18:03:14 -0700149 private static final Set<VlanId> INTF_VLAN_PAIR = Sets.newHashSet(VlanId.vlanId((short) 10),
150 VlanId.vlanId((short) 20), VlanId.vlanId((short) 30));
Charles Chan8e786b52017-09-12 18:57:47 -0700151 private static final VlanId INTF_VLAN_OTHER = VlanId.vlanId((short) 40);
Charles Chanf9a52702017-06-16 15:19:24 -0700152 // Interface subnet
153 private static final IpPrefix INTF_PREFIX1 = IpPrefix.valueOf("10.0.1.254/24");
154 private static final IpPrefix INTF_PREFIX2 = IpPrefix.valueOf("10.0.2.254/24");
Charles Chan8e786b52017-09-12 18:57:47 -0700155 private static final IpPrefix INTF_PREFIX3 = IpPrefix.valueOf("10.0.3.254/24");
Charles Chanf9a52702017-06-16 15:19:24 -0700156 private static final InterfaceIpAddress INTF_IP1 =
157 new InterfaceIpAddress(INTF_PREFIX1.address(), INTF_PREFIX1);
158 private static final InterfaceIpAddress INTF_IP2 =
159 new InterfaceIpAddress(INTF_PREFIX2.address(), INTF_PREFIX2);
Charles Chan8e786b52017-09-12 18:57:47 -0700160 private static final InterfaceIpAddress INTF_IP3 =
161 new InterfaceIpAddress(INTF_PREFIX3.address(), INTF_PREFIX3);
Charles Chan1a3b02a2017-08-18 17:11:34 -0700162 // Interfaces
163 private static final Interface INTF11 =
164 new Interface(null, CP11, Lists.newArrayList(INTF_IP1), MacAddress.NONE, null,
165 INTF_VLAN_UNTAGGED, null, null);
166 private static final Interface INTF12 =
167 new Interface(null, CP12, Lists.newArrayList(INTF_IP1), MacAddress.NONE, null,
168 INTF_VLAN_UNTAGGED, null, null);
169 private static final Interface INTF13 =
170 new Interface(null, CP13, Lists.newArrayList(INTF_IP2), MacAddress.NONE, null,
171 null, INTF_VLAN_TAGGED, INTF_VLAN_NATIVE);
172 private static final Interface INTF21 =
173 new Interface(null, CP21, Lists.newArrayList(INTF_IP1), MacAddress.NONE, null,
174 INTF_VLAN_UNTAGGED, null, null);
175 private static final Interface INTF22 =
176 new Interface(null, CP22, Lists.newArrayList(INTF_IP1), MacAddress.NONE, null,
177 INTF_VLAN_UNTAGGED, null, null);
178 private static final Interface INTF31 =
179 new Interface(null, CP31, Lists.newArrayList(INTF_IP1), MacAddress.NONE, null,
180 INTF_VLAN_UNTAGGED, null, null);
Charles Chan8e786b52017-09-12 18:57:47 -0700181 private static final Interface INTF32 =
Charles Chanf82d1552018-07-23 15:27:34 -0700182 new Interface(null, CP32, Lists.newArrayList(INTF_IP1), MacAddress.NONE, null,
183 INTF_VLAN_UNTAGGED, null, null);
184 private static final Interface INTF33 =
185 new Interface(null, CP33, Lists.newArrayList(INTF_IP3), MacAddress.NONE, null,
Charles Chan8e786b52017-09-12 18:57:47 -0700186 INTF_VLAN_OTHER, null, null);
Charles Chan1a3b02a2017-08-18 17:11:34 -0700187 private static final Interface INTF39 =
188 new Interface(null, CP39, Lists.newArrayList(INTF_IP1), MacAddress.NONE, null,
189 null, INTF_VLAN_PAIR, null);
190 private static final Interface INTF41 =
191 new Interface(null, CP41, Lists.newArrayList(INTF_IP1), MacAddress.NONE, null,
192 INTF_VLAN_UNTAGGED, null, null);
Charles Chanf82d1552018-07-23 15:27:34 -0700193 private static final Interface INTF42 =
194 new Interface(null, CP42, Lists.newArrayList(INTF_IP1), MacAddress.NONE, null,
195 INTF_VLAN_UNTAGGED, null, null);
Charles Chan1a3b02a2017-08-18 17:11:34 -0700196 private static final Interface INTF49 =
197 new Interface(null, CP49, Lists.newArrayList(INTF_IP1), MacAddress.NONE, null,
198 null, INTF_VLAN_PAIR, null);
Charles Chanf9a52702017-06-16 15:19:24 -0700199 // Host
200 private static final Host HOST1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC,
201 HOST_VLAN_UNTAGGED, Sets.newHashSet(HOST_LOC11, HOST_LOC21), Sets.newHashSet(HOST_IP11),
202 false);
Charles Chan2e2e3402017-06-19 14:00:53 -0700203
Charles Chan1a3b02a2017-08-18 17:11:34 -0700204 // A set of hosts
205 private static final Set<Host> HOSTS = Sets.newHashSet(HOST1);
206 // A set of devices of which we have mastership
207 private static final Set<DeviceId> LOCAL_DEVICES = Sets.newHashSet(DEV1, DEV2, DEV3, DEV4);
208 // A set of interfaces
209 private static final Set<Interface> INTERFACES = Sets.newHashSet(INTF11, INTF12, INTF13, INTF21,
Charles Chanf82d1552018-07-23 15:27:34 -0700210 INTF22, INTF31, INTF32, INTF33, INTF39, INTF41, INTF42, INTF49);
Charles Chan1a3b02a2017-08-18 17:11:34 -0700211
Charles Chanff79dd92018-06-01 16:33:48 -0700212 private MockHostProbingService mockLocationProbingService;
Charles Chan47933752017-11-30 15:37:50 -0800213
Charles Chan2e2e3402017-06-19 14:00:53 -0700214 @Before
Charles Chanf82d1552018-07-23 15:27:34 -0700215 public void setUp() {
Charles Chan1a3b02a2017-08-18 17:11:34 -0700216 // Initialize pairDevice and pairLocalPort config
217 ObjectMapper mapper = new ObjectMapper();
218 ConfigApplyDelegate delegate = config -> { };
219
220 SegmentRoutingDeviceConfig dev3Config = new SegmentRoutingDeviceConfig();
221 JsonNode dev3Tree = mapper.createObjectNode();
222 dev3Config.init(DEV3, "host-handler-test", dev3Tree, mapper, delegate);
223 dev3Config.setPairDeviceId(DEV4).setPairLocalPort(P9);
224
225 SegmentRoutingDeviceConfig dev4Config = new SegmentRoutingDeviceConfig();
226 JsonNode dev4Tree = mapper.createObjectNode();
227 dev4Config.init(DEV4, "host-handler-test", dev4Tree, mapper, delegate);
228 dev4Config.setPairDeviceId(DEV3).setPairLocalPort(P9);
229
230 MockNetworkConfigRegistry mockNetworkConfigRegistry = new MockNetworkConfigRegistry();
231 mockNetworkConfigRegistry.applyConfig(dev3Config);
232 mockNetworkConfigRegistry.applyConfig(dev4Config);
233
234 // Initialize Segment Routing Manager
235 SegmentRoutingManager srManager = new MockSegmentRoutingManager(NEXT_TABLE);
Charles Chan2ff1bac2018-03-29 16:03:41 -0700236 srManager.storageService = createMock(StorageService.class);
237 expect(srManager.storageService.consistentMapBuilder()).andReturn(new TestConsistentMap.Builder<>()).anyTimes();
pier41d389a2020-01-07 15:39:39 +0100238 expect(srManager.storageService.consistentMultimapBuilder()).andReturn(
239 new TestConsistentMultimap.Builder<>()).anyTimes();
Charles Chan2ff1bac2018-03-29 16:03:41 -0700240 replay(srManager.storageService);
Charles Chan2e2e3402017-06-19 14:00:53 -0700241 srManager.cfgService = new NetworkConfigRegistryAdapter();
242 srManager.deviceConfiguration = new DeviceConfiguration(srManager);
Charles Chan1a3b02a2017-08-18 17:11:34 -0700243 srManager.flowObjectiveService = new MockFlowObjectiveService(BRIDGING_TABLE, NEXT_TABLE);
244 srManager.routingRulePopulator = new MockRoutingRulePopulator(srManager, ROUTING_TABLE);
Charles Chanf433f952018-03-15 16:41:10 -0700245 srManager.defaultRoutingHandler = new MockDefaultRoutingHandler(srManager, SUBNET_TABLE, ROUTING_TABLE);
Charles Chan1a3b02a2017-08-18 17:11:34 -0700246 srManager.interfaceService = new MockInterfaceService(INTERFACES);
247 srManager.mastershipService = new MockMastershipService(LOCAL_DEVICES);
248 srManager.hostService = new MockHostService(HOSTS);
249 srManager.cfgService = mockNetworkConfigRegistry;
Charles Chanff79dd92018-06-01 16:33:48 -0700250 mockLocationProbingService = new MockHostProbingService();
Charles Chan47933752017-11-30 15:37:50 -0800251 srManager.probingService = mockLocationProbingService;
Saurav Das45f48152018-01-18 12:07:33 -0800252 srManager.linkHandler = new MockLinkHandler(srManager);
Charles Chan2e2e3402017-06-19 14:00:53 -0700253
Charles Chan4d639392018-06-21 19:07:12 -0700254 // Not important for most of the HostHandler test case. Simply return an empty set here
255 srManager.routeService = createNiceMock(RouteService.class);
256 expect(srManager.routeService.getRouteTables()).andReturn(Sets.newHashSet()).anyTimes();
257 replay(srManager.routeService);
258
Charles Chan2e2e3402017-06-19 14:00:53 -0700259 hostHandler = new HostHandler(srManager);
pierb84e9192019-05-17 20:47:06 +0200260 hostHandler.hostWorkers = new PredictableExecutor(
261 0, groupedThreads("onos/sr", "h-worker-%d"), true);
Charles Chan2e2e3402017-06-19 14:00:53 -0700262
Charles Chan1a3b02a2017-08-18 17:11:34 -0700263 ROUTING_TABLE.clear();
264 BRIDGING_TABLE.clear();
Charles Chan2e2e3402017-06-19 14:00:53 -0700265 }
266
267 @Test
Charles Chanf82d1552018-07-23 15:27:34 -0700268 public void init() {
Charles Chanf9a52702017-06-16 15:19:24 -0700269 hostHandler.init(DEV1);
Charles Chan1a3b02a2017-08-18 17:11:34 -0700270 assertEquals(1, ROUTING_TABLE.size());
271 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
272 assertEquals(1, BRIDGING_TABLE.size());
273 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chanf9a52702017-06-16 15:19:24 -0700274
275 hostHandler.init(DEV2);
Charles Chan1a3b02a2017-08-18 17:11:34 -0700276 assertEquals(2, ROUTING_TABLE.size());
277 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
278 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())));
279 assertEquals(2, BRIDGING_TABLE.size());
280 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
281 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chanf9a52702017-06-16 15:19:24 -0700282 }
283
284 @Test(expected = IllegalArgumentException.class)
Charles Chanf82d1552018-07-23 15:27:34 -0700285 public void testHostAddedAtWrongLocation() {
Charles Chanf9a52702017-06-16 15:19:24 -0700286 hostHandler.processHostAddedAtLocation(HOST1, HOST_LOC13);
287 }
288
289
290 @Test()
Charles Chanf82d1552018-07-23 15:27:34 -0700291 public void testHostAddedAtCorrectLocation() {
Charles Chanf9a52702017-06-16 15:19:24 -0700292 hostHandler.processHostAddedAtLocation(HOST1, HOST_LOC11);
Charles Chan1a3b02a2017-08-18 17:11:34 -0700293 assertEquals(1, ROUTING_TABLE.size());
294 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
295 assertEquals(1, BRIDGING_TABLE.size());
296 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chan2e2e3402017-06-19 14:00:53 -0700297 }
298
299 @Test
Charles Chanf82d1552018-07-23 15:27:34 -0700300 public void testHostAdded() {
Charles Chan2e2e3402017-06-19 14:00:53 -0700301 Host subject;
302
303 // Untagged host discovered on untagged port
304 // Expect: add one routing rule and one bridging rule
305 subject = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
Charles Chanf9a52702017-06-16 15:19:24 -0700306 Sets.newHashSet(HOST_LOC11), Sets.newHashSet(HOST_IP11), false);
Charles Chan2e2e3402017-06-19 14:00:53 -0700307 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, subject));
Charles Chan1a3b02a2017-08-18 17:11:34 -0700308 assertEquals(1, ROUTING_TABLE.size());
309 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
310 assertEquals(1, BRIDGING_TABLE.size());
311 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chan2e2e3402017-06-19 14:00:53 -0700312
313 // Untagged host discovered on tagged/native port
314 // Expect: add one routing rule and one bridging rule
315 subject = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
Charles Chanf9a52702017-06-16 15:19:24 -0700316 Sets.newHashSet(HOST_LOC13), Sets.newHashSet(HOST_IP21), false);
Charles Chan2e2e3402017-06-19 14:00:53 -0700317 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, subject));
Charles Chan1a3b02a2017-08-18 17:11:34 -0700318 assertEquals(2, ROUTING_TABLE.size());
319 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP21.toIpPrefix())));
320 assertEquals(2, BRIDGING_TABLE.size());
321 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_NATIVE)));
Charles Chan2e2e3402017-06-19 14:00:53 -0700322
323 // Tagged host discovered on untagged port
324 // Expect: ignore the host. No rule is added.
325 subject = new DefaultHost(PROVIDER_ID, HOST_ID_TAGGED, HOST_MAC, HOST_VLAN_TAGGED,
Charles Chanf9a52702017-06-16 15:19:24 -0700326 Sets.newHashSet(HOST_LOC11), Sets.newHashSet(HOST_IP11), false);
Charles Chan2e2e3402017-06-19 14:00:53 -0700327 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, subject));
Charles Chan1a3b02a2017-08-18 17:11:34 -0700328 assertEquals(2, ROUTING_TABLE.size());
329 assertEquals(2, BRIDGING_TABLE.size());
Charles Chan2e2e3402017-06-19 14:00:53 -0700330
331 // Tagged host discovered on tagged port with the same IP
332 // Expect: update existing route, add one bridging rule
333 subject = new DefaultHost(PROVIDER_ID, HOST_ID_TAGGED, HOST_MAC, HOST_VLAN_TAGGED,
Charles Chanf9a52702017-06-16 15:19:24 -0700334 Sets.newHashSet(HOST_LOC13), Sets.newHashSet(HOST_IP21), false);
Charles Chan2e2e3402017-06-19 14:00:53 -0700335 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, subject));
Charles Chan1a3b02a2017-08-18 17:11:34 -0700336 assertEquals(2, ROUTING_TABLE.size());
337 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP21.toIpPrefix())));
338 assertEquals(HOST_VLAN_TAGGED, ROUTING_TABLE.get(new MockRoutingTableKey(HOST_LOC13.deviceId(),
Charles Chanf9a52702017-06-16 15:19:24 -0700339 HOST_IP21.toIpPrefix())).vlanId);
Charles Chan1a3b02a2017-08-18 17:11:34 -0700340 assertEquals(3, BRIDGING_TABLE.size());
341 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, HOST_VLAN_TAGGED)));
Charles Chanf9a52702017-06-16 15:19:24 -0700342 }
343
344 @Test
Charles Chanf82d1552018-07-23 15:27:34 -0700345 public void testDualHomedHostAdded() {
Charles Chanf9a52702017-06-16 15:19:24 -0700346 // Add a dual-homed host that has 2 locations
347 // Expect: add two routing rules and two bridging rules
348 Host subject = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
349 Sets.newHashSet(HOST_LOC11, HOST_LOC21), Sets.newHashSet(HOST_IP11), false);
350 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, subject));
Charles Chan1a3b02a2017-08-18 17:11:34 -0700351 assertEquals(2, ROUTING_TABLE.size());
352 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
353 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())));
354 assertEquals(2, BRIDGING_TABLE.size());
355 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
356 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chan2e2e3402017-06-19 14:00:53 -0700357 }
358
359 @Test
Charles Chanf82d1552018-07-23 15:27:34 -0700360 public void testSingleHomedHostAddedOnPairLeaf() {
Charles Chan8e786b52017-09-12 18:57:47 -0700361 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
Charles Chanf82d1552018-07-23 15:27:34 -0700362 Sets.newHashSet(HOST_LOC33), Sets.newHashSet(HOST_IP33), false);
Charles Chan8e786b52017-09-12 18:57:47 -0700363
364 // Add a single-homed host with one location
365 // Expect: the pair link should not be utilized
366 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
367 assertEquals(1, ROUTING_TABLE.size());
Charles Chanf82d1552018-07-23 15:27:34 -0700368 assertEquals(P3, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP33.toIpPrefix())).portNumber);
Charles Chan8e786b52017-09-12 18:57:47 -0700369 assertEquals(1, BRIDGING_TABLE.size());
Charles Chanf82d1552018-07-23 15:27:34 -0700370 assertEquals(P3, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_OTHER)).portNumber);
Charles Chan8e786b52017-09-12 18:57:47 -0700371 }
372
373 @Test
Charles Chanf82d1552018-07-23 15:27:34 -0700374 public void testDualHomedHostAddedOneByOne() {
Charles Chan8e786b52017-09-12 18:57:47 -0700375 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
376 Sets.newHashSet(HOST_LOC31), Sets.newHashSet(HOST_IP11), false);
377 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
378 Sets.newHashSet(HOST_LOC31, HOST_LOC41), Sets.newHashSet(HOST_IP11), false);
379
380 // Add a dual-homed host with one location
381 // Expect: the pair link is utilized temporarily before the second location is discovered
382 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
383 assertEquals(2, ROUTING_TABLE.size());
384 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP11.toIpPrefix())).portNumber);
385 assertEquals(P9, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
386 assertEquals(2, BRIDGING_TABLE.size());
387 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
388 assertEquals(P9, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chan47933752017-11-30 15:37:50 -0800389 // Expect probe to be sent out on pair device
Charles Chanff79dd92018-06-01 16:33:48 -0700390 assertTrue(mockLocationProbingService.verifyProbe(host1, CP41, ProbeMode.DISCOVER));
Charles Chan8e786b52017-09-12 18:57:47 -0700391
392 // Add the second location of dual-homed host
393 // Expect: no longer use the pair link
394 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host1));
395 assertEquals(2, ROUTING_TABLE.size());
396 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP11.toIpPrefix())).portNumber);
Charles Chan50bb6ef2018-04-18 18:41:05 -0700397 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
Charles Chan8e786b52017-09-12 18:57:47 -0700398 assertEquals(2, BRIDGING_TABLE.size());
399 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
400 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
401 }
402
403 @Test
Charles Chanf82d1552018-07-23 15:27:34 -0700404 public void testHostRemoved() {
Charles Chan2e2e3402017-06-19 14:00:53 -0700405 Host subject = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
Charles Chanf9a52702017-06-16 15:19:24 -0700406 Sets.newHashSet(HOST_LOC11), Sets.newHashSet(HOST_IP11), false);
Charles Chan2e2e3402017-06-19 14:00:53 -0700407
408 // Add a host
409 // Expect: add one routing rule and one bridging rule
410 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, subject));
Charles Chan1a3b02a2017-08-18 17:11:34 -0700411 assertEquals(1, ROUTING_TABLE.size());
412 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
413 assertEquals(1, BRIDGING_TABLE.size());
414 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chan2e2e3402017-06-19 14:00:53 -0700415
416 // Remove the host
417 // Expect: add the routing rule and the bridging rule
Charles Chanf9a52702017-06-16 15:19:24 -0700418 hostHandler.processHostRemovedEvent(new HostEvent(HostEvent.Type.HOST_REMOVED, subject));
Charles Chan1a3b02a2017-08-18 17:11:34 -0700419 assertEquals(0, ROUTING_TABLE.size());
420 assertEquals(0, BRIDGING_TABLE.size());
Charles Chanf9a52702017-06-16 15:19:24 -0700421 }
422
423 @Test
Charles Chanf82d1552018-07-23 15:27:34 -0700424 public void testDualHomedHostRemoved() {
Charles Chanf9a52702017-06-16 15:19:24 -0700425 // Add a dual-homed host that has 2 locations
426 // Expect: add two routing rules and two bridging rules
427 Host subject = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
428 Sets.newHashSet(HOST_LOC11, HOST_LOC21), Sets.newHashSet(HOST_IP11), false);
429 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, subject));
Charles Chan1a3b02a2017-08-18 17:11:34 -0700430 assertEquals(2, ROUTING_TABLE.size());
431 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
432 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())));
433 assertEquals(2, BRIDGING_TABLE.size());
434 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
435 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chanf9a52702017-06-16 15:19:24 -0700436
437 // Remove a dual-homed host that has 2 locations
438 // Expect: all routing and bridging rules are removed
439 hostHandler.processHostRemovedEvent(new HostEvent(HostEvent.Type.HOST_REMOVED, subject));
Charles Chan1a3b02a2017-08-18 17:11:34 -0700440 assertEquals(0, ROUTING_TABLE.size());
441 assertEquals(0, BRIDGING_TABLE.size());
Charles Chan2e2e3402017-06-19 14:00:53 -0700442 }
443
444 @Test
Charles Chanf82d1552018-07-23 15:27:34 -0700445 public void testHostMoved() {
Charles Chan2e2e3402017-06-19 14:00:53 -0700446 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
Charles Chanf9a52702017-06-16 15:19:24 -0700447 Sets.newHashSet(HOST_LOC11), Sets.newHashSet(HOST_IP11), false);
Charles Chan2e2e3402017-06-19 14:00:53 -0700448 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
Charles Chanf9a52702017-06-16 15:19:24 -0700449 Sets.newHashSet(HOST_LOC21), Sets.newHashSet(HOST_IP11), false);
Charles Chan2e2e3402017-06-19 14:00:53 -0700450 Host host3 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
Charles Chanf9a52702017-06-16 15:19:24 -0700451 Sets.newHashSet(HOST_LOC13), Sets.newHashSet(HOST_IP11), false);
Charles Chan2e2e3402017-06-19 14:00:53 -0700452
453 // Add a host
Charles Chan65238242017-06-22 18:03:14 -0700454 // Expect: add one new routing rule, one new bridging rule
Charles Chan2e2e3402017-06-19 14:00:53 -0700455 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
Charles Chan1a3b02a2017-08-18 17:11:34 -0700456 assertEquals(1, ROUTING_TABLE.size());
457 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
458 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP21.toIpPrefix())));
459 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP13.toIpPrefix())));
460 assertEquals(1, BRIDGING_TABLE.size());
461 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
462 assertNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chan2e2e3402017-06-19 14:00:53 -0700463
Charles Chanf9a52702017-06-16 15:19:24 -0700464 // Move the host to CP13, which has different subnet setting
Charles Chan2e2e3402017-06-19 14:00:53 -0700465 // Expect: remove routing rule. Change vlan in bridging rule.
Charles Chanf9a52702017-06-16 15:19:24 -0700466 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host3, host1));
Charles Chan1a3b02a2017-08-18 17:11:34 -0700467 assertEquals(0, ROUTING_TABLE.size());
468 assertEquals(1, BRIDGING_TABLE.size());
469 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_NATIVE)));
470 assertNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chan2e2e3402017-06-19 14:00:53 -0700471
Charles Chanf9a52702017-06-16 15:19:24 -0700472 // Move the host to CP21, which has same subnet setting
Charles Chan2e2e3402017-06-19 14:00:53 -0700473 // Expect: add a new routing rule. Change vlan in bridging rule.
Charles Chanf9a52702017-06-16 15:19:24 -0700474 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host3));
Charles Chan1a3b02a2017-08-18 17:11:34 -0700475 assertEquals(1, ROUTING_TABLE.size());
476 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
477 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
478 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())));
479 assertEquals(1, BRIDGING_TABLE.size());
480 assertNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
481 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chanf9a52702017-06-16 15:19:24 -0700482 }
483
484 @Test
Charles Chanf82d1552018-07-23 15:27:34 -0700485 public void testDualHomedHostMoved() {
Charles Chanf9a52702017-06-16 15:19:24 -0700486 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
487 Sets.newHashSet(HOST_LOC11, HOST_LOC21), Sets.newHashSet(HOST_IP11, HOST_IP12), false);
488 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
489 Sets.newHashSet(HOST_LOC12, HOST_LOC22), Sets.newHashSet(HOST_IP11, HOST_IP12), false);
490 Host host3 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
491 Sets.newHashSet(HOST_LOC11, HOST_LOC21), Sets.newHashSet(HOST_IP13, HOST_IP14), false);
492 Host host4 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
493 Sets.newHashSet(HOST_LOC11, HOST_LOC22), Sets.newHashSet(HOST_IP12, HOST_IP13), false);
Charles Chan9bd0e5a2018-04-25 18:51:46 -0400494 Host host5 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
495 Sets.newHashSet(HOST_LOC12, HOST_LOC21), Sets.newHashSet(HOST_IP11, HOST_IP12), false);
496
Charles Chanf9a52702017-06-16 15:19:24 -0700497
498 // Add a host with IP11, IP12 and LOC11, LOC21
499 // Expect: 4 routing rules and 2 bridging rules
500 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
Charles Chan1a3b02a2017-08-18 17:11:34 -0700501 assertEquals(4, ROUTING_TABLE.size());
502 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())).portNumber);
503 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP12.toIpPrefix())).portNumber);
504 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())).portNumber);
505 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP12.toIpPrefix())).portNumber);
506 assertEquals(2, BRIDGING_TABLE.size());
507 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
508 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chanf9a52702017-06-16 15:19:24 -0700509
Charles Chan9bd0e5a2018-04-25 18:51:46 -0400510 // Move the host to LOC12, LOC21 and keep the IP
511 // Expect: 4 routing rules and 2 bridging rules all at the new location
512 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host5, host1));
513 assertEquals(4, ROUTING_TABLE.size());
514 assertEquals(P2, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())).portNumber);
515 assertEquals(P2, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP12.toIpPrefix())).portNumber);
516 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())).portNumber);
517 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP12.toIpPrefix())).portNumber);
518 assertEquals(2, BRIDGING_TABLE.size());
519 assertEquals(P2, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
520 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
521
Charles Chanf9a52702017-06-16 15:19:24 -0700522 // Move the host to LOC12, LOC22 and keep the IP
523 // Expect: 4 routing rules and 2 bridging rules all at the new location
Charles Chan9bd0e5a2018-04-25 18:51:46 -0400524 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host5));
Charles Chan1a3b02a2017-08-18 17:11:34 -0700525 assertEquals(4, ROUTING_TABLE.size());
526 assertEquals(P2, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())).portNumber);
527 assertEquals(P2, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP12.toIpPrefix())).portNumber);
528 assertEquals(P2, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())).portNumber);
529 assertEquals(P2, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP12.toIpPrefix())).portNumber);
530 assertEquals(2, BRIDGING_TABLE.size());
531 assertEquals(P2, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
532 assertEquals(P2, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chanf9a52702017-06-16 15:19:24 -0700533
534 // Move the host to LOC11, LOC21 and change the IP to IP13, IP14 at the same time
535 // Expect: 4 routing rules and 2 bridging rules all at the new location
536 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host3, host2));
Charles Chan1a3b02a2017-08-18 17:11:34 -0700537 assertEquals(4, ROUTING_TABLE.size());
538 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP13.toIpPrefix())).portNumber);
539 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP14.toIpPrefix())).portNumber);
540 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP13.toIpPrefix())).portNumber);
541 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP14.toIpPrefix())).portNumber);
542 assertEquals(2, BRIDGING_TABLE.size());
543 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
544 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chanf9a52702017-06-16 15:19:24 -0700545
546 // Move the host to LOC11, LOC22 and change the IP to IP12, IP13 at the same time
547 // Expect: 4 routing rules and 2 bridging rules all at the new location
548 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host4, host3));
Charles Chan1a3b02a2017-08-18 17:11:34 -0700549 assertEquals(4, ROUTING_TABLE.size());
550 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP12.toIpPrefix())).portNumber);
551 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP13.toIpPrefix())).portNumber);
552 assertEquals(P2, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP12.toIpPrefix())).portNumber);
553 assertEquals(P2, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP13.toIpPrefix())).portNumber);
554 assertEquals(2, BRIDGING_TABLE.size());
555 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
556 assertEquals(P2, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chan2e2e3402017-06-19 14:00:53 -0700557 }
558
559 @Test
Charles Chan5145de22018-10-11 12:35:36 -0700560 public void testDualHomedHostMoveTransient() {
561 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
562 Sets.newHashSet(HOST_LOC31, HOST_LOC41), Sets.newHashSet(HOST_IP11), false);
563 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
564 Sets.newHashSet(HOST_LOC32, HOST_LOC41), Sets.newHashSet(HOST_IP11), false);
565 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
566
567 // Mock DefaultRoutingHandler
568 DefaultRoutingHandler mockDefaultRoutingHandler = createMock(DefaultRoutingHandler.class);
569 hostHandler.srManager.defaultRoutingHandler = mockDefaultRoutingHandler;
570
571 // Host moved from [1A/1, 1B/1] to [1A/2, 1B/1]
572 // We should expect only one bridging flow and one routing flow programmed on 1A
Charles Chan9797ebb2020-02-14 13:23:57 -0800573
574 expect(mockDefaultRoutingHandler.populateBridging(DEV3, P2, HOST_MAC, HOST_VLAN_UNTAGGED))
575 .andReturn(CompletableFuture.completedFuture(null)).once();
576 expect(mockDefaultRoutingHandler.populateRoute(DEV3, HOST_IP11.toIpPrefix(),
577 HOST_MAC, HOST_VLAN_UNTAGGED, P2, true))
578 .andReturn(CompletableFuture.completedFuture(null)).once();
Charles Chan5145de22018-10-11 12:35:36 -0700579 replay(mockDefaultRoutingHandler);
580
581 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host1));
582 verify(mockDefaultRoutingHandler);
583 }
584
585 @Test
Charles Chanf82d1552018-07-23 15:27:34 -0700586 public void testHostMoveToInvalidLocation() {
Charles Chan9f08b102017-08-09 16:50:15 -0700587 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
588 Sets.newHashSet(HOST_LOC11), Sets.newHashSet(HOST_IP11), false);
589 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
590 Sets.newHashSet(HOST_LOC51), Sets.newHashSet(HOST_IP11), false);
591
592 // Add a host
593 // Expect: add one new routing rule, one new bridging rule
594 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
Charles Chan1a3b02a2017-08-18 17:11:34 -0700595 assertEquals(1, ROUTING_TABLE.size());
596 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
597 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP21.toIpPrefix())));
598 assertEquals(1, BRIDGING_TABLE.size());
599 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
600 assertNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chan9f08b102017-08-09 16:50:15 -0700601
602 // Move the host to an invalid location
603 // Expect: Old flow is removed. New flow is not created
604 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host1));
Charles Chan1a3b02a2017-08-18 17:11:34 -0700605 assertEquals(0, ROUTING_TABLE.size());
606 assertEquals(0, BRIDGING_TABLE.size());
Charles Chan9f08b102017-08-09 16:50:15 -0700607
608 // Move the host to a valid location
609 // Expect: add one new routing rule, one new bridging rule
610 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host1, host2));
Charles Chan1a3b02a2017-08-18 17:11:34 -0700611 assertEquals(1, ROUTING_TABLE.size());
612 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
613 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP21.toIpPrefix())));
614 assertEquals(1, BRIDGING_TABLE.size());
615 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
616 assertNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chan9f08b102017-08-09 16:50:15 -0700617 }
618
619 @Test
Charles Chanf82d1552018-07-23 15:27:34 -0700620 public void testDualHomedHostMoveToInvalidLocation() {
Charles Chan9f08b102017-08-09 16:50:15 -0700621 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
622 Sets.newHashSet(HOST_LOC11, HOST_LOC21), Sets.newHashSet(HOST_IP11), false);
623 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
624 Sets.newHashSet(HOST_LOC11, HOST_LOC51), Sets.newHashSet(HOST_IP11), false);
625 Host host3 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
626 Sets.newHashSet(HOST_LOC61, HOST_LOC51), Sets.newHashSet(HOST_IP11), false);
627
628 // Add a host
629 // Expect: add two new routing rules, two new bridging rules
630 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
Charles Chan1a3b02a2017-08-18 17:11:34 -0700631 assertEquals(2, ROUTING_TABLE.size());
632 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())).portNumber);
633 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())).portNumber);
634 assertEquals(2, BRIDGING_TABLE.size());
635 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
636 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chan9f08b102017-08-09 16:50:15 -0700637
638 // Move first host location to an invalid location
639 // Expect: One routing and one bridging flow
640 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host1));
Charles Chan1a3b02a2017-08-18 17:11:34 -0700641 assertEquals(1, ROUTING_TABLE.size());
642 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())).portNumber);
643 assertEquals(1, BRIDGING_TABLE.size());
644 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chan9f08b102017-08-09 16:50:15 -0700645
646 // Move second host location to an invalid location
647 // Expect: No routing or bridging rule
648 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host3, host2));
Charles Chan1a3b02a2017-08-18 17:11:34 -0700649 assertEquals(0, ROUTING_TABLE.size());
650 assertEquals(0, BRIDGING_TABLE.size());
Charles Chan9f08b102017-08-09 16:50:15 -0700651
652 // Move second host location back to a valid location
653 // Expect: One routing and one bridging flow
654 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host3));
Charles Chan1a3b02a2017-08-18 17:11:34 -0700655 assertEquals(1, ROUTING_TABLE.size());
656 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())).portNumber);
657 assertEquals(1, BRIDGING_TABLE.size());
658 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chan9f08b102017-08-09 16:50:15 -0700659
660 // Move first host location back to a valid location
661 // Expect: Two routing and two bridging flow
662 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host1, host2));
Charles Chan1a3b02a2017-08-18 17:11:34 -0700663 assertEquals(2, ROUTING_TABLE.size());
664 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())).portNumber);
665 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())).portNumber);
666 assertEquals(2, BRIDGING_TABLE.size());
667 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
668 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chan9f08b102017-08-09 16:50:15 -0700669 }
670
671 @Test
Charles Chanf82d1552018-07-23 15:27:34 -0700672 public void testDualHomingSingleLocationFail() {
Charles Chan65238242017-06-22 18:03:14 -0700673 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
674 Sets.newHashSet(HOST_LOC31, HOST_LOC41), Sets.newHashSet(HOST_IP11, HOST_IP12), false);
675 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
676 Sets.newHashSet(HOST_LOC31), Sets.newHashSet(HOST_IP11, HOST_IP12), false);
677
678 // Add a host
679 // Expect: add four new routing rules, two new bridging rules
680 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
Charles Chan1a3b02a2017-08-18 17:11:34 -0700681 assertEquals(4, ROUTING_TABLE.size());
682 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP11.toIpPrefix())).portNumber);
683 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP12.toIpPrefix())).portNumber);
684 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
685 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP12.toIpPrefix())).portNumber);
686 assertEquals(2, BRIDGING_TABLE.size());
687 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
688 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chan65238242017-06-22 18:03:14 -0700689
690 // Host becomes single-homed
691 // Expect: redirect flows from host location to pair link
692 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host1));
Charles Chan1a3b02a2017-08-18 17:11:34 -0700693 assertEquals(4, ROUTING_TABLE.size());
694 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP11.toIpPrefix())).portNumber);
695 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP12.toIpPrefix())).portNumber);
696 assertEquals(P9, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
697 assertEquals(P9, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP12.toIpPrefix())).portNumber);
698 assertEquals(2, BRIDGING_TABLE.size());
699 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
700 assertEquals(P9, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chan65238242017-06-22 18:03:14 -0700701
702 // Host becomes dual-homed again
703 // Expect: Redirect flows from pair link back to host location
704 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host1, host2));
Charles Chan1a3b02a2017-08-18 17:11:34 -0700705 assertEquals(4, ROUTING_TABLE.size());
706 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP11.toIpPrefix())).portNumber);
707 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP12.toIpPrefix())).portNumber);
Charles Chan47933752017-11-30 15:37:50 -0800708 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
709 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP12.toIpPrefix())).portNumber);
Charles Chan50bb6ef2018-04-18 18:41:05 -0700710 assertEquals(2, BRIDGING_TABLE.size());
711 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chan1a3b02a2017-08-18 17:11:34 -0700712 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chan65238242017-06-22 18:03:14 -0700713 }
714
715 @Test
Charles Chanf82d1552018-07-23 15:27:34 -0700716 public void testDualHomingBothLocationFail() {
Charles Chan65238242017-06-22 18:03:14 -0700717 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
718 Sets.newHashSet(HOST_LOC31, HOST_LOC41), Sets.newHashSet(HOST_IP11, HOST_IP12), false);
719 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
720 Sets.newHashSet(HOST_LOC31), Sets.newHashSet(HOST_IP11, HOST_IP12), false);
721
722 // Add a host
723 // Expect: add four new routing rules, two new bridging rules
724 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
Charles Chan1a3b02a2017-08-18 17:11:34 -0700725 assertEquals(4, ROUTING_TABLE.size());
726 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP11.toIpPrefix())).portNumber);
727 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP12.toIpPrefix())).portNumber);
728 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
729 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP12.toIpPrefix())).portNumber);
730 assertEquals(2, BRIDGING_TABLE.size());
731 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
732 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chan65238242017-06-22 18:03:14 -0700733
734 // Host becomes single-homed
735 // Expect: redirect flows from host location to pair link
736 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host1));
Charles Chan1a3b02a2017-08-18 17:11:34 -0700737 assertEquals(4, ROUTING_TABLE.size());
738 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP11.toIpPrefix())).portNumber);
739 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP12.toIpPrefix())).portNumber);
740 assertEquals(P9, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
741 assertEquals(P9, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP12.toIpPrefix())).portNumber);
742 assertEquals(2, BRIDGING_TABLE.size());
743 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
744 assertEquals(P9, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chan65238242017-06-22 18:03:14 -0700745
746 // Host loses both locations
747 // Expect: Remove last location and all previous redirection flows
748 hostHandler.processHostRemovedEvent(new HostEvent(HostEvent.Type.HOST_REMOVED, host2));
Charles Chan1a3b02a2017-08-18 17:11:34 -0700749 assertEquals(0, ROUTING_TABLE.size());
750 assertEquals(0, BRIDGING_TABLE.size());
Charles Chan65238242017-06-22 18:03:14 -0700751 }
752
753 @Test
Charles Chanf82d1552018-07-23 15:27:34 -0700754 public void testHostUpdated() {
Charles Chan2e2e3402017-06-19 14:00:53 -0700755 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
Charles Chanf9a52702017-06-16 15:19:24 -0700756 Sets.newHashSet(HOST_LOC11), Sets.newHashSet(HOST_IP11), false);
Charles Chan2e2e3402017-06-19 14:00:53 -0700757 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
Charles Chanf9a52702017-06-16 15:19:24 -0700758 Sets.newHashSet(HOST_LOC11), Sets.newHashSet(HOST_IP21), false);
Charles Chan2e2e3402017-06-19 14:00:53 -0700759 Host host3 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
Charles Chanf9a52702017-06-16 15:19:24 -0700760 Sets.newHashSet(HOST_LOC11), Sets.newHashSet(HOST_IP12), false);
Charles Chan2e2e3402017-06-19 14:00:53 -0700761
762 // Add a host
Charles Chanf9a52702017-06-16 15:19:24 -0700763 // Expect: add one new routing rule. Add one new bridging rule.
Charles Chan2e2e3402017-06-19 14:00:53 -0700764 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
Charles Chan1a3b02a2017-08-18 17:11:34 -0700765 assertEquals(1, ROUTING_TABLE.size());
766 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
767 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP21.toIpPrefix())));
768 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP12.toIpPrefix())));
769 assertEquals(1, BRIDGING_TABLE.size());
770 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(HOST_LOC11.deviceId(), HOST_MAC,
771 INTF_VLAN_UNTAGGED)));
Charles Chan2e2e3402017-06-19 14:00:53 -0700772
773 // Update the host IP to same subnet
774 // Expect: update routing rule with new IP. No change to bridging rule.
775 hostHandler.processHostUpdatedEvent(new HostEvent(HostEvent.Type.HOST_UPDATED, host3, host1));
Charles Chan1a3b02a2017-08-18 17:11:34 -0700776 assertEquals(1, ROUTING_TABLE.size());
777 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
778 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP21.toIpPrefix())));
779 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP12.toIpPrefix())));
780 assertEquals(1, BRIDGING_TABLE.size());
781 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chan2e2e3402017-06-19 14:00:53 -0700782
783 // Update the host IP to different subnet
784 // Expect: Remove routing rule. No change to bridging rule.
785 hostHandler.processHostUpdatedEvent(new HostEvent(HostEvent.Type.HOST_UPDATED, host2, host3));
Charles Chan1a3b02a2017-08-18 17:11:34 -0700786 assertEquals(0, ROUTING_TABLE.size());
787 assertEquals(1, BRIDGING_TABLE.size());
788 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chanf9a52702017-06-16 15:19:24 -0700789 }
790
791 @Test
Charles Chanf82d1552018-07-23 15:27:34 -0700792 public void testDelayedIpAndLocation() {
Charles Chan3d650a62017-11-20 08:46:24 -0800793 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
794 Sets.newHashSet(HOST_LOC31), Sets.newHashSet(), false);
795 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
796 Sets.newHashSet(HOST_LOC31), Sets.newHashSet(HOST_IP11), false);
797 Host host3 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
798 Sets.newHashSet(HOST_LOC31, HOST_LOC41), Sets.newHashSet(HOST_IP11), false);
799
800 // Add a dual-home host with only one location and no IP
801 // Expect: only bridging redirection works
802 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
803 assertEquals(0, ROUTING_TABLE.size());
804 assertEquals(2, BRIDGING_TABLE.size());
805 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
806 assertEquals(P9, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
807
808 // Discover IP
809 // Expect: routing redirection should also work
Charles Chan47933752017-11-30 15:37:50 -0800810 hostHandler.processHostUpdatedEvent(new HostEvent(HostEvent.Type.HOST_UPDATED, host2, host1));
Charles Chan3d650a62017-11-20 08:46:24 -0800811 assertEquals(2, ROUTING_TABLE.size());
812 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP11.toIpPrefix())).portNumber);
813 assertEquals(P9, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
814 assertEquals(2, BRIDGING_TABLE.size());
815 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
816 assertEquals(P9, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chan47933752017-11-30 15:37:50 -0800817 // Expect probe to be sent out on pair device
Charles Chanff79dd92018-06-01 16:33:48 -0700818 assertTrue(mockLocationProbingService.verifyProbe(host2, CP41, ProbeMode.DISCOVER));
Charles Chan3d650a62017-11-20 08:46:24 -0800819
820 // Discover location
821 // Expect: cancel all redirections
Charles Chan47933752017-11-30 15:37:50 -0800822 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host3, host2));
Charles Chan3d650a62017-11-20 08:46:24 -0800823 assertEquals(2, ROUTING_TABLE.size());
824 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP11.toIpPrefix())).portNumber);
Charles Chan50bb6ef2018-04-18 18:41:05 -0700825 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
Charles Chan3d650a62017-11-20 08:46:24 -0800826 assertEquals(2, BRIDGING_TABLE.size());
827 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chan50bb6ef2018-04-18 18:41:05 -0700828 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chan47933752017-11-30 15:37:50 -0800829 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
Charles Chan3d650a62017-11-20 08:46:24 -0800830 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
831 }
832
833 @Test
Charles Chanf82d1552018-07-23 15:27:34 -0700834 public void testDelayedIpAndLocation2() {
Charles Chan3d650a62017-11-20 08:46:24 -0800835 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
836 Sets.newHashSet(HOST_LOC31), Sets.newHashSet(), false);
837 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
838 Sets.newHashSet(HOST_LOC31, HOST_LOC41), Sets.newHashSet(), false);
839 Host host3 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
840 Sets.newHashSet(HOST_LOC31, HOST_LOC41), Sets.newHashSet(HOST_IP11), false);
841
842 // Add a dual-home host with only one location and no IP
843 // Expect: only bridging redirection works
844 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
845 assertEquals(0, ROUTING_TABLE.size());
846 assertEquals(2, BRIDGING_TABLE.size());
847 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
848 assertEquals(P9, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
849
850 // Discover Location
851 // Expect: cancel bridging redirections
852 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host1));
853 assertEquals(0, ROUTING_TABLE.size());
854 assertEquals(2, BRIDGING_TABLE.size());
855 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
856 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
857
858 // Discover IP
859 // Expect: add IP rules to both location
860 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_UPDATED, host3, host2));
861 assertEquals(2, ROUTING_TABLE.size());
862 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP11.toIpPrefix())).portNumber);
863 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
864 assertEquals(2, BRIDGING_TABLE.size());
865 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
866 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
867 }
868
869 @Test
Charles Chanf82d1552018-07-23 15:27:34 -0700870 public void testDualHomedHostUpdated() {
Charles Chanf9a52702017-06-16 15:19:24 -0700871 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
872 Sets.newHashSet(HOST_LOC11, HOST_LOC21), Sets.newHashSet(HOST_IP11, HOST_IP12), false);
873 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
874 Sets.newHashSet(HOST_LOC11, HOST_LOC21), Sets.newHashSet(HOST_IP11, HOST_IP21), false);
875 Host host3 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
876 Sets.newHashSet(HOST_LOC11, HOST_LOC21), Sets.newHashSet(HOST_IP13, HOST_IP14), false);
877
878 // Add a dual-homed host with two locations and two IPs
879 // Expect: add four new routing rules. Add two new bridging rules
880 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
Charles Chan1a3b02a2017-08-18 17:11:34 -0700881 assertEquals(4, ROUTING_TABLE.size());
882 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
883 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP12.toIpPrefix())));
884 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())));
885 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP12.toIpPrefix())));
886 assertEquals(2, BRIDGING_TABLE.size());
887 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
888 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chanf9a52702017-06-16 15:19:24 -0700889
890 // Update both host IPs
891 // Expect: update routing rules with new IP. No change to bridging rule.
892 hostHandler.processHostUpdatedEvent(new HostEvent(HostEvent.Type.HOST_UPDATED, host3, host1));
Charles Chan1a3b02a2017-08-18 17:11:34 -0700893 assertEquals(4, ROUTING_TABLE.size());
894 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
895 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP12.toIpPrefix())));
896 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP13.toIpPrefix())));
897 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP14.toIpPrefix())));
898 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())));
899 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP12.toIpPrefix())));
900 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP13.toIpPrefix())));
901 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP14.toIpPrefix())));
902 assertEquals(2, BRIDGING_TABLE.size());
903 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
904 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chanf9a52702017-06-16 15:19:24 -0700905
906 // Update one of the host IP to different subnet
907 // Expect: update routing rule with new IP. No change to bridging rule.
908 hostHandler.processHostUpdatedEvent(new HostEvent(HostEvent.Type.HOST_UPDATED, host2, host3));
Charles Chan1a3b02a2017-08-18 17:11:34 -0700909 assertEquals(2, ROUTING_TABLE.size());
910 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
911 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP21.toIpPrefix())));
912 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP12.toIpPrefix())));
913 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())));
914 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP21.toIpPrefix())));
915 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP12.toIpPrefix())));
916 assertEquals(2, BRIDGING_TABLE.size());
917 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
918 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chanf9a52702017-06-16 15:19:24 -0700919 }
Charles Chanf76de302018-06-15 18:54:18 -0700920
921 @Test
922 public void testVlanForPairPort() {
923 assertEquals(INTF_VLAN_UNTAGGED, hostHandler.vlanForPairPort(VlanId.NONE, CP11));
924 assertEquals(INTF_VLAN_NATIVE, hostHandler.vlanForPairPort(VlanId.NONE, CP13));
925 assertEquals(INTF_VLAN_TAGGED_1, hostHandler.vlanForPairPort(INTF_VLAN_TAGGED_1, CP13));
926 assertNull(hostHandler.vlanForPairPort(INTF_VLAN_UNTAGGED, CP11));
927 assertNull(hostHandler.vlanForPairPort(INTF_VLAN_UNTAGGED, CP13));
928 assertNull(hostHandler.vlanForPairPort(VlanId.NONE, CP51));
929 assertNull(hostHandler.vlanForPairPort(INTF_VLAN_UNTAGGED, CP51));
930 }
Charles Chan4d639392018-06-21 19:07:12 -0700931
932 @Test
Charles Chanf82d1552018-07-23 15:27:34 -0700933 public void testHostRemovedWithRouteRemoved() {
Charles Chan4d639392018-06-21 19:07:12 -0700934 Host subject = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
935 Sets.newHashSet(HOST_LOC11), Sets.newHashSet(HOST_IP11), false);
936
937 // Add a host
938 // Expect: add one routing rule and one bridging rule
939 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, subject));
940 assertEquals(1, ROUTING_TABLE.size());
941 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
942 assertEquals(1, BRIDGING_TABLE.size());
943 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
944
945 IpPrefix prefix = IpPrefix.valueOf("55.55.55.0/24");
946
947 // Setting up mock route service
948 RouteService routeService = hostHandler.srManager.routeService;
949 reset(routeService);
950
951 IpAddress nextHopIp2 = IpAddress.valueOf("20.0.0.1");
952 MacAddress nextHopMac2 = MacAddress.valueOf("00:22:33:44:55:66");
953 VlanId nextHopVlan2 = VlanId.NONE;
954
955 Route r1 = new Route(Route.Source.STATIC, prefix, HOST_IP11);
956 ResolvedRoute rr1 = new ResolvedRoute(r1, HOST_MAC, VlanId.NONE);
957 Route r2 = new Route(Route.Source.STATIC, prefix, nextHopIp2);
958 ResolvedRoute rr2 = new ResolvedRoute(r2, nextHopMac2, nextHopVlan2);
959 RouteInfo routeInfo = new RouteInfo(prefix, rr1, Sets.newHashSet(rr1, rr2));
960 RouteTableId routeTableId = new RouteTableId("ipv4");
961
962 expect(routeService.getRouteTables()).andReturn(Sets.newHashSet(routeTableId));
963 expect(routeService.getRoutes(routeTableId)).andReturn(Sets.newHashSet(routeInfo));
964 replay(routeService);
965
966 // Setting up mock device configuration
967 hostHandler.srManager.deviceConfiguration = EasyMock.createNiceMock(DeviceConfiguration.class);
968 DeviceConfiguration deviceConfiguration = hostHandler.srManager.deviceConfiguration;
969 expect(deviceConfiguration.inSameSubnet(CP11, HOST_IP11)).andReturn(true);
970 deviceConfiguration.removeSubnet(CP11, prefix);
971 expectLastCall();
972 replay(deviceConfiguration);
973
974 // Remove the host
975 // Expect: add the routing rule and the bridging rule
976 hostHandler.processHostRemovedEvent(new HostEvent(HostEvent.Type.HOST_REMOVED, subject));
977 assertEquals(0, ROUTING_TABLE.size());
978 assertEquals(0, BRIDGING_TABLE.size());
979
980 // Expect: subnet is removed from device config
981 verify(deviceConfiguration);
982 }
Charles Chanf82d1552018-07-23 15:27:34 -0700983
984 @Test
985 public void testHostProbing() {
986 // Case: [1A/1, 1B/1] -> [1A/2, 1B/1]
987 // Expect: DISCOVER probe should be sent to every port on 1B that has the same VLAN as 1A/2
988 // VERIFY probe should be sent to 1B/1
989 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
990 Sets.newHashSet(HOST_LOC31, HOST_LOC41), Sets.newHashSet(HOST_IP11), false);
991 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
992 Sets.newHashSet(HOST_LOC32, HOST_LOC41), Sets.newHashSet(HOST_IP11), false);
993 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
994
995 hostHandler.srManager.probingService = createMock(HostProbingService.class);
996 hostHandler.srManager.probingService.probeHost(host2, CP41, ProbeMode.DISCOVER);
997 expectLastCall();
998 hostHandler.srManager.probingService.probeHost(host2, CP42, ProbeMode.DISCOVER);
999 expectLastCall();
1000 hostHandler.srManager.probingService.probeHost(host2, CP41, ProbeMode.VERIFY);
1001 expectLastCall();
1002 replay(hostHandler.srManager.probingService);
1003
1004 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host1));
1005
1006 verify(hostHandler.srManager.probingService);
1007 }
Charles Chand7e62142019-11-25 09:47:22 -08001008
1009 @Test
1010 public void testEffectiveLocations() {
1011 Host regularHost = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_TAGGED,
1012 Sets.newHashSet(HOST_LOC11, HOST_LOC12), Sets.newHashSet(HOST_IP11), false);
1013 Host auxHost = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_TAGGED,
1014 Sets.newHashSet(HOST_LOC11, HOST_LOC12), Sets.newHashSet(HOST_LOC21, HOST_LOC22),
1015 Sets.newHashSet(HOST_IP11), VlanId.NONE, EthType.EtherType.UNKNOWN.ethType(), false, false);
1016
1017 assertEquals(Sets.newHashSet(HOST_LOC11, HOST_LOC12), hostHandler.effectiveLocations(regularHost));
1018 assertEquals(Sets.newHashSet(HOST_LOC21, HOST_LOC22), hostHandler.effectiveLocations(auxHost));
1019 }
Ray Milkeyfacf2862017-08-03 11:58:29 -07001020}