blob: 9be0da821ab9df81f292b7e2b58df8ee09fe9d84 [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.net.DeviceId;
25import org.onosproject.net.PortNumber;
26import org.onosproject.net.provider.ProviderId;
Thomas Vachuskabf916ea2015-05-20 18:24:34 -070027import org.onosproject.incubator.net.tunnel.DefaultOpticalTunnelEndPoint;
28import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
29import org.onosproject.incubator.net.tunnel.OpticalLogicId;
30import org.onosproject.incubator.net.tunnel.OpticalTunnelEndPoint;
31import org.onosproject.incubator.net.tunnel.TunnelAdminService;
32import org.onosproject.incubator.net.tunnel.TunnelEndPoint;
jccd8697232015-05-05 14:42:23 +080033
34/**
35 * Supports for deleting all tunnels by using IP address and optical as tunnel
36 * end point now. It's used by consumers.
37 */
38@Command(scope = "onos", name = "delete-tunnels", description = "Supports for deleting all tunnels by using IP address"
39 + " and optical as tunnel end point now. It's used by consumers.")
Thomas Vachuskabf916ea2015-05-20 18:24:34 -070040public class TunnelDeleteCommand extends AbstractShellCommand {
jccd8697232015-05-05 14:42:23 +080041 static String applicationId = "DEFAULT_APP_ID";
42 @Argument(index = 0, name = "src", description = "Source tunnel point."
43 + " Only supports for IpTunnelEndPoint and OpticalTunnelEndPoint as end point now."
44 + " If deletess a ODUK or OCH type tunnel, the formatter of this argument is DeviceId-PortNumber."
45 + " Otherwise src means IP address.", required = true, multiValued = false)
46 String src = null;
47 @Argument(index = 1, name = "dst", description = "Destination tunnel point."
48 + " Only supports for IpTunnelEndPoint and OpticalTunnelEndPoint as end point now."
49 + " If deletess a ODUK or OCH type tunnel, the formatter of this argument is DeviceId-PortNumber."
50 + " Otherwise dst means IP address.", required = true, multiValued = false)
51 String dst = null;
52
53 @Argument(index = 2, name = "type", description = "The type of tunnels,"
54 + " It includes MPLS, VLAN, VXLAN, GRE, ODUK, OCH", required = true, multiValued = false)
55 String type = null;
56
57 @Override
58 protected void execute() {
59 TunnelAdminService adminService = get(TunnelAdminService.class);
60 ProviderId producerName = new ProviderId("default",
61 "org.onosproject.provider.tunnel.default");
62 TunnelEndPoint srcPoint = null;
63 TunnelEndPoint dstPoint = null;
64 if ("MPLS".equals(type) || "VLAN".equals(type) || "VXLAN".equals(type) || "GRE".equals(type)) {
65 srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(src));
66 dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dst));
67 } else if ("ODUK".equals(type) || "OCH".equals(type)) {
68 String[] srcArray = src.split("-");
69 String[] dstArray = dst.split("-");
70 srcPoint = new DefaultOpticalTunnelEndPoint(
71 producerName,
72 Optional.of(DeviceId
73 .deviceId(srcArray[0])),
74 Optional.of(PortNumber
75 .portNumber(srcArray[1])),
76 null,
77 OpticalTunnelEndPoint.Type.LAMBDA,
78 OpticalLogicId
79 .logicId(0),
80 true);
81 dstPoint = new DefaultOpticalTunnelEndPoint(
82 producerName,
83 Optional.of(DeviceId
84 .deviceId(dstArray[0])),
85 Optional.of(PortNumber
86 .portNumber(dstArray[1])),
87 null,
88 OpticalTunnelEndPoint.Type.LAMBDA,
89 OpticalLogicId
90 .logicId(0),
91 true);
92 } else {
93 print("Illegal tunnel type. Please input MPLS, VLAN, VXLAN, GRE, ODUK or OCH.");
94 return;
95 }
96
97 adminService.removeTunnels(srcPoint, dstPoint, producerName);
98 }
99
100}