blob: be0f753539a80b27d11f7cb496e8351e382740ab [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();
Thomas Vachuskaa4eac6a2021-03-01 15:11:59 -0800138 private final PortStatsDriver portStatsDriver = new PortStatsDriver();
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700139
140 private DeviceProviderService deviceProviderService;
141 private HostProviderService hostProviderService;
142 private LinkProviderService linkProviderService;
143 private FlowRuleProviderService flowRuleProviderService;
Yi Tseng3dca0f82018-04-03 14:33:03 +0800144 private GroupProviderService groupProviderService;
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700145 private PacketProviderService packetProviderService;
146
147 private TopologySimulator simulator;
148
Thomas Vachuska00b5d4f2018-10-30 15:13:20 -0700149 /** Enables or disables the provider. */
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700150 private boolean enabled = false;
151
Thomas Vachuska00b5d4f2018-10-30 15:13:20 -0700152 /** Topology shape: configured, linear, reroute, tree, spineleaf, mesh, grid. */
Thomas Vachuska4167c3f2018-10-16 07:16:31 -0700153 private String topoShape = TOPO_SHAPE_DEFAULT;
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700154
Thomas Vachuska00b5d4f2018-10-30 15:13:20 -0700155 /** Number of devices to generate. */
Thomas Vachuska4167c3f2018-10-16 07:16:31 -0700156 private int deviceCount = DEVICE_COUNT_DEFAULT;
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700157
Thomas Vachuska00b5d4f2018-10-30 15:13:20 -0700158 /** Number of host to generate per device. */
Thomas Vachuska4167c3f2018-10-16 07:16:31 -0700159 private int hostCount = HOST_COUNT_DEFAULT;
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700160
Thomas Vachuska00b5d4f2018-10-30 15:13:20 -0700161 /** Packet-in/s rate; 0 for no packets. */
Thomas Vachuska4167c3f2018-10-16 07:16:31 -0700162 private int packetRate = PACKET_RATE_DEFAULT;
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700163
Thomas Vachuska00b5d4f2018-10-30 15:13:20 -0700164 /** Link event/s topology mutation rate; 0 for no mutations. */
Thomas Vachuska4167c3f2018-10-16 07:16:31 -0700165 private double mutationRate = MUTATION_RATE_DEFAULT;
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700166
Thomas Vachuska00b5d4f2018-10-30 15:13:20 -0700167 /** Mastership given as 'random' or 'node1=dpid,dpid/node2=dpid,...'. */
Thomas Vachuska4167c3f2018-10-16 07:16:31 -0700168 private String mastership = MASTERSHIP_DEFAULT;
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700169
170
171 @Activate
Thomas Vachuska41fe1ec2015-12-03 23:17:02 -0800172 public void activate() {
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700173 cfgService.registerProperties(getClass());
174
175 deviceProviderService = deviceProviderRegistry.register(deviceProvider);
176 hostProviderService = hostProviderRegistry.register(hostProvider);
177 linkProviderService = linkProviderRegistry.register(linkProvider);
178 flowRuleProviderService = flowRuleProviderRegistry.register(flowRuleProvider);
Yi Tseng3dca0f82018-04-03 14:33:03 +0800179 groupProviderService = groupProviderRegistry.register(groupProvider);
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700180 packetProviderService = packetProviderRegistry.register(packetProvider);
181 log.info("Started");
182 }
183
184 @Deactivate
Thomas Vachuska41fe1ec2015-12-03 23:17:02 -0800185 public void deactivate() {
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700186 cfgService.unregisterProperties(getClass(), false);
187 tearDown();
188
189 deviceProviderRegistry.unregister(deviceProvider);
190 hostProviderRegistry.unregister(hostProvider);
191 linkProviderRegistry.unregister(linkProvider);
192 flowRuleProviderRegistry.unregister(flowRuleProvider);
Yi Tseng3dca0f82018-04-03 14:33:03 +0800193 groupProviderRegistry.unregister(groupProvider);
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700194 packetProviderRegistry.unregister(packetProvider);
195
196 deviceProviderService = null;
197 hostProviderService = null;
198 linkProviderService = null;
199 flowRuleProviderService = null;
Yi Tseng3dca0f82018-04-03 14:33:03 +0800200 groupProviderService = null;
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700201 packetProviderService = null;
202
203 log.info("Stopped");
204 }
205
206 @Modified
207 public void modified(ComponentContext context) {
208 Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties();
209
210 boolean newEnabled;
211 int newDeviceCount, newHostCount, newPacketRate;
212 double newMutationRate;
213 String newTopoShape, newMastership;
214 try {
Thomas Vachuska00b5d4f2018-10-30 15:13:20 -0700215 String s = get(properties, ENABLED);
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700216 newEnabled = isNullOrEmpty(s) ? enabled : Boolean.parseBoolean(s.trim());
217
Thomas Vachuska00b5d4f2018-10-30 15:13:20 -0700218 newTopoShape = get(properties, TOPO_SHAPE);
219 newMastership = get(properties, MASTERSHIP);
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700220
Thomas Vachuska00b5d4f2018-10-30 15:13:20 -0700221 s = get(properties, DEVICE_COUNT);
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700222 newDeviceCount = isNullOrEmpty(s) ? deviceCount : Integer.parseInt(s.trim());
223
Thomas Vachuska00b5d4f2018-10-30 15:13:20 -0700224 s = get(properties, HOST_COUNT);
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700225 newHostCount = isNullOrEmpty(s) ? hostCount : Integer.parseInt(s.trim());
226
Thomas Vachuska00b5d4f2018-10-30 15:13:20 -0700227 s = get(properties, PACKET_RATE);
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700228 newPacketRate = isNullOrEmpty(s) ? packetRate : Integer.parseInt(s.trim());
229
Thomas Vachuska00b5d4f2018-10-30 15:13:20 -0700230 s = get(properties, MUTATION_RATE);
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700231 newMutationRate = isNullOrEmpty(s) ? mutationRate : Double.parseDouble(s.trim());
232
233 } catch (NumberFormatException e) {
234 log.warn(e.getMessage());
235 newEnabled = enabled;
236 newTopoShape = topoShape;
237 newDeviceCount = deviceCount;
238 newHostCount = hostCount;
239 newPacketRate = packetRate;
240 newMutationRate = mutationRate;
241 newMastership = mastership;
242 }
243
244 // Any change in the following parameters implies hard restart
Thomas Vachuska8e038eb2016-02-23 23:28:23 -0800245 if (newEnabled != enabled || !Objects.equals(newTopoShape, topoShape) ||
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700246 newDeviceCount != deviceCount || newHostCount != hostCount) {
247 enabled = newEnabled;
248 topoShape = newTopoShape;
249 deviceCount = newDeviceCount;
250 hostCount = newHostCount;
251 packetRate = newPacketRate;
252 mutationRate = newMutationRate;
253 restartSimulation();
254 }
255
256 // Any change in the following parameters implies just a rate change
257 if (newPacketRate != packetRate || newMutationRate != mutationRate) {
258 packetRate = newPacketRate;
259 mutationRate = newMutationRate;
260 adjustRates();
261 }
262
263 // Any change in mastership implies just reassignments.
Thomas Vachuska8e038eb2016-02-23 23:28:23 -0800264 if (!Objects.equals(newMastership, mastership)) {
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700265 mastership = newMastership;
266 reassignMastership();
267 }
268
269 log.info(FORMAT, enabled, topoShape, deviceCount, hostCount,
270 packetRate, mutationRate);
271 }
272
273 /**
Thomas Vachuska5c6ed222016-06-29 11:02:22 +0200274 * Returns the currently active topology simulator.
275 *
276 * @return current simulator; null if none is active
277 */
278 public TopologySimulator currentSimulator() {
279 return simulator;
280 }
281
282 /**
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700283 * Severs the link between the specified end-points in both directions.
284 *
285 * @param one link endpoint
286 * @param two link endpoint
287 */
288 public void severLink(ConnectPoint one, ConnectPoint two) {
289 if (enabled) {
290 topologyMutationDriver.severLink(one, two);
291 }
292 }
293
294 /**
295 * Severs the link between the specified end-points in both directions.
296 *
297 * @param one link endpoint
298 * @param two link endpoint
299 */
300 public void repairLink(ConnectPoint one, ConnectPoint two) {
301 if (enabled) {
302 topologyMutationDriver.repairLink(one, two);
303 }
304 }
305
Thomas Vachuska8e038eb2016-02-23 23:28:23 -0800306 /**
307 * Fails the specified device.
308 *
309 * @param deviceId device identifier
310 */
311 public void failDevice(DeviceId deviceId) {
312 if (enabled) {
313 topologyMutationDriver.failDevice(deviceId);
314 }
315 }
316
317 /**
318 * Repairs the specified device.
319 *
320 * @param deviceId device identifier
321 */
322 public void repairDevice(DeviceId deviceId) {
323 if (enabled) {
324 topologyMutationDriver.repairDevice(deviceId);
325 }
326 }
327
328
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700329 // Resets simulation based on the current configuration parameters.
330 private void restartSimulation() {
331 tearDown();
332 if (enabled) {
333 setUp();
334 }
335 }
336
337 // Sets up the topology simulation and all providers.
338 private void setUp() {
339 simulator = selectSimulator(topoShape);
340 simulator.init(topoShape, deviceCount, hostCount,
341 new DefaultServiceDirectory(),
342 deviceProviderService, hostProviderService,
343 linkProviderService);
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700344 flowRuleProvider.start(flowRuleProviderService);
Yi Tseng3dca0f82018-04-03 14:33:03 +0800345 groupProvider.start(groupProviderService);
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700346 packetProvider.start(packetRate, hostService, deviceService,
347 packetProviderService);
Thomas Vachuska1cbd65e2016-06-25 16:27:57 +0200348 simulator.setUpTopology();
Yi Tseng3dca0f82018-04-03 14:33:03 +0800349 groupProvider.initDevicesGroupTable(simulator.deviceIds);
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700350 topologyMutationDriver.start(mutationRate, linkService, deviceService,
Thomas Vachuska8e038eb2016-02-23 23:28:23 -0800351 linkProviderService, deviceProviderService,
352 simulator);
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700353 }
354
355 // Selects the simulator based on the specified name.
356 private TopologySimulator selectSimulator(String topoShape) {
357 if (topoShape.matches("linear([,].*|$)")) {
358 return new LinearTopologySimulator();
359 } else if (topoShape.matches("centipede([,].*|$)")) {
360 return new CentipedeTopologySimulator();
361 } else if (topoShape.matches("reroute([,].*|$)")) {
362 return new RerouteTopologySimulator();
363 } else if (topoShape.matches("tree([,].*|$)")) {
364 return new TreeTopologySimulator();
Thomas Vachuska59da18d2015-07-07 17:44:21 -0700365 } else if (topoShape.matches("agglink([,].*|$)")) {
366 return new AggLinkTopologySimulator();
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700367 } else if (topoShape.matches("spineleaf([,].*|$)")) {
368 return new SpineLeafTopologySimulator();
369 } else if (topoShape.matches("mesh([,].*|$)")) {
370 return new MeshTopologySimulator();
Thomas Vachuska8e038eb2016-02-23 23:28:23 -0800371 } else if (topoShape.matches("grid([,].*|$)")) {
372 return new GridTopologySimulator();
Andreas Pantelopoulos620d3d72016-11-08 22:18:59 +0100373 } else if (topoShape.matches("fattree([,].*|$)")) {
374 return new FatTreeTopologySimulator();
hyunmin no97174182016-12-13 21:14:30 +0900375 } else if (topoShape.matches("chordal([,].*|$)")) {
376 return new ChordalTopologySimulator();
Thomas Vachuska5c6ed222016-06-29 11:02:22 +0200377 } else if (topoShape.matches("custom([,].*|$)")) {
378 return new CustomTopologySimulator();
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700379 } else {
380 return new ConfiguredTopologySimulator();
381 }
382 }
383
384 // Shuts down the topology simulator and all providers.
385 private void tearDown() {
386 if (simulator != null) {
387 topologyMutationDriver.stop();
388 packetProvider.stop();
389 flowRuleProvider.stop();
Yi Tseng3dca0f82018-04-03 14:33:03 +0800390 groupProvider.stop();
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700391 delay(500);
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700392 simulator.tearDownTopology();
393 simulator = null;
Thomas Vachuskacab29d22018-02-21 15:47:29 -0800394
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700395 }
396 }
397
398 // Changes packet and mutation rates.
399 private void adjustRates() {
400 packetProvider.adjustRate(packetRate);
401 topologyMutationDriver.adjustRate(mutationRate);
402 }
403
404 // Re-assigns mastership roles.
405 private void reassignMastership() {
Thomas Vachuska4167c3f2018-10-16 07:16:31 -0700406 if (mastership.equals(MASTERSHIP_DEFAULT)) {
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700407 mastershipService.balanceRoles();
408 } else {
409 NodeId localNode = clusterService.getLocalNode().id();
410 rejectMastership();
411 String[] nodeSpecs = mastership.split("/");
412 for (int i = 0; i < nodeSpecs.length; i++) {
413 String[] specs = nodeSpecs[i].split("=");
414 if (specs[0].equals(localNode.toString())) {
415 String[] ids = specs[1].split(",");
416 for (String id : ids) {
417 mastershipService.setRole(localNode, deviceId(id), MASTER);
418 }
419 break;
420 }
421 }
422 }
423 }
424
425 // Rejects mastership of all devices.
426 private void rejectMastership() {
427 NodeId localNode = clusterService.getLocalNode().id();
428 deviceService.getDevices()
429 .forEach(device -> mastershipService.setRole(localNode, device.id(),
430 NONE));
431 }
432
Thomas Vachuskaf22fd662021-03-02 22:43:16 -0800433 /**
434 * Enables or disables simulated port statistics.
435 *
436 * @param on true to enable
437 */
438 public void enablePortStats(boolean on) {
439 if (on) {
440 portStatsDriver.start(deviceService, deviceProviderService);
441 } else {
442 portStatsDriver.stop();
443 }
444 }
445
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700446 // Null provider base class.
447 abstract static class AbstractNullProvider extends AbstractProvider {
448 protected AbstractNullProvider() {
449 super(new ProviderId(SCHEME, PROVIDER_ID));
450 }
451 }
452
453 // Device provider facade.
454 private class NullDeviceProvider extends AbstractNullProvider implements DeviceProvider {
455 @Override
456 public void roleChanged(DeviceId deviceId, MastershipRole newRole) {
457 deviceProviderService.receivedRoleReply(deviceId, newRole, newRole);
458 }
459
460 @Override
461 public boolean isReachable(DeviceId deviceId) {
Thomas Vachuskab1906d22018-02-14 16:50:16 -0800462 return simulator != null &&
463 (simulator.contains(deviceId) || !deviceService.getPorts(deviceId).isEmpty()) &&
464 (simulator instanceof CustomTopologySimulator ||
Thomas Vachuska8e038eb2016-02-23 23:28:23 -0800465 topologyMutationDriver.isReachable(deviceId));
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700466 }
467
468 @Override
469 public void triggerProbe(DeviceId deviceId) {
470 }
Saurav Dasa2d37502016-03-25 17:50:40 -0700471
472 @Override
473 public void changePortState(DeviceId deviceId, PortNumber portNumber,
474 boolean enable) {
475 // TODO maybe required
476 }
Thomas Vachuskac40d4632015-04-09 16:55:03 -0700477 }
478
479 // Host provider facade.
480 private class NullHostProvider extends AbstractNullProvider implements HostProvider {
481 @Override
482 public void triggerProbe(Host host) {
483 }
484 }
485
486 // Host provider facade.
487 private class NullLinkProvider extends AbstractNullProvider implements LinkProvider {
488 }
489
490}