blob: 5063e1251bdd2d0ed9cb46209b7978d80d651ac0 [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 */
16
17package org.onosproject.provider.nil.cli;
18
Ray Milkey86ad7bb2018-09-27 12:32:28 -070019import org.apache.karaf.shell.api.action.Argument;
20import org.apache.karaf.shell.api.action.Command;
21import org.apache.karaf.shell.api.action.Option;
Ray Milkey7a2dee52018-09-28 10:58:28 -070022import org.apache.karaf.shell.api.action.lifecycle.Service;
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020023import org.onosproject.net.ConnectPoint;
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020024import org.onosproject.net.Link;
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020025import org.onosproject.provider.nil.CustomTopologySimulator;
26import org.onosproject.provider.nil.NullProviders;
27import org.onosproject.provider.nil.TopologySimulator;
28
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020029/**
30 * Adds a simulated link to the custom topology simulation.
31 */
Ray Milkey7a2dee52018-09-28 10:58:28 -070032@Service
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020033@Command(scope = "onos", name = "null-create-link",
34 description = "Adds a simulated link to the custom topology simulation")
Thomas Vachuskab1906d22018-02-14 16:50:16 -080035public class CreateNullLink extends CreateNullEntity {
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020036
37 @Argument(index = 0, name = "type", description = "Link type, e.g. direct, indirect, optical",
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 = "src", description = "Source device name",
Thomas Vachuskab1906d22018-02-14 16:50:16 -080042 required = true)
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020043 String src = null;
44
45 @Argument(index = 2, name = "dst", description = "Destination device name",
Thomas Vachuskab1906d22018-02-14 16:50:16 -080046 required = true)
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020047 String dst = null;
48
Thomas Vachuskab1906d22018-02-14 16:50:16 -080049 @Option(name = "-u", aliases = "--unidirectional", description = "Unidirectional link only")
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020050 private boolean unidirectional = false;
51
52 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070053 protected void doExecute() {
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020054 NullProviders service = get(NullProviders.class);
55
56 TopologySimulator simulator = service.currentSimulator();
57 if (!(simulator instanceof CustomTopologySimulator)) {
58 error("Custom topology simulator is not active.");
59 return;
60 }
61
62 CustomTopologySimulator sim = (CustomTopologySimulator) simulator;
Thomas Vachuska4407a7e2016-07-02 12:38:01 +020063 ConnectPoint one = findAvailablePort(sim.deviceId(src), null);
64 ConnectPoint two = findAvailablePort(sim.deviceId(dst), one);
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020065 sim.createLink(one, two, Link.Type.valueOf(type.toUpperCase()), !unidirectional);
66 }
67
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020068}