Merge branch 'master' of https://github.com/OPENNETWORKINGLAB/ONOS
diff --git a/src/main/java/net/onrc/onos/ofcontroller/routing/TopoRouteService.java b/src/main/java/net/onrc/onos/ofcontroller/routing/TopoRouteService.java
index 432e578..5328eae 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/routing/TopoRouteService.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/routing/TopoRouteService.java
@@ -40,6 +40,10 @@
* of shortest paths.
*/
class Node {
+ /**
+ * A class for storing Link information for fast computation of shortest
+ * paths.
+ */
class Link {
public Node me; // The node this link originates from
public Node neighbor; // The neighbor node on the other side
@@ -90,7 +94,9 @@
}
};
-
+/**
+ * A class for implementing Topology Route Service.
+ */
public class TopoRouteService implements IFloodlightModule, ITopoRouteService {
/** The logger. */
@@ -99,6 +105,11 @@
protected GraphDBOperation op;
+ /**
+ * Get the collection of module services.
+ *
+ * @return the collection of services provided by this module.
+ */
@Override
public Collection<Class<? extends IFloodlightService>> getModuleServices() {
Collection<Class<? extends IFloodlightService>> l =
@@ -107,6 +118,11 @@
return l;
}
+ /**
+ * Get a map with the services provided by this module.
+ *
+ * @return a map with the services provided by this module.
+ */
@Override
public Map<Class<? extends IFloodlightService>, IFloodlightService>
getServiceImpls() {
@@ -118,6 +134,11 @@
return m;
}
+ /**
+ * Get the collection with the services this module depends on.
+ *
+ * @return the collection with the services this module depends on.
+ */
@Override
public Collection<Class<? extends IFloodlightService>>
getModuleDependencies() {
@@ -128,6 +149,12 @@
return l;
}
+ /**
+ * Init the module.
+ *
+ * @param context the module context to use for the initialization.
+ * @see FloodlightModuleContext.
+ */
@Override
public void init(FloodlightModuleContext context)
throws FloodlightModuleException {
@@ -135,25 +162,22 @@
op = new GraphDBOperation("");
}
+ /**
+ * Startup initialization.
+ */
@Override
public void startUp(FloodlightModuleContext context) {
// TODO: Add the approprate setup
}
-
- static class ShortestPathLoopFunction implements PipeFunction<LoopBundle<Vertex>, Boolean> {
- String dpid;
- public ShortestPathLoopFunction(String dpid) {
- super();
- this.dpid = dpid;
- }
- public Boolean compute(LoopBundle<Vertex> bundle) {
- Boolean output = false;
- if (! bundle.getObject().getProperty("dpid").equals(dpid)) {
- output = true;
- }
- return output;
- }
+ /**
+ * Set the database operation handler.
+ *
+ * @param init_op the database operation handler to use for the
+ * initialization.
+ */
+ public void setDbOperationHandler(GraphDBOperation init_op) {
+ op = init_op;
}
/**
diff --git a/src/main/java/net/onrc/onos/registry/controller/StandaloneRegistry.java b/src/main/java/net/onrc/onos/registry/controller/StandaloneRegistry.java
index 7e82bf0..640a49d 100644
--- a/src/main/java/net/onrc/onos/registry/controller/StandaloneRegistry.java
+++ b/src/main/java/net/onrc/onos/registry/controller/StandaloneRegistry.java
@@ -118,12 +118,17 @@
private long blockTop = 0L;
private static final long BLOCK_SIZE = 0x1000000L;
+
+ /**
+ * Returns a block of IDs which are unique and unused.
+ * Range of IDs is fixed size and is assigned incrementally as this method called.
+ */
@Override
- public IdBlock allocateUniqueIdBlock(){
+ public synchronized IdBlock allocateUniqueIdBlock(){
long blockHead = blockTop;
long blockTail = blockTop + BLOCK_SIZE;
- IdBlock block = new IdBlock(blockHead, blockTail, BLOCK_SIZE);
+ IdBlock block = new IdBlock(blockHead, blockTail - 1, BLOCK_SIZE);
blockTop = blockTail;
return block;
diff --git a/src/main/java/net/onrc/onos/registry/controller/ZookeeperRegistry.java b/src/main/java/net/onrc/onos/registry/controller/ZookeeperRegistry.java
index f9fb62e..2d2083f 100644
--- a/src/main/java/net/onrc/onos/registry/controller/ZookeeperRegistry.java
+++ b/src/main/java/net/onrc/onos/registry/controller/ZookeeperRegistry.java
@@ -379,6 +379,12 @@
return data;
}
+ /**
+ * Returns a block of IDs which are unique and unused.
+ * Range of IDs is fixed size and is assigned incrementally as this method called.
+ * Since the range of IDs is managed by Zookeeper in distributed way, this method may block when
+ * requests come up simultaneously.
+ */
public IdBlock allocateUniqueIdBlock(){
try {
AtomicValue<Long> result = null;
diff --git a/src/test/java/net/onrc/onos/ofcontroller/core/internal/LinkStorageImplTest.java b/src/test/java/net/onrc/onos/ofcontroller/core/internal/LinkStorageImplTest.java
index 5c42452..9b1c4d6 100644
--- a/src/test/java/net/onrc/onos/ofcontroller/core/internal/LinkStorageImplTest.java
+++ b/src/test/java/net/onrc/onos/ofcontroller/core/internal/LinkStorageImplTest.java
@@ -6,7 +6,6 @@
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -33,6 +32,11 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+/**
+ * Unit test for {@link LinkStorageImpl}.
+ * @author Naoki Shiota
+ *
+ */
@RunWith(PowerMockRunner.class)
@PrepareForTest({LinkStorageImpl.class, GraphDBConnection.class, GraphDBOperation.class})
public class LinkStorageImplTest {
@@ -100,12 +104,14 @@
*/
@Before
public void setUp() throws Exception{
+ // Create mock GraphDBConnection (replace Singleton object to mock one)
PowerMock.mockStatic(GraphDBConnection.class);
PowerMock.suppress(PowerMock.constructor(GraphDBConnection.class));
- conn = PowerMock.createNiceMock(GraphDBConnection.class);
+ conn = PowerMock.createMock(GraphDBConnection.class);
EasyMock.expect(GraphDBConnection.getInstance((String)EasyMock.anyObject())).andReturn(conn).anyTimes();
PowerMock.replay(GraphDBConnection.class);
+ // Create mock GraphDBOperation
ope = createMockGraphDBOperation();
PowerMock.expectNew(GraphDBOperation.class, new Class<?>[] {GraphDBConnection.class}, EasyMock.anyObject(GraphDBConnection.class)).andReturn(ope).anyTimes();
PowerMock.replay(GraphDBOperation.class);
@@ -121,18 +127,16 @@
/**
* Closing code called after each tests.
- * Discard test graph data.
* @throws Exception
*/
@After
public void tearDown() throws Exception {
- // finish code
linkStorage.close();
}
// TODO: remove @Ignore after UPDATE method is implemented
/**
- * Test if update() can correctly updates LinkInfo for a Link.
+ * Test if {@link LinkStorageImpl#update(Link, LinkInfo, DM_OPERATION)} can correctly updates LinkInfo for a Link.
*/
@Ignore @Test
public void testUpdate_UpdateSingleLink() {
@@ -147,7 +151,7 @@
}
/**
- * Test if update() can correctly creates a Link.
+ * Test if {@link LinkStorageImpl#update(Link, DM_OPERATION)} can correctly creates a Link.
*/
@Test
public void testUpdate_CreateSingleLink() {
@@ -157,18 +161,10 @@
//Use the link storage API to add the link
linkStorage.update(linkToCreate, ILinkStorage.DM_OPERATION.CREATE);
doTestLinkExist(linkToVerify);
-
- // Avoiding duplication is out of scope. DBOperation is responsible for this.
-// // Add same link
-// Link linkToCreateTwice = createFeasibleLink();
-// linkStorage.update(linkToCreateTwice, ILinkStorage.DM_OPERATION.CREATE);
-//
-// // this occurs assertion failure if there are two links in titanGraph
-// doTestLinkIsInGraph(linkToVerify);
}
/**
- * Test if update() can correctly inserts a Link.
+ * Test if {@link LinkStorageImpl#update(Link, DM_OPERATION)}can correctly inserts a Link.
*/
@Test
public void testUpdate_InsertSingleLink(){
@@ -181,7 +177,7 @@
}
/**
- * Test if update() can correctly deletes a Link.
+ * Test if {@link LinkStorageImpl#update(Link, DM_OPERATION)} can correctly deletes a Link.
*/
@Test
public void testUpdate_DeleteSingleLink(){
@@ -194,7 +190,7 @@
}
/**
- * Test if update() can correctly creates multiple Links.
+ * Test if {@link LinkStorageImpl#update(List, DM_OPERATION)} can correctly creates multiple Links.
*/
@Test
public void testUpdate_CreateLinks(){
@@ -206,34 +202,10 @@
for(Link l : linksToVerify) {
doTestLinkExist(l);
}
-
- // Out of scope: DBOperation is responsible for avoiding duplication.
-// // Test creation of existing links
-// linksToCreate = createFeasibleLinks();
-// linkStorage.update(linksToCreate, ILinkStorage.DM_OPERATION.CREATE);
-// for(Link l : linksToVerify) {
-// doTestLinkIsInGraph(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 if {@link LinkStorageImpl#update(List, DM_OPERATION)} can correctly inserts multiple Links.
*/
@Test
public void testUpdate_InsertLinks(){
@@ -248,22 +220,7 @@
}
/**
- * 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 if {@link LinkStorageImpl#update(List, DM_OPERATION)} can correctly deletes multiple Links.
*/
@Test
public void testUpdate_DeleteLinks(){
@@ -277,24 +234,9 @@
}
}
- /**
- * 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.
+ * Test if {@link LinkStorageImpl#updateLink(Link, LinkInfo, DM_OPERATION)} can correctly updates LinkInfo for a Link.
*/
@Ignore @Test
public void testUpdateLink_Update() {
@@ -309,7 +251,7 @@
}
/**
- * Test if updateLink() can correctly creates a Link.
+ * Test if {@link LinkStorageImpl#updateLink(Link, LinkInfo, DM_OPERATION)} can correctly creates a Link.
*/
@Test
public void testUpdateLink_Create() {
@@ -322,7 +264,7 @@
}
/**
- * Test if updateLink() can correctly inserts a Link.
+ * Test if {@link LinkStorageImpl#updateLink(Link, LinkInfo, DM_OPERATION)} can correctly inserts a Link.
*/
@Test
public void testUpdateLink_Insert() {
@@ -337,7 +279,7 @@
// TODO: Check if addOrUpdateLink() should accept DELETE operation. If not, remove this test.
/**
- * Test if updateLink() can correctly deletes a Link.
+ * Test if {@link LinkStorageImpl#updateLink(Link, LinkInfo, DM_OPERATION)} can correctly deletes a Link.
*/
@Ignore @Test
public void testUpdateLink_Delete() {
@@ -357,7 +299,7 @@
}
/**
- * Test if getLinks() can correctly return Links connected to specific DPID and port.
+ * Test if {@link LinkStorageImpl#getLinks(Long, short)} can correctly return Links connected to specific DPID and port.
*/
@Test
public void testGetLinks_ByDpidPort(){
@@ -383,7 +325,7 @@
}
/**
- * Test if getLinks() can correctly return Links connected to specific MAC address.
+ * Test if {@link LinkStorageImpl#getLinks(String)} can correctly return Links connected to specific MAC address.
*/
@Test
public void testGetLinks_ByString() {
@@ -398,7 +340,7 @@
}
/**
- * Test if deleteLink() can correctly delete a Link.
+ * Test if {@link LinkStorageImpl#deleteLink(Link)} can correctly delete a Link.
*/
@Test
public void testDeleteLink() {
@@ -411,7 +353,7 @@
}
/**
- * Test if deleteLinks() can correctly delete Links.
+ * Test if {@link LinkStorageImpl#deleteLinks(List)} can correctly delete Links.
*/
@Test
public void testDeleteLinks(){
@@ -423,24 +365,9 @@
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 if {@link LinkStorageImpl#getActiveLinks()} can correctly return active Links.
*/
@Test
public void testGetActiveLinks() {
@@ -454,7 +381,7 @@
}
/**
- * Test if deleteLinksOnPort() can delete Links.
+ * Test if {@link LinkStorageImpl#deleteLinksOnPort(Long, short)} can delete Links.
*/
@Test
public void testDeleteLinksOnPort() {
@@ -493,11 +420,12 @@
* Test if titanGraph has specific Link with specific LinkInfo
* @param link
*/
+ // TODO: Fix me
private void doTestLinkHasStateOf(Link link, LinkInfo info) {
}
/**
- * Class defines a function called back when IPortObject#removeLink is called.
+ * Class defines a function called back when {@link IPortObject#removeLink(IPortObject)} is called.
* @author Naoki Shiota
*
*/
@@ -521,9 +449,8 @@
}
/**
- * Class defines a function called back when IPortObject#setLinkPort is called.
+ * Class defines a function called back when {@link IPortObject#setLinkPort(IPortObject)} is called.
* @author Naoki Shiota
- *
*/
private class SetLinkPortCallback implements IAnswer<Object> {
private long dpid;
@@ -546,7 +473,7 @@
}
/**
- * Class defines a function called back when IPortObject#getSwitch is called.
+ * Class defines a function called back when {@link IPortObject#getSwitch()} is called.
* @author Naoki Shiota
*
*/
@@ -565,7 +492,7 @@
}
/**
- * Class defines a function called back when IPortObject#getLinkedPorts is called.
+ * Class defines a function called back when {@link IPortObject#getLinkedPorts()} is called.
* @author Naoki Shiota
*
*/
@@ -594,7 +521,7 @@
}
/**
- * Class defines a function called back when ISwitchObject#getPorts is called.
+ * Class defines a function called back when {@link LinkStorageImplTest} is called.
* @author Naoki Shiota
*
*/
@@ -619,7 +546,7 @@
// ------------------------Creation of Mock-----------------------------
/**
- * Create a mock GraphDBOperation which hooks port-related methods.
+ * Create a mock {@link GraphDBOperation} which hooks port-related methods.
* @return EasyMock-wrapped GraphDBOperation object.
*/
@SuppressWarnings("serial")
@@ -692,8 +619,8 @@
}
/**
- * Create a mock IPortObject using given DPID and port number.
- * IPortObject can't store DPID, so DPID is stored to mockToPortInfoMap for later use.
+ * Create a mock {@link IPortObject} using given DPID and port number.
+ * {@link IPortObject} can't store DPID, so DPID is stored to mockToPortInfoMap for later use.
* Duplication is not checked.
* @param dpid DPID of a port
* @param number Port Number
@@ -725,7 +652,7 @@
}
/**
- * Create a mock ISwitchObject using given DPID number.
+ * Create a mock {@link ISwitchObject} using given DPID number.
* Duplication is not checked.
* @param dpid DPID of a switch
* @return EasyMock-wrapped ISwitchObject
@@ -811,7 +738,7 @@
}
/**
- * Returns new Link object of an existing link
+ * Returns new {@link Link} object of an existing link
* @return new Link object
*/
private Link createExistingLink() {
@@ -819,7 +746,7 @@
}
/**
- * Returns new Link object of a not-existing but feasible link
+ * Returns new {@link Link} object of a not-existing but feasible link
* @return new Link object
*/
private Link createFeasibleLink() {
@@ -833,7 +760,7 @@
}
/**
- * Returns list of Link objects which all has information of existing link in titanGraph
+ * Returns list of existing {@link Link} objects
* @return ArrayList of new Link objects
*/
private List<Link> createExistingLinks() {
@@ -844,7 +771,7 @@
}
/**
- * Returns list of Link objects which all has information of not-existing but feasible link
+ * Returns list of {@link Link} objects that are all not-existing but feasible
* @return ArrayList of new Link objects
*/
private List<Link> createFeasibleLinks() {
@@ -855,7 +782,7 @@
}
/**
- * Returns new LinkInfo object with convenient values.
+ * Returns new {@link LinkInfo} object with convenient values.
* @return LinkInfo object
*/
private LinkInfo createFeasibleLinkInfo(long time) {
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
index b4cfc31..b8091fc 100644
--- a/src/test/java/net/onrc/onos/ofcontroller/core/internal/TestDatabaseManager.java
+++ b/src/test/java/net/onrc/onos/ofcontroller/core/internal/TestDatabaseManager.java
@@ -56,10 +56,19 @@
//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());
+ while (it.hasNext()){
+ Vertex port = it.next();
+
+ if(port.getProperty("number") instanceof Short)
+ {
+ Short portNum = (Short) port.getProperty("number");
+ port.setProperty("number", portNum.shortValue());
+ }
+ else{
+ Integer portNum = (Integer) port.getProperty("number");
+ port.setProperty("number", portNum.shortValue());
+ }
+
}
titanGraph.stopTransaction(Conclusion.SUCCESS);
}
@@ -73,4 +82,4 @@
}
}
-}
\ No newline at end of file
+}
diff --git a/src/test/java/net/onrc/onos/ofcontroller/flowmanager/FlowManagerTest.java b/src/test/java/net/onrc/onos/ofcontroller/flowmanager/FlowManagerTest.java
index 5add3cd..06e828d 100644
--- a/src/test/java/net/onrc/onos/ofcontroller/flowmanager/FlowManagerTest.java
+++ b/src/test/java/net/onrc/onos/ofcontroller/flowmanager/FlowManagerTest.java
@@ -11,6 +11,7 @@
import java.util.concurrent.TimeUnit;
import net.floodlightcontroller.core.IFloodlightProviderService;
+import net.floodlightcontroller.core.IOFSwitch;
import net.floodlightcontroller.core.module.FloodlightModuleContext;
import net.floodlightcontroller.core.module.IFloodlightService;
import net.floodlightcontroller.restserver.IRestApiService;
@@ -25,8 +26,12 @@
import org.easymock.IAnswer;
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.OFFlowMod;
+import org.openflow.protocol.OFType;
+import org.openflow.protocol.factory.BasicFactory;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
@@ -83,13 +88,10 @@
expect(iFlowPath.getSrcPort()).andReturn(new Short((short)srcPort)).anyTimes();
expect(iFlowPath.getDstSwitch()).andReturn(new Dpid(dstDpid).toString()).anyTimes();
expect(iFlowPath.getDstPort()).andReturn(new Short((short)dstPort)).anyTimes();
- expect(iFlowPath.getFlowEntries()).andReturn(new ArrayList<IFlowEntry>()).anyTimes();
return iFlowPath;
}
- private FlowPath createTestFlowPath(
- long flowId,
- String installerId,
+ private FlowPath createTestFlowPath(long flowId, String installerId,
final long srcDpid, final int srcPort,
final long dstDpid, final int dstPort
) {
@@ -131,6 +133,7 @@
FlowId flowId = new FlowId(123);
FlowPath flowPath = new FlowPath();
flowPath.setFlowId(flowId);
+ FlowManager fm = new FlowManager();
// setup expectations
expectInitWithContext();
@@ -140,9 +143,7 @@
// start the test
replayAll();
-// replay(GraphDBOperation.class);
- FlowManager fm = new FlowManager();
fm.init(context);
Boolean result = fm.addFlow(flowPath, flowId, "");
@@ -230,6 +231,7 @@
ArrayList<IFlowPath> flowPaths = new ArrayList<IFlowPath>();
flowPaths.add(flowPath1);
flowPaths.add(flowPath2);
+ FlowManager fm = new FlowManager();
// setup expectations
expectInitWithContext();
@@ -251,7 +253,6 @@
// start the test
replayAll();
- FlowManager fm = new FlowManager();
fm.init(context);
Boolean result = fm.deleteAllFlows();
@@ -266,6 +267,9 @@
*/
@Test
public final void testDeleteFlowSuccessEmptyFlowPath() throws Exception {
+ // instantiate required objects
+ FlowManager fm = new FlowManager();
+
// create mock objects
IFlowPath flowObj = createNiceMock(IFlowPath.class);
@@ -280,7 +284,6 @@
// start the test
replayAll();
- FlowManager fm = new FlowManager();
fm.init(context);
Boolean result = fm.deleteFlow(new FlowId(1));
@@ -336,11 +339,12 @@
public final void testGetFlowSuccessNormally() throws Exception {
// instantiate required objects
FlowManager fm = new FlowManager();
+ IFlowPath iFlowPath = createIFlowPathMock(1, "caller id", 1, 1, 2, 2);
// setup expectations
expectInitWithContext();
- expect(op.searchFlowPath(cmpEq(new FlowId(1)))).andReturn(
- createIFlowPathMock(1, "caller id", 1, 1, 2, 2));
+ expect(op.searchFlowPath(cmpEq(new FlowId(1)))).andReturn(iFlowPath);
+ expect(iFlowPath.getFlowEntries()).andReturn(new ArrayList<IFlowEntry>()).anyTimes();
op.commit();
// start the test
@@ -467,15 +471,21 @@
*/
@Test
public final void testGetAllFlowsSuccessNormally() throws Exception {
+ // create mock objects
+ IFlowPath iFlowPath1 = createIFlowPathMock(1, "caller id", 1, 1, 2, 2);
+ IFlowPath iFlowPath2 = createIFlowPathMock(2, "caller id", 2, 5, 3, 5);
+
// instantiate required objects
ArrayList<IFlowPath> flowPaths = new ArrayList<IFlowPath>();
- flowPaths.add(createIFlowPathMock(1, "caller id", 1, 1, 2, 2));
- flowPaths.add(createIFlowPathMock(1, "caller id", 2, 5, 3, 5));
+ flowPaths.add(iFlowPath1);
+ flowPaths.add(iFlowPath2);
FlowManager fm = new FlowManager();
// setup expectations
expectInitWithContext();
expect(op.getAllFlowPaths()).andReturn(flowPaths);
+ expect(iFlowPath1.getFlowEntries()).andReturn(new ArrayList<IFlowEntry>()).anyTimes();
+ expect(iFlowPath2.getFlowEntries()).andReturn(new ArrayList<IFlowEntry>()).anyTimes();
op.commit();
// start the test
@@ -749,6 +759,7 @@
// instantiate required objects
FlowPath paramFlow = createTestFlowPath(100, "installer id", 1, 3, 2, 4);
Map<Long, Object> shortestPathMap = new HashMap<Long, Object>();
+ FlowManager fm = new FlowManager();
// setup expectations
expectInitWithContext();
@@ -763,7 +774,6 @@
// start the test
replayAll();
- FlowManager fm = new FlowManager();
fm.init(context);
fm.measurementStorePathFlow(paramFlow);
Boolean result = fm.measurementClearAllPaths();
@@ -785,6 +795,9 @@
*/
@Test
public final void testInitSuccessNormally() throws Exception {
+ // instantiate required objects
+ FlowManager fm = new FlowManager();
+
// create mock objects
op = createMock(GraphDBOperation.class);
@@ -794,7 +807,6 @@
// start the test
replayAll();
- FlowManager fm = new FlowManager();
fm.init("/dummy/path");
// verify the test
@@ -934,7 +946,6 @@
mockStaticPartial(Executors.class, "newScheduledThreadPool");
ScheduledExecutorService scheduler = createMock(ScheduledExecutorService.class);
-
// instantiate required objects
FlowManager fm = new FlowManager();
@@ -958,4 +969,233 @@
// verify the test
verifyAll();
}
+
+
+ // other methods
+
+
+ /**
+ * Test method for {@link FlowManager#clearFlow(FlowId)}.
+ * @throws Exception
+ */
+ @Test
+ public final void testClearFlowSuccessNormally() throws Exception {
+ // create mock objects
+ IFlowPath flowPath = createIFlowPathMock(123, "id", 1, 2, 3, 4);
+ IFlowEntry flowEntry1 = createMock(IFlowEntry.class);
+ IFlowEntry flowEntry2 = createMock(IFlowEntry.class);
+ IFlowEntry flowEntry3 = createMock(IFlowEntry.class);
+
+ // instantiate required objects
+ FlowManager fm = new FlowManager();
+ FlowId flowId = new FlowId(123);
+ ArrayList<IFlowEntry> flowEntries = new ArrayList<IFlowEntry>();
+ flowEntries.add(flowEntry1);
+ flowEntries.add(flowEntry2);
+ flowEntries.add(flowEntry3);
+
+ // setup expectations
+ expectInitWithContext();
+ expect(op.searchFlowPath(cmpEq(flowId))).andReturn(flowPath);
+ expect(flowPath.getFlowEntries()).andReturn(flowEntries);
+ flowPath.removeFlowEntry(flowEntry1);
+ flowPath.removeFlowEntry(flowEntry2);
+ flowPath.removeFlowEntry(flowEntry3);
+ op.removeFlowEntry(flowEntry1);
+ op.removeFlowEntry(flowEntry2);
+ op.removeFlowEntry(flowEntry3);
+ op.removeFlowPath(flowPath);
+ op.commit();
+
+ // start the test
+ replayAll();
+
+ fm.init(context);
+ fm.clearFlow(flowId);
+
+ // verify the test
+ verifyAll();
+ }
+
+ /**
+ * Test method for {@link FlowManager#getAllFlowsWithoutFlowEntries()}.
+ * @throws Exception
+ */
+ @Test
+ public final void testGetAllFlowsWithoutFlowEntriesSuccessNormally() throws Exception {
+ // create mock objects
+ IFlowPath iFlowPath1 = createIFlowPathMock(1, "caller id", 1, 1, 2, 2);
+ IFlowPath iFlowPath2 = createIFlowPathMock(2, "caller id", 2, 5, 3, 5);
+
+ // instantiate required objects
+ ArrayList<IFlowPath> flowPaths = new ArrayList<IFlowPath>();
+ flowPaths.add(iFlowPath1);
+ flowPaths.add(iFlowPath2);
+ FlowManager fm = new FlowManager();
+
+ // setup expectations
+ expectInitWithContext();
+ op.commit();
+ expect(op.getAllFlowPaths()).andReturn(flowPaths);
+
+ // start the test
+ replayAll();
+
+ fm.init(context);
+ ArrayList<IFlowPath> result = fm.getAllFlowsWithoutFlowEntries();
+
+ // verify the test
+ verifyAll();
+ assertEquals(iFlowPath1, result.get(0));
+ assertEquals(iFlowPath2, result.get(1));
+
+ // TODO: does this method just return the replica of the flow paths?
+ }
+
+ /**
+ * Test method for {@link FlowManager#reconcileFlow(IFlowPath, DataPath)}.
+ * @throws Exception
+ */
+ @Test
+ public final void testReconcileFlowWithFlowPathAndDataPathSuccessNormally() throws Exception {
+ final String addFlowEntry = "addFlowEntry";
+
+ // create mock objects
+ IFlowPath iFlowPath1 = createIFlowPathMock(1, "caller id", 1, 1, 2, 2);
+ IFlowEntry iFlowEntry1 = createMock(IFlowEntry.class);
+ IFlowEntry iFlowEntry2 = createMock(IFlowEntry.class);
+ FlowManager fm = createPartialMockAndInvokeDefaultConstructor(FlowManager.class, addFlowEntry);
+
+ // instantiate required objects
+ FlowEntry flowEntry1 = new FlowEntry();
+ flowEntry1.setDpid(new Dpid(1));
+ flowEntry1.setFlowId(new FlowId(1));
+ flowEntry1.setInPort(new Port((short) 1));
+ flowEntry1.setOutPort(new Port((short) 11));
+ flowEntry1.setFlowEntryId(new FlowEntryId(1));
+ flowEntry1.setFlowEntryMatch(new FlowEntryMatch());
+ flowEntry1.setFlowEntryActions(new ArrayList<FlowEntryAction>());
+ flowEntry1.setFlowEntryErrorState(new FlowEntryErrorState());
+
+ FlowEntry flowEntry2 = new FlowEntry();
+ flowEntry2.setDpid(new Dpid(2));
+ flowEntry2.setFlowId(new FlowId(2));
+ flowEntry2.setInPort(new Port((short) 22));
+ flowEntry2.setOutPort(new Port((short) 2));
+ flowEntry2.setFlowEntryId(new FlowEntryId(2));
+ flowEntry2.setFlowEntryMatch(new FlowEntryMatch());
+ flowEntry2.setFlowEntryActions(new ArrayList<FlowEntryAction>());
+ flowEntry2.setFlowEntryErrorState(new FlowEntryErrorState());
+
+ DataPath dataPath = new DataPath();
+ ArrayList<FlowEntry> flowEntries = new ArrayList<FlowEntry>();
+ flowEntries.add(flowEntry1);
+ flowEntries.add(flowEntry2);
+ dataPath.setFlowEntries(flowEntries);
+
+ ArrayList<IFlowEntry> oldFlowEntries = new ArrayList<IFlowEntry>();
+ oldFlowEntries.add(iFlowEntry1);
+ oldFlowEntries.add(iFlowEntry2);
+
+ // setup expectations
+ expectInitWithContext();
+ expect(floodlightProvider.getSwitches()).andReturn(null); // TODO: why is this needed?
+ expect(iFlowPath1.getFlowEntries()).andReturn(oldFlowEntries);
+ iFlowEntry1.setUserState("FE_USER_DELETE");
+ iFlowEntry1.setSwitchState("FE_SWITCH_NOT_UPDATED");
+ iFlowEntry2.setUserState("FE_USER_DELETE");
+ iFlowEntry2.setSwitchState("FE_SWITCH_NOT_UPDATED");
+ expectPrivate(fm, addFlowEntry, iFlowPath1, flowEntry1).andReturn(null);
+ expectPrivate(fm, addFlowEntry, iFlowPath1, flowEntry2).andReturn(null);
+
+ // start the test
+ replayAll();
+
+ fm.init(context);
+ Boolean result = fm.reconcileFlow(iFlowPath1, dataPath);
+
+ // verify the test
+ verifyAll();
+ assertTrue(result);
+ // TODO: write more asserts
+ }
+
+ /**
+ * Test method for {@link FlowManager#installFlowEntry(net.floodlightcontroller.core.IOFSwitch, IFlowPath, IFlowEntry)}.
+ * @throws Exception
+ */
+ @Test
+ public final void testInstallFlowEntryWithIFlowPathSuccessNormally() throws Exception {
+ // create mock object
+ IOFSwitch iofSwitch = createNiceMock(IOFSwitch.class);
+ IFlowPath iFlowPath = createIFlowPathMock(1, "id", 1, 2, 3, 4);
+ IFlowEntry iFlowEntry = createMock(IFlowEntry.class);
+ BasicFactory basicFactory = createMock(BasicFactory.class);
+
+ // instantiate required objects
+ FlowManager fm = new FlowManager();
+
+ // setup expectations
+ expectInitWithContext();
+ expect(iFlowEntry.getFlowEntryId()).andReturn(new FlowEntryId(123).toString());
+ expect(iFlowEntry.getUserState()).andReturn("FE_USER_ADD");
+ iFlowEntry.setSwitchState("FE_SWITCH_UPDATED");
+ expect(iFlowEntry.getMatchInPort()).andReturn(new Short((short) 1));
+ expect(iFlowEntry.getMatchEthernetFrameType()).andReturn(new Short((short)0x0800));
+ expect(iFlowEntry.getMatchSrcIPv4Net()).andReturn("192.168.0.1");
+ expect(iFlowEntry.getMatchDstIPv4Net()).andReturn("192.168.0.2");
+ expect(iFlowEntry.getMatchSrcMac()).andReturn("01:23:45:67:89:01");
+ expect(iFlowEntry.getMatchDstMac()).andReturn("01:23:45:67:89:02");
+ expect(iFlowEntry.getActionOutput()).andReturn(new Short((short) 2));
+ expect(floodlightProvider.getOFMessageFactory()).andReturn(basicFactory);
+ expect(basicFactory.getMessage(OFType.FLOW_MOD)).andReturn(new OFFlowMod());
+ expect(iofSwitch.getStringId()).andReturn(new Dpid(100).toString());
+
+ // start the test
+ replayAll();
+
+ fm.init(context);
+ Boolean result = fm.installFlowEntry(iofSwitch, iFlowPath, iFlowEntry);
+
+ // verify the test
+ verifyAll();
+ assertTrue(result);
+ // TODO: write more asserts
+ }
+
+ /**
+ * Test method for {@link FlowManager#installFlowEntry(net.floodlightcontroller.core.IOFSwitch, FlowPath, FlowEntry)}.
+ * The method seems to be not used for now.
+ */
+ @Ignore @Test
+ public final void testInstallFlowEntryWithFlowPathSuccessNormally() {
+ fail("not yet implemented");
+ }
+
+ /**
+ * Test method for {@link FlowManager#removeFlowEntry(net.floodlightcontroller.core.IOFSwitch, FlowPath, FlowEntry)}.
+ * The method seems to be not implemented and not used for now.
+ */
+ @Ignore @Test
+ public final void testRemoveFlowEntrySuccessNormally() {
+ fail("not yet implemented");
+ }
+
+ /**
+ * Test method for {@link FlowManager#installRemoteFlowEntry(FlowPath, FlowEntry)}.
+ * The method seems to be not implemented and not used for now.
+ */
+ @Ignore @Test
+ public final void testInstallRemoteFlowEntrySuccessNormally() {
+ fail("not yet implemented");
+ }
+
+ /**
+ * Test method for {@link FlowManager#removeRemoteFlowEntry(FlowPath, FlowEntry)}.
+ * The method seems to be not implemented and not used for now.
+ */
+ @Ignore @Test
+ public final void testRemoveRemoteFlowEntrySuccessNormally() {
+ fail("not yet implemented");
+ }
}
\ No newline at end of file
diff --git a/src/test/java/net/onrc/onos/ofcontroller/routing/TopoRouteServiceTest.java b/src/test/java/net/onrc/onos/ofcontroller/routing/TopoRouteServiceTest.java
new file mode 100644
index 0000000..e6d7d16
--- /dev/null
+++ b/src/test/java/net/onrc/onos/ofcontroller/routing/TopoRouteServiceTest.java
@@ -0,0 +1,234 @@
+package net.onrc.onos.ofcontroller.routing;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+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.powermock.api.easymock.PowerMock;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import com.thinkaurelius.titan.core.TitanGraph;
+import com.thinkaurelius.titan.core.TitanFactory;
+import com.tinkerpop.blueprints.Vertex;
+import com.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine;
+import com.tinkerpop.gremlin.java.GremlinPipeline;
+import com.tinkerpop.pipes.PipeFunction;
+import com.tinkerpop.pipes.branch.LoopPipe.LoopBundle;
+
+import javax.script.ScriptContext;
+import javax.script.ScriptEngine;
+import javax.script.ScriptException;
+
+import net.onrc.onos.graph.GraphDBConnection;
+import net.onrc.onos.graph.GraphDBOperation;
+import net.onrc.onos.ofcontroller.core.internal.TestDatabaseManager;
+import net.onrc.onos.ofcontroller.routing.TopoRouteService;
+import net.onrc.onos.ofcontroller.util.DataPath;
+import net.onrc.onos.ofcontroller.util.Dpid;
+import net.onrc.onos.ofcontroller.util.Port;
+import net.onrc.onos.ofcontroller.util.SwitchPort;
+
+/**
+ * A class for testing the TopoRouteService class.
+ * @see net.onrc.onos.ofcontroller.routing.TopoRouteService
+ * @author Pavlin Radoslavov (pavlin@onlab.us)
+ */
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({TitanFactory.class, GraphDBConnection.class, GraphDBOperation.class, TopoRouteService.class})
+public class TopoRouteServiceTest {
+ String conf;
+ private GraphDBConnection conn = null;
+ private GraphDBOperation oper = null;
+ private TitanGraph titanGraph = null;
+ private TopoRouteService topoRouteService = null;
+
+ /**
+ * Setup the tests.
+ */
+ @Before
+ public void setUp() throws Exception {
+ conf = "/dummy/path/to/db";
+
+ //
+ // Make mock database.
+ // Replace TitanFactory.open() to return the mock database.
+ //
+ titanGraph = TestDatabaseManager.getTestDatabase();
+ PowerMock.mockStatic(TitanFactory.class);
+ EasyMock.expect(TitanFactory.open((String)EasyMock.anyObject())).andReturn(titanGraph);
+ PowerMock.replay(TitanFactory.class);
+
+ // Create the connection to the database
+ conn = GraphDBConnection.getInstance(conf);
+ oper = new GraphDBOperation(conn);
+
+ // Populate the database
+ TestDatabaseManager.populateTestData(titanGraph);
+
+ // Prepare the TopoRouteService instance
+ topoRouteService = new TopoRouteService();
+ topoRouteService.setDbOperationHandler(oper);
+ }
+
+ /**
+ * Cleanup after the tests.
+ */
+ @After
+ public void tearDown() throws Exception {
+ titanGraph.shutdown();
+ TestDatabaseManager.deleteTestDatabase();
+ }
+
+ /**
+ * Test method TopoRouteService.getTopoShortestPath()
+ *
+ * @see net.onrc.onos.ofcontroller.routing.TopoRouteService#getTopoShortestPath
+ */
+ @Test
+ public void test_getTopoShortestPath() {
+ DataPath dataPath = null;
+ String srcDpidStr = "00:00:00:00:00:00:0a:01";
+ String dstDpidStr = "00:00:00:00:00:00:0a:06";
+ short srcPortShort = 1;
+ short dstPortShort = 1;
+
+ //
+ // Initialize the source and destination points
+ //
+ Dpid srcDpid = new Dpid(srcDpidStr);
+ Port srcPort = new Port(srcPortShort);
+ Dpid dstDpid = new Dpid(dstDpidStr);
+ Port dstPort = new Port(dstPortShort);
+ SwitchPort srcSwitchPort = new SwitchPort(srcDpid, srcPort);
+ SwitchPort dstSwitchPort = new SwitchPort(dstDpid, dstPort);
+
+ //
+ // Test a valid Shortest-Path computation
+ //
+ Map<Long, ?> shortestPathTopo =
+ topoRouteService.prepareShortestPathTopo();
+ dataPath = topoRouteService.getTopoShortestPath(shortestPathTopo,
+ srcSwitchPort,
+ dstSwitchPort);
+ assertTrue(dataPath != null);
+ String dataPathSummaryStr = dataPath.dataPathSummary();
+ // System.out.println(dataPathSummaryStr);
+ String expectedResult = "1/00:00:00:00:00:00:0a:01/2;1/00:00:00:00:00:00:0a:03/2;2/00:00:00:00:00:00:0a:04/3;1/00:00:00:00:00:00:0a:06/1;";
+ assertEquals(dataPathSummaryStr, expectedResult);
+
+ //
+ // Test Shortest-Path computation to non-existing destination
+ //
+ String noSuchDpidStr = "ff:ff:00:00:00:00:0a:06";
+ Dpid noSuchDstDpid = new Dpid(noSuchDpidStr);
+ SwitchPort noSuchDstSwitchPort = new SwitchPort(noSuchDstDpid, dstPort);
+ dataPath = topoRouteService.getTopoShortestPath(shortestPathTopo,
+ srcSwitchPort,
+ noSuchDstSwitchPort);
+ assertTrue(dataPath == null);
+
+ topoRouteService.dropShortestPathTopo(shortestPathTopo);
+ }
+
+ /**
+ * Test method TopoRouteService.getShortestPath()
+ *
+ * @see net.onrc.onos.ofcontroller.routing.TopoRouteService#getShortestPath
+ */
+ @Test
+ public void test_getShortestPath() {
+ DataPath dataPath = null;
+ String srcDpidStr = "00:00:00:00:00:00:0a:01";
+ String dstDpidStr = "00:00:00:00:00:00:0a:06";
+ short srcPortShort = 1;
+ short dstPortShort = 1;
+
+ //
+ // Initialize the source and destination points
+ //
+ Dpid srcDpid = new Dpid(srcDpidStr);
+ Port srcPort = new Port(srcPortShort);
+ Dpid dstDpid = new Dpid(dstDpidStr);
+ Port dstPort = new Port(dstPortShort);
+ SwitchPort srcSwitchPort = new SwitchPort(srcDpid, srcPort);
+ SwitchPort dstSwitchPort = new SwitchPort(dstDpid, dstPort);
+
+ //
+ // Test a valid Shortest-Path computation
+ //
+ dataPath = topoRouteService.getShortestPath(srcSwitchPort,
+ dstSwitchPort);
+ assertTrue(dataPath != null);
+ String dataPathSummaryStr = dataPath.dataPathSummary();
+ // System.out.println(dataPathSummaryStr);
+ String expectedResult = "1/00:00:00:00:00:00:0a:01/2;1/00:00:00:00:00:00:0a:03/2;2/00:00:00:00:00:00:0a:04/3;1/00:00:00:00:00:00:0a:06/1;";
+ assertEquals(dataPathSummaryStr, expectedResult);
+
+ //
+ // Test Shortest-Path computation to non-existing destination
+ //
+ String noSuchDpidStr = "ff:ff:00:00:00:00:0a:06";
+ Dpid noSuchDstDpid = new Dpid(noSuchDpidStr);
+ SwitchPort noSuchDstSwitchPort = new SwitchPort(noSuchDstDpid, dstPort);
+
+ dataPath = topoRouteService.getShortestPath(srcSwitchPort,
+ noSuchDstSwitchPort);
+ assertTrue(dataPath == null);
+ }
+
+ /**
+ * Test method TopoRouteService.routeExists()
+ *
+ * @see net.onrc.onos.ofcontroller.routing.TopoRouteService#routeExists
+ */
+ @Test
+ public void test_routeExists() {
+ Boolean result;
+ String srcDpidStr = "00:00:00:00:00:00:0a:01";
+ String dstDpidStr = "00:00:00:00:00:00:0a:06";
+ short srcPortShort = 1;
+ short dstPortShort = 1;
+
+ //
+ // Initialize the source and destination points
+ //
+ Dpid srcDpid = new Dpid(srcDpidStr);
+ Port srcPort = new Port(srcPortShort);
+ Dpid dstDpid = new Dpid(dstDpidStr);
+ Port dstPort = new Port(dstPortShort);
+ SwitchPort srcSwitchPort = new SwitchPort(srcDpid, srcPort);
+ SwitchPort dstSwitchPort = new SwitchPort(dstDpid, dstPort);
+
+ //
+ // Test a valid route
+ //
+ result = topoRouteService.routeExists(srcSwitchPort, dstSwitchPort);
+ assertTrue(result == true);
+
+ //
+ // Test a non-existing route
+ //
+ String noSuchDpidStr = "ff:ff:00:00:00:00:0a:06";
+ Dpid noSuchDstDpid = new Dpid(noSuchDpidStr);
+ SwitchPort noSuchDstSwitchPort = new SwitchPort(noSuchDstDpid, dstPort);
+ result = topoRouteService.routeExists(srcSwitchPort,
+ noSuchDstSwitchPort);
+ assertTrue(result != true);
+ }
+}
diff --git a/src/test/java/net/onrc/onos/registry/controller/StandaloneRegistryTest.java b/src/test/java/net/onrc/onos/registry/controller/StandaloneRegistryTest.java
index 802c137..7c4a1a0 100644
--- a/src/test/java/net/onrc/onos/registry/controller/StandaloneRegistryTest.java
+++ b/src/test/java/net/onrc/onos/registry/controller/StandaloneRegistryTest.java
@@ -20,7 +20,7 @@
import org.openflow.util.HexString;
/**
- * Unit test for StandaloneRegistry.
+ * Unit test for {@link StandaloneRegistry}.
* @author Naoki Shiota
*
*/
@@ -30,14 +30,13 @@
protected StandaloneRegistry registry;
/**
- * Implementation of ControlChangeCallback which defines callback interfaces called by Registry.
+ * Implementation of {@link ControlChangeCallback} which defines callback interfaces called by Registry.
* This class remembers past callback parameters and provides methods to access them.
* This class also provides CountDownLatch so one can wait until the callback be called
- * specific times (specified by constructor param). Particularly, the first time callback
+ * specific times (specified by constructor parameter). Particularly, the first time callback
* called is supposed for registration, this class has an independent latch to wait for
* the first callback.
* @author Naoki Shiota
- *
*/
public static class LoggingCallback implements ControlChangeCallback {
private LinkedList<Long> dpidsCalledback = new LinkedList<Long>();
@@ -135,7 +134,7 @@
}
/**
- * Test if registerController() can run without error.
+ * Test if {@link StandaloneRegistry#registerController(String)} can run without error.
*/
@Test
public void testRegisterController() {
@@ -157,7 +156,7 @@
}
/**
- * Test if getControllerId() can return correct ID.
+ * Test if {@link StandaloneRegistry#getControllerId()} can return correct ID.
* @throws RegistryException
*/
@Test
@@ -178,7 +177,7 @@
}
/**
- * Test if getAllControllers() can return correct list of controllers.
+ * Test if {@link StandaloneRegistry#getAllControllers()} can return correct list of controllers.
* @throws RegistryException
*/
@Test
@@ -208,7 +207,7 @@
}
/**
- * Test if requestControl() can correctly take control for switch so that callback is called.
+ * Test if {@link StandaloneRegistry#requestControl(long, ControlChangeCallback)} can correctly take control for switch so that callback is called.
* @throws RegistryException
* @throws InterruptedException
*/
@@ -237,7 +236,7 @@
}
/**
- * Test if releaseControl() can correctly release the control so that callback is called.
+ * Test if {@link StandaloneRegistry#releaseControl(long)} can correctly release the control so that callback is called.
* @throws InterruptedException
* @throws RegistryException
*/
@@ -262,7 +261,7 @@
}
/**
- * Test if hasControl() returns correct status.
+ * Test if {@link StandaloneRegistry#hasControl(long)} returns correct status.
* @throws InterruptedException
* @throws RegistryException
*/
@@ -292,7 +291,7 @@
}
/**
- * Test if getControllerForSwitch() returns correct controller ID.
+ * Test if {@link StandaloneRegistry#getControllerForSwitch(long)} returns correct controller ID.
* @throws InterruptedException
* @throws RegistryException
*/
@@ -339,7 +338,7 @@
}
/**
- * Test if getAllSwitches() returns correct list of switches.
+ * Test if {@link StandaloneRegistry#getAllSwitches()} returns correct list of switches.
* @throws InterruptedException
* @throws RegistryException
*/
@@ -382,7 +381,7 @@
}
/**
- * Test if getSwitchesControlledByController() returns correct list of switches.
+ * Test if {@link StandaloneRegistry#getSwitchesControlledByController(String)} returns correct list of switches.
* @throws InterruptedException
* @throws RegistryException
*/
@@ -426,7 +425,8 @@
}
/**
- * Test if allocateUniqueIdBlock() returns appropriate object.
+ * Test if {@link StandaloneRegistry#allocateUniqueIdBlock()} returns appropriate object.
+ * Get bulk of IdBlocks and check if they do have unique range of IDs.
*/
@Test
public void testAllocateUniqueIdBlock() {
@@ -454,7 +454,7 @@
assertTrue(lower.getSize() > 0L);
assertTrue(higher.getSize() > 0L);
- assertTrue(lower.getEnd() <= higher.getStart());
+ assertTrue(lower.getEnd() < higher.getStart());
}
}
}
diff --git a/src/test/java/net/onrc/onos/registry/controller/ZookeeperRegistryTest.java b/src/test/java/net/onrc/onos/registry/controller/ZookeeperRegistryTest.java
index f557663..3314ad2 100644
--- a/src/test/java/net/onrc/onos/registry/controller/ZookeeperRegistryTest.java
+++ b/src/test/java/net/onrc/onos/registry/controller/ZookeeperRegistryTest.java
@@ -41,8 +41,8 @@
import com.netflix.curator.x.discovery.ServiceInstance;
/**
- * Unit test for ZookeeperRegistry.
- * NOTE: FloodlightTestCase conflicts with PowerMock. If FloodLight-related methods need to be tested,
+ * Unit test for {@link ZookeeperRegistry}.
+ * NOTE: {@link FloodlightTestCase} conflicts with PowerMock. If FloodLight-related methods need to be tested,
* implement another test class to test them.
* @author Naoki Shiota
*
@@ -61,8 +61,8 @@
protected final String CONTROLLER_ID = "controller2013";
/**
- * Initialize ZookeeperRegistry Object and inject initial value with init() method.
- * This setup code also tests init() method itself.
+ * Initialize {@link ZookeeperRegistry} Object and inject initial value with {@link ZookeeperRegistry#init(FloodlightModuleContext)} method.
+ * This setup code also tests {@link ZookeeperRegistry#init(FloodlightModuleContext)} method itself.
*/
@Before
public void setUp() throws Exception {
@@ -97,8 +97,8 @@
}
/**
- * Test if registerController() method can go through without exception.
- * (Exceptions are usually out of test target, but registerController() throws an exception in case of invalid registration.)
+ * Test if {@link ZookeeperRegistry#registerController(String)} method can go through without exception.
+ * (Exceptions are usually out of test target, but {@link ZookeeperRegistry#registerController(String)} throws an exception in case of invalid registration.)
*/
@Test
public void testRegisterController() {
@@ -113,7 +113,7 @@
}
/**
- * Test if getControllerId() correctly returns registered ID.
+ * Test if {@link ZookeeperRegistry#getControllerId()} correctly returns registered ID.
* @throws Exception
*/
@Test
@@ -134,9 +134,9 @@
}
/**
- * Test if getAllControllers() returns all controllers.
- * Controllers are injected while setup. See createCuratorFrameworkMock() to what controllers
- * are injected using ServiceCache Mock.
+ * Test if {@link ZookeeperRegistry#getAllControllers()} returns all controllers.
+ * Controllers to be returned are injected while setup. See {@link ZookeeperRegistryTest#createCuratorFrameworkMock()}
+ * to what controllers are injected using mock {@link ServiceCache}.
* @throws Exception
*/
@Test
@@ -144,7 +144,6 @@
String controllerIdRegistered = "controller1";
String controllerIdNotRegistered = "controller2013";
- // Test registered controller
try {
Collection<String> ctrls = registry.getAllControllers();
assertTrue(ctrls.contains(controllerIdRegistered));
@@ -156,13 +155,14 @@
}
/**
- * Test if requestControl() correctly take control of specific switch.
- * Because requestControl() doesn't return values, inject mock LeaderLatch object and verify latch is correctly set up.
+ * Test if {@link ZookeeperRegistry#requestControl(long, net.onrc.onos.registry.controller.IControllerRegistryService.ControlChangeCallback)}
+ * correctly take control of specific switch. Because {@link ZookeeperRegistry#requestControl(long, net.onrc.onos.registry.controller.IControllerRegistryService.ControlChangeCallback)}
+ * doesn't return values, inject mock {@link LeaderLatch} object and verify latch is correctly set up.
* @throws Exception
*/
@Test
public void testRequestControl() throws Exception {
- // Mock of LeaderLatch
+ // Mock LeaderLatch
LeaderLatch latch = EasyMock.createMock(LeaderLatch.class);
latch.addListener(EasyMock.anyObject(SwitchLeaderListener.class));
EasyMock.expectLastCall().once();
@@ -172,7 +172,7 @@
PowerMock.expectNew(LeaderLatch.class,
EasyMock.anyObject(CuratorFramework.class), EasyMock.anyObject(String.class), EasyMock.anyObject(String.class))
- .andReturn(latch);
+ .andReturn(latch).once();
PowerMock.replay(LeaderLatch.class);
String controllerId = "controller2013";
@@ -192,8 +192,9 @@
}
/**
- * Test if releaseControl() correctly release control of specific switch.
- * Because releaseControl() doesn't return values, inject mock LeaderLatch object and verify latch is correctly set up.
+ * Test if {@link ZookeeperRegistry#releaseControl(long)} correctly release control of specific switch.
+ * Because {@link ZookeeperRegistry#releaseControl(long)} doesn't return values, inject mock
+ * {@link LeaderLatch} object and verify latch is correctly set up.
* @throws Exception
*/
@Test
@@ -212,25 +213,23 @@
PowerMock.expectNew(LeaderLatch.class,
EasyMock.anyObject(CuratorFramework.class), EasyMock.anyObject(String.class), EasyMock.anyObject(String.class))
- .andReturn(latch);
+ .andReturn(latch).once();
PowerMock.replay(LeaderLatch.class);
String controllerId = "controller2013";
registry.registerController(controllerId);
- long dpidToRequest = 1000L;
+ long dpidToRequest = 2000L;
LoggingCallback callback = new LoggingCallback(1);
- // to request and wait to take control
registry.requestControl(dpidToRequest, callback);
registry.releaseControl(dpidToRequest);
- // verify
EasyMock.verify(latch);
}
/**
- * Test if hasControl() returns correct status whether controller has control of specific switch.
+ * Test if {@link ZookeeperRegistry#hasControl(long)} returns correct status whether controller has control of specific switch.
* @throws Exception
*/
@Test
@@ -276,8 +275,8 @@
}
/**
- * Test if getControllerForSwitch() correctly returns controller ID of specific switch.
- * Relation between controllers and switches are defined by setPathChildrenCache() function.
+ * Test if {@link ZookeeperRegistry#getControllerForSwitch(long)} correctly returns controller ID of specific switch.
+ * Relation between controllers and switches are defined by {@link ZookeeperRegistryTest#setPathChildrenCache()} function.
* @throws Throwable
*/
@Test
@@ -295,11 +294,11 @@
}
/**
- * Test if getSwitchesControlledByController() returns correct list of switches controlled by
- * a controller.
+ * Test if {@link ZookeeperRegistry#getSwitchesControlledByController(String)} returns correct list of
+ * switches controlled by a controller.
* @throws Exception
*/
- // TODO: Test after implementation of getSwitch() is done.
+ // TODO: Test after getSwitchesControlledByController() is implemented.
@Ignore @Test
public void testGetSwitchesControlledByController() throws Exception {
String controllerIdRegistered = "controller1";
@@ -316,8 +315,8 @@
}
/**
- * Test if getAllSwitches() returns correct list of all switches.
- * Switches are injected in setPathChildrenCache() function.
+ * Test if {@link ZookeeperRegistry#getAllSwitches()} returns correct list of all switches.
+ * Switches are injected in {@link ZookeeperRegistryTest#setPathChildrenCache()} function.
* @throws Exception
*/
@Test
@@ -339,7 +338,7 @@
}
/**
- * Test if allocateUniqueIdBlock() can assign IdBlock without duplication.
+ * Test if {@link ZookeeperRegistry#allocateUniqueIdBlock()} can assign IdBlock without duplication.
*/
@Test
public void testAllocateUniqueIdBlock() {
@@ -374,20 +373,21 @@
}
}
+
+ //-------------------------- Creation of mock objects --------------------------
/**
- * Create mock CuratorFramework object with initial value below.
- * [Ctrl ID] : [DPID]
- * controller1 : 1000
- * controller2 : 1001
- * controller2 : 1002
+ * Create mock {@link CuratorFramework} object with initial value below.<br>
+ * [Ctrl ID] : [DPID]<br>
+ * controller1 : 1000<br>
+ * controller2 : 1001<br>
+ * controller2 : 1002<br>
* controller2013 : nothing
* @return Created mock object
* @throws Exception
*/
- @SuppressWarnings("serial")
+ @SuppressWarnings({ "serial", "unchecked" })
private CuratorFramework createCuratorFrameworkMock() throws Exception {
// Mock of AtomicValue
- @SuppressWarnings("unchecked")
AtomicValue<Long> atomicValue = EasyMock.createMock(AtomicValue.class);
EasyMock.expect(atomicValue.succeeded()).andReturn(true).anyTimes();
EasyMock.expect(atomicValue.preValue()).andAnswer(new IAnswer<Long>() {
@@ -408,7 +408,7 @@
}).anyTimes();
EasyMock.replay(atomicValue);
- // Mock of DistributedAtomicLong
+ // Mock DistributedAtomicLong
DistributedAtomicLong daLong = EasyMock.createMock(DistributedAtomicLong.class);
EasyMock.expect(daLong.add(EasyMock.anyLong())).andReturn(atomicValue).anyTimes();
EasyMock.replay(daLong);
@@ -418,8 +418,7 @@
andReturn(daLong).anyTimes();
PowerMock.replay(DistributedAtomicLong.class);
- // Mock of ListenerContainer
- @SuppressWarnings("unchecked")
+ // Mock ListenerContainer
ListenerContainer<PathChildrenCacheListener> listenerContainer = EasyMock.createMock(ListenerContainer.class);
listenerContainer.addListener(EasyMock.anyObject(PathChildrenCacheListener.class));
EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
@@ -431,13 +430,13 @@
}).once();
EasyMock.replay(listenerContainer);
- // Mock of PathChildrenCache
+ // Mock PathChildrenCache
PathChildrenCache pathChildrenCacheMain = createPathChildrenCacheMock(CONTROLLER_ID, new String[] {"/switches"}, listenerContainer);
PathChildrenCache pathChildrenCache1 = createPathChildrenCacheMock("controller1", new String[] {HexString.toHexString(1000L)}, listenerContainer);
PathChildrenCache pathChildrenCache2 = createPathChildrenCacheMock("controller2", new String[] {
HexString.toHexString(1001L), HexString.toHexString(1002L) },listenerContainer);
- // Mock of PathChildrenCache constructor
+ // Mock PathChildrenCache constructor
PowerMock.expectNew(PathChildrenCache.class,
EasyMock.anyObject(CuratorFramework.class), EasyMock.anyObject(String.class), EasyMock.anyBoolean()).
andReturn(pathChildrenCacheMain).once();
@@ -449,8 +448,7 @@
andReturn(pathChildrenCache2).anyTimes();
PowerMock.replay(PathChildrenCache.class);
- // Mock of ServiceCache
- @SuppressWarnings("unchecked")
+ // Mock ServiceCache
ServiceCache<ControllerService> serviceCache = EasyMock.createMock(ServiceCache.class);
serviceCache.start();
EasyMock.expectLastCall().once();
@@ -460,15 +458,13 @@
}}).anyTimes();
EasyMock.replay(serviceCache);
- // Mock of ServiceCacheBuilder
- @SuppressWarnings("unchecked")
+ // Mock ServiceCacheBuilder
ServiceCacheBuilder<ControllerService> serviceCacheBuilder = EasyMock.createMock(ServiceCacheBuilder.class);
EasyMock.expect(serviceCacheBuilder.name(EasyMock.anyObject(String.class))).andReturn(serviceCacheBuilder).once();
EasyMock.expect(serviceCacheBuilder.build()).andReturn(serviceCache).once();
EasyMock.replay(serviceCacheBuilder);
- // Mock of ServiceDiscovery
- @SuppressWarnings("unchecked")
+ // Mock ServiceDiscovery
ServiceDiscovery<ControllerService> serviceDiscovery = EasyMock.createMock(ServiceDiscovery.class);
serviceDiscovery.start();
EasyMock.expectLastCall().once();
@@ -477,15 +473,14 @@
EasyMock.expectLastCall().once();
EasyMock.replay(serviceDiscovery);
- // Mock of CuratorFramework
+ // Mock CuratorFramework
CuratorFramework client = EasyMock.createMock(CuratorFramework.class);
client.start();
EasyMock.expectLastCall().once();
EasyMock.expect(client.usingNamespace(EasyMock.anyObject(String.class))).andReturn(client);
EasyMock.replay(client);
- // Mock of ServiceDiscoveryBuilder
- @SuppressWarnings("unchecked")
+ // Mock ServiceDiscoveryBuilder
ServiceDiscoveryBuilder<ControllerService> builder = EasyMock.createMock(ServiceDiscoveryBuilder.class);
EasyMock.expect(builder.client(client)).andReturn(builder).once();
EasyMock.expect(builder.basePath(EasyMock.anyObject(String.class))).andReturn(builder);
@@ -500,9 +495,9 @@
}
/**
- * Create mock ServiceInstance object using given controller ID.
- * @param controllerId Controller ID to represent instance's payload (ControllerSeervice).
- * @return
+ * Create mock {@link ServiceInstance} object using given controller ID.
+ * @param controllerId Controller ID to represent instance's payload (ControllerService).
+ * @return Mock ServiceInstance object
*/
private ServiceInstance<ControllerService> createServiceInstanceMock(String controllerId) {
ControllerService controllerService = EasyMock.createMock(ControllerService.class);
@@ -518,11 +513,11 @@
}
/**
- * Create mock PathChildrenCache using given controller ID and DPIDs.
+ * Create mock {@link PathChildrenCache} using given controller ID and DPIDs.
* @param controllerId Controller ID to represent current data.
* @param paths List of HexString indicating switch's DPID.
* @param listener Callback object to be set as Listenable.
- * @return
+ * @return Mock PathChildrenCache object
* @throws Exception
*/
private PathChildrenCache createPathChildrenCacheMock(final String controllerId, final String [] paths,
@@ -549,11 +544,11 @@
}
/**
- * Create mock ChildData for {@link PathChildrenCache#getCurrentData()} return value.
+ * Create mock {@link ChildData} for {@link PathChildrenCache#getCurrentData()} return value.
* This object need to include 'sequence number' in tail of path string. ("-0" means 0th sequence)
* @param controllerId Controller ID
* @param path HexString indicating switch's DPID
- * @return
+ * @return Mock ChildData object
*/
private ChildData createChildDataMockForCurrentData(String controllerId, String path) {
ChildData data = EasyMock.createMock(ChildData.class);
@@ -570,21 +565,21 @@
*/
private void setPathChildrenCache() throws Exception {
pathChildrenCacheListener.childEvent(client,
- createChildDataEventMock("controller1", HexString.toHexString(1000L), PathChildrenCacheEvent.Type.CHILD_ADDED));
+ createChildrenCacheEventMock("controller1", HexString.toHexString(1000L), PathChildrenCacheEvent.Type.CHILD_ADDED));
pathChildrenCacheListener.childEvent(client,
- createChildDataEventMock("controller2", HexString.toHexString(1001L), PathChildrenCacheEvent.Type.CHILD_ADDED));
+ createChildrenCacheEventMock("controller2", HexString.toHexString(1001L), PathChildrenCacheEvent.Type.CHILD_ADDED));
pathChildrenCacheListener.childEvent(client,
- createChildDataEventMock("controller2", HexString.toHexString(1002L), PathChildrenCacheEvent.Type.CHILD_ADDED));
+ createChildrenCacheEventMock("controller2", HexString.toHexString(1002L), PathChildrenCacheEvent.Type.CHILD_ADDED));
}
/**
- * Create mock ChildDataEvent object using given controller ID and DPID.
+ * Create mock {@link PathChildrenCacheEvent} object using given controller ID and DPID.
* @param controllerId Controller ID.
* @param path HexString of DPID.
* @param type Event type to be set to mock object.
- * @return
+ * @return Mock PathChildrenCacheEvent object
*/
- private PathChildrenCacheEvent createChildDataEventMock(String controllerId, String path,
+ private PathChildrenCacheEvent createChildrenCacheEventMock(String controllerId, String path,
PathChildrenCacheEvent.Type type) {
PathChildrenCacheEvent event = EasyMock.createMock(PathChildrenCacheEvent.class);
ChildData data = EasyMock.createMock(ChildData.class);
diff --git a/start-onos-embedded.sh b/start-onos-embedded.sh
index 5da4d9b..dac0331 100755
--- a/start-onos-embedded.sh
+++ b/start-onos-embedded.sh
@@ -14,9 +14,14 @@
JVM_OPTS=""
JVM_OPTS="$JVM_OPTS -server -d64"
JVM_OPTS="$JVM_OPTS -Xmx2g -Xms2g -Xmn800m"
-JVM_OPTS="$JVM_OPTS -XX:+UseParallelGC -XX:+AggressiveOpts -XX:+UseFastAccessorMethods"
+#JVM_OPTS="$JVM_OPTS -XX:+UseParallelGC -XX:+AggressiveOpts -XX:+UseFastAccessorMethods"
+JVM_OPTS="$JVM_OPTS -XX:+UseConcMarkSweepGC -XX:+UseAdaptiveSizePolicy -XX:+AggressiveOpts -XX:+UseFastAccessorMethods"
JVM_OPTS="$JVM_OPTS -XX:MaxInlineSize=8192 -XX:FreqInlineSize=8192"
JVM_OPTS="$JVM_OPTS -XX:CompileThreshold=1500 -XX:PreBlockSpin=8 \
+ -XX:+UseThreadPriorities \
+ -XX:ThreadPriorityPolicy=42 \
+ -XX:+UseCompressedOops \
+ -Dcassandra.compaction.priority=1 \
-Dcom.sun.management.jmxremote.port=7199 \
-Dcom.sun.management.jmxremote.ssl=false \
-Dcom.sun.management.jmxremote.authenticate=false"
diff --git a/start-onos.sh b/start-onos.sh
index 46833db..c356c87 100755
--- a/start-onos.sh
+++ b/start-onos.sh
@@ -17,11 +17,18 @@
#JVM_OPTS="$JVM_OPTS -Xmx2g -Xms2g -Xmn800m"
JVM_OPTS="$JVM_OPTS -Xmx1g -Xms1g -Xmn800m"
#JVM_OPTS="$JVM_OPTS -XX:+UseParallelGC -XX:+AggressiveOpts -XX:+UseFastAccessorMethods"
-JVM_OPTS="$JVM_OPTS -XX:+UseConcMarkSweepGC -XX:+AggressiveOpts -XX:+UseFastAccessorMethods"
+JVM_OPTS="$JVM_OPTS -XX:+UseConcMarkSweepGC -XX:+UseAdaptiveSizePolicy -XX:+AggressiveOpts -XX:+UseFastAccessorMethods"
JVM_OPTS="$JVM_OPTS -XX:MaxInlineSize=8192 -XX:FreqInlineSize=8192"
JVM_OPTS="$JVM_OPTS -XX:CompileThreshold=1500 -XX:PreBlockSpin=8"
JVM_OPTS="$JVM_OPTS -XX:OnError=crash-logger" ;# For dumping core
#JVM_OPTS="$JVM_OPTS -Dpython.security.respectJavaAccessibility=false"
+JVM_OPTS="$JVM_OPTS -XX:CompileThreshold=1500 -XX:PreBlockSpin=8 \
+ -XX:+UseThreadPriorities \
+ -XX:ThreadPriorityPolicy=42 \
+ -XX:+UseCompressedOops \
+ -Dcom.sun.management.jmxremote.port=7189 \
+ -Dcom.sun.management.jmxremote.ssl=false \
+ -Dcom.sun.management.jmxremote.authenticate=false"
# Set ONOS core main class
MAIN_CLASS="net.onrc.onos.ofcontroller.core.Main"
@@ -119,7 +126,7 @@
for p in ${pids}; do
if [ x$p != "x" ]; then
kill -KILL $p
- echo "Killed existing prosess (pid: $p)"
+ echo "Killed existing process (pid: $p)"
fi
done
}
diff --git a/titan/schema/test-network.xml b/titan/schema/test-network.xml
index 5c63d90..630c5da 100644
--- a/titan/schema/test-network.xml
+++ b/titan/schema/test-network.xml
@@ -3,6 +3,7 @@
<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="state" for="node" attr.name="state" 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>
@@ -17,31 +18,37 @@
<node id="1">
<data key="type">switch</data>
<data key="dpid">00:00:00:00:00:00:0a:01</data>
+ <data key="state">ACTIVE</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="state">ACTIVE</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="state">ACTIVE</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="state">ACTIVE</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="state">ACTIVE</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="state">ACTIVE</data>
<data key="desc">OpenFlow Switch at ATL</data>
</node>