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