blob: b4be6ac3e87ce7a6b00ad3058b12898fed7e32d6 [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.provider.tunnel.cli;
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;
27import org.onosproject.net.tunnel.DefaultOpticalTunnelEndPoint;
28import org.onosproject.net.tunnel.DefaultTunnelDescription;
29import org.onosproject.net.tunnel.IpTunnelEndPoint;
30import org.onosproject.net.tunnel.OpticalLogicId;
31import org.onosproject.net.tunnel.OpticalTunnelEndPoint;
32import org.onosproject.net.tunnel.Tunnel;
33import org.onosproject.net.tunnel.TunnelDescription;
34import org.onosproject.net.tunnel.TunnelEndPoint;
35import org.onosproject.net.tunnel.TunnelProvider;
36
37/**
38 * Supports for removing all tunnels by using IP address and optical as tunnel
39 * end point now. It's used by producers.
40 */
41@Command(scope = "onos", name = "remove-tunnels", description = "Supports for removing all tunnels by using IP address"
42 + " and optical as tunnel end point now. It's used by producers.")
43public class RemoveTunnelCommand extends AbstractShellCommand {
44 @Argument(index = 0, name = "src", description = "Source tunnel point."
45 + " Only supports for IpTunnelEndPoint and OpticalTunnelEndPoint as end point now."
46 + " If deletess a ODUK or OCH type tunnel, the formatter of this argument is DeviceId-PortNumber."
47 + " Otherwise src means IP address.", required = true, multiValued = false)
48 String src = null;
49 @Argument(index = 1, name = "dst", description = "Destination 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 dst means IP address.", required = true, multiValued = false)
53 String dst = null;
54
55 @Argument(index = 2, name = "type", description = "The type of tunnels,"
56 + " It includes MPLS, VLAN, VXLAN, GRE, ODUK, OCH", required = true, multiValued = false)
57 String type = null;
58
59 @Override
60 protected void execute() {
61 TunnelProvider service = get(TunnelProvider.class);
62 ProviderId producerName = new ProviderId("default",
63 "org.onosproject.provider.tunnel.default");
64 TunnelEndPoint srcPoint = null;
65 TunnelEndPoint dstPoint = null;
66 Tunnel.Type trueType = null;
67 if ("MPLS".equals(type)) {
68 trueType = Tunnel.Type.MPLS;
69 srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(src));
70 dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dst));
71 } else if ("VLAN".equals(type)) {
72 trueType = Tunnel.Type.VLAN;
73 srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(src));
74 dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dst));
75 } else if ("VXLAN".equals(type)) {
76 trueType = Tunnel.Type.VXLAN;
77 srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(src));
78 dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dst));
79 } else if ("GRE".equals(type)) {
80 trueType = Tunnel.Type.GRE;
81 srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(src));
82 dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dst));
83 } else if ("ODUK".equals(type)) {
84 trueType = Tunnel.Type.ODUK;
85 String[] srcArray = src.split("-");
86 String[] dstArray = dst.split("-");
87 srcPoint = new DefaultOpticalTunnelEndPoint(
88 producerName,
89 Optional.of(DeviceId
90 .deviceId(srcArray[0])),
91 Optional.of(PortNumber
92 .portNumber(srcArray[1])),
93 null,
94 OpticalTunnelEndPoint.Type.LAMBDA,
95 OpticalLogicId
96 .logicId(0),
97 true);
98 dstPoint = new DefaultOpticalTunnelEndPoint(
99 producerName,
100 Optional.of(DeviceId
101 .deviceId(dstArray[0])),
102 Optional.of(PortNumber
103 .portNumber(dstArray[1])),
104 null,
105 OpticalTunnelEndPoint.Type.LAMBDA,
106 OpticalLogicId
107 .logicId(0),
108 true);
109 } else if ("OCH".equals(type)) {
110 trueType = Tunnel.Type.OCH;
111 String[] srcArray = src.split("-");
112 String[] dstArray = dst.split("-");
113 srcPoint = new DefaultOpticalTunnelEndPoint(
114 producerName,
115 Optional.of(DeviceId
116 .deviceId(srcArray[0])),
117 Optional.of(PortNumber
118 .portNumber(srcArray[1])),
119 null,
120 OpticalTunnelEndPoint.Type.LAMBDA,
121 OpticalLogicId
122 .logicId(0),
123 true);
124 dstPoint = new DefaultOpticalTunnelEndPoint(
125 producerName,
126 Optional.of(DeviceId
127 .deviceId(dstArray[0])),
128 Optional.of(PortNumber
129 .portNumber(dstArray[1])),
130 null,
131 OpticalTunnelEndPoint.Type.LAMBDA,
132 OpticalLogicId
133 .logicId(0),
134 true);
135 } else {
136 print("Illegal tunnel type. Please input MPLS, VLAN, VXLAN, GRE, ODUK or OCH.");
137 return;
138 }
139 TunnelDescription tunnel = new DefaultTunnelDescription(null, srcPoint,
140 dstPoint,
141 trueType, null,
142 producerName,
143 null);
144 service.tunnelRemoved(tunnel);
145 }
146
147}