Merged with origin/master
diff --git a/pom.xml b/pom.xml
index 98d0e61..0a8c37c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
<maven>3.0.4</maven>
</prerequisites>
<groupId>net.onrc.onos</groupId>
- <artifactId>ONOS</artifactId>
+ <artifactId>onos</artifactId>
<version>0.1.0</version>
<packaging>jar</packaging>
<name>ONOS</name>
diff --git a/src/main/java/net/onrc/onos/graph/GraphDBConnection.java b/src/main/java/net/onrc/onos/graph/GraphDBConnection.java
index a883c59..f9f3b67 100644
--- a/src/main/java/net/onrc/onos/graph/GraphDBConnection.java
+++ b/src/main/java/net/onrc/onos/graph/GraphDBConnection.java
@@ -63,6 +63,9 @@
if (!s.contains("dpid")) {
graph.createKeyIndex("dpid", Vertex.class);
}
+ if (!s.contains("port_id")) {
+ graph.createKeyIndex("port_id", Vertex.class);
+ }
if (!s.contains("type")) {
graph.createKeyIndex("type", Vertex.class);
}
diff --git a/src/main/java/net/onrc/onos/graph/GraphDBOperation.java b/src/main/java/net/onrc/onos/graph/GraphDBOperation.java
index 0718db2..acfe43b 100644
--- a/src/main/java/net/onrc/onos/graph/GraphDBOperation.java
+++ b/src/main/java/net/onrc/onos/graph/GraphDBOperation.java
@@ -3,6 +3,8 @@
import java.util.ArrayList;
import java.util.List;
+import org.openflow.protocol.OFPhysicalPort;
+
import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IDeviceObject;
import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowEntry;
import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowPath;
@@ -12,6 +14,7 @@
import net.onrc.onos.ofcontroller.util.FlowEntryId;
import net.onrc.onos.ofcontroller.util.FlowId;
+import com.google.common.base.Stopwatch;
import com.thinkaurelius.titan.core.TitanGraph;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.frames.FramedGraph;
@@ -56,7 +59,7 @@
* @param dpid DPID of the switch
*/
public ISwitchObject searchSwitch(String dpid) {
- // TODO Auto-generated method stub
+
FramedGraph<TitanGraph> fg = conn.getFramedGraph();
return (fg != null && fg.getVertices("dpid",dpid).iterator().hasNext()) ?
@@ -136,11 +139,26 @@
FramedGraph<TitanGraph> fg = conn.getFramedGraph();
fg.removeVertex(sw.asVertex());
}
+
+ @Override
+ public IPortObject newPort(String dpid, Short portNumber) {
+ FramedGraph<TitanGraph> fg = conn.getFramedGraph();
+ IPortObject obj = fg.addVertex(null,IPortObject.class);
+ if (obj != null) {
+ obj.setType("port");
+ String id = dpid + portNumber.toString();
+ obj.setPortId(id);
+ obj.setNumber(portNumber);
+ }
+ return obj;
+
+ }
/**
* Create a port having specified port number.
* @param portNumber port number
*/
+ @Deprecated
public IPortObject newPort(Short portNumber) {
FramedGraph<TitanGraph> fg = conn.getFramedGraph();
IPortObject obj = fg.addVertex(null,IPortObject.class);
@@ -156,32 +174,11 @@
* @param dpid DPID of a switch
* @param number port number of the switch's port
*/
- public IPortObject searchPort(String dpid, short number) {
- ISwitchObject sw = searchSwitch(dpid);
- if (sw != null) {
-
- IPortObject port = null;
-
- // Requires Frames 2.3.0
-
- try {
- port = sw.getPort(number);
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- return port;
- }
-
- // if (sw != null) {
- // GremlinPipeline<Vertex, IPortObject> pipe = new GremlinPipeline<Vertex, IPortObject>();
- // pipe.start(sw.asVertex());
- // pipe.out("on").has("number", number);
- // FramedVertexIterable<IPortObject> r = new FramedVertexIterable<IPortObject>(conn.getFramedGraph(), (Iterable) pipe, IPortObject.class);
- // return r != null && r.iterator().hasNext() ? r.iterator().next() : null;
- // }
- return null;
+ public IPortObject searchPort(String dpid, Short number) {
+ FramedGraph<TitanGraph> fg = conn.getFramedGraph();
+ String id = dpid + number.toString();
+ return (fg != null && fg.getVertices("port_id",id).iterator().hasNext()) ?
+ fg.getVertices("port_id",id,IPortObject.class).iterator().next() : null;
}
/**
@@ -359,4 +356,6 @@
public void close() {
conn.close();
}
+
+
}
diff --git a/src/main/java/net/onrc/onos/graph/IDBOperation.java b/src/main/java/net/onrc/onos/graph/IDBOperation.java
index 73e7651..f873f27 100644
--- a/src/main/java/net/onrc/onos/graph/IDBOperation.java
+++ b/src/main/java/net/onrc/onos/graph/IDBOperation.java
@@ -18,8 +18,10 @@
public Iterable<IFlowEntry> getAllSwitchNotUpdatedFlowEntries();
public void removeSwitch(ISwitchObject sw);
+ @Deprecated
public IPortObject newPort(Short portNumber);
- public IPortObject searchPort(String dpid, short number);
+ public IPortObject newPort(String dpid, Short portNum);
+ public IPortObject searchPort(String dpid, Short number);
public void removePort(IPortObject port);
public IDeviceObject newDevice();
@@ -42,4 +44,5 @@
public void commit();
public void rollback();
public void close();
+
}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjects.java b/src/main/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjects.java
index fc1c32f..d08da7c 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjects.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjects.java
@@ -73,6 +73,14 @@
@Property("number")
public Short getNumber();
+ @JsonIgnore
+ @Property("port_id")
+ public void setPortId(String id);
+
+ @JsonIgnore
+ @Property("port_id")
+ public String getPortId();
+
@Property("number")
public void setNumber(Short n);
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 79a4f76..a4dd528 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/core/ISwitchStorage.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/core/ISwitchStorage.java
@@ -3,6 +3,8 @@
import java.util.Collection;
+import net.floodlightcontroller.core.IOFSwitch;
+
import org.openflow.protocol.OFPhysicalPort;
public interface ISwitchStorage extends INetMapStorage {
@@ -21,7 +23,11 @@
*/
public void addPort(String dpid, OFPhysicalPort port);
/*
- * Get all ports associated on a switch
+ * Add a switch and all its associated ports
+ */
+ public void addSwitch(IOFSwitch sw);
+ /*
+ * Add a switch
*/
public void addSwitch(String dpid);
/*
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 c9b68c6..03a5e8e 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,5 +1,6 @@
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.ofcontroller.core.ISwitchStorage;
@@ -71,23 +72,8 @@
log.info("SwitchStorage:addSwitch(): dpid {} ", dpid);
try {
- ISwitchObject sw = op.searchSwitch(dpid);
- if (sw != null) {
- //If existing the switch. set The SW state ACTIVE.
- log.info("SwitchStorage:addSwitch dpid:{} already exists", dpid);
- sw.setState(SwitchState.ACTIVE.toString());
- op.commit();
- } else {
- sw = op.newSwitch(dpid);
-
- if (sw != null) {
- sw.setState(SwitchState.ACTIVE.toString());
- op.commit();
- log.info("SwitchStorage:addSwitch dpid:{} added", dpid);
- } else {
- log.error("switchStorage:addSwitch dpid:{} failed -> newSwitch failed", dpid);
- }
- }
+ newSwitch(dpid);
+ op.commit();
} catch (Exception e) {
e.printStackTrace();
op.rollback();
@@ -95,6 +81,24 @@
}
}
+ 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
@@ -164,7 +168,7 @@
if (p != null) {
log.error("SwitchStorage:addPort dpid:{} port:{} exists", dpid, port.getPortNumber());
} else {
- p = op.newPort(port.getPortNumber());
+ p = op.newPort(dpid, port.getPortNumber());
p.setState("ACTIVE");
p.setPortState(port.getState());
p.setDesc(port.getName());
@@ -207,4 +211,32 @@
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());
+ } 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);
+ }
+
+ }
+}
\ 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 5b8e25b..8c83a7c 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/floodlightlistener/NetworkGraphPublisher.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/floodlightlistener/NetworkGraphPublisher.java
@@ -153,10 +153,7 @@
public void addedSwitch(IOFSwitch sw) {
if (registryService.hasControl(sw.getId())) {
- swStore.update(sw.getStringId(), SwitchState.ACTIVE, DM_OPERATION.UPDATE);
- for (OFPhysicalPort port: sw.getPorts()) {
- swStore.addPort(sw.getStringId(), port);
- }
+ swStore.addSwitch(sw);
}
}
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 f65eb4f..d2a6712 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
@@ -447,7 +447,7 @@
mockOpe.commit();
expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw);
expect(mockOpe.searchPort(dpid, portNumber)).andReturn(null);
- expect(mockOpe.newPort(portNumber)).andReturn(mockIPort);
+ expect(mockOpe.newPort(dpid, portNumber)).andReturn(mockIPort);
mockOpe.commit();
mockOpe.close();
replay(mockOpe);
@@ -588,7 +588,7 @@
mockOpe.commit();
expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw);
expect(mockOpe.searchPort(dpid, portNumber)).andReturn(null);
- expect(mockOpe.newPort(portNumber)).andReturn(null);
+ expect(mockOpe.newPort(dpid, portNumber)).andReturn(null);
mockOpe.rollback();
mockOpe.close();
replay(mockOpe);
@@ -639,7 +639,7 @@
mockOpe.commit();
expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw);
expect(mockOpe.searchPort(dpid, portNumber)).andReturn(null);
- expect(mockOpe.newPort(portNumber)).andReturn(mockIPort);
+ expect(mockOpe.newPort(dpid, portNumber)).andReturn(mockIPort);
mockOpe.commit();
expectLastCall().andThrow(new RuntimeException());
mockOpe.rollback();
@@ -693,7 +693,7 @@
mockOpe.commit();
expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw);
expect(mockOpe.searchPort(dpid, portNumber)).andReturn(null);
- expect(mockOpe.newPort(portNumber)).andReturn(mockIPort);
+ expect(mockOpe.newPort(dpid, portNumber)).andReturn(mockIPort);
mockOpe.commit();
expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw);
expect(mockOpe.searchPort(dpid, portNumber)).andReturn(mockIPort);
@@ -750,7 +750,7 @@
mockOpe.commit();
expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw);
expect(mockOpe.searchPort(dpid, portNumber)).andReturn(null);
- expect(mockOpe.newPort(portNumber)).andReturn(mockIPort);
+ expect(mockOpe.newPort(dpid, portNumber)).andReturn(mockIPort);
mockOpe.commit();
expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw);
expect(mockOpe.searchPort(dpid, portNumber)).andReturn(mockIPort);
diff --git a/src/test/java/net/onrc/onos/ofcontroller/core/internal/TestableGraphDBOperation.java b/src/test/java/net/onrc/onos/ofcontroller/core/internal/TestableGraphDBOperation.java
index aaca07d..658aaaf 100644
--- a/src/test/java/net/onrc/onos/ofcontroller/core/internal/TestableGraphDBOperation.java
+++ b/src/test/java/net/onrc/onos/ofcontroller/core/internal/TestableGraphDBOperation.java
@@ -3,12 +3,14 @@
import java.util.ArrayList;
import java.util.List;
+import org.codehaus.jackson.annotate.JsonIgnore;
import org.easymock.EasyMock;
import org.openflow.util.HexString;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.tinkerpop.blueprints.Vertex;
+import com.tinkerpop.frames.Property;
import com.tinkerpop.frames.annotations.gremlin.GremlinParam;
import net.onrc.onos.graph.GraphDBConnection;
@@ -291,6 +293,22 @@
@Override
public void setLinkPort(IPortObject dest_port) { linkedPortsToAdd.add(dest_port); }
+
+ @Override
+ @JsonIgnore
+ @Property("port_id")
+ public void setPortId(String id) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ @JsonIgnore
+ @Property("port_id")
+ public String getPortId() {
+ // TODO Auto-generated method stub
+ return null;
+ }
}
public static class TestDeviceObject implements IDeviceObject {
@@ -1127,7 +1145,7 @@
}
@Override
- public IPortObject searchPort(String dpid_str, short number) {
+ public IPortObject searchPort(String dpid_str, Short number) {
long dpid = HexString.toLong(dpid_str);
for(TestSwitchObject sw : switches) {
diff --git a/start-onos-embedded.sh b/start-onos-embedded.sh
index e75b696..5da4d9b 100755
--- a/start-onos-embedded.sh
+++ b/start-onos-embedded.sh
@@ -1,10 +1,9 @@
#!/bin/bash
# Set paths
-#ONOS_HOME=`dirname $0`
-ONOS_HOME=${HOME}/ONOS
-ONOS_JAR="${ONOS_HOME}/target/floodlight.jar"
-ONOS_ONLY_JAR="${ONOS_HOME}/target/floodlight-only.jar"
+if [ -z "${ONOS_HOME}" ]; then
+ ONOS_HOME=`dirname $0`
+fi
ONOS_LOGBACK="${ONOS_HOME}/logback.xml"
LOGDIR=${ONOS_HOME}/onos-logs
ONOS_LOG="${LOGDIR}/onos.`hostname`.log"
@@ -24,9 +23,7 @@
#JVM_OPTS="$JVM_OPTS -Dpython.security.respectJavaAccessibility=false"
-# Set classpath to include titan libs
-#CLASSPATH=`echo ${ONOS_HOME}/lib/*.jar ${ONOS_HOME}/lib/titan/*.jar | sed 's/ /:/g'`
-CLASSPATH="${ONOS_ONLY_JAR}:${ONOS_HOME}/lib/*:${ONOS_HOME}/lib/titan/*"
+# Set Main class to start ONOS core
MAIN_CLASS="net.onrc.onos.ofcontroller.core.Main"
if [ -z "${MVN}" ]; then
@@ -89,8 +86,6 @@
# Run floodlight
echo "Starting ONOS controller ..."
echo
- #java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -jar ${ONOS_JAR} -cf ${ONOS_HOME}/onos.properties > /dev/null 2>&1 &
- #java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -cp ${CLASSPATH} ${MAIN_CLASS} -cf ${ONOS_HOME}/onos.properties > /dev/n
# XXX MVN has to run at the project top dir..
cd ${ONOS_HOME}
@@ -110,8 +105,7 @@
echo "Timed out"
exit 1
-# echo "java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -jar ${ONOS_JAR} -cf ./onos.properties > /dev/null 2>&1 &"
-# sudo -b /usr/sbin/tcpdump -n -i eth0 -s0 -w ${PCAP_LOG} 'tcp port 6633' > /dev/null 2>&1
+ sudo -b /usr/sbin/tcpdump -n -i eth0 -s0 -w ${PCAP_LOG} 'tcp port 6633' > /dev/null 2>&1
}
function stop {
@@ -122,7 +116,7 @@
for p in ${pids}; do
if [ x$p != "x" ]; then
kill -KILL $p
- echo "Killed existing prosess (pid: $p)"
+ echo "Killed existing process (pid: $p)"
fi
done
}
diff --git a/start-onos.sh b/start-onos.sh
index 9e8d559..667fd31 100755
--- a/start-onos.sh
+++ b/start-onos.sh
@@ -1,10 +1,9 @@
#!/bin/bash
# Set paths
-#ONOS_HOME=`dirname $0`
-ONOS_HOME=${HOME}/ONOS
-ONOS_JAR="${ONOS_HOME}/target/floodlight.jar"
-ONOS_ONLY_JAR="${ONOS_HOME}/target/floodlight-only.jar"
+if [ -z "${ONOS_HOME}" ]; then
+ ONOS_HOME=`dirname $0`
+fi
ONOS_LOGBACK="${ONOS_HOME}/logback.xml"
LOGDIR=${ONOS_HOME}/onos-logs
ONOS_LOG="${LOGDIR}/onos.`hostname`.log"
@@ -23,9 +22,7 @@
JVM_OPTS="$JVM_OPTS -XX:OnError=crash-logger" ;# For dumping core
#JVM_OPTS="$JVM_OPTS -Dpython.security.respectJavaAccessibility=false"
-# Set classpath to include titan libs
-#CLASSPATH=`echo ${ONOS_HOME}/lib/*.jar ${ONOS_HOME}/lib/titan/*.jar | sed 's/ /:/g'`
-CLASSPATH="${ONOS_ONLY_JAR}:${ONOS_HOME}/lib/*:${ONOS_HOME}/lib/titan/*"
+# Set ONOS core main class
MAIN_CLASS="net.onrc.onos.ofcontroller.core.Main"
if [ -z "${MVN}" ]; then
@@ -89,8 +86,6 @@
# Run floodlight
echo "Starting ONOS controller ..."
echo
- #java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -jar ${ONOS_JAR} -cf ${ONOS_HOME}/onos.properties > /dev/null 2>&1 &
- #java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -cp ${CLASSPATH} ${MAIN_CLASS} -cf ${ONOS_HOME}/onos.properties > /dev/n
# XXX : MVN has to run at the project top dir
cd ${ONOS_HOME}