Optimize the tunnel commands
1. Split port and equipment by "/" instead of "-"; 2. Fix the bug of remove-tunnel-by-type command. Change-Id: I462e8af54f697d04b8433a59126e1c52c4cbf88c
Showing
3 changed files
with
51 additions
and
17 deletions
... | @@ -90,8 +90,8 @@ public class TunnelCreateCommand extends AbstractShellCommand { | ... | @@ -90,8 +90,8 @@ public class TunnelCreateCommand extends AbstractShellCommand { |
90 | dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dst)); | 90 | dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dst)); |
91 | } else if ("VLAN".equals(type)) { | 91 | } else if ("VLAN".equals(type)) { |
92 | trueType = Tunnel.Type.VLAN; | 92 | trueType = Tunnel.Type.VLAN; |
93 | - String[] srcArray = src.split("-"); | 93 | + String[] srcArray = src.split("/"); |
94 | - String[] dstArray = dst.split("-"); | 94 | + String[] dstArray = dst.split("/"); |
95 | srcPoint = new DefaultOpticalTunnelEndPoint( | 95 | srcPoint = new DefaultOpticalTunnelEndPoint( |
96 | producerName, | 96 | producerName, |
97 | Optional.of(DeviceId | 97 | Optional.of(DeviceId |
... | @@ -124,8 +124,8 @@ public class TunnelCreateCommand extends AbstractShellCommand { | ... | @@ -124,8 +124,8 @@ public class TunnelCreateCommand extends AbstractShellCommand { |
124 | dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dst)); | 124 | dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dst)); |
125 | } else if ("ODUK".equals(type)) { | 125 | } else if ("ODUK".equals(type)) { |
126 | trueType = Tunnel.Type.ODUK; | 126 | trueType = Tunnel.Type.ODUK; |
127 | - String[] srcArray = src.split("-"); | 127 | + String[] srcArray = src.split("/"); |
128 | - String[] dstArray = dst.split("-"); | 128 | + String[] dstArray = dst.split("/"); |
129 | srcPoint = new DefaultOpticalTunnelEndPoint( | 129 | srcPoint = new DefaultOpticalTunnelEndPoint( |
130 | producerName, | 130 | producerName, |
131 | Optional.of(DeviceId | 131 | Optional.of(DeviceId |
... | @@ -150,8 +150,8 @@ public class TunnelCreateCommand extends AbstractShellCommand { | ... | @@ -150,8 +150,8 @@ public class TunnelCreateCommand extends AbstractShellCommand { |
150 | true); | 150 | true); |
151 | } else if ("OCH".equals(type)) { | 151 | } else if ("OCH".equals(type)) { |
152 | trueType = Tunnel.Type.OCH; | 152 | trueType = Tunnel.Type.OCH; |
153 | - String[] srcArray = src.split("-"); | 153 | + String[] srcArray = src.split("/"); |
154 | - String[] dstArray = dst.split("-"); | 154 | + String[] dstArray = dst.split("/"); |
155 | srcPoint = new DefaultOpticalTunnelEndPoint( | 155 | srcPoint = new DefaultOpticalTunnelEndPoint( |
156 | producerName, | 156 | producerName, |
157 | Optional.of(DeviceId | 157 | Optional.of(DeviceId | ... | ... |
... | @@ -87,8 +87,8 @@ public class TunnelQueryCommand extends AbstractShellCommand { | ... | @@ -87,8 +87,8 @@ public class TunnelQueryCommand extends AbstractShellCommand { |
87 | dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress | 87 | dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress |
88 | .valueOf(dst)); | 88 | .valueOf(dst)); |
89 | } else if ("VLAN".equals(type)) { | 89 | } else if ("VLAN".equals(type)) { |
90 | - String[] srcArray = src.split("-"); | 90 | + String[] srcArray = src.split("/"); |
91 | - String[] dstArray = dst.split("-"); | 91 | + String[] dstArray = dst.split("/"); |
92 | srcPoint = new DefaultOpticalTunnelEndPoint( | 92 | srcPoint = new DefaultOpticalTunnelEndPoint( |
93 | producerName, | 93 | producerName, |
94 | Optional.of(DeviceId | 94 | Optional.of(DeviceId |
... | @@ -112,8 +112,8 @@ public class TunnelQueryCommand extends AbstractShellCommand { | ... | @@ -112,8 +112,8 @@ public class TunnelQueryCommand extends AbstractShellCommand { |
112 | .logicId(0), | 112 | .logicId(0), |
113 | true); | 113 | true); |
114 | } else if ("ODUK".equals(type)) { | 114 | } else if ("ODUK".equals(type)) { |
115 | - String[] srcArray = src.split("-"); | 115 | + String[] srcArray = src.split("/"); |
116 | - String[] dstArray = dst.split("-"); | 116 | + String[] dstArray = dst.split("/"); |
117 | srcPoint = new DefaultOpticalTunnelEndPoint( | 117 | srcPoint = new DefaultOpticalTunnelEndPoint( |
118 | producerName, | 118 | producerName, |
119 | Optional.of(DeviceId | 119 | Optional.of(DeviceId |
... | @@ -137,8 +137,8 @@ public class TunnelQueryCommand extends AbstractShellCommand { | ... | @@ -137,8 +137,8 @@ public class TunnelQueryCommand extends AbstractShellCommand { |
137 | .logicId(0), | 137 | .logicId(0), |
138 | true); | 138 | true); |
139 | } else if ("OCH".equals(type)) { | 139 | } else if ("OCH".equals(type)) { |
140 | - String[] srcArray = src.split("-"); | 140 | + String[] srcArray = src.split("/"); |
141 | - String[] dstArray = dst.split("-"); | 141 | + String[] dstArray = dst.split("/"); |
142 | srcPoint = new DefaultOpticalTunnelEndPoint( | 142 | srcPoint = new DefaultOpticalTunnelEndPoint( |
143 | producerName, | 143 | producerName, |
144 | Optional.of(DeviceId | 144 | Optional.of(DeviceId |
... | @@ -194,7 +194,7 @@ public class TunnelQueryCommand extends AbstractShellCommand { | ... | @@ -194,7 +194,7 @@ public class TunnelQueryCommand extends AbstractShellCommand { |
194 | } | 194 | } |
195 | if (tunnelSet != null) { | 195 | if (tunnelSet != null) { |
196 | for (Tunnel tunnel : tunnelSet) { | 196 | for (Tunnel tunnel : tunnelSet) { |
197 | - print(FMT, tunnel.tunnelId(), tunnel.src().toString(), tunnel.dst().toString(), | 197 | + print(FMT, tunnel.tunnelId().id(), tunnel.src().toString(), tunnel.dst().toString(), |
198 | tunnel.type(), tunnel.state(), tunnel.providerId(), | 198 | tunnel.type(), tunnel.state(), tunnel.providerId(), |
199 | tunnel.tunnelName(), tunnel.groupId(), | 199 | tunnel.tunnelName(), tunnel.groupId(), |
200 | showPath(tunnel.path()), | 200 | showPath(tunnel.path()), | ... | ... |
... | @@ -15,6 +15,7 @@ | ... | @@ -15,6 +15,7 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.cli.net; | 16 | package org.onosproject.cli.net; |
17 | 17 | ||
18 | +import java.util.Collection; | ||
18 | import java.util.Optional; | 19 | import java.util.Optional; |
19 | 20 | ||
20 | import org.apache.karaf.shell.commands.Command; | 21 | import org.apache.karaf.shell.commands.Command; |
... | @@ -31,6 +32,7 @@ import org.onosproject.incubator.net.tunnel.TunnelDescription; | ... | @@ -31,6 +32,7 @@ import org.onosproject.incubator.net.tunnel.TunnelDescription; |
31 | import org.onosproject.incubator.net.tunnel.TunnelEndPoint; | 32 | import org.onosproject.incubator.net.tunnel.TunnelEndPoint; |
32 | import org.onosproject.incubator.net.tunnel.TunnelId; | 33 | import org.onosproject.incubator.net.tunnel.TunnelId; |
33 | import org.onosproject.incubator.net.tunnel.TunnelProvider; | 34 | import org.onosproject.incubator.net.tunnel.TunnelProvider; |
35 | +import org.onosproject.incubator.net.tunnel.TunnelService; | ||
34 | import org.onosproject.net.DeviceId; | 36 | import org.onosproject.net.DeviceId; |
35 | import org.onosproject.net.PortNumber; | 37 | import org.onosproject.net.PortNumber; |
36 | import org.onosproject.net.provider.ProviderId; | 38 | import org.onosproject.net.provider.ProviderId; |
... | @@ -95,8 +97,8 @@ public class TunnelRemoveCommand extends AbstractShellCommand { | ... | @@ -95,8 +97,8 @@ public class TunnelRemoveCommand extends AbstractShellCommand { |
95 | .valueOf(dst)); | 97 | .valueOf(dst)); |
96 | } else if ("ODUK".equals(type)) { | 98 | } else if ("ODUK".equals(type)) { |
97 | trueType = Tunnel.Type.ODUK; | 99 | trueType = Tunnel.Type.ODUK; |
98 | - String[] srcArray = src.split("-"); | 100 | + String[] srcArray = src.split("/"); |
99 | - String[] dstArray = dst.split("-"); | 101 | + String[] dstArray = dst.split("/"); |
100 | srcPoint = new DefaultOpticalTunnelEndPoint( | 102 | srcPoint = new DefaultOpticalTunnelEndPoint( |
101 | producerName, | 103 | producerName, |
102 | Optional.of(DeviceId | 104 | Optional.of(DeviceId |
... | @@ -121,8 +123,8 @@ public class TunnelRemoveCommand extends AbstractShellCommand { | ... | @@ -121,8 +123,8 @@ public class TunnelRemoveCommand extends AbstractShellCommand { |
121 | true); | 123 | true); |
122 | } else if ("OCH".equals(type)) { | 124 | } else if ("OCH".equals(type)) { |
123 | trueType = Tunnel.Type.OCH; | 125 | trueType = Tunnel.Type.OCH; |
124 | - String[] srcArray = src.split("-"); | 126 | + String[] srcArray = src.split("/"); |
125 | - String[] dstArray = dst.split("-"); | 127 | + String[] dstArray = dst.split("/"); |
126 | srcPoint = new DefaultOpticalTunnelEndPoint( | 128 | srcPoint = new DefaultOpticalTunnelEndPoint( |
127 | producerName, | 129 | producerName, |
128 | Optional.of(DeviceId | 130 | Optional.of(DeviceId |
... | @@ -154,12 +156,44 @@ public class TunnelRemoveCommand extends AbstractShellCommand { | ... | @@ -154,12 +156,44 @@ public class TunnelRemoveCommand extends AbstractShellCommand { |
154 | trueType, null, producerName, | 156 | trueType, null, producerName, |
155 | null, null); | 157 | null, null); |
156 | service.tunnelRemoved(tunnel); | 158 | service.tunnelRemoved(tunnel); |
159 | + return; | ||
157 | } | 160 | } |
158 | if (!isNull(tunnelId)) { | 161 | if (!isNull(tunnelId)) { |
159 | TunnelId id = TunnelId.valueOf(tunnelId); | 162 | TunnelId id = TunnelId.valueOf(tunnelId); |
160 | tunnel = new DefaultTunnelDescription(id, null, null, null, null, | 163 | tunnel = new DefaultTunnelDescription(id, null, null, null, null, |
161 | producerName, null, null); | 164 | producerName, null, null); |
162 | service.tunnelRemoved(tunnel); | 165 | service.tunnelRemoved(tunnel); |
166 | + return; | ||
167 | + } | ||
168 | + | ||
169 | + if (!isNull(type)) { | ||
170 | + Tunnel.Type trueType = null; | ||
171 | + Collection<Tunnel> tunnelSet = null; | ||
172 | + TunnelService tunnelService = get(TunnelService.class); | ||
173 | + if ("MPLS".equals(type)) { | ||
174 | + trueType = Tunnel.Type.MPLS; | ||
175 | + } else if ("VLAN".equals(type)) { | ||
176 | + trueType = Tunnel.Type.VLAN; | ||
177 | + } else if ("VXLAN".equals(type)) { | ||
178 | + trueType = Tunnel.Type.VXLAN; | ||
179 | + } else if ("GRE".equals(type)) { | ||
180 | + trueType = Tunnel.Type.GRE; | ||
181 | + } else if ("ODUK".equals(type)) { | ||
182 | + trueType = Tunnel.Type.ODUK; | ||
183 | + } else if ("OCH".equals(type)) { | ||
184 | + trueType = Tunnel.Type.OCH; | ||
185 | + } else { | ||
186 | + print("Illegal tunnel type. Please input MPLS, VLAN, VXLAN, GRE, ODUK or OCH."); | ||
187 | + return; | ||
188 | + } | ||
189 | + tunnelSet = tunnelService.queryTunnel(trueType); | ||
190 | + if (tunnelSet != null) { | ||
191 | + for (Tunnel tunnelTemp : tunnelSet) { | ||
192 | + tunnel = new DefaultTunnelDescription(tunnelTemp.tunnelId(), null, null, null, null, | ||
193 | + producerName, null, null); | ||
194 | + service.tunnelRemoved(tunnel); | ||
195 | + } | ||
196 | + } | ||
163 | } | 197 | } |
164 | } | 198 | } |
165 | 199 | ... | ... |
-
Please register or login to post a comment