Added ports to Ramcloud, plus REST API to view them
Change-Id: I04ca319457304a1ae65533bc0e0bbe95d6c788c9
diff --git a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/NetworkGraphDatastore.java b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/NetworkGraphDatastore.java
index a3069c3..c8f4d8d 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/NetworkGraphDatastore.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/NetworkGraphDatastore.java
@@ -6,6 +6,7 @@
import net.onrc.onos.datastore.RCObject;
import net.onrc.onos.datastore.RCObject.WriteOp;
import net.onrc.onos.datastore.topology.RCLink;
+import net.onrc.onos.datastore.topology.RCPort;
import net.onrc.onos.datastore.topology.RCSwitch;
import org.slf4j.Logger;
@@ -54,13 +55,14 @@
// to assure that DPID is unique cluster-wide, etc.
groupOp.add(WriteOp.ForceCreate(rcSwitch));
-// for (Port port : sw.getPorts()) {
-// RCPort rcPort = new RCPort(sw.getDpid(), (long)port.getNumber());
-// rcPort.setStatus(RCPort.STATUS.ACTIVE);
-// rcSwitch.addPortId(rcPort.getId());
-//
-// groupOp.add(WriteOp.ForceCreate(rcPort));
-// }
+ //for (Port port : sw.getPorts()) {
+ for (PortEvent portEvent : sw.getPorts()) {
+ RCPort rcPort = new RCPort(sw.getDpid(), portEvent.getNumber());
+ rcPort.setStatus(RCPort.STATUS.ACTIVE);
+ //rcSwitch.addPortId(rcPort.getId());
+
+ groupOp.add(WriteOp.ForceCreate(rcPort));
+ }
boolean failed = RCObject.multiWrite(groupOp);
diff --git a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/web/NetworkGraphWebRoutable.java b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/web/NetworkGraphWebRoutable.java
index d6f1f95..6a7ab99 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/web/NetworkGraphWebRoutable.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/web/NetworkGraphWebRoutable.java
@@ -13,6 +13,7 @@
Router router = new Router(context);
router.attach("/rc/switches/json", RamcloudSwitchesResource.class);
router.attach("/rc/links/json", RamcloudLinksResource.class);
+ router.attach("/rc/ports/json", RamcloudPortsResource.class);
router.attach("/ng/switches/json", NetworkGraphSwitchesResource.class);
router.attach("/ng/links/json", NetworkGraphLinksResource.class);
return router;
diff --git a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/web/RamcloudPortsResource.java b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/web/RamcloudPortsResource.java
new file mode 100644
index 0000000..b2f88dd
--- /dev/null
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/web/RamcloudPortsResource.java
@@ -0,0 +1,14 @@
+package net.onrc.onos.ofcontroller.networkgraph.web;
+
+import net.onrc.onos.datastore.topology.RCPort;
+
+import org.restlet.resource.Get;
+import org.restlet.resource.ServerResource;
+
+public class RamcloudPortsResource extends ServerResource {
+
+ @Get("json")
+ public Iterable<RCPort> retrieve() {
+ return RCPort.getAllPorts();
+ }
+}