- Adds error handling for Segment routing CLI
- Removes SegmentRoutingManager reference from TunnelHandler and PolicyHandler
Change-Id: Iab6acdc489d41a63ebf6b37b65d0e82448a8b25a
diff --git a/src/main/java/org/onosproject/segmentrouting/cli/PolicyAddCommand.java b/src/main/java/org/onosproject/segmentrouting/cli/PolicyAddCommand.java
index 2931307..b00633c 100644
--- a/src/main/java/org/onosproject/segmentrouting/cli/PolicyAddCommand.java
+++ b/src/main/java/org/onosproject/segmentrouting/cli/PolicyAddCommand.java
@@ -19,6 +19,7 @@
import org.apache.karaf.shell.commands.Command;
import org.onosproject.cli.AbstractShellCommand;
import org.onosproject.segmentrouting.Policy;
+import org.onosproject.segmentrouting.PolicyHandler;
import org.onosproject.segmentrouting.SegmentRoutingService;
import org.onosproject.segmentrouting.TunnelPolicy;
@@ -31,7 +32,7 @@
// TODO: Need to support skipping some parameters
- @Argument(index = 0, name = "policy ID",
+ @Argument(index = 0, name = "ID",
description = "policy ID",
required = true, multiValued = false)
String policyId;
@@ -41,37 +42,37 @@
required = true, multiValued = false)
int priority;
- @Argument(index = 2, name = "src IP",
+ @Argument(index = 2, name = "src_IP",
description = "src IP",
required = false, multiValued = false)
String srcIp;
- @Argument(index = 3, name = "src port",
+ @Argument(index = 3, name = "src_port",
description = "src port",
required = false, multiValued = false)
short srcPort;
- @Argument(index = 4, name = "dst IP",
+ @Argument(index = 4, name = "dst_IP",
description = "dst IP",
required = false, multiValued = false)
String dstIp;
- @Argument(index = 5, name = "dst port",
+ @Argument(index = 5, name = "dst_port",
description = "dst port",
required = false, multiValued = false)
short dstPort;
@Argument(index = 6, name = "proto",
- description = "proto",
+ description = "IP protocol",
required = false, multiValued = false)
String proto;
- @Argument(index = 7, name = "policy type",
+ @Argument(index = 7, name = "policy_type",
description = "policy type",
required = true, multiValued = false)
String policyType;
- @Argument(index = 8, name = "tunnel ID",
+ @Argument(index = 8, name = "tunnel_ID",
description = "tunnel ID",
required = false, multiValued = false)
String tunnelId;
@@ -103,11 +104,29 @@
}
if (Policy.Type.valueOf(policyType) == Policy.Type.TUNNEL_FLOW) {
if (tunnelId == null) {
- // TODO: handle errors
+ error("tunnel ID must be specified for TUNNEL_FLOW policy");
return;
}
tpb.setTunnelId(tunnelId);
}
- srService.createPolicy(tpb.build());
+ PolicyHandler.Result result = srService.createPolicy(tpb.build());
+
+ switch (result) {
+ case POLICY_EXISTS:
+ error("the same policy exists");
+ break;
+ case ID_EXISTS:
+ error("the same policy ID exists");
+ break;
+ case TUNNEL_NOT_FOUND:
+ error("the tunnel is not found");
+ break;
+ case UNSUPPORTED_TYPE:
+ error("the policy type specified is not supported");
+ break;
+ default:
+ break;
+ }
+
}
}
diff --git a/src/main/java/org/onosproject/segmentrouting/cli/PolicyRemoveCommand.java b/src/main/java/org/onosproject/segmentrouting/cli/PolicyRemoveCommand.java
index b4f3b35..34fe40d 100644
--- a/src/main/java/org/onosproject/segmentrouting/cli/PolicyRemoveCommand.java
+++ b/src/main/java/org/onosproject/segmentrouting/cli/PolicyRemoveCommand.java
@@ -19,6 +19,7 @@
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.segmentrouting.PolicyHandler;
import org.onosproject.segmentrouting.SegmentRoutingService;
import org.onosproject.segmentrouting.TunnelPolicy;
@@ -41,6 +42,9 @@
AbstractShellCommand.get(SegmentRoutingService.class);
TunnelPolicy.Builder tpb = TunnelPolicy.builder().setPolicyId(policyId);
- srService.removePolicy(tpb.build());
+ PolicyHandler.Result result = srService.removePolicy(tpb.build());
+ if (result == PolicyHandler.Result.POLICY_NOT_FOUND) {
+ print("ERROR: the policy is not found");
+ }
}
}
\ No newline at end of file
diff --git a/src/main/java/org/onosproject/segmentrouting/cli/TunnelAddCommand.java b/src/main/java/org/onosproject/segmentrouting/cli/TunnelAddCommand.java
index 51dee41..bb0ae54 100644
--- a/src/main/java/org/onosproject/segmentrouting/cli/TunnelAddCommand.java
+++ b/src/main/java/org/onosproject/segmentrouting/cli/TunnelAddCommand.java
@@ -22,6 +22,7 @@
import org.onosproject.segmentrouting.DefaultTunnel;
import org.onosproject.segmentrouting.SegmentRoutingService;
import org.onosproject.segmentrouting.Tunnel;
+import org.onosproject.segmentrouting.TunnelHandler;
import java.util.ArrayList;
import java.util.List;
@@ -58,6 +59,22 @@
}
Tunnel tunnel = new DefaultTunnel(tunnelId, labelIds);
- srService.createTunnel(tunnel);
+ TunnelHandler.Result result = srService.createTunnel(tunnel);
+ switch (result) {
+ case ID_EXISTS:
+ print("ERROR: the same tunnel ID exists");
+ break;
+ case TUNNEL_EXISTS:
+ print("ERROR: the same tunnel exists");
+ break;
+ case INTERNAL_ERROR:
+ print("ERROR: internal tunnel creation error");
+ break;
+ case WRONG_PATH:
+ print("ERROR: the tunnel path is wrong");
+ break;
+ default:
+ break;
+ }
}
}
\ No newline at end of file
diff --git a/src/main/java/org/onosproject/segmentrouting/cli/TunnelRemoveCommand.java b/src/main/java/org/onosproject/segmentrouting/cli/TunnelRemoveCommand.java
index f5c9f58..cca22c3 100644
--- a/src/main/java/org/onosproject/segmentrouting/cli/TunnelRemoveCommand.java
+++ b/src/main/java/org/onosproject/segmentrouting/cli/TunnelRemoveCommand.java
@@ -23,6 +23,7 @@
import org.onosproject.segmentrouting.DefaultTunnel;
import org.onosproject.segmentrouting.SegmentRoutingService;
import org.onosproject.segmentrouting.Tunnel;
+import org.onosproject.segmentrouting.TunnelHandler;
/**
* Command to remove a tunnel.
@@ -38,11 +39,20 @@
@Override
protected void execute() {
-
SegmentRoutingService srService =
AbstractShellCommand.get(SegmentRoutingService.class);
Tunnel tunnel = new DefaultTunnel(tunnelId, Lists.newArrayList());
- srService.removeTunnel(tunnel);
+ TunnelHandler.Result result = srService.removeTunnel(tunnel);
+ switch (result) {
+ case TUNNEL_IN_USE:
+ print("ERROR: the tunnel is still in use");
+ break;
+ case TUNNEL_NOT_FOUND:
+ print("ERROR: the tunnel is not found");
+ break;
+ default:
+ break;
+ }
}
}
\ No newline at end of file