Thomas Vachuska | 5c6ed22 | 2016-06-29 11:02:22 +0200 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Thomas Vachuska | 5c6ed22 | 2016-06-29 11:02:22 +0200 | [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; |
Thomas Vachuska | 7b1fadc | 2018-09-27 11:20:41 -0700 | [diff] [blame] | 20 | import org.apache.karaf.shell.commands.Option; |
Thomas Vachuska | 84b4fcc | 2018-03-22 14:29:06 -0700 | [diff] [blame] | 21 | import org.onlab.util.Tools; |
Thomas Vachuska | 5c6ed22 | 2016-06-29 11:02:22 +0200 | [diff] [blame] | 22 | import org.onosproject.net.Device; |
| 23 | import org.onosproject.net.DeviceId; |
| 24 | import org.onosproject.net.config.NetworkConfigService; |
| 25 | import org.onosproject.net.config.basics.BasicDeviceConfig; |
| 26 | import org.onosproject.provider.nil.CustomTopologySimulator; |
| 27 | import org.onosproject.provider.nil.NullProviders; |
| 28 | import org.onosproject.provider.nil.TopologySimulator; |
| 29 | |
| 30 | /** |
| 31 | * Adds a simulated device to the custom topology simulation. |
| 32 | */ |
| 33 | @Command(scope = "onos", name = "null-create-device", |
| 34 | description = "Adds a simulated device to the custom topology simulation") |
Thomas Vachuska | b1906d2 | 2018-02-14 16:50:16 -0800 | [diff] [blame] | 35 | public class CreateNullDevice extends CreateNullEntity { |
Thomas Vachuska | 5c6ed22 | 2016-06-29 11:02:22 +0200 | [diff] [blame] | 36 | |
| 37 | @Argument(index = 0, name = "type", description = "Device type, e.g. switch, roadm", |
Thomas Vachuska | b1906d2 | 2018-02-14 16:50:16 -0800 | [diff] [blame] | 38 | required = true) |
Thomas Vachuska | 5c6ed22 | 2016-06-29 11:02:22 +0200 | [diff] [blame] | 39 | String type = null; |
| 40 | |
| 41 | @Argument(index = 1, name = "name", description = "Device name", |
Thomas Vachuska | b1906d2 | 2018-02-14 16:50:16 -0800 | [diff] [blame] | 42 | required = true) |
Thomas Vachuska | 5c6ed22 | 2016-06-29 11:02:22 +0200 | [diff] [blame] | 43 | String name = null; |
| 44 | |
| 45 | @Argument(index = 2, name = "portCount", description = "Port count", |
Thomas Vachuska | b1906d2 | 2018-02-14 16:50:16 -0800 | [diff] [blame] | 46 | required = true) |
Thomas Vachuska | 5c6ed22 | 2016-06-29 11:02:22 +0200 | [diff] [blame] | 47 | Integer portCount = null; |
| 48 | |
Simon Hunt | eb3cf54 | 2017-02-10 13:18:41 -0800 | [diff] [blame] | 49 | @Argument(index = 3, name = "latOrY", |
| 50 | description = "Geo latitude / Grid y-coord", |
Thomas Vachuska | b1906d2 | 2018-02-14 16:50:16 -0800 | [diff] [blame] | 51 | required = false) |
Simon Hunt | eb3cf54 | 2017-02-10 13:18:41 -0800 | [diff] [blame] | 52 | Double latOrY = null; |
Thomas Vachuska | 5c6ed22 | 2016-06-29 11:02:22 +0200 | [diff] [blame] | 53 | |
Simon Hunt | eb3cf54 | 2017-02-10 13:18:41 -0800 | [diff] [blame] | 54 | @Argument(index = 4, name = "longOrX", |
| 55 | description = "Geo longitude / Grid x-coord", |
Thomas Vachuska | b1906d2 | 2018-02-14 16:50:16 -0800 | [diff] [blame] | 56 | required = false) |
Simon Hunt | eb3cf54 | 2017-02-10 13:18:41 -0800 | [diff] [blame] | 57 | Double longOrX = null; |
| 58 | |
| 59 | @Argument(index = 5, name = "locType", description = "Location type {geo|grid}", |
Thomas Vachuska | b1906d2 | 2018-02-14 16:50:16 -0800 | [diff] [blame] | 60 | required = false) |
Simon Hunt | eb3cf54 | 2017-02-10 13:18:41 -0800 | [diff] [blame] | 61 | String locType = GEO; |
Thomas Vachuska | 5c6ed22 | 2016-06-29 11:02:22 +0200 | [diff] [blame] | 62 | |
Thomas Vachuska | 7b1fadc | 2018-09-27 11:20:41 -0700 | [diff] [blame] | 63 | @Option(name = "-I", aliases = "--id", description = "Device identifier") |
| 64 | String id = null; |
| 65 | |
| 66 | @Option(name = "-H", aliases = "--hw", description = "Hardware version") |
| 67 | String hw = "0.1"; |
| 68 | |
| 69 | @Option(name = "-S", aliases = "--sw", description = "Software version") |
| 70 | String sw = "0.1.2"; |
| 71 | |
Thomas Vachuska | 5c6ed22 | 2016-06-29 11:02:22 +0200 | [diff] [blame] | 72 | @Override |
| 73 | protected void execute() { |
| 74 | NullProviders service = get(NullProviders.class); |
| 75 | NetworkConfigService cfgService = get(NetworkConfigService.class); |
| 76 | |
| 77 | TopologySimulator simulator = service.currentSimulator(); |
Thomas Vachuska | b1906d2 | 2018-02-14 16:50:16 -0800 | [diff] [blame] | 78 | if (!validateSimulator(simulator) || !validateLocType(locType)) { |
Simon Hunt | eb3cf54 | 2017-02-10 13:18:41 -0800 | [diff] [blame] | 79 | return; |
| 80 | } |
| 81 | |
Thomas Vachuska | 5c6ed22 | 2016-06-29 11:02:22 +0200 | [diff] [blame] | 82 | CustomTopologySimulator sim = (CustomTopologySimulator) simulator; |
Thomas Vachuska | 7b1fadc | 2018-09-27 11:20:41 -0700 | [diff] [blame] | 83 | DeviceId deviceId = id == null ? sim.nextDeviceId() : DeviceId.deviceId(id); |
Thomas Vachuska | 5c6ed22 | 2016-06-29 11:02:22 +0200 | [diff] [blame] | 84 | BasicDeviceConfig cfg = cfgService.addConfig(deviceId, BasicDeviceConfig.class); |
Thomas Vachuska | b1906d2 | 2018-02-14 16:50:16 -0800 | [diff] [blame] | 85 | cfg.name(name); |
| 86 | setUiCoordinates(cfg, locType, latOrY, longOrX); |
Thomas Vachuska | 5c6ed22 | 2016-06-29 11:02:22 +0200 | [diff] [blame] | 87 | |
Thomas Vachuska | 84b4fcc | 2018-03-22 14:29:06 -0700 | [diff] [blame] | 88 | Tools.delay(10); |
Thomas Vachuska | 7b1fadc | 2018-09-27 11:20:41 -0700 | [diff] [blame] | 89 | sim.createDevice(deviceId, name, Device.Type.valueOf(type.toUpperCase()), |
| 90 | hw, sw, portCount); |
Thomas Vachuska | 5c6ed22 | 2016-06-29 11:02:22 +0200 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | } |