blob: b199a9de5220b817641228080b5de0efc6e4e85e [file] [log] [blame]
samanwita pale7c08de2015-09-24 21:59:49 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
samanwita pale7c08de2015-09-24 21:59:49 -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 */
16package org.onosproject.store.host.impl;
17
Harshada Chaundkarc9712222019-07-02 15:13:24 +000018import com.google.common.collect.ImmutableSet;
samanwita pale7c08de2015-09-24 21:59:49 -070019import org.junit.After;
20import org.junit.Before;
21import org.junit.Test;
Charles Chan2a9492da2019-12-06 19:19:30 -080022import org.onlab.packet.EthType;
samanwita pale7c08de2015-09-24 21:59:49 -070023import org.onlab.packet.IpAddress;
24import org.onlab.packet.MacAddress;
Charles Chan2a9492da2019-12-06 19:19:30 -080025import org.onlab.packet.VlanId;
Harshada Chaundkarc9712222019-07-02 15:13:24 +000026import org.onosproject.net.ConnectPoint;
27import org.onosproject.net.DefaultHost;
28import org.onosproject.net.DeviceId;
samanwita pale7c08de2015-09-24 21:59:49 -070029import org.onosproject.net.Host;
30import org.onosproject.net.HostId;
31import org.onosproject.net.HostLocation;
Harshada Chaundkarc9712222019-07-02 15:13:24 +000032import org.onosproject.net.PortNumber;
samanwita pale7c08de2015-09-24 21:59:49 -070033import org.onosproject.net.host.DefaultHostDescription;
34import org.onosproject.net.host.HostDescription;
Charles Chan2a9492da2019-12-06 19:19:30 -080035import org.onosproject.net.host.HostEvent;
36import org.onosproject.net.host.HostStoreDelegate;
samanwita pale7c08de2015-09-24 21:59:49 -070037import org.onosproject.net.provider.ProviderId;
Harshada Chaundkarc9712222019-07-02 15:13:24 +000038import org.onosproject.store.service.MapEvent;
samanwita pale7c08de2015-09-24 21:59:49 -070039import org.onosproject.store.service.TestStorageService;
40
Deepa Vaddireddy0a71c8b2017-01-19 21:20:45 +053041import com.google.common.collect.Sets;
Harshada Chaundkarc9712222019-07-02 15:13:24 +000042import org.onosproject.store.service.Versioned;
Deepa Vaddireddy0a71c8b2017-01-19 21:20:45 +053043
Harshada Chaundkarc9712222019-07-02 15:13:24 +000044import java.util.Collections;
samanwita pale7c08de2015-09-24 21:59:49 -070045import java.util.HashSet;
46import java.util.Set;
47
Sho SHIMIZU53bcc242016-08-15 11:19:24 -070048import static junit.framework.TestCase.assertTrue;
Harshada Chaundkarc9712222019-07-02 15:13:24 +000049import static org.junit.Assert.*;
Sho SHIMIZU53bcc242016-08-15 11:19:24 -070050
samanwita pale7c08de2015-09-24 21:59:49 -070051/**
52 * Tests for the ECHostStore.
53 */
Sho SHIMIZU53bcc242016-08-15 11:19:24 -070054public class DistributedHostStoreTest {
samanwita pale7c08de2015-09-24 21:59:49 -070055
alshabib8a4a6002015-11-25 14:31:16 -080056 private DistributedHostStore ecXHostStore;
Charles Chan2a9492da2019-12-06 19:19:30 -080057 private TestStoreDelegate delegate;
samanwita pale7c08de2015-09-24 21:59:49 -070058
59 private static final HostId HOSTID = HostId.hostId(MacAddress.valueOf("1a:1a:1a:1a:1a:1a"));
Deepa Vaddireddy0a71c8b2017-01-19 21:20:45 +053060 private static final HostId HOSTID1 = HostId.hostId(MacAddress.valueOf("1a:1a:1a:1a:1a:1b"));
samanwita pale7c08de2015-09-24 21:59:49 -070061
62 private static final IpAddress IP1 = IpAddress.valueOf("10.2.0.2");
63 private static final IpAddress IP2 = IpAddress.valueOf("10.2.0.3");
64
65 private static final ProviderId PID = new ProviderId("of", "foo");
Charles Chanb1e99242017-07-07 14:11:09 -070066 private static final ProviderId PID2 = new ProviderId("of", "foo2");
67
68 private static final HostDescription HOST_LEARNT =
Harshada Chaundkarc9712222019-07-02 15:13:24 +000069 createHostDesc(HOSTID, Sets.newHashSet(IP1), false, Collections.emptySet());
Charles Chanb1e99242017-07-07 14:11:09 -070070 private static final HostDescription HOST_CONFIGURED =
Harshada Chaundkarc9712222019-07-02 15:13:24 +000071 createHostDesc(HOSTID, Sets.newHashSet(IP1), true, Collections.emptySet());
72 // Host with locations
73 private static final DeviceId DEV1 = DeviceId.deviceId("of:0000000000000001");
74 private static final PortNumber P1 = PortNumber.portNumber(1);
75 private static final PortNumber P2 = PortNumber.portNumber(2);
76 private static final ConnectPoint CP11 = new ConnectPoint(DEV1, P1);
77 private static final HostLocation HOST_LOC11 = new HostLocation(CP11, 0);
78 private static final ConnectPoint CP12 = new ConnectPoint(DEV1, P2);
79 private static final HostLocation HOST_LOC12 = new HostLocation(CP12, 0);
80 private static final Set<HostLocation> HOST_LOCATIONS = ImmutableSet.of(HOST_LOC11, HOST_LOC12);
81 private static final Set<HostLocation> HOST_LOCATION = ImmutableSet.of(HOST_LOC11);
82 private static final Set<HostLocation> NONE_LOCATION = ImmutableSet.of(HostLocation.NONE);
83 private static final Set<IpAddress> HOST_ADDRESS = ImmutableSet.of(IP1);
84 private static final Set<IpAddress> HOST_ADDRESSES = ImmutableSet.of(IP1, IP2);
85 private static final HostDescription HOST_LEARNT_WITH_LOCATIONS =
86 createHostDesc(HOSTID, HOST_ADDRESS, false, HOST_LOCATIONS);
87 private static final HostDescription HOST_LEARNT_WITH_ADDRESSES =
88 createHostDesc(HOSTID, Sets.newHashSet(IP1, IP2), false, Collections.emptySet());
89 private static final DefaultHost OLD_HOST = new DefaultHost(PID, HOSTID,
90 HOST_LEARNT_WITH_ADDRESSES.hwAddress(),
91 HOST_LEARNT_WITH_ADDRESSES.vlan(),
92 HOST_LEARNT_WITH_ADDRESSES.locations(),
93 HOST_LEARNT_WITH_ADDRESSES.ipAddress(),
94 HOST_LEARNT_WITH_ADDRESSES.configured(),
95 HOST_LEARNT_WITH_ADDRESSES.annotations());
96 private static final DefaultHost NEW_HOST = new DefaultHost(PID, HOSTID,
97 HOST_LEARNT_WITH_ADDRESSES.hwAddress(),
98 HOST_LEARNT_WITH_ADDRESSES.vlan(),
99 HOST_LEARNT_WITH_ADDRESSES.locations(),
100 HOST_ADDRESS,
101 HOST_LEARNT_WITH_ADDRESSES.configured(),
102 HOST_LEARNT_WITH_ADDRESSES.annotations());
Charles Chancef8a952020-03-08 17:41:11 -0700103
104 private static final HostDescription HOST_DESC_WITHOUT_AUX =
105 new DefaultHostDescription(HOSTID.mac(), HOSTID.vlanId(),
106 Sets.newHashSet(HOST_LOC11), null,
107 Sets.newHashSet(IP1, IP2), VlanId.NONE, EthType.EtherType.UNKNOWN.ethType(),
108 false);
109 private static final HostDescription HOST_DESC_WITH_AUX =
110 new DefaultHostDescription(HOSTID1.mac(), HOSTID1.vlanId(),
111 Sets.newHashSet(HOST_LOC11), Sets.newHashSet(HOST_LOC12),
112 Sets.newHashSet(IP1, IP2), VlanId.NONE, EthType.EtherType.UNKNOWN.ethType(),
113 false);
114 private static final Host HOST_WITHOUT_AUX =
115 new DefaultHost(PID, HOSTID,
116 HOST_DESC_WITHOUT_AUX.hwAddress(), HOST_DESC_WITHOUT_AUX.vlan(),
117 HOST_DESC_WITHOUT_AUX.locations(), HOST_DESC_WITHOUT_AUX.auxLocations(),
118 HOST_DESC_WITHOUT_AUX.ipAddress(), HOST_DESC_WITHOUT_AUX.innerVlan(), HOST_DESC_WITHOUT_AUX.tpid(),
119 HOST_DESC_WITHOUT_AUX.configured(), false);
120 private static final Host HOST_WITH_AUX =
121 new DefaultHost(PID, HOSTID1,
122 HOST_DESC_WITH_AUX.hwAddress(), HOST_DESC_WITH_AUX.vlan(),
123 HOST_DESC_WITH_AUX.locations(), HOST_DESC_WITH_AUX.auxLocations(),
124 HOST_DESC_WITH_AUX.ipAddress(), HOST_DESC_WITH_AUX.innerVlan(), HOST_DESC_WITH_AUX.tpid(),
125 HOST_DESC_WITH_AUX.configured(), false);
126
Harshada Chaundkarc9712222019-07-02 15:13:24 +0000127 private static final MapEvent<HostId, DefaultHost> HOST_EVENT =
128 new MapEvent<>("foobar", HOSTID, new Versioned<>(NEW_HOST, 0), new Versioned<>(OLD_HOST, 0));
Charles Chan2a9492da2019-12-06 19:19:30 -0800129 private static final DefaultHost HOST1 = new DefaultHost(PID, HOSTID, HOSTID.mac(), HOSTID.vlanId(),
130 Set.<HostLocation>of(HOST_LOC11), null,
131 Set.<IpAddress>of(), VlanId.NONE,
132 EthType.EtherType.UNKNOWN.ethType(), false, false);
133 private static final DefaultHost HOST2 = new DefaultHost(PID, HOSTID, HOSTID.mac(), HOSTID.vlanId(),
134 Set.<HostLocation>of(HOST_LOC11), null,
135 Set.<IpAddress>of(IP1), VlanId.NONE,
136 EthType.EtherType.UNKNOWN.ethType(), false, false);
137 private static final DefaultHost HOST3 = new DefaultHost(PID, HOSTID, HOSTID.mac(), HOSTID.vlanId(),
138 Set.<HostLocation>of(HOST_LOC11, HOST_LOC12), null,
139 Set.<IpAddress>of(IP1), VlanId.NONE,
140 EthType.EtherType.UNKNOWN.ethType(), false, false);
141 private static final DefaultHost HOST4 = new DefaultHost(PID, HOSTID, HOSTID.mac(), HOSTID.vlanId(),
142 Set.<HostLocation>of(HOST_LOC11), Set.<HostLocation>of(HOST_LOC12),
143 Set.<IpAddress>of(IP1), VlanId.NONE,
144 EthType.EtherType.UNKNOWN.ethType(), false, false);
samanwita pale7c08de2015-09-24 21:59:49 -0700145
146 @Before
147 public void setUp() {
alshabib8a4a6002015-11-25 14:31:16 -0800148 ecXHostStore = new DistributedHostStore();
samanwita pale7c08de2015-09-24 21:59:49 -0700149
Charles Chan2a9492da2019-12-06 19:19:30 -0800150 delegate = new TestStoreDelegate();
151 ecXHostStore.setDelegate(delegate);
152
samanwita pale7c08de2015-09-24 21:59:49 -0700153 ecXHostStore.storageService = new TestStorageService();
samanwita pale7c08de2015-09-24 21:59:49 -0700154 ecXHostStore.activate();
155 }
156
157 @After
158 public void tearDown() {
159 ecXHostStore.deactivate();
160 }
161
162 /**
163 * Tests the removeIp method call.
164 */
165 @Test
166 public void testRemoveIp() {
167 Set<IpAddress> ips = new HashSet<>();
168 ips.add(IP1);
169 ips.add(IP2);
170
Deepa Vaddireddy0a71c8b2017-01-19 21:20:45 +0530171 HostDescription description = createHostDesc(HOSTID, ips);
samanwita pale7c08de2015-09-24 21:59:49 -0700172 ecXHostStore.createOrUpdateHost(PID, HOSTID, description, false);
173 ecXHostStore.removeIp(HOSTID, IP1);
174 Host host = ecXHostStore.getHost(HOSTID);
175
176 assertFalse(host.ipAddresses().contains(IP1));
177 assertTrue(host.ipAddresses().contains(IP2));
178 }
179
Deepa Vaddireddy0a71c8b2017-01-19 21:20:45 +0530180 @Test
181 public void testAddHostByIp() {
182 Set<IpAddress> ips = new HashSet<>();
183 ips.add(IP1);
184 ips.add(IP2);
185
186 HostDescription description = createHostDesc(HOSTID, ips);
187 ecXHostStore.createOrUpdateHost(PID, HOSTID, description, false);
188
189 Set<Host> hosts = ecXHostStore.getHosts(IP1);
190
191 assertFalse(hosts.size() > 1);
192 assertTrue(hosts.size() == 1);
193
194 HostDescription description1 = createHostDesc(HOSTID1, Sets.newHashSet(IP2));
195 ecXHostStore.createOrUpdateHost(PID, HOSTID1, description1, false);
196
197 Set<Host> hosts1 = ecXHostStore.getHosts(IP2);
198
199 assertFalse(hosts1.size() < 1);
200 assertTrue(hosts1.size() == 2);
201 }
202
203 @Test
204 public void testRemoveHostByIp() {
205 Set<IpAddress> ips = new HashSet<>();
206 ips.add(IP1);
207 ips.add(IP2);
208
209 HostDescription description = createHostDesc(HOSTID, ips);
210 ecXHostStore.createOrUpdateHost(PID, HOSTID, description, false);
211 ecXHostStore.removeIp(HOSTID, IP1);
212 Set<Host> hosts = ecXHostStore.getHosts(IP1);
213 assertTrue(hosts.size() == 0);
214 }
215
Charles Chanb1e99242017-07-07 14:11:09 -0700216 @Test
217 public void testHostOverride() {
218 Host hostInStore;
219 ecXHostStore.createOrUpdateHost(PID, HOSTID, HOST_LEARNT, false);
220 hostInStore = ecXHostStore.getHost(HOSTID);
221 assertFalse(hostInStore.configured());
222 assertEquals(PID, hostInStore.providerId());
223
224 // Expect: configured host should override learnt host
225 ecXHostStore.createOrUpdateHost(PID2, HOSTID, HOST_CONFIGURED, true);
226 hostInStore = ecXHostStore.getHost(HOSTID);
227 assertTrue(hostInStore.configured());
228 assertEquals(PID2, hostInStore.providerId());
229
230 // Expect: learnt host should not override configured host
231 ecXHostStore.createOrUpdateHost(PID, HOSTID, HOST_LEARNT, false);
232 hostInStore = ecXHostStore.getHost(HOSTID);
233 assertTrue(hostInStore.configured());
234 assertEquals(PID2, hostInStore.providerId());
235 }
236
Harshada Chaundkarc9712222019-07-02 15:13:24 +0000237 @Test
238 public void testRemoteUpdateHostsByIp() {
239 // Add host in the store
240 ecXHostStore.createOrUpdateHost(PID, HOSTID, HOST_LEARNT_WITH_ADDRESSES, false);
241
242 // Expected a learnt host with an IP
243 Host hostInHostsByIp = ecXHostStore.getHosts(IP1).stream()
244 .findFirst().orElse(null);
245 assertNotNull(hostInHostsByIp);
246 assertFalse(hostInHostsByIp.configured());
247 assertEquals(HOSTID, hostInHostsByIp.id());
248 assertEquals(PID, hostInHostsByIp.providerId());
249 assertEquals(NONE_LOCATION, hostInHostsByIp.locations());
250 assertEquals(HOST_ADDRESSES, hostInHostsByIp.ipAddresses());
251
252 // Remove one ip - simulating the update in other instances
253 ecXHostStore.hostLocationTracker.event(HOST_EVENT);
254
255 // Expected null
256 hostInHostsByIp = ecXHostStore.getHosts(IP2).stream()
257 .findFirst().orElse(null);
258 assertNull(hostInHostsByIp);
259
260 // Expected an host with an ip address
261 hostInHostsByIp = ecXHostStore.getHosts(IP1).stream()
262 .findFirst().orElse(null);
263 assertNotNull(hostInHostsByIp);
264 assertFalse(hostInHostsByIp.configured());
265 assertEquals(HOSTID, hostInHostsByIp.id());
266 assertEquals(PID, hostInHostsByIp.providerId());
267 assertEquals(NONE_LOCATION, hostInHostsByIp.locations());
268 assertEquals(HOST_ADDRESS, hostInHostsByIp.ipAddresses());
269
270 }
271
272 @Test
273 public void testLocalUpdateHostsByIp() {
274 // Add host in the store
275 ecXHostStore.createOrUpdateHost(PID, HOSTID, HOST_LEARNT_WITH_ADDRESSES, false);
276
277 // Expected a learnt host with an IP
278 Host hostInHostsByIp = ecXHostStore.getHosts(IP1).stream()
279 .findFirst().orElse(null);
280 assertNotNull(hostInHostsByIp);
281 assertFalse(hostInHostsByIp.configured());
282 assertEquals(HOSTID, hostInHostsByIp.id());
283 assertEquals(PID, hostInHostsByIp.providerId());
284 assertEquals(NONE_LOCATION, hostInHostsByIp.locations());
285 assertEquals(HOST_ADDRESSES, hostInHostsByIp.ipAddresses());
286
287 // Remove one ip
288 ecXHostStore.removeIp(HOSTID, IP2);
289
290 // Expected null
291 hostInHostsByIp = ecXHostStore.getHosts(IP2).stream()
292 .findFirst().orElse(null);
293 assertNull(hostInHostsByIp);
294
295 // Expected an host with an ip address
296 hostInHostsByIp = ecXHostStore.getHosts(IP1).stream()
297 .findFirst().orElse(null);
298 assertNotNull(hostInHostsByIp);
299 assertFalse(hostInHostsByIp.configured());
300 assertEquals(HOSTID, hostInHostsByIp.id());
301 assertEquals(PID, hostInHostsByIp.providerId());
302 assertEquals(NONE_LOCATION, hostInHostsByIp.locations());
303 assertEquals(HOST_ADDRESS, hostInHostsByIp.ipAddresses());
304
305 }
306
307 @Test
308 public void testUpdateLocationInHostsByIp() {
309 // Add host in the store
310 ecXHostStore.createOrUpdateHost(PID, HOSTID, HOST_LEARNT_WITH_LOCATIONS, false);
311 Host hostInHosts = ecXHostStore.getHost(HOSTID);
312
313 // Expected a learnt host with an IP
314 assertFalse(hostInHosts.configured());
315 assertEquals(HOSTID, hostInHosts.id());
316 assertEquals(PID, hostInHosts.providerId());
317 assertEquals(HOST_LOCATIONS, hostInHosts.locations());
318 assertEquals(HOST_ADDRESS, hostInHosts.ipAddresses());
319 Host hostInHostsByIp = ecXHostStore.getHosts(IP1).stream()
320 .findFirst().orElse(null);
321 assertNotNull(hostInHostsByIp);
322 assertFalse(hostInHostsByIp.configured());
323 assertEquals(HOSTID, hostInHostsByIp.id());
324 assertEquals(PID, hostInHostsByIp.providerId());
325 assertEquals(HOST_LOCATIONS, hostInHostsByIp.locations());
326 assertEquals(HOST_ADDRESS, hostInHostsByIp.ipAddresses());
327
328 // Remove one location
329 ecXHostStore.removeLocation(HOSTID, HOST_LOC12);
330
331 // Verify hosts is updated
332 hostInHosts = ecXHostStore.getHost(HOSTID);
333 assertFalse(hostInHosts.configured());
334 assertEquals(HOSTID, hostInHosts.id());
335 assertEquals(PID, hostInHosts.providerId());
336 assertEquals(HOST_LOCATION, hostInHosts.locations());
337 assertEquals(HOST_ADDRESS, hostInHosts.ipAddresses());
338
339 // Verify hostsByIp is updated
340 hostInHostsByIp = ecXHostStore.getHosts(IP1).stream()
341 .findFirst().orElse(null);
342 assertNotNull(hostInHostsByIp);
343 assertFalse(hostInHostsByIp.configured());
344 assertEquals(HOSTID, hostInHostsByIp.id());
345 assertEquals(PID, hostInHostsByIp.providerId());
346 assertEquals(HOST_LOCATION, hostInHostsByIp.locations());
347 assertEquals(HOST_ADDRESS, hostInHostsByIp.ipAddresses());
348 }
349
Charles Chan2a9492da2019-12-06 19:19:30 -0800350 @Test
351 public void testHostAdded() {
352 // Host is first discovered at only one location
353 MapEvent<HostId, DefaultHost> event = new MapEvent<>("event", HOSTID,
354 new Versioned<>(HOST1, 0), null);
355 // Expect: HOST_ADDED
356 ecXHostStore.hostLocationTracker.event(event);
357 assertEquals(HostEvent.Type.HOST_ADDED, delegate.lastEvent.type());
358 assertEquals(HOST1, delegate.lastEvent.subject());
359 assertNull(delegate.lastEvent.prevSubject());
360 }
361
362 @Test
363 public void testHostUpdated() {
364 // Host is updated with an IP
365 MapEvent<HostId, DefaultHost> event = new MapEvent<>("event", HOSTID,
366 new Versioned<>(HOST2, 1), new Versioned<>(HOST1, 0));
367 // Expect: HOST_UPDATED
368 ecXHostStore.hostLocationTracker.event(event);
369 assertEquals(HostEvent.Type.HOST_UPDATED, delegate.lastEvent.type());
370 assertEquals(HOST2, delegate.lastEvent.subject());
371 assertEquals(HOST1, delegate.lastEvent.prevSubject());
372 }
373
374 @Test
375 public void testHostMoved() {
376 // Host is updated with a second location
377 MapEvent<HostId, DefaultHost> event = new MapEvent<>("event", HOSTID,
378 new Versioned<>(HOST3, 1), new Versioned<>(HOST2, 0));
379 // Expect: HOST_MOVED
380 ecXHostStore.hostLocationTracker.event(event);
381 assertEquals(HostEvent.Type.HOST_MOVED, delegate.lastEvent.type());
382 assertEquals(HOST3, delegate.lastEvent.subject());
383 assertEquals(HOST2, delegate.lastEvent.prevSubject());
384 }
385
386 @Test
387 public void testHostAuxMoved() {
388 // Host aux location changed
389 MapEvent<HostId, DefaultHost> event = new MapEvent<>("event", HOSTID,
390 new Versioned<>(HOST4, 1), new Versioned<>(HOST1, 0));
391 // Expect: HOST_AUX_MOVED
392 ecXHostStore.hostLocationTracker.event(event);
393 assertEquals(HostEvent.Type.HOST_AUX_MOVED, delegate.lastEvent.type());
394 assertEquals(HOST4, delegate.lastEvent.subject());
395 assertEquals(HOST1, delegate.lastEvent.prevSubject());
396 }
397
398 @Test
399 public void testHostRemoved() {
400 // Host is removed
401 MapEvent<HostId, DefaultHost> event = new MapEvent<>("event", HOSTID,
402 null, new Versioned<>(HOST3, 0));
403 // Expect: HOST_REMOVED
404 ecXHostStore.hostLocationTracker.event(event);
405 assertEquals(HostEvent.Type.HOST_REMOVED, delegate.lastEvent.type());
406 assertEquals(HOST3, delegate.lastEvent.subject());
407 assertNull(delegate.lastEvent.prevSubject());
408 }
409
Charles Chancef8a952020-03-08 17:41:11 -0700410 @Test
411 public void testGetConnectedHost() {
412 ecXHostStore.createOrUpdateHost(PID, HOSTID, HOST_DESC_WITHOUT_AUX, false);
413 ecXHostStore.createOrUpdateHost(PID, HOSTID1, HOST_DESC_WITH_AUX, false);
414
415 assertEquals(Sets.newHashSet(HOST_WITHOUT_AUX, HOST_WITH_AUX),
416 ecXHostStore.getConnectedHosts(HOST_LOC11, false));
417 assertEquals(Sets.newHashSet(),
418 ecXHostStore.getConnectedHosts(HOST_LOC11, true));
419 assertEquals(Sets.newHashSet(HOST_WITH_AUX),
420 ecXHostStore.getConnectedHosts(HOST_LOC12, true));
421 }
422
Charles Chan2a9492da2019-12-06 19:19:30 -0800423 private class TestStoreDelegate implements HostStoreDelegate {
424 public HostEvent lastEvent;
425
426 @Override
427 public void notify(HostEvent event) {
428 lastEvent = event;
429 }
430 }
Harshada Chaundkarc9712222019-07-02 15:13:24 +0000431
Charles Chanb1e99242017-07-07 14:11:09 -0700432 private static HostDescription createHostDesc(HostId hostId, Set<IpAddress> ips) {
Harshada Chaundkarc9712222019-07-02 15:13:24 +0000433 return createHostDesc(hostId, ips, false, Collections.emptySet());
Charles Chanb1e99242017-07-07 14:11:09 -0700434 }
435
436 private static HostDescription createHostDesc(HostId hostId, Set<IpAddress> ips,
Harshada Chaundkarc9712222019-07-02 15:13:24 +0000437 boolean configured, Set<HostLocation> locations) {
438 return locations.isEmpty() ?
439 new DefaultHostDescription(hostId.mac(), hostId.vlanId(), HostLocation.NONE, ips, configured) :
440 new DefaultHostDescription(hostId.mac(), hostId.vlanId(), locations, ips, configured);
441
Deepa Vaddireddy0a71c8b2017-01-19 21:20:45 +0530442 }
Harshada Chaundkarc9712222019-07-02 15:13:24 +0000443
Sho SHIMIZU53bcc242016-08-15 11:19:24 -0700444}