Add JavaDoc comment for test code.
diff --git a/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkStorageImpl.java b/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkStorageImpl.java
index 015514e..2a4c2b9 100644
--- a/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkStorageImpl.java
+++ b/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkStorageImpl.java
@@ -84,55 +84,13 @@
}
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 if (op.equals(DM_OPERATION.UPDATE)) {
- // TODO: update linkinfo
- // GraphDB seems to have no KeyIndex for LinkInfo data
-
- // BEGIN: trial code (update implementation)
- if(linkinfo != null) {
- vportSrc.setPortState(linkinfo.getSrcPortState());
- vportDst.setPortState(linkinfo.getDstPortState());
-
- Vertex vsrc = vportSrc.asVertex();
- vsrc.setProperty("first_seen_time", linkinfo.getFirstSeenTime());
- vsrc.setProperty("last_lldp_received_time", linkinfo.getUnicastValidTime());
- vsrc.setProperty("last_bddp_received_time", linkinfo.getMulticastValidTime());
-
-// for(Edge e: vportSrc.asVertex().getEdges(Direction.OUT)) {
-// if(e.getVertex(Direction.OUT).equals(vportDst.asVertex())) {
-// e.setProperty("first_seen_time", linkinfo.getFirstSeenTime());
-// e.setProperty("last_lldp_received_time", linkinfo.getUnicastValidTime());
-// e.setProperty("last_bddp_received_time", linkinfo.getMulticastValidTime());
-// }
-// }
-
- conn.endTx(Transaction.COMMIT);
- log.debug("addOrUpdateLink(): link updated {} {} src {} dst {}", new Object[]{op, lt, vportSrc, vportDst});
- }
- // END: trial code
}
} else {
- if (op.equals(DM_OPERATION.UPDATE)) {
- log.debug("addOrUpdateLink(): failed link doesn't exist {} {} src {} dst {}",
- new Object[]{op, lt, vportSrc, vportDst});
- } else {
- vportSrc.setLinkPort(vportDst);
-
- // BEGIN: trial code (update implementation)
- if(linkinfo != null) {
- vportSrc.setPortState(linkinfo.getSrcPortState());
- vportDst.setPortState(linkinfo.getDstPortState());
-
- Vertex vsrc = vportSrc.asVertex();
- vsrc.setProperty("first_seen_time", linkinfo.getFirstSeenTime());
- vsrc.setProperty("last_lldp_received_time", linkinfo.getUnicastValidTime());
- vsrc.setProperty("last_bddp_received_time", linkinfo.getMulticastValidTime());
- }
- // END: trial code
- }
+ vportSrc.setLinkPort(vportDst);
conn.endTx(Transaction.COMMIT);
log.debug("updateLink(): link added {} {} src {} dst {}", new Object[]{op, lt, vportSrc, vportDst});
@@ -191,13 +149,6 @@
}*/
vportSrc.removeLink(vportDst);
- // BEGIN: trial code (update implementation)
- Vertex vsrc = vportSrc.asVertex();
- vsrc.removeProperty("first_seen_time");
- vsrc.removeProperty("last_lldp_received_time");
- vsrc.removeProperty("last_bddp_received_time");
- // END: trial code
-
conn.endTx(Transaction.COMMIT);
log.debug("deleteLink(): deleted edges src {} dst {}", new Object[]{
lt, vportSrc, vportDst});
@@ -264,19 +215,23 @@
}
}
+ // TODO: Fix me
@Override
public List<Link> getLinks(String dpid) {
GraphDBConnection conn = GraphDBConnection.getInstance(this.conf);
ISwitchObject vswitch;
List<Link> links = new ArrayList<Link>();
+ // BEGIN: Trial code
+ // author: Naoki Shiota
vswitch = conn.utils().searchSwitch(conn, dpid);
for(IPortObject vportSrc : vswitch.getPorts()) {
- // TODO array concatenation may be heavy
+ // array concatenation may be heavy...
List<Link> sublinks = getLinks(HexString.toLong(dpid), vportSrc.getNumber());
links.addAll(sublinks);
}
+ // END: Trial code
return links;
}
diff --git a/src/main/java/net/onrc/onos/util/GraphDBConnection.java b/src/main/java/net/onrc/onos/util/GraphDBConnection.java
index 7041329..478763c 100644
--- a/src/main/java/net/onrc/onos/util/GraphDBConnection.java
+++ b/src/main/java/net/onrc/onos/util/GraphDBConnection.java
@@ -7,7 +7,6 @@
import com.thinkaurelius.titan.core.TitanFactory;
import com.thinkaurelius.titan.core.TitanGraph;
-import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.TransactionalGraph;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.util.wrappers.event.EventTransactionalGraph;
@@ -73,43 +72,6 @@
Vertex.class);
}
- // BEGIN: trial code
- /*
- * Trial to store link state information as properties of port.
- * Currently no need to be implemented. Just reference.
- */
- // These keys are assigned to port vertex with "OUT" direction link
-// if (!s_vertices.contains("first_seen_time")) {
-// graph.createKeyIndex("first_seen_time", Vertex.class);
-// }
-// if (!s_vertices.contains("last_lldp_received_time")) {
-// graph.createKeyIndex("last_lldp_received_time", Vertex.class);
-// }
-// if (!s_vertices.contains("last_bddp_received_time")) {
-// graph.createKeyIndex("last_bddp_received_time", Vertex.class);
-// }
-//
-//
-// Set<String> s_edges = graph.getIndexedKeys(Edge.class);
-// if (!s_edges.contains("src_port_state")) {
-// graph.createKeyIndex("src_port_state",
-// Edge.class);
-// }
-// if (!s_edges.contains("dst_port_state")) {
-// graph.createKeyIndex("dst_port_state",
-// Edge.class);
-// }
-// if (!s_edges.contains("first_seen_time")) {
-// graph.createKeyIndex("first_seen_time", Edge.class);
-// }
-// if (!s_edges.contains("last_lldp_received_time")) {
-// graph.createKeyIndex("last_lldp_received_time", Edge.class);
-// }
-// if (!s_edges.contains("last_bddp_received_time")) {
-// graph.createKeyIndex("last_bddp_received_time", Edge.class);
-// }
- // END: trial code
-
graph.commit();
eg = new EventTransactionalGraph<TitanGraph>(graph);
}
diff --git a/src/test/java/net/floodlightcontroller/linkdiscovery/internal/LinkStorageImplTest.java b/src/test/java/net/floodlightcontroller/linkdiscovery/internal/LinkStorageImplTest.java
index 39221ab..6f62f76 100644
--- a/src/test/java/net/floodlightcontroller/linkdiscovery/internal/LinkStorageImplTest.java
+++ b/src/test/java/net/floodlightcontroller/linkdiscovery/internal/LinkStorageImplTest.java
@@ -85,6 +85,9 @@
}
// TODO: remove @Ignore after UPDATE method is implemented
+ /**
+ * Test if update() can correctly updates LinkInfo for a Link.
+ */
@Ignore @Test
public void testUpdate_UpdateSingleLink() {
Link linkToUpdate= createExistingLink();
@@ -97,6 +100,9 @@
doTestLinkHasStateOf(linkToUpdate, infoToVerify);
}
+ /**
+ * Test if update() can correctly creates a Link.
+ */
@Test
public void testUpdate_CreateSingleLink() {
Link linkToCreate = createFeasibleLink();
@@ -114,6 +120,9 @@
doTestLinkIsInGraph(linkToVerify);
}
+ /**
+ * Test if update() can correctly inserts a Link.
+ */
@Test
public void testUpdate_InsertSingleLink(){
Link linkToInsert = createFeasibleLink();
@@ -132,6 +141,9 @@
doTestLinkIsInGraph(linkToVerify);
}
+ /**
+ * Test if update() can correctly deletes a Link.
+ */
@Test
public void testUpdate_DeleteSingleLink(){
Link linkToDelete = createExistingLink();
@@ -148,7 +160,10 @@
linkStorage.update(linkToDelete, DM_OPERATION.DELETE);
doTestLinkIsNotInGraph(linkToVerify);
}
-
+
+ /**
+ * Test if update() can correctly creates multiple Links.
+ */
@Test
public void testUpdate_CreateLinks(){
List<Link> linksToCreate = createFeasibleLinks();
@@ -168,6 +183,9 @@
}
}
+ /**
+ * Test if update() can handle mixture of normal/abnormal input for creation of Links.
+ */
@Test
public void testUpdate_CreateLinks_Mixuture(){
List<Link> linksToCreate = new ArrayList<Link>();
@@ -180,6 +198,9 @@
doTestLinkIsInGraph(createExistingLink());
}
+ /**
+ * Test if update() can correctly inserts multiple Links.
+ */
@Test
public void testUpdate_InsertLinks(){
List<Link> linksToInsert = createFeasibleLinks();
@@ -199,6 +220,9 @@
}
}
+ /**
+ * Test if update() can handle mixture of normal/abnormal input for creation of Links.
+ */
@Test
public void testUpdate_InsertLinks_Mixuture(){
List<Link> linksToInsert = new ArrayList<Link>();
@@ -211,7 +235,9 @@
doTestLinkIsInGraph(createExistingLink());
}
-
+ /**
+ * Test if update() can correctly deletes multiple Links.
+ */
@Test
public void testUpdate_DeleteLinks(){
List<Link> linksToDelete = createExistingLinks();
@@ -231,6 +257,9 @@
}
}
+ /**
+ * Test if update() can handle mixture of normal/abnormal input for deletion of Links.
+ */
@Test
public void testUpdate_DeleteLinks_Mixuture(){
List<Link> linksToDelete = new ArrayList<Link>();
@@ -244,71 +273,86 @@
}
// TODO: remove @Ignore after UPDATE method is implemented
+ /**
+ * Test if updateLink() can correctly updates LinkInfo for a Link.
+ */
@Ignore @Test
- public void testAddOrUpdateLink_Update() {
+ public void testUpdateLink_Update() {
Link linkToUpdate= createExistingLink();
long currentTime = System.currentTimeMillis();
LinkInfo infoToUpdate = createFeasibleLinkInfo(currentTime);
LinkInfo infoToVerify = createFeasibleLinkInfo(currentTime);
- linkStorage.addOrUpdateLink(linkToUpdate, infoToUpdate, ILinkStorage.DM_OPERATION.UPDATE);
+ linkStorage.updateLink(linkToUpdate, infoToUpdate, ILinkStorage.DM_OPERATION.UPDATE);
doTestLinkHasStateOf(linkToUpdate, infoToVerify);
}
+ /**
+ * Test if updateLink() can correctly creates a Link.
+ */
@Test
- public void testAddOrUpdateLink_Create() {
+ public void testUpdateLink_Create() {
Link linkToCreate = createFeasibleLink();
Link linkToVerify = createFeasibleLink();
//Use the link storage API to add the link
- linkStorage.addOrUpdateLink(linkToCreate, null, ILinkStorage.DM_OPERATION.CREATE);
+ linkStorage.updateLink(linkToCreate, null, ILinkStorage.DM_OPERATION.CREATE);
doTestLinkIsInGraph(linkToVerify);
// Add same link
Link linkToCreateTwice = createFeasibleLink();
- linkStorage.addOrUpdateLink(linkToCreateTwice, null, ILinkStorage.DM_OPERATION.CREATE);
+ linkStorage.updateLink(linkToCreateTwice, null, ILinkStorage.DM_OPERATION.CREATE);
// this occurs assertion failure if there are two links in titanGraph
doTestLinkIsInGraph(linkToVerify);
}
+ /**
+ * Test if updateLink() can correctly inserts a Link.
+ */
@Test
- public void testAddOrUpdateLink_Insert() {
+ public void testUpdateLink_Insert() {
Link linkToInsert = createFeasibleLink();
Link linkToVerify = createFeasibleLink();
//Use the link storage API to add the link
- linkStorage.addOrUpdateLink(linkToInsert, null, ILinkStorage.DM_OPERATION.INSERT);
+ linkStorage.updateLink(linkToInsert, null, ILinkStorage.DM_OPERATION.INSERT);
doTestLinkIsInGraph(linkToVerify);
// Add same link
Link linkToInsertTwice = createFeasibleLink();
- linkStorage.addOrUpdateLink(linkToInsertTwice, null, ILinkStorage.DM_OPERATION.INSERT);
+ linkStorage.updateLink(linkToInsertTwice, null, ILinkStorage.DM_OPERATION.INSERT);
// this occurs assertion failure if there are two links in titanGraph
doTestLinkIsInGraph(linkToVerify);
}
// TODO: Check if addOrUpdateLink() should accept DELETE operation. If not, remove this test.
+ /**
+ * Test if updateLink() can correctly deletes a Link.
+ */
@Ignore @Test
- public void testAddOrUpdateLink_Delete() {
+ public void testUpdateLink_Delete() {
Link linkToDelete = createExistingLink();
Link linkToVerify = createExistingLink();
// Test deletion of existing link
- linkStorage.addOrUpdateLink(linkToDelete, null, DM_OPERATION.DELETE);
+ linkStorage.updateLink(linkToDelete, null, DM_OPERATION.DELETE);
doTestLinkIsNotInGraph(linkToVerify);
linkToDelete = createFeasibleLink();
linkToVerify = createFeasibleLink();
// Test deletion of not-existing link
- linkStorage.addOrUpdateLink(linkToDelete, null, DM_OPERATION.DELETE);
+ linkStorage.updateLink(linkToDelete, null, DM_OPERATION.DELETE);
doTestLinkIsNotInGraph(linkToVerify);
}
+ /**
+ * Test if getLinks() can correctly return Links connected to specific DPID and port.
+ */
@Test
public void testGetLinks_ByDpidPort(){
Link linkToVerify = createExistingLink();
@@ -332,6 +376,9 @@
assertEquals(list2.size(), 0);
}
+ /**
+ * Test if getLinks() can correctly return Links connected to specific MAC address.
+ */
@Test
public void testGetLinks_ByString() {
Link linkToVeryfy = createExistingLink();
@@ -344,6 +391,9 @@
assertFalse(links.contains(linkToVerifyNot));
}
+ /**
+ * Test if deleteLink() can correctly delete a Link.
+ */
@Test
public void testDeleteLink() {
// Deletion of existing link
@@ -361,6 +411,9 @@
doTestLinkIsNotInGraph(linkToVerify);
}
+ /**
+ * Test if deleteLinks() can correctly delete Links.
+ */
@Test
public void testDeleteLinks(){
List<Link> linksToDelete = createExistingLinks();
@@ -372,6 +425,9 @@
}
}
+ /**
+ * Test if deleteLinks() can handle mixture of normal/abnormal input.
+ */
@Test
public void testDeleteLinks_Mixture(){
List<Link> linksToDelete = new ArrayList<Link>();
@@ -384,6 +440,9 @@
doTestLinkIsNotInGraph(createExistingLink());
}
+ /**
+ * Test if getActiveLinks() can correctly return active Links.
+ */
@Test
public void testGetActiveLinks() {
Link existingLink = createExistingLink();
@@ -395,6 +454,9 @@
assertFalse(links.contains(notExistingLink));
}
+ /**
+ * Test if deleteLinksOnPort() can delete Links.
+ */
@Test
public void testDeleteLinksOnPort() {
Link linkToDelete = createExistingLink();
@@ -501,21 +563,7 @@
assertFalse(pipe.hasNext());
// TODO: implement test code to check if update is correctly done.
- int portStateSrc = edge.getVertex(Direction.OUT).getProperty("port_state");
- int portStateDst = edge.getVertex(Direction.IN).getProperty("port_state");
-
- assertTrue(portStateSrc == info.getSrcPortState());
- assertTrue(portStateDst == info.getDstPortState());
-
-// long firstSeenTime = edge.getProperty("first_seen_time");
-// long lastLldpReceivedTime = edge.getProperty("last_lldp_received_time");
-// long lastBddpReceivedTime = edge.getProperty("last_bddp_received_time");
- long firstSeenTime = edge.getVertex(Direction.OUT).getProperty("first_seen_time");
- long lastLldpReceivedTime = edge.getVertex(Direction.OUT).getProperty("last_lldp_received_time");
- long lastBddpReceivedTime = edge.getVertex(Direction.OUT).getProperty("last_bddp_received_time");
- assertTrue(firstSeenTime == info.getFirstSeenTime());
- assertTrue(lastLldpReceivedTime == info.getUnicastValidTime());
- assertTrue(lastBddpReceivedTime == info.getMulticastValidTime());
+ assertTrue(false);
}