blob: 4d081f8e4a6af2217977f83945e7f105c5fa7652 [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 Vachuska5c6ed222016-06-29 11:02:22 +020020import org.onosproject.net.Device;
21import org.onosproject.net.DeviceId;
22import org.onosproject.net.config.NetworkConfigService;
23import org.onosproject.net.config.basics.BasicDeviceConfig;
24import org.onosproject.provider.nil.CustomTopologySimulator;
25import org.onosproject.provider.nil.NullProviders;
26import org.onosproject.provider.nil.TopologySimulator;
27
28/**
29 * Adds a simulated device to the custom topology simulation.
30 */
31@Command(scope = "onos", name = "null-create-device",
32 description = "Adds a simulated device to the custom topology simulation")
Thomas Vachuskab1906d22018-02-14 16:50:16 -080033public class CreateNullDevice extends CreateNullEntity {
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020034
35 @Argument(index = 0, name = "type", description = "Device type, e.g. switch, roadm",
Thomas Vachuskab1906d22018-02-14 16:50:16 -080036 required = true)
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020037 String type = null;
38
39 @Argument(index = 1, name = "name", description = "Device name",
Thomas Vachuskab1906d22018-02-14 16:50:16 -080040 required = true)
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020041 String name = null;
42
43 @Argument(index = 2, name = "portCount", description = "Port count",
Thomas Vachuskab1906d22018-02-14 16:50:16 -080044 required = true)
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020045 Integer portCount = null;
46
Simon Hunteb3cf542017-02-10 13:18:41 -080047 @Argument(index = 3, name = "latOrY",
48 description = "Geo latitude / Grid y-coord",
Thomas Vachuskab1906d22018-02-14 16:50:16 -080049 required = false)
Simon Hunteb3cf542017-02-10 13:18:41 -080050 Double latOrY = null;
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020051
Simon Hunteb3cf542017-02-10 13:18:41 -080052 @Argument(index = 4, name = "longOrX",
53 description = "Geo longitude / Grid x-coord",
Thomas Vachuskab1906d22018-02-14 16:50:16 -080054 required = false)
Simon Hunteb3cf542017-02-10 13:18:41 -080055 Double longOrX = null;
56
57 @Argument(index = 5, name = "locType", description = "Location type {geo|grid}",
Thomas Vachuskab1906d22018-02-14 16:50:16 -080058 required = false)
Simon Hunteb3cf542017-02-10 13:18:41 -080059 String locType = GEO;
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020060
61 @Override
62 protected void execute() {
63 NullProviders service = get(NullProviders.class);
64 NetworkConfigService cfgService = get(NetworkConfigService.class);
65
66 TopologySimulator simulator = service.currentSimulator();
Thomas Vachuskab1906d22018-02-14 16:50:16 -080067 if (!validateSimulator(simulator) || !validateLocType(locType)) {
Simon Hunteb3cf542017-02-10 13:18:41 -080068 return;
69 }
70
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020071 CustomTopologySimulator sim = (CustomTopologySimulator) simulator;
72 DeviceId deviceId = sim.nextDeviceId();
73 BasicDeviceConfig cfg = cfgService.addConfig(deviceId, BasicDeviceConfig.class);
Thomas Vachuskab1906d22018-02-14 16:50:16 -080074 cfg.name(name);
75 setUiCoordinates(cfg, locType, latOrY, longOrX);
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020076
77 sim.createDevice(deviceId, name, Device.Type.valueOf(type.toUpperCase()), portCount);
78 }
79
80}