Integration of SR Tunnel REST calls with APIs
diff --git a/cli/cli/c_actions.py b/cli/cli/c_actions.py
index 26499aa..9c6ee2e 100755
--- a/cli/cli/c_actions.py
+++ b/cli/cli/c_actions.py
@@ -99,8 +99,8 @@
entries = tunnel_dict[tunnel_id]
url_str = "http://%s/rest/v1/tunnel/" % (sdnsh.controller)
obj_data = {}
- obj_data['tunnel-id']=tunnel_id
- obj_data['tunnel-path']=entries
+ obj_data['tunnel_id']=tunnel_id
+ obj_data['tunnel_path']=entries
data = sdnsh.store.rest_post_request(url_str,obj_data)
# LOOK! successful stuff should be returned in json too.
if data != "success":
diff --git a/src/main/java/net/onrc/onos/apps/segmentrouting/web/RouterStatisticsResource.java b/src/main/java/net/onrc/onos/apps/segmentrouting/web/RouterStatisticsResource.java
index 1f5cb12..00c2f15 100644
--- a/src/main/java/net/onrc/onos/apps/segmentrouting/web/RouterStatisticsResource.java
+++ b/src/main/java/net/onrc/onos/apps/segmentrouting/web/RouterStatisticsResource.java
@@ -64,8 +64,8 @@
JSONArray subnetArray = JSONArray.fromObject(subnets);
Iterator<Port> pI = portList.iterator();
while(pI.hasNext()){
- Port p = (Port) pI.next();
- Iterator sI = subnetArray.iterator();
+ Port p = pI.next();
+ Iterator<?> sI = subnetArray.iterator();
String subnet = null;
while(sI.hasNext()){
JSONObject portSubnetIp = (JSONObject) sI.next();
@@ -83,7 +83,7 @@
else{
Iterator<Port> pI = portList.iterator();
while(pI.hasNext()){
- Port p = (Port) pI.next();
+ Port p = pI.next();
String subnet = null;
listPortInfo.add( new SegmentRouterPortInfo(subnet,p));
}
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 57e42c7..7bcdfa6 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
@@ -1,5 +1,13 @@
package net.onrc.onos.apps.segmentrouting.web;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import net.onrc.onos.apps.segmentrouting.ISegmentRoutingService;
+import net.onrc.onos.core.util.Dpid;
+
+import org.codehaus.jackson.map.ObjectMapper;
import org.restlet.resource.Delete;
import org.restlet.resource.Get;
import org.restlet.resource.Post;
@@ -17,9 +25,28 @@
@Post("json")
public String createTunnel(String tunnelParams) {
- String reply = "success";
- log.debug("createTunnel with params {}", tunnelParams);
- return reply;
+ ISegmentRoutingService segmentRoutingService =
+ (ISegmentRoutingService) getContext().getAttributes().
+ get(ISegmentRoutingService.class.getCanonicalName());
+ ObjectMapper mapper = new ObjectMapper();
+ TunnelCreateParams createParams = null;
+ try {
+ if (tunnelParams != null) {
+ createParams = mapper.readValue(tunnelParams, TunnelCreateParams.class);
+ }
+ } catch (IOException ex) {
+ log.error("Exception occurred parsing inbound JSON", ex);
+ return "fail";
+ }
+ log.debug("createTunnel with tunnelId {} tunnelPath{}",
+ createParams.getTunnel_id(), createParams.getTunnel_path());
+ List<Dpid> tunnelDpids = new ArrayList<Dpid>();
+ for (String dpid : createParams.getTunnel_path()) {
+ tunnelDpids.add(new Dpid(dpid));
+ }
+ boolean result = segmentRoutingService.createTunnel(createParams.getTunnel_id(),
+ tunnelDpids);
+ return (result == true) ? "success" : "fail";
}
@Delete("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/TunnelCreateParams.java
new file mode 100644
index 0000000..fb3a00d
--- /dev/null
+++ b/src/main/java/net/onrc/onos/apps/segmentrouting/web/TunnelCreateParams.java
@@ -0,0 +1,29 @@
+package net.onrc.onos.apps.segmentrouting.web;
+
+import java.util.List;
+
+public class TunnelCreateParams {
+ private String tunnel_id;
+ private List<String> tunnel_path;
+
+ public TunnelCreateParams() {
+ this.tunnel_id = null;
+ this.tunnel_path = null;
+ }
+
+ public void setTunnel_id(String tunnel_id) {
+ this.tunnel_id = tunnel_id;
+ }
+
+ public String getTunnel_id() {
+ return this.tunnel_id;
+ }
+
+ public void setTunnel_path(List<String> tunnel_path) {
+ this.tunnel_path = tunnel_path;
+ }
+
+ public List<String> getTunnel_path() {
+ return this.tunnel_path;
+ }
+}