blob: 86b12f0be11bd39c1d0cc3926f9492533307004e [file] [log] [blame]
Thomas Vachuska5c6ed222016-06-29 11:02:22 +02001/*
2 * Copyright 2016 Open Networking Laboratory
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 */
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 {
35
36 @Argument(index = 0, name = "type", description = "Device type, e.g. switch, roadm",
37 required = true, multiValued = false)
38 String type = null;
39
40 @Argument(index = 1, name = "name", description = "Device name",
41 required = true, multiValued = false)
42 String name = null;
43
44 @Argument(index = 2, name = "portCount", description = "Port count",
45 required = true, multiValued = false)
46 Integer portCount = null;
47
48 @Argument(index = 3, name = "latitude", description = "Geo latitude",
49 required = true, multiValued = false)
50 Double latitude = null;
51
52 @Argument(index = 4, name = "longitude", description = "Geo longitude",
53 required = true, multiValued = false)
54 Double longitude = null;
55
56 @Override
57 protected void execute() {
58 NullProviders service = get(NullProviders.class);
59 NetworkConfigService cfgService = get(NetworkConfigService.class);
60
61 TopologySimulator simulator = service.currentSimulator();
62 if (!(simulator instanceof CustomTopologySimulator)) {
63 error("Custom topology simulator is not active.");
64 return;
65 }
66
67 CustomTopologySimulator sim = (CustomTopologySimulator) simulator;
68 DeviceId deviceId = sim.nextDeviceId();
69 BasicDeviceConfig cfg = cfgService.addConfig(deviceId, BasicDeviceConfig.class);
70 cfg.name(name);
71 cfg.latitude(latitude);
72 cfg.longitude(longitude);
73 cfg.apply();
74
75 sim.createDevice(deviceId, name, Device.Type.valueOf(type.toUpperCase()), portCount);
76 }
77
78}