Merge branch 'master' of https://github.com/OPENNETWORKINGLAB/ONOS
Conflicts:
src/test/java/net/floodlightcontroller/linkdiscovery/internal/LinkStorageImplTest.java
diff --git a/src/main/java/net/floodlightcontroller/core/INetMapService.java b/src/main/java/net/floodlightcontroller/core/INetMapService.java
new file mode 100644
index 0000000..fcc542a
--- /dev/null
+++ b/src/main/java/net/floodlightcontroller/core/INetMapService.java
@@ -0,0 +1,5 @@
+package net.floodlightcontroller.core;
+
+public interface INetMapService {
+
+}
diff --git a/src/main/java/net/floodlightcontroller/core/INetMapTopologyService.java b/src/main/java/net/floodlightcontroller/core/INetMapTopologyService.java
new file mode 100644
index 0000000..da00e0f
--- /dev/null
+++ b/src/main/java/net/floodlightcontroller/core/INetMapTopologyService.java
@@ -0,0 +1,36 @@
+package net.floodlightcontroller.core;
+
+import java.util.List;
+
+import net.floodlightcontroller.routing.Link;
+import net.floodlightcontroller.topology.NodePortTuple;
+
+public interface INetMapTopologyService extends INetMapService {
+
+ public interface ITopoSwitchService {
+ List<String> GetActiveSwitches();
+ List<String> GetAllSwitches();
+ List<String> GetInactiveSwitches();
+ List<String> GetPortsOnSwitch(String dpid);
+ }
+
+ public interface ITopoLinkService {
+ List<Link> GetActiveLinks();
+ List<Link> GetLinksOnSwitch(String dpid);
+ }
+ public interface ITopoDeviceService {
+ List<Link> GetActiveDevices();
+ List<Link> GetDevicesOnSwitch(String dpid);
+ }
+
+ public interface ITopoRouteService {
+ List<NodePortTuple> GetShortestpath(NodePortTuple src, NodePortTuple dest);
+ Boolean RouteExists(NodePortTuple src, NodePortTuple dest);
+ }
+
+ public interface ITopoFlowService {
+ Boolean FlowExists(NodePortTuple src, NodePortTuple dest);
+ List<NodePortTuple> GetShortestFlowPath(NodePortTuple src, NodePortTuple dest);
+
+ }
+}
diff --git a/src/main/java/net/floodlightcontroller/core/ISwitchStorage.java b/src/main/java/net/floodlightcontroller/core/ISwitchStorage.java
index 082995f..8060c4d 100644
--- a/src/main/java/net/floodlightcontroller/core/ISwitchStorage.java
+++ b/src/main/java/net/floodlightcontroller/core/ISwitchStorage.java
@@ -50,9 +50,13 @@
public void deletePort(String dpid, String portName);
public List<String> getActiveSwitches();
+ public List<String> getAllSwitches();
+ public List<String> getInactiveSwitches();
/*
* Initialize
*/
public void init(String conf);
+
+
}
diff --git a/src/main/java/net/floodlightcontroller/core/internal/Controller.java b/src/main/java/net/floodlightcontroller/core/internal/Controller.java
index 0cbcfcb..6e816c7 100644
--- a/src/main/java/net/floodlightcontroller/core/internal/Controller.java
+++ b/src/main/java/net/floodlightcontroller/core/internal/Controller.java
@@ -107,6 +107,7 @@
import org.openflow.protocol.OFPacketIn;
import org.openflow.protocol.OFPhysicalPort;
import org.openflow.protocol.OFPortStatus;
+import org.openflow.protocol.OFPhysicalPort.OFPortConfig;
import org.openflow.protocol.OFPhysicalPort.OFPortState;
import org.openflow.protocol.OFPortStatus.OFPortReason;
import org.openflow.protocol.OFSetConfig;
@@ -1145,12 +1146,10 @@
short portNumber = m.getDesc().getPortNumber();
OFPhysicalPort port = m.getDesc();
if (m.getReason() == (byte)OFPortReason.OFPPR_MODIFY.ordinal()) {
- int srcPortState = port.getState();
- boolean portUp = ((srcPortState &
- OFPortState.OFPPS_STP_MASK.getValue()) !=
- OFPortState.OFPPS_STP_BLOCK.getValue());
+ boolean portDown = ((OFPortConfig.OFPPC_PORT_DOWN.getValue() & port.getConfig()) > 0) ||
+ ((OFPortState.OFPPS_LINK_DOWN.getValue() & port.getState()) > 0);
sw.setPort(port);
- if (portUp) {
+ if (!portDown) {
swStore.addPort(sw.getStringId(), port);
} else {
swStore.deletePort(sw.getStringId(), port.getPortNumber());
diff --git a/src/main/java/net/floodlightcontroller/core/internal/SwitchStorageImpl.java b/src/main/java/net/floodlightcontroller/core/internal/SwitchStorageImpl.java
index 0636400..be33659 100644
--- a/src/main/java/net/floodlightcontroller/core/internal/SwitchStorageImpl.java
+++ b/src/main/java/net/floodlightcontroller/core/internal/SwitchStorageImpl.java
@@ -1,5 +1,6 @@
package net.floodlightcontroller.core.internal;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
@@ -8,6 +9,8 @@
import org.slf4j.LoggerFactory;
import org.openflow.protocol.OFPhysicalPort;
+import org.openflow.protocol.OFPhysicalPort.OFPortConfig;
+import org.openflow.protocol.OFPhysicalPort.OFPortState;
import com.thinkaurelius.titan.core.TitanException;
import com.thinkaurelius.titan.core.TitanFactory;
@@ -63,6 +66,13 @@
public void addPort(String dpid, OFPhysicalPort port) {
// TODO Auto-generated method stub
Vertex sw;
+
+ boolean portDown = ((OFPortConfig.OFPPC_PORT_DOWN.getValue() & port.getConfig()) > 0) ||
+ ((OFPortState.OFPPS_LINK_DOWN.getValue() & port.getState()) > 0);
+ if (portDown) {
+ deletePort(dpid, port.getPortNumber());
+ return;
+ }
try {
if ((sw = graph.getVertices("dpid",dpid).iterator().next()) != null) {
log.info("SwitchStorage:addPort dpid:{} port:{}", dpid, port.getPortNumber());
@@ -118,7 +128,11 @@
/*
* Do nothing or throw exception?
*/
- log.info("SwitchStorage:addSwitch dpid:{} already exists", dpid);
+ Vertex sw = graph.getVertices("dpid",dpid).iterator().next();
+
+ log.info("SwitchStorage:addSwitch dpid:{} already exists", dpid);
+ sw.setProperty("state",SwitchState.ACTIVE.toString());
+ graph.stopTransaction(Conclusion.SUCCESS);
} else {
Vertex sw = graph.addVertex(null);
@@ -185,8 +199,14 @@
@Override
public List<String> getActiveSwitches() {
- // TODO Auto-generated method stub
- return null;
+ // TODO Add unit test
+ List<String> switches = new ArrayList<String>();
+ for (Vertex V : graph.getVertices("type","switch")) {
+ if (V.getProperty("state").equals(SwitchState.ACTIVE.toString())) {
+ switches.add((String) V.getProperty("dpid"));
+ }
+ }
+ return switches;
}
@Override
@@ -206,4 +226,27 @@
}
}
+ @Override
+ public List<String> getAllSwitches() {
+ // TODO Auto-generated method stub
+ List<String> switches = new ArrayList<String>();
+ for (Vertex V : graph.getVertices("type","switch")) {
+ switches.add((String) V.getProperty("dpid"));
+ }
+ return switches;
+ }
+
+ @Override
+ public List<String> getInactiveSwitches() {
+ // TODO Auto-generated method stub
+ List<String> switches = new ArrayList<String>();
+ for (Vertex V : graph.getVertices("type","switch")) {
+ if (V.getProperty("state").equals(SwitchState.INACTIVE.toString())) {
+ switches.add((String) V.getProperty("dpid"));
+ }
+ }
+ return switches;
+ }
+
+
}
diff --git a/src/main/java/net/floodlightcontroller/core/internal/SwitchStorageImplStubs.java b/src/main/java/net/floodlightcontroller/core/internal/SwitchStorageImplStubs.java
index c281141..88f94db 100644
--- a/src/main/java/net/floodlightcontroller/core/internal/SwitchStorageImplStubs.java
+++ b/src/main/java/net/floodlightcontroller/core/internal/SwitchStorageImplStubs.java
@@ -111,4 +111,16 @@
}
+ @Override
+ public List<String> getAllSwitches() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public List<String> getInactiveSwitches() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
}
diff --git a/src/main/java/net/floodlightcontroller/core/internal/TopoSwitchServiceImpl.java b/src/main/java/net/floodlightcontroller/core/internal/TopoSwitchServiceImpl.java
new file mode 100644
index 0000000..99f291d
--- /dev/null
+++ b/src/main/java/net/floodlightcontroller/core/internal/TopoSwitchServiceImpl.java
@@ -0,0 +1,45 @@
+package net.floodlightcontroller.core.internal;
+
+import java.util.List;
+
+import net.floodlightcontroller.core.INetMapTopologyService.ITopoSwitchService;
+
+public class TopoSwitchServiceImpl implements ITopoSwitchService {
+
+ ThreadLocal<SwitchStorageImpl> store = new ThreadLocal<SwitchStorageImpl>() {
+ @Override
+ protected SwitchStorageImpl initialValue() {
+ SwitchStorageImpl swStore = new SwitchStorageImpl();
+ //TODO: Get the file path from global properties
+ swStore.init("/tmp/cassandra.titan");
+ return swStore;
+ }
+ };
+
+ SwitchStorageImpl swStore = store.get();
+
+ @Override
+ public List<String> GetActiveSwitches() {
+ // TODO Auto-generated method stub
+ return swStore.getActiveSwitches();
+ }
+
+ @Override
+ public List<String> GetAllSwitches() {
+ // TODO Auto-generated method stub
+ return swStore.getAllSwitches();
+ }
+
+ @Override
+ public List<String> GetInactiveSwitches() {
+ // TODO Auto-generated method stub
+ return swStore.getInactiveSwitches();
+ }
+
+ @Override
+ public List<String> GetPortsOnSwitch(String dpid) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/src/main/java/net/floodlightcontroller/core/web/CoreWebRoutable.java b/src/main/java/net/floodlightcontroller/core/web/CoreWebRoutable.java
index 45ef6e9..0c41259 100644
--- a/src/main/java/net/floodlightcontroller/core/web/CoreWebRoutable.java
+++ b/src/main/java/net/floodlightcontroller/core/web/CoreWebRoutable.java
@@ -60,6 +60,7 @@
router.attach("/role/json", ControllerRoleResource.class);
router.attach("/health/json", HealthCheckResource.class);
router.attach("/system/uptime/json", SystemUptimeResource.class);
+ router.attach("/topology/switches/{filter}/json", TopoSwitchesResource.class);
return router;
}
}
diff --git a/src/main/java/net/floodlightcontroller/core/web/TopoSwitchesResource.java b/src/main/java/net/floodlightcontroller/core/web/TopoSwitchesResource.java
new file mode 100644
index 0000000..a73b0b4
--- /dev/null
+++ b/src/main/java/net/floodlightcontroller/core/web/TopoSwitchesResource.java
@@ -0,0 +1,27 @@
+package net.floodlightcontroller.core.web;
+
+import java.util.Iterator;
+
+import net.floodlightcontroller.core.internal.TopoSwitchServiceImpl;
+
+import org.restlet.resource.Get;
+import org.restlet.resource.ServerResource;
+
+public class TopoSwitchesResource extends ServerResource {
+
+ @Get("json")
+ public Iterator<String> retrieve() {
+ TopoSwitchServiceImpl impl = new TopoSwitchServiceImpl();
+
+ String filter = (String) getRequestAttributes().get("filter");
+
+ if (filter.equals("active")) {
+ return (Iterator<String>) impl.GetActiveSwitches().iterator();
+ }
+ if (filter.equals("inactive")) {
+ return (Iterator<String>) impl.GetInactiveSwitches().iterator();
+ }
+ return (Iterator<String>) impl.GetAllSwitches().iterator();
+ }
+
+}
diff --git a/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkStorageImpl.java b/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkStorageImpl.java
index 9c0ee4e..0e9f32b 100644
--- a/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkStorageImpl.java
+++ b/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkStorageImpl.java
@@ -139,16 +139,16 @@
if (vportSrc != null && vportDst != null) {
for (Edge e : vportSrc.getEdges(Direction.OUT)) {
- log.debug("deleteLink(): {} {}", e.getLabel(), e.getVertex(Direction.IN));
- // if (e.getLabel().equals("link") && e.getVertex(Direction.OUT).equals(vportDst)) {
- if (e.getLabel().equals("link")) {
+ 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++;
}
}
graph.stopTransaction(Conclusion.SUCCESS);
- log.debug("deleteLink(): {} {} src {} dst {}", new Object[]{
- (count > 0) ? "deleted " + count : "failure", lt, vportSrc, vportDst});
+ log.debug("deleteLink(): deleted {} edges {} src {} dst {}", new Object[]{
+ count, lt, vportSrc, vportDst});
} else {
log.error("deleteLink(): failed src port vertex not found {} src {} dst {}", new Object[]{lt, vportSrc, vportDst});
diff --git a/src/main/resources/cassandra.titan b/src/main/resources/cassandra.titan
index e6f3357..8846963 100644
--- a/src/main/resources/cassandra.titan
+++ b/src/main/resources/cassandra.titan
@@ -1,3 +1,3 @@
storage.backend=cassandra
-storage.hostname=127.0.0.1
+storage.hostname=onos8vpc
storage.keyspace=onos
diff --git a/src/test/java/net/floodlightcontroller/core/internal/SwitchStorageImplTest.java b/src/test/java/net/floodlightcontroller/core/internal/SwitchStorageImplTest.java
index 2f66bcb..8f272c5 100644
--- a/src/test/java/net/floodlightcontroller/core/internal/SwitchStorageImplTest.java
+++ b/src/test/java/net/floodlightcontroller/core/internal/SwitchStorageImplTest.java
@@ -1,33 +1,32 @@
package net.floodlightcontroller.core.internal;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.util.Iterator;
-import junit.framework.TestCase;
import net.floodlightcontroller.core.ISwitchStorage;
import net.floodlightcontroller.core.ISwitchStorage.SwitchState;
import org.junit.After;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.openflow.protocol.OFPhysicalPort;
import com.thinkaurelius.titan.core.TitanGraph;
-import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.gremlin.java.GremlinPipeline;
-public class SwitchStorageImplTest extends TestCase {
+public class SwitchStorageImplTest {
- private static ISwitchStorage switchStorage;
- private static TitanGraph titanGraph;
+ private ISwitchStorage switchStorage;
+ private TitanGraph titanGraph;
@Before
- protected void setUp() throws Exception {
- super.setUp();
-
- TestDatabaseManager.deleteTestDatabase();
-
+ public void setUp() throws Exception {
titanGraph = TestDatabaseManager.getTestDatabase();
TestDatabaseManager.populateTestData(titanGraph);
@@ -35,13 +34,11 @@
}
@After
- protected void tearDown() throws Exception {
- super.tearDown();
- //TODO reenable once test debugging is finished
- TestDatabaseManager.deleteTestDatabase();
+ public void tearDown() throws Exception {
+ titanGraph.shutdown();
}
- @Test
+ @Ignore @Test
public void testUpdate() {
fail("Not yet implemented");
}
@@ -71,17 +68,17 @@
assertEquals(addedPort.getProperty("number"), portNumber);
}
- @Test
+ @Ignore @Test
public void testGetPorts() {
fail("Not yet implemented");
}
- @Test
+ @Ignore @Test
public void testGetPortStringShort() {
fail("Not yet implemented");
}
- @Test
+ @Ignore @Test
public void testGetPortStringString() {
fail("Not yet implemented");
}
@@ -103,8 +100,6 @@
}
- //FIXME something causes this test to fail when run in the suite. Probably something
- //to do with not properly refreshing our DB connection for each test
@Test
public void testDeleteSwitch() {
String dpid = "00:00:00:00:00:00:0a:01";
@@ -115,11 +110,6 @@
assertFalse(it.hasNext());
}
- //TODO there's an issue with the datatypes for things link port numbers.
- //There should be a standard type in the DB for everything, however there
- //are discrepancies for example when I read data in from a file port numbers
- //are ints but if they're put in by the API they're shorts.
-
@Test
public void testDeletePortByPortNum() {
//FIXME fails because query for the port is wrong in SwitchStorageImpl
@@ -131,25 +121,26 @@
Vertex sw = titanGraph.getVertices("dpid", dpid).iterator().next();
+ /*
Iterator<Vertex> it = sw.getVertices(Direction.OUT, "on").iterator();
while (it.hasNext()){
System.out.println(it.next());
}
+ */
GremlinPipeline<Vertex, Vertex> pipe = new GremlinPipeline<Vertex, Vertex>();
- pipe.start(sw).out("on").has("number", (int)portNum);
+ pipe.start(sw).out("on").has("number", portNum);
assertFalse(pipe.hasNext());
}
- @Test
+ @Ignore @Test
public void testDeletePortStringString() {
fail("Not yet implemented");
}
- @Test
+ @Ignore @Test
public void testGetActiveSwitches() {
fail("Not yet implemented");
}
-
}
diff --git a/src/test/java/net/floodlightcontroller/core/internal/TestDatabaseManager.java b/src/test/java/net/floodlightcontroller/core/internal/TestDatabaseManager.java
index c6872a0..cea67c3 100644
--- a/src/test/java/net/floodlightcontroller/core/internal/TestDatabaseManager.java
+++ b/src/test/java/net/floodlightcontroller/core/internal/TestDatabaseManager.java
@@ -1,15 +1,17 @@
package net.floodlightcontroller.core.internal;
-import java.io.ByteArrayInputStream;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
+import java.util.Iterator;
import java.util.Set;
-import org.apache.commons.io.FileUtils;
-
import junit.framework.Assert;
+import org.apache.commons.io.FileUtils;
+
import com.thinkaurelius.titan.core.TitanFactory;
import com.thinkaurelius.titan.core.TitanGraph;
import com.tinkerpop.blueprints.TransactionalGraph.Conclusion;
@@ -19,10 +21,13 @@
public class TestDatabaseManager {
private static final String testDbLocation = "/tmp/onos-testdb";
- private static final String testDbGraphML = "<?xml version=\"1.0\" ?><graphml xmlns=\"http://graphml.graphdrawing.org/xmlns\"> <key id=\"id\" for=\"node\" attr.name=\"id\" attr.type=\"string\"></key> <key id=\"type\" for=\"node\" attr.name=\"type\" attr.type=\"string\"></key> <key id=\"dpid\" for=\"node\" attr.name=\"dpid\" attr.type=\"string\"></key> <key id=\"desc\" for=\"node\" attr.name=\"desc\" attr.type=\"string\"></key> <key id=\"number\" for=\"node\" attr.name=\"number\" attr.type=\"int\"></key> <key id=\"dl_addr\" for=\"node\" attr.name=\"dl_addr\" attr.type=\"string\"></key> <key id=\"nw_addr\" for=\"node\" attr.name=\"nw_addr\" attr.type=\"string\"></key> <key id=\"id\" for=\"edge\" attr.name=\"id\" attr.type=\"string\"></key> <key id=\"source\" for=\"edge\" attr.name=\"source\" attr.type=\"string\"></key> <key id=\"target\" for=\"edge\" attr.name=\"target\" attr.type=\"string\"></key> <key id=\"label\" for=\"edge\" attr.name=\"label\" attr.type=\"string\"></key> <graph id=\"G\" edgedefault=\"directed\"> <node id=\"1\"> <data key=\"type\">switch</data> <data key=\"dpid\">00:00:00:00:00:00:0a:01</data> <data key=\"desc\">OpenFlow Switch at SEA</data> </node> <node id=\"2\"> <data key=\"type\">switch</data> <data key=\"dpid\">00:00:00:00:00:00:0a:02</data> <data key=\"desc\">OpenFlow Switch at LAX</data> </node> <node id=\"3\"> <data key=\"type\">switch</data> <data key=\"dpid\">00:00:00:00:00:00:0a:03</data> <data key=\"desc\">OpenFlow Switch at CHI</data> </node> <node id=\"4\"> <data key=\"type\">switch</data> <data key=\"dpid\">00:00:00:00:00:00:0a:04</data> <data key=\"desc\">OpenFlow Switch at IAH</data> </node> <node id=\"5\"> <data key=\"type\">switch</data> <data key=\"dpid\">00:00:00:00:00:00:0a:05</data> <data key=\"desc\">OpenFlow Switch at NYC</data> </node> <node id=\"6\"> <data key=\"type\">switch</data> <data key=\"dpid\">00:00:00:00:00:00:0a:06</data> <data key=\"desc\">OpenFlow Switch at ATL</data> </node> <node id=\"100\"> <data key=\"type\">port</data> <data key=\"number\">1</data> <data key=\"desc\">port 1 at SEA Switch</data> </node> <node id=\"101\"> <data key=\"type\">port</data> <data key=\"number\">2</data> <data key=\"desc\">port 2 at SEA Switch</data> </node> <node id=\"102\"> <data key=\"type\">port</data> <data key=\"number\">3</data> <data key=\"desc\">port 3 at SEA Switch</data> </node> <node id=\"103\"> <data key=\"type\">port</data> <data key=\"number\">4</data> <data key=\"desc\">port 4 at SEA Switch</data> </node> <node id=\"104\"> <data key=\"type\">port</data> <data key=\"number\">1</data> <data key=\"desc\">port 1 at LAX Switch</data> </node> <node id=\"105\"> <data key=\"type\">port</data> <data key=\"number\">2</data> <data key=\"desc\">port 2 at LAX Switch</data> </node> <node id=\"106\"> <data key=\"type\">port</data> <data key=\"number\">3</data> <data key=\"desc\">port 3 at LAX Switch</data> </node> <node id=\"107\"> <data key=\"type\">port</data> <data key=\"number\">1</data> <data key=\"desc\">port 1 at CHI Switch</data> </node> <node id=\"108\"> <data key=\"type\">port</data> <data key=\"number\">2</data> <data key=\"desc\">port 2 at CHI Switch</data> </node> <node id=\"109\"> <data key=\"type\">port</data> <data key=\"number\">3</data> <data key=\"desc\">port 3 at CHI Switch</data> </node> <node id=\"110\"> <data key=\"type\">port</data> <data key=\"number\">4</data> <data key=\"desc\">port 4 at CHI Switch</data> </node> <node id=\"111\"> <data key=\"type\">port</data> <data key=\"number\">1</data> <data key=\"desc\">port 1 at IAH Switch</data> </node> <node id=\"112\"> <data key=\"type\">port</data> <data key=\"number\">2</data> <data key=\"desc\">port 2 at IAH Switch</data> </node> <node id=\"113\"> <data key=\"type\">port</data> <data key=\"number\">3</data> <data key=\"desc\">port 3 at IAH Switch</data> </node> <node id=\"114\"> <data key=\"type\">port</data> <data key=\"number\">1</data> <data key=\"desc\">port 1 at NYC Switch</data> </node> <node id=\"115\"> <data key=\"type\">port</data> <data key=\"number\">2</data> <data key=\"desc\">port 2 at NYC Switch</data> </node> <node id=\"116\"> <data key=\"type\">port</data> <data key=\"number\">3</data> <data key=\"desc\">port 3 at NYC Switch</data> </node> <node id=\"117\"> <data key=\"type\">port</data> <data key=\"number\">1</data> <data key=\"desc\">port 1 at ATL Switch</data> </node> <node id=\"118\"> <data key=\"type\">port</data> <data key=\"number\">2</data> <data key=\"desc\">port 2 at ATL Switch</data> </node> <node id=\"119\"> <data key=\"type\">port</data> <data key=\"number\">3</data> <data key=\"desc\">port 3 at ATL Switch</data> </node> <node id=\"1000\"> <data key=\"type\">device</data> <data key=\"dl_addr\">20:c9:d0:4a:e1:73</data> <data key=\"nw_addr\">192.168.10.101</data> </node> <node id=\"1001\"> <data key=\"type\">device</data> <data key=\"dl_addr\">20:c9:d0:4a:e1:62</data> <data key=\"nw_addr\">192.168.20.101</data> </node> <node id=\"1002\"> <data key=\"type\">device</data> <data key=\"dl_addr\">10:40:f3:e6:8d:55</data> <data key=\"nw_addr\">192.168.10.1</data> </node> <node id=\"1003\"> <data key=\"type\">device</data> <data key=\"dl_addr\">a0:b3:cc:9c:c6:88</data> <data key=\"nw_addr\">192.168.20.1</data> </node> <node id=\"1004\"> <data key=\"type\">device</data> <data key=\"dl_addr\">00:04:20:e2:50:a2</data> <data key=\"nw_addr\">192.168.30.1</data> </node> <node id=\"1005\"> <data key=\"type\">device</data> <data key=\"dl_addr\">58:55:ca:c4:1b:a0</data> <data key=\"nw_addr\">192.168.40.1</data> </node> <edge id=\"10000\" source=\"1\" target=\"101\" label=\"on\"></edge> <edge id=\"10001\" source=\"1\" target=\"102\" label=\"on\"></edge> <edge id=\"10002\" source=\"1\" target=\"103\" label=\"on\"></edge> <edge id=\"10003\" source=\"2\" target=\"104\" label=\"on\"></edge> <edge id=\"10004\" source=\"2\" target=\"105\" label=\"on\"></edge> <edge id=\"10005\" source=\"2\" target=\"106\" label=\"on\"></edge> <edge id=\"10006\" source=\"3\" target=\"107\" label=\"on\"></edge> <edge id=\"10007\" source=\"3\" target=\"108\" label=\"on\"></edge> <edge id=\"10008\" source=\"3\" target=\"109\" label=\"on\"></edge> <edge id=\"10009\" source=\"3\" target=\"110\" label=\"on\"></edge> <edge id=\"10010\" source=\"4\" target=\"111\" label=\"on\"></edge> <edge id=\"10011\" source=\"4\" target=\"112\" label=\"on\"></edge> <edge id=\"10012\" source=\"4\" target=\"113\" label=\"on\"></edge> <edge id=\"10013\" source=\"5\" target=\"114\" label=\"on\"></edge> <edge id=\"10014\" source=\"5\" target=\"115\" label=\"on\"></edge> <edge id=\"10015\" source=\"5\" target=\"116\" label=\"on\"></edge> <edge id=\"10016\" source=\"6\" target=\"117\" label=\"on\"></edge> <edge id=\"10017\" source=\"6\" target=\"118\" label=\"on\"></edge> <edge id=\"10018\" source=\"6\" target=\"119\" label=\"on\"></edge> <edge id=\"11000\" source=\"101\" target=\"107\" label=\"link\"></edge> <edge id=\"11003\" source=\"105\" target=\"111\" label=\"link\"></edge> <edge id=\"11004\" source=\"107\" target=\"101\" label=\"link\"></edge> <edge id=\"11005\" source=\"108\" target=\"112\" label=\"link\"></edge> <edge id=\"11006\" source=\"109\" target=\"114\" label=\"link\"></edge> <edge id=\"11007\" source=\"111\" target=\"105\" label=\"link\"></edge> <edge id=\"11008\" source=\"112\" target=\"108\" label=\"link\"></edge> <edge id=\"11009\" source=\"113\" target=\"117\" label=\"link\"></edge> <edge id=\"11010\" source=\"114\" target=\"109\" label=\"link\"></edge> <edge id=\"11011\" source=\"115\" target=\"118\" label=\"link\"></edge> <edge id=\"11012\" source=\"117\" target=\"113\" label=\"link\"></edge> <edge id=\"11013\" source=\"118\" target=\"115\" label=\"link\"></edge> <edge id=\"12000\" source=\"103\" target=\"1000\" label=\"host\"></edge> <edge id=\"12001\" source=\"103\" target=\"1001\" label=\"host\"></edge> <edge id=\"12002\" source=\"110\" target=\"1002\" label=\"host\"></edge> <edge id=\"12003\" source=\"116\" target=\"1003\" label=\"host\"></edge> <edge id=\"12004\" source=\"106\" target=\"1004\" label=\"host\"></edge> <edge id=\"12005\" source=\"119\" target=\"1005\" label=\"host\"></edge> </graph> </graphml>";
+ //private static final String testDbGraphML = "<?xml version=\"1.0\" ?><graphml xmlns=\"http://graphml.graphdrawing.org/xmlns\"> <key id=\"id\" for=\"node\" attr.name=\"id\" attr.type=\"string\"></key> <key id=\"type\" for=\"node\" attr.name=\"type\" attr.type=\"string\"></key> <key id=\"dpid\" for=\"node\" attr.name=\"dpid\" attr.type=\"string\"></key> <key id=\"desc\" for=\"node\" attr.name=\"desc\" attr.type=\"string\"></key> <key id=\"number\" for=\"node\" attr.name=\"number\" attr.type=\"int\"></key> <key id=\"dl_addr\" for=\"node\" attr.name=\"dl_addr\" attr.type=\"string\"></key> <key id=\"nw_addr\" for=\"node\" attr.name=\"nw_addr\" attr.type=\"string\"></key> <key id=\"id\" for=\"edge\" attr.name=\"id\" attr.type=\"string\"></key> <key id=\"source\" for=\"edge\" attr.name=\"source\" attr.type=\"string\"></key> <key id=\"target\" for=\"edge\" attr.name=\"target\" attr.type=\"string\"></key> <key id=\"label\" for=\"edge\" attr.name=\"label\" attr.type=\"string\"></key> <graph id=\"G\" edgedefault=\"directed\"> <node id=\"1\"> <data key=\"type\">switch</data> <data key=\"dpid\">00:00:00:00:00:00:0a:01</data> <data key=\"desc\">OpenFlow Switch at SEA</data> </node> <node id=\"2\"> <data key=\"type\">switch</data> <data key=\"dpid\">00:00:00:00:00:00:0a:02</data> <data key=\"desc\">OpenFlow Switch at LAX</data> </node> <node id=\"3\"> <data key=\"type\">switch</data> <data key=\"dpid\">00:00:00:00:00:00:0a:03</data> <data key=\"desc\">OpenFlow Switch at CHI</data> </node> <node id=\"4\"> <data key=\"type\">switch</data> <data key=\"dpid\">00:00:00:00:00:00:0a:04</data> <data key=\"desc\">OpenFlow Switch at IAH</data> </node> <node id=\"5\"> <data key=\"type\">switch</data> <data key=\"dpid\">00:00:00:00:00:00:0a:05</data> <data key=\"desc\">OpenFlow Switch at NYC</data> </node> <node id=\"6\"> <data key=\"type\">switch</data> <data key=\"dpid\">00:00:00:00:00:00:0a:06</data> <data key=\"desc\">OpenFlow Switch at ATL</data> </node> <node id=\"100\"> <data key=\"type\">port</data> <data key=\"number\">1</data> <data key=\"desc\">port 1 at SEA Switch</data> </node> <node id=\"101\"> <data key=\"type\">port</data> <data key=\"number\">2</data> <data key=\"desc\">port 2 at SEA Switch</data> </node> <node id=\"102\"> <data key=\"type\">port</data> <data key=\"number\">3</data> <data key=\"desc\">port 3 at SEA Switch</data> </node> <node id=\"103\"> <data key=\"type\">port</data> <data key=\"number\">4</data> <data key=\"desc\">port 4 at SEA Switch</data> </node> <node id=\"104\"> <data key=\"type\">port</data> <data key=\"number\">1</data> <data key=\"desc\">port 1 at LAX Switch</data> </node> <node id=\"105\"> <data key=\"type\">port</data> <data key=\"number\">2</data> <data key=\"desc\">port 2 at LAX Switch</data> </node> <node id=\"106\"> <data key=\"type\">port</data> <data key=\"number\">3</data> <data key=\"desc\">port 3 at LAX Switch</data> </node> <node id=\"107\"> <data key=\"type\">port</data> <data key=\"number\">1</data> <data key=\"desc\">port 1 at CHI Switch</data> </node> <node id=\"108\"> <data key=\"type\">port</data> <data key=\"number\">2</data> <data key=\"desc\">port 2 at CHI Switch</data> </node> <node id=\"109\"> <data key=\"type\">port</data> <data key=\"number\">3</data> <data key=\"desc\">port 3 at CHI Switch</data> </node> <node id=\"110\"> <data key=\"type\">port</data> <data key=\"number\">4</data> <data key=\"desc\">port 4 at CHI Switch</data> </node> <node id=\"111\"> <data key=\"type\">port</data> <data key=\"number\">1</data> <data key=\"desc\">port 1 at IAH Switch</data> </node> <node id=\"112\"> <data key=\"type\">port</data> <data key=\"number\">2</data> <data key=\"desc\">port 2 at IAH Switch</data> </node> <node id=\"113\"> <data key=\"type\">port</data> <data key=\"number\">3</data> <data key=\"desc\">port 3 at IAH Switch</data> </node> <node id=\"114\"> <data key=\"type\">port</data> <data key=\"number\">1</data> <data key=\"desc\">port 1 at NYC Switch</data> </node> <node id=\"115\"> <data key=\"type\">port</data> <data key=\"number\">2</data> <data key=\"desc\">port 2 at NYC Switch</data> </node> <node id=\"116\"> <data key=\"type\">port</data> <data key=\"number\">3</data> <data key=\"desc\">port 3 at NYC Switch</data> </node> <node id=\"117\"> <data key=\"type\">port</data> <data key=\"number\">1</data> <data key=\"desc\">port 1 at ATL Switch</data> </node> <node id=\"118\"> <data key=\"type\">port</data> <data key=\"number\">2</data> <data key=\"desc\">port 2 at ATL Switch</data> </node> <node id=\"119\"> <data key=\"type\">port</data> <data key=\"number\">3</data> <data key=\"desc\">port 3 at ATL Switch</data> </node> <node id=\"1000\"> <data key=\"type\">device</data> <data key=\"dl_addr\">20:c9:d0:4a:e1:73</data> <data key=\"nw_addr\">192.168.10.101</data> </node> <node id=\"1001\"> <data key=\"type\">device</data> <data key=\"dl_addr\">20:c9:d0:4a:e1:62</data> <data key=\"nw_addr\">192.168.20.101</data> </node> <node id=\"1002\"> <data key=\"type\">device</data> <data key=\"dl_addr\">10:40:f3:e6:8d:55</data> <data key=\"nw_addr\">192.168.10.1</data> </node> <node id=\"1003\"> <data key=\"type\">device</data> <data key=\"dl_addr\">a0:b3:cc:9c:c6:88</data> <data key=\"nw_addr\">192.168.20.1</data> </node> <node id=\"1004\"> <data key=\"type\">device</data> <data key=\"dl_addr\">00:04:20:e2:50:a2</data> <data key=\"nw_addr\">192.168.30.1</data> </node> <node id=\"1005\"> <data key=\"type\">device</data> <data key=\"dl_addr\">58:55:ca:c4:1b:a0</data> <data key=\"nw_addr\">192.168.40.1</data> </node> <edge id=\"10000\" source=\"1\" target=\"101\" label=\"on\"></edge> <edge id=\"10001\" source=\"1\" target=\"102\" label=\"on\"></edge> <edge id=\"10002\" source=\"1\" target=\"103\" label=\"on\"></edge> <edge id=\"10003\" source=\"2\" target=\"104\" label=\"on\"></edge> <edge id=\"10004\" source=\"2\" target=\"105\" label=\"on\"></edge> <edge id=\"10005\" source=\"2\" target=\"106\" label=\"on\"></edge> <edge id=\"10006\" source=\"3\" target=\"107\" label=\"on\"></edge> <edge id=\"10007\" source=\"3\" target=\"108\" label=\"on\"></edge> <edge id=\"10008\" source=\"3\" target=\"109\" label=\"on\"></edge> <edge id=\"10009\" source=\"3\" target=\"110\" label=\"on\"></edge> <edge id=\"10010\" source=\"4\" target=\"111\" label=\"on\"></edge> <edge id=\"10011\" source=\"4\" target=\"112\" label=\"on\"></edge> <edge id=\"10012\" source=\"4\" target=\"113\" label=\"on\"></edge> <edge id=\"10013\" source=\"5\" target=\"114\" label=\"on\"></edge> <edge id=\"10014\" source=\"5\" target=\"115\" label=\"on\"></edge> <edge id=\"10015\" source=\"5\" target=\"116\" label=\"on\"></edge> <edge id=\"10016\" source=\"6\" target=\"117\" label=\"on\"></edge> <edge id=\"10017\" source=\"6\" target=\"118\" label=\"on\"></edge> <edge id=\"10018\" source=\"6\" target=\"119\" label=\"on\"></edge> <edge id=\"11000\" source=\"101\" target=\"107\" label=\"link\"></edge> <edge id=\"11003\" source=\"105\" target=\"111\" label=\"link\"></edge> <edge id=\"11004\" source=\"107\" target=\"101\" label=\"link\"></edge> <edge id=\"11005\" source=\"108\" target=\"112\" label=\"link\"></edge> <edge id=\"11006\" source=\"109\" target=\"114\" label=\"link\"></edge> <edge id=\"11007\" source=\"111\" target=\"105\" label=\"link\"></edge> <edge id=\"11008\" source=\"112\" target=\"108\" label=\"link\"></edge> <edge id=\"11009\" source=\"113\" target=\"117\" label=\"link\"></edge> <edge id=\"11010\" source=\"114\" target=\"109\" label=\"link\"></edge> <edge id=\"11011\" source=\"115\" target=\"118\" label=\"link\"></edge> <edge id=\"11012\" source=\"117\" target=\"113\" label=\"link\"></edge> <edge id=\"11013\" source=\"118\" target=\"115\" label=\"link\"></edge> <edge id=\"12000\" source=\"103\" target=\"1000\" label=\"host\"></edge> <edge id=\"12001\" source=\"103\" target=\"1001\" label=\"host\"></edge> <edge id=\"12002\" source=\"110\" target=\"1002\" label=\"host\"></edge> <edge id=\"12003\" source=\"116\" target=\"1003\" label=\"host\"></edge> <edge id=\"12004\" source=\"106\" target=\"1004\" label=\"host\"></edge> <edge id=\"12005\" source=\"119\" target=\"1005\" label=\"host\"></edge> </graph> </graphml>";
+
+ private static final String testDataLocation = "titan/schema/test-network.xml";
public static TitanGraph getTestDatabase(){
- return TitanFactory.open(testDbLocation);
+ //return TitanFactory.open(testDbLocation);
+ return TitanFactory.openInMemoryGraph();
}
public static void populateTestData(TitanGraph titanGraph){
@@ -36,13 +41,26 @@
titanGraph.stopTransaction(Conclusion.SUCCESS);
}
- InputStream graphMLStream = new ByteArrayInputStream(testDbGraphML.getBytes());
+ //InputStream graphMLStream = new ByteArrayInputStream(testDbGraphML.getBytes());
+
try {
+ InputStream graphMLStream = new FileInputStream(testDataLocation);
GraphMLReader.inputGraph(titanGraph, graphMLStream);
+ } catch (FileNotFoundException e) {
+ Assert.fail("Test data file not found: " + testDataLocation);
} catch (IOException e) {
e.printStackTrace();
Assert.fail("IOException thrown");
}
+
+ //Change the type of all port numbers to short in the database
+ Iterator<Vertex> it = titanGraph.getVertices("type", "port").iterator();
+ while (it.hasNext()){
+ Vertex port = it.next();
+ Integer portNum = (Integer) port.getProperty("number");
+ port.setProperty("number", portNum.shortValue());
+ }
+ titanGraph.stopTransaction(Conclusion.SUCCESS);
}
public static void deleteTestDatabase(){
diff --git a/src/test/java/net/floodlightcontroller/linkdiscovery/internal/LinkStorageImplTest.java b/src/test/java/net/floodlightcontroller/linkdiscovery/internal/LinkStorageImplTest.java
index 0324a51..1e71138 100644
--- a/src/test/java/net/floodlightcontroller/linkdiscovery/internal/LinkStorageImplTest.java
+++ b/src/test/java/net/floodlightcontroller/linkdiscovery/internal/LinkStorageImplTest.java
@@ -1,9 +1,12 @@
package net.floodlightcontroller.linkdiscovery.internal;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
import java.util.Iterator;
import java.util.List;
-import junit.framework.TestCase;
import net.floodlightcontroller.core.INetMapStorage.DM_OPERATION;
import net.floodlightcontroller.core.internal.TestDatabaseManager;
import net.floodlightcontroller.linkdiscovery.ILinkStorage;
@@ -11,17 +14,14 @@
import org.junit.After;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import com.thinkaurelius.titan.core.TitanGraph;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.gremlin.java.GremlinPipeline;
-public class LinkStorageImplTest extends TestCase {
- //private static final String testDbLocation = "/tmp/onos-testdb";
-
- //private static final String testDbGraphML = "<?xml version=\"1.0\" ?><graphml xmlns=\"http://graphml.graphdrawing.org/xmlns\"> <key id=\"id\" for=\"node\" attr.name=\"id\" attr.type=\"string\"></key> <key id=\"type\" for=\"node\" attr.name=\"type\" attr.type=\"string\"></key> <key id=\"dpid\" for=\"node\" attr.name=\"dpid\" attr.type=\"string\"></key> <key id=\"desc\" for=\"node\" attr.name=\"desc\" attr.type=\"string\"></key> <key id=\"number\" for=\"node\" attr.name=\"number\" attr.type=\"int\"></key> <key id=\"dl_addr\" for=\"node\" attr.name=\"dl_addr\" attr.type=\"string\"></key> <key id=\"nw_addr\" for=\"node\" attr.name=\"nw_addr\" attr.type=\"string\"></key> <key id=\"id\" for=\"edge\" attr.name=\"id\" attr.type=\"string\"></key> <key id=\"source\" for=\"edge\" attr.name=\"source\" attr.type=\"string\"></key> <key id=\"target\" for=\"edge\" attr.name=\"target\" attr.type=\"string\"></key> <key id=\"label\" for=\"edge\" attr.name=\"label\" attr.type=\"string\"></key> <graph id=\"G\" edgedefault=\"directed\"> <node id=\"1\"> <data key=\"type\">switch</data> <data key=\"dpid\">00:00:00:00:00:00:0a:01</data> <data key=\"desc\">OpenFlow Switch at SEA</data> </node> <node id=\"2\"> <data key=\"type\">switch</data> <data key=\"dpid\">00:00:00:00:00:00:0a:02</data> <data key=\"desc\">OpenFlow Switch at LAX</data> </node> <node id=\"3\"> <data key=\"type\">switch</data> <data key=\"dpid\">00:00:00:00:00:00:0a:03</data> <data key=\"desc\">OpenFlow Switch at CHI</data> </node> <node id=\"4\"> <data key=\"type\">switch</data> <data key=\"dpid\">00:00:00:00:00:00:0a:04</data> <data key=\"desc\">OpenFlow Switch at IAH</data> </node> <node id=\"5\"> <data key=\"type\">switch</data> <data key=\"dpid\">00:00:00:00:00:00:0a:05</data> <data key=\"desc\">OpenFlow Switch at NYC</data> </node> <node id=\"6\"> <data key=\"type\">switch</data> <data key=\"dpid\">00:00:00:00:00:00:0a:06</data> <data key=\"desc\">OpenFlow Switch at ATL</data> </node> <node id=\"100\"> <data key=\"type\">port</data> <data key=\"number\">1</data> <data key=\"desc\">port 1 at SEA Switch</data> </node> <node id=\"101\"> <data key=\"type\">port</data> <data key=\"number\">2</data> <data key=\"desc\">port 2 at SEA Switch</data> </node> <node id=\"102\"> <data key=\"type\">port</data> <data key=\"number\">3</data> <data key=\"desc\">port 3 at SEA Switch</data> </node> <node id=\"103\"> <data key=\"type\">port</data> <data key=\"number\">4</data> <data key=\"desc\">port 4 at SEA Switch</data> </node> <node id=\"104\"> <data key=\"type\">port</data> <data key=\"number\">1</data> <data key=\"desc\">port 1 at LAX Switch</data> </node> <node id=\"105\"> <data key=\"type\">port</data> <data key=\"number\">2</data> <data key=\"desc\">port 2 at LAX Switch</data> </node> <node id=\"106\"> <data key=\"type\">port</data> <data key=\"number\">3</data> <data key=\"desc\">port 3 at LAX Switch</data> </node> <node id=\"107\"> <data key=\"type\">port</data> <data key=\"number\">1</data> <data key=\"desc\">port 1 at CHI Switch</data> </node> <node id=\"108\"> <data key=\"type\">port</data> <data key=\"number\">2</data> <data key=\"desc\">port 2 at CHI Switch</data> </node> <node id=\"109\"> <data key=\"type\">port</data> <data key=\"number\">3</data> <data key=\"desc\">port 3 at CHI Switch</data> </node> <node id=\"110\"> <data key=\"type\">port</data> <data key=\"number\">4</data> <data key=\"desc\">port 4 at CHI Switch</data> </node> <node id=\"111\"> <data key=\"type\">port</data> <data key=\"number\">1</data> <data key=\"desc\">port 1 at IAH Switch</data> </node> <node id=\"112\"> <data key=\"type\">port</data> <data key=\"number\">2</data> <data key=\"desc\">port 2 at IAH Switch</data> </node> <node id=\"113\"> <data key=\"type\">port</data> <data key=\"number\">3</data> <data key=\"desc\">port 3 at IAH Switch</data> </node> <node id=\"114\"> <data key=\"type\">port</data> <data key=\"number\">1</data> <data key=\"desc\">port 1 at NYC Switch</data> </node> <node id=\"115\"> <data key=\"type\">port</data> <data key=\"number\">2</data> <data key=\"desc\">port 2 at NYC Switch</data> </node> <node id=\"116\"> <data key=\"type\">port</data> <data key=\"number\">3</data> <data key=\"desc\">port 3 at NYC Switch</data> </node> <node id=\"117\"> <data key=\"type\">port</data> <data key=\"number\">1</data> <data key=\"desc\">port 1 at ATL Switch</data> </node> <node id=\"118\"> <data key=\"type\">port</data> <data key=\"number\">2</data> <data key=\"desc\">port 2 at ATL Switch</data> </node> <node id=\"119\"> <data key=\"type\">port</data> <data key=\"number\">3</data> <data key=\"desc\">port 3 at ATL Switch</data> </node> <node id=\"1000\"> <data key=\"type\">device</data> <data key=\"dl_addr\">20:c9:d0:4a:e1:73</data> <data key=\"nw_addr\">192.168.10.101</data> </node> <node id=\"1001\"> <data key=\"type\">device</data> <data key=\"dl_addr\">20:c9:d0:4a:e1:62</data> <data key=\"nw_addr\">192.168.20.101</data> </node> <node id=\"1002\"> <data key=\"type\">device</data> <data key=\"dl_addr\">10:40:f3:e6:8d:55</data> <data key=\"nw_addr\">192.168.10.1</data> </node> <node id=\"1003\"> <data key=\"type\">device</data> <data key=\"dl_addr\">a0:b3:cc:9c:c6:88</data> <data key=\"nw_addr\">192.168.20.1</data> </node> <node id=\"1004\"> <data key=\"type\">device</data> <data key=\"dl_addr\">00:04:20:e2:50:a2</data> <data key=\"nw_addr\">192.168.30.1</data> </node> <node id=\"1005\"> <data key=\"type\">device</data> <data key=\"dl_addr\">58:55:ca:c4:1b:a0</data> <data key=\"nw_addr\">192.168.40.1</data> </node> <edge id=\"10000\" source=\"1\" target=\"101\" label=\"on\"></edge> <edge id=\"10001\" source=\"1\" target=\"102\" label=\"on\"></edge> <edge id=\"10002\" source=\"1\" target=\"103\" label=\"on\"></edge> <edge id=\"10003\" source=\"2\" target=\"104\" label=\"on\"></edge> <edge id=\"10004\" source=\"2\" target=\"105\" label=\"on\"></edge> <edge id=\"10005\" source=\"2\" target=\"106\" label=\"on\"></edge> <edge id=\"10006\" source=\"3\" target=\"107\" label=\"on\"></edge> <edge id=\"10007\" source=\"3\" target=\"108\" label=\"on\"></edge> <edge id=\"10008\" source=\"3\" target=\"109\" label=\"on\"></edge> <edge id=\"10009\" source=\"3\" target=\"110\" label=\"on\"></edge> <edge id=\"10010\" source=\"4\" target=\"111\" label=\"on\"></edge> <edge id=\"10011\" source=\"4\" target=\"112\" label=\"on\"></edge> <edge id=\"10012\" source=\"4\" target=\"113\" label=\"on\"></edge> <edge id=\"10013\" source=\"5\" target=\"114\" label=\"on\"></edge> <edge id=\"10014\" source=\"5\" target=\"115\" label=\"on\"></edge> <edge id=\"10015\" source=\"5\" target=\"116\" label=\"on\"></edge> <edge id=\"10016\" source=\"6\" target=\"117\" label=\"on\"></edge> <edge id=\"10017\" source=\"6\" target=\"118\" label=\"on\"></edge> <edge id=\"10018\" source=\"6\" target=\"119\" label=\"on\"></edge> <edge id=\"11000\" source=\"101\" target=\"107\" label=\"link\"></edge> <edge id=\"11003\" source=\"105\" target=\"111\" label=\"link\"></edge> <edge id=\"11004\" source=\"107\" target=\"101\" label=\"link\"></edge> <edge id=\"11005\" source=\"108\" target=\"112\" label=\"link\"></edge> <edge id=\"11006\" source=\"109\" target=\"114\" label=\"link\"></edge> <edge id=\"11007\" source=\"111\" target=\"105\" label=\"link\"></edge> <edge id=\"11008\" source=\"112\" target=\"108\" label=\"link\"></edge> <edge id=\"11009\" source=\"113\" target=\"117\" label=\"link\"></edge> <edge id=\"11010\" source=\"114\" target=\"109\" label=\"link\"></edge> <edge id=\"11011\" source=\"115\" target=\"118\" label=\"link\"></edge> <edge id=\"11012\" source=\"117\" target=\"113\" label=\"link\"></edge> <edge id=\"11013\" source=\"118\" target=\"115\" label=\"link\"></edge> <edge id=\"12000\" source=\"103\" target=\"1000\" label=\"host\"></edge> <edge id=\"12001\" source=\"103\" target=\"1001\" label=\"host\"></edge> <edge id=\"12002\" source=\"110\" target=\"1002\" label=\"host\"></edge> <edge id=\"12003\" source=\"116\" target=\"1003\" label=\"host\"></edge> <edge id=\"12004\" source=\"106\" target=\"1004\" label=\"host\"></edge> <edge id=\"12005\" source=\"119\" target=\"1005\" label=\"host\"></edge> </graph> </graphml>";
-
+public class LinkStorageImplTest {
private static ILinkStorage linkStorage;
private static TitanGraph titanGraph;
@@ -31,38 +31,16 @@
@Before
public void setUp() throws Exception{
- super.setUp();
- TestDatabaseManager.deleteTestDatabase();
-
- //titanGraph = TitanFactory.open(testDbLocation);
titanGraph = TestDatabaseManager.getTestDatabase();
TestDatabaseManager.populateTestData(titanGraph);
linkStorage = new TestableLinkStorageImpl(titanGraph);
}
- /*
- private void populateTestData(){
- Set<String> s = titanGraph.getIndexedKeys(Vertex.class);
- if (!s.contains("dpid")) {
- titanGraph.createKeyIndex("dpid", Vertex.class);
- titanGraph.stopTransaction(Conclusion.SUCCESS);
- }
- if (!s.contains("type")) {
- titanGraph.createKeyIndex("type", Vertex.class);
- titanGraph.stopTransaction(Conclusion.SUCCESS);
- }
-
- InputStream graphMLStream = new ByteArrayInputStream(testDbGraphML.getBytes());
- try {
- GraphMLReader.inputGraph(titanGraph, graphMLStream);
- } catch (IOException e) {
- e.printStackTrace();
- Assert.fail("IOException thrown");
- }
-
+ @After
+ public void tearDown() throws Exception {
+ titanGraph.shutdown();
}
- */
/*
* Add a link between port 1.102 and 2.104
@@ -83,7 +61,7 @@
Vertex sw1 = it.next();
assertFalse(it.hasNext());
- pipe.start(sw1).out("on").has("number", 3).out("link").in("on");
+ pipe.start(sw1).out("on").has("number", (short)3).out("link").in("on");
assertTrue(pipe.hasNext());
Vertex sw2 = pipe.next();
@@ -93,7 +71,8 @@
assertEquals((String)sw2.getProperty("dpid"), "00:00:00:00:00:00:0a:02");
}
- @Test
+ //TODO enable once method is written
+ @Ignore @Test
public void testGetLinks(){
//TODO Make sure this works when the implementation is written
List<Link> list = linkStorage.getLinks(Long.decode("0x0000000000000a01"), (short)2);
@@ -107,9 +86,9 @@
assertEquals(l.getDstPort(), (short)1);
}
- @Test
+ //TODO enable once method is written
+ @Ignore @Test
public void testUpdateDelete(){
- //TODO Make sure this works when the implementation is written
Link linkToDelete = new Link(Long.decode("0x0000000000000a01"), 2, Long.decode("0x0000000000000a03"), 1);
linkStorage.update(linkToDelete, DM_OPERATION.DELETE);
@@ -127,7 +106,8 @@
assertFalse(pipe.hasNext());
}
- @Test
+ //TODO enable once method is written
+ @Ignore @Test
public void testDeleteLinks(){
//TODO Make sure this works when the implementation is written
@@ -146,21 +126,4 @@
assertFalse(pipe.hasNext());
}
- @After
- public void tearDown() throws Exception {
- super.tearDown();
- //TODO Reenable this once the tests are written. It's good to clean up afterwards.
- //TestDatabaseManager.deleteTestDatabase();
- }
-
- /*
- private void deleteTestDatabase(){
- try {
- FileUtils.deleteDirectory(new File(testDbLocation));
- } catch (IOException e) {
- System.out.println("delete failed");
- e.printStackTrace();
- }
- }
- */
}
diff --git a/titan/schema/test-network.xml b/titan/schema/test-network.xml
new file mode 100644
index 0000000..a03a99c
--- /dev/null
+++ b/titan/schema/test-network.xml
@@ -0,0 +1,237 @@
+<?xml version="1.0" ?>
+<graphml xmlns="http://graphml.graphdrawing.org/xmlns">
+
+ <key id="id" for="node" attr.name="id" attr.type="string"></key>
+ <key id="type" for="node" attr.name="type" attr.type="string"></key>
+ <key id="dpid" for="node" attr.name="dpid" attr.type="string"></key>
+ <key id="desc" for="node" attr.name="desc" attr.type="string"></key>
+ <key id="number" for="node" attr.name="number" attr.type="int"></key>
+ <key id="dl_addr" for="node" attr.name="dl_addr" attr.type="string"></key>
+ <key id="nw_addr" for="node" attr.name="nw_addr" attr.type="string"></key>
+ <key id="id" for="edge" attr.name="id" attr.type="string"></key>
+ <key id="source" for="edge" attr.name="source" attr.type="string"></key>
+ <key id="target" for="edge" attr.name="target" attr.type="string"></key>
+ <key id="label" for="edge" attr.name="label" attr.type="string"></key>
+
+ <graph id="G" edgedefault="directed">
+ <node id="1">
+ <data key="type">switch</data>
+ <data key="dpid">00:00:00:00:00:00:0a:01</data>
+ <data key="desc">OpenFlow Switch at SEA</data>
+ </node>
+ <node id="2">
+ <data key="type">switch</data>
+ <data key="dpid">00:00:00:00:00:00:0a:02</data>
+ <data key="desc">OpenFlow Switch at LAX</data>
+ </node>
+ <node id="3">
+ <data key="type">switch</data>
+ <data key="dpid">00:00:00:00:00:00:0a:03</data>
+ <data key="desc">OpenFlow Switch at CHI</data>
+ </node>
+ <node id="4">
+ <data key="type">switch</data>
+ <data key="dpid">00:00:00:00:00:00:0a:04</data>
+ <data key="desc">OpenFlow Switch at IAH</data>
+ </node>
+ <node id="5">
+ <data key="type">switch</data>
+ <data key="dpid">00:00:00:00:00:00:0a:05</data>
+ <data key="desc">OpenFlow Switch at NYC</data>
+ </node>
+ <node id="6">
+ <data key="type">switch</data>
+ <data key="dpid">00:00:00:00:00:00:0a:06</data>
+ <data key="desc">OpenFlow Switch at ATL</data>
+ </node>
+
+ <node id="100">
+ <data key="type">port</data>
+ <data key="number">1</data>
+ <data key="desc">port 1 at SEA Switch</data>
+ </node>
+ <node id="101">
+ <data key="type">port</data>
+ <data key="number">2</data>
+ <data key="desc">port 2 at SEA Switch</data>
+ </node>
+ <node id="102">
+ <data key="type">port</data>
+ <data key="number">3</data>
+ <data key="desc">port 3 at SEA Switch</data>
+ </node>
+ <node id="103">
+ <data key="type">port</data>
+ <data key="number">4</data>
+ <data key="desc">port 4 at SEA Switch</data>
+ </node>
+
+ <node id="104">
+ <data key="type">port</data>
+ <data key="number">1</data>
+ <data key="desc">port 1 at LAX Switch</data>
+ </node>
+ <node id="105">
+ <data key="type">port</data>
+ <data key="number">2</data>
+ <data key="desc">port 2 at LAX Switch</data>
+ </node>
+ <node id="106">
+ <data key="type">port</data>
+ <data key="number">3</data>
+ <data key="desc">port 3 at LAX Switch</data>
+ </node>
+
+ <node id="107">
+ <data key="type">port</data>
+ <data key="number">1</data>
+ <data key="desc">port 1 at CHI Switch</data>
+ </node>
+ <node id="108">
+ <data key="type">port</data>
+ <data key="number">2</data>
+ <data key="desc">port 2 at CHI Switch</data>
+ </node>
+ <node id="109">
+ <data key="type">port</data>
+ <data key="number">3</data>
+ <data key="desc">port 3 at CHI Switch</data>
+ </node>
+ <node id="110">
+ <data key="type">port</data>
+ <data key="number">4</data>
+ <data key="desc">port 4 at CHI Switch</data>
+ </node>
+
+ <node id="111">
+ <data key="type">port</data>
+ <data key="number">1</data>
+ <data key="desc">port 1 at IAH Switch</data>
+ </node>
+ <node id="112">
+ <data key="type">port</data>
+ <data key="number">2</data>
+ <data key="desc">port 2 at IAH Switch</data>
+ </node>
+ <node id="113">
+ <data key="type">port</data>
+ <data key="number">3</data>
+ <data key="desc">port 3 at IAH Switch</data>
+ </node>
+
+ <node id="114">
+ <data key="type">port</data>
+ <data key="number">1</data>
+ <data key="desc">port 1 at NYC Switch</data>
+ </node>
+ <node id="115">
+ <data key="type">port</data>
+ <data key="number">2</data>
+ <data key="desc">port 2 at NYC Switch</data>
+ </node>
+ <node id="116">
+ <data key="type">port</data>
+ <data key="number">3</data>
+ <data key="desc">port 3 at NYC Switch</data>
+ </node>
+
+ <node id="117">
+ <data key="type">port</data>
+ <data key="number">1</data>
+ <data key="desc">port 1 at ATL Switch</data>
+ </node>
+ <node id="118">
+ <data key="type">port</data>
+ <data key="number">2</data>
+ <data key="desc">port 2 at ATL Switch</data>
+ </node>
+ <node id="119">
+ <data key="type">port</data>
+ <data key="number">3</data>
+ <data key="desc">port 3 at ATL Switch</data>
+ </node>
+
+ <node id="1000">
+ <data key="type">device</data>
+ <data key="dl_addr">20:c9:d0:4a:e1:73</data>
+ <data key="nw_addr">192.168.10.101</data>
+ </node>
+ <node id="1001">
+ <data key="type">device</data>
+ <data key="dl_addr">20:c9:d0:4a:e1:62</data>
+ <data key="nw_addr">192.168.20.101</data>
+ </node>
+ <node id="1002">
+ <data key="type">device</data>
+ <data key="dl_addr">10:40:f3:e6:8d:55</data>
+ <data key="nw_addr">192.168.10.1</data>
+ </node>
+ <node id="1003">
+ <data key="type">device</data>
+ <data key="dl_addr">a0:b3:cc:9c:c6:88</data>
+ <data key="nw_addr">192.168.20.1</data>
+ </node>
+ <node id="1004">
+ <data key="type">device</data>
+ <data key="dl_addr">00:04:20:e2:50:a2</data>
+ <data key="nw_addr">192.168.30.1</data>
+ </node>
+ <node id="1005">
+ <data key="type">device</data>
+ <data key="dl_addr">58:55:ca:c4:1b:a0</data>
+ <data key="nw_addr">192.168.40.1</data>
+ </node>
+
+ <edge id="10000" source="1" target="101" label="on"></edge>
+ <edge id="10001" source="1" target="102" label="on"></edge>
+ <edge id="10002" source="1" target="103" label="on"></edge>
+
+ <edge id="10003" source="2" target="104" label="on"></edge>
+ <edge id="10004" source="2" target="105" label="on"></edge>
+ <edge id="10005" source="2" target="106" label="on"></edge>
+
+ <edge id="10006" source="3" target="107" label="on"></edge>
+ <edge id="10007" source="3" target="108" label="on"></edge>
+ <edge id="10008" source="3" target="109" label="on"></edge>
+ <edge id="10009" source="3" target="110" label="on"></edge>
+
+ <edge id="10010" source="4" target="111" label="on"></edge>
+ <edge id="10011" source="4" target="112" label="on"></edge>
+ <edge id="10012" source="4" target="113" label="on"></edge>
+
+ <edge id="10013" source="5" target="114" label="on"></edge>
+ <edge id="10014" source="5" target="115" label="on"></edge>
+ <edge id="10015" source="5" target="116" label="on"></edge>
+
+ <edge id="10016" source="6" target="117" label="on"></edge>
+ <edge id="10017" source="6" target="118" label="on"></edge>
+ <edge id="10018" source="6" target="119" label="on"></edge>
+
+ <edge id="11000" source="101" target="107" label="link"></edge>
+ <!--<edge id="11001" source="102" target="104" label="link"></edge>-->
+
+ <edge id="11002" source="104" target="102" label="link"></edge>
+ <edge id="11003" source="105" target="111" label="link"></edge>
+
+ <edge id="11004" source="107" target="101" label="link"></edge>
+ <edge id="11005" source="108" target="112" label="link"></edge>
+ <edge id="11006" source="109" target="114" label="link"></edge>
+
+ <edge id="11007" source="111" target="105" label="link"></edge>
+ <edge id="11008" source="112" target="108" label="link"></edge>
+ <edge id="11009" source="113" target="117" label="link"></edge>
+
+ <edge id="11010" source="114" target="109" label="link"></edge>
+ <edge id="11011" source="115" target="118" label="link"></edge>
+
+ <edge id="11012" source="117" target="113" label="link"></edge>
+ <edge id="11013" source="118" target="115" label="link"></edge>
+
+ <edge id="12000" source="103" target="1000" label="host"></edge>
+ <edge id="12001" source="103" target="1001" label="host"></edge>
+ <edge id="12002" source="110" target="1002" label="host"></edge>
+ <edge id="12003" source="116" target="1003" label="host"></edge>
+ <edge id="12004" source="106" target="1004" label="host"></edge>
+ <edge id="12005" source="119" target="1005" label="host"></edge>
+ </graph>
+</graphml>
\ No newline at end of file
diff --git a/web/restapi3.py b/web/restapi3.py
index ea070f5..e1b1c04 100755
--- a/web/restapi3.py
+++ b/web/restapi3.py
@@ -1,5 +1,5 @@
#! /usr/bin/env python
-
+import pprint
import os
import sys
import subprocess
@@ -13,7 +13,10 @@
## Global Var ##
RestIP="127.0.0.1"
RestPort=8182
-DBName="network-map"
+DBName="onos-network-map"
+
+DEBUG=1
+pp = pprint.PrettyPrinter(indent=4)
app = Flask(__name__)
@@ -21,6 +24,10 @@
def log_error(txt):
print '%s' % (txt)
+def debug(txt):
+ if DEBUG:
+ print '%s' % (txt)
+
def portV_to_dpid(vertex):
try:
command = "curl -s http://%s:%s/graphs/%s/vertices/%d/in" % (RestIP, RestPort, DBName, vertex)
@@ -30,8 +37,10 @@
log_error("REST IF has issue")
exit
+ debug("portV_to_dpid %s" % command)
+ debug("parsed %s" % parsedResult)
for v in parsedResult:
- if v['type'] == "switch":
+ if v.has_key('type') and v['type'] == "switch":
sw_dpid = v['dpid']
break
@@ -46,7 +55,8 @@
log_error("REST IF has issue")
exit
- if parsedResult['type'] != "switch":
+ debug("switchV_to_dpid %s" % command)
+ if not parsedResult.has_key("type") or parsedResult['type'] != "switch":
print "not a switch vertex"
exit
else:
@@ -63,6 +73,7 @@
log_error("REST IF has issue")
exit
+ debug("portV_to_port_dpid %s" % command)
port_number = parsedResult['number']
switch_dpid = portV_to_dpid(vertex)
@@ -178,7 +189,7 @@
@app.route("/wm/core/controller/switches/json")
def query_switch():
try:
- command = "curl -s http://%s:%s/graphs/%s/vertices\?key=type\&value=switch" % (RestIP, RestPort, DBName)
+ command = "curl -s \'http://%s:%s/graphs/%s/vertices?key=type&value=switch\'" % (RestIP, RestPort, DBName)
result = os.popen(command).read()
parsedResult = json.loads(result)['results']
except:
@@ -187,12 +198,16 @@
switches_ = []
for v in parsedResult:
- dpid = str(v['dpid']) ;# removing quotation
- sw = {}
- sw['dpid']=dpid
- switches_.append(sw)
+ if v.has_key('dpid'):
+# if v.has_key('dpid') and str(v['state']) == "ACTIVE":#;if you want only ACTIVE nodes
+ dpid = str(v['dpid'])
+ state = str(v['state'])
+ sw = {}
+ sw['dpid']=dpid
+ sw['active']=state
+ switches_.append(sw)
- print switches_
+ pp.pprint(switches_)
js = json.dumps(switches_)
resp = Response(js, status=200, mimetype='application/json')
return resp
@@ -200,41 +215,46 @@
@app.route("/wm/topology/links/json")
def query_links():
try:
- command = "curl -s http://%s:%s/graphs/%s/vertices?key=type\&value=port" % (RestIP, RestPort, DBName)
+ command = 'curl -s http://%s:%s/graphs/%s/vertices?key=type\&value=port' % (RestIP, RestPort, DBName)
result = os.popen(command).read()
parsedResult = json.loads(result)['results']
except:
log_error("REST IF has issue")
exit
+ debug("query_links %s" % command)
+ pp.pprint(parsedResult)
sport = []
- switches_ = []
+ links = []
for v in parsedResult:
srcport = v['_id']
try:
command = "curl -s http://%s:%s/graphs/%s/vertices/%d/out?_label=link" % (RestIP, RestPort, DBName, srcport)
+ print command
result = os.popen(command).read()
linkResults = json.loads(result)['results']
except:
log_error("REST IF has issue")
exit
+ # print linkResults
for p in linkResults:
- dstport = p['_id']
- (sport, sdpid) = portV_to_port_dpid(srcport)
- (dport, ddpid) = portV_to_port_dpid(dstport)
- link = {}
- link["src-switch"]=sdpid
- link["src-port"]=sport
- link["src-port-state"]=0
- link["dst-switch"]=ddpid
- link["dst-port"]=dport
- link["dst-port-state"]=0
- link["type"]="internal"
- switches_.append(link)
+ if p.has_key('type') and p['type'] == "port":
+ dstport = p['_id']
+ (sport, sdpid) = portV_to_port_dpid(srcport)
+ (dport, ddpid) = portV_to_port_dpid(dstport)
+ link = {}
+ link["src-switch"]=sdpid
+ link["src-port"]=sport
+ link["src-port-state"]=0
+ link["dst-switch"]=ddpid
+ link["dst-port"]=dport
+ link["dst-port-state"]=0
+ link["type"]="internal"
+ links.append(link)
- print switches_
- js = json.dumps(switches_)
+ pp.pprint(links)
+ js = json.dumps(links)
resp = Response(js, status=200, mimetype='application/json')
return resp