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 | |
| 18 | import org.apache.karaf.shell.commands.Argument; |
| 19 | import org.apache.karaf.shell.commands.Command; |
| 20 | import org.onosproject.cfg.ComponentConfigService; |
| 21 | import org.onosproject.cli.AbstractShellCommand; |
Simon Hunt | b356728 | 2017-04-07 22:59:28 -0700 | [diff] [blame] | 22 | import org.onosproject.provider.nil.CustomTopologySimulator; |
Thomas Vachuska | c40d463 | 2015-04-09 16:55:03 -0700 | [diff] [blame] | 23 | import org.onosproject.provider.nil.NullProviders; |
Simon Hunt | b356728 | 2017-04-07 22:59:28 -0700 | [diff] [blame] | 24 | import org.onosproject.provider.nil.TopologySimulator; |
Thomas Vachuska | c40d463 | 2015-04-09 16:55:03 -0700 | [diff] [blame] | 25 | |
| 26 | import 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") |
| 33 | public class NullControlCommand extends AbstractShellCommand { |
| 34 | |
Simon Hunt | b356728 | 2017-04-07 22:59:28 -0700 | [diff] [blame] | 35 | private static final String CUSTOM = "custom"; |
| 36 | |
Thomas Vachuska | c40d463 | 2015-04-09 16:55:03 -0700 | [diff] [blame] | 37 | @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 Hunt | b356728 | 2017-04-07 22:59:28 -0700 | [diff] [blame] | 42 | description = "Topology shape: e.g. configured, linear, reroute, " + |
| 43 | "centipede, tree, spineleaf, mesh, fattree, custom", |
Thomas Vachuska | c40d463 | 2015-04-09 16:55:03 -0700 | [diff] [blame] | 44 | 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 Hunt | b356728 | 2017-04-07 22:59:28 -0700 | [diff] [blame] | 55 | |
| 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 Vachuska | c40d463 | 2015-04-09 16:55:03 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | } |