blob: a4c6fdc16a5b691631e962f72747e2fb3e80eab0 [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");
pierventre37dcf4c2021-09-16 18:43:06 +020091 private static final MacAddress HOST_5_MAC = MacAddress.valueOf("00:00:00:00:00:05");
Charles Chan114aec72017-06-19 14:00:53 -070092 private static final VlanId HOST_VLAN_UNTAGGED = VlanId.NONE;
93 private static final HostId HOST_ID_UNTAGGED = HostId.hostId(HOST_MAC, HOST_VLAN_UNTAGGED);
pierventre37dcf4c2021-09-16 18:43:06 +020094 private static final HostId HOST_5_ID_UNTAGGED = HostId.hostId(HOST_5_MAC, HOST_VLAN_UNTAGGED);
Charles Chan114aec72017-06-19 14:00:53 -070095 private static final VlanId HOST_VLAN_TAGGED = VlanId.vlanId((short) 20);
96 private static final HostId HOST_ID_TAGGED = HostId.hostId(HOST_MAC, HOST_VLAN_TAGGED);
Charles Chand9265a32017-06-16 15:19:24 -070097 // Host IP
98 private static final IpAddress HOST_IP11 = IpAddress.valueOf("10.0.1.1");
99 private static final IpAddress HOST_IP21 = IpAddress.valueOf("10.0.2.1");
100 private static final IpAddress HOST_IP12 = IpAddress.valueOf("10.0.1.2");
101 private static final IpAddress HOST_IP13 = IpAddress.valueOf("10.0.1.3");
102 private static final IpAddress HOST_IP14 = IpAddress.valueOf("10.0.1.4");
Charles Chan6e90fbb2018-07-23 15:27:34 -0700103 private static final IpAddress HOST_IP33 = IpAddress.valueOf("10.0.3.3");
pierventre37dcf4c2021-09-16 18:43:06 +0200104 private static final IpAddress HOST_IP51 = IpAddress.valueOf("10.0.5.1");
Charles Chand9265a32017-06-16 15:19:24 -0700105 // Device
106 private static final DeviceId DEV1 = DeviceId.deviceId("of:0000000000000001");
107 private static final DeviceId DEV2 = DeviceId.deviceId("of:0000000000000002");
Charles Chanabfe7e02017-08-09 16:50:15 -0700108 private static final DeviceId DEV3 = DeviceId.deviceId("of:0000000000000003");
109 private static final DeviceId DEV4 = DeviceId.deviceId("of:0000000000000004");
110 private static final DeviceId DEV5 = DeviceId.deviceId("of:0000000000000005");
111 private static final DeviceId DEV6 = DeviceId.deviceId("of:0000000000000006");
Charles Chand9265a32017-06-16 15:19:24 -0700112 // Port
113 private static final PortNumber P1 = PortNumber.portNumber(1);
114 private static final PortNumber P2 = PortNumber.portNumber(2);
115 private static final PortNumber P3 = PortNumber.portNumber(3);
Charles Chan3ed34d82017-06-22 18:03:14 -0700116 private static final PortNumber P9 = PortNumber.portNumber(9);
Charles Chand9265a32017-06-16 15:19:24 -0700117 // Connect Point
118 private static final ConnectPoint CP11 = new ConnectPoint(DEV1, P1);
119 private static final HostLocation HOST_LOC11 = new HostLocation(CP11, 0);
120 private static final ConnectPoint CP12 = new ConnectPoint(DEV1, P2);
121 private static final HostLocation HOST_LOC12 = new HostLocation(CP12, 0);
122 private static final ConnectPoint CP13 = new ConnectPoint(DEV1, P3);
123 private static final HostLocation HOST_LOC13 = new HostLocation(CP13, 0);
124 private static final ConnectPoint CP21 = new ConnectPoint(DEV2, P1);
125 private static final HostLocation HOST_LOC21 = new HostLocation(CP21, 0);
126 private static final ConnectPoint CP22 = new ConnectPoint(DEV2, P2);
127 private static final HostLocation HOST_LOC22 = new HostLocation(CP22, 0);
Charles Chan3ed34d82017-06-22 18:03:14 -0700128 // Connect Point for dual-homed host failover
129 private static final ConnectPoint CP31 = new ConnectPoint(DEV3, P1);
130 private static final HostLocation HOST_LOC31 = new HostLocation(CP31, 0);
Charles Chanceb2a2e2017-09-12 18:57:47 -0700131 private static final ConnectPoint CP32 = new ConnectPoint(DEV3, P2);
132 private static final HostLocation HOST_LOC32 = new HostLocation(CP32, 0);
Charles Chan6e90fbb2018-07-23 15:27:34 -0700133 private static final ConnectPoint CP33 = new ConnectPoint(DEV3, P3);
134 private static final HostLocation HOST_LOC33 = new HostLocation(CP33, 0);
Charles Chan3ed34d82017-06-22 18:03:14 -0700135 private static final ConnectPoint CP41 = new ConnectPoint(DEV4, P1);
136 private static final HostLocation HOST_LOC41 = new HostLocation(CP41, 0);
Charles Chan6e90fbb2018-07-23 15:27:34 -0700137 private static final ConnectPoint CP42 = new ConnectPoint(DEV4, P2);
138 private static final HostLocation HOST_LOC42 = new HostLocation(CP42, 0);
Charles Chan3ed34d82017-06-22 18:03:14 -0700139 private static final ConnectPoint CP39 = new ConnectPoint(DEV3, P9);
140 private static final ConnectPoint CP49 = new ConnectPoint(DEV4, P9);
pierventre37dcf4c2021-09-16 18:43:06 +0200141 // Connect Point for leadership test and move to invalid locations
Charles Chanabfe7e02017-08-09 16:50:15 -0700142 private static final ConnectPoint CP51 = new ConnectPoint(DEV5, P1);
143 private static final HostLocation HOST_LOC51 = new HostLocation(CP51, 0);
144 private static final ConnectPoint CP61 = new ConnectPoint(DEV6, P1);
145 private static final HostLocation HOST_LOC61 = new HostLocation(CP61, 0);
Charles Chand9265a32017-06-16 15:19:24 -0700146 // Interface VLAN
Charles Chan114aec72017-06-19 14:00:53 -0700147 private static final VlanId INTF_VLAN_UNTAGGED = VlanId.vlanId((short) 10);
Charles Chan868c9572018-06-15 18:54:18 -0700148 private static final VlanId INTF_VLAN_TAGGED_1 = VlanId.vlanId((short) 20);
149 private static final Set<VlanId> INTF_VLAN_TAGGED = Sets.newHashSet(INTF_VLAN_TAGGED_1);
Charles Chan114aec72017-06-19 14:00:53 -0700150 private static final VlanId INTF_VLAN_NATIVE = VlanId.vlanId((short) 30);
Charles Chan3ed34d82017-06-22 18:03:14 -0700151 private static final Set<VlanId> INTF_VLAN_PAIR = Sets.newHashSet(VlanId.vlanId((short) 10),
152 VlanId.vlanId((short) 20), VlanId.vlanId((short) 30));
Charles Chanceb2a2e2017-09-12 18:57:47 -0700153 private static final VlanId INTF_VLAN_OTHER = VlanId.vlanId((short) 40);
Charles Chand9265a32017-06-16 15:19:24 -0700154 // Interface subnet
155 private static final IpPrefix INTF_PREFIX1 = IpPrefix.valueOf("10.0.1.254/24");
156 private static final IpPrefix INTF_PREFIX2 = IpPrefix.valueOf("10.0.2.254/24");
Charles Chanceb2a2e2017-09-12 18:57:47 -0700157 private static final IpPrefix INTF_PREFIX3 = IpPrefix.valueOf("10.0.3.254/24");
Charles Chand9265a32017-06-16 15:19:24 -0700158 private static final InterfaceIpAddress INTF_IP1 =
159 new InterfaceIpAddress(INTF_PREFIX1.address(), INTF_PREFIX1);
160 private static final InterfaceIpAddress INTF_IP2 =
161 new InterfaceIpAddress(INTF_PREFIX2.address(), INTF_PREFIX2);
Charles Chanceb2a2e2017-09-12 18:57:47 -0700162 private static final InterfaceIpAddress INTF_IP3 =
163 new InterfaceIpAddress(INTF_PREFIX3.address(), INTF_PREFIX3);
Charles Chan6c624992017-08-18 17:11:34 -0700164 // Interfaces
165 private static final Interface INTF11 =
166 new Interface(null, CP11, Lists.newArrayList(INTF_IP1), MacAddress.NONE, null,
167 INTF_VLAN_UNTAGGED, null, null);
168 private static final Interface INTF12 =
169 new Interface(null, CP12, Lists.newArrayList(INTF_IP1), MacAddress.NONE, null,
170 INTF_VLAN_UNTAGGED, null, null);
171 private static final Interface INTF13 =
172 new Interface(null, CP13, Lists.newArrayList(INTF_IP2), MacAddress.NONE, null,
173 null, INTF_VLAN_TAGGED, INTF_VLAN_NATIVE);
174 private static final Interface INTF21 =
175 new Interface(null, CP21, Lists.newArrayList(INTF_IP1), MacAddress.NONE, null,
176 INTF_VLAN_UNTAGGED, null, null);
177 private static final Interface INTF22 =
178 new Interface(null, CP22, Lists.newArrayList(INTF_IP1), MacAddress.NONE, null,
179 INTF_VLAN_UNTAGGED, null, null);
180 private static final Interface INTF31 =
181 new Interface(null, CP31, Lists.newArrayList(INTF_IP1), MacAddress.NONE, null,
182 INTF_VLAN_UNTAGGED, null, null);
Charles Chanceb2a2e2017-09-12 18:57:47 -0700183 private static final Interface INTF32 =
Charles Chan6e90fbb2018-07-23 15:27:34 -0700184 new Interface(null, CP32, Lists.newArrayList(INTF_IP1), MacAddress.NONE, null,
185 INTF_VLAN_UNTAGGED, null, null);
186 private static final Interface INTF33 =
187 new Interface(null, CP33, Lists.newArrayList(INTF_IP3), MacAddress.NONE, null,
Charles Chanceb2a2e2017-09-12 18:57:47 -0700188 INTF_VLAN_OTHER, null, null);
Charles Chan6c624992017-08-18 17:11:34 -0700189 private static final Interface INTF39 =
190 new Interface(null, CP39, Lists.newArrayList(INTF_IP1), MacAddress.NONE, null,
191 null, INTF_VLAN_PAIR, null);
192 private static final Interface INTF41 =
193 new Interface(null, CP41, Lists.newArrayList(INTF_IP1), MacAddress.NONE, null,
194 INTF_VLAN_UNTAGGED, null, null);
Charles Chan6e90fbb2018-07-23 15:27:34 -0700195 private static final Interface INTF42 =
196 new Interface(null, CP42, Lists.newArrayList(INTF_IP1), MacAddress.NONE, null,
197 INTF_VLAN_UNTAGGED, null, null);
Charles Chan6c624992017-08-18 17:11:34 -0700198 private static final Interface INTF49 =
199 new Interface(null, CP49, Lists.newArrayList(INTF_IP1), MacAddress.NONE, null,
200 null, INTF_VLAN_PAIR, null);
Charles Chand9265a32017-06-16 15:19:24 -0700201 // Host
202 private static final Host HOST1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC,
203 HOST_VLAN_UNTAGGED, Sets.newHashSet(HOST_LOC11, HOST_LOC21), Sets.newHashSet(HOST_IP11),
204 false);
pierventre37dcf4c2021-09-16 18:43:06 +0200205 private static final Host HOST5 = new DefaultHost(PROVIDER_ID, HOST_5_ID_UNTAGGED, HOST_5_MAC,
206 HOST_VLAN_UNTAGGED, Sets.newHashSet(HOST_LOC51), Sets.newHashSet(HOST_IP51),
207 false);
Charles Chan114aec72017-06-19 14:00:53 -0700208
Charles Chan6c624992017-08-18 17:11:34 -0700209 // A set of hosts
pierventre37dcf4c2021-09-16 18:43:06 +0200210 private static final Set<Host> HOSTS = Sets.newHashSet(HOST1, HOST5);
211 // A set of devices of which we have leadership
212 private static final Set<DeviceId> LED_DEVICES = Sets.newHashSet(DEV1, DEV2, DEV3, DEV4);
Charles Chan6c624992017-08-18 17:11:34 -0700213 // A set of interfaces
214 private static final Set<Interface> INTERFACES = Sets.newHashSet(INTF11, INTF12, INTF13, INTF21,
Charles Chan6e90fbb2018-07-23 15:27:34 -0700215 INTF22, INTF31, INTF32, INTF33, INTF39, INTF41, INTF42, INTF49);
Charles Chan6c624992017-08-18 17:11:34 -0700216
Charles Chanc6bcdf92018-06-01 16:33:48 -0700217 private MockHostProbingService mockLocationProbingService;
Charles Chan873661e2017-11-30 15:37:50 -0800218
Charles Chan114aec72017-06-19 14:00:53 -0700219 @Before
Charles Chan6e90fbb2018-07-23 15:27:34 -0700220 public void setUp() {
Charles Chan6c624992017-08-18 17:11:34 -0700221 // Initialize pairDevice and pairLocalPort config
222 ObjectMapper mapper = new ObjectMapper();
223 ConfigApplyDelegate delegate = config -> { };
224
225 SegmentRoutingDeviceConfig dev3Config = new SegmentRoutingDeviceConfig();
226 JsonNode dev3Tree = mapper.createObjectNode();
227 dev3Config.init(DEV3, "host-handler-test", dev3Tree, mapper, delegate);
228 dev3Config.setPairDeviceId(DEV4).setPairLocalPort(P9);
229
230 SegmentRoutingDeviceConfig dev4Config = new SegmentRoutingDeviceConfig();
231 JsonNode dev4Tree = mapper.createObjectNode();
232 dev4Config.init(DEV4, "host-handler-test", dev4Tree, mapper, delegate);
233 dev4Config.setPairDeviceId(DEV3).setPairLocalPort(P9);
234
235 MockNetworkConfigRegistry mockNetworkConfigRegistry = new MockNetworkConfigRegistry();
236 mockNetworkConfigRegistry.applyConfig(dev3Config);
237 mockNetworkConfigRegistry.applyConfig(dev4Config);
238
239 // Initialize Segment Routing Manager
Charles Chanfab61472021-06-14 23:31:23 -0700240 SegmentRoutingManager srManager = new MockSegmentRoutingManager(NEXT_TABLE, Maps.newHashMap());
Charles Chand66d6712018-03-29 16:03:41 -0700241 srManager.storageService = createMock(StorageService.class);
pierventre37dcf4c2021-09-16 18:43:06 +0200242 expect(srManager.storageService.consistentMapBuilder()).andReturn(
243 new TestConsistentMap.Builder<>()).anyTimes();
pierf331a492020-01-07 15:39:39 +0100244 expect(srManager.storageService.consistentMultimapBuilder()).andReturn(
245 new TestConsistentMultimap.Builder<>()).anyTimes();
Charles Chand66d6712018-03-29 16:03:41 -0700246 replay(srManager.storageService);
Charles Chan114aec72017-06-19 14:00:53 -0700247 srManager.cfgService = new NetworkConfigRegistryAdapter();
248 srManager.deviceConfiguration = new DeviceConfiguration(srManager);
Charles Chan6c624992017-08-18 17:11:34 -0700249 srManager.flowObjectiveService = new MockFlowObjectiveService(BRIDGING_TABLE, NEXT_TABLE);
250 srManager.routingRulePopulator = new MockRoutingRulePopulator(srManager, ROUTING_TABLE);
pierventre37dcf4c2021-09-16 18:43:06 +0200251 srManager.defaultRoutingHandler = new MockDefaultRoutingHandler(srManager, SUBNET_TABLE,
252 ROUTING_TABLE, LED_DEVICES);
Charles Chan6c624992017-08-18 17:11:34 -0700253 srManager.interfaceService = new MockInterfaceService(INTERFACES);
Charles Chan6c624992017-08-18 17:11:34 -0700254 srManager.hostService = new MockHostService(HOSTS);
255 srManager.cfgService = mockNetworkConfigRegistry;
Charles Chanc6bcdf92018-06-01 16:33:48 -0700256 mockLocationProbingService = new MockHostProbingService();
Charles Chan873661e2017-11-30 15:37:50 -0800257 srManager.probingService = mockLocationProbingService;
Saurav Dase6c448a2018-01-18 12:07:33 -0800258 srManager.linkHandler = new MockLinkHandler(srManager);
Charles Chan114aec72017-06-19 14:00:53 -0700259
Charles Chanbd84dd52018-06-21 19:07:12 -0700260 // Not important for most of the HostHandler test case. Simply return an empty set here
261 srManager.routeService = createNiceMock(RouteService.class);
262 expect(srManager.routeService.getRouteTables()).andReturn(Sets.newHashSet()).anyTimes();
263 replay(srManager.routeService);
264
Charles Chan114aec72017-06-19 14:00:53 -0700265 hostHandler = new HostHandler(srManager);
piercf557922019-05-17 20:47:06 +0200266 hostHandler.hostWorkers = new PredictableExecutor(
267 0, groupedThreads("onos/sr", "h-worker-%d"), true);
Charles Chan114aec72017-06-19 14:00:53 -0700268
Charles Chan6c624992017-08-18 17:11:34 -0700269 ROUTING_TABLE.clear();
270 BRIDGING_TABLE.clear();
Charles Chan114aec72017-06-19 14:00:53 -0700271 }
272
273 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700274 public void init() {
Charles Chand9265a32017-06-16 15:19:24 -0700275 hostHandler.init(DEV1);
Charles Chan6c624992017-08-18 17:11:34 -0700276 assertEquals(1, ROUTING_TABLE.size());
277 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
278 assertEquals(1, BRIDGING_TABLE.size());
279 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chand9265a32017-06-16 15:19:24 -0700280
281 hostHandler.init(DEV2);
Charles Chan6c624992017-08-18 17:11:34 -0700282 assertEquals(2, ROUTING_TABLE.size());
283 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
284 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())));
285 assertEquals(2, BRIDGING_TABLE.size());
286 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
287 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chand9265a32017-06-16 15:19:24 -0700288 }
289
290 @Test(expected = IllegalArgumentException.class)
Charles Chan6e90fbb2018-07-23 15:27:34 -0700291 public void testHostAddedAtWrongLocation() {
Charles Chand9265a32017-06-16 15:19:24 -0700292 hostHandler.processHostAddedAtLocation(HOST1, HOST_LOC13);
293 }
294
295
296 @Test()
Charles Chan6e90fbb2018-07-23 15:27:34 -0700297 public void testHostAddedAtCorrectLocation() {
Charles Chand9265a32017-06-16 15:19:24 -0700298 hostHandler.processHostAddedAtLocation(HOST1, HOST_LOC11);
Charles Chan6c624992017-08-18 17:11:34 -0700299 assertEquals(1, ROUTING_TABLE.size());
300 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
301 assertEquals(1, BRIDGING_TABLE.size());
302 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chan114aec72017-06-19 14:00:53 -0700303 }
304
305 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700306 public void testHostAdded() {
Charles Chan114aec72017-06-19 14:00:53 -0700307 Host subject;
308
309 // Untagged host discovered on untagged port
310 // Expect: add one routing rule and one bridging rule
311 subject = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
Charles Chand9265a32017-06-16 15:19:24 -0700312 Sets.newHashSet(HOST_LOC11), Sets.newHashSet(HOST_IP11), false);
Charles Chan114aec72017-06-19 14:00:53 -0700313 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, subject));
Charles Chan6c624992017-08-18 17:11:34 -0700314 assertEquals(1, ROUTING_TABLE.size());
315 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
316 assertEquals(1, BRIDGING_TABLE.size());
317 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chan114aec72017-06-19 14:00:53 -0700318
319 // Untagged host discovered on tagged/native port
320 // Expect: add one routing rule and one bridging rule
321 subject = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
Charles Chand9265a32017-06-16 15:19:24 -0700322 Sets.newHashSet(HOST_LOC13), Sets.newHashSet(HOST_IP21), false);
Charles Chan114aec72017-06-19 14:00:53 -0700323 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, subject));
Charles Chan6c624992017-08-18 17:11:34 -0700324 assertEquals(2, ROUTING_TABLE.size());
325 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP21.toIpPrefix())));
326 assertEquals(2, BRIDGING_TABLE.size());
327 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_NATIVE)));
Charles Chan114aec72017-06-19 14:00:53 -0700328
329 // Tagged host discovered on untagged port
330 // Expect: ignore the host. No rule is added.
331 subject = new DefaultHost(PROVIDER_ID, HOST_ID_TAGGED, HOST_MAC, HOST_VLAN_TAGGED,
Charles Chand9265a32017-06-16 15:19:24 -0700332 Sets.newHashSet(HOST_LOC11), Sets.newHashSet(HOST_IP11), false);
Charles Chan114aec72017-06-19 14:00:53 -0700333 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, subject));
Charles Chan6c624992017-08-18 17:11:34 -0700334 assertEquals(2, ROUTING_TABLE.size());
335 assertEquals(2, BRIDGING_TABLE.size());
Charles Chan114aec72017-06-19 14:00:53 -0700336
337 // Tagged host discovered on tagged port with the same IP
338 // Expect: update existing route, add one bridging rule
339 subject = new DefaultHost(PROVIDER_ID, HOST_ID_TAGGED, HOST_MAC, HOST_VLAN_TAGGED,
Charles Chand9265a32017-06-16 15:19:24 -0700340 Sets.newHashSet(HOST_LOC13), Sets.newHashSet(HOST_IP21), false);
Charles Chan114aec72017-06-19 14:00:53 -0700341 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, subject));
Charles Chan6c624992017-08-18 17:11:34 -0700342 assertEquals(2, ROUTING_TABLE.size());
343 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP21.toIpPrefix())));
344 assertEquals(HOST_VLAN_TAGGED, ROUTING_TABLE.get(new MockRoutingTableKey(HOST_LOC13.deviceId(),
Charles Chand9265a32017-06-16 15:19:24 -0700345 HOST_IP21.toIpPrefix())).vlanId);
Charles Chan6c624992017-08-18 17:11:34 -0700346 assertEquals(3, BRIDGING_TABLE.size());
347 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, HOST_VLAN_TAGGED)));
Charles Chand9265a32017-06-16 15:19:24 -0700348 }
349
350 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700351 public void testDualHomedHostAdded() {
Charles Chand9265a32017-06-16 15:19:24 -0700352 // Add a dual-homed host that has 2 locations
353 // Expect: add two routing rules and two bridging rules
354 Host subject = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
355 Sets.newHashSet(HOST_LOC11, HOST_LOC21), Sets.newHashSet(HOST_IP11), false);
356 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, subject));
Charles Chan6c624992017-08-18 17:11:34 -0700357 assertEquals(2, ROUTING_TABLE.size());
358 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
359 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())));
360 assertEquals(2, BRIDGING_TABLE.size());
361 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
362 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chan114aec72017-06-19 14:00:53 -0700363 }
364
365 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700366 public void testSingleHomedHostAddedOnPairLeaf() {
Charles Chanceb2a2e2017-09-12 18:57:47 -0700367 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
Charles Chan6e90fbb2018-07-23 15:27:34 -0700368 Sets.newHashSet(HOST_LOC33), Sets.newHashSet(HOST_IP33), false);
Charles Chanceb2a2e2017-09-12 18:57:47 -0700369
370 // Add a single-homed host with one location
371 // Expect: the pair link should not be utilized
372 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
373 assertEquals(1, ROUTING_TABLE.size());
Charles Chan6e90fbb2018-07-23 15:27:34 -0700374 assertEquals(P3, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP33.toIpPrefix())).portNumber);
Charles Chanceb2a2e2017-09-12 18:57:47 -0700375 assertEquals(1, BRIDGING_TABLE.size());
Charles Chan6e90fbb2018-07-23 15:27:34 -0700376 assertEquals(P3, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_OTHER)).portNumber);
Charles Chanceb2a2e2017-09-12 18:57:47 -0700377 }
378
379 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700380 public void testDualHomedHostAddedOneByOne() {
Charles Chanceb2a2e2017-09-12 18:57:47 -0700381 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
382 Sets.newHashSet(HOST_LOC31), Sets.newHashSet(HOST_IP11), false);
383 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
384 Sets.newHashSet(HOST_LOC31, HOST_LOC41), Sets.newHashSet(HOST_IP11), false);
385
386 // Add a dual-homed host with one location
387 // Expect: the pair link is utilized temporarily before the second location is discovered
388 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
389 assertEquals(2, ROUTING_TABLE.size());
390 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP11.toIpPrefix())).portNumber);
391 assertEquals(P9, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
392 assertEquals(2, BRIDGING_TABLE.size());
393 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
394 assertEquals(P9, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chan873661e2017-11-30 15:37:50 -0800395 // Expect probe to be sent out on pair device
Charles Chanc6bcdf92018-06-01 16:33:48 -0700396 assertTrue(mockLocationProbingService.verifyProbe(host1, CP41, ProbeMode.DISCOVER));
Charles Chanceb2a2e2017-09-12 18:57:47 -0700397
398 // Add the second location of dual-homed host
399 // Expect: no longer use the pair link
400 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host1));
401 assertEquals(2, ROUTING_TABLE.size());
402 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP11.toIpPrefix())).portNumber);
Charles Chanfbcb8812018-04-18 18:41:05 -0700403 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
Charles Chanceb2a2e2017-09-12 18:57:47 -0700404 assertEquals(2, BRIDGING_TABLE.size());
405 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
406 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
407 }
408
409 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700410 public void testHostRemoved() {
Charles Chan114aec72017-06-19 14:00:53 -0700411 Host subject = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
Charles Chand9265a32017-06-16 15:19:24 -0700412 Sets.newHashSet(HOST_LOC11), Sets.newHashSet(HOST_IP11), false);
Charles Chan114aec72017-06-19 14:00:53 -0700413
414 // Add a host
415 // Expect: add one routing rule and one bridging rule
416 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, subject));
Charles Chan6c624992017-08-18 17:11:34 -0700417 assertEquals(1, ROUTING_TABLE.size());
418 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
419 assertEquals(1, BRIDGING_TABLE.size());
420 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chan114aec72017-06-19 14:00:53 -0700421
422 // Remove the host
423 // Expect: add the routing rule and the bridging rule
Charles Chand9265a32017-06-16 15:19:24 -0700424 hostHandler.processHostRemovedEvent(new HostEvent(HostEvent.Type.HOST_REMOVED, subject));
Charles Chan6c624992017-08-18 17:11:34 -0700425 assertEquals(0, ROUTING_TABLE.size());
426 assertEquals(0, BRIDGING_TABLE.size());
Charles Chand9265a32017-06-16 15:19:24 -0700427 }
428
429 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700430 public void testDualHomedHostRemoved() {
Charles Chand9265a32017-06-16 15:19:24 -0700431 // Add a dual-homed host that has 2 locations
432 // Expect: add two routing rules and two bridging rules
433 Host subject = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
434 Sets.newHashSet(HOST_LOC11, HOST_LOC21), Sets.newHashSet(HOST_IP11), false);
435 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, subject));
Charles Chan6c624992017-08-18 17:11:34 -0700436 assertEquals(2, ROUTING_TABLE.size());
437 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
438 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())));
439 assertEquals(2, BRIDGING_TABLE.size());
440 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
441 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chand9265a32017-06-16 15:19:24 -0700442
443 // Remove a dual-homed host that has 2 locations
444 // Expect: all routing and bridging rules are removed
445 hostHandler.processHostRemovedEvent(new HostEvent(HostEvent.Type.HOST_REMOVED, subject));
Charles Chan6c624992017-08-18 17:11:34 -0700446 assertEquals(0, ROUTING_TABLE.size());
447 assertEquals(0, BRIDGING_TABLE.size());
Charles Chan114aec72017-06-19 14:00:53 -0700448 }
449
450 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700451 public void testHostMoved() {
Charles Chan114aec72017-06-19 14:00:53 -0700452 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
Charles Chand9265a32017-06-16 15:19:24 -0700453 Sets.newHashSet(HOST_LOC11), Sets.newHashSet(HOST_IP11), false);
Charles Chan114aec72017-06-19 14:00:53 -0700454 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
Charles Chand9265a32017-06-16 15:19:24 -0700455 Sets.newHashSet(HOST_LOC21), Sets.newHashSet(HOST_IP11), false);
Charles Chan114aec72017-06-19 14:00:53 -0700456 Host host3 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
Charles Chand9265a32017-06-16 15:19:24 -0700457 Sets.newHashSet(HOST_LOC13), Sets.newHashSet(HOST_IP11), false);
Charles Chan114aec72017-06-19 14:00:53 -0700458
459 // Add a host
Charles Chan3ed34d82017-06-22 18:03:14 -0700460 // Expect: add one new routing rule, one new bridging rule
Charles Chan114aec72017-06-19 14:00:53 -0700461 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
Charles Chan6c624992017-08-18 17:11:34 -0700462 assertEquals(1, ROUTING_TABLE.size());
463 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
464 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP21.toIpPrefix())));
465 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP13.toIpPrefix())));
466 assertEquals(1, BRIDGING_TABLE.size());
467 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
468 assertNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chan114aec72017-06-19 14:00:53 -0700469
Charles Chand9265a32017-06-16 15:19:24 -0700470 // Move the host to CP13, which has different subnet setting
Charles Chan114aec72017-06-19 14:00:53 -0700471 // Expect: remove routing rule. Change vlan in bridging rule.
Charles Chand9265a32017-06-16 15:19:24 -0700472 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host3, host1));
Charles Chan6c624992017-08-18 17:11:34 -0700473 assertEquals(0, ROUTING_TABLE.size());
474 assertEquals(1, BRIDGING_TABLE.size());
475 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_NATIVE)));
476 assertNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chan114aec72017-06-19 14:00:53 -0700477
Charles Chand9265a32017-06-16 15:19:24 -0700478 // Move the host to CP21, which has same subnet setting
Charles Chan114aec72017-06-19 14:00:53 -0700479 // Expect: add a new routing rule. Change vlan in bridging rule.
Charles Chand9265a32017-06-16 15:19:24 -0700480 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host3));
Charles Chan6c624992017-08-18 17:11:34 -0700481 assertEquals(1, ROUTING_TABLE.size());
482 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
483 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
484 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())));
485 assertEquals(1, BRIDGING_TABLE.size());
486 assertNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
487 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chand9265a32017-06-16 15:19:24 -0700488 }
489
490 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700491 public void testDualHomedHostMoved() {
Charles Chand9265a32017-06-16 15:19:24 -0700492 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
493 Sets.newHashSet(HOST_LOC11, HOST_LOC21), Sets.newHashSet(HOST_IP11, HOST_IP12), false);
494 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
495 Sets.newHashSet(HOST_LOC12, HOST_LOC22), Sets.newHashSet(HOST_IP11, HOST_IP12), false);
496 Host host3 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
497 Sets.newHashSet(HOST_LOC11, HOST_LOC21), Sets.newHashSet(HOST_IP13, HOST_IP14), false);
498 Host host4 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
499 Sets.newHashSet(HOST_LOC11, HOST_LOC22), Sets.newHashSet(HOST_IP12, HOST_IP13), false);
Charles Chan4b5769a2018-04-25 18:51:46 -0400500 Host host5 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
501 Sets.newHashSet(HOST_LOC12, HOST_LOC21), Sets.newHashSet(HOST_IP11, HOST_IP12), false);
502
Charles Chand9265a32017-06-16 15:19:24 -0700503
504 // Add a host with IP11, IP12 and LOC11, LOC21
505 // Expect: 4 routing rules and 2 bridging rules
506 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
Charles Chan6c624992017-08-18 17:11:34 -0700507 assertEquals(4, ROUTING_TABLE.size());
508 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())).portNumber);
509 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP12.toIpPrefix())).portNumber);
510 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())).portNumber);
511 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP12.toIpPrefix())).portNumber);
512 assertEquals(2, BRIDGING_TABLE.size());
513 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
514 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chand9265a32017-06-16 15:19:24 -0700515
Charles Chan4b5769a2018-04-25 18:51:46 -0400516 // Move the host to LOC12, LOC21 and keep the IP
517 // Expect: 4 routing rules and 2 bridging rules all at the new location
518 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host5, host1));
519 assertEquals(4, ROUTING_TABLE.size());
520 assertEquals(P2, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())).portNumber);
521 assertEquals(P2, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP12.toIpPrefix())).portNumber);
522 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())).portNumber);
523 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP12.toIpPrefix())).portNumber);
524 assertEquals(2, BRIDGING_TABLE.size());
525 assertEquals(P2, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
526 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
527
Charles Chand9265a32017-06-16 15:19:24 -0700528 // Move the host to LOC12, LOC22 and keep the IP
529 // Expect: 4 routing rules and 2 bridging rules all at the new location
Charles Chan4b5769a2018-04-25 18:51:46 -0400530 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host5));
Charles Chan6c624992017-08-18 17:11:34 -0700531 assertEquals(4, ROUTING_TABLE.size());
532 assertEquals(P2, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())).portNumber);
533 assertEquals(P2, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP12.toIpPrefix())).portNumber);
534 assertEquals(P2, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())).portNumber);
535 assertEquals(P2, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP12.toIpPrefix())).portNumber);
536 assertEquals(2, BRIDGING_TABLE.size());
537 assertEquals(P2, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
538 assertEquals(P2, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chand9265a32017-06-16 15:19:24 -0700539
540 // Move the host to LOC11, LOC21 and change the IP to IP13, IP14 at the same time
541 // Expect: 4 routing rules and 2 bridging rules all at the new location
542 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host3, host2));
Charles Chan6c624992017-08-18 17:11:34 -0700543 assertEquals(4, ROUTING_TABLE.size());
544 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP13.toIpPrefix())).portNumber);
545 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP14.toIpPrefix())).portNumber);
546 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP13.toIpPrefix())).portNumber);
547 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP14.toIpPrefix())).portNumber);
548 assertEquals(2, BRIDGING_TABLE.size());
549 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
550 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chand9265a32017-06-16 15:19:24 -0700551
552 // Move the host to LOC11, LOC22 and change the IP to IP12, IP13 at the same time
553 // Expect: 4 routing rules and 2 bridging rules all at the new location
554 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host4, host3));
Charles Chan6c624992017-08-18 17:11:34 -0700555 assertEquals(4, ROUTING_TABLE.size());
556 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP12.toIpPrefix())).portNumber);
557 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP13.toIpPrefix())).portNumber);
558 assertEquals(P2, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP12.toIpPrefix())).portNumber);
559 assertEquals(P2, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP13.toIpPrefix())).portNumber);
560 assertEquals(2, BRIDGING_TABLE.size());
561 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
562 assertEquals(P2, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chan114aec72017-06-19 14:00:53 -0700563 }
564
565 @Test
Charles Chan6d43c162018-10-11 12:35:36 -0700566 public void testDualHomedHostMoveTransient() {
567 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
568 Sets.newHashSet(HOST_LOC31, HOST_LOC41), Sets.newHashSet(HOST_IP11), false);
569 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
570 Sets.newHashSet(HOST_LOC32, HOST_LOC41), Sets.newHashSet(HOST_IP11), false);
571 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
572
573 // Mock DefaultRoutingHandler
574 DefaultRoutingHandler mockDefaultRoutingHandler = createMock(DefaultRoutingHandler.class);
575 hostHandler.srManager.defaultRoutingHandler = mockDefaultRoutingHandler;
576
577 // Host moved from [1A/1, 1B/1] to [1A/2, 1B/1]
578 // We should expect only one bridging flow and one routing flow programmed on 1A
Charles Chan12a8a842020-02-14 13:23:57 -0800579
580 expect(mockDefaultRoutingHandler.populateBridging(DEV3, P2, HOST_MAC, HOST_VLAN_UNTAGGED))
581 .andReturn(CompletableFuture.completedFuture(null)).once();
582 expect(mockDefaultRoutingHandler.populateRoute(DEV3, HOST_IP11.toIpPrefix(),
583 HOST_MAC, HOST_VLAN_UNTAGGED, P2, true))
584 .andReturn(CompletableFuture.completedFuture(null)).once();
Charles Chan6d43c162018-10-11 12:35:36 -0700585 replay(mockDefaultRoutingHandler);
586
587 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host1));
588 verify(mockDefaultRoutingHandler);
589 }
590
591 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700592 public void testHostMoveToInvalidLocation() {
Charles Chanabfe7e02017-08-09 16:50:15 -0700593 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
594 Sets.newHashSet(HOST_LOC11), Sets.newHashSet(HOST_IP11), false);
595 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
596 Sets.newHashSet(HOST_LOC51), Sets.newHashSet(HOST_IP11), false);
597
598 // Add a host
599 // Expect: add one new routing rule, one new bridging rule
600 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
Charles Chan6c624992017-08-18 17:11:34 -0700601 assertEquals(1, ROUTING_TABLE.size());
602 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
603 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP21.toIpPrefix())));
604 assertEquals(1, BRIDGING_TABLE.size());
605 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
606 assertNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chanabfe7e02017-08-09 16:50:15 -0700607
608 // Move the host to an invalid location
609 // Expect: Old flow is removed. New flow is not created
610 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host1));
Charles Chan6c624992017-08-18 17:11:34 -0700611 assertEquals(0, ROUTING_TABLE.size());
612 assertEquals(0, BRIDGING_TABLE.size());
Charles Chanabfe7e02017-08-09 16:50:15 -0700613
614 // Move the host to a valid location
615 // Expect: add one new routing rule, one new bridging rule
616 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host1, host2));
Charles Chan6c624992017-08-18 17:11:34 -0700617 assertEquals(1, ROUTING_TABLE.size());
618 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
619 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP21.toIpPrefix())));
620 assertEquals(1, BRIDGING_TABLE.size());
621 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
622 assertNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chanabfe7e02017-08-09 16:50:15 -0700623 }
624
625 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700626 public void testDualHomedHostMoveToInvalidLocation() {
Charles Chanabfe7e02017-08-09 16:50:15 -0700627 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
628 Sets.newHashSet(HOST_LOC11, HOST_LOC21), Sets.newHashSet(HOST_IP11), false);
629 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
630 Sets.newHashSet(HOST_LOC11, HOST_LOC51), Sets.newHashSet(HOST_IP11), false);
631 Host host3 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
632 Sets.newHashSet(HOST_LOC61, HOST_LOC51), Sets.newHashSet(HOST_IP11), false);
633
634 // Add a host
635 // Expect: add two new routing rules, two new bridging rules
636 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
Charles Chan6c624992017-08-18 17:11:34 -0700637 assertEquals(2, ROUTING_TABLE.size());
638 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())).portNumber);
639 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())).portNumber);
640 assertEquals(2, BRIDGING_TABLE.size());
641 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
642 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chanabfe7e02017-08-09 16:50:15 -0700643
644 // Move first host location to an invalid location
645 // Expect: One routing and one bridging flow
646 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host1));
Charles Chan6c624992017-08-18 17:11:34 -0700647 assertEquals(1, ROUTING_TABLE.size());
648 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())).portNumber);
649 assertEquals(1, BRIDGING_TABLE.size());
650 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chanabfe7e02017-08-09 16:50:15 -0700651
652 // Move second host location to an invalid location
653 // Expect: No routing or bridging rule
654 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host3, host2));
Charles Chan6c624992017-08-18 17:11:34 -0700655 assertEquals(0, ROUTING_TABLE.size());
656 assertEquals(0, BRIDGING_TABLE.size());
Charles Chanabfe7e02017-08-09 16:50:15 -0700657
658 // Move second host location back to a valid location
659 // Expect: One routing and one bridging flow
660 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host3));
Charles Chan6c624992017-08-18 17:11:34 -0700661 assertEquals(1, ROUTING_TABLE.size());
662 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())).portNumber);
663 assertEquals(1, BRIDGING_TABLE.size());
664 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chanabfe7e02017-08-09 16:50:15 -0700665
666 // Move first host location back to a valid location
667 // Expect: Two routing and two bridging flow
668 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host1, host2));
Charles Chan6c624992017-08-18 17:11:34 -0700669 assertEquals(2, ROUTING_TABLE.size());
670 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())).portNumber);
671 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())).portNumber);
672 assertEquals(2, BRIDGING_TABLE.size());
673 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
674 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chanabfe7e02017-08-09 16:50:15 -0700675 }
676
677 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700678 public void testDualHomingSingleLocationFail() {
Charles Chan3ed34d82017-06-22 18:03:14 -0700679 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
680 Sets.newHashSet(HOST_LOC31, HOST_LOC41), Sets.newHashSet(HOST_IP11, HOST_IP12), false);
681 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
682 Sets.newHashSet(HOST_LOC31), Sets.newHashSet(HOST_IP11, HOST_IP12), false);
683
684 // Add a host
685 // Expect: add four new routing rules, two new bridging rules
686 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
Charles Chan6c624992017-08-18 17:11:34 -0700687 assertEquals(4, ROUTING_TABLE.size());
688 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP11.toIpPrefix())).portNumber);
689 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP12.toIpPrefix())).portNumber);
690 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
691 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP12.toIpPrefix())).portNumber);
692 assertEquals(2, BRIDGING_TABLE.size());
693 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
694 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chan3ed34d82017-06-22 18:03:14 -0700695
696 // Host becomes single-homed
697 // Expect: redirect flows from host location to pair link
698 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host1));
Charles Chan6c624992017-08-18 17:11:34 -0700699 assertEquals(4, ROUTING_TABLE.size());
700 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP11.toIpPrefix())).portNumber);
701 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP12.toIpPrefix())).portNumber);
702 assertEquals(P9, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
703 assertEquals(P9, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP12.toIpPrefix())).portNumber);
704 assertEquals(2, BRIDGING_TABLE.size());
705 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
706 assertEquals(P9, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chan3ed34d82017-06-22 18:03:14 -0700707
708 // Host becomes dual-homed again
709 // Expect: Redirect flows from pair link back to host location
710 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host1, host2));
Charles Chan6c624992017-08-18 17:11:34 -0700711 assertEquals(4, ROUTING_TABLE.size());
712 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP11.toIpPrefix())).portNumber);
713 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP12.toIpPrefix())).portNumber);
Charles Chan873661e2017-11-30 15:37:50 -0800714 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
715 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP12.toIpPrefix())).portNumber);
Charles Chanfbcb8812018-04-18 18:41:05 -0700716 assertEquals(2, BRIDGING_TABLE.size());
717 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chan6c624992017-08-18 17:11:34 -0700718 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chan3ed34d82017-06-22 18:03:14 -0700719 }
720
721 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700722 public void testDualHomingBothLocationFail() {
Charles Chan3ed34d82017-06-22 18:03:14 -0700723 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
724 Sets.newHashSet(HOST_LOC31, HOST_LOC41), Sets.newHashSet(HOST_IP11, HOST_IP12), false);
725 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
726 Sets.newHashSet(HOST_LOC31), Sets.newHashSet(HOST_IP11, HOST_IP12), false);
727
728 // Add a host
729 // Expect: add four new routing rules, two new bridging rules
730 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
Charles Chan6c624992017-08-18 17:11:34 -0700731 assertEquals(4, ROUTING_TABLE.size());
732 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP11.toIpPrefix())).portNumber);
733 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP12.toIpPrefix())).portNumber);
734 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
735 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP12.toIpPrefix())).portNumber);
736 assertEquals(2, BRIDGING_TABLE.size());
737 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
738 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chan3ed34d82017-06-22 18:03:14 -0700739
740 // Host becomes single-homed
741 // Expect: redirect flows from host location to pair link
742 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host1));
Charles Chan6c624992017-08-18 17:11:34 -0700743 assertEquals(4, ROUTING_TABLE.size());
744 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP11.toIpPrefix())).portNumber);
745 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP12.toIpPrefix())).portNumber);
746 assertEquals(P9, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
747 assertEquals(P9, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP12.toIpPrefix())).portNumber);
748 assertEquals(2, BRIDGING_TABLE.size());
749 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
750 assertEquals(P9, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chan3ed34d82017-06-22 18:03:14 -0700751
752 // Host loses both locations
753 // Expect: Remove last location and all previous redirection flows
754 hostHandler.processHostRemovedEvent(new HostEvent(HostEvent.Type.HOST_REMOVED, host2));
Charles Chan6c624992017-08-18 17:11:34 -0700755 assertEquals(0, ROUTING_TABLE.size());
756 assertEquals(0, BRIDGING_TABLE.size());
Charles Chan3ed34d82017-06-22 18:03:14 -0700757 }
758
759 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700760 public void testHostUpdated() {
Charles Chan114aec72017-06-19 14:00:53 -0700761 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
Charles Chand9265a32017-06-16 15:19:24 -0700762 Sets.newHashSet(HOST_LOC11), Sets.newHashSet(HOST_IP11), false);
Charles Chan114aec72017-06-19 14:00:53 -0700763 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
Charles Chand9265a32017-06-16 15:19:24 -0700764 Sets.newHashSet(HOST_LOC11), Sets.newHashSet(HOST_IP21), false);
Charles Chan114aec72017-06-19 14:00:53 -0700765 Host host3 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
Charles Chand9265a32017-06-16 15:19:24 -0700766 Sets.newHashSet(HOST_LOC11), Sets.newHashSet(HOST_IP12), false);
Charles Chan114aec72017-06-19 14:00:53 -0700767
768 // Add a host
Charles Chand9265a32017-06-16 15:19:24 -0700769 // Expect: add one new routing rule. Add one new bridging rule.
Charles Chan114aec72017-06-19 14:00:53 -0700770 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
Charles Chan6c624992017-08-18 17:11:34 -0700771 assertEquals(1, ROUTING_TABLE.size());
772 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
773 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP21.toIpPrefix())));
774 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP12.toIpPrefix())));
775 assertEquals(1, BRIDGING_TABLE.size());
776 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(HOST_LOC11.deviceId(), HOST_MAC,
777 INTF_VLAN_UNTAGGED)));
Charles Chan114aec72017-06-19 14:00:53 -0700778
779 // Update the host IP to same subnet
780 // Expect: update routing rule with new IP. No change to bridging rule.
781 hostHandler.processHostUpdatedEvent(new HostEvent(HostEvent.Type.HOST_UPDATED, host3, host1));
Charles Chan6c624992017-08-18 17:11:34 -0700782 assertEquals(1, ROUTING_TABLE.size());
783 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
784 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP21.toIpPrefix())));
785 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP12.toIpPrefix())));
786 assertEquals(1, BRIDGING_TABLE.size());
787 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chan114aec72017-06-19 14:00:53 -0700788
789 // Update the host IP to different subnet
790 // Expect: Remove routing rule. No change to bridging rule.
791 hostHandler.processHostUpdatedEvent(new HostEvent(HostEvent.Type.HOST_UPDATED, host2, host3));
Charles Chan6c624992017-08-18 17:11:34 -0700792 assertEquals(0, ROUTING_TABLE.size());
793 assertEquals(1, BRIDGING_TABLE.size());
794 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chand9265a32017-06-16 15:19:24 -0700795 }
796
797 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700798 public void testDelayedIpAndLocation() {
Charles Chanb3c1faf2017-11-20 08:46:24 -0800799 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
800 Sets.newHashSet(HOST_LOC31), Sets.newHashSet(), false);
801 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
802 Sets.newHashSet(HOST_LOC31), Sets.newHashSet(HOST_IP11), false);
803 Host host3 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
804 Sets.newHashSet(HOST_LOC31, HOST_LOC41), Sets.newHashSet(HOST_IP11), false);
805
806 // Add a dual-home host with only one location and no IP
807 // Expect: only bridging redirection works
808 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
809 assertEquals(0, ROUTING_TABLE.size());
810 assertEquals(2, BRIDGING_TABLE.size());
811 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
812 assertEquals(P9, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
813
814 // Discover IP
815 // Expect: routing redirection should also work
Charles Chan873661e2017-11-30 15:37:50 -0800816 hostHandler.processHostUpdatedEvent(new HostEvent(HostEvent.Type.HOST_UPDATED, host2, host1));
Charles Chanb3c1faf2017-11-20 08:46:24 -0800817 assertEquals(2, ROUTING_TABLE.size());
818 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP11.toIpPrefix())).portNumber);
819 assertEquals(P9, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
820 assertEquals(2, BRIDGING_TABLE.size());
821 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
822 assertEquals(P9, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chan873661e2017-11-30 15:37:50 -0800823 // Expect probe to be sent out on pair device
Charles Chanc6bcdf92018-06-01 16:33:48 -0700824 assertTrue(mockLocationProbingService.verifyProbe(host2, CP41, ProbeMode.DISCOVER));
Charles Chanb3c1faf2017-11-20 08:46:24 -0800825
826 // Discover location
827 // Expect: cancel all redirections
Charles Chan873661e2017-11-30 15:37:50 -0800828 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host3, host2));
Charles Chanb3c1faf2017-11-20 08:46:24 -0800829 assertEquals(2, ROUTING_TABLE.size());
830 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP11.toIpPrefix())).portNumber);
Charles Chanfbcb8812018-04-18 18:41:05 -0700831 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
Charles Chanb3c1faf2017-11-20 08:46:24 -0800832 assertEquals(2, BRIDGING_TABLE.size());
833 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chanfbcb8812018-04-18 18:41:05 -0700834 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
Charles Chan873661e2017-11-30 15:37:50 -0800835 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
Charles Chanb3c1faf2017-11-20 08:46:24 -0800836 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
837 }
838
839 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700840 public void testDelayedIpAndLocation2() {
Charles Chanb3c1faf2017-11-20 08:46:24 -0800841 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
842 Sets.newHashSet(HOST_LOC31), Sets.newHashSet(), false);
843 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
844 Sets.newHashSet(HOST_LOC31, HOST_LOC41), Sets.newHashSet(), false);
845 Host host3 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
846 Sets.newHashSet(HOST_LOC31, HOST_LOC41), Sets.newHashSet(HOST_IP11), false);
847
848 // Add a dual-home host with only one location and no IP
849 // Expect: only bridging redirection works
850 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
851 assertEquals(0, ROUTING_TABLE.size());
852 assertEquals(2, BRIDGING_TABLE.size());
853 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
854 assertEquals(P9, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
855
856 // Discover Location
857 // Expect: cancel bridging redirections
858 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host1));
859 assertEquals(0, ROUTING_TABLE.size());
860 assertEquals(2, BRIDGING_TABLE.size());
861 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
862 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
863
864 // Discover IP
865 // Expect: add IP rules to both location
866 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_UPDATED, host3, host2));
867 assertEquals(2, ROUTING_TABLE.size());
868 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP11.toIpPrefix())).portNumber);
869 assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
870 assertEquals(2, BRIDGING_TABLE.size());
871 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
872 assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
873 }
874
875 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700876 public void testDualHomedHostUpdated() {
Charles Chand9265a32017-06-16 15:19:24 -0700877 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
878 Sets.newHashSet(HOST_LOC11, HOST_LOC21), Sets.newHashSet(HOST_IP11, HOST_IP12), false);
879 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
880 Sets.newHashSet(HOST_LOC11, HOST_LOC21), Sets.newHashSet(HOST_IP11, HOST_IP21), false);
881 Host host3 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
882 Sets.newHashSet(HOST_LOC11, HOST_LOC21), Sets.newHashSet(HOST_IP13, HOST_IP14), false);
883
884 // Add a dual-homed host with two locations and two IPs
885 // Expect: add four new routing rules. Add two new bridging rules
886 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
Charles Chan6c624992017-08-18 17:11:34 -0700887 assertEquals(4, ROUTING_TABLE.size());
888 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
889 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP12.toIpPrefix())));
890 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())));
891 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP12.toIpPrefix())));
892 assertEquals(2, BRIDGING_TABLE.size());
893 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
894 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chand9265a32017-06-16 15:19:24 -0700895
896 // Update both host IPs
897 // Expect: update routing rules with new IP. No change to bridging rule.
898 hostHandler.processHostUpdatedEvent(new HostEvent(HostEvent.Type.HOST_UPDATED, host3, host1));
Charles Chan6c624992017-08-18 17:11:34 -0700899 assertEquals(4, ROUTING_TABLE.size());
900 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
901 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP12.toIpPrefix())));
902 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP13.toIpPrefix())));
903 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP14.toIpPrefix())));
904 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())));
905 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP12.toIpPrefix())));
906 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP13.toIpPrefix())));
907 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP14.toIpPrefix())));
908 assertEquals(2, BRIDGING_TABLE.size());
909 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
910 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chand9265a32017-06-16 15:19:24 -0700911
912 // Update one of the host IP to different subnet
913 // Expect: update routing rule with new IP. No change to bridging rule.
914 hostHandler.processHostUpdatedEvent(new HostEvent(HostEvent.Type.HOST_UPDATED, host2, host3));
Charles Chan6c624992017-08-18 17:11:34 -0700915 assertEquals(2, ROUTING_TABLE.size());
916 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
917 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP21.toIpPrefix())));
918 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP12.toIpPrefix())));
919 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP11.toIpPrefix())));
920 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP21.toIpPrefix())));
921 assertNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV2, HOST_IP12.toIpPrefix())));
922 assertEquals(2, BRIDGING_TABLE.size());
923 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
924 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV2, HOST_MAC, INTF_VLAN_UNTAGGED)));
Charles Chand9265a32017-06-16 15:19:24 -0700925 }
Charles Chan868c9572018-06-15 18:54:18 -0700926
927 @Test
928 public void testVlanForPairPort() {
929 assertEquals(INTF_VLAN_UNTAGGED, hostHandler.vlanForPairPort(VlanId.NONE, CP11));
930 assertEquals(INTF_VLAN_NATIVE, hostHandler.vlanForPairPort(VlanId.NONE, CP13));
931 assertEquals(INTF_VLAN_TAGGED_1, hostHandler.vlanForPairPort(INTF_VLAN_TAGGED_1, CP13));
932 assertNull(hostHandler.vlanForPairPort(INTF_VLAN_UNTAGGED, CP11));
933 assertNull(hostHandler.vlanForPairPort(INTF_VLAN_UNTAGGED, CP13));
934 assertNull(hostHandler.vlanForPairPort(VlanId.NONE, CP51));
935 assertNull(hostHandler.vlanForPairPort(INTF_VLAN_UNTAGGED, CP51));
936 }
Charles Chanbd84dd52018-06-21 19:07:12 -0700937
938 @Test
Charles Chan6e90fbb2018-07-23 15:27:34 -0700939 public void testHostRemovedWithRouteRemoved() {
Charles Chanbd84dd52018-06-21 19:07:12 -0700940 Host subject = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
941 Sets.newHashSet(HOST_LOC11), Sets.newHashSet(HOST_IP11), false);
942
943 // Add a host
944 // Expect: add one routing rule and one bridging rule
945 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, subject));
946 assertEquals(1, ROUTING_TABLE.size());
947 assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
948 assertEquals(1, BRIDGING_TABLE.size());
949 assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
950
951 IpPrefix prefix = IpPrefix.valueOf("55.55.55.0/24");
952
953 // Setting up mock route service
954 RouteService routeService = hostHandler.srManager.routeService;
955 reset(routeService);
956
957 IpAddress nextHopIp2 = IpAddress.valueOf("20.0.0.1");
958 MacAddress nextHopMac2 = MacAddress.valueOf("00:22:33:44:55:66");
959 VlanId nextHopVlan2 = VlanId.NONE;
960
961 Route r1 = new Route(Route.Source.STATIC, prefix, HOST_IP11);
962 ResolvedRoute rr1 = new ResolvedRoute(r1, HOST_MAC, VlanId.NONE);
963 Route r2 = new Route(Route.Source.STATIC, prefix, nextHopIp2);
964 ResolvedRoute rr2 = new ResolvedRoute(r2, nextHopMac2, nextHopVlan2);
965 RouteInfo routeInfo = new RouteInfo(prefix, rr1, Sets.newHashSet(rr1, rr2));
966 RouteTableId routeTableId = new RouteTableId("ipv4");
967
968 expect(routeService.getRouteTables()).andReturn(Sets.newHashSet(routeTableId));
969 expect(routeService.getRoutes(routeTableId)).andReturn(Sets.newHashSet(routeInfo));
970 replay(routeService);
971
972 // Setting up mock device configuration
973 hostHandler.srManager.deviceConfiguration = EasyMock.createNiceMock(DeviceConfiguration.class);
974 DeviceConfiguration deviceConfiguration = hostHandler.srManager.deviceConfiguration;
975 expect(deviceConfiguration.inSameSubnet(CP11, HOST_IP11)).andReturn(true);
976 deviceConfiguration.removeSubnet(CP11, prefix);
977 expectLastCall();
978 replay(deviceConfiguration);
979
980 // Remove the host
981 // Expect: add the routing rule and the bridging rule
982 hostHandler.processHostRemovedEvent(new HostEvent(HostEvent.Type.HOST_REMOVED, subject));
983 assertEquals(0, ROUTING_TABLE.size());
984 assertEquals(0, BRIDGING_TABLE.size());
985
986 // Expect: subnet is removed from device config
987 verify(deviceConfiguration);
988 }
Charles Chan6e90fbb2018-07-23 15:27:34 -0700989
990 @Test
991 public void testHostProbing() {
992 // Case: [1A/1, 1B/1] -> [1A/2, 1B/1]
993 // Expect: DISCOVER probe should be sent to every port on 1B that has the same VLAN as 1A/2
994 // VERIFY probe should be sent to 1B/1
995 Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
996 Sets.newHashSet(HOST_LOC31, HOST_LOC41), Sets.newHashSet(HOST_IP11), false);
997 Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED,
998 Sets.newHashSet(HOST_LOC32, HOST_LOC41), Sets.newHashSet(HOST_IP11), false);
999 hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
1000
1001 hostHandler.srManager.probingService = createMock(HostProbingService.class);
1002 hostHandler.srManager.probingService.probeHost(host2, CP41, ProbeMode.DISCOVER);
1003 expectLastCall();
1004 hostHandler.srManager.probingService.probeHost(host2, CP42, ProbeMode.DISCOVER);
1005 expectLastCall();
1006 hostHandler.srManager.probingService.probeHost(host2, CP41, ProbeMode.VERIFY);
1007 expectLastCall();
1008 replay(hostHandler.srManager.probingService);
1009
1010 hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host1));
1011
1012 verify(hostHandler.srManager.probingService);
1013 }
Charles Chana2ccb582019-11-25 09:47:22 -08001014
1015 @Test
1016 public void testEffectiveLocations() {
1017 Host regularHost = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_TAGGED,
1018 Sets.newHashSet(HOST_LOC11, HOST_LOC12), Sets.newHashSet(HOST_IP11), false);
1019 Host auxHost = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_TAGGED,
1020 Sets.newHashSet(HOST_LOC11, HOST_LOC12), Sets.newHashSet(HOST_LOC21, HOST_LOC22),
1021 Sets.newHashSet(HOST_IP11), VlanId.NONE, EthType.EtherType.UNKNOWN.ethType(), false, false);
1022
1023 assertEquals(Sets.newHashSet(HOST_LOC11, HOST_LOC12), hostHandler.effectiveLocations(regularHost));
1024 assertEquals(Sets.newHashSet(HOST_LOC21, HOST_LOC22), hostHandler.effectiveLocations(auxHost));
1025 }
pierventre37dcf4c2021-09-16 18:43:06 +02001026
1027 @Test
1028 public void initOfNonLedDevices() {
1029 hostHandler.init(DEV5);
1030 assertEquals(0, ROUTING_TABLE.size());
1031 assertEquals(0, BRIDGING_TABLE.size());
1032
1033 hostHandler.init(DEV6);
1034 assertEquals(0, ROUTING_TABLE.size());
1035 assertEquals(0, BRIDGING_TABLE.size());
1036 }
Ray Milkeyc2d43be2017-08-03 11:58:29 -07001037}