blob: 431bcd36c03ad048a74982f9f5130640b4455b10 [file] [log] [blame]
Thomas Vachuska5c6ed222016-06-29 11:02:22 +02001/*
Brian O'Connor0a4e6742016-09-15 23:03:10 -07002 * Copyright 2016-present Open Networking Laboratory
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;
20import org.onosproject.cli.AbstractShellCommand;
21import org.onosproject.net.Device;
22import org.onosproject.net.DeviceId;
23import org.onosproject.net.config.NetworkConfigService;
24import org.onosproject.net.config.basics.BasicDeviceConfig;
25import org.onosproject.provider.nil.CustomTopologySimulator;
26import org.onosproject.provider.nil.NullProviders;
27import org.onosproject.provider.nil.TopologySimulator;
28
29/**
30 * Adds a simulated device to the custom topology simulation.
31 */
32@Command(scope = "onos", name = "null-create-device",
33 description = "Adds a simulated device to the custom topology simulation")
34public class CreateNullDevice extends AbstractShellCommand {
Simon Hunteb3cf542017-02-10 13:18:41 -080035 private static final String GEO = "geo";
36 private static final String GRID = "grid";
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020037
38 @Argument(index = 0, name = "type", description = "Device type, e.g. switch, roadm",
39 required = true, multiValued = false)
40 String type = null;
41
42 @Argument(index = 1, name = "name", description = "Device name",
43 required = true, multiValued = false)
44 String name = null;
45
46 @Argument(index = 2, name = "portCount", description = "Port count",
47 required = true, multiValued = false)
48 Integer portCount = null;
49
Simon Hunteb3cf542017-02-10 13:18:41 -080050 @Argument(index = 3, name = "latOrY",
51 description = "Geo latitude / Grid y-coord",
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020052 required = true, multiValued = false)
Simon Hunteb3cf542017-02-10 13:18:41 -080053 Double latOrY = null;
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020054
Simon Hunteb3cf542017-02-10 13:18:41 -080055 @Argument(index = 4, name = "longOrX",
56 description = "Geo longitude / Grid x-coord",
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020057 required = true, multiValued = false)
Simon Hunteb3cf542017-02-10 13:18:41 -080058 Double longOrX = null;
59
60 @Argument(index = 5, name = "locType", description = "Location type {geo|grid}",
61 required = false, multiValued = false)
62 String locType = GEO;
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020063
64 @Override
65 protected void execute() {
66 NullProviders service = get(NullProviders.class);
67 NetworkConfigService cfgService = get(NetworkConfigService.class);
68
69 TopologySimulator simulator = service.currentSimulator();
70 if (!(simulator instanceof CustomTopologySimulator)) {
71 error("Custom topology simulator is not active.");
72 return;
73 }
74
Simon Hunteb3cf542017-02-10 13:18:41 -080075 if (!(GEO.equals(locType) || GRID.equals(locType))) {
76 error("locType must be 'geo' or 'grid'.");
77 return;
78 }
79
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020080 CustomTopologySimulator sim = (CustomTopologySimulator) simulator;
81 DeviceId deviceId = sim.nextDeviceId();
82 BasicDeviceConfig cfg = cfgService.addConfig(deviceId, BasicDeviceConfig.class);
Simon Hunt53612212016-12-04 17:19:52 -080083 cfg.name(name)
Simon Hunteb3cf542017-02-10 13:18:41 -080084 .locType(locType);
85
86 if (GEO.equals(locType)) {
87 cfg.latitude(latOrY).longitude(longOrX);
88 } else {
89 cfg.gridX(longOrX).gridY(latOrY);
90 }
91 cfg.apply();
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020092
93 sim.createDevice(deviceId, name, Device.Type.valueOf(type.toUpperCase()), portCount);
94 }
95
96}