blob: 752ef51933a8ebfabab44312baaa2a4c64d2ed45 [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
Ray Milkey86ad7bb2018-09-27 12:32:28 -070018import org.apache.karaf.shell.api.action.Argument;
19import org.apache.karaf.shell.api.action.Command;
Ray Milkey0b18b722018-10-16 13:19:15 -070020import org.apache.karaf.shell.api.action.Option;
Ray Milkey7a2dee52018-09-28 10:58:28 -070021import org.apache.karaf.shell.api.action.lifecycle.Service;
Ray Milkey0b18b722018-10-16 13:19:15 -070022
Thomas Vachuska84b4fcc2018-03-22 14:29:06 -070023import org.onlab.util.Tools;
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020024import org.onosproject.net.Device;
25import org.onosproject.net.DeviceId;
26import org.onosproject.net.config.NetworkConfigService;
27import org.onosproject.net.config.basics.BasicDeviceConfig;
28import org.onosproject.provider.nil.CustomTopologySimulator;
29import org.onosproject.provider.nil.NullProviders;
30import org.onosproject.provider.nil.TopologySimulator;
31
32/**
33 * Adds a simulated device to the custom topology simulation.
34 */
Ray Milkey7a2dee52018-09-28 10:58:28 -070035@Service
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020036@Command(scope = "onos", name = "null-create-device",
37 description = "Adds a simulated device to the custom topology simulation")
Thomas Vachuskab1906d22018-02-14 16:50:16 -080038public class CreateNullDevice extends CreateNullEntity {
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020039
40 @Argument(index = 0, name = "type", description = "Device type, e.g. switch, roadm",
Thomas Vachuskab1906d22018-02-14 16:50:16 -080041 required = true)
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020042 String type = null;
43
44 @Argument(index = 1, name = "name", description = "Device name",
Thomas Vachuskab1906d22018-02-14 16:50:16 -080045 required = true)
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020046 String name = null;
47
48 @Argument(index = 2, name = "portCount", description = "Port count",
Thomas Vachuskab1906d22018-02-14 16:50:16 -080049 required = true)
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020050 Integer portCount = null;
51
Simon Hunteb3cf542017-02-10 13:18:41 -080052 @Argument(index = 3, name = "latOrY",
53 description = "Geo latitude / Grid y-coord",
Thomas Vachuskab1906d22018-02-14 16:50:16 -080054 required = false)
Simon Hunteb3cf542017-02-10 13:18:41 -080055 Double latOrY = null;
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020056
Simon Hunteb3cf542017-02-10 13:18:41 -080057 @Argument(index = 4, name = "longOrX",
58 description = "Geo longitude / Grid x-coord",
Thomas Vachuskab1906d22018-02-14 16:50:16 -080059 required = false)
Simon Hunteb3cf542017-02-10 13:18:41 -080060 Double longOrX = null;
61
62 @Argument(index = 5, name = "locType", description = "Location type {geo|grid}",
Thomas Vachuskab1906d22018-02-14 16:50:16 -080063 required = false)
Simon Hunteb3cf542017-02-10 13:18:41 -080064 String locType = GEO;
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020065
Thomas Vachuska7b1fadc2018-09-27 11:20:41 -070066 @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 Vachuska5c6ed222016-06-29 11:02:22 +020075 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070076 protected void doExecute() {
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020077 NullProviders service = get(NullProviders.class);
78 NetworkConfigService cfgService = get(NetworkConfigService.class);
79
80 TopologySimulator simulator = service.currentSimulator();
Thomas Vachuskab1906d22018-02-14 16:50:16 -080081 if (!validateSimulator(simulator) || !validateLocType(locType)) {
Simon Hunteb3cf542017-02-10 13:18:41 -080082 return;
83 }
84
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020085 CustomTopologySimulator sim = (CustomTopologySimulator) simulator;
Thomas Vachuska7b1fadc2018-09-27 11:20:41 -070086 DeviceId deviceId = id == null ? sim.nextDeviceId() : DeviceId.deviceId(id);
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020087 BasicDeviceConfig cfg = cfgService.addConfig(deviceId, BasicDeviceConfig.class);
Thomas Vachuskab1906d22018-02-14 16:50:16 -080088 cfg.name(name);
89 setUiCoordinates(cfg, locType, latOrY, longOrX);
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020090
Thomas Vachuska84b4fcc2018-03-22 14:29:06 -070091 Tools.delay(10);
Thomas Vachuska7b1fadc2018-09-27 11:20:41 -070092 sim.createDevice(deviceId, name, Device.Type.valueOf(type.toUpperCase()),
93 hw, sw, portCount);
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020094 }
95
96}