blob: df0259d30855b83feb7b213a0c607d54aee7dac4 [file] [log] [blame]
Brian Stanke5df14472016-03-11 19:34:38 -05001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Brian Stanke5df14472016-03-11 19:34:38 -05003 *
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.cli.net.vnet;
18
Ray Milkeyd84f89b2018-08-17 14:54:17 -070019import org.apache.karaf.shell.api.action.Argument;
20import org.apache.karaf.shell.api.action.Command;
Ray Milkey0068fd02018-10-11 15:45:39 -070021import org.apache.karaf.shell.api.action.Completion;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070022import org.apache.karaf.shell.api.action.lifecycle.Service;
23import org.apache.karaf.shell.api.action.Option;
Brian Stanke5df14472016-03-11 19:34:38 -050024import org.onosproject.cli.AbstractShellCommand;
25import org.onosproject.incubator.net.virtual.NetworkId;
26import org.onosproject.incubator.net.virtual.VirtualNetworkAdminService;
27import org.onosproject.net.ConnectPoint;
28import org.onosproject.net.DeviceId;
29import org.onosproject.net.PortNumber;
30
31/**
32 * Removes a virtual link.
33 */
Ray Milkeyd84f89b2018-08-17 14:54:17 -070034@Service
Brian Stanke5df14472016-03-11 19:34:38 -050035@Command(scope = "onos", name = "vnet-remove-link",
36 description = "Removes a virtual link.")
37public class VirtualLinkRemoveCommand extends AbstractShellCommand {
38
39 @Argument(index = 0, name = "networkId", description = "Network ID",
40 required = true, multiValued = false)
Ray Milkey0068fd02018-10-11 15:45:39 -070041 @Completion(VirtualNetworkCompleter.class)
Brian Stanke5df14472016-03-11 19:34:38 -050042 Long networkId = null;
43
44 @Argument(index = 1, name = "srcDeviceId", description = "Source device ID",
45 required = true, multiValued = false)
Ray Milkey0068fd02018-10-11 15:45:39 -070046 @Completion(VirtualDeviceCompleter.class)
Brian Stanke5df14472016-03-11 19:34:38 -050047 String srcDeviceId = null;
48
49 @Argument(index = 2, name = "srcPortNum", description = "Source port number",
50 required = true, multiValued = false)
Ray Milkey0068fd02018-10-11 15:45:39 -070051 @Completion(VirtualPortCompleter.class)
Brian Stanke5df14472016-03-11 19:34:38 -050052 Integer srcPortNum = null;
53
54 @Argument(index = 3, name = "dstDeviceId", description = "Destination device ID",
55 required = true, multiValued = false)
Ray Milkey0068fd02018-10-11 15:45:39 -070056 @Completion(VirtualDeviceCompleter.class)
Brian Stanke5df14472016-03-11 19:34:38 -050057 String dstDeviceId = null;
58
59 @Argument(index = 4, name = "dstPortNum", description = "Destination port number",
60 required = true, multiValued = false)
Ray Milkey0068fd02018-10-11 15:45:39 -070061 @Completion(VirtualPortCompleter.class)
Brian Stanke5df14472016-03-11 19:34:38 -050062 Integer dstPortNum = null;
63
64 @Option(name = "-b", aliases = "--bidirectional",
65 description = "If this argument is passed in then then bidirectional virtual link will be removed, " +
66 "otherwise the unidirectional link will be removed.",
67 required = false, multiValued = false)
68 boolean bidirectional = false;
69
70 @Override
Ray Milkeyd84f89b2018-08-17 14:54:17 -070071 protected void doExecute() {
Brian Stanke5df14472016-03-11 19:34:38 -050072 VirtualNetworkAdminService service = get(VirtualNetworkAdminService.class);
73 ConnectPoint src = new ConnectPoint(DeviceId.deviceId(srcDeviceId), PortNumber.portNumber(srcPortNum));
74 ConnectPoint dst = new ConnectPoint(DeviceId.deviceId(dstDeviceId), PortNumber.portNumber(dstPortNum));
75
76 service.removeVirtualLink(NetworkId.networkId(networkId), src, dst);
77 if (bidirectional) {
78 service.removeVirtualLink(NetworkId.networkId(networkId), dst, src);
79 }
80 print("Virtual link successfully removed.");
81 }
82}