Merge branch 'javadoc' into release
diff --git a/cluster-mgmt/bin/func.sh b/cluster-mgmt/bin/func.sh
index fe65ab6..b42ead1 100755
--- a/cluster-mgmt/bin/func.sh
+++ b/cluster-mgmt/bin/func.sh
@@ -29,9 +29,11 @@
case "$1" in
start)
echo "Starting ZK.."
- dsh -g $basename "$ZK_DIR/bin/zkServer.sh start"
+# dsh -g $basename "$ZK_DIR/bin/zkServer.sh start"
+ dsh -g $basename 'cd ONOS; ./start-zk.sh start'
while [ 1 ]; do
- nup=`dsh -g $basename "$ZK_DIR/bin/zkServer.sh status" | grep "Mode" | egrep "leader|follower" | wc -l`
+# nup=`dsh -g $basename "$ZK_DIR/bin/zkServer.sh status" | grep "Mode" | egrep "leader|follower" | wc -l`
+ nup=`dsh -g $basename "cd ONOS; ./start-zk.sh status" | grep "Mode" | egrep "leader|follower|standalone" | wc -l`
if [ $nup == $nr_nodes ]; then
echo "everybody's up: $nup up of of $nr_nodes"
echo "ZK started"
@@ -125,7 +127,9 @@
start)
if [ x$2 == "x" -o x$2 == "xall" ]; then
echo "Starting ONOS on all nodes"
- dsh -g ${basename} "cd $ONOS_DIR; ./start-onos.sh start"
+ dsh -w ${basename}1 "cd $ONOS_DIR; ./start-onos.sh start"
+ sleep 3
+ dsh -g ${basename} -x ${basename}1 "cd $ONOS_DIR; ./start-onos.sh start"
dsh -g ${basename} "cd $ONOS_DIR; ./start-rest.sh start"
else
echo "Starting ONOS on ${basename}$2"
diff --git a/cluster-mgmt/bin/zk b/cluster-mgmt/bin/zk
index 262c936..b2033ad 100755
--- a/cluster-mgmt/bin/zk
+++ b/cluster-mgmt/bin/zk
@@ -1,5 +1,5 @@
#! /bin/bash
-. ${HOME}/bin/func.sh
+. `dirname $0`/func.sh
#$0 $1 $2
`basename $0` $1 $2
diff --git a/src/main/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjects.java b/src/main/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjects.java
index d08da7c..3a5c9e2 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjects.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjects.java
@@ -14,6 +14,12 @@
import com.tinkerpop.frames.annotations.gremlin.GremlinParam;
import com.tinkerpop.frames.VertexFrame;
+/*
+ * This is the interfaces to make the objects for Cassandra DB.
+ * They are interfaces, but it is also implementation,
+ * so this handles various control to the objects.
+ * Please take a look at tinkerpop/frames annotation doc to understand more.
+ */
public interface INetMapTopologyObjects {
public interface IBaseObject extends VertexFrame {
@@ -62,7 +68,7 @@
public Iterable<IDeviceObject> getDevices();
@JsonIgnore
- @Incidence(label="switch",direction = Direction.IN)
+ @Adjacency(label="switch",direction = Direction.IN)
public Iterable<IFlowEntry> getFlowEntries();
}
@@ -114,11 +120,11 @@
public void removeDevice(final IDeviceObject device);
@JsonIgnore
- @Incidence(label="inport",direction = Direction.IN)
+ @Adjacency(label="inport",direction = Direction.IN)
public Iterable<IFlowEntry> getInFlowEntries();
@JsonIgnore
- @Incidence(label="outport",direction = Direction.IN)
+ @Adjacency(label="outport",direction = Direction.IN)
public Iterable<IFlowEntry> getOutFlowEntries();
@JsonIgnore
@@ -155,11 +161,11 @@
public Iterable<IPortObject> getAttachedPorts();
@JsonIgnore
- @Incidence(label="host",direction=Direction.IN)
+ @Adjacency(label="host",direction=Direction.IN)
public void setHostPort(final IPortObject port);
@JsonIgnore
- @Incidence(label="host",direction=Direction.IN)
+ @Adjacency(label="host",direction=Direction.IN)
public void removeHostPort(final IPortObject port);
@JsonIgnore
diff --git a/src/main/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImpl.java b/src/main/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImpl.java
index 03a5e8e..126efb3 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImpl.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImpl.java
@@ -72,7 +72,8 @@
log.info("SwitchStorage:addSwitch(): dpid {} ", dpid);
try {
- newSwitch(dpid);
+ ISwitchObject sw = newSwitch(dpid);
+ if ( sw == null ) throw new RuntimeException();
op.commit();
} catch (Exception e) {
e.printStackTrace();
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/test/java/net/floodlightcontroller/core/internal/ControllerTest.java b/src/test/java/net/floodlightcontroller/core/internal/ControllerTest.java
index 88e2d35..ecdc2d7 100644
--- a/src/test/java/net/floodlightcontroller/core/internal/ControllerTest.java
+++ b/src/test/java/net/floodlightcontroller/core/internal/ControllerTest.java
@@ -70,6 +70,12 @@
import net.floodlightcontroller.test.FloodlightTestCase;
import net.floodlightcontroller.threadpool.IThreadPoolService;
import net.onrc.onos.ofcontroller.core.IOFSwitchPortListener;
+import net.onrc.onos.ofcontroller.core.INetMapTopologyService.ITopoRouteService;
+import net.onrc.onos.ofcontroller.flowmanager.FlowManager;
+import net.onrc.onos.ofcontroller.flowmanager.IFlowService;
+import net.onrc.onos.ofcontroller.routing.TopoRouteService;
+import net.onrc.onos.registry.controller.IControllerRegistryService;
+import net.onrc.onos.registry.controller.StandaloneRegistry;
import org.easymock.Capture;
import org.easymock.EasyMock;
@@ -82,6 +88,8 @@
import org.openflow.protocol.OFPacketIn;
import org.openflow.protocol.OFPacketIn.OFPacketInReason;
import org.openflow.protocol.OFPhysicalPort;
+import org.openflow.protocol.OFPhysicalPort.OFPortConfig;
+import org.openflow.protocol.OFPhysicalPort.OFPortState;
import org.openflow.protocol.OFPortStatus;
import org.openflow.protocol.OFPortStatus.OFPortReason;
import org.openflow.protocol.OFStatisticsReply;
@@ -128,16 +136,26 @@
tp = new MockThreadPoolService();
fmc.addService(IThreadPoolService.class, tp);
+ // Following added by ONOS
+ // TODO replace with mock if further testing is needed.
+ fmc.addService(IFlowService.class, new FlowManager() );
+ fmc.addService(ITopoRouteService.class, new TopoRouteService() );
+ StandaloneRegistry sr = new StandaloneRegistry();
+ fmc.addService(IControllerRegistryService.class, sr );
+
+
ppt.init(fmc);
restApi.init(fmc);
memstorage.init(fmc);
cm.init(fmc);
tp.init(fmc);
+ sr.init(fmc);
ppt.startUp(fmc);
restApi.startUp(fmc);
memstorage.startUp(fmc);
cm.startUp(fmc);
tp.startUp(fmc);
+ sr.startUp(fmc);
}
public Controller getController() {
@@ -394,7 +412,6 @@
expect(newsw.getBuffers()).andReturn(0).anyTimes();
expect(newsw.getTables()).andReturn((byte)0).anyTimes();
expect(newsw.getActions()).andReturn(0).anyTimes();
- expect(newsw.getPorts()).andReturn(new ArrayList<OFPhysicalPort>());
controller.activeSwitches.put(0L, oldsw);
replay(newsw, channel, channel2);
@@ -647,7 +664,7 @@
assertTrue("Check that update is HARoleUpdate",
upd instanceof Controller.HARoleUpdate);
Controller.HARoleUpdate roleUpd = (Controller.HARoleUpdate)upd;
- assertSame(null, roleUpd.oldRole);
+ assertSame(Role.MASTER, roleUpd.oldRole);
assertSame(Role.SLAVE, roleUpd.newRole);
}
@@ -701,15 +718,16 @@
state.hasGetConfigReply = true;
// Role support disabled. Switch should be promoted to active switch
// list.
- setupSwitchForAddSwitch(chdlr.sw, 0L);
- chdlr.sw.clearAllFlowMods();
- replay(controller.roleChanger, chdlr.sw);
- chdlr.checkSwitchReady();
- verify(controller.roleChanger, chdlr.sw);
- assertSame(OFChannelState.HandshakeState.READY, state.hsState);
- assertSame(chdlr.sw, controller.activeSwitches.get(0L));
- assertTrue(controller.connectedSwitches.contains(chdlr.sw));
- assertTrue(state.firstRoleReplyReceived);
+// FIXME: ONOS modified the behavior to always submit Role Request to trigger OFS error.
+// setupSwitchForAddSwitch(chdlr.sw, 0L);
+// chdlr.sw.clearAllFlowMods();
+// replay(controller.roleChanger, chdlr.sw);
+// chdlr.checkSwitchReady();
+// verify(controller.roleChanger, chdlr.sw);
+// assertSame(OFChannelState.HandshakeState.READY, state.hsState);
+// assertSame(chdlr.sw, controller.activeSwitches.get(0L));
+// assertTrue(controller.connectedSwitches.contains(chdlr.sw));
+// assertTrue(state.firstRoleReplyReceived);
reset(chdlr.sw);
reset(controller.roleChanger);
controller.connectedSwitches.clear();
@@ -719,9 +737,15 @@
// Role support enabled.
state.hsState = OFChannelState.HandshakeState.FEATURES_REPLY;
controller.role = Role.MASTER;
+ expect(chdlr.sw.getStringId()).andReturn("SomeID").anyTimes();
+ expect(chdlr.sw.getId()).andReturn(42L).anyTimes();
Capture<Collection<OFSwitchImpl>> swListCapture =
new Capture<Collection<OFSwitchImpl>>();
controller.roleChanger.submitRequest(capture(swListCapture),
+ same(Role.SLAVE));
+ Capture<Collection<OFSwitchImpl>> swListCapture2 =
+ new Capture<Collection<OFSwitchImpl>>();
+ controller.roleChanger.submitRequest(capture(swListCapture2),
same(Role.MASTER));
replay(controller.roleChanger, chdlr.sw);
chdlr.checkSwitchReady();
@@ -729,7 +753,7 @@
assertSame(OFChannelState.HandshakeState.READY, state.hsState);
assertTrue(controller.activeSwitches.isEmpty());
assertTrue(controller.connectedSwitches.contains(chdlr.sw));
- assertTrue(state.firstRoleReplyReceived);
+// assertTrue(state.firstRoleReplyReceived);
Collection<OFSwitchImpl> swList = swListCapture.getValue();
assertEquals(1, swList.size());
assertTrue("swList must contain this switch", swList.contains(chdlr.sw));
@@ -825,7 +849,7 @@
state.firstRoleReplyReceived = false;
controller.role = Role.SLAVE;
expect(chdlr.sw.checkFirstPendingRoleRequestXid(xid)).andReturn(true);
- chdlr.sw.deliverRoleRequestNotSupportedEx(xid);
+ expect(chdlr.sw.deliverRoleRequestNotSupportedEx(xid)).andReturn(Role.SLAVE);
expect(chdlr.sw.getChannel()).andReturn(ch).anyTimes();
expect(ch.close()).andReturn(null);
@@ -845,7 +869,7 @@
state.firstRoleReplyReceived = false;
controller.role = Role.SLAVE;
expect(chdlr.sw.checkFirstPendingRoleRequestXid(xid)).andReturn(true);
- chdlr.sw.deliverRoleRequestNotSupportedEx(xid);
+ expect(chdlr.sw.deliverRoleRequestNotSupportedEx(xid)).andReturn(Role.SLAVE);
expect(chdlr.sw.getChannel()).andReturn(ch).anyTimes();
expect(ch.close()).andReturn(null);
replay(ch, chdlr.sw);
@@ -864,7 +888,7 @@
state.firstRoleReplyReceived = false;
controller.role = Role.MASTER;
expect(chdlr.sw.checkFirstPendingRoleRequestXid(xid)).andReturn(true);
- chdlr.sw.deliverRoleRequestNotSupportedEx(xid);
+ expect(chdlr.sw.deliverRoleRequestNotSupportedEx(xid)).andReturn(Role.MASTER);
setupSwitchForAddSwitch(chdlr.sw, 0L);
chdlr.sw.clearAllFlowMods();
replay(ch, chdlr.sw);
@@ -1102,6 +1126,26 @@
assertEquals(SwitchUpdateType.PORTCHANGED, swUpdate.switchUpdateType);
}
+ public void verifyPortAddedUpdateInQueue(IOFSwitch sw) throws Exception {
+ assertEquals(2, controller.updates.size());
+ IUpdate update = controller.updates.take();
+ assertEquals(true, update instanceof SwitchUpdate);
+ SwitchUpdate swUpdate = (SwitchUpdate)update;
+ assertEquals(sw, swUpdate.sw);
+ assertEquals(SwitchUpdateType.PORTADDED, swUpdate.switchUpdateType);
+ verifyPortChangedUpdateInQueue(sw);
+ }
+
+ public void verifyPortRemovedUpdateInQueue(IOFSwitch sw) throws Exception {
+ assertEquals(2, controller.updates.size());
+ IUpdate update = controller.updates.take();
+ assertEquals(true, update instanceof SwitchUpdate);
+ SwitchUpdate swUpdate = (SwitchUpdate)update;
+ assertEquals(sw, swUpdate.sw);
+ assertEquals(SwitchUpdateType.PORTREMOVED, swUpdate.switchUpdateType);
+ verifyPortChangedUpdateInQueue(sw);
+ }
+
/*
* Test handlePortStatus()
* TODO: test correct updateStorage behavior!
@@ -1122,25 +1166,51 @@
replay(sw);
controller.handlePortStatusMessage(sw, ofps, false);
verify(sw);
- verifyPortChangedUpdateInQueue(sw);
+ verifyPortAddedUpdateInQueue(sw);
reset(sw);
+ // ONOS:Port is considered added if Link state is not down and not configured to be down
ofps.setReason((byte)OFPortReason.OFPPR_MODIFY.ordinal());
sw.setPort(port);
expectLastCall().once();
replay(sw);
controller.handlePortStatusMessage(sw, ofps, false);
verify(sw);
- verifyPortChangedUpdateInQueue(sw);
+ verifyPortAddedUpdateInQueue(sw);
reset(sw);
+ // ONOS:Port is considered removed if Link state is down
+ ofps.setReason((byte)OFPortReason.OFPPR_MODIFY.ordinal());
+ port.setState(OFPortState.OFPPS_LINK_DOWN.getValue());
+ sw.setPort(port);
+ expectLastCall().once();
+ replay(sw);
+ controller.handlePortStatusMessage(sw, ofps, false);
+ verify(sw);
+ verifyPortRemovedUpdateInQueue(sw);
+ reset(sw);
+ port.setState(0);// reset
+
+ // ONOS: .. or is configured to be down
+ ofps.setReason((byte)OFPortReason.OFPPR_MODIFY.ordinal());
+ port.setConfig(OFPortConfig.OFPPC_PORT_DOWN.getValue());
+ sw.setPort(port);
+ expectLastCall().once();
+ replay(sw);
+ controller.handlePortStatusMessage(sw, ofps, false);
+ verify(sw);
+ verifyPortRemovedUpdateInQueue(sw);
+ reset(sw);
+ port.setConfig(0);// reset
+
+
ofps.setReason((byte)OFPortReason.OFPPR_DELETE.ordinal());
sw.deletePort(port.getPortNumber());
expectLastCall().once();
replay(sw);
controller.handlePortStatusMessage(sw, ofps, false);
verify(sw);
- verifyPortChangedUpdateInQueue(sw);
+ verifyPortRemovedUpdateInQueue(sw);
reset(sw);
}
}
diff --git a/src/test/java/net/floodlightcontroller/core/internal/RoleChangerTest.java b/src/test/java/net/floodlightcontroller/core/internal/RoleChangerTest.java
index 991afff..a6a6d85 100644
--- a/src/test/java/net/floodlightcontroller/core/internal/RoleChangerTest.java
+++ b/src/test/java/net/floodlightcontroller/core/internal/RoleChangerTest.java
@@ -16,6 +16,7 @@
import org.easymock.EasyMock;
import org.jboss.netty.channel.Channel;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
public class RoleChangerTest {
@@ -58,6 +59,7 @@
* The connection should be closed.
*/
@Test
+ @Ignore // FIXME: ONOS modified the behavior here to intentionally trigger OFS error.
public void testSendRoleRequestMasterNotSupported() {
LinkedList<OFSwitchImpl> switches = new LinkedList<OFSwitchImpl>();
diff --git a/src/test/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjectsIDeviceObjectTest.java b/src/test/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjectsIDeviceObjectTest.java
new file mode 100644
index 0000000..3ea90ba
--- /dev/null
+++ b/src/test/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjectsIDeviceObjectTest.java
@@ -0,0 +1,206 @@
+package net.onrc.onos.ofcontroller.core;
+
+import static org.junit.Assert.*;
+
+import java.util.HashMap;
+
+import net.onrc.onos.graph.GraphDBConnection;
+import net.onrc.onos.graph.GraphDBOperation;
+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.internal.SwitchStorageImpl;
+import net.onrc.onos.ofcontroller.core.internal.TestDatabaseManager;
+import org.easymock.EasyMock;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.api.easymock.PowerMock;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.slf4j.LoggerFactory;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import com.thinkaurelius.titan.core.TitanFactory;
+import com.thinkaurelius.titan.core.TitanGraph;
+
+//Add Powermock preparation
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({TitanFactory.class, GraphDBConnection.class, GraphDBOperation.class, SwitchStorageImpl.class})
+public class INetMapTopologyObjectsIDeviceObjectTest {
+
+ //The test network is ./titan/schema/test-network.xml
+
+ protected static org.slf4j.Logger log = LoggerFactory.getLogger(SwitchStorageImpl.class);
+
+ String conf;
+ private GraphDBConnection conn = null;
+ private GraphDBOperation ope = null;
+ private TitanGraph titanGraph = null;
+
+ @Before
+ public void setUp() throws Exception {
+ conf = "/dummy/path/to/db";
+
+ // Make mock cassandra DB
+ // Replace TitanFactory.open() to return mock DB
+ TestDatabaseManager.deleteTestDatabase();
+ titanGraph = TestDatabaseManager.getTestDatabase();
+ //TestDatabaseManager.populateTestData(titanGraph);
+ PowerMock.mockStatic(TitanFactory.class);
+ EasyMock.expect(TitanFactory.open((String)EasyMock.anyObject())).andReturn(titanGraph);
+ PowerMock.replay(TitanFactory.class);
+
+ conn = GraphDBConnection.getInstance(conf);
+ ope = new GraphDBOperation(conn);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ titanGraph.shutdown();
+ TestDatabaseManager.deleteTestDatabase();
+ }
+
+ /**
+ * Desc:
+ * Test method for get and set MacAddress method.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set the mac address.
+ * 2. Should get the mac address.
+ */
+ @Test
+ public void testSetGetMacAddress() {
+ String macaddr = "00:00:00:00:00:00:0a:07";
+ IDeviceObject devObj = ope.newDevice();
+ devObj.setMACAddress(macaddr);
+ assertEquals(devObj.getMACAddress(), macaddr);
+ }
+
+ /**
+ * Desc:
+ * Test method for get and set IPAddress method.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set the ip address.
+ * 2. Should get the ip address.
+ */
+ @Test
+ public void testSetGetIPAddress() {
+ String ipaddr = "192.168.0.1";
+ IDeviceObject devObj = ope.newDevice();
+ devObj.setIPAddress(ipaddr);
+ assertEquals(devObj.getIPAddress(), ipaddr);
+ }
+
+ /**
+ * Desc:
+ * Test method for get attached port.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should get the attached ports.
+ */
+ @Test
+ public void testGetAttachedPort() {
+ String dpid = "00:00:00:00:00:00:0a:07";
+ Short number = 1;
+ Short number2 = 2;
+ IPortObject portObj = ope.newPort(dpid, number);
+ IPortObject portObj2 = ope.newPort(dpid, number2);
+
+ String ipaddr = "192.168.0.1";
+ IDeviceObject devObj = ope.newDevice();
+
+ portObj.setDevice(devObj);
+ portObj2.setDevice(devObj);
+
+ HashMap<Short, IPortObject> portObjectList = new HashMap<Short, IPortObject>();
+ for(IPortObject port : devObj.getAttachedPorts())
+ {
+ portObjectList.put(port.getNumber(), port);
+ }
+
+ assertTrue(portObjectList.containsValue(portObj));
+ assertTrue(portObjectList.containsValue(portObj2));
+
+ }
+
+ /**
+ * Desc:
+ * Test method for set and remove host port method.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set host port from the device.
+ * 2. Should remove host port from the device.
+ */
+ @Test
+ public void testSetRemoveHostPort() {
+ String dpid = "00:00:00:00:00:00:0a:07";
+ Short number = 1;
+ Short number2 = 2;
+ IPortObject portObj = ope.newPort(dpid, number);
+ IPortObject portObj2 = ope.newPort(dpid, number2);
+
+ String ipaddr = "192.168.0.1";
+ IDeviceObject devObj = ope.newDevice();
+
+ devObj.setHostPort(portObj);
+
+ HashMap<String, IDeviceObject> portObjectList = new HashMap<String, IDeviceObject>();
+ for(IDeviceObject dev : portObj.getDevices())
+ {
+ portObjectList.put(dev.getMACAddress(), dev);
+ }
+ assertTrue(portObjectList.containsValue(devObj));
+
+ devObj.removeHostPort(portObj);
+
+ HashMap<String, IDeviceObject> portObjectList2 = new HashMap<String, IDeviceObject>();
+ for(IDeviceObject dev : portObj.getDevices())
+ {
+ portObjectList2.put(dev.getMACAddress(), dev);
+ }
+ assertTrue(!portObjectList2.containsValue(devObj));
+ }
+
+ /**
+ * Desc:
+ * Test method for getSwitch method.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should get the switch connected to the device.
+ */
+ @Test
+ public void testGetSwitches() {
+ String dpid = "00:00:00:00:00:00:0a:07";
+ String dpid2 = "00:00:00:00:00:00:0a:08";
+ Short number = 1;
+ Short number2 = 2;
+ ISwitchObject swObj = ope.newSwitch(dpid);
+ ISwitchObject swObj2 = ope.newSwitch(dpid2);
+ IPortObject portObj = ope.newPort(dpid, number);
+ IPortObject portObj2 = ope.newPort(dpid2, number2);
+ swObj.addPort(portObj);
+ swObj2.addPort(portObj2);
+ IDeviceObject devObj = ope.newDevice();
+ portObj.setDevice(devObj);
+ portObj2.setDevice(devObj);
+
+ HashMap<String, ISwitchObject> switchObjectList = new HashMap<String, ISwitchObject>();
+ for(ISwitchObject sw : devObj.getSwitch())
+ {
+ switchObjectList.put(sw.getDPID(), sw);
+ }
+ assertTrue(switchObjectList.containsValue(swObj));
+ assertTrue(switchObjectList.containsValue(swObj2));
+ }
+
+
+}
\ No newline at end of file
diff --git a/src/test/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjectsIFlowEntryTest.java b/src/test/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjectsIFlowEntryTest.java
new file mode 100644
index 0000000..eba7447
--- /dev/null
+++ b/src/test/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjectsIFlowEntryTest.java
@@ -0,0 +1,348 @@
+package net.onrc.onos.ofcontroller.core;
+
+import static org.junit.Assert.*;
+
+import net.onrc.onos.graph.GraphDBConnection;
+import net.onrc.onos.graph.GraphDBOperation;
+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.internal.SwitchStorageImpl;
+import net.onrc.onos.ofcontroller.core.internal.TestDatabaseManager;
+import org.easymock.EasyMock;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.api.easymock.PowerMock;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.slf4j.LoggerFactory;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import com.thinkaurelius.titan.core.TitanFactory;
+import com.thinkaurelius.titan.core.TitanGraph;
+
+//Add Powermock preparation
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({TitanFactory.class, GraphDBConnection.class, GraphDBOperation.class, SwitchStorageImpl.class})
+public class INetMapTopologyObjectsIFlowEntryTest {
+
+ //The test network is ./titan/schema/test-network.xml
+
+ protected static org.slf4j.Logger log = LoggerFactory.getLogger(SwitchStorageImpl.class);
+
+ String conf;
+ private GraphDBConnection conn = null;
+ private GraphDBOperation ope = null;
+ private TitanGraph titanGraph = null;
+ private IFlowEntry flowEntry = null;
+
+ @Before
+ public void setUp() throws Exception {
+ conf = "/dummy/path/to/db";
+
+ // Make mock cassandra DB
+ // Replace TitanFactory.open() to return mock DB
+ TestDatabaseManager.deleteTestDatabase();
+ titanGraph = TestDatabaseManager.getTestDatabase();
+ //TestDatabaseManager.populateTestData(titanGraph);
+ PowerMock.mockStatic(TitanFactory.class);
+ EasyMock.expect(TitanFactory.open((String)EasyMock.anyObject())).andReturn(titanGraph);
+ PowerMock.replay(TitanFactory.class);
+
+ conn = GraphDBConnection.getInstance(conf);
+ ope = new GraphDBOperation(conn);
+
+ flowEntry = ope.newFlowEntry();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ titanGraph.shutdown();
+ TestDatabaseManager.deleteTestDatabase();
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get FlowEntryId.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set FlowEntryId.
+ * 2. Should get FlowEntryId.
+ */
+ @Test
+ public void testSetGetFlowEntryId() {
+ String flowEntryId = "xx";
+ flowEntry.setFlowEntryId(flowEntryId);
+ assertEquals(flowEntry.getFlowEntryId(), flowEntryId);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get SwitchDpid.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set SwitchDpid.
+ * 2. Should get SwitchDpid.
+ */
+ @Test
+ public void testSetGetSwitchDpid() {
+ String switchDpid = "00:00:00:00:00:11";
+ flowEntry.setSwitchDpid(switchDpid);
+ assertEquals(flowEntry.getSwitchDpid(), switchDpid);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get UserState.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set UserState.
+ * 2. Should get UserState.
+ */
+ @Test
+ public void testSetGetUserState() {
+ String userStete = "good";
+ flowEntry.setUserState(userStete);
+ assertEquals(flowEntry.getUserState(), userStete);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get SwitchState.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set SwitchState.
+ * 2. Should get SwitchState.
+ */
+ @Test
+ public void testSetGetSwitchState() {
+ String switchStete = "ACTIVE";
+ flowEntry.setSwitchState(switchStete);
+ assertEquals(flowEntry.getSwitchState(), switchStete);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get ErrorStateType.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set ErrorStateType.
+ * 2. Should get ErrorStateType.
+ */
+ @Test
+ public void testSetGetErrorStateType() {
+ String errorSteteType = "error";
+ flowEntry.setErrorStateType(errorSteteType);
+ assertEquals(flowEntry.getErrorStateType(), errorSteteType);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get ErrorStateCode.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set ErrorStateCode.
+ * 2. Should get ErrorStateCode.
+ */
+ @Test
+ public void testSetGetErrorStateCode() {
+ String errorSteteCode = "error";
+ flowEntry.setErrorStateCode(errorSteteCode);
+ assertEquals(flowEntry.getErrorStateCode(), errorSteteCode);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get MatchInPort.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set MatchInPort.
+ * 2. Should get MatchInPort.
+ */
+ @Test
+ public void testSetGetMatchInPort() {
+ Short inPort = 1;
+ flowEntry.setMatchInPort(inPort);
+ assertEquals(flowEntry.getMatchInPort(), inPort);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get MatchEthernetFrameType.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set MatchEthernetFrameType.
+ * 2. Should get MatchEthernetFrameType.
+ */
+ @Test
+ public void testSetGetMatchEthernetFrameType() {
+ Short matchEthernetFrameType = 1;
+ flowEntry.setMatchEthernetFrameType(matchEthernetFrameType);
+ assertEquals(flowEntry.getMatchEthernetFrameType(), matchEthernetFrameType);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get MatchSrcMac.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set MatchSrcMac.
+ * 2. Should get MatchSrcMac.
+ */
+ @Test
+ public void testSetGetMatchSrcMac() {
+ String matchSrcMac = "00:00:00:00:00:11";
+ flowEntry.setMatchSrcMac(matchSrcMac);
+ assertEquals(flowEntry.getMatchSrcMac(), matchSrcMac);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get MatchDstMac.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set MatchDstMac.
+ * 2. Should get MatchDstMac.
+ */
+ @Test
+ public void testSetGetMatchDstMac() {
+ String matchDstMac = "00:00:00:00:00:11";
+ flowEntry.setMatchDstMac(matchDstMac);
+ assertEquals(flowEntry.getMatchDstMac(), matchDstMac);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get SrcIPv4Net.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set SrcIPv4Net.
+ * 2. Should get SrcIPv4Net.
+ */
+ @Test
+ public void testSetGetMatchSrcIPv4Net() {
+ String srcIPv4Net = "192.168.0.1";
+ flowEntry.setMatchSrcIPv4Net(srcIPv4Net);
+ assertEquals(flowEntry.getMatchSrcIPv4Net(), srcIPv4Net);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get MatchDstIPv4Net.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set MatchDstIPv4Net.
+ * 2. Should get MatchDstIPv4Net.
+ */
+ @Test
+ public void testSetGetMatchDstIPv4Net() {
+ String dstIPv4Net = "192.168.0.1";
+ flowEntry.setMatchDstIPv4Net(dstIPv4Net);
+ assertEquals(flowEntry.getMatchDstIPv4Net(), dstIPv4Net);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get ActionOutput.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set ActionOutput.
+ * 2. Should get ActionOutput.
+ */
+ @Test
+ public void testSetGetActionOutput() {
+ Short actionOutput = 1;
+ flowEntry.setActionOutput(actionOutput);
+ assertEquals(flowEntry.getActionOutput(), actionOutput);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get FlowPath.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set FlowPath.
+ * 2. Should get FlowPath.
+ */
+ @Test
+ public void testSetGetFlowPath() {
+ IFlowPath fp = ope.newFlowPath();
+ String flowId = "xx";
+ fp.setFlowId(flowId);
+ flowEntry.setFlow(fp);
+ IFlowPath fp2 = flowEntry.getFlow();
+ assertEquals(fp2.getFlowId(), flowId);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get Switch.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set Switch.
+ * 2. Should get Switch.
+ */
+ @Test
+ public void testSetGetSwitch() {
+ String dpid = "00:00:00:00:00:22";
+ ISwitchObject sw1 = ope.newSwitch(dpid);
+ flowEntry.setSwitch(sw1);
+ ISwitchObject sw2 = flowEntry.getSwitch();
+ assertEquals(sw2, sw1);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get InPort.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set InPort.
+ * 2. Should get InPort.
+ */
+ @Test
+ public void testSetGetInPort() {
+ String dpid = "00:00:00:00:00:22";
+ Short portNum = 4;
+ IPortObject port1 = ope.newPort(dpid, portNum);
+ flowEntry.setInPort(port1);
+ IPortObject port2 = flowEntry.getInPort();
+ assertEquals(port2, port1);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get OutPort.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set OutPort.
+ * 2. Should get OutPort.
+ */
+ @Test
+ public void testSetGetOutPort() {
+ String dpid = "00:00:00:00:00:22";
+ Short portNum = 4;
+ IPortObject port1 = ope.newPort(dpid, portNum);
+ flowEntry.setOutPort(port1);
+ IPortObject port2 = flowEntry.getOutPort();
+ assertEquals(port2, port1);
+ }
+}
diff --git a/src/test/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjectsIFlowPathTest.java b/src/test/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjectsIFlowPathTest.java
new file mode 100644
index 0000000..9765af8
--- /dev/null
+++ b/src/test/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjectsIFlowPathTest.java
@@ -0,0 +1,383 @@
+package net.onrc.onos.ofcontroller.core;
+
+import static org.junit.Assert.*;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import net.onrc.onos.graph.GraphDBConnection;
+import net.onrc.onos.graph.GraphDBOperation;
+import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowEntry;
+import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowPath;
+import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject;
+import net.onrc.onos.ofcontroller.core.internal.SwitchStorageImpl;
+import net.onrc.onos.ofcontroller.core.internal.TestDatabaseManager;
+import org.easymock.EasyMock;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.api.easymock.PowerMock;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.slf4j.LoggerFactory;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import com.thinkaurelius.titan.core.TitanFactory;
+import com.thinkaurelius.titan.core.TitanGraph;
+
+//Add Powermock preparation
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({TitanFactory.class, GraphDBConnection.class, GraphDBOperation.class, SwitchStorageImpl.class})
+public class INetMapTopologyObjectsIFlowPathTest {
+
+ //The test network is ./titan/schema/test-network.xml
+
+ protected static org.slf4j.Logger log = LoggerFactory.getLogger(SwitchStorageImpl.class);
+
+ String conf;
+ private GraphDBConnection conn = null;
+ private GraphDBOperation ope = null;
+ private TitanGraph titanGraph = null;
+ private IFlowPath flowPath = null;
+ private IFlowEntry flowEntry = null;
+
+ @Before
+ public void setUp() throws Exception {
+ conf = "/dummy/path/to/db";
+
+ // Make mock cassandra DB
+ // Replace TitanFactory.open() to return mock DB
+ TestDatabaseManager.deleteTestDatabase();
+ titanGraph = TestDatabaseManager.getTestDatabase();
+ //TestDatabaseManager.populateTestData(titanGraph);
+ PowerMock.mockStatic(TitanFactory.class);
+ EasyMock.expect(TitanFactory.open((String)EasyMock.anyObject())).andReturn(titanGraph);
+ PowerMock.replay(TitanFactory.class);
+
+ conn = GraphDBConnection.getInstance(conf);
+ ope = new GraphDBOperation(conn);
+
+ flowPath = ope.newFlowPath();
+ flowEntry = ope.newFlowEntry();
+ flowEntry.setState("zz");
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ titanGraph.shutdown();
+ TestDatabaseManager.deleteTestDatabase();
+ }
+
+ /**
+ * Desc:
+ * Test method for get and set FlowId method.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set the flow id.
+ * 2. Should get the flow id.
+ */
+ @Test
+ public void testSetGetFlowId() {
+ String flowId = "xx";
+ flowPath.setFlowId(flowId);
+ assertEquals(flowPath.getFlowId(), flowId);
+ }
+
+ /**
+ * Desc:
+ * Test method for get and set InstallerId method.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set the installer id.
+ * 2. Should get the installer id.
+ */
+ @Test
+ public void testSetGetInstallerId() {
+ String flowId = "xx";
+ String installerId = "yy";
+ flowPath.setFlowId(flowId);
+ flowPath.setInstallerId(installerId);
+ assertEquals(flowPath.getInstallerId(), installerId);
+ }
+
+ /**
+ * Desc:
+ * Test method for get and set SourceSwitch method.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set the source switch.
+ * 2. Should get the source switch.
+ */
+ @Test
+ public void testSetGetSourceSwitch() {
+ String flowId = "xx";
+ String sourceSwitch = "aa";
+ flowPath.setFlowId(flowId);
+ flowPath.setSrcSwitch(sourceSwitch);
+ assertEquals(flowPath.getSrcSwitch(), sourceSwitch);
+ }
+
+ /**
+ * Desc:
+ * Test method for get and set SourcePort method.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set the source port.
+ * 2. Should get the source port.
+ */
+ @Test
+ public void testSetGetSourcePort() {
+ String flowId = "xx";
+ Short sourcePort = 1;
+ flowPath.setFlowId(flowId);
+ flowPath.setSrcPort(sourcePort);
+ assertEquals(flowPath.getSrcPort(), sourcePort);
+ }
+
+ /**
+ * Desc:
+ * Test method for get and set DestSwitch method.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set the dest switch.
+ * 2. Should get the dest switch.
+ */
+ @Test
+ public void testSetGetDestSwitch() {
+ String flowId = "xx";
+ String destSwitch = "bb";
+ flowPath.setFlowId(flowId);
+ flowPath.setDstSwitch(destSwitch);
+ assertEquals(flowPath.getDstSwitch(), destSwitch);
+ }
+
+ /**
+ * Desc:
+ * Test method for get and set DestPort method.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set the source dest port.
+ * 2. Should get the source dest port.
+ */
+ @Test
+ public void testSetGetDstPort() {
+ String flowId = "xx";
+ Short dstPort = 2;
+ flowPath.setFlowId(flowId);
+ flowPath.setDstPort(dstPort);
+ assertEquals(flowPath.getDstPort(), dstPort);
+ }
+
+ /**
+ * Desc:
+ * Test method for get and set DataPathSummary method.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set the data path summary.
+ * 2. Should get the data path summary.
+ */
+ @Test
+ public void testSetGetDataPathSummary() {
+ String flowId = "xx";
+ String dataPathSummary = "yy";
+ flowPath.setFlowId(flowId);
+ flowPath.setInstallerId(dataPathSummary);
+ assertEquals(flowPath.getInstallerId(), dataPathSummary);
+ }
+
+ public boolean testIFlowEntry(IFlowPath fp, IFlowEntry fe)
+ {
+ ArrayList<IFlowEntry> flowEntryList = new ArrayList<IFlowEntry>();
+ for(IFlowEntry inFlowEntry : fp.getFlowEntries())
+ {
+ flowEntryList.add(inFlowEntry);
+ }
+ return flowEntryList.contains(fe);
+ }
+
+ /**
+ * Desc:
+ * Test method for addFlowEntry and getFlorEntries method.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should add the FlowEntry.
+ * 2. Should get the FlowEntries. It is tested in the testIFlowEntry method.
+ */
+ @Test
+ public void testAddFlowEntryAndGetFlowEntries() {
+ String flowId = "xx";
+ flowPath.setFlowId(flowId);
+ flowPath.addFlowEntry(flowEntry);
+ IFlowEntry flowEntry2 = ope.newFlowEntry();
+ flowPath.addFlowEntry(flowEntry2);
+ assertTrue(testIFlowEntry(flowPath, flowEntry));
+ assertTrue(testIFlowEntry(flowPath, flowEntry2));
+ }
+
+ /**
+ * Desc:
+ * Test method for remove FlowEntry.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should remove FlowEntry.
+ */
+ @Test
+ public void testRemoveFlowEntry() {
+ String flowId = "xx";
+ flowPath.setFlowId(flowId);
+ flowPath.addFlowEntry(flowEntry);
+ flowPath.removeFlowEntry(flowEntry);
+ assertTrue(!testIFlowEntry(flowPath, flowEntry));
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get MatchEthernetFrameType
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set MatchEthernetFrameType.
+ * 2. Should get MatchEthernetFrameType.
+ */
+ @Test
+ public void testSetGetMatchEthernetFrameType() {
+ String flowId = "xx";
+ Short matchEthernetFrameTypeShort = 1;
+ flowPath.setFlowId(flowId);
+ flowPath.setMatchEthernetFrameType(matchEthernetFrameTypeShort);
+ assertEquals(flowPath.getMatchEthernetFrameType(), matchEthernetFrameTypeShort);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get MatchSrcMac
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set MatchSrcMac.
+ * 2. Should get MatchSrcMac.
+ */
+ @Test
+ public void testSetGetMatchSrcMac() {
+ String flowId = "xx";
+ String matchSrcMac = "00:00:00:00:00:11";
+ flowPath.setFlowId(flowId);
+ flowPath.setMatchSrcMac(matchSrcMac);
+ assertEquals(flowPath.getMatchSrcMac(), matchSrcMac);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get MatchDstMac.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set MatchDstMac.
+ * 2. Should get MatchDstMac.
+ */
+ @Test
+ public void testSetGetMatchDstMac() {
+ String flowId = "xx";
+ String matchDstMac = "00:00:00:00:00:11";
+ flowPath.setFlowId(flowId);
+ flowPath.setMatchDstMac(matchDstMac);
+ assertEquals(flowPath.getMatchDstMac(), matchDstMac);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get SrcIPv4Net.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set SrcIPv4Net.
+ * 2. Should get SrcIPv4Net.
+ */
+ @Test
+ public void testSetGetMatchSrcIPv4Net() {
+ String flowId = "xx";
+ String ip = "192.168.0.1";
+ flowPath.setFlowId(flowId);
+ flowPath.setMatchSrcIPv4Net(ip);
+ assertEquals(flowPath.getMatchSrcIPv4Net(), ip);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get DstIPv4Net.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set DstIPv4Net.
+ * 2. Should get DstIPv4Net.
+ */
+ @Test
+ public void testSetGetMatchDstIPv4Net() {
+ String flowId = "xx";
+ String ip = "192.168.0.1";
+ flowPath.setFlowId(flowId);
+ flowPath.setMatchDstIPv4Net(ip);
+ assertEquals(flowPath.getMatchDstIPv4Net(), ip);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get UserState.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set UserState.
+ * 2. Should get UserState.
+ */
+ @Test
+ public void testSetGetUserState() {
+ String flowId = "xx";
+ String userStatus = "Good";
+ flowPath.setFlowId(flowId);
+ flowPath.setUserState(userStatus);
+ assertEquals(flowPath.getUserState(), userStatus);
+ }
+
+ /**
+ * Desc:
+ * Test method for get Switches.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should get switches.
+ */
+ @Test
+ public void testGetSwitches() {
+ String flowId = "xx";
+ String dpid = "1";
+ flowPath.setFlowId(flowId);
+ ISwitchObject sw = ope.newSwitch(dpid);
+ flowEntry.setSwitch(sw);
+ flowPath.addFlowEntry(flowEntry);
+
+ HashMap<String, ISwitchObject> swList = new HashMap<String, ISwitchObject>();
+ for(ISwitchObject insw : flowPath.getSwitches()){
+ swList.put(sw.getDPID(), insw);
+ }
+
+ assertTrue(swList.containsKey(dpid));
+ }
+
+ //TODO Dont know how to set the state property.
+ @Test
+ public void testGetState() {
+ String status = null;
+ assertEquals(flowPath.getState(), status);
+ }
+
+
+}
diff --git a/src/test/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjectsIPortObjectTest.java b/src/test/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjectsIPortObjectTest.java
new file mode 100644
index 0000000..2ddab3d
--- /dev/null
+++ b/src/test/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjectsIPortObjectTest.java
@@ -0,0 +1,359 @@
+package net.onrc.onos.ofcontroller.core;
+
+import static org.junit.Assert.*;
+
+import net.onrc.onos.graph.GraphDBConnection;
+import net.onrc.onos.graph.GraphDBOperation;
+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.internal.SwitchStorageImpl;
+import net.onrc.onos.ofcontroller.core.internal.TestDatabaseManager;
+import net.onrc.onos.ofcontroller.flowmanager.FlowManager;
+import net.onrc.onos.ofcontroller.util.FlowId;
+import net.onrc.onos.ofcontroller.util.FlowPath;
+
+import org.easymock.EasyMock;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.openflow.protocol.OFPhysicalPort.OFPortState;
+import org.powermock.api.easymock.PowerMock;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.slf4j.LoggerFactory;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import com.thinkaurelius.titan.core.TitanFactory;
+import com.thinkaurelius.titan.core.TitanGraph;
+import java.util.ArrayList;
+import java.util.HashMap;
+
+//Add Powermock preparation
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({TitanFactory.class, GraphDBConnection.class, GraphDBOperation.class, SwitchStorageImpl.class})
+public class INetMapTopologyObjectsIPortObjectTest {
+
+ //The test network is ./titan/schema/test-network.xml
+
+ protected static org.slf4j.Logger log = LoggerFactory.getLogger(SwitchStorageImpl.class);
+
+ String conf;
+ private GraphDBConnection conn = null;
+ private GraphDBOperation ope = null;
+ private TitanGraph titanGraph = null;
+
+ private ISwitchObject swObj;
+ private IPortObject portObj;
+ private IPortObject portObj2;
+ String dpid;
+ Short number;
+ Short number2;
+
+ private ISwitchObject swObjParty;
+ private IPortObject portObjParty1;
+ private IPortObject portObjParty2;
+ String dpidParty;
+ Short numberParty1;
+ Short numberParty2;
+
+
+ @Before
+ public void setUp() throws Exception {
+ conf = "/dummy/path/to/db";
+
+ // Make mock cassandra DB
+ // Replace TitanFactory.open() to return mock DB
+ TestDatabaseManager.deleteTestDatabase();
+ titanGraph = TestDatabaseManager.getTestDatabase();
+ //TestDatabaseManager.populateTestData(titanGraph);
+ PowerMock.mockStatic(TitanFactory.class);
+ EasyMock.expect(TitanFactory.open((String)EasyMock.anyObject())).andReturn(titanGraph);
+ PowerMock.replay(TitanFactory.class);
+
+ conn = GraphDBConnection.getInstance(conf);
+ ope = new GraphDBOperation(conn);
+
+ dpid = "00:00:00:00:00:00:0a:07";
+ number = 1;
+ number2 = 2;
+ swObj = ope.newSwitch(dpid);
+ portObj = ope.newPort(dpid, number);
+ portObj2 = ope.newPort(dpid, number2);
+
+ swObj.addPort(portObj);
+ swObj.addPort(portObj2);
+
+ dpidParty = "00:00:00:00:00:00:0a:08";
+ numberParty1 = 1;
+ numberParty2 = 2;
+ swObjParty = ope.newSwitch(dpidParty);
+ portObjParty1 = ope.newPort(dpidParty, numberParty1);
+ portObjParty2 = ope.newPort(dpidParty, numberParty2);
+ swObjParty.addPort(portObjParty1);
+ swObjParty.addPort(portObjParty2);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ titanGraph.shutdown();
+ TestDatabaseManager.deleteTestDatabase();
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get port number property.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set the port number.
+ * 2. Should get the port number.
+ */
+ @Test
+ public void testSetGetNumber() {
+ assertEquals(portObj.getNumber(), number);
+ Short testedNumber = 4;
+ portObj.setNumber(testedNumber);
+ assertEquals(portObj.getNumber(), testedNumber);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get port id property.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set the port id.
+ * 2. Should get the port id.
+ */
+ @Test
+ public void testSetGetPortId() {
+ String portId = "test1";
+ portObj.setPortId(portId);
+ assertEquals(portObj.getPortId(), portId);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get port desc property.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set the port desc.
+ * 2. Should get the port desc.
+ */
+ @Test
+ public void testSetGetDesc() {
+ String testedDesc = "port 4 at ATL Switch";
+ portObj.setDesc(testedDesc);
+ assertEquals(portObj.getDesc(), testedDesc);
+ }
+
+
+ /**
+ * Desc:
+ * Test method for set and get port status property.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set the port status.
+ * 2. Should get the port status.
+ */
+ @Test
+ public void testSetGetPortState() {
+ Integer portState = OFPortState.OFPPS_STP_FORWARD.getValue();
+ portObj.setPortState(portState);
+ assertEquals(portObj.getPortState(), portState);
+ }
+
+ /**
+ * Desc:
+ * Test method for get switch object.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should get the switch status.
+ */
+ @Test
+ public void testGetSwitch() {
+ ISwitchObject sw = portObj.getSwitch();
+ assertEquals(sw.getDPID(), dpid);
+ }
+
+ private boolean checkIDeviceObject(IPortObject IportObj, String mac)
+ {
+ HashMap<String, IDeviceObject> devList = new HashMap<String, IDeviceObject>();
+ for(IDeviceObject IdevObj : IportObj.getDevices())
+ {
+ devList.put(IdevObj.getMACAddress(), IdevObj);
+ }
+ return devList.containsKey(mac);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and remove device object.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set the device object.
+ * 2. SHould remove the device object.
+ */
+ @Test
+ public void testSetAndRemoveDevice() {
+ IDeviceObject devObj = ope.newDevice();
+ String devMac = "00:00:00:00:00:11";
+ devObj.setMACAddress(devMac);
+
+ boolean b = checkIDeviceObject(portObj, devMac);
+ assertTrue(!b);
+ portObj.setDevice(devObj);
+ boolean b2 = checkIDeviceObject(portObj, devMac);
+ assertTrue(b2);
+
+ portObj.removeDevice(devObj);
+ boolean b3 = checkIDeviceObject(portObj, devMac);
+ assertTrue(!b3);
+
+ }
+
+ /**
+ * Desc:
+ * Test method for get devices object.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should get the device objects.
+ */
+ @Test
+ public void testGetDevices() {
+ IDeviceObject devObj = ope.newDevice();
+ String devMac = "58:55:ca:c4:1b:a0";
+ devObj.setMACAddress(devMac);
+
+ portObj.setDevice(devObj);
+ boolean b = checkIDeviceObject(portObj, devMac);
+ assertTrue(b);
+ }
+
+ /**
+ * Desc:
+ * Test method for set, get and remove linked port.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set the linked objects.
+ * 2. Should get the linked objects.
+ * 3. SHould remove the liked objects.
+ */
+ @Test
+ public void testSetGetRemoveLinkedPorts() {
+ String dpidParty = "00:00:00:00:00:00:00:08";
+ ISwitchObject swParty = ope.newSwitch(dpidParty);
+ Short poShort = 1;
+ IPortObject poParty = ope.newPort(dpidParty, poShort);
+ swParty.addPort(poParty);
+
+ portObj.setLinkPort(poParty);
+
+ ArrayList<IPortObject> iPortList = new ArrayList<IPortObject>();
+ for(IPortObject port : portObj.getLinkedPorts()) {
+ iPortList.add(port);
+ }
+ assertTrue(iPortList.contains(poParty));
+
+ portObj.removeLink(poParty);
+
+ ArrayList<IPortObject> iPortList2 = new ArrayList<IPortObject>();
+ for(IPortObject port : portObj.getLinkedPorts()) {
+ iPortList2.add(port);
+ }
+
+ assertTrue(!iPortList2.contains(poParty));
+ }
+
+ /**
+ * Desc:
+ * Test method for get inbound flowEntry
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should get the inbound flowEntry.
+ */
+ @Test
+ public void testGetInFlowEntries() {
+
+ portObj.setLinkPort(portObj2);
+
+ IFlowPath flowPathObj = ope.newFlowPath();
+
+ String flowEId = "1";
+ IFlowEntry flowEntryObj = ope.newFlowEntry();
+ flowEntryObj.setFlowEntryId(flowEId);
+ flowEntryObj.setInPort(portObj);
+ flowEntryObj.setOutPort(portObj2);
+ flowEntryObj.setSwitch(swObj);
+ flowEntryObj.setFlow(flowPathObj);
+
+ String flowEId2 = "2";
+ IFlowEntry flowEntryObj2 = ope.newFlowEntry();
+ flowEntryObj2.setFlowEntryId(flowEId2);
+ flowEntryObj2.setInPort(portObjParty1);
+ flowEntryObj2.setOutPort(portObjParty2);
+ flowEntryObj.setSwitch(swObjParty);
+ flowEntryObj2.setFlow(flowPathObj);
+
+ HashMap<String, IFlowEntry> flowEntryList = new HashMap<String, IFlowEntry>();
+ for(IFlowEntry flowEnt : portObj.getInFlowEntries())
+ {
+ flowEntryList.put(flowEnt.getFlowEntryId(), flowEnt);
+ }
+
+ assertTrue(flowEntryList.containsValue(flowEntryObj));
+
+ }
+
+ /**
+ * Desc:
+ * Test method for get outbound flowEntry
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should get the outbound flowEntry.
+ */
+ @Test
+ public void testGetOutFlowEntries() {
+
+ portObj.setLinkPort(portObj2);
+
+ IFlowPath flowPathObj = ope.newFlowPath();
+
+ String flowEId = "1";
+ IFlowEntry flowEntryObj = ope.newFlowEntry();
+ flowEntryObj.setFlowEntryId(flowEId);
+ flowEntryObj.setInPort(portObj);
+ flowEntryObj.setOutPort(portObj2);
+ flowEntryObj.setSwitch(swObj);
+ flowEntryObj.setFlow(flowPathObj);
+
+ String flowEId2 = "2";
+ IFlowEntry flowEntryObj2 = ope.newFlowEntry();
+ flowEntryObj2.setFlowEntryId(flowEId2);
+ flowEntryObj2.setInPort(portObjParty1);
+ flowEntryObj2.setOutPort(portObjParty2);
+ flowEntryObj.setSwitch(swObjParty);
+ flowEntryObj2.setFlow(flowPathObj);
+
+ HashMap<String, IFlowEntry> flowEntryList = new HashMap<String, IFlowEntry>();
+ for(IFlowEntry flowEnt : portObj2.getOutFlowEntries())
+ {
+ flowEntryList.put(flowEnt.getFlowEntryId(), flowEnt);
+ }
+
+ assertTrue(flowEntryList.containsValue(flowEntryObj));
+
+ }
+
+}
diff --git a/src/test/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjectsISwitchObjectTest.java b/src/test/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjectsISwitchObjectTest.java
new file mode 100644
index 0000000..c4dca4b
--- /dev/null
+++ b/src/test/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjectsISwitchObjectTest.java
@@ -0,0 +1,285 @@
+package net.onrc.onos.ofcontroller.core;
+
+import static org.junit.Assert.*;
+
+import java.util.HashMap;
+
+import net.onrc.onos.graph.GraphDBConnection;
+import net.onrc.onos.graph.GraphDBOperation;
+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.internal.SwitchStorageImpl;
+import net.onrc.onos.ofcontroller.core.internal.TestDatabaseManager;
+import org.easymock.EasyMock;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.api.easymock.PowerMock;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.slf4j.LoggerFactory;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import com.thinkaurelius.titan.core.TitanFactory;
+import com.thinkaurelius.titan.core.TitanGraph;
+
+//Add Powermock preparation
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({TitanFactory.class, GraphDBConnection.class, GraphDBOperation.class, SwitchStorageImpl.class})
+public class INetMapTopologyObjectsISwitchObjectTest {
+
+ //The test network is ./titan/schema/test-network.xml
+
+ protected static org.slf4j.Logger log = LoggerFactory.getLogger(SwitchStorageImpl.class);
+
+ String conf;
+ private GraphDBConnection conn = null;
+ private GraphDBOperation ope = null;
+ private TitanGraph titanGraph = null;
+
+ @Before
+ public void setUp() throws Exception {
+ conf = "/dummy/path/to/db";
+
+ // Make mock cassandra DB
+ // Replace TitanFactory.open() to return mock DB
+ TestDatabaseManager.deleteTestDatabase();
+ titanGraph = TestDatabaseManager.getTestDatabase();
+ //TestDatabaseManager.populateTestData(titanGraph);
+ PowerMock.mockStatic(TitanFactory.class);
+ EasyMock.expect(TitanFactory.open((String)EasyMock.anyObject())).andReturn(titanGraph);
+ PowerMock.replay(TitanFactory.class);
+
+ conn = GraphDBConnection.getInstance(conf);
+ ope = new GraphDBOperation(conn);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ titanGraph.shutdown();
+ TestDatabaseManager.deleteTestDatabase();
+ }
+
+ /**
+ * Desc:
+ * Test method for get and set state method.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set the status of the switch.
+ * 2. Should get the status of the switch.
+ */
+ @Test
+ public void testSetGetState() {
+ String dpid = "00:00:00:00:00:00:0a:07";
+ String state = "ACTIVE";
+ ISwitchObject swObj = ope.newSwitch(dpid);
+ swObj.setState(state);
+ assertEquals(swObj.getState(), state);
+ }
+
+ /**
+ * Desc:
+ * Test method for get and set Type method.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set the Type of the switch.
+ * 2. Should get the Type of the switch.
+ */
+ @Test
+ public void testSetGetType() {
+ String dpid = "00:00:00:00:00:00:0a:07";
+ String type = "Switch";
+ ISwitchObject swObj = ope.newSwitch(dpid);
+ swObj.setType("Switch");
+ assertEquals(swObj.getType(), type);
+ }
+
+ /**
+ * Desc:
+ * Test method for getDPID method.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should get the dpid of the switch.
+ */
+ @Test
+ public void testGetDPID() {
+ String dpid = "00:00:00:00:00:00:0a:07";
+ ISwitchObject swObj = ope.newSwitch(dpid);
+
+ assertEquals(swObj.getDPID(), dpid);
+ }
+
+ /**
+ * Desc:
+ * Test method for setDPID method.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set the dpid of the switch.
+ */
+ @Test
+ public void testSetDPID() {
+ String dpid = "00:00:00:00:00:00:0a:07";
+ String dpid2 = "00:00:00:00:00:00:0a:08";
+ ISwitchObject obj = ope.newSwitch(dpid);
+ assertEquals(obj.getDPID(), dpid);
+
+ obj.setDPID(dpid2);
+ assertEquals(obj.getDPID(), dpid2);
+ }
+
+ /**
+ * Desc:
+ * Test method for getPorts method.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should get all of ports taken by the switch.
+ */
+ @Test
+ public void testGetPorts() {
+ String dpid = "00:00:00:00:00:00:0a:07";
+ Short portNumber = 1;
+ int testSwitchPortNumber = 1;
+ ISwitchObject swObj = ope.newSwitch(dpid);
+ IPortObject portObj = ope.newPort(dpid, portNumber);
+
+ swObj.addPort(portObj);
+ int i = 0;
+ for(IPortObject port : swObj.getPorts()){
+ i++;
+ }
+ assertEquals(testSwitchPortNumber, 1);
+ }
+
+ /**
+ * Desc:
+ * Test method for add and getPort method.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should add the port.
+ * 1. Should get the port.
+ */
+ @Test
+ public void testGetPort() {
+ String dpid = "00:00:00:00:00:00:0a:07";
+ Short portNumber = 1;
+ ISwitchObject swObj = ope.newSwitch(dpid);
+ IPortObject portObj = ope.newPort(dpid, portNumber);
+
+ swObj.addPort(portObj);
+ IPortObject portObj2 = swObj.getPort(portNumber);
+ assertEquals(portObj, portObj2);
+ }
+
+ /**
+ * Desc:
+ * Test method for add and removePort method.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should add a port to the switch.
+ * 1. Should remove a port from the switch.
+ */
+ @Test
+ public void testAddRemovePorts() {
+ String dpid = "00:00:00:00:00:00:0a:07";
+ Short portNum = 1;
+ ISwitchObject swObj = ope.newSwitch(dpid);
+ IPortObject portObj = ope.newPort(dpid, portNum);
+ swObj.addPort(portObj);
+
+ IPortObject portObj2 = swObj.getPort(portNum);
+ assertEquals(portObj2, portObj);
+ swObj.removePort(portObj);
+ assertNull(swObj.getPort(portNum));
+ }
+
+ /**
+ * Desc:
+ * Test method for getDevices method.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should get all devices attached to the switch.
+ */
+ @Test
+ public void testGetDevices() {
+ String dpid = "00:00:00:00:00:00:0a:07";
+ Short portNum = 1;
+ String devMac = "00:00:00:00:00:11";
+ int numOfDev = 1;
+
+ ISwitchObject swObj = ope.newSwitch(dpid);
+ IPortObject portObj = ope.newPort(dpid, portNum);
+ IDeviceObject devObj = ope.newDevice();
+ devObj.setMACAddress(devMac);
+ swObj.addPort(portObj);
+ portObj.setDevice(devObj);
+
+ int i = 0;
+ for(IDeviceObject dev : swObj.getDevices()){
+ i++;
+ }
+ assertEquals(i, numOfDev);
+ }
+
+ /**
+ * Desc:
+ * Test method for getFlowEntries method.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should get all flowEntries attached to the switch.
+ */
+ @Test
+ public void testGetFlowEntries() {
+ String dpid = "00:00:00:00:00:00:0a:07";
+ Short number = 1;
+ Short number2 = 2;
+ Short number3 = 3;
+ ISwitchObject swObj = ope.newSwitch(dpid);
+ IPortObject portObj = ope.newPort(dpid, number);
+ IPortObject portObj2 = ope.newPort(dpid, number2);
+ IPortObject portObj3 = ope.newPort(dpid, number3);
+
+ swObj.addPort(portObj);
+ swObj.addPort(portObj2);
+ swObj.addPort(portObj3);
+
+ IFlowPath flowPathObj = ope.newFlowPath();
+
+ String flowEId = "1";
+ IFlowEntry flowEntryObj = ope.newFlowEntry();
+ flowEntryObj.setFlowEntryId(flowEId);
+ flowEntryObj.setInPort(portObj);
+ flowEntryObj.setOutPort(portObj2);
+ flowEntryObj.setSwitch(swObj);
+ flowEntryObj.setFlow(flowPathObj);
+
+ String flowEId2 = "2";
+ IFlowEntry flowEntryObj2 = ope.newFlowEntry();
+ flowEntryObj2.setFlowEntryId(flowEId2);
+ flowEntryObj2.setInPort(portObj);
+ flowEntryObj2.setOutPort(portObj3);
+ flowEntryObj2.setSwitch(swObj);
+ flowEntryObj2.setFlow(flowPathObj);
+
+ HashMap<String, IFlowEntry> flowEntryList = new HashMap<String, IFlowEntry>();
+ for(IFlowEntry flowEnt : swObj.getFlowEntries())
+ {
+ flowEntryList.put(flowEnt.getFlowEntryId(), flowEnt);
+ }
+
+ assertTrue(flowEntryList.containsValue(flowEntryObj));
+ assertTrue(flowEntryList.containsValue(flowEntryObj2));
+ }
+
+}
diff --git a/src/test/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImplTest.java b/src/test/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImplTest.java
index d2a6712..4956136 100644
--- a/src/test/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImplTest.java
+++ b/src/test/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImplTest.java
@@ -80,7 +80,6 @@
* Expect:
* Call SwitchStorageImpl.addSwitch func with proper properties.
*/
- @Ignore
@Test
public void testAddSwitch() {
String dpid = "00:00:00:00:00:00:0a:07";
@@ -144,7 +143,6 @@
* Expect:
* Write the status as info log.
*/
- //@Ignore
@Test
public void testAddSwitchAbnormal() {
String dpid = "00:00:00:00:00:00:0a:07";
@@ -152,6 +150,7 @@
//Expectation of mock operation.
expect(mockOpe.searchSwitch(dpid)).andReturn(null);
expect(mockOpe.newSwitch(dpid)).andReturn(null);
+ mockOpe.rollback();
mockOpe.close();
replay(mockOpe);
@@ -163,7 +162,7 @@
* Desc:
* Test method for addSwitch method.
* Condition:
- * Tthrow runtimeException.
+ * Throw runtimeException.
* Expect:
* The rollback method is called.
*/
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..5b0a5b1 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,11 +56,22 @@
//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());
+
+ 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 +84,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/start-cassandra.sh b/start-cassandra.sh
index d4d722c..426fa60 100755
--- a/start-cassandra.sh
+++ b/start-cassandra.sh
@@ -3,8 +3,8 @@
# Set paths
ONOS_HOME=`dirname $0`
CASSANDRA_DIR=${HOME}/apache-cassandra-1.2.4
-LOGDIR=${HOME}/ONOS/onos-logs
-CASSANDRA_LOG=$LOGDIR/cassandara.`hostname`.log
+LOGDIR=${ONOS_HOME}/ONOS/onos-logs
+CASSANDRA_LOG=${LOGDIR}/cassandara.`hostname`.log
function lotate {
logfile=$1
@@ -30,10 +30,11 @@
# Run cassandra
echo "Starting cassandra"
- echo "[31;48m[WARNING] This script copies conf/cassandra.yam to $CASSANDRA_DIR/conf/cassandra.yaml (overwrites)[0m"
- echo "[31;48moriginal cassandra.yaml was backed up as cassandra.yaml.backup[0m"
- cp $CASSANDRA_DIR/conf/cassandra.yaml $CASSANDRA_DIR/conf/cassandra.yaml.backup
- cp ${ONOS_HOME}/conf/cassandra.yaml $CASSANDRA_DIR/conf
+# echo "[31;48m[WARNING] This script copies conf/cassandra.yaml to $CASSANDRA_DIR/conf/cassandra.yaml (overwrites)[0m"
+# echo "[31;48moriginal cassandra.yaml was backed up as cassandra.yaml.backup[0m"
+# id=`hostid`
+# cp ${CASSANDRA_DIR}/conf/cassandra.yaml $CASSANDRA_DIR/conf/cassandra.yaml.backup
+# cp ${ONOS_HOME}/conf/cassandra.yaml.${id} $CASSANDRA_DIR/conf
$CASSANDRA_DIR/bin/cassandra > $CASSANDRA_LOG 2>&1
}
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 667fd31..c356c87 100755
--- a/start-onos.sh
+++ b/start-onos.sh
@@ -4,6 +4,7 @@
if [ -z "${ONOS_HOME}" ]; then
ONOS_HOME=`dirname $0`
fi
+
ONOS_LOGBACK="${ONOS_HOME}/logback.xml"
LOGDIR=${ONOS_HOME}/onos-logs
ONOS_LOG="${LOGDIR}/onos.`hostname`.log"
@@ -16,17 +17,24 @@
#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"
if [ -z "${MVN}" ]; then
- MVN="mvn"
+ MVN="mvn -o"
fi
#<logger name="net.floodlightcontroller.linkdiscovery.internal" level="TRACE"/>
@@ -89,7 +97,8 @@
# XXX : MVN has to run at the project top dir
cd ${ONOS_HOME}
- ${MVN} exec:exec -Dexec.executable="java" -Dexec.args="${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -cp %classpath ${MAIN_CLASS} -cf ${ONOS_HOME}/conf/onos.properties" > ${LOGDIR}/onos.stdout 2>${LOGDIR}/onos.stderr &
+ echo "${MVN} exec:exec -Dexec.executable=\"java\" -Dexec.args=\"${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -cp %classpath ${MAIN_CLASS} -cf ${ONOS_HOME}/conf/onos.properties\""
+ ${MVN} exec:exec -Dexec.executable="java" -Dexec.args="${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -cp %classpath ${MAIN_CLASS} -cf ${ONOS_HOME}/conf/onos.properties" > ${LOGDIR}/onos.`hostname`.stdout 2>${LOGDIR}/onos.`hostname`.stderr &
echo "Waiting for ONOS to start..."
COUNT=0
@@ -117,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/start-zk.sh b/start-zk.sh
index 206370f..0853a96 100755
--- a/start-zk.sh
+++ b/start-zk.sh
@@ -3,18 +3,19 @@
ONOS_HOME=`dirname $0`
ZK_DIR=${HOME}/zookeeper-3.4.5
-ZK_CONF=${ONOS_HOME}/conf/zoo.cfg
+#ZK_CONF=${ONOS_HOME}/conf/zoo.cfg
function start {
# Run Zookeeper with our configuration
echo "Starting Zookeeper"
- echo "[31;48m[WARNING] This script copies conf/zoo.cfg to $ZK_DIR/conf/zoo.cfg (overwrites)[0m"
- echo "[31;48moriginal zoo.cfg was backed up as zoo.cfg.backup[0m"
- if [ $ZK_DIR/conf/zoo.cfg ]; then
- cp $ZK_DIR/conf/zoo.cfg $ZK_DIR/conf/zoo.cfg.backup
- fi
- cp $ZK_CONF $ZK_DIR/conf
- echo "cp $ZK_CONF $ZK_DIR/conf"
+# echo "[31;48m[WARNING] This script copies conf/zoo.cfg to $ZK_DIR/conf/zoo.cfg (overwrites)[0m"
+# echo "[31;48moriginal zoo.cfg was backed up as zoo.cfg.backup[0m"
+# if [ $ZK_DIR/conf/zoo.cfg ]; then
+# cp $ZK_DIR/conf/zoo.cfg $ZK_DIR/conf/zoo.cfg.backup
+# fi
+# hostid > /var/lib/zookeeper/myid
+# cp $ZK_CONF $ZK_DIR/conf
+# echo "cp $ZK_CONF $ZK_DIR/conf"
$ZK_DIR/bin/zkServer.sh start
}
@@ -29,7 +30,7 @@
done
}
function status {
- $ZK_DIR/bin/zkServer.sh status $ZK_CONF
+ $ZK_DIR/bin/zkServer.sh status
}
case "$1" in
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>