blob: bfca14e4efeef7280e5407897e8b5120b1d09717 [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.cli;
17
18import org.apache.karaf.shell.commands.Argument;
19import org.apache.karaf.shell.commands.Command;
20import org.onosproject.cfg.ComponentConfigService;
21import org.onosproject.cli.AbstractShellCommand;
Simon Huntb3567282017-04-07 22:59:28 -070022import org.onosproject.provider.nil.CustomTopologySimulator;
Thomas Vachuskac40d4632015-04-09 16:55:03 -070023import org.onosproject.provider.nil.NullProviders;
Simon Huntb3567282017-04-07 22:59:28 -070024import org.onosproject.provider.nil.TopologySimulator;
Thomas Vachuskac40d4632015-04-09 16:55:03 -070025
26import static org.onosproject.cli.StartStopCompleter.START;
27
28/**
29 * Starts or stops topology simulation.
30 */
31@Command(scope = "onos", name = "null-simulation",
32 description = "Starts or stops topology simulation")
33public class NullControlCommand extends AbstractShellCommand {
34
Simon Huntb3567282017-04-07 22:59:28 -070035 private static final String CUSTOM = "custom";
36
Thomas Vachuskac40d4632015-04-09 16:55:03 -070037 @Argument(index = 0, name = "cmd", description = "Control command: start/stop",
38 required = true, multiValued = false)
39 String cmd = null;
40
41 @Argument(index = 1, name = "topoShape",
Simon Huntb3567282017-04-07 22:59:28 -070042 description = "Topology shape: e.g. configured, linear, reroute, " +
43 "centipede, tree, spineleaf, mesh, fattree, custom",
Thomas Vachuskac40d4632015-04-09 16:55:03 -070044 required = false, multiValued = false)
45 String topoShape = null;
46
47 @Override
48 protected void execute() {
49 ComponentConfigService service = get(ComponentConfigService.class);
50 if (topoShape != null) {
51 service.setProperty(NullProviders.class.getName(), "topoShape", topoShape);
52 }
53 service.setProperty(NullProviders.class.getName(), "enabled",
54 cmd.equals(START) ? "true" : "false");
Simon Huntb3567282017-04-07 22:59:28 -070055
56 // If we are re-starting the "custom" topology, reset the counts
57 // on the auto-assigned IDs for null-devices and null-hosts, so that
58 // scripts can rely on consistent assignment of IDs to nodes.
59 if (CUSTOM.equals(topoShape) && START.equals(cmd)) {
60 NullProviders npService = get(NullProviders.class);
61 TopologySimulator simulator = npService.currentSimulator();
62 if (simulator instanceof CustomTopologySimulator) {
63 CustomTopologySimulator sim = (CustomTopologySimulator) simulator;
64 sim.resetIdSeeds();
65 }
66 }
Thomas Vachuskac40d4632015-04-09 16:55:03 -070067 }
68
69}