blob: d95943b4d8b550e5c18da5288ccd920ebe7b37fe [file] [log] [blame]
Thomas Vachuskac40d4632015-04-09 16:55:03 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Thomas Vachuskac40d4632015-04-09 16:55:03 -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.provider.nil;
17
Thomas Vachuskac40d4632015-04-09 16:55:03 -070018import org.onlab.osgi.DefaultServiceDirectory;
19import org.onosproject.cfg.ComponentConfigService;
20import org.onosproject.cluster.ClusterService;
21import org.onosproject.cluster.NodeId;
22import org.onosproject.mastership.MastershipAdminService;
23import org.onosproject.net.ConnectPoint;
24import org.onosproject.net.DeviceId;
25import org.onosproject.net.Host;
26import org.onosproject.net.MastershipRole;
Saurav Dasa2d37502016-03-25 17:50:40 -070027import org.onosproject.net.PortNumber;
Thomas Vachuskac40d4632015-04-09 16:55:03 -070028import org.onosproject.net.device.DeviceAdminService;
29import org.onosproject.net.device.DeviceProvider;
30import org.onosproject.net.device.DeviceProviderRegistry;
31import org.onosproject.net.device.DeviceProviderService;
32import org.onosproject.net.flow.FlowRuleProviderRegistry;
33import org.onosproject.net.flow.FlowRuleProviderService;
Yi Tseng3dca0f82018-04-03 14:33:03 +080034import org.onosproject.net.group.GroupProviderRegistry;
35import org.onosproject.net.group.GroupProviderService;
Thomas Vachuskac40d4632015-04-09 16:55:03 -070036import org.onosproject.net.host.HostProvider;
37import org.onosproject.net.host.HostProviderRegistry;
38import org.onosproject.net.host.HostProviderService;
39import org.onosproject.net.host.HostService;
40import org.onosproject.net.link.LinkProvider;
41import org.onosproject.net.link.LinkProviderRegistry;
42import org.onosproject.net.link.LinkProviderService;
43import org.onosproject.net.link.LinkService;
44import org.onosproject.net.packet.PacketProviderRegistry;
45import org.onosproject.net.packet.PacketProviderService;
46import org.onosproject.net.provider.AbstractProvider;
47import org.onosproject.net.provider.ProviderId;
48import org.osgi.service.component.ComponentContext;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070049import org.osgi.service.component.annotations.Activate;
50import org.osgi.service.component.annotations.Component;
51import org.osgi.service.component.annotations.Deactivate;
52import org.osgi.service.component.annotations.Modified;
53import org.osgi.service.component.annotations.Reference;
54import org.osgi.service.component.annotations.ReferenceCardinality;
Thomas Vachuskac40d4632015-04-09 16:55:03 -070055import org.slf4j.Logger;
56
57import java.util.Dictionary;
Thomas Vachuska8e038eb2016-02-23 23:28:23 -080058import java.util.Objects;
Thomas Vachuskac40d4632015-04-09 16:55:03 -070059import java.util.Properties;
60
61import static com.google.common.base.Strings.isNullOrEmpty;
62import static org.onlab.util.Tools.delay;
63import static org.onlab.util.Tools.get;
64import static org.onosproject.net.DeviceId.deviceId;
65import static org.onosproject.net.MastershipRole.MASTER;
66import static org.onosproject.net.MastershipRole.NONE;
Thomas Vachuska00b5d4f2018-10-30 15:13:20 -070067import static org.onosproject.provider.nil.OsgiPropertyConstants.*;
Thomas Vachuskac40d4632015-04-09 16:55:03 -070068import static org.slf4j.LoggerFactory.getLogger;
69
70/**
71 * Provider of a fake network environment, i.e. devices, links, hosts, etc.
72 * To be used for benchmarking only.
73 */
Thomas Vachuska4167c3f2018-10-16 07:16:31 -070074@Component(immediate = true, service = NullProviders.class,
75 property = {
Thomas Vachuska00b5d4f2018-10-30 15:13:20 -070076 ENABLED + ":Boolean=" + ENABLED_DEFAULT,
77 TOPO_SHAPE + "=" + TOPO_SHAPE_DEFAULT,
78 DEVICE_COUNT + ":Integer=" + DEVICE_COUNT_DEFAULT,
79 HOST_COUNT + ":Integer=" + HOST_COUNT_DEFAULT,
80 PACKET_RATE + ":Integer=" + PACKET_RATE_DEFAULT,
81 MUTATION_RATE + ":Double=" + MUTATION_RATE_DEFAULT,
82 MASTERSHIP + "=" + MASTERSHIP_DEFAULT,
Thomas Vachuska4167c3f2018-10-16 07:16:31 -070083 })
Thomas Vachuskac40d4632015-04-09 16:55:03 -070084public class NullProviders {
85
86 private static final Logger log = getLogger(NullProviders.class);
87
88 static final String SCHEME = "null";
89 static final String PROVIDER_ID = "org.onosproject.provider.nil";
90
91 private static final String FORMAT =
92 "Settings: enabled={}, topoShape={}, deviceCount={}, " +
93 "hostCount={}, packetRate={}, mutationRate={}";
94
Ray Milkeyd84f89b2018-08-17 14:54:17 -070095 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Thomas Vachuskac40d4632015-04-09 16:55:03 -070096 protected ClusterService clusterService;
97
Ray Milkeyd84f89b2018-08-17 14:54:17 -070098 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Thomas Vachuskac40d4632015-04-09 16:55:03 -070099 protected MastershipAdminService mastershipService;
100
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700101 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700102 protected ComponentConfigService cfgService;
103
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700104 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700105 protected DeviceAdminService deviceService;
106
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700107 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700108 protected HostService hostService;
109
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700110 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700111 protected LinkService linkService;
112
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700113 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700114 protected DeviceProviderRegistry deviceProviderRegistry;
115
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700116 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700117 protected HostProviderRegistry hostProviderRegistry;
118
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700119 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700120 protected LinkProviderRegistry linkProviderRegistry;
121
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700122 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700123 protected FlowRuleProviderRegistry flowRuleProviderRegistry;
124
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700125 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Yi Tseng3dca0f82018-04-03 14:33:03 +0800126 protected GroupProviderRegistry groupProviderRegistry;
127
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700128 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700129 protected PacketProviderRegistry packetProviderRegistry;
130
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700131 private final NullDeviceProvider deviceProvider = new NullDeviceProvider();
132 private final NullLinkProvider linkProvider = new NullLinkProvider();
133 private final NullHostProvider hostProvider = new NullHostProvider();
134 private final NullFlowRuleProvider flowRuleProvider = new NullFlowRuleProvider();
Yi Tseng3dca0f82018-04-03 14:33:03 +0800135 private final NullGroupProvider groupProvider = new NullGroupProvider();
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700136 private final NullPacketProvider packetProvider = new NullPacketProvider();
137 private final TopologyMutationDriver topologyMutationDriver = new TopologyMutationDriver();
138
139 private DeviceProviderService deviceProviderService;
140 private HostProviderService hostProviderService;
141 private LinkProviderService linkProviderService;
142 private FlowRuleProviderService flowRuleProviderService;
Yi Tseng3dca0f82018-04-03 14:33:03 +0800143 private GroupProviderService groupProviderService;
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700144 private PacketProviderService packetProviderService;
145
146 private TopologySimulator simulator;
147
Thomas Vachuska00b5d4f2018-10-30 15:13:20 -0700148 /** Enables or disables the provider. */
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700149 private boolean enabled = false;
150
Thomas Vachuska00b5d4f2018-10-30 15:13:20 -0700151 /** Topology shape: configured, linear, reroute, tree, spineleaf, mesh, grid. */
Thomas Vachuska4167c3f2018-10-16 07:16:31 -0700152 private String topoShape = TOPO_SHAPE_DEFAULT;
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700153
Thomas Vachuska00b5d4f2018-10-30 15:13:20 -0700154 /** Number of devices to generate. */
Thomas Vachuska4167c3f2018-10-16 07:16:31 -0700155 private int deviceCount = DEVICE_COUNT_DEFAULT;
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700156
Thomas Vachuska00b5d4f2018-10-30 15:13:20 -0700157 /** Number of host to generate per device. */
Thomas Vachuska4167c3f2018-10-16 07:16:31 -0700158 private int hostCount = HOST_COUNT_DEFAULT;
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700159
Thomas Vachuska00b5d4f2018-10-30 15:13:20 -0700160 /** Packet-in/s rate; 0 for no packets. */
Thomas Vachuska4167c3f2018-10-16 07:16:31 -0700161 private int packetRate = PACKET_RATE_DEFAULT;
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700162
Thomas Vachuska00b5d4f2018-10-30 15:13:20 -0700163 /** Link event/s topology mutation rate; 0 for no mutations. */
Thomas Vachuska4167c3f2018-10-16 07:16:31 -0700164 private double mutationRate = MUTATION_RATE_DEFAULT;
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700165
Thomas Vachuska00b5d4f2018-10-30 15:13:20 -0700166 /** Mastership given as 'random' or 'node1=dpid,dpid/node2=dpid,...'. */
Thomas Vachuska4167c3f2018-10-16 07:16:31 -0700167 private String mastership = MASTERSHIP_DEFAULT;
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700168
169
170 @Activate
Thomas Vachuska41fe1ec2015-12-03 23:17:02 -0800171 public void activate() {
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700172 cfgService.registerProperties(getClass());
173
174 deviceProviderService = deviceProviderRegistry.register(deviceProvider);
175 hostProviderService = hostProviderRegistry.register(hostProvider);
176 linkProviderService = linkProviderRegistry.register(linkProvider);
177 flowRuleProviderService = flowRuleProviderRegistry.register(flowRuleProvider);
Yi Tseng3dca0f82018-04-03 14:33:03 +0800178 groupProviderService = groupProviderRegistry.register(groupProvider);
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700179 packetProviderService = packetProviderRegistry.register(packetProvider);
180 log.info("Started");
181 }
182
183 @Deactivate
Thomas Vachuska41fe1ec2015-12-03 23:17:02 -0800184 public void deactivate() {
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700185 cfgService.unregisterProperties(getClass(), false);
186 tearDown();
187
188 deviceProviderRegistry.unregister(deviceProvider);
189 hostProviderRegistry.unregister(hostProvider);
190 linkProviderRegistry.unregister(linkProvider);
191 flowRuleProviderRegistry.unregister(flowRuleProvider);
Yi Tseng3dca0f82018-04-03 14:33:03 +0800192 groupProviderRegistry.unregister(groupProvider);
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700193 packetProviderRegistry.unregister(packetProvider);
194
195 deviceProviderService = null;
196 hostProviderService = null;
197 linkProviderService = null;
198 flowRuleProviderService = null;
Yi Tseng3dca0f82018-04-03 14:33:03 +0800199 groupProviderService = null;
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700200 packetProviderService = null;
201
202 log.info("Stopped");
203 }
204
205 @Modified
206 public void modified(ComponentContext context) {
207 Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties();
208
209 boolean newEnabled;
210 int newDeviceCount, newHostCount, newPacketRate;
211 double newMutationRate;
212 String newTopoShape, newMastership;
213 try {
Thomas Vachuska00b5d4f2018-10-30 15:13:20 -0700214 String s = get(properties, ENABLED);
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700215 newEnabled = isNullOrEmpty(s) ? enabled : Boolean.parseBoolean(s.trim());
216
Thomas Vachuska00b5d4f2018-10-30 15:13:20 -0700217 newTopoShape = get(properties, TOPO_SHAPE);
218 newMastership = get(properties, MASTERSHIP);
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700219
Thomas Vachuska00b5d4f2018-10-30 15:13:20 -0700220 s = get(properties, DEVICE_COUNT);
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700221 newDeviceCount = isNullOrEmpty(s) ? deviceCount : Integer.parseInt(s.trim());
222
Thomas Vachuska00b5d4f2018-10-30 15:13:20 -0700223 s = get(properties, HOST_COUNT);
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700224 newHostCount = isNullOrEmpty(s) ? hostCount : Integer.parseInt(s.trim());
225
Thomas Vachuska00b5d4f2018-10-30 15:13:20 -0700226 s = get(properties, PACKET_RATE);
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700227 newPacketRate = isNullOrEmpty(s) ? packetRate : Integer.parseInt(s.trim());
228
Thomas Vachuska00b5d4f2018-10-30 15:13:20 -0700229 s = get(properties, MUTATION_RATE);
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700230 newMutationRate = isNullOrEmpty(s) ? mutationRate : Double.parseDouble(s.trim());
231
232 } catch (NumberFormatException e) {
233 log.warn(e.getMessage());
234 newEnabled = enabled;
235 newTopoShape = topoShape;
236 newDeviceCount = deviceCount;
237 newHostCount = hostCount;
238 newPacketRate = packetRate;
239 newMutationRate = mutationRate;
240 newMastership = mastership;
241 }
242
243 // Any change in the following parameters implies hard restart
Thomas Vachuska8e038eb2016-02-23 23:28:23 -0800244 if (newEnabled != enabled || !Objects.equals(newTopoShape, topoShape) ||
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700245 newDeviceCount != deviceCount || newHostCount != hostCount) {
246 enabled = newEnabled;
247 topoShape = newTopoShape;
248 deviceCount = newDeviceCount;
249 hostCount = newHostCount;
250 packetRate = newPacketRate;
251 mutationRate = newMutationRate;
252 restartSimulation();
253 }
254
255 // Any change in the following parameters implies just a rate change
256 if (newPacketRate != packetRate || newMutationRate != mutationRate) {
257 packetRate = newPacketRate;
258 mutationRate = newMutationRate;
259 adjustRates();
260 }
261
262 // Any change in mastership implies just reassignments.
Thomas Vachuska8e038eb2016-02-23 23:28:23 -0800263 if (!Objects.equals(newMastership, mastership)) {
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700264 mastership = newMastership;
265 reassignMastership();
266 }
267
268 log.info(FORMAT, enabled, topoShape, deviceCount, hostCount,
269 packetRate, mutationRate);
270 }
271
272 /**
Thomas Vachuska5c6ed222016-06-29 11:02:22 +0200273 * Returns the currently active topology simulator.
274 *
275 * @return current simulator; null if none is active
276 */
277 public TopologySimulator currentSimulator() {
278 return simulator;
279 }
280
281 /**
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700282 * Severs the link between the specified end-points in both directions.
283 *
284 * @param one link endpoint
285 * @param two link endpoint
286 */
287 public void severLink(ConnectPoint one, ConnectPoint two) {
288 if (enabled) {
289 topologyMutationDriver.severLink(one, two);
290 }
291 }
292
293 /**
294 * Severs the link between the specified end-points in both directions.
295 *
296 * @param one link endpoint
297 * @param two link endpoint
298 */
299 public void repairLink(ConnectPoint one, ConnectPoint two) {
300 if (enabled) {
301 topologyMutationDriver.repairLink(one, two);
302 }
303 }
304
Thomas Vachuska8e038eb2016-02-23 23:28:23 -0800305 /**
306 * Fails the specified device.
307 *
308 * @param deviceId device identifier
309 */
310 public void failDevice(DeviceId deviceId) {
311 if (enabled) {
312 topologyMutationDriver.failDevice(deviceId);
313 }
314 }
315
316 /**
317 * Repairs the specified device.
318 *
319 * @param deviceId device identifier
320 */
321 public void repairDevice(DeviceId deviceId) {
322 if (enabled) {
323 topologyMutationDriver.repairDevice(deviceId);
324 }
325 }
326
327
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700328 // Resets simulation based on the current configuration parameters.
329 private void restartSimulation() {
330 tearDown();
331 if (enabled) {
332 setUp();
333 }
334 }
335
336 // Sets up the topology simulation and all providers.
337 private void setUp() {
338 simulator = selectSimulator(topoShape);
339 simulator.init(topoShape, deviceCount, hostCount,
340 new DefaultServiceDirectory(),
341 deviceProviderService, hostProviderService,
342 linkProviderService);
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700343 flowRuleProvider.start(flowRuleProviderService);
Yi Tseng3dca0f82018-04-03 14:33:03 +0800344 groupProvider.start(groupProviderService);
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700345 packetProvider.start(packetRate, hostService, deviceService,
346 packetProviderService);
Thomas Vachuska1cbd65e2016-06-25 16:27:57 +0200347 simulator.setUpTopology();
Yi Tseng3dca0f82018-04-03 14:33:03 +0800348 groupProvider.initDevicesGroupTable(simulator.deviceIds);
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700349 topologyMutationDriver.start(mutationRate, linkService, deviceService,
Thomas Vachuska8e038eb2016-02-23 23:28:23 -0800350 linkProviderService, deviceProviderService,
351 simulator);
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700352 }
353
354 // Selects the simulator based on the specified name.
355 private TopologySimulator selectSimulator(String topoShape) {
356 if (topoShape.matches("linear([,].*|$)")) {
357 return new LinearTopologySimulator();
358 } else if (topoShape.matches("centipede([,].*|$)")) {
359 return new CentipedeTopologySimulator();
360 } else if (topoShape.matches("reroute([,].*|$)")) {
361 return new RerouteTopologySimulator();
362 } else if (topoShape.matches("tree([,].*|$)")) {
363 return new TreeTopologySimulator();
Thomas Vachuska59da18d2015-07-07 17:44:21 -0700364 } else if (topoShape.matches("agglink([,].*|$)")) {
365 return new AggLinkTopologySimulator();
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700366 } else if (topoShape.matches("spineleaf([,].*|$)")) {
367 return new SpineLeafTopologySimulator();
368 } else if (topoShape.matches("mesh([,].*|$)")) {
369 return new MeshTopologySimulator();
Thomas Vachuska8e038eb2016-02-23 23:28:23 -0800370 } else if (topoShape.matches("grid([,].*|$)")) {
371 return new GridTopologySimulator();
Andreas Pantelopoulos620d3d72016-11-08 22:18:59 +0100372 } else if (topoShape.matches("fattree([,].*|$)")) {
373 return new FatTreeTopologySimulator();
hyunmin no97174182016-12-13 21:14:30 +0900374 } else if (topoShape.matches("chordal([,].*|$)")) {
375 return new ChordalTopologySimulator();
Thomas Vachuska5c6ed222016-06-29 11:02:22 +0200376 } else if (topoShape.matches("custom([,].*|$)")) {
377 return new CustomTopologySimulator();
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700378 } else {
379 return new ConfiguredTopologySimulator();
380 }
381 }
382
383 // Shuts down the topology simulator and all providers.
384 private void tearDown() {
385 if (simulator != null) {
386 topologyMutationDriver.stop();
387 packetProvider.stop();
388 flowRuleProvider.stop();
Yi Tseng3dca0f82018-04-03 14:33:03 +0800389 groupProvider.stop();
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700390 delay(500);
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700391 simulator.tearDownTopology();
392 simulator = null;
Thomas Vachuskacab29d22018-02-21 15:47:29 -0800393
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700394 }
395 }
396
397 // Changes packet and mutation rates.
398 private void adjustRates() {
399 packetProvider.adjustRate(packetRate);
400 topologyMutationDriver.adjustRate(mutationRate);
401 }
402
403 // Re-assigns mastership roles.
404 private void reassignMastership() {
Thomas Vachuska4167c3f2018-10-16 07:16:31 -0700405 if (mastership.equals(MASTERSHIP_DEFAULT)) {
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700406 mastershipService.balanceRoles();
407 } else {
408 NodeId localNode = clusterService.getLocalNode().id();
409 rejectMastership();
410 String[] nodeSpecs = mastership.split("/");
411 for (int i = 0; i < nodeSpecs.length; i++) {
412 String[] specs = nodeSpecs[i].split("=");
413 if (specs[0].equals(localNode.toString())) {
414 String[] ids = specs[1].split(",");
415 for (String id : ids) {
416 mastershipService.setRole(localNode, deviceId(id), MASTER);
417 }
418 break;
419 }
420 }
421 }
422 }
423
424 // Rejects mastership of all devices.
425 private void rejectMastership() {
426 NodeId localNode = clusterService.getLocalNode().id();
427 deviceService.getDevices()
428 .forEach(device -> mastershipService.setRole(localNode, device.id(),
429 NONE));
430 }
431
432 // Null provider base class.
433 abstract static class AbstractNullProvider extends AbstractProvider {
434 protected AbstractNullProvider() {
435 super(new ProviderId(SCHEME, PROVIDER_ID));
436 }
437 }
438
439 // Device provider facade.
440 private class NullDeviceProvider extends AbstractNullProvider implements DeviceProvider {
441 @Override
442 public void roleChanged(DeviceId deviceId, MastershipRole newRole) {
443 deviceProviderService.receivedRoleReply(deviceId, newRole, newRole);
444 }
445
446 @Override
447 public boolean isReachable(DeviceId deviceId) {
Thomas Vachuskab1906d22018-02-14 16:50:16 -0800448 return simulator != null &&
449 (simulator.contains(deviceId) || !deviceService.getPorts(deviceId).isEmpty()) &&
450 (simulator instanceof CustomTopologySimulator ||
Thomas Vachuska8e038eb2016-02-23 23:28:23 -0800451 topologyMutationDriver.isReachable(deviceId));
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700452 }
453
454 @Override
455 public void triggerProbe(DeviceId deviceId) {
456 }
Saurav Dasa2d37502016-03-25 17:50:40 -0700457
458 @Override
459 public void changePortState(DeviceId deviceId, PortNumber portNumber,
460 boolean enable) {
461 // TODO maybe required
462 }
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700463 }
464
465 // Host provider facade.
466 private class NullHostProvider extends AbstractNullProvider implements HostProvider {
467 @Override
468 public void triggerProbe(Host host) {
469 }
470 }
471
472 // Host provider facade.
473 private class NullLinkProvider extends AbstractNullProvider implements LinkProvider {
474 }
475
476}