blob: 3de8f00f2b4b6fbb29289ff3d04bb24c8db52c3b [file] [log] [blame]
jccd8697232015-05-05 14:42:23 +08001/*
2 * Copyright 2014-2015 Open Networking Laboratory
3 *
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 */
16package org.onosproject.cli.net;
17
18import java.util.Optional;
19
20import org.apache.karaf.shell.commands.Argument;
21import org.apache.karaf.shell.commands.Command;
22import org.onlab.packet.IpAddress;
23import org.onosproject.cli.AbstractShellCommand;
24import org.onosproject.core.ApplicationId;
25import org.onosproject.core.DefaultApplicationId;
26import org.onosproject.net.DeviceId;
27import org.onosproject.net.PortNumber;
28import org.onosproject.net.provider.ProviderId;
Thomas Vachuskabf916ea2015-05-20 18:24:34 -070029import org.onosproject.incubator.net.tunnel.DefaultOpticalTunnelEndPoint;
30import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
31import org.onosproject.incubator.net.tunnel.OpticalLogicId;
32import org.onosproject.incubator.net.tunnel.OpticalTunnelEndPoint;
33import org.onosproject.incubator.net.tunnel.TunnelEndPoint;
34import org.onosproject.incubator.net.tunnel.TunnelService;
jccd8697232015-05-05 14:42:23 +080035
36/**
37 * Returns all tunnels between specific source tunnel end point and specific
38 * destination tunnel end point. Supports for IP address and optical as tunnel
39 * end point now. It's used by consumers.
40 */
41@Command(scope = "onos", name = "return-tunnels",
42description = "Returns all tunnels between specific source tunnel end point and specific "
43 + " destination tunnel end point. Supports for IP address and optical as tunnel end point now."
44 + " It's used by consumers.")
Thomas Vachuskabf916ea2015-05-20 18:24:34 -070045public class TunnelReturnCommand extends AbstractShellCommand {
jccd8697232015-05-05 14:42:23 +080046 @Argument(index = 0, name = "consumerId", description = "consumer id means application id.",
47 required = true, multiValued = false)
48 String consumerId = null;
49 @Argument(index = 1, name = "src", description = "Source tunnel point."
50 + " Only supports for IpTunnelEndPoint and OpticalTunnelEndPoint as end point now."
51 + " If deletess a ODUK or OCH type tunnel, the formatter of this argument is DeviceId-PortNumber."
52 + " Otherwise src means IP address.", required = true, multiValued = false)
53 String src = null;
54 @Argument(index = 2, name = "dst", description = "Destination tunnel point."
55 + " Only supports for IpTunnelEndPoint and OpticalTunnelEndPoint as end point now."
56 + " If deletess a ODUK or OCH type tunnel, the formatter of this argument is DeviceId-PortNumber."
57 + " Otherwise dst means IP address.", required = true, multiValued = false)
58 String dst = null;
59
60 @Argument(index = 3, name = "type", description = "The type of tunnels,"
61 + " It includes MPLS, VLAN, VXLAN, GRE, ODUK, OCH", required = true, multiValued = false)
62 String type = null;
63
64 @Override
65 protected void execute() {
66 TunnelService service = get(TunnelService.class);
67 ApplicationId appId = new DefaultApplicationId(1, consumerId);
68 ProviderId producerName = new ProviderId("default",
69 "org.onosproject.provider.tunnel.default");
70 TunnelEndPoint srcPoint = null;
71 TunnelEndPoint dstPoint = null;
72 if ("MPLS".equals(type) || "VLAN".equals(type) || "VXLAN".equals(type)
73 || "GRE".equals(type)) {
74 srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(src));
75 dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dst));
76 } else if ("ODUK".equals(type) || "OCH".equals(type)) {
77 String[] srcArray = src.split("-");
78 String[] dstArray = dst.split("-");
79 srcPoint = new DefaultOpticalTunnelEndPoint(
80 producerName,
81 Optional.of(DeviceId
82 .deviceId(srcArray[0])),
83 Optional.of(PortNumber
84 .portNumber(srcArray[1])),
85 null,
86 OpticalTunnelEndPoint.Type.LAMBDA,
87 OpticalLogicId
88 .logicId(0),
89 true);
90 dstPoint = new DefaultOpticalTunnelEndPoint(
91 producerName,
92 Optional.of(DeviceId
93 .deviceId(dstArray[0])),
94 Optional.of(PortNumber
95 .portNumber(dstArray[1])),
96 null,
97 OpticalTunnelEndPoint.Type.LAMBDA,
98 OpticalLogicId
99 .logicId(0),
100 true);
101 } else {
102 print("Illegal tunnel type. Please input MPLS, VLAN, VXLAN, GRE, ODUK or OCH.");
103 return;
104 }
105 service.returnTunnel(appId, srcPoint, dstPoint);
106 }
107
108}