Thomas Vachuska | c40d463 | 2015-04-09 16:55:03 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Thomas Vachuska | c40d463 | 2015-04-09 16:55:03 -0700 | [diff] [blame] | 3 | * |
| 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 | */ |
| 16 | package org.onosproject.provider.nil.cli; |
| 17 | |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 18 | import org.apache.karaf.shell.api.action.Argument; |
| 19 | import org.apache.karaf.shell.api.action.Command; |
Ray Milkey | d543518 | 2018-10-11 16:18:51 -0700 | [diff] [blame] | 20 | import org.apache.karaf.shell.api.action.Completion; |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 21 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
Thomas Vachuska | c40d463 | 2015-04-09 16:55:03 -0700 | [diff] [blame] | 22 | import org.onosproject.cfg.ComponentConfigService; |
| 23 | import org.onosproject.cli.AbstractShellCommand; |
Ray Milkey | d543518 | 2018-10-11 16:18:51 -0700 | [diff] [blame] | 24 | import org.onosproject.cli.StartStopCompleter; |
Thomas Vachuska | c40d463 | 2015-04-09 16:55:03 -0700 | [diff] [blame] | 25 | import org.onosproject.provider.nil.NullProviders; |
Simon Hunt | b356728 | 2017-04-07 22:59:28 -0700 | [diff] [blame] | 26 | import org.onosproject.provider.nil.TopologySimulator; |
Thomas Vachuska | c40d463 | 2015-04-09 16:55:03 -0700 | [diff] [blame] | 27 | |
| 28 | import static org.onosproject.cli.StartStopCompleter.START; |
| 29 | |
| 30 | /** |
| 31 | * Starts or stops topology simulation. |
| 32 | */ |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 33 | @Service |
Thomas Vachuska | c40d463 | 2015-04-09 16:55:03 -0700 | [diff] [blame] | 34 | @Command(scope = "onos", name = "null-simulation", |
| 35 | description = "Starts or stops topology simulation") |
| 36 | public class NullControlCommand extends AbstractShellCommand { |
| 37 | |
| 38 | @Argument(index = 0, name = "cmd", description = "Control command: start/stop", |
Thomas Vachuska | cab29d2 | 2018-02-21 15:47:29 -0800 | [diff] [blame] | 39 | required = true) |
Ray Milkey | d543518 | 2018-10-11 16:18:51 -0700 | [diff] [blame] | 40 | @Completion(StartStopCompleter.class) |
Thomas Vachuska | c40d463 | 2015-04-09 16:55:03 -0700 | [diff] [blame] | 41 | String cmd = null; |
| 42 | |
| 43 | @Argument(index = 1, name = "topoShape", |
Simon Hunt | b356728 | 2017-04-07 22:59:28 -0700 | [diff] [blame] | 44 | description = "Topology shape: e.g. configured, linear, reroute, " + |
Thomas Vachuska | cab29d2 | 2018-02-21 15:47:29 -0800 | [diff] [blame] | 45 | "centipede, tree, spineleaf, mesh, fattree, custom") |
Ray Milkey | d543518 | 2018-10-11 16:18:51 -0700 | [diff] [blame] | 46 | @Completion(TopologyShapeCompleter.class) |
Thomas Vachuska | c40d463 | 2015-04-09 16:55:03 -0700 | [diff] [blame] | 47 | String topoShape = null; |
| 48 | |
| 49 | @Override |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 50 | protected void doExecute() { |
Thomas Vachuska | c40d463 | 2015-04-09 16:55:03 -0700 | [diff] [blame] | 51 | ComponentConfigService service = get(ComponentConfigService.class); |
Thomas Vachuska | cab29d2 | 2018-02-21 15:47:29 -0800 | [diff] [blame] | 52 | // 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 Vachuska | c40d463 | 2015-04-09 16:55:03 -0700 | [diff] [blame] | 61 | 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 Vachuska | c40d463 | 2015-04-09 16:55:03 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | } |