cheng fan

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
......@@ -90,8 +90,8 @@ public class TunnelCreateCommand extends AbstractShellCommand {
dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dst));
} else if ("VLAN".equals(type)) {
trueType = Tunnel.Type.VLAN;
String[] srcArray = src.split("-");
String[] dstArray = dst.split("-");
String[] srcArray = src.split("/");
String[] dstArray = dst.split("/");
srcPoint = new DefaultOpticalTunnelEndPoint(
producerName,
Optional.of(DeviceId
......@@ -124,8 +124,8 @@ public class TunnelCreateCommand extends AbstractShellCommand {
dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dst));
} else if ("ODUK".equals(type)) {
trueType = Tunnel.Type.ODUK;
String[] srcArray = src.split("-");
String[] dstArray = dst.split("-");
String[] srcArray = src.split("/");
String[] dstArray = dst.split("/");
srcPoint = new DefaultOpticalTunnelEndPoint(
producerName,
Optional.of(DeviceId
......@@ -150,8 +150,8 @@ public class TunnelCreateCommand extends AbstractShellCommand {
true);
} else if ("OCH".equals(type)) {
trueType = Tunnel.Type.OCH;
String[] srcArray = src.split("-");
String[] dstArray = dst.split("-");
String[] srcArray = src.split("/");
String[] dstArray = dst.split("/");
srcPoint = new DefaultOpticalTunnelEndPoint(
producerName,
Optional.of(DeviceId
......
......@@ -87,8 +87,8 @@ public class TunnelQueryCommand extends AbstractShellCommand {
dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress
.valueOf(dst));
} else if ("VLAN".equals(type)) {
String[] srcArray = src.split("-");
String[] dstArray = dst.split("-");
String[] srcArray = src.split("/");
String[] dstArray = dst.split("/");
srcPoint = new DefaultOpticalTunnelEndPoint(
producerName,
Optional.of(DeviceId
......@@ -112,8 +112,8 @@ public class TunnelQueryCommand extends AbstractShellCommand {
.logicId(0),
true);
} else if ("ODUK".equals(type)) {
String[] srcArray = src.split("-");
String[] dstArray = dst.split("-");
String[] srcArray = src.split("/");
String[] dstArray = dst.split("/");
srcPoint = new DefaultOpticalTunnelEndPoint(
producerName,
Optional.of(DeviceId
......@@ -137,8 +137,8 @@ public class TunnelQueryCommand extends AbstractShellCommand {
.logicId(0),
true);
} else if ("OCH".equals(type)) {
String[] srcArray = src.split("-");
String[] dstArray = dst.split("-");
String[] srcArray = src.split("/");
String[] dstArray = dst.split("/");
srcPoint = new DefaultOpticalTunnelEndPoint(
producerName,
Optional.of(DeviceId
......@@ -194,7 +194,7 @@ public class TunnelQueryCommand extends AbstractShellCommand {
}
if (tunnelSet != null) {
for (Tunnel tunnel : tunnelSet) {
print(FMT, tunnel.tunnelId(), tunnel.src().toString(), tunnel.dst().toString(),
print(FMT, tunnel.tunnelId().id(), tunnel.src().toString(), tunnel.dst().toString(),
tunnel.type(), tunnel.state(), tunnel.providerId(),
tunnel.tunnelName(), tunnel.groupId(),
showPath(tunnel.path()),
......
......@@ -15,6 +15,7 @@
*/
package org.onosproject.cli.net;
import java.util.Collection;
import java.util.Optional;
import org.apache.karaf.shell.commands.Command;
......@@ -31,6 +32,7 @@ import org.onosproject.incubator.net.tunnel.TunnelDescription;
import org.onosproject.incubator.net.tunnel.TunnelEndPoint;
import org.onosproject.incubator.net.tunnel.TunnelId;
import org.onosproject.incubator.net.tunnel.TunnelProvider;
import org.onosproject.incubator.net.tunnel.TunnelService;
import org.onosproject.net.DeviceId;
import org.onosproject.net.PortNumber;
import org.onosproject.net.provider.ProviderId;
......@@ -95,8 +97,8 @@ public class TunnelRemoveCommand extends AbstractShellCommand {
.valueOf(dst));
} else if ("ODUK".equals(type)) {
trueType = Tunnel.Type.ODUK;
String[] srcArray = src.split("-");
String[] dstArray = dst.split("-");
String[] srcArray = src.split("/");
String[] dstArray = dst.split("/");
srcPoint = new DefaultOpticalTunnelEndPoint(
producerName,
Optional.of(DeviceId
......@@ -121,8 +123,8 @@ public class TunnelRemoveCommand extends AbstractShellCommand {
true);
} else if ("OCH".equals(type)) {
trueType = Tunnel.Type.OCH;
String[] srcArray = src.split("-");
String[] dstArray = dst.split("-");
String[] srcArray = src.split("/");
String[] dstArray = dst.split("/");
srcPoint = new DefaultOpticalTunnelEndPoint(
producerName,
Optional.of(DeviceId
......@@ -154,12 +156,44 @@ public class TunnelRemoveCommand extends AbstractShellCommand {
trueType, null, producerName,
null, null);
service.tunnelRemoved(tunnel);
return;
}
if (!isNull(tunnelId)) {
TunnelId id = TunnelId.valueOf(tunnelId);
tunnel = new DefaultTunnelDescription(id, null, null, null, null,
producerName, null, null);
service.tunnelRemoved(tunnel);
return;
}
if (!isNull(type)) {
Tunnel.Type trueType = null;
Collection<Tunnel> tunnelSet = null;
TunnelService tunnelService = get(TunnelService.class);
if ("MPLS".equals(type)) {
trueType = Tunnel.Type.MPLS;
} else if ("VLAN".equals(type)) {
trueType = Tunnel.Type.VLAN;
} else if ("VXLAN".equals(type)) {
trueType = Tunnel.Type.VXLAN;
} else if ("GRE".equals(type)) {
trueType = Tunnel.Type.GRE;
} else if ("ODUK".equals(type)) {
trueType = Tunnel.Type.ODUK;
} else if ("OCH".equals(type)) {
trueType = Tunnel.Type.OCH;
} else {
print("Illegal tunnel type. Please input MPLS, VLAN, VXLAN, GRE, ODUK or OCH.");
return;
}
tunnelSet = tunnelService.queryTunnel(trueType);
if (tunnelSet != null) {
for (Tunnel tunnelTemp : tunnelSet) {
tunnel = new DefaultTunnelDescription(tunnelTemp.tunnelId(), null, null, null, null,
producerName, null, null);
service.tunnelRemoved(tunnel);
}
}
}
}
......