first commit
diff --git a/conf/onos.properties b/conf/onos.properties
index 283203a..7f50e6e 100644
--- a/conf/onos.properties
+++ b/conf/onos.properties
@@ -13,5 +13,7 @@
net.floodlightcontroller.core.FloodlightProvider.workerthreads = 16
net.floodlightcontroller.forwarding.Forwarding.idletimeout = 5
net.floodlightcontroller.forwarding.Forwarding.hardtimeout = 0
-net.onrc.onos.ofcontroller.floodlightlistener.NetworkGraphPublisher.dbconf = /tmp/cassandra.titan
+#net.onrc.onos.ofcontroller.floodlightlistener.NetworkGraphPublisher.dbconf = /tmp/cassandra.titan
+net.onrc.onos.ofcontroller.floodlightlistener.NetworkGraphPublisher.dbconf = /tmp/ramcloud.conf
+net.onrc.onos.ofcontroller.floodlightlistener.NetworkGraphPublisher.graph_db_store = ramcloud
diff --git a/pom.xml b/pom.xml
index 943133d..4a93625 100644
--- a/pom.xml
+++ b/pom.xml
@@ -32,7 +32,7 @@
</repositories>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <powermock.version>1.5</powermock.version>
+ <powermock.version>1.5.1</powermock.version>
<restlet.version>2.1-RC1</restlet.version>
<github.global.server>github</github.global.server>
</properties>
@@ -232,13 +232,16 @@
<artifactId>frames</artifactId>
<version>2.3.1</version>
</dependency>
- <!--
<dependency>
<groupId>com.tinkerpop.blueprints</groupId>
<artifactId>blueprints-core</artifactId>
- <version>2.3.0</version>
+ <version>2.4.0</version>
</dependency>
- -->
+ <dependency>
+ <groupId>com.hazelcast</groupId>
+ <artifactId>hazelcast</artifactId>
+ <version>3.0.2</version>
+ </dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
@@ -344,7 +347,7 @@
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
- <version>3.1</version>
+ <version>3.2</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -400,5 +403,12 @@
<version>0.1.0</version>
</dependency>
-->
+ <dependency>
+ <groupId>com.tinkerpop.blueprints.impls.ramcloud</groupId>
+ <artifactId>blueprints-ramcloud-graph</artifactId>
+ <version>2.4.0</version>
+ <scope>system</scope>
+ <systemPath>${project.basedir}/lib/blueprints-ramcloud-graph-2.4.0.jar</systemPath>
+ </dependency>
</dependencies>
</project>
diff --git a/src/main/java/net/onrc/onos/flow/FlowManagerImpl.java b/src/main/java/net/onrc/onos/flow/FlowManagerImpl.java
index 2e2706c..bf5ce51 100644
--- a/src/main/java/net/onrc/onos/flow/FlowManagerImpl.java
+++ b/src/main/java/net/onrc/onos/flow/FlowManagerImpl.java
@@ -18,7 +18,7 @@
import com.tinkerpop.blueprints.Vertex;
import net.floodlightcontroller.core.IOFSwitch;
-import net.onrc.onos.graph.GraphDBOperation;
+import net.onrc.onos.graph.DBOperation;
import net.onrc.onos.graph.LocalTopologyEventListener;
import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowEntry;
import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowPath;
@@ -37,7 +37,7 @@
public class FlowManagerImpl implements IFlowManager {
protected static Logger log = LoggerFactory.getLogger(LocalTopologyEventListener.class);
- protected GraphDBOperation op;
+ protected DBOperation op;
@Override
public void createFlow(IPortObject src_port, IPortObject dest_port) {
@@ -85,10 +85,8 @@
String dst_dpid = flow.getDstSwitch();
Short src_port = flow.getSrcPort();
Short dst_port = flow.getDstPort();
- IPortObject src = null;
- IPortObject dst = null;
- src = op.searchPort(src_dpid, src_port);
- dst = op.searchPort(dst_dpid, dst_port);
+ IPortObject src = op.searchPort(src_dpid, src_port);
+ IPortObject dst = op.searchPort(dst_dpid, dst_port);
if (src != null && dst != null) {
FlowPath newFlow = this.computeFlowPath(src,dst);
installFlow(newFlow);
diff --git a/src/main/java/net/onrc/onos/graph/IDBConnection.java b/src/main/java/net/onrc/onos/graph/IDBConnection.java
index 82ebba2..cd65ec0 100644
--- a/src/main/java/net/onrc/onos/graph/IDBConnection.java
+++ b/src/main/java/net/onrc/onos/graph/IDBConnection.java
@@ -1,13 +1,12 @@
package net.onrc.onos.graph;
-import com.thinkaurelius.titan.core.TitanGraph;
import com.tinkerpop.frames.FramedGraph;
public interface IDBConnection {
- public FramedGraph<TitanGraph> getFramedGraph();
- public void addEventListener(final LocalGraphChangedListener listener);
- public Boolean isValid();
- public void commit();
- public void rollback();
- public void close();
+ public FramedGraph getFramedGraph();
+ public void addEventListener(final LocalGraphChangedListener listener);
+ public Boolean isValid();
+ public void commit();
+ public void rollback();
+ public void close();
}
diff --git a/src/main/java/net/onrc/onos/graph/LocalTopologyEventListener.java b/src/main/java/net/onrc/onos/graph/LocalTopologyEventListener.java
index f83e7c2..fc8a196 100644
--- a/src/main/java/net/onrc/onos/graph/LocalTopologyEventListener.java
+++ b/src/main/java/net/onrc/onos/graph/LocalTopologyEventListener.java
@@ -11,94 +11,102 @@
import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Vertex;
+import com.tinkerpop.blueprints.impls.ramcloud.*;
+import java.util.Map;
public class LocalTopologyEventListener implements LocalGraphChangedListener {
-
- protected static Logger log = LoggerFactory.getLogger(LocalTopologyEventListener.class);
- protected static GraphDBConnection conn;
-
- public LocalTopologyEventListener(GraphDBConnection conn) {
- LocalTopologyEventListener.conn = conn;
- }
- @Override
- public void edgeAdded(Edge arg0) {
- // TODO Auto-generated method stub
- // Convert this Event into NetMapEvent (LinkAdded, FlowEntryEnabled, HostAttached, PortEnabled)
- }
+ protected static Logger log = LoggerFactory.getLogger(LocalTopologyEventListener.class);
+ protected static DBConnection conn;
+ public LocalTopologyEventListener(DBConnection conn) {
+ LocalTopologyEventListener.conn = conn;
+ }
- @Override
- public void edgePropertyRemoved(Edge arg0, String arg1, Object arg2) {
- // TODO Auto-generated method stub
- // Currently not needed
+ @Override
+ public void edgeAdded(Edge arg0) {
+ // TODO Auto-generated method stub
+ // Convert this Event into NetMapEvent (LinkAdded, FlowEntryEnabled, HostAttached, PortEnabled)
+ }
- }
+ @Override
+ public void edgePropertyRemoved(Edge arg0, String arg1, Object arg2) {
+ // TODO Auto-generated method stub
+ // Currently not needed
+ }
- @Override
- public void edgeRemoved(Edge e) {
- // TODO Auto-generated method stub
- // Fire NetMapEvents (LinkRemoved, FlowEntryRemoved, HostRemoved, PortRemoved)
- TitanEdge edge = (TitanEdge) e;
- log.debug("TopologyEvents: Received edge removed event: {}",edge.toString());
- String label = edge.getLabel();
- if (label.equals("link")) {
- Vertex v = edge.getVertex(Direction.IN);
- IPortObject src_port = conn.getFramedGraph().frame(v, IPortObject.class);
- v = edge.getVertex(Direction.OUT);
- IPortObject dest_port = conn.getFramedGraph().frame(v, IPortObject.class);
+ public void edgeRemoved(Edge e) {
+ Edge edge;
+ if (e instanceof com.tinkerpop.blueprints.impls.ramcloud.RamCloudEdge) {
+ edge = (RamCloudEdge) e;
+ } else {
+ edge = (TitanEdge) e;
+ }
+ // TODO Auto-generated method stub
+ // Fire NetMapEvents (LinkRemoved, FlowEntryRemoved, HostRemoved, PortRemoved)
+ // TitanEdge edge = (TitanEdge) e;
+ log.debug("TopologyEvents: Received edge removed event: {}", edge.toString());
+ String label = edge.getLabel();
+ if (label.equals("link")) {
+ Vertex v = edge.getVertex(Direction.IN);
+ IPortObject src_port = (IPortObject)conn.getFramedGraph().frame(v, IPortObject.class);
+ v = edge.getVertex(Direction.OUT);
+ IPortObject dest_port = (IPortObject)conn.getFramedGraph().frame(v, IPortObject.class);
- log.debug("TopologyEvents: link broken {}", new Object []{src_port.getSwitch().getDPID(),
- src_port.getNumber(),
- dest_port.getSwitch().getDPID(),
- dest_port.getNumber()});
- IFlowManager manager = new FlowManagerImpl();
- // TODO: Find the flows and add to reconcile queue
- manager.reconcileFlows(src_port);
- }
- }
+ log.debug("TopologyEvents: link broken {}", new Object[]{src_port.getSwitch().getDPID(),
+ src_port.getNumber(),
+ dest_port.getSwitch().getDPID(),
+ dest_port.getNumber()});
+ IFlowManager manager = new FlowManagerImpl();
+ // TODO: Find the flows and add to reconcile queue
+ manager.reconcileFlows(src_port);
+ }
+ }
- @Override
- public void vertexAdded(Vertex arg0) {
- // TODO Auto-generated method stub
+ @Override
+ public void vertexAdded(Vertex arg0) {
+ // TODO Auto-generated method stub
+ }
- }
+ @Override
+ public void vertexPropertyRemoved(Vertex arg0, String arg1, Object arg2) {
+ // TODO Auto-generated method stub
+ }
- @Override
- public void vertexPropertyRemoved(Vertex arg0, String arg1, Object arg2) {
- // TODO Auto-generated method stub
+ public void vertexRemoved(Vertex vertex) {
+ // TODO Auto-generated method stub
+ // Generate NetMapEvents
+ String type = (String) vertex.getProperty("type");
+ log.debug("TopologyEvents: Received vertex removed event: {}", vertex.toString());
+ if (type.equals("port")) {
+ // port is removed...lets fire reconcile here directly for now
- }
+ IPortObject src_port = (IPortObject)conn.getFramedGraph().frame(vertex, IPortObject.class);
+ log.debug("TopologyEvents: Port removed: {}:{}", src_port.getSwitch().getDPID(), src_port.getNumber());
+ IFlowManager manager = new FlowManagerImpl();
+ manager.reconcileFlows(src_port);
+ }
+ }
- @Override
- public void vertexRemoved(Vertex vertex) {
- // TODO Auto-generated method stub
- // Generate NetMapEvents
- String type = (String) vertex.getProperty("type");
- log.debug("TopologyEvents: Received vertex removed event: {}",vertex.toString());
- if (type.equals("port")) {
- // port is removed...lets fire reconcile here directly for now
-
- IPortObject src_port = conn.getFramedGraph().frame(vertex, IPortObject.class);
- log.debug("TopologyEvents: Port removed: {}:{}",src_port.getSwitch().getDPID(),src_port.getNumber());
- IFlowManager manager = new FlowManagerImpl();
- manager.reconcileFlows(src_port);
- }
- }
+ @Override
+ public void edgePropertyChanged(Edge arg0, String arg1, Object arg2,
+ Object arg3) {
+ // TODO Auto-generated method stub
+ }
+ @Override
+ public void vertexPropertyChanged(Vertex arg0, String arg1, Object arg2,
+ Object arg3) {
+ // TODO Auto-generated method stub
+ }
- @Override
- public void edgePropertyChanged(Edge arg0, String arg1, Object arg2,
- Object arg3) {
- // TODO Auto-generated method stub
-
- }
+ @Override
+ public void vertexRemoved(Vertex vertex, Map<String, Object> props) {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
- @Override
- public void vertexPropertyChanged(Vertex arg0, String arg1, Object arg2,
- Object arg3) {
- // TODO Auto-generated method stub
-
- }
-
+ @Override
+ public void edgeRemoved(Edge edge, Map<String, Object> props) {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/bgproute/BgpRoute.java b/src/main/java/net/onrc/onos/ofcontroller/bgproute/BgpRoute.java
index 826fd93..52281ac 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/bgproute/BgpRoute.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/bgproute/BgpRoute.java
@@ -272,7 +272,7 @@
ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
topologyChangeDetectorTask = new SingletonTask(executor, new TopologyChangeDetector());
- topoRouteService = new TopoRouteService("");
+ topoRouteService = new TopoRouteService("", "");
pathsWaitingOnArp = new HashMap<InetAddress, Path>();
prefixesWaitingOnArp = Multimaps.synchronizedSetMultimap(
diff --git a/src/main/java/net/onrc/onos/ofcontroller/core/ILinkStorage.java b/src/main/java/net/onrc/onos/ofcontroller/core/ILinkStorage.java
index b56cfef..0ea6fd5 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/core/ILinkStorage.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/core/ILinkStorage.java
@@ -48,6 +48,6 @@
/*
* Init with Storage conf
*/
- public void init(String conf);
+ public void init(final String dbStore, final String conf);
}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/core/INetMapStorage.java b/src/main/java/net/onrc/onos/ofcontroller/core/INetMapStorage.java
index b052540..2cf0e18 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/core/INetMapStorage.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/core/INetMapStorage.java
@@ -14,6 +14,6 @@
DELETE, // Delete the object
UPDATE // Update the object if exists or CREATE/INSERT if does not exist
}
- public void init(String conf);
+ public void init(final String dbStore, final String conf);
public void close();
}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/core/ISwitchStorage.java b/src/main/java/net/onrc/onos/ofcontroller/core/ISwitchStorage.java
index 4fcebb2..4a62251 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/core/ISwitchStorage.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/core/ISwitchStorage.java
@@ -38,7 +38,7 @@
/*
* Initialize
*/
- public void init(String conf);
+ public void init(final String dbStore, final String conf);
}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/core/internal/DeviceStorageImpl.java b/src/main/java/net/onrc/onos/ofcontroller/core/internal/DeviceStorageImpl.java
index 386c1bd..938ebeb 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/core/internal/DeviceStorageImpl.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/core/internal/DeviceStorageImpl.java
@@ -11,254 +11,274 @@
import net.floodlightcontroller.devicemanager.IDevice;
import net.floodlightcontroller.devicemanager.SwitchPort;
import net.floodlightcontroller.packet.IPv4;
-import net.onrc.onos.graph.GraphDBOperation;
+import net.onrc.onos.graph.DBOperation;
+import net.onrc.onos.graph.GraphDBManager;
import net.onrc.onos.ofcontroller.core.IDeviceStorage;
import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IDeviceObject;
import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IPortObject;
-import net.onrc.onos.ofcontroller.core.internal.SwitchStorageImpl;
/**
* This is the class for storing the information of devices into CassandraDB
+ *
* @author Pankaj
*/
public class DeviceStorageImpl implements IDeviceStorage {
-
- private GraphDBOperation ope;
- protected static Logger log = LoggerFactory.getLogger(SwitchStorageImpl.class);
- /***
- * Initialize function. Before you use this class, please call this method
- * @param conf configuration file for Cassandra DB
- */
- @Override
- public void init(String conf) {
- try{
- ope = new GraphDBOperation(conf);
- } catch(Exception e) {
- log.error(e.getMessage());
- }
- }
-
- /***
- * Finalize/close function. After you use this class, please call this method.
- * It will close the DB connection.
- */
- @Override
- public void close() {
- ope.close();
- }
-
- /***
- * Finalize/close function. After you use this class, please call this method.
- * It will close the DB connection. This is for Java garbage collection.
- */
- @Override
- public void finalize() {
- close();
- }
+ private DBOperation ope;
+ protected static Logger log = LoggerFactory.getLogger(SwitchStorageImpl.class);
- /***
- * This function is for adding the device into the DB.
- * @param device The device you want to add into the DB.
- * @return IDeviceObject which was added in the DB.
- */
- @Override
- public IDeviceObject addDevice(IDevice device) {
- IDeviceObject obj = null;
- try {
- if ((obj = ope.searchDevice(device.getMACAddressString())) != null) {
- log.debug("Adding device {}: found existing device",device.getMACAddressString());
- } else {
- obj = ope.newDevice();
- log.debug("Adding device {}: creating new device",device.getMACAddressString());
- }
- changeDeviceAttachments(device, obj);
-
- String multiIntString = "";
- for(Integer intValue : device.getIPv4Addresses()) {
- if (multiIntString == null || multiIntString.isEmpty()){
- multiIntString = IPv4.fromIPv4Address(intValue);
- multiIntString = "[" + IPv4.fromIPv4Address(intValue);
- }else{
- multiIntString += "," + IPv4.fromIPv4Address(intValue);
- }
- }
-
- if(multiIntString.toString() != null && !multiIntString.toString().isEmpty()){
- obj.setIPAddress(multiIntString + "]");
- }
-
- obj.setMACAddress(device.getMACAddressString());
- obj.setType("device");
- obj.setState("ACTIVE");
- ope.commit();
-
- log.debug("Adding device {}",device.getMACAddressString());
- } catch (Exception e) {
- ope.rollback();
- log.error(":addDevice mac:{} failed", device.getMACAddressString());
- obj = null;
- }
- return obj;
- }
+ /**
+ * *
+ * Initialize function. Before you use this class, please call this method
+ *
+ * @param conf configuration file for Cassandra DB
+ */
+ @Override
+ public void init(final String dbStore, final String conf) {
+ try {
+ ope = GraphDBManager.getDBOperation(dbStore, conf);
+ } catch (Exception e) {
+ log.error(e.getMessage());
+ }
+ }
- /***
- * This function is for updating the Device properties.
- * @param device The device you want to add into the DB.
- * @return IDeviceObject which was added in the DB.
- */
- @Override
- public IDeviceObject updateDevice(IDevice device) {
- return addDevice(device);
- }
+ /**
+ * *
+ * Finalize/close function. After you use this class, please call this
+ * method. It will close the DB connection.
+ */
+ @Override
+ public void close() {
+ ope.close();
+ }
- /***
- * This function is for removing the Device from the DB.
- * @param device The device you want to delete from the DB.
- */
- @Override
- public void removeDevice(IDevice device) {
- IDeviceObject dev;
- try {
- if ((dev = ope.searchDevice(device.getMACAddressString())) != null) {
- ope.removeDevice(dev);
- ope.commit();
- log.error("DeviceStorage:removeDevice mac:{} done", device.getMACAddressString());
- }
- } catch (Exception e) {
- ope.rollback();
- log.error("DeviceStorage:removeDevice mac:{} failed", device.getMACAddressString());
- }
- }
+ /**
+ * *
+ * Finalize/close function. After you use this class, please call this
+ * method. It will close the DB connection. This is for Java garbage
+ * collection.
+ */
+ @Override
+ public void finalize() {
+ close();
+ }
- /***
- * This function is for getting the Device from the DB by Mac address of the device.
- * @param mac The device mac address you want to get from the DB.
- * @return IDeviceObject you want to get.
- */
- @Override
- public IDeviceObject getDeviceByMac(String mac) {
- return ope.searchDevice(mac);
- }
-
- /***
- * This function is for getting the Device from the DB by IP address of the device.
- * @param ip The device ip address you want to get from the DB.
- * @return IDeviceObject you want to get.
- */
- @Override
- public IDeviceObject getDeviceByIP(String ip) {
- try
- {
- for(IDeviceObject dev : ope.getDevices()){
- String ips;
- if((ips = dev.getIPAddress()) != null){
- String nw_addr_wob = ips.replace("[", "").replace("]", "");
- ArrayList<String> iplists = Lists.newArrayList(nw_addr_wob.split(","));
- if(iplists.contains(ip)){
- return dev;
- }
- }
- }
- return null;
- }
- catch (Exception e)
- {
- log.error("DeviceStorage:getDeviceByIP:{} failed");
- return null;
- }
- }
-
- /***
- * This function is for changing the Device attachment point.
- * @param device The device you want change the attachment point
- */
- @Override
- public void changeDeviceAttachments(IDevice device) {
- IDeviceObject obj = null;
- try {
+ /**
+ * *
+ * This function is for adding the device into the DB.
+ *
+ * @param device The device you want to add into the DB.
+ * @return IDeviceObject which was added in the DB.
+ */
+ @Override
+ public IDeviceObject addDevice(IDevice device) {
+ IDeviceObject obj = null;
+ try {
if ((obj = ope.searchDevice(device.getMACAddressString())) != null) {
- log.debug("Changing device ports {}: found existing device",device.getMACAddressString());
+ log.debug("Adding device {}: found existing device", device.getMACAddressString());
+ } else {
+ obj = ope.newDevice();
+ log.debug("Adding device {}: creating new device", device.getMACAddressString());
+ }
+ changeDeviceAttachments(device, obj);
+
+ String multiIntString = "";
+ for (Integer intValue : device.getIPv4Addresses()) {
+ if (multiIntString == null || multiIntString.isEmpty()) {
+ multiIntString = IPv4.fromIPv4Address(intValue);
+ multiIntString = "[" + IPv4.fromIPv4Address(intValue);
+ } else {
+ multiIntString += "," + IPv4.fromIPv4Address(intValue);
+ }
+ }
+
+ if (multiIntString.toString() != null && !multiIntString.toString().isEmpty()) {
+ obj.setIPAddress(multiIntString + "]");
+ }
+
+ obj.setMACAddress(device.getMACAddressString());
+ obj.setType("device");
+ obj.setState("ACTIVE");
+ ope.commit();
+
+ log.debug("Adding device {}", device.getMACAddressString());
+ } catch (Exception e) {
+ ope.rollback();
+ log.error(":addDevice mac:{} failed", device.getMACAddressString());
+ obj = null;
+ }
+ return obj;
+ }
+
+ /**
+ * *
+ * This function is for updating the Device properties.
+ *
+ * @param device The device you want to add into the DB.
+ * @return IDeviceObject which was added in the DB.
+ */
+ @Override
+ public IDeviceObject updateDevice(IDevice device) {
+ return addDevice(device);
+ }
+
+ /**
+ * *
+ * This function is for removing the Device from the DB.
+ *
+ * @param device The device you want to delete from the DB.
+ */
+ @Override
+ public void removeDevice(IDevice device) {
+ IDeviceObject dev;
+ try {
+ if ((dev = ope.searchDevice(device.getMACAddressString())) != null) {
+ ope.removeDevice(dev);
+ ope.commit();
+ log.error("DeviceStorage:removeDevice mac:{} done", device.getMACAddressString());
+ }
+ } catch (Exception e) {
+ ope.rollback();
+ log.error("DeviceStorage:removeDevice mac:{} failed", device.getMACAddressString());
+ }
+ }
+
+ /**
+ * *
+ * This function is for getting the Device from the DB by Mac address of the
+ * device.
+ *
+ * @param mac The device mac address you want to get from the DB.
+ * @return IDeviceObject you want to get.
+ */
+ @Override
+ public IDeviceObject getDeviceByMac(String mac) {
+ return ope.searchDevice(mac);
+ }
+
+ /**
+ * *
+ * This function is for getting the Device from the DB by IP address of the
+ * device.
+ *
+ * @param ip The device ip address you want to get from the DB.
+ * @return IDeviceObject you want to get.
+ */
+ @Override
+ public IDeviceObject getDeviceByIP(String ip) {
+ try {
+ for (IDeviceObject dev : ope.getDevices()) {
+ String ips;
+ if ((ips = dev.getIPAddress()) != null) {
+ String nw_addr_wob = ips.replace("[", "").replace("]", "");
+ ArrayList<String> iplists = Lists.newArrayList(nw_addr_wob.split(","));
+ if (iplists.contains(ip)) {
+ return dev;
+ }
+ }
+ }
+ return null;
+ } catch (Exception e) {
+ log.error("DeviceStorage:getDeviceByIP:{} failed");
+ return null;
+ }
+ }
+
+ /**
+ * *
+ * This function is for changing the Device attachment point.
+ *
+ * @param device The device you want change the attachment point
+ */
+ @Override
+ public void changeDeviceAttachments(IDevice device) {
+ IDeviceObject obj = null;
+ try {
+ if ((obj = ope.searchDevice(device.getMACAddressString())) != null) {
+ log.debug("Changing device ports {}: found existing device", device.getMACAddressString());
changeDeviceAttachments(device, obj);
ope.commit();
} else {
- log.debug("failed to search device...now adding {}",device.getMACAddressString());
- addDevice(device);
- }
- } catch (Exception e) {
- ope.rollback();
- log.error(":addDevice mac:{} failed", device.getMACAddressString());
- }
- }
-
- /***
- * This function is for changing the Device attachment point.
- * @param device The new device you want change the attachment point
- * @param obj The old device IDeviceObject that is going to change the attachment point.
- */
- public void changeDeviceAttachments(IDevice device, IDeviceObject obj) {
- SwitchPort[] attachmentPoints = device.getAttachmentPoints();
- List<IPortObject> attachedPorts = Lists.newArrayList(obj.getAttachedPorts());
-
- for (SwitchPort ap : attachmentPoints) {
- //Check weather there is the port
- IPortObject port = ope.searchPort( HexString.toHexString(ap.getSwitchDPID()),
- (short) ap.getPort());
- log.debug("New Switch Port is {},{}", HexString.toHexString(ap.getSwitchDPID()),(short) ap.getPort());
-
- if(port != null){
- if(attachedPorts.contains(port))
- {
- log.debug("This is the port you already attached {}: do nothing",device.getMACAddressString());
- //This port will be remained, so remove from the removed port lists.
- attachedPorts.remove(port);
- } else {
- log.debug("Adding device {}: attaching to port",device.getMACAddressString());
- port.setDevice(obj);
- }
-
- log.debug("port number is {}", port.getNumber().toString());
- log.debug("port desc is {}", port.getDesc());
- }
- }
-
- for (IPortObject port: attachedPorts) {
- log.debug("Detouching the device {}: detouching from port",device.getMACAddressString());
- port.removeDevice(obj);
+ log.debug("failed to search device...now adding {}", device.getMACAddressString());
+ addDevice(device);
+ }
+ } catch (Exception e) {
+ ope.rollback();
+ log.error(":addDevice mac:{} failed", device.getMACAddressString());
}
- }
+ }
- /***
- * This function is for changing the Device IPv4 address.
- * @param device The new device you want change the ipaddress
- */
- @Override
- public void changeDeviceIPv4Address(IDevice device) {
- IDeviceObject obj;
- try {
- if ((obj = ope.searchDevice(device.getMACAddressString())) != null) {
+ /**
+ * *
+ * This function is for changing the Device attachment point.
+ *
+ * @param device The new device you want change the attachment point
+ * @param obj The old device IDeviceObject that is going to change the
+ * attachment point.
+ */
+ public void changeDeviceAttachments(IDevice device, IDeviceObject obj) {
+ SwitchPort[] attachmentPoints = device.getAttachmentPoints();
+ List<IPortObject> attachedPorts = Lists.newArrayList(obj.getAttachedPorts());
- String multiIntString = "";
- for(Integer intValue : device.getIPv4Addresses()){
- if (multiIntString == null || multiIntString.isEmpty()){
- multiIntString = "[" + IPv4.fromIPv4Address(intValue);
- } else {
- multiIntString += "," + IPv4.fromIPv4Address(intValue);
- }
- }
-
- if(multiIntString != null && !multiIntString.isEmpty()){
- obj.setIPAddress(multiIntString + "]");
- }
-
- ope.commit();
- } else {
- log.error(":changeDeviceIPv4Address mac:{} failed", device.getMACAddressString());
- }
- } catch (TitanException e) {
- ope.rollback();
- log.error(":changeDeviceIPv4Address mac:{} failed due to exception {}", device.getMACAddressString(),e);
- }
- }
+ for (SwitchPort ap : attachmentPoints) {
+ //Check weather there is the port
+ IPortObject port = ope.searchPort(HexString.toHexString(ap.getSwitchDPID()),
+ (short) ap.getPort());
+ log.debug("New Switch Port is {},{}", HexString.toHexString(ap.getSwitchDPID()), (short) ap.getPort());
+ if (port != null) {
+ if (attachedPorts.contains(port)) {
+ log.debug("This is the port you already attached {}: do nothing", device.getMACAddressString());
+ //This port will be remained, so remove from the removed port lists.
+ attachedPorts.remove(port);
+ } else {
+ log.debug("Adding device {}: attaching to port", device.getMACAddressString());
+ port.setDevice(obj);
+ }
+
+ log.debug("port number is {}", port.getNumber().toString());
+ log.debug("port desc is {}", port.getDesc());
+ }
+ }
+
+ for (IPortObject port : attachedPorts) {
+ log.debug("Detouching the device {}: detouching from port", device.getMACAddressString());
+ port.removeDevice(obj);
+ }
+ }
+
+ /**
+ * *
+ * This function is for changing the Device IPv4 address.
+ *
+ * @param device The new device you want change the ipaddress
+ */
+ @Override
+ public void changeDeviceIPv4Address(IDevice device) {
+ IDeviceObject obj;
+ try {
+ if ((obj = ope.searchDevice(device.getMACAddressString())) != null) {
+
+ String multiIntString = "";
+ for (Integer intValue : device.getIPv4Addresses()) {
+ if (multiIntString == null || multiIntString.isEmpty()) {
+ multiIntString = "[" + IPv4.fromIPv4Address(intValue);
+ } else {
+ multiIntString += "," + IPv4.fromIPv4Address(intValue);
+ }
+ }
+
+ if (multiIntString != null && !multiIntString.isEmpty()) {
+ obj.setIPAddress(multiIntString + "]");
+ }
+
+ ope.commit();
+ } else {
+ log.error(":changeDeviceIPv4Address mac:{} failed", device.getMACAddressString());
+ }
+ } catch (TitanException e) {
+ ope.rollback();
+ log.error(":changeDeviceIPv4Address mac:{} failed due to exception {}", device.getMACAddressString(), e);
+ }
+ }
}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/core/internal/LinkStorageImpl.java b/src/main/java/net/onrc/onos/ofcontroller/core/internal/LinkStorageImpl.java
index e5f2f58..6516bf7 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/core/internal/LinkStorageImpl.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/core/internal/LinkStorageImpl.java
@@ -4,7 +4,7 @@
import java.util.List;
import net.floodlightcontroller.routing.Link;
-import net.onrc.onos.graph.GraphDBOperation;
+import net.onrc.onos.graph.DBOperation;
import net.onrc.onos.ofcontroller.core.ILinkStorage;
import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IPortObject;
import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject;
@@ -18,330 +18,342 @@
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.pipes.PipeFunction;
import com.tinkerpop.pipes.transform.PathPipe;
+import net.onrc.onos.graph.GraphDBManager;
/**
* This is the class for storing the information of links into CassandraDB
*/
public class LinkStorageImpl implements ILinkStorage {
-
- protected static Logger log = LoggerFactory.getLogger(LinkStorageImpl.class);
- protected GraphDBOperation dbop;
- /**
- * Update a record in the LinkStorage in a way provided by op.
- * @param link Record of a link to be updated.
- * @param op Operation to be done.
- */
- @Override
- public void update(Link link, DM_OPERATION op) {
- update(link, (LinkInfo)null, op);
- }
+ protected static Logger log = LoggerFactory.getLogger(LinkStorageImpl.class);
+ protected DBOperation dbop;
- /**
- * Update multiple records in the LinkStorage in a way provided by op.
- * @param links List of records to be updated.
- * @param op Operation to be done.
- */
- @Override
- public void update(List<Link> links, DM_OPERATION op) {
- for (Link lt: links) {
- update(lt, (LinkInfo)null, op);
- }
- }
+ /**
+ * Update a record in the LinkStorage in a way provided by op.
+ *
+ * @param link Record of a link to be updated.
+ * @param op Operation to be done.
+ */
+ @Override
+ public void update(Link link, DM_OPERATION op) {
+ update(link, (LinkInfo) null, op);
+ }
- /**
- * Update a record of link with meta-information in the LinkStorage in a way provided by op.
- * @param link Record of a link to update.
- * @param linkinfo Meta-information of a link to be updated.
- * @param op Operation to be done.
- */
- @Override
- public void update(Link link, LinkInfo linkinfo, DM_OPERATION op) {
- switch (op) {
- case UPDATE:
- case CREATE:
- case INSERT:
- updateLink(link, linkinfo, op);
- break;
- case DELETE:
- deleteLink(link);
- break;
- }
- }
-
- /**
- * Perform INSERT/CREATE/UPDATE operation to update the LinkStorage.
- * @param lt Record of a link to be updated.
- * @param linkinfo Meta-information of a link to be updated.
- * @param op Operation to be done. (only INSERT/CREATE/UPDATE is acceptable)
- */
- public void updateLink(Link lt, LinkInfo linkinfo, DM_OPERATION op) {
- IPortObject vportSrc = null, vportDst = null;
-
- log.trace("updateLink(): op {} {} {}", new Object[]{op, lt, linkinfo});
-
+ /**
+ * Update multiple records in the LinkStorage in a way provided by op.
+ *
+ * @param links List of records to be updated.
+ * @param op Operation to be done.
+ */
+ @Override
+ public void update(List<Link> links, DM_OPERATION op) {
+ for (Link lt : links) {
+ update(lt, (LinkInfo) null, op);
+ }
+ }
+
+ /**
+ * Update a record of link with meta-information in the LinkStorage in a way
+ * provided by op.
+ *
+ * @param link Record of a link to update.
+ * @param linkinfo Meta-information of a link to be updated.
+ * @param op Operation to be done.
+ */
+ @Override
+ public void update(Link link, LinkInfo linkinfo, DM_OPERATION op) {
+ switch (op) {
+ case UPDATE:
+ case CREATE:
+ case INSERT:
+ updateLink(link, linkinfo, op);
+ break;
+ case DELETE:
+ deleteLink(link);
+ break;
+ }
+ }
+
+ /**
+ * Perform INSERT/CREATE/UPDATE operation to update the LinkStorage.
+ *
+ * @param lt Record of a link to be updated.
+ * @param linkinfo Meta-information of a link to be updated.
+ * @param op Operation to be done. (only INSERT/CREATE/UPDATE is acceptable)
+ */
+ public void updateLink(Link lt, LinkInfo linkinfo, DM_OPERATION op) {
+ IPortObject vportSrc = null, vportDst = null;
+
+ log.trace("updateLink(): op {} {} {}", new Object[]{op, lt, linkinfo});
+
try {
// get source port vertex
- String dpid = HexString.toHexString(lt.getSrc());
- short port = lt.getSrcPort();
- vportSrc = dbop.searchPort(dpid, port);
-
+ String dpid = HexString.toHexString(lt.getSrc());
+ short port = lt.getSrcPort();
+ vportSrc = dbop.searchPort(dpid, port);
+
// get dest port vertex
dpid = HexString.toHexString(lt.getDst());
port = lt.getDstPort();
vportDst = dbop.searchPort(dpid, port);
-
+
if (vportSrc != null && vportDst != null) {
- // check if the link exists
-
- Iterable<IPortObject> currPorts = vportSrc.getLinkedPorts();
- List<IPortObject> currLinks = new ArrayList<IPortObject>();
- for (IPortObject V : currPorts) {
- currLinks.add(V);
- }
+ // check if the link exists
- if (currLinks.contains(vportDst)) {
- // TODO: update linkinfo
- if (op.equals(DM_OPERATION.INSERT) || op.equals(DM_OPERATION.CREATE)) {
- log.debug("addOrUpdateLink(): failed link exists {} {} src {} dst {}",
- new Object[]{op, lt, vportSrc, vportDst});
- }
- } else {
- vportSrc.setLinkPort(vportDst);
+ Iterable<IPortObject> currPorts = vportSrc.getLinkedPorts();
+ List<IPortObject> currLinks = new ArrayList<IPortObject>();
+ for (IPortObject V : currPorts) {
+ currLinks.add(V);
+ }
- dbop.commit();
- log.debug("updateLink(): link added {} {} src {} dst {}", new Object[]{op, lt, vportSrc, vportDst});
- }
+ if (currLinks.contains(vportDst)) {
+ // TODO: update linkinfo
+ if (op.equals(DM_OPERATION.INSERT) || op.equals(DM_OPERATION.CREATE)) {
+ log.debug("addOrUpdateLink(): failed link exists {} {} src {} dst {}",
+ new Object[]{op, lt, vportSrc, vportDst});
+ }
+ } else {
+ vportSrc.setLinkPort(vportDst);
+
+ dbop.commit();
+ log.debug("updateLink(): link added {} {} src {} dst {}", new Object[]{op, lt, vportSrc, vportDst});
+ }
} else {
- log.error("updateLink(): failed invalid vertices {} {} src {} dst {}", new Object[]{op, lt, vportSrc, vportDst});
- dbop.rollback();
+ log.error("updateLink(): failed invalid vertices {} {} src {} dst {}", new Object[]{op, lt, vportSrc, vportDst});
+ dbop.rollback();
}
} catch (TitanException e) {
/*
* retry till we succeed?
*/
- e.printStackTrace();
- log.error("updateLink(): titan exception {} {} {}", new Object[]{op, lt, e.toString()});
+ e.printStackTrace();
+ log.error("updateLink(): titan exception {} {} {}", new Object[]{op, lt, e.toString()});
}
- }
-
- /**
- * Delete multiple records in LinkStorage.
- * @param links List of records to be deleted.
- */
- @Override
- public void deleteLinks(List<Link> links) {
+ }
- for (Link lt : links) {
- deleteLink(lt);
- }
- }
-
- /**
- * Delete a record in the LinkStorage.
- * @param lt Record to be deleted.
- */
- @Override
- public void deleteLink(Link lt) {
- IPortObject vportSrc = null, vportDst = null;
- int count = 0;
-
- log.debug("deleteLink(): {}", lt);
-
+ /**
+ * Delete multiple records in LinkStorage.
+ *
+ * @param links List of records to be deleted.
+ */
+ @Override
+ public void deleteLinks(List<Link> links) {
+
+ for (Link lt : links) {
+ deleteLink(lt);
+ }
+ }
+
+ /**
+ * Delete a record in the LinkStorage.
+ *
+ * @param lt Record to be deleted.
+ */
+ @Override
+ public void deleteLink(Link lt) {
+ IPortObject vportSrc = null, vportDst = null;
+ int count = 0;
+
+ log.debug("deleteLink(): {}", lt);
+
try {
// get source port vertex
- String dpid = HexString.toHexString(lt.getSrc());
- short port = lt.getSrcPort();
- vportSrc = dbop.searchPort(dpid, port);
-
- // get dst port vertex
- dpid = HexString.toHexString(lt.getDst());
- port = lt.getDstPort();
- vportDst = dbop.searchPort(dpid, port);
- // FIXME: This needs to remove all edges
-
- if (vportSrc != null && vportDst != null) {
+ String dpid = HexString.toHexString(lt.getSrc());
+ short port = lt.getSrcPort();
+ vportSrc = dbop.searchPort(dpid, port);
- /* for (Edge e : vportSrc.asVertex().getEdges(Direction.OUT)) {
- log.debug("deleteLink(): {} in {} out {}",
- new Object[]{e.getLabel(), e.getVertex(Direction.IN), e.getVertex(Direction.OUT)});
- if (e.getLabel().equals("link") && e.getVertex(Direction.IN).equals(vportDst)) {
- graph.removeEdge(e);
- count++;
- }
- }*/
- vportSrc.removeLink(vportDst);
- dbop.commit();
- log.debug("deleteLink(): deleted edges src {} dst {}", new Object[]{
- lt, vportSrc, vportDst});
-
+ // get dst port vertex
+ dpid = HexString.toHexString(lt.getDst());
+ port = lt.getDstPort();
+ vportDst = dbop.searchPort(dpid, port);
+ // FIXME: This needs to remove all edges
+
+ if (vportSrc != null && vportDst != null) {
+
+ /* for (Edge e : vportSrc.asVertex().getEdges(Direction.OUT)) {
+ log.debug("deleteLink(): {} in {} out {}",
+ new Object[]{e.getLabel(), e.getVertex(Direction.IN), e.getVertex(Direction.OUT)});
+ if (e.getLabel().equals("link") && e.getVertex(Direction.IN).equals(vportDst)) {
+ graph.removeEdge(e);
+ count++;
+ }
+ }*/
+ vportSrc.removeLink(vportDst);
+ dbop.commit();
+ log.debug("deleteLink(): deleted edges src {} dst {}", new Object[]{
+ lt, vportSrc, vportDst});
+
} else {
- log.error("deleteLink(): failed invalid vertices {} src {} dst {}", new Object[]{lt, vportSrc, vportDst});
- dbop.rollback();
+ log.error("deleteLink(): failed invalid vertices {} src {} dst {}", new Object[]{lt, vportSrc, vportDst});
+ dbop.rollback();
}
-
+
} catch (TitanException e) {
/*
* retry till we succeed?
*/
- log.error("deleteLink(): titan exception {} {}", new Object[]{lt, e.toString()});
- dbop.rollback();
- e.printStackTrace();
+ log.error("deleteLink(): titan exception {} {}", new Object[]{lt, e.toString()});
+ dbop.rollback();
+ e.printStackTrace();
}
- }
+ }
- /**
- * Get list of all links connected to the port specified by given DPID and port number.
- * @param dpid DPID of desired port.
- * @param port Port number of desired port.
- * @return List of links. Empty list if no port was found.
- */
- // TODO: Fix me
- @Override
- public List<Link> getLinks(Long dpid, short port) {
- List<Link> links = new ArrayList<Link>();
-
- IPortObject srcPort = dbop.searchPort(HexString.toHexString(dpid), port);
- ISwitchObject srcSw = srcPort.getSwitch();
-
- if(srcSw != null && srcPort != null) {
- for(IPortObject dstPort : srcPort.getLinkedPorts()) {
- ISwitchObject dstSw = dstPort.getSwitch();
- Link link = new Link(HexString.toLong(srcSw.getDPID()),
- srcPort.getNumber(),
- HexString.toLong(dstSw.getDPID()),
- dstPort.getNumber());
-
- links.add(link);
- }
- }
-
- return links;
- }
-
- /**
- * Initialize the object. Open LinkStorage using given configuration file.
- * @param conf Path (absolute path for now) to configuration file.
- */
- @Override
- public void init(String conf) {
- //TODO extract the DB location from properties
- this.dbop = new GraphDBOperation(conf);
- }
+ /**
+ * Get list of all links connected to the port specified by given DPID and
+ * port number.
+ *
+ * @param dpid DPID of desired port.
+ * @param port Port number of desired port.
+ * @return List of links. Empty list if no port was found.
+ */
+ // TODO: Fix me
+ @Override
+ public List<Link> getLinks(Long dpid, short port) {
+ List<Link> links = new ArrayList<Link>();
- /**
- * Delete records of the links connected to the port specified by given DPID and port number.
- * @param dpid DPID of desired port.
- * @param port Port number of desired port.
- */
- // TODO: Fix me
- @Override
- public void deleteLinksOnPort(Long dpid, short port) {
- List<Link> linksToDelete = getLinks(dpid,port);
-
- for(Link l : linksToDelete) {
- deleteLink(l);
- }
- }
+ IPortObject srcPort = dbop.searchPort(HexString.toHexString(dpid), port);
+ ISwitchObject srcSw = srcPort.getSwitch();
- /**
- * Get list of all links connected to the switch specified by given DPID.
- * @param dpid DPID of desired switch.
- * @return List of links. Empty list if no port was found.
- */
- // TODO: Fix me
- @Override
- public List<Link> getLinks(String dpid) {
- List<Link> links = new ArrayList<Link>();
+ if (srcSw != null && srcPort != null) {
+ for (IPortObject dstPort : srcPort.getLinkedPorts()) {
+ ISwitchObject dstSw = dstPort.getSwitch();
+ Link link = new Link(HexString.toLong(srcSw.getDPID()),
+ srcPort.getNumber(),
+ HexString.toLong(dstSw.getDPID()),
+ dstPort.getNumber());
- ISwitchObject srcSw = dbop.searchSwitch(dpid);
-
- if(srcSw != null) {
- for(IPortObject srcPort : srcSw.getPorts()) {
- for(IPortObject dstPort : srcPort.getLinkedPorts()) {
- ISwitchObject dstSw = dstPort.getSwitch();
- if(dstSw != null) {
- Link link = new Link(HexString.toLong(srcSw.getDPID()),
- srcPort.getNumber(),
- HexString.toLong(dstSw.getDPID()),
- dstPort.getNumber());
- links.add(link);
- }
- }
- }
- }
-
- return links;
- }
+ links.add(link);
+ }
+ }
- /**
- * Get list of all links whose state is ACTIVE.
- * @return List of active links. Empty list if no port was found.
- */
- public List<Link> getActiveLinks() {
- Iterable<ISwitchObject> switches = dbop.getActiveSwitches();
+ return links;
+ }
- List<Link> links = new ArrayList<Link>();
-
- for (ISwitchObject srcSw : switches) {
- for(IPortObject srcPort : srcSw.getPorts()) {
- for(IPortObject dstPort : srcPort.getLinkedPorts()) {
- ISwitchObject dstSw = dstPort.getSwitch();
-
- if(dstSw != null && dstSw.getState().equals("ACTIVE")) {
- links.add(new Link(HexString.toLong(srcSw.getDPID()),
- srcPort.getNumber(),
- HexString.toLong(dstSw.getDPID()),
- dstPort.getNumber()));
- }
- }
- }
- }
-
- return links;
- }
-
- static class ExtractLink implements PipeFunction<PathPipe<Vertex>, Link> {
-
- @Override
- public Link compute(PathPipe<Vertex> pipe ) {
- // TODO Auto-generated method stub
- long s_dpid = 0;
- long d_dpid = 0;
- short s_port = 0;
- short d_port = 0;
- List<Vertex> V = new ArrayList<Vertex>();
- V = pipe.next();
- Vertex src_sw = V.get(0);
- Vertex dest_sw = V.get(3);
- Vertex src_port = V.get(1);
- Vertex dest_port = V.get(2);
- s_dpid = HexString.toLong((String) src_sw.getProperty("dpid"));
- d_dpid = HexString.toLong((String) dest_sw.getProperty("dpid"));
- s_port = (Short) src_port.getProperty("number");
- d_port = (Short) dest_port.getProperty("number");
-
- Link l = new Link(s_dpid,s_port,d_dpid,d_port);
-
- return l;
- }
- }
-
- /**
- * Finalize the object.
- */
- public void finalize() {
- close();
- }
+ /**
+ * Initialize the object. Open LinkStorage using given configuration file.
+ *
+ * @param conf Path (absolute path for now) to configuration file.
+ */
+ @Override
+ public void init(final String dbStore, final String conf) {
+ this.dbop = GraphDBManager.getDBOperation(dbStore, conf);
+ }
- /**
- * Close LinkStorage.
- */
- @Override
- public void close() {
- // TODO Auto-generated method stub
+ /**
+ * Delete records of the links connected to the port specified by given DPID
+ * and port number.
+ *
+ * @param dpid DPID of desired port.
+ * @param port Port number of desired port.
+ */
+ // TODO: Fix me
+ @Override
+ public void deleteLinksOnPort(Long dpid, short port) {
+ List<Link> linksToDelete = getLinks(dpid, port);
+
+ for (Link l : linksToDelete) {
+ deleteLink(l);
+ }
+ }
+
+ /**
+ * Get list of all links connected to the switch specified by given DPID.
+ *
+ * @param dpid DPID of desired switch.
+ * @return List of links. Empty list if no port was found.
+ */
+ // TODO: Fix me
+ @Override
+ public List<Link> getLinks(String dpid) {
+ List<Link> links = new ArrayList<Link>();
+
+ ISwitchObject srcSw = dbop.searchSwitch(dpid);
+
+ if (srcSw != null) {
+ for (IPortObject srcPort : srcSw.getPorts()) {
+ for (IPortObject dstPort : srcPort.getLinkedPorts()) {
+ ISwitchObject dstSw = dstPort.getSwitch();
+ if (dstSw != null) {
+ Link link = new Link(HexString.toLong(srcSw.getDPID()),
+ srcPort.getNumber(),
+ HexString.toLong(dstSw.getDPID()),
+ dstPort.getNumber());
+ links.add(link);
+ }
+ }
+ }
+ }
+
+ return links;
+ }
+
+ /**
+ * Get list of all links whose state is ACTIVE.
+ *
+ * @return List of active links. Empty list if no port was found.
+ */
+ public List<Link> getActiveLinks() {
+ Iterable<ISwitchObject> switches = dbop.getActiveSwitches();
+
+ List<Link> links = new ArrayList<Link>();
+
+ for (ISwitchObject srcSw : switches) {
+ for (IPortObject srcPort : srcSw.getPorts()) {
+ for (IPortObject dstPort : srcPort.getLinkedPorts()) {
+ ISwitchObject dstSw = dstPort.getSwitch();
+
+ if (dstSw != null && dstSw.getState().equals("ACTIVE")) {
+ links.add(new Link(HexString.toLong(srcSw.getDPID()),
+ srcPort.getNumber(),
+ HexString.toLong(dstSw.getDPID()),
+ dstPort.getNumber()));
+ }
+ }
+ }
+ }
+
+ return links;
+ }
+
+ static class ExtractLink implements PipeFunction<PathPipe<Vertex>, Link> {
+
+ @Override
+ public Link compute(PathPipe<Vertex> pipe) {
+ // TODO Auto-generated method stub
+ long s_dpid = 0;
+ long d_dpid = 0;
+ short s_port = 0;
+ short d_port = 0;
+ List<Vertex> V = new ArrayList<Vertex>();
+ V = pipe.next();
+ Vertex src_sw = V.get(0);
+ Vertex dest_sw = V.get(3);
+ Vertex src_port = V.get(1);
+ Vertex dest_port = V.get(2);
+ s_dpid = HexString.toLong((String) src_sw.getProperty("dpid"));
+ d_dpid = HexString.toLong((String) dest_sw.getProperty("dpid"));
+ s_port = (Short) src_port.getProperty("number");
+ d_port = (Short) dest_port.getProperty("number");
+
+ Link l = new Link(s_dpid, s_port, d_dpid, d_port);
+
+ return l;
+ }
+ }
+
+ /**
+ * Finalize the object.
+ */
+ public void finalize() {
+ close();
+ }
+
+ /**
+ * Close LinkStorage.
+ */
+ @Override
+ public void close() {
+ // TODO Auto-generated method stub
// graph.shutdown();
- }
-
-
+ }
}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImpl.java b/src/main/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImpl.java
index b7c97f8..b990157 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImpl.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImpl.java
@@ -1,8 +1,8 @@
package net.onrc.onos.ofcontroller.core.internal;
import net.floodlightcontroller.core.IOFSwitch;
-import net.onrc.onos.graph.GraphDBConnection;
-import net.onrc.onos.graph.GraphDBOperation;
+import net.onrc.onos.graph.DBOperation;
+import net.onrc.onos.graph.GraphDBManager;
import net.onrc.onos.ofcontroller.core.ISwitchStorage;
import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IPortObject;
import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject;
@@ -17,233 +17,250 @@
* This is the class for storing the information of switches into CassandraDB
*/
public class SwitchStorageImpl implements ISwitchStorage {
- protected GraphDBOperation op;
- protected static Logger log = LoggerFactory.getLogger(SwitchStorageImpl.class);
-
- /***
- * Initialize function. Before you use this class, please call this method
- * @param conf configuration file for Cassandra DB
- */
- @Override
- public void init(String conf) {
- GraphDBConnection conn = GraphDBConnection.getInstance(conf);
- op = new GraphDBOperation(conn);
- }
- /***
- * Finalize/close function. After you use this class, please call this method.
- * It will close the DB connection.
- */
- public void finalize() {
- close();
- }
-
- /***
- * Finalize/close function. After you use this class, please call this method.
- * It will close the DB connection. This is for Java garbage collection.
- */
- @Override
- public void close() {
- op.close();
- }
-
- private void setStatus(String dpid, SwitchState state) {
- ISwitchObject sw = op.searchSwitch(dpid);
-
- try {
- if (sw != null) {
- sw.setState(state.toString());
- op.commit();
- log.info("SwitchStorage:setStatus dpid:{} state: {} done", dpid, state);
- }
- } catch(Exception e) {
- e.printStackTrace();
- op.rollback();
- log.info("SwitchStorage:setStatus dpid:{} state: {} failed: switch not found", dpid, state);
- }
- }
+ protected DBOperation op;
+ protected static Logger log = LoggerFactory.getLogger(SwitchStorageImpl.class);
- /***
- * This function is for adding the switch into the DB.
- * @param dpid The switch dpid you want to add into the DB.
- */
- @Override
- public void addSwitch(String dpid) {
-
- log.info("SwitchStorage:addSwitch(): dpid {} ", dpid);
- try {
- ISwitchObject sw = newSwitch(dpid);
- if ( sw == null ) throw new RuntimeException();
+ /**
+ * *
+ * Initialize function. Before you use this class, please call this method
+ *
+ * @param conf configuration file for Cassandra DB
+ */
+ @Override
+ public void init(final String dbStore, final String conf) {
+ op = GraphDBManager.getDBOperation(dbStore, conf);
+ }
+
+ /**
+ * *
+ * Finalize/close function. After you use this class, please call this
+ * method. It will close the DB connection.
+ */
+ public void finalize() {
+ close();
+ }
+
+ /**
+ * *
+ * Finalize/close function. After you use this class, please call this
+ * method. It will close the DB connection. This is for Java garbage
+ * collection.
+ */
+ @Override
+ public void close() {
+ op.close();
+ }
+
+ private void setStatus(String dpid, SwitchState state) {
+ ISwitchObject sw = op.searchSwitch(dpid);
+
+ try {
+ if (sw != null) {
+ sw.setState(state.toString());
+ op.commit();
+ log.info("SwitchStorage:setStatus dpid:{} state: {} done", dpid, state);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ op.rollback();
+ log.info("SwitchStorage:setStatus dpid:{} state: {} failed: switch not found", dpid, state);
+ }
+ }
+
+ /**
+ * *
+ * This function is for adding the switch into the DB.
+ *
+ * @param dpid The switch dpid you want to add into the DB.
+ */
+ @Override
+ public void addSwitch(String dpid) {
+
+ log.info("SwitchStorage:addSwitch(): dpid {} ", dpid);
+ try {
+ ISwitchObject sw = newSwitch(dpid);
+ if (sw == null) {
+ throw new RuntimeException();
+ }
op.commit();
- } catch (Exception e) {
- e.printStackTrace();
- op.rollback();
- log.info("SwitchStorage:addSwitch dpid:{} failed", dpid);
- }
- }
-
- private ISwitchObject newSwitch(String dpid) {
- ISwitchObject sw = op.searchSwitch(dpid);
- if (sw != null) {
- //If existing the switch. set The SW state ACTIVE.
- log.info("SwitchStorage:newSwitch dpid:{} already exists", dpid);
- sw.setState(SwitchState.ACTIVE.toString());
- } else {
- sw = op.newSwitch(dpid);
- if (sw != null) {
- sw.setState(SwitchState.ACTIVE.toString());
- log.info("SwitchStorage:newSwitch dpid:{} added", dpid);
- } else {
- log.error("switchStorage:newSwitch dpid:{} failed -> newSwitch failed", dpid);
- }
- }
- return sw;
- }
-
- /***
- * This function is for updating the switch into the DB.
- * @param dpid The switch dpid you want to update from the DB
- * @param state The state of the switch like ACTIVE, INACTIVE
- * @param dmope The DM_OPERATION of the switch
- */
- @Override
- public void update(String dpid, SwitchState state, DM_OPERATION dmope) {
- log.info("SwitchStorage:update dpid:{} state: {} ", dpid, state);
- switch(dmope) {
- case UPDATE:
- case INSERT:
- case CREATE:
+ } catch (Exception e) {
+ e.printStackTrace();
+ op.rollback();
+ log.info("SwitchStorage:addSwitch dpid:{} failed", dpid);
+ }
+ }
+
+ private ISwitchObject newSwitch(String dpid) {
+ ISwitchObject sw = op.searchSwitch(dpid);
+ if (sw != null) {
+ //If existing the switch. set The SW state ACTIVE.
+ log.info("SwitchStorage:newSwitch dpid:{} already exists", dpid);
+ sw.setState(SwitchState.ACTIVE.toString());
+ } else {
+ sw = op.newSwitch(dpid);
+ if (sw != null) {
+ sw.setState(SwitchState.ACTIVE.toString());
+ log.info("SwitchStorage:newSwitch dpid:{} added", dpid);
+ } else {
+ log.error("switchStorage:newSwitch dpid:{} failed -> newSwitch failed", dpid);
+ }
+ }
+ return sw;
+ }
+
+ /**
+ * *
+ * This function is for updating the switch into the DB.
+ *
+ * @param dpid The switch dpid you want to update from the DB
+ * @param state The state of the switch like ACTIVE, INACTIVE
+ * @param dmope The DM_OPERATION of the switch
+ */
+ @Override
+ public void update(String dpid, SwitchState state, DM_OPERATION dmope) {
+ log.info("SwitchStorage:update dpid:{} state: {} ", dpid, state);
+ switch (dmope) {
+ case UPDATE:
+ case INSERT:
+ case CREATE:
addSwitch(dpid);
if (state != SwitchState.ACTIVE) {
- setStatus(dpid, state);
+ setStatus(dpid, state);
}
break;
- case DELETE:
+ case DELETE:
deleteSwitch(dpid);
break;
- default:
+ default:
}
- }
+ }
- /***
- * This function is for deleting the switch into the DB.
- * @param dpid The switch dpid you want to delete from the DB.
- */
- @Override
- public void deleteSwitch(String dpid) {
- try {
- ISwitchObject sw = op.searchSwitch(dpid);
- if (sw != null) {
- op.removeSwitch(sw);
- op.commit();
- log.info("SwitchStorage:DeleteSwitch dpid:{} done", dpid);
+ /**
+ * *
+ * This function is for deleting the switch into the DB.
+ *
+ * @param dpid The switch dpid you want to delete from the DB.
+ */
+ @Override
+ public void deleteSwitch(String dpid) {
+ try {
+ ISwitchObject sw = op.searchSwitch(dpid);
+ if (sw != null) {
+ op.removeSwitch(sw);
+ op.commit();
+ log.info("SwitchStorage:DeleteSwitch dpid:{} done", dpid);
}
- } catch (Exception e) {
- e.printStackTrace();
- op.rollback();
- log.error("SwitchStorage:deleteSwitch {} failed", dpid);
- }
+ } catch (Exception e) {
+ e.printStackTrace();
+ op.rollback();
+ log.error("SwitchStorage:deleteSwitch {} failed", dpid);
+ }
- }
+ }
- /***
- * This function is for adding the switch port into the DB.
- * @param dpid The switch dpid that has the port.
- * @param port The port you want to add the switch.
- */
- @Override
- public void addPort(String dpid, OFPhysicalPort port) {
-
- if(((OFPortConfig.OFPPC_PORT_DOWN.getValue() & port.getConfig()) > 0) ||
- ((OFPortState.OFPPS_LINK_DOWN.getValue() & port.getState()) > 0)) {
- deletePort(dpid, port.getPortNumber());
- return;
- }
+ /**
+ * *
+ * This function is for adding the switch port into the DB.
+ *
+ * @param dpid The switch dpid that has the port.
+ * @param port The port you want to add the switch.
+ */
+ @Override
+ public void addPort(String dpid, OFPhysicalPort port) {
- try {
- ISwitchObject sw = op.searchSwitch(dpid);
+ if (((OFPortConfig.OFPPC_PORT_DOWN.getValue() & port.getConfig()) > 0)
+ || ((OFPortState.OFPPS_LINK_DOWN.getValue() & port.getState()) > 0)) {
+ deletePort(dpid, port.getPortNumber());
+ return;
+ }
+
+ try {
+ ISwitchObject sw = op.searchSwitch(dpid);
if (sw != null) {
- IPortObject p = op.searchPort(dpid, port.getPortNumber());
- log.info("SwitchStorage:addPort dpid:{} port:{}", dpid, port.getPortNumber());
- if (p != null) {
- log.error("SwitchStorage:addPort dpid:{} port:{} exists setting as ACTIVE", dpid, port.getPortNumber());
- p.setState("ACTIVE");
- p.setPortState(port.getState());
- p.setDesc(port.getName());
- op.commit();
- } else {
- p = op.newPort(dpid, port.getPortNumber());
- p.setState("ACTIVE");
- p.setPortState(port.getState());
- p.setDesc(port.getName());
- sw.addPort(p);
- op.commit();
- }
- } else {
- log.error("SwitchStorage:addPort dpid:{} port:{} : failed switch does not exist", dpid, port.getPortNumber());
- }
- } catch (Exception e) {
- e.printStackTrace();
- op.rollback();
- log.error("SwitchStorage:addPort dpid:{} port:{} failed", dpid, port.getPortNumber());
- }
-
- }
-
- /***
- * This function is for deleting the switch port from the DB.
- * @param dpid The switch dpid that has the port.
- * @param port The port you want to delete the switch.
- */
- @Override
- public void deletePort(String dpid, short port) {
- try {
- ISwitchObject sw = op.searchSwitch(dpid);
-
- if (sw != null) {
- IPortObject p = op.searchPort(dpid, port);
+ IPortObject p = op.searchPort(dpid, port.getPortNumber());
+ log.info("SwitchStorage:addPort dpid:{} port:{}", dpid, port.getPortNumber());
if (p != null) {
- log.info("SwitchStorage:deletePort dpid:{} port:{} found and set INACTIVE", dpid, port);
- p.setState("INACTIVE");
- op.commit();
- }
+ log.error("SwitchStorage:addPort dpid:{} port:{} exists setting as ACTIVE", dpid, port.getPortNumber());
+ p.setState("ACTIVE");
+ p.setPortState(port.getState());
+ p.setDesc(port.getName());
+ op.commit();
+ } else {
+ p = op.newPort(dpid, port.getPortNumber());
+ p.setState("ACTIVE");
+ p.setPortState(port.getState());
+ p.setDesc(port.getName());
+ sw.addPort(p);
+ op.commit();
+ }
+ } else {
+ log.error("SwitchStorage:addPort dpid:{} port:{} : failed switch does not exist", dpid, port.getPortNumber());
}
- } catch (Exception e) {
- e.printStackTrace();
- op.rollback();
- log.info("SwitchStorage:deletePort dpid:{} port:{} failed", dpid, port);
- }
- }
+ } catch (Exception e) {
+ e.printStackTrace();
+ op.rollback();
+ log.error("SwitchStorage:addPort dpid:{} port:{} failed", dpid, port.getPortNumber());
+ }
- @Override
- public void addSwitch(IOFSwitch sw) {
- // TODO Auto-generated method stub
- String dpid = sw.getStringId();
- log.info("SwitchStorage:addSwitch(): dpid {} ", dpid);
- try {
- ISwitchObject switchObject = newSwitch(dpid);
- for (OFPhysicalPort port: sw.getPorts()) {
- IPortObject p = op.searchPort(dpid, port.getPortNumber());
- if (p != null) {
- log.error("SwitchStorage:addPort dpid:{} port:{} exists", dpid, port.getPortNumber());
- p.setState("ACTIVE");
- p.setPortState(port.getState());
- p.setDesc(port.getName());
- } else {
- p = op.newPort(dpid, port.getPortNumber());
- p.setState("ACTIVE");
- p.setPortState(port.getState());
- p.setDesc(port.getName());
- switchObject.addPort(p);
- }
- }
+ }
+
+ /**
+ * *
+ * This function is for deleting the switch port from the DB.
+ *
+ * @param dpid The switch dpid that has the port.
+ * @param port The port you want to delete the switch.
+ */
+ @Override
+ public void deletePort(String dpid, short port) {
+ try {
+ ISwitchObject sw = op.searchSwitch(dpid);
+
+ if (sw != null) {
+ IPortObject p = op.searchPort(dpid, port);
+ if (p != null) {
+ log.info("SwitchStorage:deletePort dpid:{} port:{} found and set INACTIVE", dpid, port);
+ p.setState("INACTIVE");
+ op.commit();
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ op.rollback();
+ log.info("SwitchStorage:deletePort dpid:{} port:{} failed", dpid, port);
+ }
+ }
+
+ @Override
+ public void addSwitch(IOFSwitch sw) {
+ // TODO Auto-generated method stub
+ String dpid = sw.getStringId();
+ log.info("SwitchStorage:addSwitch(): dpid {} ", dpid);
+ try {
+ ISwitchObject switchObject = newSwitch(dpid);
+ for (OFPhysicalPort port : sw.getPorts()) {
+ IPortObject p = op.searchPort(dpid, port.getPortNumber());
+ if (p != null) {
+ log.error("SwitchStorage:addPort dpid:{} port:{} exists", dpid, port.getPortNumber());
+ p.setState("ACTIVE");
+ p.setPortState(port.getState());
+ p.setDesc(port.getName());
+ } else {
+ p = op.newPort(dpid, port.getPortNumber());
+ p.setState("ACTIVE");
+ p.setPortState(port.getState());
+ p.setDesc(port.getName());
+ switchObject.addPort(p);
+ }
+ }
op.commit();
- } catch (Exception e) {
- e.printStackTrace();
- op.rollback();
- log.info("SwitchStorage:addSwitch dpid:{} failed", dpid);
- }
-
- }
+ } catch (Exception e) {
+ e.printStackTrace();
+ op.rollback();
+ log.info("SwitchStorage:addSwitch dpid:{} failed", dpid);
+ }
+
+ }
}
\ No newline at end of file
diff --git a/src/main/java/net/onrc/onos/ofcontroller/floodlightlistener/NetworkGraphPublisher.java b/src/main/java/net/onrc/onos/ofcontroller/floodlightlistener/NetworkGraphPublisher.java
index e0ac4e1..5c372fb 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/floodlightlistener/NetworkGraphPublisher.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/floodlightlistener/NetworkGraphPublisher.java
@@ -24,8 +24,9 @@
import net.floodlightcontroller.devicemanager.IDeviceService;
import net.floodlightcontroller.routing.Link;
import net.floodlightcontroller.threadpool.IThreadPoolService;
-import net.onrc.onos.graph.GraphDBConnection;
-import net.onrc.onos.graph.GraphDBOperation;
+import net.onrc.onos.graph.DBOperation;
+import net.onrc.onos.graph.DBConnection;
+import net.onrc.onos.graph.GraphDBManager;
import net.onrc.onos.graph.IDBConnection;
import net.onrc.onos.graph.LocalTopologyEventListener;
import net.onrc.onos.ofcontroller.core.IDeviceStorage;
@@ -53,9 +54,10 @@
protected static Logger log;
protected IDeviceService deviceService;
protected IControllerRegistryService registryService;
- protected GraphDBOperation op;
+ protected DBOperation op;
protected static final String DBConfigFile = "dbconf";
+ protected static final String GraphDBStore = "graph_db_store";
protected static final String CleanupEnabled = "EnableCleanup";
protected IThreadPoolService threadPool;
protected IFloodlightProviderService floodlightProvider;
@@ -252,7 +254,8 @@
// TODO Auto-generated method stub
Map<String, String> configMap = context.getConfigParams(this);
String conf = configMap.get(DBConfigFile);
- op = new GraphDBOperation(conf);
+ String dbStore = configMap.get(GraphDBStore);
+ op = GraphDBManager.getDBOperation(dbStore, conf);
log = LoggerFactory.getLogger(NetworkGraphPublisher.class);
floodlightProvider =
@@ -263,13 +266,13 @@
registryService = context.getServiceImpl(IControllerRegistryService.class);
devStore = new DeviceStorageImpl();
- devStore.init(conf);
+ devStore.init(dbStore, conf);
swStore = new SwitchStorageImpl();
- swStore.init(conf);
+ swStore.init(dbStore, conf);
linkStore = new LinkStorageImpl();
- linkStore.init(conf);
+ linkStore.init(dbStore, conf);
log.debug("Initializing NetworkGraphPublisher module with {}", conf);
@@ -287,7 +290,7 @@
log.debug("Adding EventListener");
IDBConnection conn = op.getDBConnection();
- conn.addEventListener(new LocalTopologyEventListener((GraphDBConnection) conn));
+ conn.addEventListener(new LocalTopologyEventListener((DBConnection) conn));
// Setup the Cleanup task.
if (cleanupNeeded == null || !cleanupNeeded.equals("False")) {
ScheduledExecutorService ses = threadPool.getScheduledExecutor();
diff --git a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowManager.java b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowManager.java
index ce9941e..cd6f5eb 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowManager.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowManager.java
@@ -27,7 +27,8 @@
import net.floodlightcontroller.restserver.IRestApiService;
import net.floodlightcontroller.util.MACAddress;
import net.floodlightcontroller.util.OFMessageDamper;
-import net.onrc.onos.graph.GraphDBOperation;
+import net.onrc.onos.graph.DBOperation;
+import net.onrc.onos.graph.GraphDBManager;
import net.onrc.onos.ofcontroller.core.INetMapStorage;
import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowEntry;
import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowPath;
@@ -69,7 +70,7 @@
*/
public class FlowManager implements IFloodlightModule, IFlowService, INetMapStorage {
- protected GraphDBOperation op;
+ protected DBOperation op;
protected IRestApiService restApi;
protected volatile IFloodlightProviderService floodlightProvider;
@@ -431,9 +432,9 @@
* @param conf the Graph Database configuration string.
*/
@Override
- public void init(String conf) {
- op = new GraphDBOperation(conf);
- topoRouteService = new TopoRouteService(conf);
+ public void init(final String dbStore, final String conf) {
+ op = GraphDBManager.getDBOperation(dbStore, conf);
+ topoRouteService = new TopoRouteService(dbStore, conf);
}
/**
@@ -512,7 +513,7 @@
// TODO: An ugly hack!
String conf = "/tmp/cassandra.titan";
- this.init(conf);
+ this.init("titan", conf);
mapReaderScheduler = Executors.newScheduledThreadPool(1);
shortestPathReconcileScheduler = Executors.newScheduledThreadPool(1);
diff --git a/src/main/java/net/onrc/onos/ofcontroller/routing/TopoRouteService.java b/src/main/java/net/onrc/onos/ofcontroller/routing/TopoRouteService.java
index 21381d9..0aa5f2e 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/routing/TopoRouteService.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/routing/TopoRouteService.java
@@ -9,7 +9,7 @@
import java.util.Queue;
import java.util.Set;
-import net.onrc.onos.graph.GraphDBOperation;
+import net.onrc.onos.graph.DBOperation;
import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject;
import net.onrc.onos.ofcontroller.core.INetMapTopologyService.ITopoRouteService;
import net.onrc.onos.ofcontroller.core.ISwitchStorage.SwitchState;
@@ -25,6 +25,7 @@
import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Vertex;
+import net.onrc.onos.graph.GraphDBManager;
/**
@@ -48,7 +49,7 @@
* @param me the node this link originates from.
* @param the neighbor node on the other side of the link.
* @param myPort local port number for the link.
- * @param neighborPort neighrobr port number for the link.
+ * @param neighborPort neighbor port number for the link.
*/
public Link(Node me, Node neighbor, short myPort, short neighborPort) {
this.me = me;
@@ -95,7 +96,7 @@
private static Logger log =
LoggerFactory.getLogger(TopoRouteService.class);
- protected GraphDBOperation op;
+ protected DBOperation op;
/**
@@ -110,8 +111,8 @@
* @param config the database configuration file to use for
* the initialization.
*/
- public TopoRouteService(String config) {
- this.init(config);
+ public TopoRouteService(final String dbStore, final String config) {
+ this.init(dbStore, config);
}
/**
@@ -120,9 +121,9 @@
* @param config the database configuration file to use for
* the initialization.
*/
- public void init(String config) {
+ public void init(final String dbStore, final String config) {
try {
- op = new GraphDBOperation(config);
+ op = GraphDBManager.getDBOperation(dbStore, config);
} catch (Exception e) {
log.error(e.getMessage());
}
@@ -141,7 +142,7 @@
* @param init_op the database operation handler to use for the
* initialization.
*/
- public void setDbOperationHandler(GraphDBOperation init_op) {
+ public void setDbOperationHandler(DBOperation init_op) {
op = init_op;
}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/topology/web/RouteResource.java b/src/main/java/net/onrc/onos/ofcontroller/topology/web/RouteResource.java
index 659609d..ee7ffce 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/topology/web/RouteResource.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/topology/web/RouteResource.java
@@ -18,7 +18,7 @@
@Get("json")
public DataPath retrieve() {
- ITopoRouteService topoRouteService = new TopoRouteService("");
+ ITopoRouteService topoRouteService = new TopoRouteService("titan", "");
if (topoRouteService == null) {
log.debug("Topology Route Service not found");
return null;
diff --git a/src/test/java/net/onrc/onos/ofcontroller/core/internal/LinkStorageImplTest.java b/src/test/java/net/onrc/onos/ofcontroller/core/internal/LinkStorageImplTest.java
index 9b1c4d6..08b8176 100644
--- a/src/test/java/net/onrc/onos/ofcontroller/core/internal/LinkStorageImplTest.java
+++ b/src/test/java/net/onrc/onos/ofcontroller/core/internal/LinkStorageImplTest.java
@@ -120,7 +120,7 @@
mockToPortInfoMap = new HashMap<IPortObject,PortInfo>();
linkStorage = new LinkStorageImpl();
- linkStorage.init("/dummy/path/to/conf");
+ linkStorage.init("dummyStore", "/dummy/path/to/conf");
initLinks();
}
diff --git a/src/test/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImplTest.java b/src/test/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImplTest.java
index f276680..7d26f2f 100644
--- a/src/test/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImplTest.java
+++ b/src/test/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImplTest.java
@@ -33,6 +33,7 @@
protected static org.slf4j.Logger log = LoggerFactory.getLogger(SwitchStorageImpl.class);
String conf;
+ String dbStore;
private GraphDBConnection mockConn = null;
private GraphDBOperation mockOpe = null;
private GraphDBOperation realOpe = null;
@@ -43,6 +44,7 @@
public void setUp() throws Exception {
swSt = new SwitchStorageImpl();
+ dbStore = "dummyStore";
conf = "/dummy/path/to/db";
// Make mock cassandra DB
@@ -96,7 +98,7 @@
mockOpe.close();
replay(mockOpe);
- swSt.init(conf);
+ swSt.init(dbStore, conf);
swSt.addSwitch(dpid);
}
@@ -129,7 +131,7 @@
mockOpe.close();
replay(mockOpe);
- swSt.init(conf);
+ swSt.init(dbStore, conf);
swSt.addSwitch(dpid);
swSt.addSwitch(dpid);
}
@@ -153,7 +155,7 @@
mockOpe.close();
replay(mockOpe);
- swSt.init(conf);
+ swSt.init(dbStore, conf);
swSt.addSwitch(dpid);
}
@@ -185,7 +187,7 @@
mockOpe.close();
replay(mockOpe);
- swSt.init(conf);
+ swSt.init(dbStore, conf);
swSt.addSwitch(dpid);
}
@@ -220,7 +222,7 @@
mockOpe.close();
replay(mockOpe);
- swSt.init(conf);
+ swSt.init(dbStore, conf);
swSt.update(dpid, stateINACTIVE, opUPDATE);
}
@@ -255,7 +257,7 @@
mockOpe.close();
replay(mockOpe);
- swSt.init(conf);
+ swSt.init(dbStore, conf);
swSt.update(dpid, stateINACTIVE, opCREATE);
}
@@ -290,7 +292,7 @@
mockOpe.close();
replay(mockOpe);
- swSt.init(conf);
+ swSt.init(dbStore, conf);
swSt.update(dpid, stateINACTIVE, opINSERT);
}
@@ -325,7 +327,7 @@
mockOpe.close();
replay(mockOpe);
- swSt.init(conf);
+ swSt.init(dbStore, conf);
swSt.addSwitch(dpid);
swSt.update(dpid, stateACTIVE, opDELETE);
}
@@ -359,7 +361,7 @@
mockOpe.close();
replay(mockOpe);
- swSt.init(conf);
+ swSt.init(dbStore, conf);
swSt.addSwitch(dpid);
swSt.deleteSwitch(dpid);
@@ -399,7 +401,7 @@
mockOpe.close();
replay(mockOpe);
- swSt.init(conf);
+ swSt.init(dbStore, conf);
swSt.addSwitch(dpid);
swSt.deleteSwitch(dpid);
}
@@ -450,7 +452,7 @@
mockOpe.close();
replay(mockOpe);
- swSt.init(conf);
+ swSt.init(dbStore, conf);
swSt.addSwitch(dpid);
swSt.addPort(dpid, portToAdd);
}
@@ -502,7 +504,7 @@
mockOpe.close();
replay(mockOpe);
- swSt.init(conf);
+ swSt.init(dbStore, conf);
swSt.addSwitch(dpid);
swSt.addPort(dpid, portToAdd);
}
@@ -542,7 +544,7 @@
mockOpe.close();
replay(mockOpe);
- swSt.init(conf);
+ swSt.init(dbStore, conf);
swSt.addPort(dpid, portToAdd);
}
@@ -592,7 +594,7 @@
mockOpe.close();
replay(mockOpe);
- swSt.init(conf);
+ swSt.init(dbStore, conf);
swSt.addSwitch(dpid);
swSt.addPort(dpid, portToAdd);
}
@@ -645,7 +647,7 @@
mockOpe.close();
replay(mockOpe);
- swSt.init(conf);
+ swSt.init(dbStore, conf);
swSt.addSwitch(dpid);
swSt.addPort(dpid, portToAdd);
}
@@ -705,7 +707,7 @@
mockOpe.close();
replay(mockOpe);
- swSt.init(conf);
+ swSt.init(dbStore, conf);
swSt.addSwitch(dpid);
swSt.addPort(dpid, portToAdd);
swSt.deletePort(dpid, portNumber);
@@ -766,7 +768,7 @@
mockOpe.close();
replay(mockOpe);
- swSt.init(conf);
+ swSt.init(dbStore, conf);
swSt.addSwitch(dpid);
swSt.addPort(dpid, portToAdd);
swSt.deletePort(dpid, portNumber);
diff --git a/src/test/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImplTestBB.java b/src/test/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImplTestBB.java
index 19ac709..1a006ef 100644
--- a/src/test/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImplTestBB.java
+++ b/src/test/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImplTestBB.java
@@ -7,7 +7,6 @@
import net.onrc.onos.graph.GraphDBOperation;
import net.onrc.onos.ofcontroller.core.ISwitchStorage;
import net.onrc.onos.ofcontroller.core.ISwitchStorage.SwitchState;
-import net.onrc.onos.ofcontroller.core.internal.SwitchStorageImpl;
import net.onrc.onos.ofcontroller.core.INetMapStorage;
import net.onrc.onos.ofcontroller.core.INetMapStorage.DM_OPERATION;
import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IPortObject;
@@ -35,6 +34,7 @@
protected static org.slf4j.Logger log = LoggerFactory.getLogger(SwitchStorageImpl.class);
String conf;
+ String dbStore;
private GraphDBConnection conn = null;
private GraphDBOperation ope = null;
private TitanGraph titanGraph = null;
@@ -45,6 +45,7 @@
swSt = new SwitchStorageImpl();
conf = "/dummy/path/to/db";
+ dbStore ="dummyStore";
// Make mock cassandra DB
// Replace TitanFactory.open() to return mock DB
@@ -57,7 +58,7 @@
conn = GraphDBConnection.getInstance(conf);
ope = new GraphDBOperation(conn);
- swSt.init(conf);
+ swSt.init(dbStore, conf);
}
@After
diff --git a/src/test/java/net/onrc/onos/ofcontroller/core/internal/TestableLinkStorageImpl.java b/src/test/java/net/onrc/onos/ofcontroller/core/internal/TestableLinkStorageImpl.java
index 2f90d48..a09970b 100644
--- a/src/test/java/net/onrc/onos/ofcontroller/core/internal/TestableLinkStorageImpl.java
+++ b/src/test/java/net/onrc/onos/ofcontroller/core/internal/TestableLinkStorageImpl.java
@@ -2,7 +2,6 @@
import java.util.Set;
-import net.onrc.onos.ofcontroller.core.internal.LinkStorageImpl;
import com.thinkaurelius.titan.core.TitanGraph;
import com.tinkerpop.blueprints.TransactionalGraph.Conclusion;
@@ -26,7 +25,7 @@
}
@Override
- public void init(String conf){
+ public void init(final String dbStore, final String conf){
Set<String> s = graph.getIndexedKeys(Vertex.class);
if (!s.contains("dpid")) {
graph.createKeyIndex("dpid", Vertex.class);
diff --git a/src/test/java/net/onrc/onos/ofcontroller/core/internal/TestableSwitchStorageImpl.java b/src/test/java/net/onrc/onos/ofcontroller/core/internal/TestableSwitchStorageImpl.java
index e0b34e1..82d1faf 100644
--- a/src/test/java/net/onrc/onos/ofcontroller/core/internal/TestableSwitchStorageImpl.java
+++ b/src/test/java/net/onrc/onos/ofcontroller/core/internal/TestableSwitchStorageImpl.java
@@ -18,9 +18,9 @@
}
@Override
- public void init(String conf){
+ public void init(final String dbStore, final String conf){
- super.init(conf);
+ super.init(dbStore, conf);
}
}
diff --git a/src/test/java/net/onrc/onos/ofcontroller/devicemanager/internal/DeviceStorageImplTest.java b/src/test/java/net/onrc/onos/ofcontroller/devicemanager/internal/DeviceStorageImplTest.java
index de8be4e..02231ba 100644
--- a/src/test/java/net/onrc/onos/ofcontroller/devicemanager/internal/DeviceStorageImplTest.java
+++ b/src/test/java/net/onrc/onos/ofcontroller/devicemanager/internal/DeviceStorageImplTest.java
@@ -43,6 +43,7 @@
protected static Logger log = LoggerFactory.getLogger(SwitchStorageImpl.class);
String conf;
+ String dbStore;
DeviceStorageImpl deviceImpl;
private GraphDBConnection mockConn;
private GraphDBOperation mockOpe;
@@ -51,6 +52,7 @@
public void setUp() throws Exception {
deviceImpl = new DeviceStorageImpl();
conf = "/dummy/path/to/db";
+ dbStore = "dummyStore";
PowerMock.mockStatic(GraphDBConnection.class);
mockConn = createMock(GraphDBConnection.class);
@@ -155,7 +157,7 @@
mockOpe.commit();
replay(mockOpe);
- deviceImpl.init(conf);
+ deviceImpl.init(dbStore, conf);
//Add the device
IDeviceObject obj = deviceImpl.addDevice(mockDev);
@@ -233,7 +235,7 @@
mockOpe.commit();
replay(mockOpe);
- deviceImpl.init(conf);
+ deviceImpl.init(dbStore, conf);
//Add the device
IDeviceObject obj = deviceImpl.addDevice(mockDev);
@@ -325,7 +327,7 @@
mockOpe.commit();
replay(mockOpe);
- deviceImpl.init(conf);
+ deviceImpl.init(dbStore, conf);
IDeviceObject obj = deviceImpl.addDevice(mockDev);
assertNotNull(obj);
@@ -414,7 +416,7 @@
expect(mockOpe.searchDevice(macAddr)).andReturn(null);
replay(mockOpe);
- deviceImpl.init(conf);
+ deviceImpl.init(dbStore, conf);
IDeviceObject obj = deviceImpl.addDevice(mockDev);
assertNotNull(obj);
@@ -498,7 +500,7 @@
expect(mockOpe.searchDevice(macAddr)).andReturn(mockIDev);
replay(mockOpe);
- deviceImpl.init(conf);
+ deviceImpl.init(dbStore, conf);
IDeviceObject obj = deviceImpl.addDevice(mockDev);
assertNotNull(obj);
@@ -587,7 +589,7 @@
expect(mockOpe.getDevices()).andReturn(deviceList).times(2);
replay(mockOpe);
- deviceImpl.init(conf);
+ deviceImpl.init(dbStore, conf);
IDeviceObject obj = deviceImpl.addDevice(mockDev);
assertNotNull(obj);
@@ -724,7 +726,7 @@
mockOpe.commit();
replay(mockOpe);
- deviceImpl.init(conf);
+ deviceImpl.init(dbStore, conf);
IDeviceObject obj = deviceImpl.addDevice(mockDev);
assertNotNull(obj);
@@ -818,7 +820,7 @@
mockOpe.commit();
replay(mockOpe);
- deviceImpl.init(conf);
+ deviceImpl.init(dbStore, conf);
IDeviceObject obj = deviceImpl.addDevice(mockDev);
assertNotNull(obj);
diff --git a/src/test/java/net/onrc/onos/ofcontroller/devicemanager/internal/DeviceStorageImplTestBB.java b/src/test/java/net/onrc/onos/ofcontroller/devicemanager/internal/DeviceStorageImplTestBB.java
index e4053f4..20c3926 100644
--- a/src/test/java/net/onrc/onos/ofcontroller/devicemanager/internal/DeviceStorageImplTestBB.java
+++ b/src/test/java/net/onrc/onos/ofcontroller/devicemanager/internal/DeviceStorageImplTestBB.java
@@ -40,6 +40,7 @@
protected static org.slf4j.Logger log = LoggerFactory.getLogger(SwitchStorageImpl.class);
String conf;
+ String dbStore;
private GraphDBConnection conn = null;
private GraphDBOperation ope = null;
private TitanGraph titanGraph = null;
@@ -50,6 +51,7 @@
deviceImpl = new DeviceStorageImpl();
conf = "/dummy/path/to/db";
+ dbStore = "dummyStore";
// Make mock cassandra DB
// Replace TitanFactory.open() to return mock DB
@@ -62,7 +64,7 @@
conn = GraphDBConnection.getInstance(conf);
ope = new GraphDBOperation(conn);
- deviceImpl.init(conf);
+ deviceImpl.init(dbStore, conf);
}
@After
diff --git a/src/test/java/net/onrc/onos/ofcontroller/flowmanager/FlowManagerTest.java b/src/test/java/net/onrc/onos/ofcontroller/flowmanager/FlowManagerTest.java
index 83a5fab..e168977 100644
--- a/src/test/java/net/onrc/onos/ofcontroller/flowmanager/FlowManagerTest.java
+++ b/src/test/java/net/onrc/onos/ofcontroller/flowmanager/FlowManagerTest.java
@@ -594,7 +594,7 @@
// start the test
replayAll();
- fm.init("/dummy/path");
+ fm.init("dummy_store", "/dummy/path");
// verify the test
verifyAll();
diff --git a/src/test/java/net/onrc/onos/ofcontroller/routing/TopoRouteServiceTest.java b/src/test/java/net/onrc/onos/ofcontroller/routing/TopoRouteServiceTest.java
index 7929eb1..7466ce7 100644
--- a/src/test/java/net/onrc/onos/ofcontroller/routing/TopoRouteServiceTest.java
+++ b/src/test/java/net/onrc/onos/ofcontroller/routing/TopoRouteServiceTest.java
@@ -17,10 +17,12 @@
import com.thinkaurelius.titan.core.TitanGraph;
import com.thinkaurelius.titan.core.TitanFactory;
+import net.onrc.onos.graph.DBConnection;
+import net.onrc.onos.graph.DBOperation;
import net.onrc.onos.graph.GraphDBConnection;
+import net.onrc.onos.graph.GraphDBManager;
import net.onrc.onos.graph.GraphDBOperation;
import net.onrc.onos.ofcontroller.core.internal.TestDatabaseManager;
-import net.onrc.onos.ofcontroller.routing.TopoRouteService;
import net.onrc.onos.ofcontroller.util.DataPath;
import net.onrc.onos.ofcontroller.util.Dpid;
import net.onrc.onos.ofcontroller.util.FlowPathFlags;
@@ -35,8 +37,9 @@
@PrepareForTest({TitanFactory.class, GraphDBConnection.class, GraphDBOperation.class, TopoRouteService.class})
public class TopoRouteServiceTest {
String conf;
- private GraphDBConnection conn = null;
- private GraphDBOperation oper = null;
+ String dbStore;
+ private DBConnection conn = null;
+ private DBOperation oper = null;
private TitanGraph titanGraph = null;
private TopoRouteService topoRouteService = null;
@@ -45,6 +48,7 @@
*/
@Before
public void setUp() throws Exception {
+ dbStore = "dummyStore";
conf = "/dummy/path/to/db";
//
@@ -56,9 +60,9 @@
EasyMock.expect(TitanFactory.open((String)EasyMock.anyObject())).andReturn(titanGraph);
PowerMock.replay(TitanFactory.class);
+ oper = GraphDBManager.getDBOperation(dbStore, conf);
// Create the connection to the database
- conn = GraphDBConnection.getInstance(conf);
- oper = new GraphDBOperation(conn);
+ conn = GraphDBManager.getConnection(dbStore, conf);
// Populate the database
TestDatabaseManager.populateTestData(titanGraph);