Merged with the latest master
diff --git a/src/test/java/net/floodlightcontroller/core/internal/ControllerTest.java b/src/test/java/net/floodlightcontroller/core/internal/ControllerTest.java
index 05e01a3..88e2d35 100644
--- a/src/test/java/net/floodlightcontroller/core/internal/ControllerTest.java
+++ b/src/test/java/net/floodlightcontroller/core/internal/ControllerTest.java
@@ -69,6 +69,7 @@
import net.floodlightcontroller.storage.memory.MemoryStorageSource;
import net.floodlightcontroller.test.FloodlightTestCase;
import net.floodlightcontroller.threadpool.IThreadPoolService;
+import net.onrc.onos.ofcontroller.core.IOFSwitchPortListener;
import org.easymock.Capture;
import org.easymock.EasyMock;
@@ -404,7 +405,7 @@
@Test
public void testUpdateQueue() throws Exception {
- class DummySwitchListener implements IOFSwitchListener {
+ class DummySwitchListener implements IOFSwitchListener, IOFSwitchPortListener {
public int nAdded;
public int nRemoved;
public int nPortChanged;
@@ -824,7 +825,7 @@
state.firstRoleReplyReceived = false;
controller.role = Role.SLAVE;
expect(chdlr.sw.checkFirstPendingRoleRequestXid(xid)).andReturn(true);
- chdlr.sw.deliverRoleRequestNotSupported(xid);
+ chdlr.sw.deliverRoleRequestNotSupportedEx(xid);
expect(chdlr.sw.getChannel()).andReturn(ch).anyTimes();
expect(ch.close()).andReturn(null);
@@ -844,7 +845,7 @@
state.firstRoleReplyReceived = false;
controller.role = Role.SLAVE;
expect(chdlr.sw.checkFirstPendingRoleRequestXid(xid)).andReturn(true);
- chdlr.sw.deliverRoleRequestNotSupported(xid);
+ chdlr.sw.deliverRoleRequestNotSupportedEx(xid);
expect(chdlr.sw.getChannel()).andReturn(ch).anyTimes();
expect(ch.close()).andReturn(null);
replay(ch, chdlr.sw);
@@ -863,7 +864,7 @@
state.firstRoleReplyReceived = false;
controller.role = Role.MASTER;
expect(chdlr.sw.checkFirstPendingRoleRequestXid(xid)).andReturn(true);
- chdlr.sw.deliverRoleRequestNotSupported(xid);
+ chdlr.sw.deliverRoleRequestNotSupportedEx(xid);
setupSwitchForAddSwitch(chdlr.sw, 0L);
chdlr.sw.clearAllFlowMods();
replay(ch, chdlr.sw);
diff --git a/src/test/java/net/floodlightcontroller/core/internal/OFSwitchImplTest.java b/src/test/java/net/floodlightcontroller/core/internal/OFSwitchImplTest.java
index 758cd05..128c09f 100644
--- a/src/test/java/net/floodlightcontroller/core/internal/OFSwitchImplTest.java
+++ b/src/test/java/net/floodlightcontroller/core/internal/OFSwitchImplTest.java
@@ -197,7 +197,7 @@
sw.role = Role.SLAVE;
sw.pendingRoleRequests.add(pending);
replay(sw.channel);
- sw.deliverRoleRequestNotSupported(pending.xid);
+ sw.deliverRoleRequestNotSupportedEx(pending.xid);
verify(sw.channel);
assertEquals(false, sw.getAttribute(IOFSwitch.SWITCH_SUPPORTS_NX_ROLE));
assertEquals(null, sw.role);
@@ -210,7 +210,7 @@
sw.role = Role.SLAVE;
expect(sw.channel.close()).andReturn(null);
replay(sw.channel);
- sw.deliverRoleRequestNotSupported(1);
+ sw.deliverRoleRequestNotSupportedEx(1);
verify(sw.channel);
assertEquals(null, sw.role);
assertEquals(0, sw.pendingRoleRequests.size());
@@ -228,7 +228,7 @@
sw.pendingRoleRequests.add(pending);
expect(sw.channel.close()).andReturn(null);
replay(sw.channel);
- sw.deliverRoleRequestNotSupported(pending.xid+1);
+ sw.deliverRoleRequestNotSupportedEx(pending.xid+1);
verify(sw.channel);
assertEquals(null, sw.role);
assertEquals(0, sw.pendingRoleRequests.size());
diff --git a/src/test/java/net/floodlightcontroller/linkdiscovery/internal/LinkStorageImplTest.java b/src/test/java/net/floodlightcontroller/linkdiscovery/internal/LinkStorageImplTest.java
deleted file mode 100644
index 857d091..0000000
--- a/src/test/java/net/floodlightcontroller/linkdiscovery/internal/LinkStorageImplTest.java
+++ /dev/null
@@ -1,129 +0,0 @@
-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 net.floodlightcontroller.core.internal.TestDatabaseManager;
-import net.floodlightcontroller.routing.Link;
-import net.onrc.onos.ofcontroller.core.INetMapStorage.DM_OPERATION;
-import net.onrc.onos.ofcontroller.linkdiscovery.ILinkStorage;
-
-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 {
- private static ILinkStorage linkStorage;
- private static TitanGraph titanGraph;
-
- //TODO Future ideas:
- //Test add links with CREATE and UPDATE
- //Test adding existing link again
-
- @Before
- public void setUp() throws Exception{
- titanGraph = TestDatabaseManager.getTestDatabase();
- TestDatabaseManager.populateTestData(titanGraph);
-
- linkStorage = new TestableLinkStorageImpl(titanGraph);
- }
-
- @After
- public void tearDown() throws Exception {
- titanGraph.shutdown();
- }
-
- /*
- * Add a link between port 1.102 and 2.104
- * i.e SEA switch port 3 to LAX switch port 1
- */
- @Test
- public void testAddSingleLink(){
- Link linkToAdd = new Link(Long.decode("0x0000000000000a01"), 3, Long.decode("0x0000000000000a02"), 1);
-
- //Use the link storage API to add the link
- linkStorage.update(linkToAdd, ILinkStorage.DM_OPERATION.INSERT);
-
- //Test if it was added correctly with the Gremlin API
- GremlinPipeline<Vertex, Vertex> pipe = new GremlinPipeline<Vertex, Vertex>();
- Iterator<Vertex> it = titanGraph.getVertices("dpid", "00:00:00:00:00:00:0a:01").iterator();
-
- assertTrue(it.hasNext());
- Vertex sw1 = it.next();
- assertFalse(it.hasNext());
-
- pipe.start(sw1).out("on").has("number", (short)3).out("link").in("on");
-
- assertTrue(pipe.hasNext());
- Vertex sw2 = pipe.next();
- assertFalse(pipe.hasNext());
-
- //Check we ended up at the right vertex
- assertEquals((String)sw2.getProperty("dpid"), "00:00:00:00:00:00:0a:02");
- }
-
- //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);
-
- assertEquals(list.size(), 1);
-
- Link l = list.get(0);
- assertEquals(l.getSrc(), 2561L);
- assertEquals(l.getSrcPort(), (short)2);
- assertEquals(l.getDst(), 2563L);
- assertEquals(l.getDstPort(), (short)1);
- }
-
- //TODO enable once method is written
- @Ignore @Test
- public void testUpdateDelete(){
- Link linkToDelete = new Link(Long.decode("0x0000000000000a01"), 2, Long.decode("0x0000000000000a03"), 1);
-
- linkStorage.update(linkToDelete, DM_OPERATION.DELETE);
-
- //Test if it was deleted correctly with the Gremlin API
- GremlinPipeline<Vertex, Vertex> pipe = new GremlinPipeline<Vertex, Vertex>();
- Iterator<Vertex> it = titanGraph.getVertices("dpid", "00:00:00:00:00:00:0a:01").iterator();
-
- assertTrue(it.hasNext());
- Vertex sw1 = it.next();
- assertFalse(it.hasNext());
-
- pipe.start(sw1).out("on").has("number", 2).out("link");
-
- assertFalse(pipe.hasNext());
- }
-
- //TODO enable once method is written
- @Ignore @Test
- public void testDeleteLinks(){
- //TODO Make sure this works when the implementation is written
-
- linkStorage.deleteLinksOnPort(Long.decode("0x0000000000000a01"), (short)2);
-
- //Test if it was deleted correctly with the Gremlin API
- GremlinPipeline<Vertex, Vertex> pipe = new GremlinPipeline<Vertex, Vertex>();
- Iterator<Vertex> it = titanGraph.getVertices("dpid", "00:00:00:00:00:00:0a:01").iterator();
-
- assertTrue(it.hasNext());
- Vertex sw1 = it.next();
- assertFalse(it.hasNext());
-
- pipe.start(sw1).out("on").has("number", 2).out("link");
-
- assertFalse(pipe.hasNext());
- }
-
-}
diff --git a/src/test/java/net/floodlightcontroller/topology/TopologyInstanceTest.java b/src/test/java/net/floodlightcontroller/topology/TopologyInstanceTest.java
index e72179d..9232bb5 100644
--- a/src/test/java/net/floodlightcontroller/topology/TopologyInstanceTest.java
+++ b/src/test/java/net/floodlightcontroller/topology/TopologyInstanceTest.java
@@ -11,11 +11,11 @@
import net.floodlightcontroller.core.module.FloodlightModuleContext;
import net.floodlightcontroller.core.test.MockFloodlightProvider;
import net.floodlightcontroller.core.test.MockThreadPoolService;
-import net.floodlightcontroller.linkdiscovery.ILinkDiscovery;
import net.floodlightcontroller.threadpool.IThreadPoolService;
import net.floodlightcontroller.topology.NodePortTuple;
import net.floodlightcontroller.topology.TopologyInstance;
import net.floodlightcontroller.topology.TopologyManager;
+import net.onrc.onos.ofcontroller.linkdiscovery.ILinkDiscovery;
import org.junit.Before;
import org.junit.Test;
diff --git a/src/test/java/net/floodlightcontroller/topology/TopologyManagerTest.java b/src/test/java/net/floodlightcontroller/topology/TopologyManagerTest.java
index 113cecb..1cf344d 100644
--- a/src/test/java/net/floodlightcontroller/topology/TopologyManagerTest.java
+++ b/src/test/java/net/floodlightcontroller/topology/TopologyManagerTest.java
@@ -4,10 +4,10 @@
import net.floodlightcontroller.core.IFloodlightProviderService.Role;
import net.floodlightcontroller.core.module.FloodlightModuleContext;
import net.floodlightcontroller.core.test.MockThreadPoolService;
-import net.floodlightcontroller.linkdiscovery.ILinkDiscovery;
import net.floodlightcontroller.test.FloodlightTestCase;
import net.floodlightcontroller.threadpool.IThreadPoolService;
import net.floodlightcontroller.topology.TopologyManager;
+import net.onrc.onos.ofcontroller.linkdiscovery.ILinkDiscovery;
import org.junit.Before;
import org.junit.Test;
diff --git a/src/test/java/net/floodlightcontroller/util/OFMessageDamperMockSwitch.java b/src/test/java/net/floodlightcontroller/util/OFMessageDamperMockSwitch.java
index ffabf6f..59e0a51 100644
--- a/src/test/java/net/floodlightcontroller/util/OFMessageDamperMockSwitch.java
+++ b/src/test/java/net/floodlightcontroller/util/OFMessageDamperMockSwitch.java
@@ -346,10 +346,4 @@
return 0;
}
- @Override
- public void setupRemoteSwitch(Long dpid) {
- // TODO Auto-generated method stub
-
- }
-
}
\ No newline at end of file
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
new file mode 100644
index 0000000..7bf2b1a
--- /dev/null
+++ b/src/test/java/net/onrc/onos/ofcontroller/core/internal/LinkStorageImplTest.java
@@ -0,0 +1,536 @@
+package net.onrc.onos.ofcontroller.core.internal;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import net.floodlightcontroller.routing.Link;
+import net.onrc.onos.ofcontroller.core.ILinkStorage;
+import net.onrc.onos.ofcontroller.core.INetMapStorage.DM_OPERATION;
+import net.onrc.onos.ofcontroller.core.internal.TestableGraphDBOperation.TestPortObject;
+import net.onrc.onos.util.GraphDBConnection;
+import net.onrc.onos.util.GraphDBOperation;
+import net.onrc.onos.ofcontroller.linkdiscovery.LinkInfo;
+
+import org.easymock.EasyMock;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.openflow.protocol.OFPhysicalPort;
+import org.openflow.util.HexString;
+import org.powermock.api.easymock.PowerMock;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({LinkStorageImpl.class, GraphDBConnection.class, GraphDBOperation.class})
+public class LinkStorageImplTest {
+ protected static Logger log = LoggerFactory.getLogger(LinkStorageImplTest.class);
+
+ private static ILinkStorage linkStorage;
+
+ // Mock GraphDBConnection (do nothing)
+ private static GraphDBConnection conn;
+
+ // Mock GraphDBOperation (mocks port-related methods only)
+ private static TestableGraphDBOperation ope;
+
+ /**
+ * Setup code called before each tests.
+ * Read test graph data and replace DB access by test graph data.
+ * @throws Exception
+ */
+ @Before
+ public void setUp() throws Exception{
+ PowerMock.mockStatic(GraphDBConnection.class);
+ PowerMock.suppress(PowerMock.constructor(GraphDBConnection.class));
+ conn = PowerMock.createNiceMock(GraphDBConnection.class);
+ EasyMock.expect(GraphDBConnection.getInstance((String)EasyMock.anyObject())).andReturn(conn).anyTimes();
+ PowerMock.replay(GraphDBConnection.class);
+
+ ope = new TestableGraphDBOperation();
+ PowerMock.expectNew(GraphDBOperation.class, (GraphDBConnection)EasyMock.anyObject()).andReturn(ope).anyTimes();
+ PowerMock.replay(GraphDBOperation.class);
+
+ linkStorage = new LinkStorageImpl();
+ linkStorage.init("/dummy/path/to/conf");
+
+ initLinks();
+ }
+
+ /**
+ * Closing code called after each tests.
+ * Discard test graph data.
+ * @throws Exception
+ */
+ @After
+ public void tearDown() throws Exception {
+ // finish code
+ linkStorage.close();
+ ope.close();
+ }
+
+ // 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();
+ long currentTime = System.currentTimeMillis();
+ LinkInfo infoToUpdate = createFeasibleLinkInfo(currentTime);
+ LinkInfo infoToVerify = createFeasibleLinkInfo(currentTime);
+
+ linkStorage.update(linkToUpdate, infoToUpdate, ILinkStorage.DM_OPERATION.UPDATE);
+
+ doTestLinkHasStateOf(linkToUpdate, infoToVerify);
+ }
+
+ /**
+ * Test if update() can correctly creates a Link.
+ */
+ @Test
+ public void testUpdate_CreateSingleLink() {
+ Link linkToCreate = createFeasibleLink();
+ Link linkToVerify = createFeasibleLink();
+
+ //Use the link storage API to add the link
+ linkStorage.update(linkToCreate, ILinkStorage.DM_OPERATION.CREATE);
+ doTestLinkExist(linkToVerify);
+ }
+
+ /**
+ * Test if update() can correctly inserts a Link.
+ */
+ @Test
+ public void testUpdate_InsertSingleLink(){
+ Link linkToInsert = createFeasibleLink();
+ Link linkToVerify = createFeasibleLink();
+
+ //Use the link storage API to add the link
+ linkStorage.update(linkToInsert, ILinkStorage.DM_OPERATION.INSERT);
+ doTestLinkExist(linkToVerify);
+ }
+
+ /**
+ * Test if update() can correctly deletes a Link.
+ */
+ @Test
+ public void testUpdate_DeleteSingleLink(){
+ Link linkToDelete = createExistingLink();
+ Link linkToVerify = createExistingLink();
+
+ // Test deletion of existing link
+ linkStorage.update(linkToDelete, DM_OPERATION.DELETE);
+ doTestLinkNotExist(linkToVerify);
+ }
+
+ /**
+ * Test if update() can correctly creates multiple Links.
+ */
+ @Test
+ public void testUpdate_CreateLinks(){
+ List<Link> linksToCreate = createFeasibleLinks();
+ List<Link> linksToVerify = createFeasibleLinks();
+
+ // Test creation of new links
+ linkStorage.update(linksToCreate, ILinkStorage.DM_OPERATION.CREATE);
+ for(Link l : linksToVerify) {
+ doTestLinkExist(l);
+ }
+ }
+
+ /**
+ * Test if update() can handle mixture of normal/abnormal input for creation of Links.
+ * Deprecated: DBOperation is responsible.
+ */
+ @Ignore @Test
+ public void testUpdate_CreateLinks_Mixuture(){
+ List<Link> linksToCreate = new ArrayList<Link>();
+ linksToCreate.add(createFeasibleLink());
+ linksToCreate.add(createExistingLink());
+
+ // Test creation of mixture of new/existing links
+ linkStorage.update(linksToCreate, ILinkStorage.DM_OPERATION.CREATE);
+ doTestLinkExist(createFeasibleLink());
+ doTestLinkExist(createExistingLink());
+ }
+
+ /**
+ * Test if update() can correctly inserts multiple Links.
+ */
+ @Test
+ public void testUpdate_InsertLinks(){
+ List<Link> linksToInsert = createFeasibleLinks();
+ List<Link> linksToVerify = createFeasibleLinks();
+
+ // Test insertion of new links
+ linkStorage.update(linksToInsert, ILinkStorage.DM_OPERATION.INSERT);
+ for(Link l : linksToVerify) {
+ doTestLinkExist(l);
+ }
+ }
+
+ /**
+ * Test if update() can handle mixture of normal/abnormal input for creation of Links.
+ */
+ @Ignore @Test
+ public void testUpdate_InsertLinks_Mixuture(){
+ List<Link> linksToInsert = new ArrayList<Link>();
+ linksToInsert.add(createFeasibleLink());
+ linksToInsert.add(createExistingLink());
+
+ // Test insertion of mixture of new/existing links
+ linkStorage.update(linksToInsert, ILinkStorage.DM_OPERATION.INSERT);
+ doTestLinkExist(createFeasibleLink());
+ doTestLinkExist(createExistingLink());
+ }
+
+ /**
+ * Test if update() can correctly deletes multiple Links.
+ */
+ @Test
+ public void testUpdate_DeleteLinks(){
+ List<Link> linksToDelete = createExistingLinks();
+ List<Link> linksToVerify = createExistingLinks();
+
+ // Test deletion of existing links
+ linkStorage.update(linksToDelete, ILinkStorage.DM_OPERATION.DELETE);
+ for(Link l : linksToVerify) {
+ doTestLinkNotExist(l);
+ }
+ }
+
+ /**
+ * Test if update() can handle mixture of normal/abnormal input for deletion of Links.
+ */
+ @Ignore @Test
+ public void testUpdate_DeleteLinks_Mixuture(){
+ List<Link> linksToDelete = new ArrayList<Link>();
+ linksToDelete.add(createFeasibleLink());
+ linksToDelete.add(createExistingLink());
+
+ // Test deletion of mixture of new/existing links
+ linkStorage.update(linksToDelete, ILinkStorage.DM_OPERATION.DELETE);
+ doTestLinkNotExist(createFeasibleLink());
+ doTestLinkNotExist(createExistingLink());
+ }
+
+ // TODO: remove @Ignore after UPDATE method is implemented
+ /**
+ * Test if updateLink() can correctly updates LinkInfo for a Link.
+ */
+ @Ignore @Test
+ public void testUpdateLink_Update() {
+ Link linkToUpdate= createExistingLink();
+ long currentTime = System.currentTimeMillis();
+ LinkInfo infoToUpdate = createFeasibleLinkInfo(currentTime);
+ LinkInfo infoToVerify = createFeasibleLinkInfo(currentTime);
+
+ linkStorage.updateLink(linkToUpdate, infoToUpdate, ILinkStorage.DM_OPERATION.UPDATE);
+
+ doTestLinkHasStateOf(linkToUpdate, infoToVerify);
+ }
+
+ /**
+ * Test if updateLink() can correctly creates a Link.
+ */
+ @Test
+ public void testUpdateLink_Create() {
+ Link linkToCreate = createFeasibleLink();
+ Link linkToVerify = createFeasibleLink();
+
+ //Use the link storage API to add the link
+ linkStorage.updateLink(linkToCreate, null, ILinkStorage.DM_OPERATION.CREATE);
+ doTestLinkExist(linkToVerify);
+ }
+
+ /**
+ * Test if updateLink() can correctly inserts a Link.
+ */
+ @Test
+ public void testUpdateLink_Insert() {
+ Link linkToInsert = createFeasibleLink();
+ Link linkToVerify = createFeasibleLink();
+
+ //Use the link storage API to add the link
+ linkStorage.updateLink(linkToInsert, null, ILinkStorage.DM_OPERATION.INSERT);
+
+ doTestLinkExist(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 testUpdateLink_Delete() {
+ Link linkToDelete = createExistingLink();
+ Link linkToVerify = createExistingLink();
+
+ // Test deletion of existing link
+ linkStorage.updateLink(linkToDelete, null, DM_OPERATION.DELETE);
+ doTestLinkNotExist(linkToVerify);
+
+ linkToDelete = createFeasibleLink();
+ linkToVerify = createFeasibleLink();
+
+ // Test deletion of not-existing link
+ linkStorage.updateLink(linkToDelete, null, DM_OPERATION.DELETE);
+ doTestLinkNotExist(linkToVerify);
+ }
+
+ /**
+ * Test if getLinks() can correctly return Links connected to specific DPID and port.
+ */
+ @Test
+ public void testGetLinks_ByDpidPort(){
+ Link linkToVerify = createExistingLink();
+ Long dpid = linkToVerify.getSrc();
+ short port = (short)linkToVerify.getSrcPort();
+
+ List<Link> list = linkStorage.getLinks(dpid, port);
+
+ assertEquals(list.size(), 1);
+
+ Link l = list.get(0);
+ assertEquals(l.getSrc(), linkToVerify.getSrc());
+ assertEquals(l.getSrcPort(), linkToVerify.getSrcPort());
+ assertEquals(l.getDst(), linkToVerify.getDst());
+ assertEquals(l.getDstPort(), linkToVerify.getDstPort());
+
+ Link linkToVerifyNot = createFeasibleLink();
+
+ List<Link> list2 = linkStorage.getLinks(linkToVerifyNot.getSrc(), (short)linkToVerifyNot.getSrcPort());
+
+ assertEquals(list2.size(), 0);
+ }
+
+ /**
+ * Test if getLinks() can correctly return Links connected to specific MAC address.
+ */
+ @Test
+ public void testGetLinks_ByString() {
+ Link linkToVeryfy = createExistingLink();
+ String dpid = HexString.toHexString(linkToVeryfy.getSrc());
+
+ List<Link> links = linkStorage.getLinks(dpid);
+ assertTrue(links.contains(linkToVeryfy));
+
+ Link linkToVerifyNot = createFeasibleLink();
+ assertFalse(links.contains(linkToVerifyNot));
+ }
+
+ /**
+ * Test if deleteLink() can correctly delete a Link.
+ */
+ @Test
+ public void testDeleteLink() {
+ // Deletion of existing link
+ Link linkToDelete = createExistingLink();
+ Link linkToVerify = createExistingLink();
+
+ linkStorage.deleteLink(linkToDelete);
+ doTestLinkNotExist(linkToVerify);
+ }
+
+ /**
+ * Test if deleteLinks() can correctly delete Links.
+ */
+ @Test
+ public void testDeleteLinks(){
+ List<Link> linksToDelete = createExistingLinks();
+ List<Link> linksToVerify = createExistingLinks();
+
+ linkStorage.deleteLinks(linksToDelete);
+ for(Link l : linksToVerify) {
+ doTestLinkNotExist(l);
+ }
+ }
+
+ /**
+ * Test if deleteLinks() can handle mixture of normal/abnormal input.
+ */
+ @Ignore @Test
+ public void testDeleteLinks_Mixture(){
+ List<Link> linksToDelete = new ArrayList<Link>();
+ linksToDelete.add(createFeasibleLink());
+ linksToDelete.add(createExistingLink());
+
+ // Test deletion of mixture of new/existing links
+ linkStorage.deleteLinks(linksToDelete);
+ doTestLinkNotExist(createFeasibleLink());
+ doTestLinkNotExist(createExistingLink());
+ }
+
+ /**
+ * Test if getActiveLinks() can correctly return active Links.
+ */
+ @Test
+ public void testGetActiveLinks() {
+ Link existingLink = createExistingLink();
+ Link notExistingLink = createFeasibleLink();
+
+ List<Link> links = linkStorage.getActiveLinks();
+
+ assertTrue(links.contains(existingLink));
+ assertFalse(links.contains(notExistingLink));
+ }
+
+ /**
+ * Test if deleteLinksOnPort() can delete Links.
+ */
+ @Test
+ public void testDeleteLinksOnPort() {
+ Link linkToDelete = createExistingLink();
+ Link linkToVerify = createExistingLink();
+
+ linkStorage.deleteLinksOnPort(linkToDelete.getSrc(), linkToDelete.getSrcPort());
+
+ doTestLinkNotExist(linkToVerify);
+ }
+
+ /**
+ * Test if specific link is existing
+ * @param link
+ */
+ private void doTestLinkExist(Link link) {
+ assertTrue(ope.hasLinkBetween(HexString.toHexString(link.getSrc()),
+ link.getSrcPort(),
+ HexString.toHexString(link.getDst()),
+ link.getDstPort()));
+ }
+
+ /**
+ * Test if titanGraph doesn't have specific link
+ * @param link
+ */
+ private void doTestLinkNotExist(Link link) {
+ assertFalse(ope.hasLinkBetween(HexString.toHexString(link.getSrc()),
+ link.getSrcPort(),
+ HexString.toHexString(link.getDst()),
+ link.getDstPort()));
+ }
+
+ /**
+ * Test if titanGraph has specific Link with specific LinkInfo
+ * @param link
+ */
+ private void doTestLinkHasStateOf(Link link, LinkInfo info) {
+ }
+
+ //----------------- Creation of test data -----------------------
+ // Assume a network shown below.
+ //
+ // [dpid1]--+--[port:1]----[port:1]--+--[dpid2]
+ // | |
+ // +--[port:2] [port:2]--+
+ // |
+ // +--[port:3] [port:1]--+--[dpid3]
+ // | |
+ // +--[port:4]----[port:2]--+
+ //
+ // dpid1 : 00:00:00:00:0a:01
+ // dpid2 : 00:00:00:00:0a:02
+ // dpid3 : 00:00:00:00:0a:03
+
+ private void initLinks() {
+ final String dpid1 = "00:00:00:00:0a:01";
+ final String dpid2 = "00:00:00:00:0a:02";
+ final String dpid3 = "00:00:00:00:0a:03";
+
+ ope.createNewSwitchForTest(dpid1).setStateForTest("ACTIVE");
+ ope.createNewSwitchForTest(dpid2).setStateForTest("ACTIVE");
+ ope.createNewSwitchForTest(dpid3).setStateForTest("ACTIVE");
+
+ TestPortObject ports1 [] = {
+ ope.createNewPortForTest(dpid1, (short)1),
+ ope.createNewPortForTest(dpid1, (short)2),
+ ope.createNewPortForTest(dpid1, (short)3),
+ ope.createNewPortForTest(dpid1, (short)4),
+ };
+
+ TestPortObject ports2 [] = {
+ ope.createNewPortForTest(dpid2, (short)1),
+ ope.createNewPortForTest(dpid2, (short)2),
+ };
+
+ TestPortObject ports3 [] = {
+ ope.createNewPortForTest(dpid3, (short)1),
+ ope.createNewPortForTest(dpid3, (short)2),
+ };
+
+ ope.setLinkBetweenPortsForTest(ports1[0], ports2[0]);
+ ope.setLinkBetweenPortsForTest(ports1[3], ports3[1]);
+ }
+
+ /**
+ * Returns new Link object of existing link
+ * @return new Link object
+ */
+ private Link createExistingLink() {
+ return new Link(Long.decode("0x0000000000000a01"), 1, Long.decode("0x0000000000000a02"), 1);
+ }
+
+ /**
+ * Returns new Link object of not-existing but feasible link
+ * @return new Link object
+ */
+ private Link createFeasibleLink() {
+ return new Link(Long.decode("0x0000000000000a01"), 3, Long.decode("0x0000000000000a03"), 1);
+ }
+
+ // make NO sense while test-network data doesn't define physical network (i.e. any link is feasible)
+ @SuppressWarnings("unused")
+ private Link createInfeasibleLink() {
+ return new Link(Long.decode("0x0000000000000a01"), 1, Long.decode("0x0000000000000a03"), 3);
+ }
+
+ /**
+ * Returns list of Link objects which all has information of existing link in titanGraph
+ * @return ArrayList of new Link objects
+ */
+ private List<Link> createExistingLinks() {
+ List<Link> links = new ArrayList<Link>();
+ links.add(new Link(Long.decode("0x0000000000000a01"), 1, Long.decode("0x0000000000000a02"), 1));
+ links.add(new Link(Long.decode("0x0000000000000a01"), 4, Long.decode("0x0000000000000a03"), 2));
+ return links;
+ }
+
+ /**
+ * Returns list of Link objects which all has information of not-existing but feasible link
+ * @return ArrayList of new Link objects
+ */
+ private List<Link> createFeasibleLinks() {
+ List<Link> links = new ArrayList<Link>();
+ links.add(new Link(Long.decode("0x0000000000000a01"), 2, Long.decode("0x0000000000000a02"), 2));
+ links.add(new Link(Long.decode("0x0000000000000a01"), 3, Long.decode("0x0000000000000a03"), 1));
+ return links;
+ }
+
+ /**
+ * Returns new LinkInfo object with convenient values.
+ * @return LinkInfo object
+ */
+ private LinkInfo createFeasibleLinkInfo(long time) {
+ long time_first = time;
+ long time_last_lldp = time + 50;
+ long time_last_bddp = time + 100;
+ int state_src = OFPhysicalPort.OFPortState.OFPPS_STP_FORWARD.getValue();
+ int state_dst = OFPhysicalPort.OFPortState.OFPPS_STP_LISTEN.getValue();
+
+ return new LinkInfo(time_first,
+ time_last_lldp,
+ time_last_bddp,
+ state_src,
+ state_dst);
+ }
+ //---------------------------------------------------------------
+}
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 78594b5..f6f70ae 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
@@ -97,10 +97,10 @@
* Desc:
* Test method for addSwitch method.
* Condition:
- * The switch status is INACTIVE.
+ * The existing switch status is INACTIVE.
+ * The switch is already existing.
* Expect:
- * 1. Switch should be existing.
- * 2. The status of switch should be ACTIVE
+ * 1. After add the same switch, the status of switch should be ACTIVE
*/
//@Ignore
@Test
@@ -121,7 +121,9 @@
* Desc:
* Test method for testUpdate method.
* Condition:
- * We will create a swith with this method.
+ * The switch is not existing.
+ * The status of added switch is INACTIVE.
+ * DM_OPERATION is CREATE.
* Expect:
* 1. Switch should be created.
* 2. The status of switch should be INACTIVE.
@@ -146,6 +148,8 @@
* Test method for testUpdate method.
* Condition:
* The switch is existing.
+ * The status of added switch is ACTIVE.
+ * DM_OPERATION is DELETE.
* Expect:
* 1. Switch should be deleted.
*/
@@ -189,7 +193,7 @@
* Condition:
* The switch is not existing.
* Expect:
- * Nothing happends.
+ * Nothing happens.
*/
//@Ignore
@Test
@@ -209,7 +213,7 @@
* Condition:
* The port is existing.
* Expect:
- * Delete the port.
+ * Deleted the port.
*/
//@Ignore
@Test
@@ -247,11 +251,12 @@
/**
* Desc:
- * Test method for add method.
+ * Test method for add port method.
* Condition:
* The port is not existing.
* Expect:
* The port should be added.
+ * The desc of IPortObject is the same as the name of OFPhysicalPort.
*/
//@Ignore
@Test
@@ -270,6 +275,7 @@
swSt.addPort(dpid, port);
IPortObject portObj = ope.searchPort(dpid, portNumber);
assertTrue(portObj != null);
+ assertEquals(portObj.getDesc(), name);
}
/**
@@ -285,7 +291,7 @@
public void testAddExistingPort() {
String dpid = "00:00:00:00:00:00:0a:06";
short portNumber = 3;
- String name = "port 3 at ATL Switch";
+ String name = "xxx";
int state = OFPortState.OFPPS_STP_FORWARD.getValue();
OFPhysicalPort port = new OFPhysicalPort();
port.setPortNumber(portNumber);
diff --git a/src/test/java/net/onrc/onos/ofcontroller/core/internal/TestDatabaseManager.java b/src/test/java/net/onrc/onos/ofcontroller/core/internal/TestDatabaseManager.java
new file mode 100644
index 0000000..b4cfc31
--- /dev/null
+++ b/src/test/java/net/onrc/onos/ofcontroller/core/internal/TestDatabaseManager.java
@@ -0,0 +1,76 @@
+package net.onrc.onos.ofcontroller.core.internal;
+
+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 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;
+import com.tinkerpop.blueprints.Vertex;
+import com.tinkerpop.blueprints.util.io.graphml.GraphMLReader;
+
+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 testDataLocation = "titan/schema/test-network.xml";
+
+ public static TitanGraph getTestDatabase(){
+ //return TitanFactory.open(testDbLocation);
+// return TitanFactory.openInMemoryGraph();
+ return TitanFactory.open(testDbLocation);
+ }
+
+ public static void populateTestData(TitanGraph titanGraph){
+ 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 {
+ 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(){
+ try {
+ FileUtils.deleteDirectory(new File(testDbLocation));
+ } catch (IOException e) {
+ System.out.println("delete failed");
+ e.printStackTrace();
+ }
+ }
+
+}
\ No newline at end of file
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
new file mode 100644
index 0000000..31a4bb0
--- /dev/null
+++ b/src/test/java/net/onrc/onos/ofcontroller/core/internal/TestableGraphDBOperation.java
@@ -0,0 +1,1331 @@
+package net.onrc.onos.ofcontroller.core.internal;
+
+import java.util.ArrayList;
+import java.util.List;
+
+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.annotations.gremlin.GremlinParam;
+
+import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IDeviceObject;
+import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowEntry;
+import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowPath;
+import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IPortObject;
+import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject;
+import net.onrc.onos.ofcontroller.util.FlowEntryId;
+import net.onrc.onos.ofcontroller.util.FlowId;
+import net.onrc.onos.util.GraphDBConnection;
+import net.onrc.onos.util.GraphDBOperation;
+import net.onrc.onos.util.IDBConnection;
+
+/**
+ * Mock class of GraphDBOperation which provides additional setter to construct a graph for test.
+ * This object simply caches parameters set up by override interfaces and reflect them when commit().
+ * *ForTest() methods are exempt from cache, parameters through those methods are reflected soon.
+ * @author Naoki Shiota
+ *
+ */
+public class TestableGraphDBOperation extends GraphDBOperation {
+ protected static Logger log = LoggerFactory.getLogger(TestableGraphDBOperation.class);
+
+ protected List<TestSwitchObject> switches;
+ protected List<TestPortObject> ports;
+ protected List<TestDeviceObject> devices;
+ protected List<TestFlowPath> paths;
+ protected List<TestFlowEntry> entries;
+
+ protected List<TestSwitchObject> switchesToAdd;
+ protected List<TestPortObject> portsToAdd;
+ protected List<TestDeviceObject> devicesToAdd;
+ protected List<TestFlowPath> pathsToAdd;
+ protected List<TestFlowEntry> entriesToAdd;
+
+ protected List<TestSwitchObject> switchesToRemove;
+ protected List<TestPortObject> portsToRemove;
+ protected List<TestDeviceObject> devicesToRemove;
+ protected List<TestFlowPath> pathsToRemove;
+ protected List<TestFlowEntry> entriesToRemove;
+
+ // Testable implementations of INetMapTopologyObject interfaces
+
+ public static class TestSwitchObject implements ISwitchObject {
+ private String state,type,dpid;
+ private List<IPortObject> ports;
+ private List<IDeviceObject> devices;
+ private List<IFlowEntry> entries;
+
+ private String stateToUpdate, typeToUpdate, dpidToUpdate;
+ private List<IPortObject> portsToAdd;
+ private List<IPortObject> portsToRemove;
+
+ public TestSwitchObject() {
+ type = "switch";
+
+ ports = new ArrayList<IPortObject>();
+ portsToAdd = new ArrayList<IPortObject>();
+ portsToRemove = new ArrayList<IPortObject>();
+ devices = new ArrayList<IDeviceObject>();
+ entries = new ArrayList<IFlowEntry>();
+
+ clearUncommitedData();
+ }
+
+ public void commit() {
+ for(IPortObject port : portsToAdd) {
+ ports.add(port);
+ }
+ for(IPortObject port : portsToRemove) {
+ ports.remove(port);
+ }
+ if(stateToUpdate != null) { state = stateToUpdate; }
+ if(typeToUpdate != null) { type = typeToUpdate; }
+ if(dpidToUpdate != null) { dpid = dpidToUpdate; }
+
+ clearUncommitedData();
+ }
+
+ public void rollback() {
+ clearUncommitedData();
+ }
+
+ public void clearUncommitedData() {
+ portsToAdd.clear();
+ portsToRemove.clear();
+ stateToUpdate = typeToUpdate = dpidToUpdate = null;
+ }
+
+ public void setStateForTest(String state) { this.state = state; }
+ public void setTypeForTest(String type) { this.type = type; }
+ public void setDpidForTest(String dpid) { this.dpid = dpid; }
+ public void addPortForTest(TestPortObject port) { ports.add(port); }
+ public void addDeviceForTest(TestDeviceObject dev) { devices.add(dev); }
+ public void addEntryForTest(TestFlowEntry entry) { entries.add(entry); }
+
+ @Override
+ public String getState() { return state; }
+
+ @Override
+ public void setState(String state) { this.stateToUpdate = state; }
+
+ @Override
+ public String getType() { return type ; }
+
+ @Override
+ public void setType(String type) { this.typeToUpdate = type; }
+
+ // Not support for test
+ @Override
+ public Vertex asVertex() { return null; }
+
+ @Override
+ public String getDPID() { return dpid; }
+
+ @Override
+ public void setDPID(String dpid) { this.dpidToUpdate = dpid; }
+
+ @Override
+ public Iterable<IPortObject> getPorts() { return ports; }
+
+ @Override
+ public IPortObject getPort(@GremlinParam("port_num") short port_num) {
+ for(IPortObject port : ports) {
+ if(port.getNumber() == port_num) {
+ return port;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public void addPort(IPortObject port) { portsToAdd.add(port); }
+
+ @Override
+ public void removePort(IPortObject port) { portsToRemove.add(port); }
+
+ @Override
+ public Iterable<IDeviceObject> getDevices() { return devices; }
+
+ @Override
+ public Iterable<IFlowEntry> getFlowEntries() { return entries; }
+ }
+
+ public static class TestPortObject implements IPortObject {
+ private String state,type,desc;
+ private Short number;
+ private Integer port_state;
+ private ISwitchObject sw;
+
+ private List<IPortObject> linkedPorts;
+ private List<IDeviceObject> devices;
+ private List<IFlowEntry> inflows,outflows;
+
+ private String stateToUpdate,typeToUpdate,descToUpdate;
+ private Short numberToUpdate;
+ private Integer port_stateToUpdate;
+
+ private List<IPortObject> linkedPortsToAdd;
+ private List<IPortObject> linkedPortsToRemove;
+ private List<IDeviceObject> devicesToAdd;
+ private List<IDeviceObject> devicesToRemove;
+
+
+ public TestPortObject() {
+ type = "port";
+
+ linkedPorts = new ArrayList<IPortObject>();
+ linkedPortsToAdd = new ArrayList<IPortObject>();
+ linkedPortsToRemove = new ArrayList<IPortObject>();
+ devices = new ArrayList<IDeviceObject>();
+ devicesToAdd = new ArrayList<IDeviceObject>();
+ devicesToRemove = new ArrayList<IDeviceObject>();
+ inflows = new ArrayList<IFlowEntry>();
+ outflows = new ArrayList<IFlowEntry>();
+
+ clearUncommitedData();
+ }
+
+ public void commit() {
+ for(IPortObject port : linkedPortsToAdd) { linkedPorts.add(port); }
+ for(IPortObject port : linkedPortsToRemove) { linkedPorts.remove(port); }
+ for(IDeviceObject dev : devicesToAdd) { devices.add(dev); }
+ for(IDeviceObject dev : devicesToRemove) { devices.remove(dev); }
+
+ if(stateToUpdate != null) { state = stateToUpdate; }
+ if(typeToUpdate != null) { type = typeToUpdate; }
+ if(descToUpdate != null) { desc = descToUpdate; }
+ if(numberToUpdate != null) { number = numberToUpdate; }
+ if(port_stateToUpdate != null) { port_state = port_stateToUpdate; }
+
+ clearUncommitedData();
+ }
+
+ public void rollback() {
+ clearUncommitedData();
+ }
+
+ public void clearUncommitedData() {
+ linkedPortsToAdd.clear();
+ linkedPortsToRemove.clear();
+ devicesToAdd.clear();
+ devicesToRemove.clear();
+ stateToUpdate = typeToUpdate = descToUpdate = null;
+ port_stateToUpdate = null;
+ numberToUpdate = null;
+ }
+
+ // Setter methods for test
+ public void setStateForTest(String state) { this.state = state; }
+ public void setTypeForTest(String type) { this.type = type; }
+ public void setDescForTest(String desc) { this.desc = desc; }
+ public void setNumberForTest(Short number) { this.number = number; }
+ public void setPortStateForTest(Integer state) { this.port_state = state; }
+ public void setSwitchForTest(ISwitchObject sw) { this.sw = sw; }
+ public void addLinkedPortForTest(TestPortObject port) { this.linkedPorts.add(port); }
+ public void addInflowForTest(TestFlowEntry entry) { inflows.add(entry); }
+ public void addOutflowForTest(TestFlowEntry entry) { outflows.add(entry); }
+
+ // Override methods for mock IPortObject
+ @Override
+ public String getState() { return state; }
+
+ @Override
+ public void setState(String state) { this.stateToUpdate = state; }
+
+ @Override
+ public String getType() { return type; }
+
+ @Override
+ public void setType(String type) { this.typeToUpdate = type; }
+
+ // not support for test
+ @Override
+ public Vertex asVertex() {
+ return null;
+ }
+
+ @Override
+ public Short getNumber() { return number; }
+
+ @Override
+ public void setNumber(Short n) { this.numberToUpdate = n; }
+
+ @Override
+ public String getDesc() { return desc; }
+
+ @Override
+ public void setDesc(String s) { this.descToUpdate = s; }
+
+ @Override
+ public Integer getPortState() { return port_state; }
+
+ @Override
+ public void setPortState(Integer s) { this.port_stateToUpdate = s; }
+
+ @Override
+ public ISwitchObject getSwitch() { return sw; }
+
+ @Override
+ public Iterable<IDeviceObject> getDevices() { return devices; }
+
+ @Override
+ public void setDevice(IDeviceObject device) { devicesToAdd.add(device); }
+
+ @Override
+ public void removeDevice(IDeviceObject device) { devicesToRemove.add(device); }
+
+ @Override
+ public Iterable<IFlowEntry> getInFlowEntries() { return inflows; }
+
+ @Override
+ public Iterable<IFlowEntry> getOutFlowEntries() { return outflows; }
+
+ @Override
+ public Iterable<IPortObject> getLinkedPorts() { return linkedPorts; }
+
+ @Override
+ public void removeLink(IPortObject dest_port) { linkedPortsToRemove.add(dest_port); }
+
+ @Override
+ public void setLinkPort(IPortObject dest_port) { linkedPortsToAdd.add(dest_port); }
+ }
+
+ public static class TestDeviceObject implements IDeviceObject {
+ private String state,type,mac,ipaddr;
+ private List<IPortObject> ports;
+ private List<ISwitchObject> switches;
+
+ private String stateToUpdate,typeToUpdate,macToUpdate,ipaddrToUpdate;
+ private List<IPortObject> portsToAdd;
+ private List<IPortObject> portsToRemove;
+
+ public TestDeviceObject() {
+ type = "device";
+
+ ports = new ArrayList<IPortObject>();
+ portsToAdd = new ArrayList<IPortObject>();
+ portsToRemove = new ArrayList<IPortObject>();
+ switches = new ArrayList<ISwitchObject>();
+
+ clearUncommitedData();
+ }
+
+ public void commit() {
+ for(IPortObject port : portsToAdd) {
+ ports.add(port);
+ }
+ for(IPortObject port : portsToRemove) {
+ ports.remove(port);
+ }
+
+ if(stateToUpdate != null) { state = stateToUpdate; }
+ if(typeToUpdate != null) { type = typeToUpdate; }
+ if(macToUpdate != null) { mac = macToUpdate; }
+ if(ipaddrToUpdate != null) { ipaddr = ipaddrToUpdate; }
+
+ clearUncommitedData();
+ }
+
+ public void rollback() {
+ clearUncommitedData();
+ }
+
+ public void clearUncommitedData() {
+ ports.clear();
+ portsToAdd.clear();
+ portsToRemove.clear();
+
+ stateToUpdate = typeToUpdate = macToUpdate = ipaddrToUpdate = null;
+ }
+
+ // Setter methods for test
+ public void setStateForTest(String state) { this.state = state; }
+ public void setTypeForTest(String type) { this.type = type; }
+ public void setMacForTest(String mac) { this.mac = mac; }
+ public void setIpaddrForTest(String ipaddr) { this.ipaddr = ipaddr; }
+ public void addSwitchForTest(ISwitchObject sw) { switches.add(sw); }
+ public void addPortForTest(IPortObject port) { ports.add(port); }
+
+
+ // Override methods
+ @Override
+ public String getState() { return state; }
+
+ @Override
+ public void setState(String state) { stateToUpdate = state; }
+
+ @Override
+ public String getType() { return type; }
+
+ @Override
+ public void setType(String type) { typeToUpdate = type; }
+
+ @Override
+ public Vertex asVertex() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getMACAddress() { return mac; }
+
+ @Override
+ public void setMACAddress(String macaddr) { macToUpdate = macaddr; }
+
+ @Override
+ public String getIPAddress() { return ipaddr; }
+
+ @Override
+ public void setIPAddress(String ipaddr) { ipaddrToUpdate = ipaddr; }
+
+ @Override
+ public Iterable<IPortObject> getAttachedPorts() {
+ return ports; }
+
+ @Override
+ public void setHostPort(IPortObject port) { portsToAdd.add(port); }
+
+ @Override
+ public void removeHostPort(IPortObject port) { portsToRemove.add(port); }
+
+ @Override
+ public Iterable<ISwitchObject> getSwitch() { return switches; }
+ }
+
+ public static class TestFlowPath implements IFlowPath {
+ private String state,type,flowId,installerId,srcSw,dstSw;
+ private String dataPathSummary,userState;
+ private String matchSrcMac,matchDstMac,matchSrcIpaddr,matchDstIpaddr;
+ private Short srcPort,dstPort,matchEthernetFrameType;
+
+ private List<IFlowEntry> entries;
+ private List<ISwitchObject> switches;
+
+ private String stateToUpdate,typeToUpdate,flowIdToUpdate,installerIdToUpdate,srcSwToUpdate,dstSwToUpdate;
+ private String dataPathSummaryToUpdate,userStateToUpdate;
+ private String matchSrcMacToUpdate,matchDstMacToUpdate,matchSrcIpaddrToUpdate,matchDstIpaddrToUpdate;
+ private Short srcPortToUpdate,dstPortToUpdate,matchEthernetFrameTypeToUpdate;
+
+ private List<IFlowEntry> flowsToAdd;
+ private List<IFlowEntry> flowsToRemove;
+
+ public TestFlowPath() {
+ type = "flow";
+
+ entries = new ArrayList<IFlowEntry>();
+ flowsToAdd = new ArrayList<IFlowEntry>();
+ flowsToRemove = new ArrayList<IFlowEntry>();
+
+ switches = new ArrayList<ISwitchObject>();
+
+ clear();
+ }
+
+ public void commit() {
+ for(IFlowEntry flow : flowsToAdd) {
+ entries.add(flow);
+ }
+ for(IFlowEntry flow : flowsToRemove) {
+ entries.remove(flow);
+ }
+ if(stateToUpdate != null) { state = stateToUpdate; }
+ if(typeToUpdate != null) { type = typeToUpdate; }
+ if(flowIdToUpdate != null) { flowId = flowIdToUpdate; }
+ if(installerIdToUpdate != null) { installerId = installerIdToUpdate; }
+ if(srcSwToUpdate != null) { srcSw = srcSwToUpdate; }
+ if(dstSwToUpdate != null) { dstSw = dstSwToUpdate; }
+ if(dataPathSummaryToUpdate != null) { dataPathSummary = dataPathSummaryToUpdate; }
+ if(userStateToUpdate != null) { userState = userStateToUpdate; }
+ if(matchSrcMacToUpdate != null) { matchSrcMac = matchSrcMacToUpdate; }
+ if(matchDstMacToUpdate != null) { matchDstMac = matchDstMacToUpdate; }
+ if(matchSrcIpaddrToUpdate != null) { matchSrcIpaddr = matchSrcIpaddrToUpdate; }
+ if(matchDstIpaddrToUpdate != null) { matchDstIpaddr = matchDstIpaddrToUpdate; }
+ if(srcPortToUpdate != null) { srcPort = srcPortToUpdate; }
+ if(dstPortToUpdate != null) { dstPort = dstPortToUpdate; }
+ if(matchEthernetFrameTypeToUpdate != null) { matchEthernetFrameType = matchEthernetFrameTypeToUpdate; }
+ }
+
+ public void rollback() {
+ clear();
+ }
+
+ public void clear() {
+ flowsToAdd.clear();
+ flowsToRemove.clear();
+
+ stateToUpdate = typeToUpdate = flowIdToUpdate = installerIdToUpdate = null;
+ srcSwToUpdate = dstSwToUpdate = dataPathSummaryToUpdate = userStateToUpdate = null;
+ matchSrcMacToUpdate = matchDstMacToUpdate = matchSrcIpaddrToUpdate = matchDstIpaddrToUpdate = null;
+ srcPortToUpdate = dstPortToUpdate = matchEthernetFrameTypeToUpdate = null;
+ }
+
+ // Setter methods for test
+ public void setStateForTest(String state) { this.state = state; }
+ public void setTypeForTest(String type) { this.type = type; }
+ public void setFlowIdForTest(String flowId) { this.flowId = flowId; }
+ public void setInstallerIdForTest(String installerId) { this.installerId = installerId; }
+ public void setSrcSwForTest(String srcSw) { this.srcSw = srcSw; }
+ public void setDstSwForTest(String dstSw) { this.dstSw = dstSw; }
+ public void setDataPathSummaryForTest(String dataPathSummary) { this.dataPathSummary = dataPathSummary; }
+ public void setUserStateForTest(String userState) { this.userState = userState; }
+ public void setMatchSrcMacForTest(String matchSrcMac) { this.matchSrcMac = matchSrcMac; }
+ public void setMatchDstMacForTest(String matchDstMac) { this.matchDstMac = matchDstMac; }
+ public void setMatchSrcIpaddrForTest(String matchSrcIpaddr) { this.matchSrcIpaddr = matchSrcIpaddr; }
+ public void setMatchDstIpaddrForTest(String matchDstIpaddr) { this.matchDstIpaddr = matchDstIpaddr; }
+ public void setSrcPortForTest(Short srcPort) { this.srcPort = srcPort; }
+ public void setDstPortForTest(Short dstPort) { this.dstPort = dstPort; }
+ public void setMatchEthernetFrameTypeForTest(Short matchEthernetFrameType) { this.matchEthernetFrameType = matchEthernetFrameType; }
+ public void addFlowEntryForTest(IFlowEntry entry) { entries.add(entry); }
+ public void addSwitchForTest(ISwitchObject sw) { switches.add(sw); }
+
+ @Override
+ public String getState() { return state; }
+
+ @Override
+ public void setState(String state) { stateToUpdate = state; }
+
+ @Override
+ public String getType() { return type; }
+
+ @Override
+ public void setType(String type) { typeToUpdate = type; }
+
+ @Override
+ public Vertex asVertex() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getFlowId() { return flowId; }
+
+ @Override
+ public void setFlowId(String flowId) { flowIdToUpdate = flowId; }
+
+ @Override
+ public String getInstallerId() { return installerId; }
+
+ @Override
+ public void setInstallerId(String installerId) { installerIdToUpdate = installerId; }
+
+ @Override
+ public String getSrcSwitch() { return srcSw; }
+
+ @Override
+ public void setSrcSwitch(String srcSwitch) { srcSwToUpdate = srcSwitch; }
+
+ @Override
+ public Short getSrcPort() { return srcPort; }
+
+ @Override
+ public void setSrcPort(Short srcPort) { srcPortToUpdate = srcPort; }
+
+ @Override
+ public String getDstSwitch() { return dstSw; }
+
+ @Override
+ public void setDstSwitch(String dstSwitch) { dstSwToUpdate = dstSwitch; }
+
+ @Override
+ public Short getDstPort() { return dstPort; }
+
+ @Override
+ public void setDstPort(Short dstPort) { dstPortToUpdate = dstPort; }
+
+ @Override
+ public String getDataPathSummary() { return dataPathSummary; }
+
+ @Override
+ public void setDataPathSummary(String dataPathSummary) { dataPathSummaryToUpdate = dataPathSummary; }
+
+ @Override
+ public Iterable<IFlowEntry> getFlowEntries() { return entries; }
+
+ @Override
+ public void addFlowEntry(IFlowEntry flowEntry) {
+ if(! entries.contains(flowEntry)) {
+ flowsToAdd.add(flowEntry);
+ }
+ }
+
+ @Override
+ public void removeFlowEntry(IFlowEntry flowEntry) {
+ if(entries.contains(flowEntry)) {
+ flowsToAdd.add(flowEntry);
+ }
+ }
+
+ @Override
+ public Short getMatchEthernetFrameType() { return matchEthernetFrameType; }
+
+ @Override
+ public void setMatchEthernetFrameType(Short matchEthernetFrameType) {
+ matchEthernetFrameTypeToUpdate = matchEthernetFrameType; }
+
+ @Override
+ public String getMatchSrcMac() { return matchSrcMac; }
+
+ @Override
+ public void setMatchSrcMac(String matchSrcMac) { matchSrcMacToUpdate = matchSrcMac; }
+
+ @Override
+ public String getMatchDstMac() { return matchDstMac; }
+
+ @Override
+ public void setMatchDstMac(String matchDstMac) { matchDstMacToUpdate = matchDstMac; }
+
+ @Override
+ public String getMatchSrcIPv4Net() { return matchSrcIpaddr; }
+
+ @Override
+ public void setMatchSrcIPv4Net(String matchSrcIPv4Net) {
+ matchSrcIpaddrToUpdate = matchSrcIPv4Net; }
+
+ @Override
+ public String getMatchDstIPv4Net() { return matchDstIpaddr; }
+
+ @Override
+ public void setMatchDstIPv4Net(String matchDstIPv4Net) {
+ matchDstIpaddrToUpdate = matchDstIPv4Net; }
+
+ @Override
+ public Iterable<ISwitchObject> getSwitches() { return switches; }
+
+ @Override
+ public String getUserState() { return userState; }
+
+ @Override
+ public void setUserState(String userState) { userStateToUpdate = userState; }
+ }
+
+ public static class TestFlowEntry implements IFlowEntry {
+ private String state,type,entryId,dpid,userState,switchState,errorStateType,errorStateCode;
+ private String matchSrcMac,matchDstMac,matchSrcIpaddr,matchDstIpaddr;
+ private Short matchInPort,matchEtherFrameType,actionOutput;
+
+ private IFlowPath flowPath;
+ private ISwitchObject sw;
+ private IPortObject inport,outport;
+
+ private String stateToUpdate,typeToUpdate,entryIdToUpdate,dpidToUpdate,
+ userStateToUpdate,switchStateToUpdate,errorStateTypeToUpdate,errorStateCodeToUpdate;
+ private String matchSrcMacToUpdate,matchDstMacToUpdate,matchSrcIpaddrToUpdate,matchDstIpaddrToUpdate;
+
+ private Short matchInPortToUpdate,matchEtherFrameTypeToUpdate,actionOutputToUpdate;
+
+ private IFlowPath flowPathToUpdate;
+ private ISwitchObject swToUpdate;
+ private IPortObject inportToUpdate,outportToUpdate;
+
+ public TestFlowEntry() {
+ type = "flow_entry";
+
+ clearUncommitedData();
+ }
+
+ public void commit() {
+ if(stateToUpdate != null) { state = stateToUpdate; }
+ if(typeToUpdate != null) { type = typeToUpdate; }
+ if(entryIdToUpdate != null) { entryId = entryIdToUpdate; }
+ if(dpidToUpdate != null) { dpid = dpidToUpdate; }
+ if(userStateToUpdate != null) { userState = userStateToUpdate; }
+ if(switchStateToUpdate != null) { switchState = switchStateToUpdate; }
+ if(errorStateTypeToUpdate != null) { errorStateType = errorStateTypeToUpdate; }
+ if(errorStateCodeToUpdate != null) { errorStateCode = errorStateCodeToUpdate; }
+ if(matchSrcMacToUpdate != null) { matchSrcMac = matchSrcMacToUpdate; }
+ if(matchDstMacToUpdate != null) { matchDstMac = matchDstMacToUpdate; }
+ if(matchSrcIpaddrToUpdate != null) { matchSrcIpaddr = matchSrcIpaddrToUpdate; }
+ if(matchDstIpaddrToUpdate != null) { matchDstIpaddr = matchDstIpaddrToUpdate; }
+ if(matchInPortToUpdate != null) { matchInPort = matchInPortToUpdate; }
+ if(matchEtherFrameTypeToUpdate != null) { matchEtherFrameType = matchEtherFrameTypeToUpdate; }
+ if(actionOutputToUpdate != null) { actionOutput = actionOutputToUpdate; }
+
+ if(flowPathToUpdate != null) { flowPath = flowPathToUpdate; }
+ if(swToUpdate != null) { sw = swToUpdate; }
+ if(inportToUpdate != null) { inport = inportToUpdate; }
+ if(outportToUpdate != null) { outport = outportToUpdate; }
+
+ clearUncommitedData();
+ }
+
+ public void rollback() {
+ clearUncommitedData();
+ }
+
+ public void clearUncommitedData() {
+ stateToUpdate = typeToUpdate = entryIdToUpdate = dpidToUpdate = null;
+ userStateToUpdate = switchStateToUpdate = errorStateTypeToUpdate = errorStateCodeToUpdate = null;
+ matchSrcMacToUpdate = matchDstMacToUpdate = matchSrcIpaddrToUpdate = matchDstIpaddrToUpdate = null;
+ matchInPortToUpdate = matchEtherFrameTypeToUpdate = actionOutputToUpdate = null;
+ flowPathToUpdate = null;
+ swToUpdate = null;
+ inportToUpdate = outportToUpdate = null;
+ }
+
+ // Setter methods for test
+ public void setStateForTest(String state) { this.state = state; }
+ public void setTypeForTest(String type) { this.type = type; }
+ public void setEntryIdForTest(String entryId) { this.entryId = entryId; }
+ public void setDpidForTest(String dpid) { this.dpid = dpid; }
+ public void setUserStateForTest(String userState) { this.userState = userState; }
+ public void setSwitchStateForTest(String switchState) { this.switchState = switchState; }
+ public void setErrorStateTypeForTest(String errorStateType) { this.errorStateType = errorStateType; }
+ public void setErrorStateCodeForTest(String errorStateCode) { this.errorStateCode = errorStateCode; }
+ public void setMatchSrcMacForTest(String matchSrcMac) { this.matchSrcMac = matchSrcMac; }
+ public void setMatchDstMacForTest(String matchDstMac) { this.matchDstMac = matchDstMac; }
+ public void setMatchSrcIpaddrForTest(String matchSrcIpaddr) { this.matchSrcIpaddr = matchSrcIpaddr; }
+ public void setMatchDstIpaddrForTest(String matchDstIpaddr) { this.matchDstIpaddr = matchDstIpaddr; }
+ public void setMatchInPortForTest(Short matchInPort) { this.matchInPort = matchInPort; }
+ public void setMatchEtherFrameTypeForTest(Short matchEtherFrameType) { this.matchEtherFrameType = matchEtherFrameType; }
+ public void setActionOutputForTest(Short actionOutput) { this.actionOutput = actionOutput; }
+ public void setFlowPathForTest(IFlowPath flowPath) { this.flowPath = flowPath; }
+ public void setSwitchForTest(ISwitchObject sw) { this.sw = sw; }
+ public void setInportForTest(IPortObject inport) { this.inport = inport; }
+ public void setOutportForTest(IPortObject outport) { this.outport = outport; }
+
+ @Override
+ public String getState() { return state; }
+
+ @Override
+ public void setState(String state) { stateToUpdate = state; }
+
+ @Override
+ public String getType() { return type; }
+
+ @Override
+ public void setType(String type) { typeToUpdate = type; }
+
+ @Override
+ public Vertex asVertex() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getFlowEntryId() { return entryId; }
+
+ @Override
+ public void setFlowEntryId(String flowEntryId) { entryIdToUpdate = flowEntryId; }
+
+ @Override
+ public String getSwitchDpid() { return dpid; }
+
+ @Override
+ public void setSwitchDpid(String switchDpid) { dpidToUpdate = switchDpid; }
+
+ @Override
+ public String getUserState() { return userState; }
+
+ @Override
+ public void setUserState(String userState) { userStateToUpdate = userState; }
+
+ @Override
+ public String getSwitchState() { return switchState; }
+
+ @Override
+ public void setSwitchState(String switchState) { switchStateToUpdate = switchState; }
+
+ @Override
+ public String getErrorStateType() { return errorStateType; }
+
+ @Override
+ public void setErrorStateType(String errorStateType) { errorStateTypeToUpdate = errorStateType; }
+
+ @Override
+ public String getErrorStateCode() { return errorStateCode; }
+
+ @Override
+ public void setErrorStateCode(String errorStateCode) { errorStateCodeToUpdate = errorStateCode; }
+
+ @Override
+ public Short getMatchInPort() { return matchInPort; }
+
+ @Override
+ public void setMatchInPort(Short matchInPort) { matchInPortToUpdate = matchInPort; }
+
+ @Override
+ public Short getMatchEthernetFrameType() {return matchEtherFrameType; }
+
+ @Override
+ public void setMatchEthernetFrameType(Short matchEthernetFrameType) { matchEtherFrameTypeToUpdate = matchEthernetFrameType; }
+
+ @Override
+ public String getMatchSrcMac() { return matchSrcMac; }
+
+ @Override
+ public void setMatchSrcMac(String matchSrcMac) { matchSrcMacToUpdate = matchSrcMac; }
+
+ @Override
+ public String getMatchDstMac() { return matchDstMac; }
+
+ @Override
+ public void setMatchDstMac(String matchDstMac) { matchDstMacToUpdate = matchDstMac; }
+
+ @Override
+ public String getMatchSrcIPv4Net() { return matchSrcIpaddr; }
+
+ @Override
+ public void setMatchSrcIPv4Net(String matchSrcIPv4Net) { matchSrcIpaddrToUpdate = matchSrcIPv4Net; }
+
+ @Override
+ public String getMatchDstIPv4Net() { return matchDstIpaddr; }
+
+ @Override
+ public void setMatchDstIPv4Net(String matchDstIPv4Net) { matchDstIpaddrToUpdate = matchDstIPv4Net; }
+
+ @Override
+ public Short getActionOutput() { return actionOutput; }
+
+ @Override
+ public void setActionOutput(Short actionOutput) { actionOutputToUpdate = actionOutput; }
+
+ @Override
+ public IFlowPath getFlow() { return flowPath; }
+
+ @Override
+ public void setFlow(IFlowPath flow) { flowPathToUpdate = flow; }
+
+ @Override
+ public ISwitchObject getSwitch() { return sw; }
+
+ @Override
+ public void setSwitch(ISwitchObject sw) { swToUpdate = sw; }
+
+ @Override
+ public IPortObject getInPort() { return inport; }
+
+ @Override
+ public void setInPort(IPortObject port) { inportToUpdate = port; }
+
+ @Override
+ public IPortObject getOutPort() { return outport; }
+
+ @Override
+ public void setOutPort(IPortObject port) { outportToUpdate = port; }
+ }
+
+
+ public TestableGraphDBOperation() {
+ super(EasyMock.createNiceMock(GraphDBConnection.class));
+
+ switches = new ArrayList<TestSwitchObject>();
+ ports = new ArrayList<TestPortObject>();
+ devices = new ArrayList<TestDeviceObject>();
+ paths = new ArrayList<TestFlowPath>();
+ entries = new ArrayList<TestFlowEntry>();
+
+ switchesToAdd = new ArrayList<TestSwitchObject>();
+ portsToAdd = new ArrayList<TestPortObject>();
+ devicesToAdd = new ArrayList<TestDeviceObject>();
+ pathsToAdd = new ArrayList<TestFlowPath>();
+ entriesToAdd = new ArrayList<TestFlowEntry>();
+
+ switchesToRemove = new ArrayList<TestSwitchObject>();
+ portsToRemove = new ArrayList<TestPortObject>();
+ devicesToRemove = new ArrayList<TestDeviceObject>();
+ pathsToRemove = new ArrayList<TestFlowPath>();
+ entriesToRemove = new ArrayList<TestFlowEntry>();
+
+ clearUncommitedData();
+ }
+
+ private void clearUncommitedData() {
+ for(TestFlowEntry flow : entries) {
+ flow.clearUncommitedData();
+ }
+ for(TestFlowEntry flow : entriesToAdd) {
+ flow.clearUncommitedData();
+ }
+
+ for(TestDeviceObject dev : devices) {
+ dev.clearUncommitedData();
+ }
+ for(TestDeviceObject dev : devicesToAdd) {
+ dev.clearUncommitedData();
+ }
+
+ for(TestSwitchObject sw : switches) {
+ sw.clearUncommitedData();
+ }
+ for(TestSwitchObject sw : switchesToAdd) {
+ sw.clearUncommitedData();
+ }
+
+ for(TestPortObject port : ports) {
+ port.clearUncommitedData();
+ }
+ for(TestPortObject port : portsToAdd) {
+ port.clearUncommitedData();
+ }
+
+ entriesToAdd.clear();
+ entriesToRemove.clear();
+ devicesToAdd.clear();
+ devicesToRemove.clear();
+ switchesToAdd.clear();
+ switchesToRemove.clear();
+ portsToAdd.clear();
+ portsToRemove.clear();
+ }
+
+
+ // this.*ForTest() methods below are supposed to be used for creation of test topology.
+ /**
+ * Create new empty TestSwitchObject.
+ * @return New TestSwitchObject
+ */
+ public TestSwitchObject createNewSwitchForTest() {
+ TestSwitchObject sw = new TestSwitchObject();
+ switches.add(sw);
+ return sw;
+ }
+
+ /**
+ * Create new TestSwitchObject with specific DPID.
+ * @param dpid DPID to be set
+ * @return New TestSwitchObject
+ */
+ public TestSwitchObject createNewSwitchForTest(String dpid) {
+ for(TestSwitchObject sw_loop : switches) {
+ if(sw_loop.getDPID().equals(dpid)) {
+ // Already created
+ log.error("switch already exists : " + dpid);
+ return sw_loop;
+ }
+ }
+
+ TestSwitchObject sw = new TestSwitchObject();
+
+ sw.setDpidForTest(dpid);
+ switches.add(sw);
+
+ return sw;
+ }
+
+ /**
+ * Create new empty TestPortObject.
+ * @return New TestPortObject
+ */
+ public TestPortObject createNewPortForTest() {
+ TestPortObject port = new TestPortObject();
+ ports.add(port);
+ return port;
+ }
+
+ /**
+ * Create new TestPortObject with specific DPID and port number.
+ * @param dpid DPID to be set
+ * @param number Port number to be set
+ * @return New TestPortObject
+ */
+ public TestPortObject createNewPortForTest(String dpid, Short number) {
+ TestSwitchObject sw = null;
+
+ for(TestSwitchObject sw_loop : switches) {
+ if(sw_loop.getDPID().equals(dpid)) {
+ sw = sw_loop;
+ }
+ }
+
+ if(sw != null) {
+ TestPortObject port = new TestPortObject();
+ port.setNumberForTest(number);
+ port.setSwitchForTest(sw);
+ sw.addPortForTest(port);
+
+ ports.add(port);
+
+ return port;
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Link a TestPortObject to other TestPortObject.
+ * @param src TestPortObjecgt of source port.
+ * @param dst TestPortObjecgt of destination port.
+ */
+ public void setLinkBetweenPortsForTest(TestPortObject src, TestPortObject dst) {
+ src.addLinkedPortForTest(dst);
+ }
+
+ /**
+ * Create new empty TestDeviceObject.
+ * @return New TestDeviceObject
+ */
+ public TestDeviceObject createNewDeviceForTest() {
+ TestDeviceObject dev = new TestDeviceObject();
+
+ return dev;
+ }
+
+ /**
+ * Create new empty TestFlowPathObject.
+ * @return New TestFlowPathObject
+ */
+ public TestFlowPath createNewFlowPathForTest() {
+ TestFlowPath path = new TestFlowPath();
+ paths.add(path);
+ return path;
+ }
+
+ /**
+ * Create new empty TestFlowEntryObject.
+ * @return New TestFlowEntryObject
+ */
+ public TestFlowEntry createNewFlowEntryForTest() {
+ TestFlowEntry entry = new TestFlowEntry();
+ entries.add(entry);
+ return entry;
+ }
+
+
+ public boolean hasLinkBetween(String srcSw_str, Short srcNumber, String dstSw_str, Short dstNumber) {
+ IPortObject srcPort = null, dstPort = null;
+ long srcSw = HexString.toLong(srcSw_str);
+ long dstSw = HexString.toLong(dstSw_str);
+
+ for(TestSwitchObject sw : switches) {
+ long swLong = HexString.toLong(sw.getDPID());
+ if(swLong == srcSw) {
+ for(IPortObject port : sw.getPorts()) {
+ if(port.getNumber().equals(srcNumber)) {
+ srcPort = port;
+ }
+ }
+ } else if(swLong == dstSw) {
+ for(IPortObject port : sw.getPorts()) {
+ if(port.getNumber().equals(dstNumber)) {
+ dstPort = port;
+ }
+ }
+ }
+ }
+
+ if(srcPort != null && dstPort != null) {
+ for(IPortObject port : srcPort.getLinkedPorts()) {
+ if(port.equals(dstPort)) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ // Overriding methods below are to mock GraphDBOperation class.
+ @Override
+ public ISwitchObject newSwitch(String dpid) {
+ TestSwitchObject sw = new TestSwitchObject();
+ sw.setDPID(dpid);
+ switchesToAdd.add(sw);
+
+ return sw;
+ }
+
+ @Override
+ public ISwitchObject searchSwitch(String dpid_str) {
+ Long dpid = HexString.toLong(dpid_str);
+
+ for(ISwitchObject sw : switches) {
+ if(HexString.toLong(sw.getDPID()) == dpid) {
+ return sw;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public ISwitchObject searchActiveSwitch(String dpid_str) {
+ Long dpid = HexString.toLong(dpid_str);
+
+ for(ISwitchObject sw : switches) {
+ if(HexString.toLong(sw.getDPID()) == dpid && sw.getState().equals("ACTIVE")) {
+ return sw;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public Iterable<ISwitchObject> getActiveSwitches() {
+ List<ISwitchObject> list = new ArrayList<ISwitchObject>();
+
+ for(ISwitchObject sw : switches) {
+ if(sw.getState() != null && sw.getState().equals("ACTIVE")) {
+ list.add(sw);
+ }
+ }
+ return list.isEmpty() ? null : list;
+ }
+
+ @Override
+ public Iterable<ISwitchObject> getAllSwitches() {
+ List<ISwitchObject> list = new ArrayList<ISwitchObject>();
+
+ for(ISwitchObject sw : switches) {
+ list.add(sw);
+ }
+
+ return list.isEmpty() ? null : list;
+ }
+
+ @Override
+ public Iterable<ISwitchObject> getInactiveSwitches() {
+ List<ISwitchObject> list = new ArrayList<ISwitchObject>();
+
+ for(ISwitchObject sw : switches) {
+ if(! sw.getState().equals("ACTIVE")) {
+ list.add(sw);
+ }
+ }
+ return list.isEmpty() ? null : list;
+ }
+
+ @Override
+ public Iterable<IFlowEntry> getAllSwitchNotUpdatedFlowEntries() {
+ List<IFlowEntry> list = new ArrayList<IFlowEntry>();
+
+ for(TestFlowEntry entry : entries) {
+ if(entry.getSwitchState().equals("FE_SWITCH_NOT_UPDATED")) {
+ list.add(entry);
+ }
+ }
+ return list;
+ }
+
+ @Override
+ public void removeSwitch(ISwitchObject sw) {
+ if(switches.contains(sw)) {
+ switchesToRemove.add((TestSwitchObject)sw);
+ }
+ }
+
+ @Override
+ public IPortObject newPort(Short portNumber) {
+ TestPortObject port = new TestPortObject();
+ port.setNumber(portNumber);
+
+ return port;
+ }
+
+ public IPortObject newPort(Long dpid, Short portNumber) {
+ TestPortObject port = null;
+ TestSwitchObject sw = (TestSwitchObject)searchSwitch(HexString.toHexString(dpid));
+
+ if(sw != null) {
+ port = (TestPortObject)newPort(portNumber);
+ portsToAdd.add(port);
+ sw.addPort(port);
+ }
+
+ return port;
+ }
+
+ @Override
+ public IPortObject searchPort(String dpid_str, short number) {
+ long dpid = HexString.toLong(dpid_str);
+
+ for(TestSwitchObject sw : switches) {
+ if(HexString.toLong(sw.getDPID()) == dpid) {
+ for(IPortObject port : sw.getPorts()) {
+ if(port.getNumber().equals(number)) {
+ return port;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public void removePort(IPortObject port) {
+ for(TestSwitchObject sw : switches) {
+ for(IPortObject pt : sw.getPorts()) {
+ if(pt.equals(port)) {
+ sw.removePort(port);
+ }
+ }
+ }
+ portsToRemove.add((TestPortObject)port);
+ }
+
+ @Override
+ public IDeviceObject newDevice() {
+ TestDeviceObject dev = new TestDeviceObject();
+ devicesToAdd.add(dev);
+
+ return dev;
+ }
+
+ @Override
+ public IDeviceObject searchDevice(String macAddr) {
+ for(IDeviceObject dev : devices) {
+ if(dev.getMACAddress().equals(macAddr)) {
+ return dev;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public Iterable<IDeviceObject> getDevices() {
+ List<IDeviceObject> list = new ArrayList<IDeviceObject>();
+
+ for(TestDeviceObject dev : devices) {
+ list.add(dev);
+ }
+
+ return list;
+ }
+
+ @Override
+ public void removeDevice(IDeviceObject dev) {
+ if(devices.contains((TestDeviceObject)dev)) {
+ devicesToRemove.add((TestDeviceObject)dev);
+ }
+ }
+
+ @Override
+ public IFlowPath newFlowPath() {
+ TestFlowPath path = new TestFlowPath();
+ pathsToAdd.add(path);
+
+ return path;
+ }
+
+ @Override
+ public IFlowPath searchFlowPath(FlowId flowId) {
+ for(IFlowPath path : paths) {
+ if(path.getFlowId().equals(flowId)) {
+ return path;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public IFlowPath getFlowPathByFlowEntry(IFlowEntry flowEntry) {
+ for(IFlowPath path : paths) {
+ for(IFlowEntry entry : path.getFlowEntries()) {
+ if(entry.equals(flowEntry)) {
+ return path;
+ }
+ }
+
+ }
+ return null;
+ }
+
+ @Override
+ public Iterable<IFlowPath> getAllFlowPaths() {
+ List<IFlowPath> list = new ArrayList<IFlowPath>();
+
+ for(IFlowPath path : paths) {
+ list.add(path);
+ }
+
+ return list;
+ }
+
+ @Override
+ public void removeFlowPath(IFlowPath flowPath) {
+ if(paths.contains((TestFlowPath)flowPath)) {
+ pathsToRemove.add((TestFlowPath)flowPath);
+ }
+ }
+
+ @Override
+ public IFlowEntry newFlowEntry() {
+ TestFlowEntry entry = new TestFlowEntry();
+ entriesToAdd.add(entry);
+ return entry;
+ }
+
+ @Override
+ public IFlowEntry searchFlowEntry(FlowEntryId flowEntryId) {
+ for(TestFlowEntry entry : entries) {
+ // TODO check if this matching works
+ if(entry.getFlowEntryId().equals(flowEntryId)) {
+ return entry;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public Iterable<IFlowEntry> getAllFlowEntries() {
+ List<IFlowEntry> list = new ArrayList<IFlowEntry>();
+
+ for(TestFlowEntry entry : entries) {
+ list.add(entry);
+ }
+
+ return list;
+ }
+
+ @Override
+ public void removeFlowEntry(IFlowEntry flowEntry) {
+ if(entries.contains((TestFlowEntry)flowEntry)) {
+ entriesToRemove.add((TestFlowEntry)flowEntry);
+ }
+ }
+
+ @Override
+ public IDBConnection getDBConnection() {
+ return super.getDBConnection();
+ }
+
+ @Override
+ public void commit() {
+ for(TestSwitchObject sw : switchesToAdd) {
+ switches.add(sw);
+ }
+ for(TestSwitchObject sw : switchesToRemove) {
+ sw.commit();
+ switches.remove(sw);
+ }
+ for(TestSwitchObject sw : switches) {
+ sw.commit();
+ }
+
+ for(TestPortObject port : portsToAdd) {
+ ports.add(port);
+ }
+ for(TestPortObject port : portsToRemove) {
+ port.commit();
+ ports.remove(port);
+ }
+ for(TestPortObject port : ports) {
+ port.commit();
+ }
+
+ for(TestDeviceObject dev : devicesToAdd) {
+ devices.add(dev);
+ }
+ for(TestDeviceObject dev : devicesToRemove) {
+ dev.commit();
+ devices.remove(dev);
+ }
+ for(TestDeviceObject dev : devices) {
+ dev.commit();
+ }
+
+ clearUncommitedData();
+ }
+
+ @Override
+ public void rollback() {
+ clearUncommitedData();
+ }
+
+ @Override
+ public void close() {
+ // TODO Auto-generated method stub
+
+ }
+}
diff --git a/src/test/java/net/floodlightcontroller/linkdiscovery/internal/TestableLinkStorageImpl.java b/src/test/java/net/onrc/onos/ofcontroller/core/internal/TestableLinkStorageImpl.java
similarity index 89%
rename from src/test/java/net/floodlightcontroller/linkdiscovery/internal/TestableLinkStorageImpl.java
rename to src/test/java/net/onrc/onos/ofcontroller/core/internal/TestableLinkStorageImpl.java
index 5709f03..2f90d48 100644
--- a/src/test/java/net/floodlightcontroller/linkdiscovery/internal/TestableLinkStorageImpl.java
+++ b/src/test/java/net/onrc/onos/ofcontroller/core/internal/TestableLinkStorageImpl.java
@@ -1,7 +1,9 @@
-package net.floodlightcontroller.linkdiscovery.internal;
+package net.onrc.onos.ofcontroller.core.internal;
import java.util.Set;
+import net.onrc.onos.ofcontroller.core.internal.LinkStorageImpl;
+
import com.thinkaurelius.titan.core.TitanGraph;
import com.tinkerpop.blueprints.TransactionalGraph.Conclusion;
import com.tinkerpop.blueprints.Vertex;
diff --git a/src/test/java/net/floodlightcontroller/core/internal/TestableSwitchStorageImpl.java b/src/test/java/net/onrc/onos/ofcontroller/core/internal/TestableSwitchStorageImpl.java
similarity index 93%
rename from src/test/java/net/floodlightcontroller/core/internal/TestableSwitchStorageImpl.java
rename to src/test/java/net/onrc/onos/ofcontroller/core/internal/TestableSwitchStorageImpl.java
index a73b90f..e78a1b6 100644
--- a/src/test/java/net/floodlightcontroller/core/internal/TestableSwitchStorageImpl.java
+++ b/src/test/java/net/onrc/onos/ofcontroller/core/internal/TestableSwitchStorageImpl.java
@@ -1,4 +1,4 @@
-package net.floodlightcontroller.core.internal;
+package net.onrc.onos.ofcontroller.core.internal;
import java.util.Set;
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 5309667..5cdcbb5 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
@@ -1,24 +1,30 @@
package net.onrc.onos.ofcontroller.devicemanager.internal;
-import static org.junit.Assert.*;
-import static org.easymock.EasyMock.*;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.List;
-import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IDeviceObject;
-import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IPortObject;
-import net.onrc.onos.ofcontroller.core.internal.SwitchStorageImpl;
-import net.onrc.onos.ofcontroller.devicemanager.internal.DeviceStorageImpl;
-import net.onrc.onos.util.GraphDBConnection;
-import net.onrc.onos.util.GraphDBOperation;
import net.floodlightcontroller.devicemanager.IDevice;
import net.floodlightcontroller.devicemanager.SwitchPort;
-import net.floodlightcontroller.devicemanager.internal.Device;
import net.floodlightcontroller.packet.IPv4;
+import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IDeviceObject;
+import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IPortObject;
+import net.onrc.onos.ofcontroller.core.internal.DeviceStorageImpl;
+import net.onrc.onos.ofcontroller.core.internal.SwitchStorageImpl;
+import net.onrc.onos.util.GraphDBConnection;
+import net.onrc.onos.util.GraphDBOperation;
+import net.floodlightcontroller.devicemanager.internal.Device;
import org.easymock.EasyMock;
import org.junit.After;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openflow.util.HexString;
@@ -43,7 +49,9 @@
@Before
public void setUp() throws Exception {
-
+ deviceImpl = new DeviceStorageImpl();
+ conf = "/dummy/path/to/db";
+
PowerMock.mockStatic(GraphDBConnection.class);
mockConn = createMock(GraphDBConnection.class);
PowerMock.suppress(PowerMock.constructor(GraphDBConnection.class));
@@ -52,19 +60,22 @@
//PowerMock.mockStatic(GraphDBOperation.class);
mockOpe = PowerMock.createMock(GraphDBOperation.class);
- PowerMock.expectNew(GraphDBOperation.class, mockConn).andReturn(mockOpe);
+ PowerMock.expectNew(GraphDBOperation.class, new Class<?>[]{String.class}, conf).andReturn(mockOpe);
+ mockOpe.close();
PowerMock.replay(GraphDBOperation.class);
// Replace the conf to dummy conf
// String conf = "/tmp/cassandra.titan";
- conf = "/dummy/path/to/db";
+
- deviceImpl = new DeviceStorageImpl();
+
}
@After
public void tearDown() throws Exception {
deviceImpl.close();
deviceImpl = null;
+
+ verify(mockOpe);
}
private String makeIPStringFromArray(Integer[] ipaddresses){
@@ -142,7 +153,6 @@
expect(mockOpe.newDevice()).andReturn(mockIDev);
expect(mockOpe.searchPort(switchMacAddr, portNum)).andReturn(mockIPort);
mockOpe.commit();
-
replay(mockOpe);
deviceImpl.init(conf);
@@ -152,7 +162,6 @@
assertNotNull(obj);
verify(mockIDev);
- verify(mockOpe);
} catch(Exception e) {
fail(e.getMessage());
@@ -233,10 +242,7 @@
//Add the same device
IDeviceObject obj2 = deviceImpl.addDevice(mockDev);
assertNotNull(obj2);
-
- verify(mockIDev);
- verify(mockOpe);
-
+
} catch(Exception e) {
fail(e.getMessage());
}
@@ -329,7 +335,6 @@
assertNotNull(obj2);
verify(mockIDev);
- verify(mockOpe);
} catch(Exception e) {
fail(e.getMessage());
@@ -423,7 +428,7 @@
assertNull(dev2);
verify(mockIDev);
- verify(mockOpe);
+
} catch(Exception e) {
fail(e.getMessage());
}
@@ -505,7 +510,7 @@
assertNotNull(dev);
verify(mockIDev);
- verify(mockOpe);
+
} catch(Exception e) {
fail(e.getMessage());
}
@@ -594,7 +599,7 @@
assertNotNull(dev);
verify(mockIDev);
- verify(mockOpe);
+
} catch(Exception e) {
fail(e.getMessage());
@@ -729,18 +734,17 @@
deviceImpl.changeDeviceAttachments(mockDev3);
verify(mockIDev);
- verify(mockOpe);
+
} catch(Exception e) {
fail(e.getMessage());
}
}
- //@Ignore
+ @Ignore
@Test
public void testChangeDeviceAttachmentsIDeviceIDeviceObject() {
//It is tested by the testChangeDeviceAttachmentsIDevice
- deviceImpl.init(conf);
}
/**
@@ -822,7 +826,7 @@
deviceImpl.changeDeviceIPv4Address(mockDev2);
verify(mockIDev);
- verify(mockOpe);
+
}
catch(Exception e) {
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 8ec42be..cea70f0 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
@@ -10,11 +10,12 @@
import net.floodlightcontroller.devicemanager.SwitchPort;
import net.floodlightcontroller.devicemanager.internal.Device;
import net.floodlightcontroller.packet.IPv4;
+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.INetMapTopologyObjects.ISwitchObject;
+import net.onrc.onos.ofcontroller.core.internal.DeviceStorageImpl;
import net.onrc.onos.ofcontroller.core.internal.SwitchStorageImpl;
-import net.onrc.onos.ofcontroller.devicemanager.IDeviceStorage;
import net.onrc.onos.util.GraphDBConnection;
import net.onrc.onos.util.GraphDBOperation;
diff --git a/src/test/java/net/floodlightcontroller/linkdiscovery/internal/LinkDiscoveryManagerTest.java b/src/test/java/net/onrc/onos/ofcontroller/linkdiscovery/internal/LinkDiscoveryManagerTest.java
similarity index 97%
rename from src/test/java/net/floodlightcontroller/linkdiscovery/internal/LinkDiscoveryManagerTest.java
rename to src/test/java/net/onrc/onos/ofcontroller/linkdiscovery/internal/LinkDiscoveryManagerTest.java
index 6e99acd..87b48b2 100644
--- a/src/test/java/net/floodlightcontroller/linkdiscovery/internal/LinkDiscoveryManagerTest.java
+++ b/src/test/java/net/onrc/onos/ofcontroller/linkdiscovery/internal/LinkDiscoveryManagerTest.java
@@ -15,7 +15,7 @@
* under the License.
**/
-package net.floodlightcontroller.linkdiscovery.internal;
+package net.onrc.onos.ofcontroller.linkdiscovery.internal;
import static org.easymock.EasyMock.*;
@@ -35,10 +35,6 @@
import net.floodlightcontroller.core.IOFSwitch;
import net.floodlightcontroller.core.module.FloodlightModuleContext;
import net.floodlightcontroller.core.test.MockThreadPoolService;
-import net.floodlightcontroller.linkdiscovery.ILinkDiscoveryListener;
-import net.floodlightcontroller.linkdiscovery.ILinkDiscoveryService;
-import net.floodlightcontroller.linkdiscovery.LinkInfo;
-import net.floodlightcontroller.linkdiscovery.internal.LinkDiscoveryManager;
import net.floodlightcontroller.restserver.IRestApiService;
import net.floodlightcontroller.restserver.RestApiServer;
import net.floodlightcontroller.routing.IRoutingService;
@@ -50,6 +46,10 @@
import net.floodlightcontroller.topology.ITopologyService;
import net.floodlightcontroller.topology.NodePortTuple;
import net.floodlightcontroller.topology.TopologyManager;
+import net.onrc.onos.ofcontroller.linkdiscovery.ILinkDiscoveryListener;
+import net.onrc.onos.ofcontroller.linkdiscovery.ILinkDiscoveryService;
+import net.onrc.onos.ofcontroller.linkdiscovery.LinkInfo;
+import net.onrc.onos.ofcontroller.linkdiscovery.internal.LinkDiscoveryManager;
/**
*
diff --git a/src/test/java/net/onrc/onos/util/GraphDBOperationTest.java b/src/test/java/net/onrc/onos/util/GraphDBOperationTest.java
index d1e1c39..223ac67 100644
--- a/src/test/java/net/onrc/onos/util/GraphDBOperationTest.java
+++ b/src/test/java/net/onrc/onos/util/GraphDBOperationTest.java
@@ -5,11 +5,19 @@
import static org.junit.Assert.*;
-import java.util.Iterator;
+import java.util.*;
+import junit.framework.TestCase;
+
+import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IDeviceObject;
+import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowEntry;
+import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowPath;
+import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IPortObject;
import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject;
import net.onrc.onos.ofcontroller.core.ISwitchStorage.SwitchState;
-import net.floodlightcontroller.core.internal.TestDatabaseManager;
+import net.onrc.onos.ofcontroller.core.internal.TestDatabaseManager;
+import net.onrc.onos.ofcontroller.util.FlowEntryId;
+import net.onrc.onos.ofcontroller.util.FlowId;
import org.easymock.EasyMock;
import org.junit.After;
@@ -30,11 +38,11 @@
* @author Toshio Koide
*
*/
+
@RunWith(PowerMockRunner.class)
@PrepareForTest({TitanFactory.class})
-public class GraphDBOperationTest {
+public class GraphDBOperationTest extends TestCase {
private static TitanGraph testdb;
- private static GraphDBConnection conn;
private static GraphDBOperation op;
/**
@@ -59,14 +67,14 @@
TestDatabaseManager.deleteTestDatabase();
testdb = TestDatabaseManager.getTestDatabase();
// TestDatabaseManager.populateTestData(titanGraph);
-
+
+ String dummyPath = "/dummy/to/conf";
// replace return value of TitanFactory.open() to dummy DB created above
PowerMock.mockStatic(TitanFactory.class);
- EasyMock.expect(TitanFactory.open((String)EasyMock.anyObject())).andReturn(testdb);
+ EasyMock.expect(TitanFactory.open(dummyPath)).andReturn(testdb);
PowerMock.replay(TitanFactory.class);
- conn = GraphDBConnection.getInstance("/dummy/to/conf");
- op = new GraphDBOperation(conn);
+ op = new GraphDBOperation(dummyPath);
}
/**
@@ -74,30 +82,24 @@
*/
@After
public void tearDown() throws Exception {
- conn.close();
+ op.close();
testdb.shutdown();
+ PowerMock.verifyAll();
}
- private Iterator<Vertex> enumerateVertices(String vertexType) {
- return testdb.getVertices("type", vertexType).iterator();
- }
-
/**
* Test method for {@link net.onrc.onos.util.GraphDBOperation#newSwitch(net.onrc.onos.util.GraphDBConnection)}.
*/
@Test
public final void testNewSwitch() {
- Iterator<Vertex> vertices;
- assertFalse(enumerateVertices("switch").hasNext());
+ assertNull(op.searchSwitch("123"));
- ISwitchObject sw = op.newSwitch("123");
-
- assertEquals("123", sw.getDPID());
+ op.newSwitch("123");
op.commit();
- vertices = enumerateVertices("switch");
- assertTrue(vertices.hasNext());
- assertEquals(vertices.next().getProperty("dpid").toString(), "123");
+ ISwitchObject sw = op.searchSwitch("123");
+ assertNotNull(op);
+ assertEquals("123", sw.getDPID());
}
/**
@@ -105,13 +107,16 @@
*/
@Test
public final void testSearchSwitch() {
- ISwitchObject sw = op.newSwitch("123");
+ op.newSwitch("123");
+ op.newSwitch("456");
op.commit();
-
- sw = op.searchSwitch("123");
-
+
+ ISwitchObject sw = op.searchSwitch("123");
assertNotNull(sw);
assertEquals("123", sw.getDPID());
+
+ sw = op.searchSwitch("789");
+ assertNull(sw);
}
/**
@@ -119,13 +124,11 @@
*/
@Test
public final void testSearchActiveSwitch() {
- ISwitchObject sw = op.newSwitch("111");
- sw.setState(SwitchState.ACTIVE.toString());
- sw = op.newSwitch("222");
- sw.setState(SwitchState.INACTIVE.toString());
+ op.newSwitch("111").setState(SwitchState.ACTIVE.toString());
+ op.newSwitch("222").setState(SwitchState.INACTIVE.toString());
op.commit();
- sw = op.searchActiveSwitch("111");
+ ISwitchObject sw = op.searchActiveSwitch("111");
assertNotNull(sw);
assertEquals("111", sw.getDPID());
@@ -138,16 +141,71 @@
*/
@Test
public final void testGetActiveSwitches() {
- ISwitchObject sw = op.newSwitch("111");
- sw.setState(SwitchState.ACTIVE.toString());
- sw = op.newSwitch("222");
- sw.setState(SwitchState.INACTIVE.toString());
+ op.newSwitch("111").setState(SwitchState.ACTIVE.toString());
+ op.newSwitch("222").setState(SwitchState.INACTIVE.toString());
op.commit();
Iterator<ISwitchObject> i = op.getActiveSwitches().iterator();
+
assertTrue(i.hasNext());
assertEquals("111", i.next().getDPID());
- assertFalse(i.hasNext());
+ assertFalse(i.hasNext());
+ }
+
+ /**
+ * Test method for {@link net.onrc.onos.util.GraphDBOperation#getAllSwitches(net.onrc.onos.util.GraphDBConnection)}.
+ */
+ @Test
+ public final void testGetAllSwitches() {
+ List<String> dpids = Arrays.asList("111", "222", "333");
+ Collections.sort(dpids);
+
+ for (String dpid: dpids) op.newSwitch(dpid);
+ op.commit();
+
+ List<String> actual_ids = new ArrayList<String>();
+ for (ISwitchObject switchObj: op.getAllSwitches()) actual_ids.add(switchObj.getDPID());
+ Collections.sort(actual_ids);
+
+ assertArrayEquals(dpids.toArray(), actual_ids.toArray());
+ }
+
+ /**
+ * Test method for {@link net.onrc.onos.util.GraphDBOperation#getInactiveSwitches(net.onrc.onos.util.GraphDBConnection)}.
+ */
+ @Test
+ public final void testGetInactiveSwitches() {
+ op.newSwitch("111").setState(SwitchState.ACTIVE.toString());
+ op.newSwitch("222").setState(SwitchState.INACTIVE.toString());
+ op.commit();
+
+ Iterator<ISwitchObject> i = op.getInactiveSwitches().iterator();
+
+ assertTrue(i.hasNext());
+ assertEquals("222", i.next().getDPID());
+ assertFalse(i.hasNext());
+ }
+
+ /**
+ * Test method for {@link net.onrc.onos.util.GraphDBOperation#getAllSwitchNotUpdatedFlowEntries(net.onrc.onos.util.GraphDBConnection)}.
+ */
+ @Test
+ public final void testGetAllSwitchNotUpdatedFlowEntries() {
+ FlowEntryId flowEntryId10 = new FlowEntryId(10);
+ FlowEntryId flowEntryId20 = new FlowEntryId(20);
+ IFlowEntry flowEntry10 = op.newFlowEntry();
+ IFlowEntry flowEntry20 = op.newFlowEntry();
+ flowEntry10.setFlowEntryId(flowEntryId10.toString());
+ flowEntry20.setFlowEntryId(flowEntryId20.toString());
+ flowEntry10.setSwitchState("FE_SWITCH_NOT_UPDATED");
+ flowEntry20.setSwitchState("FE_SWITCH_UPDATED");
+ op.commit();
+
+ Iterator<IFlowEntry> flowEntries = op.getAllSwitchNotUpdatedFlowEntries().iterator();
+ assertNotNull(flowEntries);
+ assertTrue(flowEntries.hasNext());
+ assertEquals(flowEntryId10.toString(), flowEntries.next().getFlowEntryId());
+ assertFalse(flowEntries.hasNext());
}
/**
@@ -158,26 +216,12 @@
ISwitchObject sw = op.newSwitch("123");
op.commit();
sw = op.searchSwitch("123");
-
+ assertNotNull(sw);
+
op.removeSwitch(sw);
-
- assertFalse(enumerateVertices("switch").hasNext());
- }
-
- /**
- * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchDevice(net.onrc.onos.util.GraphDBConnection, java.lang.String)}.
- */
- @Test
- public final void testSearchDevice() {
- fail("Not yet implemented");
- }
-
- /**
- * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchPort(net.onrc.onos.util.GraphDBConnection, java.lang.String, short)}.
- */
- @Test
- public final void testSearchPort() {
- fail("Not yet implemented");
+ op.commit();
+
+ assertNull(op.searchSwitch("123"));
}
/**
@@ -185,15 +229,65 @@
*/
@Test
public final void testNewPort() {
- fail("Not yet implemented");
+ assertFalse(testdb.getVertices("type", "port").iterator().hasNext());
+
+ IPortObject port = op.newPort((short) 10);
+ assertTrue(port.getNumber() == 10);
+ op.commit();
+
+ Iterator<Vertex> vertices = testdb.getVertices("type", "port").iterator();
+ assertTrue(vertices.hasNext());
+ assertEquals(vertices.next().getProperty("number").toString(), "10");
}
/**
- * Test method for {@link net.onrc.onos.util.GraphDBOperation#newDevice(net.onrc.onos.util.GraphDBConnection)}.
+ * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchPort(net.onrc.onos.util.GraphDBConnection, java.lang.String, short)}.
*/
@Test
- public final void testNewDevice() {
- fail("Not yet implemented");
+ public final void testSearchPort() {
+ ISwitchObject sw;
+ IPortObject port;
+
+ sw = op.newSwitch("1");
+ sw.addPort(op.newPort((short) 1));
+ sw.addPort(op.newPort((short) 2));
+
+ sw = op.newSwitch("2");
+ sw.addPort(op.newPort((short) 1));
+ sw.addPort(op.newPort((short) 2));
+
+ op.commit();
+
+ assertNull(op.searchPort("3", (short) 1));
+ assertNull(op.searchPort("1", (short) 3));
+
+ port = op.searchPort("1", (short) 1);
+ assertNotNull(port);
+ assertTrue(port.getNumber() == 1);
+ sw = port.getSwitch();
+ assertNotNull(sw);
+ assertEquals("1", sw.getDPID());
+
+ port = op.searchPort("1", (short) 2);
+ assertNotNull(port);
+ assertTrue(port.getNumber() == 2);
+ sw = port.getSwitch();
+ assertNotNull(sw);
+ assertEquals("1", sw.getDPID());
+
+ port = op.searchPort("2", (short) 1);
+ assertNotNull(port);
+ assertTrue(port.getNumber() == 1);
+ sw = port.getSwitch();
+ assertNotNull(sw);
+ assertEquals("2", sw.getDPID());
+
+ port = op.searchPort("2", (short) 2);
+ assertNotNull(port);
+ assertTrue(port.getNumber() == 2);
+ sw = port.getSwitch();
+ assertNotNull(sw);
+ assertEquals("2", sw.getDPID());
}
/**
@@ -201,15 +295,69 @@
*/
@Test
public final void testRemovePort() {
- fail("Not yet implemented");
+ ISwitchObject sw;
+ IPortObject port;
+
+ sw = op.newSwitch("1");
+ sw.addPort(op.newPort((short) 1));
+ sw.addPort(op.newPort((short) 2));
+
+ op.commit();
+
+ port = op.searchPort("1", (short) 1);
+ assertNotNull(port);
+ assertNotNull(op.searchPort("1", (short) 2));
+ assertNull(op.searchPort("1", (short) 3));
+
+ op.removePort(port);
+ op.commit();
+
+ assertNull(op.searchPort("1", (short) 1));
+ port = op.searchPort("1", (short) 2);
+ assertNotNull(port);
+
+ op.removePort(port);
+ op.commit();
+
+ assertNull(op.searchPort("1", (short) 1));
+ assertNull(op.searchPort("1", (short) 2));
}
/**
- * Test method for {@link net.onrc.onos.util.GraphDBOperation#removeDevice(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IDeviceObject)}.
+ * Test method for {@link net.onrc.onos.util.GraphDBOperation#newDevice(net.onrc.onos.util.GraphDBConnection)}.
*/
@Test
- public final void testRemoveDevice() {
- fail("Not yet implemented");
+ public final void testNewDevice() {
+ assertFalse(testdb.getVertices("type", "device").iterator().hasNext());
+
+ IDeviceObject device = op.newDevice();
+ device.setMACAddress("11:22:33:44:55:66");
+ device.setIPAddress("192.168.1.1");
+ op.commit();
+
+ Iterator<Vertex> vertices = testdb.getVertices("type", "device").iterator();
+ assertTrue(vertices.hasNext());
+ Vertex v = vertices.next();
+ assertEquals("11:22:33:44:55:66", v.getProperty("dl_addr").toString());
+ assertEquals("192.168.1.1", v.getProperty("nw_addr").toString());
+ }
+
+ /**
+ * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchDevice(net.onrc.onos.util.GraphDBConnection, java.lang.String)}.
+ */
+ @Test
+ public final void testSearchDevice() {
+ assertNull(op.searchDevice("11:22:33:44:55:66"));
+ assertNull(op.searchDevice("66:55:44:33:22:11"));
+
+ op.newDevice().setMACAddress("11:22:33:44:55:66");
+ op.commit();
+
+ IDeviceObject device = op.searchDevice("11:22:33:44:55:66");
+ assertNotNull(device);
+ assertEquals("11:22:33:44:55:66", device.getMACAddress());
+
+ assertNull(op.searchDevice("66:55:44:33:22:11"));
}
/**
@@ -217,15 +365,33 @@
*/
@Test
public final void testGetDevices() {
- fail("Not yet implemented");
+ List<String> original_macs = Arrays.asList(
+ "11:11:11:11:11:11",
+ "22:22:22:22:22:22",
+ "33:33:33:33:33:33"
+ );
+
+ for (String mac: original_macs) op.newDevice().setMACAddress(mac);
+ op.commit();
+
+ Iterable<IDeviceObject> devices = op.getDevices();
+ List<String> macs = new ArrayList<String>();
+ for (IDeviceObject device: devices) macs.add(device.getMACAddress());
+ Collections.sort(macs);
+ assertArrayEquals(original_macs.toArray(), macs.toArray());
}
/**
- * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchFlowPath(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.util.FlowId)}.
+ * Test method for {@link net.onrc.onos.util.GraphDBOperation#removeDevice(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IDeviceObject)}.
*/
@Test
- public final void testSearchFlowPath() {
- fail("Not yet implemented");
+ public final void testRemoveDevice() {
+ op.newDevice().setMACAddress("11:22:33:44:55:66");
+ op.commit();
+
+ op.removeDevice(op.searchDevice("11:22:33:44:55:66"));
+ op.commit();
+ assertNull(op.searchDevice("11:22:33:44:55:66"));
}
/**
@@ -233,15 +399,30 @@
*/
@Test
public final void testNewFlowPath() {
- fail("Not yet implemented");
+ FlowId flowId = new FlowId(10);
+ IFlowPath flowPath = op.newFlowPath();
+ flowPath.setFlowId(flowId.toString());
+ op.commit();
+
+ Iterator<IFlowPath> flows = op.getAllFlowPaths().iterator();
+ assertTrue(flows.hasNext());
+ assertEquals(flowId.toString(), flows.next().getFlowId());
}
/**
- * Test method for {@link net.onrc.onos.util.GraphDBOperation#removeFlowPath(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IFlowPath)}.
+ * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchFlowPath(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.util.FlowId)}.
*/
@Test
- public final void testRemoveFlowPath() {
- fail("Not yet implemented");
+ public final void testSearchFlowPath() {
+ FlowId flowId = new FlowId(20);
+ assertNull(op.searchFlowPath(flowId));
+
+ op.newFlowPath().setFlowId(flowId.toString());
+ op.commit();
+
+ IFlowPath flowPath = op.searchFlowPath(flowId);
+ assertNotNull(flowPath);
+ assertEquals(flowId.toString(), flowPath.getFlowId());
}
/**
@@ -249,7 +430,38 @@
*/
@Test
public final void testGetFlowPathByFlowEntry() {
- fail("Not yet implemented");
+ FlowId flowId10 = new FlowId(10);
+ FlowId flowId20 = new FlowId(20);
+ IFlowPath flowPath10 = op.newFlowPath();
+ IFlowPath flowPath20 = op.newFlowPath();
+ IFlowEntry flowEntry10 = op.newFlowEntry();
+ IFlowEntry flowEntry20 = op.newFlowEntry();
+ IFlowEntry flowEntry30 = op.newFlowEntry();
+ FlowEntryId flowEntryId10 = new FlowEntryId(10);
+ FlowEntryId flowEntryId20 = new FlowEntryId(20);
+ FlowEntryId flowEntryId30 = new FlowEntryId(30);
+ flowEntry10.setFlowEntryId(flowEntryId10.toString());
+ flowEntry20.setFlowEntryId(flowEntryId20.toString());
+ flowEntry30.setFlowEntryId(flowEntryId30.toString());
+ flowPath10.setFlowId(flowId10.toString());
+ flowPath10.addFlowEntry(flowEntry10);
+ flowPath20.setFlowId(flowId20.toString());
+ flowPath20.addFlowEntry(flowEntry20);
+ op.commit();
+
+ flowEntry10 = op.searchFlowEntry(flowEntryId10);
+ IFlowPath obtainedFlowPath = op.getFlowPathByFlowEntry(flowEntry10);
+ assertNotNull(obtainedFlowPath);
+ assertEquals(flowId10.toString(), obtainedFlowPath.getFlowId());
+
+ flowEntry20 = op.searchFlowEntry(flowEntryId20);
+ obtainedFlowPath = op.getFlowPathByFlowEntry(flowEntry20);
+ assertNotNull(obtainedFlowPath);
+ assertEquals(flowId20.toString(), obtainedFlowPath.getFlowId());
+
+ flowEntry30 = op.searchFlowEntry(flowEntryId30);
+ obtainedFlowPath = op.getFlowPathByFlowEntry(flowEntry30);
+ assertNull(obtainedFlowPath);
}
/**
@@ -257,15 +469,43 @@
*/
@Test
public final void testGetAllFlowPaths() {
- fail("Not yet implemented");
+ List<FlowId> flowids = Arrays.asList(
+ new FlowId(10), new FlowId(20), new FlowId(30)
+ );
+
+ for (FlowId flowId: flowids)
+ op.newFlowPath().setFlowId(flowId.toString());
+ op.commit();
+
+ List<String> actual_ids = new ArrayList<String>();
+ for (IFlowPath flowPath: op.getAllFlowPaths()) actual_ids.add(flowPath.getFlowId());
+ Collections.sort(actual_ids);
+
+ List<String> expected_ids = new ArrayList<String>();
+ for (FlowId flowid: flowids) expected_ids.add(flowid.toString());
+ Collections.sort(expected_ids);
+
+ assertArrayEquals(expected_ids.toArray(), actual_ids.toArray());
}
/**
- * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchFlowEntry(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.util.FlowEntryId)}.
+ * Test method for {@link net.onrc.onos.util.GraphDBOperation#removeFlowPath(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IFlowPath)}.
*/
@Test
- public final void testSearchFlowEntry() {
- fail("Not yet implemented");
+ public final void testRemoveFlowPath() {
+ FlowId flowId10 = new FlowId(10);
+ FlowId flowId20 = new FlowId(20);
+ op.newFlowPath().setFlowId(flowId10.toString());
+ op.newFlowPath().setFlowId(flowId20.toString());
+ op.commit();
+
+ IFlowPath flowPath = op.searchFlowPath(flowId10);
+ assertNotNull(flowPath);
+ op.removeFlowPath(flowPath);
+ op.commit();
+
+ assertNull(op.searchFlowPath(flowId10));
+ assertNotNull(op.searchFlowPath(flowId20));
}
/**
@@ -273,15 +513,38 @@
*/
@Test
public final void testNewFlowEntry() {
- fail("Not yet implemented");
+ IFlowEntry flowEntry = op.newFlowEntry();
+ FlowEntryId flowEntryId = new FlowEntryId();
+ flowEntryId.setValue(12345);
+ flowEntry.setFlowEntryId(flowEntryId.toString());
+ op.commit();
+
+ flowEntry = op.searchFlowEntry(flowEntryId);
+ assertNotNull(flowEntry);
+ assertEquals(flowEntry.getFlowEntryId(), flowEntryId.toString());
}
/**
- * Test method for {@link net.onrc.onos.util.GraphDBOperation#removeFlowEntry(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IFlowEntry)}.
+ * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchFlowEntry(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.util.FlowEntryId)}.
*/
@Test
- public final void testRemoveFlowEntry() {
- fail("Not yet implemented");
+ public final void testSearchFlowEntry() {
+ FlowEntryId flowEntryId10 = new FlowEntryId();
+ flowEntryId10.setValue(10);
+ FlowEntryId flowEntryId20 = new FlowEntryId();
+ flowEntryId20.setValue(20);
+ FlowEntryId flowEntryId30 = new FlowEntryId();
+ flowEntryId30.setValue(30);
+
+ op.newFlowEntry().setFlowEntryId(flowEntryId10.toString());
+ op.newFlowEntry().setFlowEntryId(flowEntryId20.toString());
+ op.commit();
+
+ assertNull(op.searchFlowEntry(flowEntryId30));
+ IFlowEntry flowEntry = op.searchFlowEntry(flowEntryId10);
+ assertEquals(flowEntry.getFlowEntryId(), flowEntryId10.toString());
+ flowEntry = op.searchFlowEntry(flowEntryId20);
+ assertEquals(flowEntry.getFlowEntryId(), flowEntryId20.toString());
}
/**
@@ -289,31 +552,43 @@
*/
@Test
public final void testGetAllFlowEntries() {
- fail("Not yet implemented");
+ List<FlowEntryId> flowEntryIds = Arrays.asList(
+ new FlowEntryId(10), new FlowEntryId(20), new FlowEntryId(30)
+ );
+
+ for (FlowEntryId flowEntryId: flowEntryIds)
+ op.newFlowEntry().setFlowEntryId(flowEntryId.toString());
+ op.commit();
+
+ List<String> actual_ids = new ArrayList<String>();
+ for (IFlowEntry flowEntry: op.getAllFlowEntries()) actual_ids.add(flowEntry.getFlowEntryId());
+ Collections.sort(actual_ids);
+
+ List<String> expected_ids = new ArrayList<String>();
+ for (FlowEntryId flowEntryId: flowEntryIds) expected_ids.add(flowEntryId.toString());
+ Collections.sort(expected_ids);
+
+ assertArrayEquals(expected_ids.toArray(), actual_ids.toArray());
}
/**
- * Test method for {@link net.onrc.onos.util.GraphDBOperation#getAllSwitchNotUpdatedFlowEntries(net.onrc.onos.util.GraphDBConnection)}.
+ * Test method for {@link net.onrc.onos.util.GraphDBOperation#removeFlowEntry(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IFlowEntry)}.
*/
@Test
- public final void testGetAllSwitchNotUpdatedFlowEntries() {
- fail("Not yet implemented");
- }
-
- /**
- * Test method for {@link net.onrc.onos.util.GraphDBOperation#getAllSwitches(net.onrc.onos.util.GraphDBConnection)}.
- */
- @Test
- public final void testGetAllSwitches() {
- fail("Not yet implemented");
- }
-
- /**
- * Test method for {@link net.onrc.onos.util.GraphDBOperation#getInactiveSwitches(net.onrc.onos.util.GraphDBConnection)}.
- */
- @Test
- public final void testGetInactiveSwitches() {
- fail("Not yet implemented");
+ public final void testRemoveFlowEntry() {
+ FlowEntryId flowEntryId10 = new FlowEntryId(10);
+ FlowEntryId flowEntryId20 = new FlowEntryId(20);
+ op.newFlowEntry().setFlowEntryId(flowEntryId10.toString());
+ op.newFlowEntry().setFlowEntryId(flowEntryId20.toString());
+ op.commit();
+
+ IFlowEntry flowEntry = op.searchFlowEntry(flowEntryId10);
+ assertNotNull(flowEntry);
+ op.removeFlowEntry(flowEntry);
+ op.commit();
+
+ assertNull(op.searchFlowEntry(flowEntryId10));
+ assertNotNull(op.searchFlowEntry(flowEntryId20));
}
}