Integration of SR Policy REST calls with APIs
diff --git a/src/main/java/net/onrc/onos/apps/segmentrouting/web/SegmentRouterPolicyRESTParams.java b/src/main/java/net/onrc/onos/apps/segmentrouting/web/SegmentRouterPolicyRESTParams.java
new file mode 100644
index 0000000..d0a34b0
--- /dev/null
+++ b/src/main/java/net/onrc/onos/apps/segmentrouting/web/SegmentRouterPolicyRESTParams.java
@@ -0,0 +1,108 @@
+package net.onrc.onos.apps.segmentrouting.web;
+
+
+public class SegmentRouterPolicyRESTParams {
+    private String policy_id;
+    private int priority;
+    private String tunnel_id;
+    private String proto_type;
+    private String src_ip;
+    private String src_tp_port_op;
+    private short src_tp_port;
+    private String dst_ip;
+    private String dst_tp_port_op;
+    private short dst_tp_port;
+
+    public SegmentRouterPolicyRESTParams() {
+        this.policy_id = null;
+        this.priority = 0;
+        this.tunnel_id = null;
+        this.proto_type = null;
+        this.src_ip = null;
+        this.src_tp_port_op = null;
+        this.src_tp_port = 0;
+        this.dst_ip = null;
+        this.dst_tp_port_op = null;
+        this.dst_tp_port = 0;
+    }
+
+    public void setPolicy_id(String policy_id) {
+        this.policy_id = policy_id;
+    }
+
+    public String getPolicy_id() {
+        return this.policy_id;
+    }
+
+    public void setPriority(int priority) {
+        this.priority = priority;
+    }
+
+    public int getPriority() {
+        return this.priority;
+    }
+
+    public void setTunnel_id(String tunnel_id) {
+        this.tunnel_id = tunnel_id;
+    }
+
+    public String getTunnel_id() {
+        return this.tunnel_id;
+    }
+
+    public void setProto_type(String proto_type) {
+        this.proto_type = proto_type;
+    }
+
+    public String getProto_type() {
+        return this.proto_type;
+    }
+
+    public void setSrc_ip(String src_ip) {
+        this.src_ip = src_ip;
+    }
+
+    public String getSrc_ip() {
+        return this.src_ip;
+    }
+
+    public void setSrc_tp_port_op(String src_tp_port_op) {
+        this.src_tp_port_op = src_tp_port_op;
+    }
+
+    public String getSrc_tp_port_op() {
+        return this.src_tp_port_op;
+    }
+
+    public void setSrc_tp_port(short src_tp_port) {
+        this.src_tp_port = src_tp_port;
+    }
+
+    public short getSrc_tp_port() {
+        return this.src_tp_port;
+    }
+
+    public void setDst_ip(String dst_ip) {
+        this.dst_ip = dst_ip;
+    }
+
+    public String getDst_ip() {
+        return this.dst_ip;
+    }
+
+    public void setDst_tp_port_op(String dst_tp_port_op) {
+        this.dst_tp_port_op = dst_tp_port_op;
+    }
+
+    public String getDst_tp_port_op() {
+        return this.dst_tp_port_op;
+    }
+
+    public void setDst_tp_port(short dst_tp_port) {
+        this.dst_tp_port = dst_tp_port;
+    }
+
+    public short getDst_tp_port() {
+        return this.dst_tp_port;
+    }
+}
diff --git a/src/main/java/net/onrc/onos/apps/segmentrouting/web/SegmentRouterPolicyResource.java b/src/main/java/net/onrc/onos/apps/segmentrouting/web/SegmentRouterPolicyResource.java
index f91cc7d..694258c 100644
--- a/src/main/java/net/onrc/onos/apps/segmentrouting/web/SegmentRouterPolicyResource.java
+++ b/src/main/java/net/onrc/onos/apps/segmentrouting/web/SegmentRouterPolicyResource.java
@@ -1,5 +1,12 @@
 package net.onrc.onos.apps.segmentrouting.web;
 
+import java.io.IOException;
+
+import net.onrc.onos.apps.segmentrouting.ISegmentRoutingService;
+import net.onrc.onos.core.packet.IPv4;
+import net.onrc.onos.core.util.IPv4Net;
+
+import org.codehaus.jackson.map.ObjectMapper;
 import org.restlet.resource.Delete;
 import org.restlet.resource.Get;
 import org.restlet.resource.Post;
@@ -17,16 +24,74 @@
 
     @Post("json")
     public String createPolicy(String policyParams) {
-        String reply = "success";
-        log.debug("createPolicy with params {}", policyParams);
-        return reply;
+        ISegmentRoutingService segmentRoutingService =
+                (ISegmentRoutingService) getContext().getAttributes().
+                        get(ISegmentRoutingService.class.getCanonicalName());
+        ObjectMapper mapper = new ObjectMapper();
+        SegmentRouterPolicyRESTParams createParams = null;
+        try {
+            if (policyParams != null) {
+                createParams = mapper.readValue(policyParams,
+                        SegmentRouterPolicyRESTParams.class);
+            }
+        } catch (IOException ex) {
+            log.error("Exception occurred parsing inbound JSON", ex);
+            return "fail";
+        }
+
+        log.debug("createPolicy with params id {} src_ip {} dst_ip {}"
+                + "proto {} src_port {} dst_port {} priority {} tunnel_id {}",
+                createParams.getPolicy_id(), createParams.getSrc_ip(),
+                createParams.getDst_ip(), createParams.getProto_type(),
+                createParams.getSrc_tp_port(), createParams.getDst_tp_port(),
+                createParams.getPriority(), createParams.getTunnel_id());
+
+        boolean result = segmentRoutingService.createPolicy(
+                createParams.getPolicy_id(), null, null, (short) 0,
+                new IPv4Net(createParams.getSrc_ip()),
+                new IPv4Net(createParams.getDst_ip()),
+                getProtoTypeByte(createParams.getProto_type()),
+                createParams.getSrc_tp_port(),
+                createParams.getDst_tp_port(),
+                createParams.getPriority(),
+                createParams.getTunnel_id());
+        return (result == true) ? "success" : "fail";
+    }
+
+    private Byte getProtoTypeByte(String protoType) {
+        Byte protoTypeByte = 0;
+        switch (protoType) {
+        case "tcp":
+            protoTypeByte = IPv4.PROTOCOL_TCP;
+            break;
+        case "udp":
+            protoTypeByte = IPv4.PROTOCOL_UDP;
+            break;
+        }
+        return protoTypeByte;
     }
 
     @Delete("json")
-    public String deletePolicy(String policyId) {
-        String reply = "deleted";
-        log.debug("deletePolicy with Id {}", policyId);
-        return reply;
+    public String deletePolicy(String policyParams) {
+        ISegmentRoutingService segmentRoutingService =
+                (ISegmentRoutingService) getContext().getAttributes().
+                        get(ISegmentRoutingService.class.getCanonicalName());
+        ObjectMapper mapper = new ObjectMapper();
+        SegmentRouterPolicyRESTParams createParams = null;
+        try {
+            if (policyParams != null) {
+                createParams = mapper.readValue(policyParams,
+                        SegmentRouterPolicyRESTParams.class);
+            }
+        } catch (IOException ex) {
+            log.error("Exception occurred parsing inbound JSON", ex);
+            return "fail";
+        }
+
+        log.debug("deletePolicy with Id {}", createParams.getPolicy_id());
+        boolean result = segmentRoutingService.removePolicy(
+                createParams.getPolicy_id());
+        return (result == true) ? "deleted" : "fail";
     }
 
     @Get("json")
diff --git a/src/main/java/net/onrc/onos/apps/segmentrouting/web/TunnelCreateParams.java b/src/main/java/net/onrc/onos/apps/segmentrouting/web/SegmentRouterTunnelRESTParams.java
similarity index 86%
rename from src/main/java/net/onrc/onos/apps/segmentrouting/web/TunnelCreateParams.java
rename to src/main/java/net/onrc/onos/apps/segmentrouting/web/SegmentRouterTunnelRESTParams.java
index fb3a00d..4248b24 100644
--- a/src/main/java/net/onrc/onos/apps/segmentrouting/web/TunnelCreateParams.java
+++ b/src/main/java/net/onrc/onos/apps/segmentrouting/web/SegmentRouterTunnelRESTParams.java
@@ -2,11 +2,11 @@
 
 import java.util.List;
 
-public class TunnelCreateParams {
+public class SegmentRouterTunnelRESTParams {
     private String tunnel_id;
     private List<String> tunnel_path;
 
-    public TunnelCreateParams() {
+    public SegmentRouterTunnelRESTParams() {
         this.tunnel_id = null;
         this.tunnel_path = null;
     }
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 71cfc05..3c19a21 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
@@ -39,10 +39,11 @@
                 (ISegmentRoutingService) getContext().getAttributes().
                         get(ISegmentRoutingService.class.getCanonicalName());
         ObjectMapper mapper = new ObjectMapper();
-        TunnelCreateParams createParams = null;
+        SegmentRouterTunnelRESTParams createParams = null;
         try {
             if (tunnelParams != null) {
-                createParams = mapper.readValue(tunnelParams, TunnelCreateParams.class);
+                createParams = mapper.readValue(tunnelParams,
+                        SegmentRouterTunnelRESTParams.class);
             }
         } catch (IOException ex) {
             log.error("Exception occurred parsing inbound JSON", ex);
@@ -60,10 +61,25 @@
     }
 
     @Delete("json")
-    public String deleteTunnel(String tunnelId) {
-        String reply = "deleted";
-        log.debug("deleteTunnel with Id {}", tunnelId);
-        return reply;
+    public String deleteTunnel(String tunnelParams) {
+        ISegmentRoutingService segmentRoutingService =
+                (ISegmentRoutingService) getContext().getAttributes().
+                        get(ISegmentRoutingService.class.getCanonicalName());
+        ObjectMapper mapper = new ObjectMapper();
+        SegmentRouterTunnelRESTParams createParams = null;
+        try {
+            if (tunnelParams != null) {
+                createParams = mapper.readValue(tunnelParams,
+                        SegmentRouterTunnelRESTParams.class);
+            }
+        } catch (IOException ex) {
+            log.error("Exception occurred parsing inbound JSON", ex);
+            return "fail";
+        }
+        log.debug("deleteTunnel with Id {}", createParams.getTunnel_id());
+        boolean result = segmentRoutingService.removeTunnel(
+                createParams.getTunnel_id());
+        return (result == true) ? "deleted" : "fail";
     }
 
     @Get("json")