blob: acb9d22294306954f0dfbed79dba07ecb6d82bbc [file] [log] [blame]
Thomas Vachuska5c6ed222016-06-29 11:02:22 +02001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Thomas Vachuska5c6ed222016-06-29 11:02:22 +02003 *
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
18import org.apache.karaf.shell.commands.Argument;
19import org.apache.karaf.shell.commands.Command;
Thomas Vachuska7b1fadc2018-09-27 11:20:41 -070020import org.apache.karaf.shell.commands.Option;
Thomas Vachuska84b4fcc2018-03-22 14:29:06 -070021import org.onlab.util.Tools;
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020022import org.onosproject.net.Device;
23import org.onosproject.net.DeviceId;
24import org.onosproject.net.config.NetworkConfigService;
25import org.onosproject.net.config.basics.BasicDeviceConfig;
26import org.onosproject.provider.nil.CustomTopologySimulator;
27import org.onosproject.provider.nil.NullProviders;
28import 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 Vachuskab1906d22018-02-14 16:50:16 -080035public class CreateNullDevice extends CreateNullEntity {
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020036
37 @Argument(index = 0, name = "type", description = "Device type, e.g. switch, roadm",
Thomas Vachuskab1906d22018-02-14 16:50:16 -080038 required = true)
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020039 String type = null;
40
41 @Argument(index = 1, name = "name", description = "Device name",
Thomas Vachuskab1906d22018-02-14 16:50:16 -080042 required = true)
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020043 String name = null;
44
45 @Argument(index = 2, name = "portCount", description = "Port count",
Thomas Vachuskab1906d22018-02-14 16:50:16 -080046 required = true)
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020047 Integer portCount = null;
48
Simon Hunteb3cf542017-02-10 13:18:41 -080049 @Argument(index = 3, name = "latOrY",
50 description = "Geo latitude / Grid y-coord",
Thomas Vachuskab1906d22018-02-14 16:50:16 -080051 required = false)
Simon Hunteb3cf542017-02-10 13:18:41 -080052 Double latOrY = null;
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020053
Simon Hunteb3cf542017-02-10 13:18:41 -080054 @Argument(index = 4, name = "longOrX",
55 description = "Geo longitude / Grid x-coord",
Thomas Vachuskab1906d22018-02-14 16:50:16 -080056 required = false)
Simon Hunteb3cf542017-02-10 13:18:41 -080057 Double longOrX = null;
58
59 @Argument(index = 5, name = "locType", description = "Location type {geo|grid}",
Thomas Vachuskab1906d22018-02-14 16:50:16 -080060 required = false)
Simon Hunteb3cf542017-02-10 13:18:41 -080061 String locType = GEO;
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020062
Thomas Vachuska7b1fadc2018-09-27 11:20:41 -070063 @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 Vachuska5c6ed222016-06-29 11:02:22 +020072 @Override
73 protected void execute() {
74 NullProviders service = get(NullProviders.class);
75 NetworkConfigService cfgService = get(NetworkConfigService.class);
76
77 TopologySimulator simulator = service.currentSimulator();
Thomas Vachuskab1906d22018-02-14 16:50:16 -080078 if (!validateSimulator(simulator) || !validateLocType(locType)) {
Simon Hunteb3cf542017-02-10 13:18:41 -080079 return;
80 }
81
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020082 CustomTopologySimulator sim = (CustomTopologySimulator) simulator;
Thomas Vachuska7b1fadc2018-09-27 11:20:41 -070083 DeviceId deviceId = id == null ? sim.nextDeviceId() : DeviceId.deviceId(id);
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020084 BasicDeviceConfig cfg = cfgService.addConfig(deviceId, BasicDeviceConfig.class);
Thomas Vachuskab1906d22018-02-14 16:50:16 -080085 cfg.name(name);
86 setUiCoordinates(cfg, locType, latOrY, longOrX);
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020087
Thomas Vachuska84b4fcc2018-03-22 14:29:06 -070088 Tools.delay(10);
Thomas Vachuska7b1fadc2018-09-27 11:20:41 -070089 sim.createDevice(deviceId, name, Device.Type.valueOf(type.toUpperCase()),
90 hw, sw, portCount);
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020091 }
92
93}