blob: a1cbee5d3493165fbc8c0894c80966c8d48c5dac [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
Ray Milkey34c95902015-04-15 09:47:53 -07002 * Copyright 2014-2015 Open Networking Laboratory
Thomas Vachuska781d18b2014-10-27 10:31:25 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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
Thomas Vachuska781d18b2014-10-27 10:31:25 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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.
Thomas Vachuska781d18b2014-10-27 10:31:25 -070015 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.provider.lldp.impl;
alshabib0ed6a202014-10-19 12:42:57 -070017
Ray Milkeycd6ab182016-02-03 11:13:09 -080018import java.nio.ByteBuffer;
19import java.util.Collections;
20import java.util.HashMap;
21import java.util.HashSet;
22import java.util.List;
23import java.util.Map;
24import java.util.Set;
25import java.util.concurrent.CompletableFuture;
Ayaka Koshibe12c8c082015-12-08 12:48:46 -080026
alshabib0ed6a202014-10-19 12:42:57 -070027import org.junit.After;
28import org.junit.Before;
29import org.junit.Test;
Jonathan Hart3cfce8e2015-01-14 16:43:27 -080030import org.onlab.packet.ChassisId;
31import org.onlab.packet.Ethernet;
Ayaka Koshibe12c8c082015-12-08 12:48:46 -080032import org.onlab.packet.IpAddress;
Jonathan Hart3cfce8e2015-01-14 16:43:27 -080033import org.onlab.packet.ONOSLLDP;
Thomas Vachuska6519e6f2015-03-11 02:29:31 -070034import org.onosproject.cfg.ComponentConfigAdapter;
Ayaka Koshibe12c8c082015-12-08 12:48:46 -080035import org.onosproject.cluster.ClusterMetadata;
Madan Jampaniab7e7cd2016-01-14 14:02:32 -080036import org.onosproject.cluster.ClusterMetadataEventListener;
Ayaka Koshibe12c8c082015-12-08 12:48:46 -080037import org.onosproject.cluster.ClusterMetadataService;
38import org.onosproject.cluster.ControllerNode;
39import org.onosproject.cluster.DefaultControllerNode;
Madan Jampani8474fdd2016-01-19 09:56:28 -080040import org.onosproject.cluster.DefaultPartition;
Brian O'Connorabafb502014-12-02 22:26:20 -080041import org.onosproject.cluster.NodeId;
Ayaka Koshibe12c8c082015-12-08 12:48:46 -080042import org.onosproject.cluster.Partition;
Madan Jampaniab7e7cd2016-01-14 14:02:32 -080043import org.onosproject.cluster.PartitionId;
Brian O'Connorabafb502014-12-02 22:26:20 -080044import org.onosproject.cluster.RoleInfo;
Pavlin Radoslavovd36a74b2015-01-09 11:59:07 -080045import org.onosproject.core.ApplicationId;
46import org.onosproject.core.CoreService;
47import org.onosproject.core.DefaultApplicationId;
Brian O'Connorabafb502014-12-02 22:26:20 -080048import org.onosproject.mastership.MastershipListener;
49import org.onosproject.mastership.MastershipService;
HIGUCHI Yuta9a9edf82015-10-21 11:23:20 -070050import org.onosproject.net.Annotations;
Brian O'Connorabafb502014-12-02 22:26:20 -080051import org.onosproject.net.ConnectPoint;
HIGUCHI Yuta9a9edf82015-10-21 11:23:20 -070052import org.onosproject.net.DefaultAnnotations;
Brian O'Connorabafb502014-12-02 22:26:20 -080053import org.onosproject.net.DefaultDevice;
54import org.onosproject.net.DefaultPort;
55import org.onosproject.net.Device;
56import org.onosproject.net.DeviceId;
57import org.onosproject.net.MastershipRole;
58import org.onosproject.net.Port;
59import org.onosproject.net.PortNumber;
Naoki Shiota399a0b32015-11-15 20:36:13 -060060import org.onosproject.net.config.Config;
Naoki Shiota399a0b32015-11-15 20:36:13 -060061import org.onosproject.net.config.NetworkConfigEvent;
HIGUCHI Yutad9fe3a32015-11-24 18:52:25 -080062import org.onosproject.net.config.NetworkConfigEvent.Type;
Naoki Shiota399a0b32015-11-15 20:36:13 -060063import org.onosproject.net.config.NetworkConfigListener;
64import org.onosproject.net.config.NetworkConfigRegistryAdapter;
Brian O'Connorabafb502014-12-02 22:26:20 -080065import org.onosproject.net.device.DeviceEvent;
66import org.onosproject.net.device.DeviceListener;
67import org.onosproject.net.device.DeviceServiceAdapter;
68import org.onosproject.net.flow.TrafficTreatment;
Ray Milkeycd6ab182016-02-03 11:13:09 -080069import org.onosproject.net.link.LinkProviderRegistryAdapter;
70import org.onosproject.net.link.LinkProviderServiceAdapter;
Thomas Vachuskae4ebac92015-09-10 11:39:05 -070071import org.onosproject.net.link.LinkServiceAdapter;
Brian O'Connorabafb502014-12-02 22:26:20 -080072import org.onosproject.net.packet.DefaultInboundPacket;
73import org.onosproject.net.packet.InboundPacket;
74import org.onosproject.net.packet.OutboundPacket;
75import org.onosproject.net.packet.PacketContext;
76import org.onosproject.net.packet.PacketProcessor;
Thomas Vachuska27bee092015-06-23 19:03:10 -070077import org.onosproject.net.packet.PacketServiceAdapter;
Brian O'Connorabafb502014-12-02 22:26:20 -080078import org.onosproject.net.provider.ProviderId;
Ray Milkey957390e2016-02-09 10:02:46 -080079import org.onosproject.provider.lldpcommon.LinkDiscovery;
alshabib0ed6a202014-10-19 12:42:57 -070080
Ray Milkeycd6ab182016-02-03 11:13:09 -080081import com.google.common.collect.ArrayListMultimap;
82import com.google.common.collect.ImmutableList;
83import com.google.common.collect.ImmutableMap;
84import com.google.common.collect.ImmutableSet;
85import com.google.common.collect.Lists;
86import com.google.common.collect.Sets;
Thomas Vachuska27bee092015-06-23 19:03:10 -070087
Naoki Shiota399a0b32015-11-15 20:36:13 -060088import static org.easymock.EasyMock.createMock;
89import static org.easymock.EasyMock.expect;
90import static org.easymock.EasyMock.replay;
Naoki Shiota399a0b32015-11-15 20:36:13 -060091import static org.junit.Assert.assertEquals;
Ray Milkeycd6ab182016-02-03 11:13:09 -080092import static org.junit.Assert.assertFalse;
93import static org.junit.Assert.assertNotNull;
94import static org.junit.Assert.assertNull;
Naoki Shiota399a0b32015-11-15 20:36:13 -060095import static org.junit.Assert.assertTrue;
Thomas Vachuskab5f6f522016-03-01 13:52:10 -080096import static org.onlab.junit.TestTools.assertAfter;
Naoki Shiota399a0b32015-11-15 20:36:13 -060097import static org.onosproject.provider.lldp.impl.LldpLinkProvider.DEFAULT_RULES;
Naoki Shiota399a0b32015-11-15 20:36:13 -060098
alshabib0ed6a202014-10-19 12:42:57 -070099
Jonathan Hartb35540a2015-11-17 09:30:56 -0800100public class LldpLinkProviderTest {
alshabib0ed6a202014-10-19 12:42:57 -0700101
102 private static final DeviceId DID1 = DeviceId.deviceId("of:0000000000000001");
103 private static final DeviceId DID2 = DeviceId.deviceId("of:0000000000000002");
HIGUCHI Yuta9a9edf82015-10-21 11:23:20 -0700104 private static final DeviceId DID3 = DeviceId.deviceId("of:0000000000000003");
Thomas Vachuskab5f6f522016-03-01 13:52:10 -0800105 private static final int EVENT_MS = 500;
alshabib0ed6a202014-10-19 12:42:57 -0700106
107 private static Port pd1;
108 private static Port pd2;
109 private static Port pd3;
110 private static Port pd4;
111
Jonathan Hartb35540a2015-11-17 09:30:56 -0800112 private final LldpLinkProvider provider = new LldpLinkProvider();
Ray Milkeycd6ab182016-02-03 11:13:09 -0800113 private final LinkProviderRegistryAdapter linkRegistry = new LinkProviderRegistryAdapter();
Thomas Vachuskae4ebac92015-09-10 11:39:05 -0700114 private final TestLinkService linkService = new TestLinkService();
alshabib0ed6a202014-10-19 12:42:57 -0700115 private final TestPacketService packetService = new TestPacketService();
116 private final TestDeviceService deviceService = new TestDeviceService();
117 private final TestMasterShipService masterService = new TestMasterShipService();
Naoki Shiota399a0b32015-11-15 20:36:13 -0600118 private final TestNetworkConfigRegistry configRegistry = new TestNetworkConfigRegistry();
alshabib0ed6a202014-10-19 12:42:57 -0700119
Pavlin Radoslavovd36a74b2015-01-09 11:59:07 -0800120 private CoreService coreService;
Ray Milkeycd6ab182016-02-03 11:13:09 -0800121 private LinkProviderServiceAdapter providerService;
alshabib0ed6a202014-10-19 12:42:57 -0700122
123 private PacketProcessor testProcessor;
124 private DeviceListener deviceListener;
Naoki Shiota399a0b32015-11-15 20:36:13 -0600125 private NetworkConfigListener configListener;
alshabib0ed6a202014-10-19 12:42:57 -0700126
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800127 private ApplicationId appId =
128 new DefaultApplicationId(100, "org.onosproject.provider.lldp");
Pavlin Radoslavovd36a74b2015-01-09 11:59:07 -0800129
Naoki Shiota399a0b32015-11-15 20:36:13 -0600130 private TestSuppressionConfig cfg;
131
HIGUCHI Yutad9fe3a32015-11-24 18:52:25 -0800132 private Set<DeviceId> deviceBlacklist;
133
134 private Set<ConnectPoint> portBlacklist;
135
alshabib0ed6a202014-10-19 12:42:57 -0700136 @Before
137 public void setUp() {
HIGUCHI Yutad9fe3a32015-11-24 18:52:25 -0800138 deviceBlacklist = new HashSet<>();
139 portBlacklist = new HashSet<>();
Naoki Shiota399a0b32015-11-15 20:36:13 -0600140 cfg = new TestSuppressionConfig();
Pavlin Radoslavovd36a74b2015-01-09 11:59:07 -0800141 coreService = createMock(CoreService.class);
142 expect(coreService.registerApplication(appId.name()))
Thomas Vachuskab5f6f522016-03-01 13:52:10 -0800143 .andReturn(appId).anyTimes();
Pavlin Radoslavovd36a74b2015-01-09 11:59:07 -0800144 replay(coreService);
145
Thomas Vachuska6519e6f2015-03-11 02:29:31 -0700146 provider.cfgService = new ComponentConfigAdapter();
Pavlin Radoslavovd36a74b2015-01-09 11:59:07 -0800147 provider.coreService = coreService;
Naoki Shiota399a0b32015-11-15 20:36:13 -0600148 provider.cfgRegistry = configRegistry;
Pavlin Radoslavovd36a74b2015-01-09 11:59:07 -0800149
alshabib0ed6a202014-10-19 12:42:57 -0700150 provider.deviceService = deviceService;
Thomas Vachuskae4ebac92015-09-10 11:39:05 -0700151 provider.linkService = linkService;
Marc De Leenheer8b3e80b2015-03-06 14:27:03 -0800152 provider.packetService = packetService;
Thomas Vachuskae4ebac92015-09-10 11:39:05 -0700153 provider.providerRegistry = linkRegistry;
alshabib0ed6a202014-10-19 12:42:57 -0700154 provider.masterService = masterService;
Ayaka Koshibe12c8c082015-12-08 12:48:46 -0800155 provider.clusterMetadataService = new TestMetadataService();
Ray Milkeycd6ab182016-02-03 11:13:09 -0800156
Saurav Dasc313c402015-02-27 10:09:47 -0800157 provider.activate(null);
Ray Milkeycd6ab182016-02-03 11:13:09 -0800158
159 providerService = linkRegistry.registeredProvider();
alshabib0ed6a202014-10-19 12:42:57 -0700160 }
161
162 @Test
163 public void basics() {
164 assertNotNull("registration expected", providerService);
165 assertEquals("incorrect provider", provider, providerService.provider());
166 }
167
168 @Test
169 public void switchAdd() {
170 DeviceEvent de = deviceEvent(DeviceEvent.Type.DEVICE_ADDED, DID1);
171 deviceListener.event(de);
172
173 assertFalse("Device not added", provider.discoverers.isEmpty());
174 }
175
176 @Test
177 public void switchRemove() {
178 deviceListener.event(deviceEvent(DeviceEvent.Type.DEVICE_ADDED, DID1));
179 deviceListener.event(deviceEvent(DeviceEvent.Type.DEVICE_REMOVED, DID1));
180
HIGUCHI Yuta9a9edf82015-10-21 11:23:20 -0700181 final LinkDiscovery linkDiscovery = provider.discoverers.get(DID1);
182 if (linkDiscovery != null) {
183 // If LinkDiscovery helper is there after DEVICE_REMOVED,
184 // it should be stopped
185 assertTrue("Discoverer is not stopped", linkDiscovery.isStopped());
186 }
alshabib0ed6a202014-10-19 12:42:57 -0700187 assertTrue("Device is not gone.", vanishedDpid(DID1));
188 }
189
HIGUCHI Yuta9a9edf82015-10-21 11:23:20 -0700190 /**
191 * Checks that links on a reconfigured switch are properly removed.
192 */
193 @Test
HIGUCHI Yutad9fe3a32015-11-24 18:52:25 -0800194 public void switchSuppressedByAnnotation() {
Naoki Shiota399a0b32015-11-15 20:36:13 -0600195
HIGUCHI Yuta9a9edf82015-10-21 11:23:20 -0700196 // add device to stub DeviceService
197 deviceService.putDevice(device(DID3));
198 deviceListener.event(deviceEvent(DeviceEvent.Type.DEVICE_ADDED, DID3));
199
200 assertFalse("Device not added", provider.discoverers.isEmpty());
201
202 // update device in stub DeviceService with suppression config
203 deviceService.putDevice(device(DID3, DefaultAnnotations.builder()
Thomas Vachuskab5f6f522016-03-01 13:52:10 -0800204 .set(LldpLinkProvider.NO_LLDP, "true")
205 .build()));
HIGUCHI Yuta9a9edf82015-10-21 11:23:20 -0700206 deviceListener.event(deviceEvent(DeviceEvent.Type.DEVICE_UPDATED, DID3));
207
Naoki Shiota399a0b32015-11-15 20:36:13 -0600208 // discovery on device is expected to be gone or stopped
209 LinkDiscovery linkDiscovery = provider.discoverers.get(DID3);
210 if (linkDiscovery != null) {
211 assertTrue("Discovery expected to be stopped", linkDiscovery.isStopped());
212 }
HIGUCHI Yuta9a9edf82015-10-21 11:23:20 -0700213 }
214
alshabib0ed6a202014-10-19 12:42:57 -0700215 @Test
HIGUCHI Yutad9fe3a32015-11-24 18:52:25 -0800216 public void switchSuppressByBlacklist() {
217 // add device in stub DeviceService
218 deviceService.putDevice(device(DID3));
219 deviceListener.event(deviceEvent(DeviceEvent.Type.DEVICE_ADDED, DID3));
220
221 // add deviveId to device blacklist
222 deviceBlacklist.add(DID3);
223 configListener.event(new NetworkConfigEvent(Type.CONFIG_ADDED,
224 DID3,
225 LinkDiscoveryFromDevice.class));
226
Thomas Vachuskab5f6f522016-03-01 13:52:10 -0800227 assertAfter(EVENT_MS, () -> {
228 // discovery helper for device is expected to be gone or stopped
229 LinkDiscovery linkDiscovery = provider.discoverers.get(DID3);
230 if (linkDiscovery != null) {
231 assertTrue("Discovery expected to be stopped", linkDiscovery.isStopped());
232 }
233 });
HIGUCHI Yutad9fe3a32015-11-24 18:52:25 -0800234 }
235
236 @Test
alshabib0ed6a202014-10-19 12:42:57 -0700237 public void portUp() {
238 deviceListener.event(deviceEvent(DeviceEvent.Type.DEVICE_ADDED, DID1));
239 deviceListener.event(portEvent(DeviceEvent.Type.PORT_ADDED, DID1, port(DID1, 3, true)));
240
241 assertTrue("Port not added to discoverer",
Sho SHIMIZUc14b2a22015-05-05 18:15:13 -0700242 provider.discoverers.get(DID1).containsPort(3L));
alshabib0ed6a202014-10-19 12:42:57 -0700243 }
244
245 @Test
246 public void portDown() {
247
248 deviceListener.event(deviceEvent(DeviceEvent.Type.DEVICE_ADDED, DID1));
249 deviceListener.event(portEvent(DeviceEvent.Type.PORT_ADDED, DID1, port(DID1, 1, false)));
250
alshabib0ed6a202014-10-19 12:42:57 -0700251 assertFalse("Port added to discoverer",
Sho SHIMIZUc14b2a22015-05-05 18:15:13 -0700252 provider.discoverers.get(DID1).containsPort(1L));
253 assertTrue("Port is not gone.", vanishedPort(1L));
alshabib0ed6a202014-10-19 12:42:57 -0700254 }
255
256 @Test
HIGUCHI Yuta9a9edf82015-10-21 11:23:20 -0700257 public void portRemoved() {
258 deviceListener.event(deviceEvent(DeviceEvent.Type.DEVICE_ADDED, DID1));
259 deviceListener.event(portEvent(DeviceEvent.Type.PORT_ADDED, DID1, port(DID1, 3, true)));
260 deviceListener.event(portEvent(DeviceEvent.Type.PORT_REMOVED, DID1, port(DID1, 3, true)));
261
262 assertTrue("Port is not gone.", vanishedPort(3L));
263 assertFalse("Port was not removed from discoverer",
Thomas Vachuskab5f6f522016-03-01 13:52:10 -0800264 provider.discoverers.get(DID1).containsPort(3L));
HIGUCHI Yuta9a9edf82015-10-21 11:23:20 -0700265 }
266
267 /**
268 * Checks that discovery on reconfigured switch are properly restarted.
269 */
270 @Test
Naoki Shiota399a0b32015-11-15 20:36:13 -0600271 public void portSuppressedByDeviceAnnotationConfig() {
HIGUCHI Yuta9a9edf82015-10-21 11:23:20 -0700272
273 /// When Device is configured with suppression:ON, Port also is same
274
275 // add device in stub DeviceService with suppression configured
276 deviceService.putDevice(device(DID3, DefaultAnnotations.builder()
Thomas Vachuskab5f6f522016-03-01 13:52:10 -0800277 .set(LldpLinkProvider.NO_LLDP, "true")
278 .build()));
HIGUCHI Yuta9a9edf82015-10-21 11:23:20 -0700279 deviceListener.event(deviceEvent(DeviceEvent.Type.DEVICE_ADDED, DID3));
280
281 // non-suppressed port added to suppressed device
282 final long portno3 = 3L;
283 deviceService.putPorts(DID3, port(DID3, portno3, true));
284 deviceListener.event(portEvent(DeviceEvent.Type.PORT_ADDED, DID3, port(DID3, portno3, true)));
285
286 // discovery on device is expected to be stopped
287 LinkDiscovery linkDiscovery = provider.discoverers.get(DID3);
288 if (linkDiscovery != null) {
289 assertTrue("Discovery expected to be stopped", linkDiscovery.isStopped());
290 }
291
292 /// When Device is reconfigured without suppression:OFF,
293 /// Port should be included for discovery
294
295 // update device in stub DeviceService without suppression configured
296 deviceService.putDevice(device(DID3));
297 // update the Port in stub DeviceService. (Port has reference to Device)
298 deviceService.putPorts(DID3, port(DID3, portno3, true));
299 deviceListener.event(deviceEvent(DeviceEvent.Type.DEVICE_UPDATED, DID3));
300
301 // discovery should come back on
302 assertFalse("Discoverer is expected to start", provider.discoverers.get(DID3).isStopped());
303 assertTrue("Discoverer should contain the port there", provider.discoverers.get(DID3).containsPort(portno3));
304 }
305
306 /**
Naoki Shiota399a0b32015-11-15 20:36:13 -0600307 * Checks that discovery on reconfigured switch are properly restarted.
308 */
309 @Test
HIGUCHI Yutad9fe3a32015-11-24 18:52:25 -0800310 public void portSuppressedByParentDeviceIdBlacklist() {
Naoki Shiota399a0b32015-11-15 20:36:13 -0600311
312 /// When Device is configured without suppression:OFF,
313 /// Port should be included for discovery
314
315 // add device in stub DeviceService without suppression configured
316 deviceService.putDevice(device(DID3));
317 deviceListener.event(deviceEvent(DeviceEvent.Type.DEVICE_ADDED, DID3));
318
319 // non-suppressed port added to suppressed device
320 final long portno3 = 3L;
321 deviceService.putPorts(DID3, port(DID3, portno3, true));
322 deviceListener.event(portEvent(DeviceEvent.Type.PORT_ADDED, DID3, port(DID3, portno3, true)));
323
324 // discovery should succeed
325 assertFalse("Discoverer is expected to start", provider.discoverers.get(DID3).isStopped());
326 assertTrue("Discoverer should contain the port there", provider.discoverers.get(DID3).containsPort(portno3));
327
328 // add suppression rule for "deviceId: "of:0000000000000003""
HIGUCHI Yutad9fe3a32015-11-24 18:52:25 -0800329 deviceBlacklist.add(DID3);
330 configListener.event(new NetworkConfigEvent(Type.CONFIG_ADDED,
331 DID3,
332 LinkDiscoveryFromDevice.class));
333
Naoki Shiota399a0b32015-11-15 20:36:13 -0600334
335 /// When Device is reconfigured with suppression:ON, Port also is same
336
337 // update device in stub DeviceService with suppression configured
338 deviceService.putDevice(device(DID3));
339 // update the Port in stub DeviceService. (Port has reference to Device)
340 deviceService.putPorts(DID3, port(DID3, portno3, true));
341 deviceListener.event(deviceEvent(DeviceEvent.Type.DEVICE_UPDATED, DID3));
342
HIGUCHI Yutad9fe3a32015-11-24 18:52:25 -0800343 // discovery helper for device is expected to be gone or stopped
Naoki Shiota399a0b32015-11-15 20:36:13 -0600344 LinkDiscovery linkDiscovery = provider.discoverers.get(DID3);
345 if (linkDiscovery != null) {
346 assertTrue("Discovery expected to be stopped", linkDiscovery.isStopped());
347 }
348 }
349
350 /**
351 * Checks that discovery on reconfigured switch are properly restarted.
352 */
353 @Test
354 public void portSuppressedByDeviceTypeConfig() {
355
356 /// When Device is configured without suppression:OFF,
357 /// Port should be included for discovery
358
359 // add device in stub DeviceService without suppression configured
360 deviceService.putDevice(device(DID1, Device.Type.SWITCH));
361 deviceListener.event(deviceEvent(DeviceEvent.Type.DEVICE_ADDED, DID1));
362
363 // non-suppressed port added to suppressed device
364 final long portno3 = 3L;
365 deviceService.putPorts(DID1, port(DID1, portno3, true));
366 deviceListener.event(portEvent(DeviceEvent.Type.PORT_ADDED, DID1, port(DID1, portno3, true)));
367
368 // add device in stub DeviceService with suppression configured
369 deviceService.putDevice(device(DID2, Device.Type.ROADM));
370 deviceListener.event(deviceEvent(DeviceEvent.Type.DEVICE_ADDED, DID2));
371
372 // non-suppressed port added to suppressed device
373 final long portno4 = 4L;
374 deviceService.putPorts(DID2, port(DID2, portno4, true));
375 deviceListener.event(portEvent(DeviceEvent.Type.PORT_ADDED, DID2, port(DID2, portno4, true)));
376
377 // discovery should succeed for this device
378 assertFalse("Discoverer is expected to start", provider.discoverers.get(DID1).isStopped());
379 assertTrue("Discoverer should contain the port there", provider.discoverers.get(DID1).containsPort(portno3));
380
381 // discovery on device is expected to be stopped for this device
382 LinkDiscovery linkDiscovery = provider.discoverers.get(DID2);
383 if (linkDiscovery != null) {
384 assertTrue("Discovery expected to be stopped", linkDiscovery.isStopped());
385 }
386 }
387
388 /**
HIGUCHI Yuta9a9edf82015-10-21 11:23:20 -0700389 * Checks that discovery on reconfigured port are properly restarted.
390 */
391 @Test
392 public void portSuppressedByPortConfig() {
Naoki Shiota399a0b32015-11-15 20:36:13 -0600393
HIGUCHI Yuta9a9edf82015-10-21 11:23:20 -0700394 // add device in stub DeviceService without suppression configured
395 deviceService.putDevice(device(DID3));
396 deviceListener.event(deviceEvent(DeviceEvent.Type.DEVICE_ADDED, DID3));
397
398 // suppressed port added to non-suppressed device
399 final long portno3 = 3L;
400 final Port port3 = port(DID3, portno3, true,
Thomas Vachuskab5f6f522016-03-01 13:52:10 -0800401 DefaultAnnotations.builder()
402 .set(LldpLinkProvider.NO_LLDP, "true")
403 .build());
HIGUCHI Yuta9a9edf82015-10-21 11:23:20 -0700404 deviceService.putPorts(DID3, port3);
405 deviceListener.event(portEvent(DeviceEvent.Type.PORT_ADDED, DID3, port3));
406
407 // discovery helper should be there turned on
408 assertFalse("Discoverer is expected to start", provider.discoverers.get(DID3).isStopped());
409 assertFalse("Discoverer should not contain the port there",
410 provider.discoverers.get(DID3).containsPort(portno3));
411 }
412
413 @Test
HIGUCHI Yutad9fe3a32015-11-24 18:52:25 -0800414 public void portSuppressedByPortBlacklist() {
415
416 // add device in stub DeviceService without suppression configured
417 deviceService.putDevice(device(DID3));
418 deviceListener.event(deviceEvent(DeviceEvent.Type.DEVICE_ADDED, DID3));
419
420 final long portno3 = 3L;
421 final Port port3 = port(DID3, portno3, true);
422
423 final ConnectPoint cpDid3no3 = new ConnectPoint(DID3, PortNumber.portNumber(portno3));
424 portBlacklist.add(cpDid3no3);
425
426 // suppressed port added to non-suppressed device
427 deviceService.putPorts(DID3, port3);
428 deviceListener.event(portEvent(DeviceEvent.Type.PORT_ADDED, DID3, port3));
429
430 configListener.event(new NetworkConfigEvent(Type.CONFIG_ADDED,
431 cpDid3no3,
432 LinkDiscoveryFromPort.class));
433
434 // discovery helper should be there turned on
435 assertFalse("Discoverer is expected to start", provider.discoverers.get(DID3).isStopped());
436 // but port is not a discovery target
437 assertFalse("Discoverer should not contain the port there",
438 provider.discoverers.get(DID3).containsPort(portno3));
439 }
440
441 @Test
alshabib0ed6a202014-10-19 12:42:57 -0700442 public void portUnknown() {
443 deviceListener.event(deviceEvent(DeviceEvent.Type.DEVICE_ADDED, DID1));
HIGUCHI Yuta9a9edf82015-10-21 11:23:20 -0700444 // Note: DID3 hasn't been added to TestDeviceService, but only port is added
445 deviceListener.event(portEvent(DeviceEvent.Type.PORT_ADDED, DID3, port(DID3, 1, false)));
alshabib0ed6a202014-10-19 12:42:57 -0700446
447
alshabibdfc7afb2014-10-21 20:13:27 -0700448 assertNull("DeviceId exists",
HIGUCHI Yuta9a9edf82015-10-21 11:23:20 -0700449 provider.discoverers.get(DID3));
alshabib0ed6a202014-10-19 12:42:57 -0700450 }
451
452 @Test
453 public void unknownPktCtx() {
454
HIGUCHI Yuta9a9edf82015-10-21 11:23:20 -0700455 // Note: DID3 hasn't been added to TestDeviceService
456 PacketContext pktCtx = new TestPacketContext(device(DID3));
alshabib0ed6a202014-10-19 12:42:57 -0700457
458 testProcessor.process(pktCtx);
459 assertFalse("Context should still be free", pktCtx.isHandled());
460 }
461
462 @Test
463 public void knownPktCtx() {
464 deviceListener.event(deviceEvent(DeviceEvent.Type.DEVICE_ADDED, DID1));
465 deviceListener.event(deviceEvent(DeviceEvent.Type.DEVICE_ADDED, DID2));
466 PacketContext pktCtx = new TestPacketContext(deviceService.getDevice(DID2));
467
468
469 testProcessor.process(pktCtx);
470
471 assertTrue("Link not detected", detectedLink(DID1, DID2));
472
473 }
474
475
476 @After
477 public void tearDown() {
478 provider.deactivate();
Pavlin Radoslavovd36a74b2015-01-09 11:59:07 -0800479 provider.coreService = null;
alshabib0ed6a202014-10-19 12:42:57 -0700480 provider.providerRegistry = null;
481 provider.deviceService = null;
Marc De Leenheer8b3e80b2015-03-06 14:27:03 -0800482 provider.packetService = null;
alshabib0ed6a202014-10-19 12:42:57 -0700483 }
484
485 private DeviceEvent deviceEvent(DeviceEvent.Type type, DeviceId did) {
486 return new DeviceEvent(type, deviceService.getDevice(did));
487
488 }
489
HIGUCHI Yuta9a9edf82015-10-21 11:23:20 -0700490 private DefaultDevice device(DeviceId did) {
491 return new DefaultDevice(ProviderId.NONE, did, Device.Type.SWITCH,
Thomas Vachuskab5f6f522016-03-01 13:52:10 -0800492 "TESTMF", "TESTHW", "TESTSW", "TESTSN", new ChassisId());
HIGUCHI Yuta9a9edf82015-10-21 11:23:20 -0700493 }
494
Naoki Shiota399a0b32015-11-15 20:36:13 -0600495 private DefaultDevice device(DeviceId did, Device.Type type) {
496 return new DefaultDevice(ProviderId.NONE, did, type,
Thomas Vachuskab5f6f522016-03-01 13:52:10 -0800497 "TESTMF", "TESTHW", "TESTSW", "TESTSN", new ChassisId());
Naoki Shiota399a0b32015-11-15 20:36:13 -0600498 }
499
HIGUCHI Yuta9a9edf82015-10-21 11:23:20 -0700500 private DefaultDevice device(DeviceId did, Annotations annotations) {
501 return new DefaultDevice(ProviderId.NONE, did, Device.Type.SWITCH,
Thomas Vachuskab5f6f522016-03-01 13:52:10 -0800502 "TESTMF", "TESTHW", "TESTSW", "TESTSN", new ChassisId(), annotations);
HIGUCHI Yuta9a9edf82015-10-21 11:23:20 -0700503 }
504
Thomas Vachuskab5f6f522016-03-01 13:52:10 -0800505 @SuppressWarnings(value = {"unused"})
alshabib0ed6a202014-10-19 12:42:57 -0700506 private DeviceEvent portEvent(DeviceEvent.Type type, DeviceId did, PortNumber port) {
Thomas Vachuskab5f6f522016-03-01 13:52:10 -0800507 return new DeviceEvent(type, deviceService.getDevice(did),
508 deviceService.getPort(did, port));
alshabib0ed6a202014-10-19 12:42:57 -0700509 }
510
511 private DeviceEvent portEvent(DeviceEvent.Type type, DeviceId did, Port port) {
Thomas Vachuskab5f6f522016-03-01 13:52:10 -0800512 return new DeviceEvent(type, deviceService.getDevice(did), port);
alshabib0ed6a202014-10-19 12:42:57 -0700513 }
514
515 private Port port(DeviceId did, long port, boolean enabled) {
516 return new DefaultPort(deviceService.getDevice(did),
517 PortNumber.portNumber(port), enabled);
518 }
519
HIGUCHI Yuta9a9edf82015-10-21 11:23:20 -0700520 private Port port(DeviceId did, long port, boolean enabled, Annotations annotations) {
521 return new DefaultPort(deviceService.getDevice(did),
522 PortNumber.portNumber(port), enabled, annotations);
523 }
alshabib0ed6a202014-10-19 12:42:57 -0700524
525 private boolean vanishedDpid(DeviceId... dids) {
526 for (int i = 0; i < dids.length; i++) {
Ray Milkeycd6ab182016-02-03 11:13:09 -0800527 if (!providerService.vanishedDpid().contains(dids[i])) {
alshabib0ed6a202014-10-19 12:42:57 -0700528 return false;
529 }
530 }
531 return true;
532 }
533
534 private boolean vanishedPort(Long... ports) {
535 for (int i = 0; i < ports.length; i++) {
Ray Milkeycd6ab182016-02-03 11:13:09 -0800536 if (!providerService.vanishedPort().contains(ports[i])) {
alshabib0ed6a202014-10-19 12:42:57 -0700537 return false;
538 }
539 }
540 return true;
541 }
542
543 private boolean detectedLink(DeviceId src, DeviceId dst) {
Ray Milkeycd6ab182016-02-03 11:13:09 -0800544 for (DeviceId key : providerService.discoveredLinks().keySet()) {
alshabib0ed6a202014-10-19 12:42:57 -0700545 if (key.equals(src)) {
Ray Milkeycd6ab182016-02-03 11:13:09 -0800546 return providerService.discoveredLinks().get(src).equals(dst);
alshabib0ed6a202014-10-19 12:42:57 -0700547 }
548 }
549 return false;
550 }
551
Naoki Shiota399a0b32015-11-15 20:36:13 -0600552 @Test
553 public void addDeviceTypeRule() {
554 Device.Type deviceType1 = Device.Type.ROADM;
555 Device.Type deviceType2 = Device.Type.SWITCH;
556
557 Set<Device.Type> deviceTypes = new HashSet<>();
558 deviceTypes.add(deviceType1);
559
560 cfg.deviceTypes(deviceTypes);
561
562 configEvent(NetworkConfigEvent.Type.CONFIG_ADDED);
563
564 assertTrue(provider.rules().getSuppressedDeviceType().contains(deviceType1));
565 assertFalse(provider.rules().getSuppressedDeviceType().contains(deviceType2));
566 }
567
568 @Test
569 public void updateDeviceTypeRule() {
570 Device.Type deviceType1 = Device.Type.ROADM;
571 Device.Type deviceType2 = Device.Type.SWITCH;
572 Set<Device.Type> deviceTypes = new HashSet<>();
573
574 deviceTypes.add(deviceType1);
575 cfg.deviceTypes(deviceTypes);
576
577 configEvent(NetworkConfigEvent.Type.CONFIG_ADDED);
578
579 deviceTypes.add(deviceType2);
580 cfg.deviceTypes(deviceTypes);
581
582 configEvent(NetworkConfigEvent.Type.CONFIG_UPDATED);
583
Thomas Vachuskab5f6f522016-03-01 13:52:10 -0800584 assertAfter(EVENT_MS, () -> {
585 assertTrue(provider.rules().getSuppressedDeviceType().contains(deviceType1));
586 assertTrue(provider.rules().getSuppressedDeviceType().contains(deviceType2));
587 });
Naoki Shiota399a0b32015-11-15 20:36:13 -0600588 }
589
590 @Test
591 public void addAnnotationRule() {
592 final String key1 = "key1", key2 = "key2";
593 final String value1 = "value1";
594
595 Map<String, String> annotation = new HashMap<>();
596 annotation.put(key1, value1);
597
598 cfg.annotation(annotation);
599
600 configEvent(NetworkConfigEvent.Type.CONFIG_ADDED);
601
Thomas Vachuskab5f6f522016-03-01 13:52:10 -0800602 assertAfter(EVENT_MS, () -> {
603 assertTrue(provider.rules().getSuppressedAnnotation().containsKey(key1));
604 assertEquals(value1, provider.rules().getSuppressedAnnotation().get(key1));
605 assertFalse(provider.rules().getSuppressedAnnotation().containsKey(key2));
606 });
Naoki Shiota399a0b32015-11-15 20:36:13 -0600607 }
608
609 @Test
610 public void updateAnnotationRule() {
611 final String key1 = "key1", key2 = "key2";
612 final String value1 = "value1", value2 = "value2";
613 Map<String, String> annotation = new HashMap<>();
614
615 annotation.put(key1, value1);
616 cfg.annotation(annotation);
617
618 configEvent(NetworkConfigEvent.Type.CONFIG_ADDED);
619
Thomas Vachuskab5f6f522016-03-01 13:52:10 -0800620 assertAfter(EVENT_MS, () -> {
621 assertTrue(provider.rules().getSuppressedAnnotation().containsKey(key1));
622 assertEquals(value1, provider.rules().getSuppressedAnnotation().get(key1));
623 assertFalse(provider.rules().getSuppressedAnnotation().containsKey(key2));
624 });
Naoki Shiota399a0b32015-11-15 20:36:13 -0600625
626 annotation.put(key2, value2);
627 cfg.annotation(annotation);
628
629 configEvent(NetworkConfigEvent.Type.CONFIG_UPDATED);
630
Thomas Vachuskab5f6f522016-03-01 13:52:10 -0800631 assertAfter(EVENT_MS, () -> {
632 assertTrue(provider.rules().getSuppressedAnnotation().containsKey(key1));
633 assertEquals(value1, provider.rules().getSuppressedAnnotation().get(key1));
634 assertTrue(provider.rules().getSuppressedAnnotation().containsKey(key2));
635 assertEquals(value2, provider.rules().getSuppressedAnnotation().get(key2));
636 });
Naoki Shiota399a0b32015-11-15 20:36:13 -0600637 }
638
639 private void configEvent(NetworkConfigEvent.Type evType) {
640 configListener.event(new NetworkConfigEvent(evType,
Thomas Vachuskab5f6f522016-03-01 13:52:10 -0800641 appId,
642 SuppressionConfig.class));
Naoki Shiota399a0b32015-11-15 20:36:13 -0600643 }
644
alshabib0ed6a202014-10-19 12:42:57 -0700645 private class TestPacketContext implements PacketContext {
646
647 protected Device device;
648 protected boolean blocked = false;
649
650 public TestPacketContext(Device dev) {
651 device = dev;
652 }
653
654 @Override
655 public long time() {
656 return 0;
657 }
658
659 @Override
660 public InboundPacket inPacket() {
Ayaka Koshibe12c8c082015-12-08 12:48:46 -0800661 ONOSLLDP lldp = ONOSLLDP.onosLLDP(deviceService.getDevice(DID1).id().toString(),
662 device.chassisId(),
663 (int) pd1.number().toLong());
alshabib0ed6a202014-10-19 12:42:57 -0700664
665 Ethernet ethPacket = new Ethernet();
666 ethPacket.setEtherType(Ethernet.TYPE_LLDP);
667 ethPacket.setDestinationMACAddress(ONOSLLDP.LLDP_NICIRA);
668 ethPacket.setPayload(lldp);
669 ethPacket.setPad(true);
670
alshabib0ed6a202014-10-19 12:42:57 -0700671 ethPacket.setSourceMACAddress("DE:AD:BE:EF:BA:11");
672
673 ConnectPoint cp = new ConnectPoint(device.id(), pd3.number());
674
675 return new DefaultInboundPacket(cp, ethPacket,
676 ByteBuffer.wrap(ethPacket.serialize()));
677
678 }
679
680 @Override
681 public OutboundPacket outPacket() {
682 return null;
683 }
684
685 @Override
686 public TrafficTreatment.Builder treatmentBuilder() {
687 return null;
688 }
689
690 @Override
691 public void send() {
692
693 }
694
695 @Override
696 public boolean block() {
697 blocked = true;
698 return blocked;
699 }
700
701 @Override
702 public boolean isHandled() {
703 return blocked;
704 }
705
706 }
707
Thomas Vachuska27bee092015-06-23 19:03:10 -0700708 private class TestPacketService extends PacketServiceAdapter {
alshabib0ed6a202014-10-19 12:42:57 -0700709 @Override
710 public void addProcessor(PacketProcessor processor, int priority) {
711 testProcessor = processor;
712 }
alshabib0ed6a202014-10-19 12:42:57 -0700713 }
714
Yuta HIGUCHIf1f2ac02014-11-26 14:02:22 -0800715 private class TestDeviceService extends DeviceServiceAdapter {
alshabib0ed6a202014-10-19 12:42:57 -0700716
HIGUCHI Yuta9a9edf82015-10-21 11:23:20 -0700717 private final Map<DeviceId, Device> devices = new HashMap<>();
alshabib0ed6a202014-10-19 12:42:57 -0700718 private final ArrayListMultimap<DeviceId, Port> ports =
719 ArrayListMultimap.create();
Thomas Vachuskab5f6f522016-03-01 13:52:10 -0800720
alshabib0ed6a202014-10-19 12:42:57 -0700721 public TestDeviceService() {
722 Device d1 = new DefaultDevice(ProviderId.NONE, DID1, Device.Type.SWITCH,
723 "TESTMF", "TESTHW", "TESTSW", "TESTSN", new ChassisId());
724 Device d2 = new DefaultDevice(ProviderId.NONE, DID2, Device.Type.SWITCH,
725 "TESTMF", "TESTHW", "TESTSW", "TESTSN", new ChassisId());
726 devices.put(DID1, d1);
727 devices.put(DID2, d2);
alshabib0ed6a202014-10-19 12:42:57 -0700728 pd1 = new DefaultPort(d1, PortNumber.portNumber(1), true);
729 pd2 = new DefaultPort(d1, PortNumber.portNumber(2), true);
730 pd3 = new DefaultPort(d2, PortNumber.portNumber(1), true);
731 pd4 = new DefaultPort(d2, PortNumber.portNumber(2), true);
732
733 ports.putAll(DID1, Lists.newArrayList(pd1, pd2));
734 ports.putAll(DID2, Lists.newArrayList(pd3, pd4));
alshabib0ed6a202014-10-19 12:42:57 -0700735 }
736
HIGUCHI Yuta9a9edf82015-10-21 11:23:20 -0700737 private void putDevice(Device device) {
738 DeviceId deviceId = device.id();
739 devices.put(deviceId, device);
740 }
741
Thomas Vachuskab5f6f522016-03-01 13:52:10 -0800742 private void putPorts(DeviceId did, Port... ports) {
HIGUCHI Yuta9a9edf82015-10-21 11:23:20 -0700743 this.ports.putAll(did, Lists.newArrayList(ports));
744 }
745
alshabib0ed6a202014-10-19 12:42:57 -0700746 @Override
747 public int getDeviceCount() {
748 return devices.values().size();
749 }
750
751 @Override
752 public Iterable<Device> getDevices() {
HIGUCHI Yuta9a9edf82015-10-21 11:23:20 -0700753 return ImmutableList.copyOf(devices.values());
alshabib0ed6a202014-10-19 12:42:57 -0700754 }
755
756 @Override
757 public Device getDevice(DeviceId deviceId) {
758 return devices.get(deviceId);
759 }
760
761 @Override
762 public MastershipRole getRole(DeviceId deviceId) {
763 return MastershipRole.MASTER;
764 }
765
766 @Override
767 public List<Port> getPorts(DeviceId deviceId) {
768 return ports.get(deviceId);
769 }
770
771 @Override
772 public Port getPort(DeviceId deviceId, PortNumber portNumber) {
773 for (Port p : ports.get(deviceId)) {
774 if (p.number().equals(portNumber)) {
775 return p;
776 }
777 }
778 return null;
779 }
780
781 @Override
782 public boolean isAvailable(DeviceId deviceId) {
783 return true;
784 }
785
786 @Override
787 public void addListener(DeviceListener listener) {
788 deviceListener = listener;
789
790 }
791
792 @Override
793 public void removeListener(DeviceListener listener) {
794
795 }
796 }
797
798 private final class TestMasterShipService implements MastershipService {
799
800 @Override
801 public MastershipRole getLocalRole(DeviceId deviceId) {
802 return MastershipRole.MASTER;
803 }
804
805 @Override
Madan Jampanide003d92015-05-11 17:14:20 -0700806 public CompletableFuture<MastershipRole> requestRoleFor(DeviceId deviceId) {
807 return CompletableFuture.completedFuture(null);
alshabib0ed6a202014-10-19 12:42:57 -0700808 }
809
810 @Override
Madan Jampanic6e574f2015-05-29 13:41:52 -0700811 public CompletableFuture<Void> relinquishMastership(DeviceId deviceId) {
812 return null;
alshabib0ed6a202014-10-19 12:42:57 -0700813 }
814
815 @Override
816 public NodeId getMasterFor(DeviceId deviceId) {
817 return null;
818 }
819
820 @Override
821 public Set<DeviceId> getDevicesOf(NodeId nodeId) {
822 return null;
823 }
824
825 @Override
alshabib0ed6a202014-10-19 12:42:57 -0700826 public void addListener(MastershipListener listener) {
827
828 }
829
830 @Override
831 public void removeListener(MastershipListener listener) {
832
833 }
Yuta HIGUCHI376d7502014-10-19 15:57:52 -0700834
835 @Override
Ayaka Koshibeabedb092014-10-20 17:01:31 -0700836 public RoleInfo getNodesFor(DeviceId deviceId) {
837 return new RoleInfo(new NodeId("foo"), Collections.<NodeId>emptyList());
Yuta HIGUCHI376d7502014-10-19 15:57:52 -0700838 }
alshabib0ed6a202014-10-19 12:42:57 -0700839 }
840
841
Thomas Vachuskae4ebac92015-09-10 11:39:05 -0700842 private class TestLinkService extends LinkServiceAdapter {
843 }
Naoki Shiota399a0b32015-11-15 20:36:13 -0600844
845 private final class TestNetworkConfigRegistry
Thomas Vachuskab5f6f522016-03-01 13:52:10 -0800846 extends NetworkConfigRegistryAdapter {
HIGUCHI Yutad9fe3a32015-11-24 18:52:25 -0800847 @SuppressWarnings("unchecked")
Naoki Shiota399a0b32015-11-15 20:36:13 -0600848 @Override
HIGUCHI Yutad9fe3a32015-11-24 18:52:25 -0800849 public <S, C extends Config<S>> C getConfig(S subj, Class<C> configClass) {
850 if (configClass == SuppressionConfig.class) {
851 return (C) cfg;
852 } else if (configClass == LinkDiscoveryFromDevice.class) {
853 return (C) new LinkDiscoveryFromDevice() {
854 @Override
855 public boolean enabled() {
856 return !deviceBlacklist.contains(subj);
857 }
858 };
859 } else if (configClass == LinkDiscoveryFromPort.class) {
860 return (C) new LinkDiscoveryFromPort() {
861 @Override
862 public boolean enabled() {
863 return !portBlacklist.contains(subj);
864 }
865 };
866 } else {
867 return null;
868 }
Naoki Shiota399a0b32015-11-15 20:36:13 -0600869 }
870
871 @Override
872 public void addListener(NetworkConfigListener listener) {
873 configListener = listener;
874 }
875 }
876
877 private final class TestSuppressionConfig extends SuppressionConfig {
Naoki Shiota399a0b32015-11-15 20:36:13 -0600878 private Set<Device.Type> deviceTypes = new HashSet<>(DEFAULT_RULES.getSuppressedDeviceType());
879 private Map<String, String> annotation = new HashMap<>(DEFAULT_RULES.getSuppressedAnnotation());
880
881 @Override
Naoki Shiota399a0b32015-11-15 20:36:13 -0600882 public Set<Device.Type> deviceTypes() {
883 return ImmutableSet.copyOf(deviceTypes);
884 }
885
886 @Override
887 public SuppressionConfig deviceTypes(Set<Device.Type> deviceTypes) {
888 this.deviceTypes = ImmutableSet.copyOf(deviceTypes);
889 return this;
890 }
891
892 @Override
893 public Map<String, String> annotation() {
894 return ImmutableMap.copyOf(annotation);
895 }
896
897 @Override
898 public SuppressionConfig annotation(Map<String, String> annotation) {
899 this.annotation = ImmutableMap.copyOf(annotation);
900 return this;
901 }
902 }
Ayaka Koshibe12c8c082015-12-08 12:48:46 -0800903
904 private final class TestMetadataService implements ClusterMetadataService {
905 @Override
906 public ClusterMetadata getClusterMetadata() {
907 final NodeId nid = new NodeId("test-node");
908 final IpAddress addr = IpAddress.valueOf(0);
Madan Jampani8474fdd2016-01-19 09:56:28 -0800909 final Partition p = new DefaultPartition(PartitionId.from(1), Sets.newHashSet(nid));
Madan Jampaniad3c5262016-01-20 00:50:17 -0800910 return new ClusterMetadata("test-cluster",
Thomas Vachuskab5f6f522016-03-01 13:52:10 -0800911 Sets.newHashSet(new DefaultControllerNode(nid, addr)),
912 Sets.newHashSet(p));
Ayaka Koshibe12c8c082015-12-08 12:48:46 -0800913 }
914
915 @Override
Madan Jampaniab7e7cd2016-01-14 14:02:32 -0800916 public ControllerNode getLocalNode() {
917 return null;
Ayaka Koshibe12c8c082015-12-08 12:48:46 -0800918 }
919
920 @Override
Madan Jampaniab7e7cd2016-01-14 14:02:32 -0800921 public void addListener(ClusterMetadataEventListener listener) {
922 }
923
924 @Override
925 public void removeListener(ClusterMetadataEventListener listener) {
Ayaka Koshibe12c8c082015-12-08 12:48:46 -0800926 }
927 }
alshabib0ed6a202014-10-19 12:42:57 -0700928}