blob: 89057ad3b53dec1bf9aa816574b05b01ea2baa32 [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;
21import org.apache.karaf.shell.api.action.lifecycle.Service;
22import org.apache.karaf.shell.api.action.Option;
Brian Stanke5df14472016-03-11 19:34:38 -050023import org.onosproject.cli.AbstractShellCommand;
Brian Stanke5df14472016-03-11 19:34:38 -050024import org.onosproject.incubator.net.virtual.NetworkId;
25import org.onosproject.incubator.net.virtual.VirtualNetworkAdminService;
26import org.onosproject.net.ConnectPoint;
27import org.onosproject.net.DeviceId;
28import org.onosproject.net.PortNumber;
29
30/**
31 * Creates a new virtual link.
32 */
Ray Milkeyd84f89b2018-08-17 14:54:17 -070033@Service
Brian Stanke5df14472016-03-11 19:34:38 -050034@Command(scope = "onos", name = "vnet-create-link",
35 description = "Creates a new virtual link in a network.")
36public class VirtualLinkCreateCommand extends AbstractShellCommand {
37
38 @Argument(index = 0, name = "networkId", description = "Network ID",
39 required = true, multiValued = false)
40 Long networkId = null;
41
42 @Argument(index = 1, name = "srcDeviceId", description = "Source device ID",
43 required = true, multiValued = false)
44 String srcDeviceId = null;
45
46 @Argument(index = 2, name = "srcPortNum", description = "Source port number",
47 required = true, multiValued = false)
48 Integer srcPortNum = null;
49
50 @Argument(index = 3, name = "dstDeviceId", description = "Destination device ID",
51 required = true, multiValued = false)
52 String dstDeviceId = null;
53
54 @Argument(index = 4, name = "dstPortNum", description = "Destination port number",
55 required = true, multiValued = false)
56 Integer dstPortNum = null;
57
58 @Option(name = "-b", aliases = "--bidirectional",
59 description = "If this argument is passed in then the virtual link created will be bidirectional, " +
60 "otherwise the link will be unidirectional.",
61 required = false, multiValued = false)
62 boolean bidirectional = false;
63
64 @Override
Ray Milkeyd84f89b2018-08-17 14:54:17 -070065 protected void doExecute() {
Brian Stanke5df14472016-03-11 19:34:38 -050066 VirtualNetworkAdminService service = get(VirtualNetworkAdminService.class);
67 ConnectPoint src = new ConnectPoint(DeviceId.deviceId(srcDeviceId), PortNumber.portNumber(srcPortNum));
68 ConnectPoint dst = new ConnectPoint(DeviceId.deviceId(dstDeviceId), PortNumber.portNumber(dstPortNum));
Brian Stanke5df14472016-03-11 19:34:38 -050069
Brian Stanke9a108972016-04-11 15:25:17 -040070 service.createVirtualLink(NetworkId.networkId(networkId), src, dst);
Brian Stanke5df14472016-03-11 19:34:38 -050071 if (bidirectional) {
Brian Stanke9a108972016-04-11 15:25:17 -040072 service.createVirtualLink(NetworkId.networkId(networkId), dst, src);
Brian Stanke5df14472016-03-11 19:34:38 -050073 }
74 print("Virtual link successfully created.");
75 }
76}