Added error codes: messages for remove tunnel
diff --git a/cli/cli/c_actions.py b/cli/cli/c_actions.py
index c953deb..6852f57 100755
--- a/cli/cli/c_actions.py
+++ b/cli/cli/c_actions.py
@@ -151,8 +151,8 @@
except Exception, e:
errors = sdnsh.rest_error_to_dict(e)
print sdnsh.rest_error_dict_to_message(errors)
- if result != "deleted":
- print "command failed"
+ if not result.startswith("SUCCESS"):
+ print result
policy_obj_data = {}
def policy_create(data=None):
diff --git a/src/main/java/net/onrc/onos/apps/segmentrouting/ISegmentRoutingService.java b/src/main/java/net/onrc/onos/apps/segmentrouting/ISegmentRoutingService.java
index 61ec630..446384e 100644
--- a/src/main/java/net/onrc/onos/apps/segmentrouting/ISegmentRoutingService.java
+++ b/src/main/java/net/onrc/onos/apps/segmentrouting/ISegmentRoutingService.java
@@ -8,6 +8,7 @@
import net.floodlightcontroller.util.MACAddress;
import net.onrc.onos.apps.segmentrouting.SegmentRoutingManager.PolicyInfo;
import net.onrc.onos.apps.segmentrouting.SegmentRoutingManager.TunnelInfo;
+import net.onrc.onos.apps.segmentrouting.SegmentRoutingManager.removeTunnelMessages;
import net.onrc.onos.core.util.IPv4Net;
/**
@@ -33,7 +34,7 @@
*
* @return "true/false" depending tunnel deletion status
*/
- public boolean removeTunnel(String tunnelId);
+ public removeTunnelMessages removeTunnel(String tunnelId);
/**
* Create a policy for policy based segment routing
diff --git a/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingManager.java b/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingManager.java
index fbc9597..dbd3b7e 100644
--- a/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingManager.java
+++ b/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingManager.java
@@ -1597,6 +1597,35 @@
return true;
}
+ public enum removeTunnelMessages{
+ SUCCESS(0, "Tunnel is removed successfully."),
+ ERROR_REFERENCED(1, "Can't remove tunnel as its referenced by other policy(s)"),
+ ERROR_SWITCH(2, "Switch not found in the tunnel route"),
+ ERROR_DRIVER(3, "Can't remove tunnel at driver"),
+ ERROR_TUNNEL(4, "Tunnel not found");
+
+ private final int code;
+ private final String description;
+
+ private removeTunnelMessages(int code, String description) {
+ this.code = code;
+ this.description = description;
+ }
+
+ public String getDescription() {
+ return this.description;
+ }
+
+ public int getCode() {
+ return this.code;
+ }
+
+ @Override
+ public String toString() {
+ return "[" + this.code + ": " + this.description + "]";
+ }
+
+ }
/**
* Remove a tunnel
* It removes all groups for the tunnel if the tunnel is not used for any
@@ -1604,20 +1633,20 @@
*
* @param tunnelId tunnel ID to remove
*/
- public boolean removeTunnel(String tunnelId) {
+ public removeTunnelMessages removeTunnel(String tunnelId) {
// Check if the tunnel is used for any policy
for (PolicyInfo policyInfo: policyTable.values()) {
if (policyInfo.tunnelId.equals(tunnelId)) {
log.debug("Tunnel {} is still used for the policy {}.",
policyInfo.policyId, tunnelId);
- return false;
+ return removeTunnelMessages.ERROR_REFERENCED;
}
}
TunnelInfo tunnelInfo = tunnelTable.get(tunnelId);
if (tunnelInfo == null)
- return false;
+ return removeTunnelMessages.ERROR_TUNNEL;
List<TunnelRouteInfo> routes = tunnelInfo.routes;
for (TunnelRouteInfo route: routes) {
@@ -1625,20 +1654,21 @@
getSwId(route.srcSwDpid));
if (sw13 == null) {
- return false;
+ return removeTunnelMessages.ERROR_SWITCH;
}
else {
if (!sw13.removeGroup(route.getGroupId())) {
log.warn("Faied to remove the tunnel {} at driver",
tunnelId);
- return false; }
+ return removeTunnelMessages.ERROR_DRIVER;
+ }
}
}
tunnelTable.remove(tunnelId);
log.debug("Tunnel {} was removed successfully.", tunnelId);
- return true;
+ return removeTunnelMessages.SUCCESS;
}
// ************************************
diff --git a/src/main/java/net/onrc/onos/apps/segmentrouting/web/SegmentRouterTunnelResource.java b/src/main/java/net/onrc/onos/apps/segmentrouting/web/SegmentRouterTunnelResource.java
index aa9b62f..7990e48 100644
--- a/src/main/java/net/onrc/onos/apps/segmentrouting/web/SegmentRouterTunnelResource.java
+++ b/src/main/java/net/onrc/onos/apps/segmentrouting/web/SegmentRouterTunnelResource.java
@@ -12,6 +12,7 @@
import net.onrc.onos.apps.segmentrouting.SegmentRoutingManager.PolicyInfo;
import net.onrc.onos.apps.segmentrouting.SegmentRoutingManager.TunnelInfo;
import net.onrc.onos.apps.segmentrouting.SegmentRoutingManager.TunnelRouteInfo;
+import net.onrc.onos.apps.segmentrouting.SegmentRoutingManager.removeTunnelMessages;
import org.codehaus.jackson.map.ObjectMapper;
import org.restlet.resource.Delete;
@@ -68,9 +69,9 @@
return "fail";
}
log.debug("deleteTunnel with Id {}", createParams.getTunnel_id());
- boolean result = segmentRoutingService.removeTunnel(
+ removeTunnelMessages result = segmentRoutingService.removeTunnel(
createParams.getTunnel_id());
- return (result == true) ? "deleted" : "fail";
+ return result.name()+" "+result.toString();
}
@Get("json")