blob: f0bac10b35bc9942c4ebb6e5adfb9664d0f3d7c8 [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;
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020022import org.onosproject.net.ConnectPoint;
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020023import org.onosproject.net.Link;
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020024import org.onosproject.provider.nil.CustomTopologySimulator;
25import org.onosproject.provider.nil.NullProviders;
26import org.onosproject.provider.nil.TopologySimulator;
27
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020028/**
29 * Adds a simulated link to the custom topology simulation.
30 */
31@Command(scope = "onos", name = "null-create-link",
32 description = "Adds a simulated link to the custom topology simulation")
Thomas Vachuskab1906d22018-02-14 16:50:16 -080033public class CreateNullLink extends CreateNullEntity {
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020034
35 @Argument(index = 0, name = "type", description = "Link type, e.g. direct, indirect, optical",
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 = "src", description = "Source device name",
Thomas Vachuskab1906d22018-02-14 16:50:16 -080040 required = true)
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020041 String src = null;
42
43 @Argument(index = 2, name = "dst", description = "Destination device name",
Thomas Vachuskab1906d22018-02-14 16:50:16 -080044 required = true)
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020045 String dst = null;
46
Thomas Vachuskab1906d22018-02-14 16:50:16 -080047 @Option(name = "-u", aliases = "--unidirectional", description = "Unidirectional link only")
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020048 private boolean unidirectional = false;
49
50 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070051 protected void doExecute() {
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020052 NullProviders service = get(NullProviders.class);
53
54 TopologySimulator simulator = service.currentSimulator();
55 if (!(simulator instanceof CustomTopologySimulator)) {
56 error("Custom topology simulator is not active.");
57 return;
58 }
59
60 CustomTopologySimulator sim = (CustomTopologySimulator) simulator;
Thomas Vachuska4407a7e2016-07-02 12:38:01 +020061 ConnectPoint one = findAvailablePort(sim.deviceId(src), null);
62 ConnectPoint two = findAvailablePort(sim.deviceId(dst), one);
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020063 sim.createLink(one, two, Link.Type.valueOf(type.toUpperCase()), !unidirectional);
64 }
65
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020066}