blob: 1be41d69c20e646a9a0a2ad8c9f2fd6b86b9fe26 [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
Ray Milkey86ad7bb2018-09-27 12:32:28 -070018import org.apache.karaf.shell.api.action.Argument;
19import org.apache.karaf.shell.api.action.Command;
Ray Milkeyd5435182018-10-11 16:18:51 -070020import org.apache.karaf.shell.api.action.Completion;
Ray Milkey7a2dee52018-09-28 10:58:28 -070021import org.apache.karaf.shell.api.action.lifecycle.Service;
Thomas Vachuskac40d4632015-04-09 16:55:03 -070022import org.onosproject.cfg.ComponentConfigService;
23import org.onosproject.cli.AbstractShellCommand;
Ray Milkeyd5435182018-10-11 16:18:51 -070024import org.onosproject.cli.StartStopCompleter;
Thomas Vachuskac40d4632015-04-09 16:55:03 -070025import org.onosproject.provider.nil.NullProviders;
Simon Huntb3567282017-04-07 22:59:28 -070026import org.onosproject.provider.nil.TopologySimulator;
Thomas Vachuskac40d4632015-04-09 16:55:03 -070027
28import static org.onosproject.cli.StartStopCompleter.START;
29
30/**
31 * Starts or stops topology simulation.
32 */
Ray Milkey7a2dee52018-09-28 10:58:28 -070033@Service
Thomas Vachuskac40d4632015-04-09 16:55:03 -070034@Command(scope = "onos", name = "null-simulation",
35 description = "Starts or stops topology simulation")
36public class NullControlCommand extends AbstractShellCommand {
37
38 @Argument(index = 0, name = "cmd", description = "Control command: start/stop",
Thomas Vachuskacab29d22018-02-21 15:47:29 -080039 required = true)
Ray Milkeyd5435182018-10-11 16:18:51 -070040 @Completion(StartStopCompleter.class)
Thomas Vachuskac40d4632015-04-09 16:55:03 -070041 String cmd = null;
42
43 @Argument(index = 1, name = "topoShape",
Simon Huntb3567282017-04-07 22:59:28 -070044 description = "Topology shape: e.g. configured, linear, reroute, " +
Thomas Vachuskacab29d22018-02-21 15:47:29 -080045 "centipede, tree, spineleaf, mesh, fattree, custom")
Ray Milkeyd5435182018-10-11 16:18:51 -070046 @Completion(TopologyShapeCompleter.class)
Thomas Vachuskac40d4632015-04-09 16:55:03 -070047 String topoShape = null;
48
49 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070050 protected void doExecute() {
Thomas Vachuskac40d4632015-04-09 16:55:03 -070051 ComponentConfigService service = get(ComponentConfigService.class);
Thomas Vachuskacab29d22018-02-21 15:47:29 -080052 // If there is an existing topology; make sure it's stopped before restarting
53 if (cmd.equals(START)) {
54 NullProviders npService = get(NullProviders.class);
55 TopologySimulator simulator = npService.currentSimulator();
56 if (simulator != null) {
57 simulator.tearDownTopology();
58 }
59 }
60
Thomas Vachuskac40d4632015-04-09 16:55:03 -070061 if (topoShape != null) {
62 service.setProperty(NullProviders.class.getName(), "topoShape", topoShape);
63 }
64 service.setProperty(NullProviders.class.getName(), "enabled",
65 cmd.equals(START) ? "true" : "false");
Thomas Vachuskac40d4632015-04-09 16:55:03 -070066 }
67
68}