blob: db0e56f490520bdf0afceae5ca48dbfeff701315 [file] [log] [blame]
Brian Stanke5df14472016-03-11 19:34:38 -05001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
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
19import org.apache.karaf.shell.commands.Argument;
20import org.apache.karaf.shell.commands.Command;
21import org.apache.karaf.shell.commands.Option;
22import org.onosproject.cli.AbstractShellCommand;
23import org.onosproject.incubator.net.tunnel.TunnelId;
24import 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 */
33@Command(scope = "onos", name = "vnet-create-link",
34 description = "Creates a new virtual link in a network.")
35public class VirtualLinkCreateCommand extends AbstractShellCommand {
36
37 @Argument(index = 0, name = "networkId", description = "Network ID",
38 required = true, multiValued = false)
39 Long networkId = null;
40
41 @Argument(index = 1, name = "srcDeviceId", description = "Source device ID",
42 required = true, multiValued = false)
43 String srcDeviceId = null;
44
45 @Argument(index = 2, name = "srcPortNum", description = "Source port number",
46 required = true, multiValued = false)
47 Integer srcPortNum = null;
48
49 @Argument(index = 3, name = "dstDeviceId", description = "Destination device ID",
50 required = true, multiValued = false)
51 String dstDeviceId = null;
52
53 @Argument(index = 4, name = "dstPortNum", description = "Destination port number",
54 required = true, multiValued = false)
55 Integer dstPortNum = null;
56
57 @Option(name = "-b", aliases = "--bidirectional",
58 description = "If this argument is passed in then the virtual link created will be bidirectional, " +
59 "otherwise the link will be unidirectional.",
60 required = false, multiValued = false)
61 boolean bidirectional = false;
62
63 @Override
64 protected void execute() {
65 VirtualNetworkAdminService service = get(VirtualNetworkAdminService.class);
66 ConnectPoint src = new ConnectPoint(DeviceId.deviceId(srcDeviceId), PortNumber.portNumber(srcPortNum));
67 ConnectPoint dst = new ConnectPoint(DeviceId.deviceId(dstDeviceId), PortNumber.portNumber(dstPortNum));
68 //TODO use a real/valid tunnel ID
69 TunnelId tunnelId = TunnelId.valueOf(0);
70
71 service.createVirtualLink(NetworkId.networkId(networkId), src, dst, tunnelId);
72 if (bidirectional) {
73 service.createVirtualLink(NetworkId.networkId(networkId), dst, src, tunnelId);
74 }
75 print("Virtual link successfully created.");
76 }
77}