Merge branch 'master' of https://github.com/OPENNETWORKINGLAB/ONOS
diff --git a/README.md b/README.md
index 08878d4..b71b9aa 100644
--- a/README.md
+++ b/README.md
@@ -41,8 +41,9 @@
Edit file (ONOS-INSTALL-DIR)/start-cassandra.sh and set variable
"CASSANDRA_DIR" to point to the Cassandra directory.
-Running ONOS
-------------
+Running ONOS with Cassandra as a separate process
+-------------------------------------------------
+[See below for information how to run ONOS with Embedded Cassandra]
1. Start Zookeeper
diff --git a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowManager.java b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowManager.java
index a072882..bca9ef7 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowManager.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowManager.java
@@ -97,11 +97,6 @@
private static String measurementFlowIdStr = "0x186a0"; // 100000
private long modifiedMeasurementFlowTime = 0;
//
- private LinkedList<FlowPath> measurementStoredPaths = new LinkedList<FlowPath>();
- private long measurementStartTimeProcessingPaths = 0;
- private long measurementEndTimeProcessingPaths = 0;
- Map<Long, ?> measurementShortestPathTopo = null;
- private String measurementPerFlowStr = new String();
/** The logger. */
private static Logger log = LoggerFactory.getLogger(FlowManager.class);
@@ -2305,207 +2300,4 @@
//
return (installRemoteFlowEntry(flowPath, flowEntry));
}
-
- /**
- * Store a path flow for measurement purpose.
- *
- * NOTE: The Flow Path argument does NOT contain flow entries.
- * The Shortest Path is computed, and the corresponding Flow Entries
- * are stored in the Flow Path.
- *
- * @param flowPath the Flow Path with the endpoints and the match
- * conditions to store.
- * @return the stored shortest-path flow on success, otherwise null.
- */
- @Override
- public synchronized FlowPath measurementStorePathFlow(FlowPath flowPath) {
- //
- // Prepare the Shortest Path computation if the first Flow Path
- //
- if (measurementStoredPaths.isEmpty())
- measurementShortestPathTopo = topoRouteService.prepareShortestPathTopo();
-
- //
- // Compute the Shortest Path
- //
- DataPath dataPath =
- topoRouteService.getTopoShortestPath(measurementShortestPathTopo,
- flowPath.dataPath().srcPort(),
- flowPath.dataPath().dstPort());
- if (dataPath == null) {
- // We need the DataPath to populate the Network MAP
- dataPath = new DataPath();
- dataPath.setSrcPort(flowPath.dataPath().srcPort());
- dataPath.setDstPort(flowPath.dataPath().dstPort());
- }
- dataPath.applyFlowPathFlags(flowPath.flowPathFlags());
-
- //
- // Set the incoming port matching and the outgoing port output
- // actions for each flow entry.
- //
- for (FlowEntry flowEntry : dataPath.flowEntries()) {
- // Set the incoming port matching
- FlowEntryMatch flowEntryMatch = new FlowEntryMatch();
- flowEntry.setFlowEntryMatch(flowEntryMatch);
- flowEntryMatch.enableInPort(flowEntry.inPort());
-
- // Set the outgoing port output action
- FlowEntryActions flowEntryActions = flowEntry.flowEntryActions();
- FlowEntryAction flowEntryAction = new FlowEntryAction();
- flowEntryAction.setActionOutput(flowEntry.outPort());
- flowEntryActions.addAction(flowEntryAction);
- }
-
- //
- // Prepare the computed Flow Path
- //
- FlowPath computedFlowPath = new FlowPath();
- computedFlowPath.setFlowId(new FlowId(flowPath.flowId().value()));
- computedFlowPath.setInstallerId(new CallerId(flowPath.installerId().value()));
- computedFlowPath.setFlowPathFlags(new FlowPathFlags(flowPath.flowPathFlags().flags()));
- computedFlowPath.setDataPath(dataPath);
- computedFlowPath.setFlowEntryMatch(new FlowEntryMatch(flowPath.flowEntryMatch()));
-
- //
- // Add the computed Flow Path to the internal storage
- //
- measurementStoredPaths.add(computedFlowPath);
-
- log.debug("Measurement storing path {}",
- computedFlowPath.flowId().toString());
-
- return (computedFlowPath);
- }
-
- /**
- * Install path flows for measurement purpose.
- *
- * @param numThreads the number of threads to use to install the path
- * flows.
- * @return true on success, otherwise false.
- */
- @Override
- public boolean measurementInstallPaths(Integer numThreads) {
- // Create a copy of the Flow Paths to install
- final ConcurrentLinkedQueue<FlowPath> measurementProcessingPaths =
- new ConcurrentLinkedQueue<FlowPath>(measurementStoredPaths);
-
- /**
- * A Thread-wrapper class for executing the threads and collecting
- * the measurement data.
- */
- class MyThread extends Thread {
- public long[] execTime = new long[2000];
- public int samples = 0;
- public int threadId = -1;
- @Override
- public void run() {
- while (true) {
- FlowPath flowPath = measurementProcessingPaths.poll();
- if (flowPath == null)
- return;
- // Install the Flow Path
- FlowId flowId = new FlowId();
- String dataPathSummaryStr =
- flowPath.dataPath().dataPathSummary();
- long startTime = System.nanoTime();
- addFlow(flowPath, flowId, dataPathSummaryStr);
- long endTime = System.nanoTime();
- execTime[samples] = endTime - startTime;
- samples++;
- }
- }
- };
-
- List<MyThread> threads = new LinkedList<MyThread>();
-
- log.debug("Measurement Installing {} flows",
- measurementProcessingPaths.size());
-
- //
- // Create the threads to install the Flow Paths
- //
- for (int i = 0; i < numThreads; i++) {
- MyThread thread = new MyThread();
- thread.threadId = i;
- threads.add(thread);
- }
-
- //
- // Start processing
- //
- measurementEndTimeProcessingPaths = 0;
- measurementStartTimeProcessingPaths = System.nanoTime();
- for (Thread thread : threads) {
- thread.start();
- }
-
- // Wait for all threads to complete
- for (Thread thread : threads) {
- try {
- thread.join();
- } catch (InterruptedException e) {
- log.debug("Exception waiting for a thread to install a Flow Path: ", e);
- }
- }
-
- // Record the end of processing
- measurementEndTimeProcessingPaths = System.nanoTime();
-
- //
- // Prepare the string with measurement data per each Flow Path
- // installation.
- // The string is multiple lines: one line per Flow Path installation:
- // ThreadAndTimePerFlow <ThreadId> <TotalThreads> <Time(ns)>
- //
- measurementPerFlowStr = new String();
- String eol = System.getProperty("line.separator");
- for (MyThread thread : threads) {
- for (int i = 0; i < thread.samples; i++) {
- measurementPerFlowStr += "ThreadAndTimePerFlow " + thread.threadId + " " + numThreads + " " + thread.execTime[i] + eol;
- }
- }
-
- return true;
- }
-
- /**
- * Get the measurement time that took to install the path flows.
- *
- * @return the measurement time (in nanoseconds) it took to install
- * the path flows.
- */
- @Override
- public Long measurementGetInstallPathsTimeNsec() {
- return new Long(measurementEndTimeProcessingPaths -
- measurementStartTimeProcessingPaths);
- }
-
- /**
- * Get the measurement install time per Flow.
- *
- * @return a multi-line string with the following format per line:
- * ThreadAndTimePerFlow <ThreadId> <TotalThreads> <Time(ns)>
- */
- @Override
- public String measurementGetPerFlowInstallTime() {
- return new String(measurementPerFlowStr);
- }
-
- /**
- * Clear the path flows stored for measurement purpose.
- *
- * @return true on success, otherwise false.
- */
- @Override
- public boolean measurementClearAllPaths() {
- measurementStoredPaths.clear();
- topoRouteService.dropShortestPathTopo(measurementShortestPathTopo);
- measurementStartTimeProcessingPaths = 0;
- measurementEndTimeProcessingPaths = 0;
- measurementPerFlowStr = new String();
-
- return true;
- }
}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/IFlowService.java b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/IFlowService.java
index ba9cd1b..0fbb23c 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/IFlowService.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/IFlowService.java
@@ -115,47 +115,4 @@
* @return the added shortest-path flow on success, otherwise null.
*/
public FlowPath addAndMaintainShortestPathFlow(FlowPath flowPath);
-
- /**
- * Store a path flow for measurement purpose.
- *
- * NOTE: The Flow Path argument does NOT contain flow entries.
- *
- * @param flowPath the Flow Path with the endpoints and the match
- * conditions to store.
- * @return the stored shortest-path flow on success, otherwise null.
- */
- public FlowPath measurementStorePathFlow(FlowPath flowPath);
-
- /**
- * Install path flows for measurement purpose.
- *
- * @param numThreads the number of threads to use to install the path
- * flows.
- * @return true on success, otherwise false.
- */
- public boolean measurementInstallPaths(Integer numThreads);
-
- /**
- * Get the measurement time that took to install the path flows.
- *
- * @return the measurement time (in nanoseconds) it took to install
- * the path flows.
- */
- public Long measurementGetInstallPathsTimeNsec();
-
- /**
- * Get the measurement install time per Flow.
- *
- * @return a multi-line string with the following format per line:
- * ThreadAndTimePerFlow <ThreadId> <TotalThreads> <Time(ns)>
- */
- public String measurementGetPerFlowInstallTime();
-
- /**
- * Clear the path flows stored for measurement purpose.
- *
- * @return true on success, otherwise false.
- */
- public boolean measurementClearAllPaths();
}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/web/FlowWebRoutable.java b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/web/FlowWebRoutable.java
index 954c84d..e1c6da9 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/web/FlowWebRoutable.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/web/FlowWebRoutable.java
@@ -22,11 +22,6 @@
router.attach("/getall-by-endpoints/{src-dpid}/{src-port}/{dst-dpid}/{dst-port}/json", GetAllFlowsByEndpointsResource.class);
router.attach("/getall/json", GetAllFlowsResource.class);
router.attach("/getsummary/{flow-id}/{max-flows}/json", GetSummaryFlowsResource.class);
- router.attach("/measurement-store-path/json", MeasurementStorePathFlowResource.class);
- router.attach("/measurement-install-paths/{num-threads}/json", MeasurementInstallPathsFlowResource.class);
- router.attach("/measurement-get-install-paths-time-nsec/json", MeasurementGetInstallPathsTimeNsecFlowResource.class);
- router.attach("/measurement-get-per-flow-install-time/json", MeasurementGetPerFlowInstallTimeFlowResource.class);
- router.attach("/measurement-clear-all-paths/json", MeasurementClearAllPathsFlowResource.class);
return router;
}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/web/MeasurementClearAllPathsFlowResource.java b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/web/MeasurementClearAllPathsFlowResource.java
deleted file mode 100644
index 07d9fb2..0000000
--- a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/web/MeasurementClearAllPathsFlowResource.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package net.onrc.onos.ofcontroller.flowmanager.web;
-
-import net.onrc.onos.ofcontroller.flowmanager.IFlowService;
-
-import org.restlet.resource.Get;
-import org.restlet.resource.ServerResource;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class MeasurementClearAllPathsFlowResource extends ServerResource {
- protected static Logger log = LoggerFactory.getLogger(MeasurementClearAllPathsFlowResource.class);
-
- @Get("json")
- public Boolean retrieve() {
- Boolean result = false;
-
- IFlowService flowService =
- (IFlowService)getContext().getAttributes().
- get(IFlowService.class.getCanonicalName());
-
- if (flowService == null) {
- log.debug("ONOS Flow Service not found");
- return result;
- }
-
- // Extract the arguments
- log.debug("Measurement Clear All Paths");
-
- // Process the request
- result = flowService.measurementClearAllPaths();
- return result;
- }
-}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/web/MeasurementGetInstallPathsTimeNsecFlowResource.java b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/web/MeasurementGetInstallPathsTimeNsecFlowResource.java
deleted file mode 100644
index 467afca..0000000
--- a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/web/MeasurementGetInstallPathsTimeNsecFlowResource.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package net.onrc.onos.ofcontroller.flowmanager.web;
-
-import net.onrc.onos.ofcontroller.flowmanager.IFlowService;
-
-import org.restlet.resource.Get;
-import org.restlet.resource.ServerResource;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class MeasurementGetInstallPathsTimeNsecFlowResource extends ServerResource {
- protected static Logger log = LoggerFactory.getLogger(MeasurementGetInstallPathsTimeNsecFlowResource.class);
-
- @Get("json")
- public Long retrieve() {
- Long result = null;
-
- IFlowService flowService =
- (IFlowService)getContext().getAttributes().
- get(IFlowService.class.getCanonicalName());
-
- if (flowService == null) {
- log.debug("ONOS Flow Service not found");
- return result;
- }
-
- // Extract the arguments
-
- // Process the request
- result = flowService.measurementGetInstallPathsTimeNsec();
-
- log.debug("Measurement Get Install Paths Time (nsec): " + result);
-
- return result;
- }
-}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/web/MeasurementGetPerFlowInstallTimeFlowResource.java b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/web/MeasurementGetPerFlowInstallTimeFlowResource.java
deleted file mode 100644
index 92d84ab..0000000
--- a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/web/MeasurementGetPerFlowInstallTimeFlowResource.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package net.onrc.onos.ofcontroller.flowmanager.web;
-
-import net.onrc.onos.ofcontroller.flowmanager.IFlowService;
-
-import org.restlet.resource.Get;
-import org.restlet.resource.ServerResource;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class MeasurementGetPerFlowInstallTimeFlowResource extends ServerResource {
- protected static Logger log = LoggerFactory.getLogger(MeasurementGetPerFlowInstallTimeFlowResource.class);
-
- @Get("json")
- public String retrieve() {
- String result = null;
-
- IFlowService flowService =
- (IFlowService)getContext().getAttributes().
- get(IFlowService.class.getCanonicalName());
-
- if (flowService == null) {
- log.debug("ONOS Flow Service not found");
- return result;
- }
-
- // Extract the arguments
-
- // Process the request
- result = flowService.measurementGetPerFlowInstallTime();
-
- log.debug("Measurement Get Install Paths Time (nsec): " + result);
-
- return result;
- }
-}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/web/MeasurementInstallPathsFlowResource.java b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/web/MeasurementInstallPathsFlowResource.java
deleted file mode 100644
index 074dfb4..0000000
--- a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/web/MeasurementInstallPathsFlowResource.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package net.onrc.onos.ofcontroller.flowmanager.web;
-
-import net.onrc.onos.ofcontroller.flowmanager.IFlowService;
-
-import org.restlet.resource.Get;
-import org.restlet.resource.ServerResource;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class MeasurementInstallPathsFlowResource extends ServerResource {
- protected static Logger log = LoggerFactory.getLogger(MeasurementInstallPathsFlowResource.class);
-
- @Get("json")
- public Boolean retrieve() {
- Boolean result = false;
-
- IFlowService flowService =
- (IFlowService)getContext().getAttributes().
- get(IFlowService.class.getCanonicalName());
-
- if (flowService == null) {
- log.debug("ONOS Flow Service not found");
- return result;
- }
-
- // Extract the arguments
- String numThreadsStr = (String) getRequestAttributes().get("num-threads");
- Integer numThreads = new Integer(numThreadsStr);
- log.debug("Measurement Install Paths Number of Threads " + numThreadsStr);
-
- // Process the request
- result = flowService.measurementInstallPaths(numThreads);
- return result;
- }
-}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/web/MeasurementStorePathFlowResource.java b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/web/MeasurementStorePathFlowResource.java
deleted file mode 100644
index 0f23663..0000000
--- a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/web/MeasurementStorePathFlowResource.java
+++ /dev/null
@@ -1,64 +0,0 @@
-package net.onrc.onos.ofcontroller.flowmanager.web;
-
-import java.io.IOException;
-
-import net.onrc.onos.ofcontroller.flowmanager.IFlowService;
-import net.onrc.onos.ofcontroller.util.FlowId;
-import net.onrc.onos.ofcontroller.util.FlowPath;
-
-import org.codehaus.jackson.JsonGenerationException;
-import org.codehaus.jackson.map.JsonMappingException;
-import org.codehaus.jackson.map.ObjectMapper;
-import org.restlet.resource.Post;
-import org.restlet.resource.ServerResource;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class MeasurementStorePathFlowResource extends ServerResource {
-
- protected static Logger log = LoggerFactory.getLogger(MeasurementStorePathFlowResource.class);
-
- @Post("json")
- public FlowId store(String flowJson) {
- FlowId result = new FlowId();
-
- IFlowService flowService =
- (IFlowService)getContext().getAttributes().
- get(IFlowService.class.getCanonicalName());
-
- if (flowService == null) {
- log.debug("ONOS Flow Service not found");
- return result;
- }
-
- //
- // Extract the arguments
- // NOTE: The "flow" is specified in JSON format.
- //
- ObjectMapper mapper = new ObjectMapper();
- String flowPathStr = flowJson;
- FlowPath flowPath = null;
- log.debug("Measurement Store Flow Path: " + flowPathStr);
- try {
- flowPath = mapper.readValue(flowPathStr, FlowPath.class);
- } catch (JsonGenerationException e) {
- e.printStackTrace();
- } catch (JsonMappingException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
-
- // Process the request
- if (flowPath != null) {
- FlowPath addedFlowPath =
- flowService.measurementStorePathFlow(flowPath);
- if (addedFlowPath == null)
- result = new FlowId(); // Error: Return empty Flow Id
- else
- result = addedFlowPath.flowId();
- }
-
- return result;
- }
-}
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 7bc0aac..83a5fab 100644
--- a/src/test/java/net/onrc/onos/ofcontroller/flowmanager/FlowManagerTest.java
+++ b/src/test/java/net/onrc/onos/ofcontroller/flowmanager/FlowManagerTest.java
@@ -574,234 +574,8 @@
assertEquals(paramFlow.flowEntryMatch().toString(), resultFlow.flowEntryMatch().toString());
}
- /**
- * Test method for {@link FlowManager#measurementStorePathFlow(FlowPath)}.
- * @throws Exception
- */
- @Test
- public final void testMeasurementStorePathFlowSuccessNormally() throws Exception {
- // instantiate required objects
- FlowPath paramFlow = createTestFlowPath(100, "installer id", 0, 1, 3, 2, 4);
- Map<Long, Object> shortestPathMap = new HashMap<Long, Object>();
- FlowManager fm = new FlowManager();
-
- // setup expectations
- expectInitWithContext();
- expect((Map<Long,Object>)topoRouteService.prepareShortestPathTopo()
- ).andReturn(shortestPathMap);
- expect(topoRouteService.getTopoShortestPath(
- shortestPathMap,
- paramFlow.dataPath().srcPort(),
- paramFlow.dataPath().dstPort())).andReturn(null);
-
- // start the test
- replayAll();
-
- fm.init(context);
- FlowPath resultFlowPath = fm.measurementStorePathFlow(paramFlow);
-
- // verify the test
- verifyAll();
- assertEquals(paramFlow.flowId().value(), resultFlowPath.flowId().value());
- assertEquals(paramFlow.installerId().toString(), resultFlowPath.installerId().toString());
- assertEquals(paramFlow.flowPathFlags().flags(), resultFlowPath.flowPathFlags().flags());
- assertEquals(paramFlow.dataPath().toString(), resultFlowPath.dataPath().toString());
- assertEquals(paramFlow.flowEntryMatch().toString(), resultFlowPath.flowEntryMatch().toString());
- }
-
- /**
- * Test method for {@link FlowManager#measurementInstallPaths(Integer)}.
- * @throws Exception
- */
- @Test
- public final void testMeasurementInstallPathsSuccessNormally() throws Exception {
- final String addFlow = "addFlow";
-
- // create mock objects
- FlowManager fm = createPartialMockAndInvokeDefaultConstructor(FlowManager.class, addFlow);
-
- // instantiate required objects
- FlowPath flow1 = createTestFlowPath(1, "installer id", 0, 1, 2, 3, 4);
- FlowPath flow2 = createTestFlowPath(2, "installer id", 0, 2, 3, 4, 5);
- FlowPath flow3 = createTestFlowPath(3, "installer id", 0, 3, 4, 5, 6);
- Map<Long, Object> shortestPathMap = new HashMap<Long, Object>();
-
- // setup expectations
- expectInitWithContext();
- expect((Map<Long,Object>)topoRouteService.prepareShortestPathTopo()
- ).andReturn(shortestPathMap);
-
- expect(topoRouteService.getTopoShortestPath(
- shortestPathMap,
- flow1.dataPath().srcPort(),
- flow1.dataPath().dstPort())).andReturn(null);
-
- expect(topoRouteService.getTopoShortestPath(
- shortestPathMap,
- flow2.dataPath().srcPort(),
- flow2.dataPath().dstPort())).andReturn(null);
-
- expect(topoRouteService.getTopoShortestPath(
- shortestPathMap,
- flow3.dataPath().srcPort(),
- flow3.dataPath().dstPort())).andReturn(null);
-
- expectPrivate(fm, addFlow,
- EasyMock.cmpEq(flow1),
- EasyMock.anyObject(FlowId.class),
- EasyMock.anyObject(String.class)).andReturn(true);
-
- expectPrivate(fm, addFlow,
- EasyMock.cmpEq(flow2),
- EasyMock.anyObject(FlowId.class),
- EasyMock.anyObject(String.class)).andReturn(true);
-
- expectPrivate(fm, addFlow,
- EasyMock.cmpEq(flow3),
- EasyMock.anyObject(FlowId.class),
- EasyMock.anyObject(String.class)).andReturn(true);
-
- // start the test
- replayAll();
-
- fm.init(context);
- fm.measurementStorePathFlow(flow1);
- fm.measurementStorePathFlow(flow2);
- fm.measurementStorePathFlow(flow3);
- Boolean result = fm.measurementInstallPaths(3);
-
- // verify the test
- verifyAll();
- assertTrue(result);
- }
-
- /**
- * Test method for {@link FlowManager#measurementGetInstallPathsTimeNsec()}.
- * @throws Exception
- */
- @Test
- public final void testMeasurementGetInstallPathsTimeNsecSuccessNormally() throws Exception {
- final String addFlow = "addFlow";
-
- // create mock objects
- FlowManager fm = createPartialMockAndInvokeDefaultConstructor(FlowManager.class, addFlow);
- mockStaticPartial(System.class, "nanoTime");
-
- // instantiate required objects
- FlowPath flow1 = createTestFlowPath(1, "installer id", 0, 1, 2, 3, 4);
- Map<Long, Object> shortestPathMap = new HashMap<Long, Object>();
-
- // setup expectations
- expectInitWithContext();
- expect(System.nanoTime()).andReturn(new Long(100000));
- expect(System.nanoTime()).andReturn(new Long(110000));
- expect((Map<Long,Object>)topoRouteService.prepareShortestPathTopo()
- ).andReturn(shortestPathMap);
- expect(topoRouteService.getTopoShortestPath(
- shortestPathMap,
- flow1.dataPath().srcPort(),
- flow1.dataPath().dstPort())).andReturn(null);
- expectPrivate(fm, addFlow,
- EasyMock.cmpEq(flow1),
- EasyMock.anyObject(FlowId.class),
- EasyMock.anyObject(String.class)).andReturn(true);
-
- // start the test
- replayAll();
-
- fm.init(context);
- fm.measurementStorePathFlow(flow1).toString();
- fm.measurementInstallPaths(1);
- Long result = fm.measurementGetInstallPathsTimeNsec();
-
- // verify the test
- verifyAll();
- assertEquals(new Long(10000), result);
- }
-
- /**
- * Test method for {@link FlowManager#measurementGetPerFlowInstallTime()}.
- * @throws Exception
- */
- @Test
- public final void testMeasurementGetPerFlowInstallTimeSuccessNormally() throws Exception {
- final String addFlow = "addFlow";
-
- // create mock objects
- FlowManager fm = createPartialMockAndInvokeDefaultConstructor(FlowManager.class, addFlow);
-
- // instantiate required objects
- FlowPath flow1 = createTestFlowPath(1, "installer id", 0, 1, 2, 3, 4);
- Map<Long, Object> shortestPathMap = new HashMap<Long, Object>();
-
- // setup expectations
- expectInitWithContext();
- expect((Map<Long,Object>)topoRouteService.prepareShortestPathTopo()
- ).andReturn(shortestPathMap);
-
- expect(topoRouteService.getTopoShortestPath(
- shortestPathMap,
- flow1.dataPath().srcPort(),
- flow1.dataPath().dstPort())).andReturn(null);
-
- expectPrivate(fm, addFlow,
- EasyMock.cmpEq(flow1),
- EasyMock.anyObject(FlowId.class),
- EasyMock.anyObject(String.class)).andReturn(true);
-
-
- // start the test
- replayAll();
-
- fm.init(context);
- fm.measurementStorePathFlow(flow1);
- fm.measurementInstallPaths(10);
- String result = fm.measurementGetPerFlowInstallTime();
-
- // verify the test
- verifyAll();
- assertTrue(result.startsWith("ThreadAndTimePerFlow"));
- }
-
- /**
- * Test method for {@link FlowManager#measurementClearAllPaths()}.
- * @throws Exception
- */
- @Test
- public final void testMeasurementClearAllPathsSuccessNormally() throws Exception {
- // instantiate required objects
- FlowPath paramFlow = createTestFlowPath(100, "installer id", 0, 1, 3, 2, 4);
- Map<Long, Object> shortestPathMap = new HashMap<Long, Object>();
- FlowManager fm = new FlowManager();
-
- // setup expectations
- expectInitWithContext();
- expect((Map<Long,Object>)topoRouteService.prepareShortestPathTopo()
- ).andReturn(shortestPathMap);
- expect(topoRouteService.getTopoShortestPath(
- shortestPathMap,
- paramFlow.dataPath().srcPort(),
- paramFlow.dataPath().dstPort())).andReturn(null);
- topoRouteService.dropShortestPathTopo(shortestPathMap);
-
- // start the test
- replayAll();
-
- fm.init(context);
- fm.measurementStorePathFlow(paramFlow);
- Boolean result = fm.measurementClearAllPaths();
-
- // verify the test
- verifyAll();
- assertTrue(result);
- assertEquals(new Long(0), fm.measurementGetInstallPathsTimeNsec());
- assertEquals("", fm.measurementGetPerFlowInstallTime());
- }
-
-
// INetMapStorage methods
-
/**
* Test method for {@link FlowManager#init(String)}.
* @throws Exception
diff --git a/web/measurement_clear_all_paths.py b/web/measurement_clear_all_paths.py
deleted file mode 100755
index 5bb73c5..0000000
--- a/web/measurement_clear_all_paths.py
+++ /dev/null
@@ -1,61 +0,0 @@
-#! /usr/bin/env python
-# -*- Mode: python; py-indent-offset: 4; tab-width: 8; indent-tabs-mode: t; -*-
-
-import pprint
-import os
-import sys
-import subprocess
-import json
-import argparse
-import io
-import time
-
-from flask import Flask, json, Response, render_template, make_response, request
-
-#
-# TODO: remove this! We don't use JSON argument here!
-# curl http://127.0.0.1:8080/wm/flow/delete/{"value":"0xf"}/json'
-#
-
-## Global Var ##
-ControllerIP="127.0.0.1"
-ControllerPort=8080
-
-DEBUG=0
-pp = pprint.PrettyPrinter(indent=4)
-
-app = Flask(__name__)
-
-## Worker Functions ##
-def log_error(txt):
- print '%s' % (txt)
-
-def debug(txt):
- if DEBUG:
- print '%s' % (txt)
-
-# @app.route("/wm/flow/measurement-clear-all-paths/json")
-def measurement_clear_all_paths():
- command = "curl -s \"http://%s:%s/wm/flow/measurement-clear-all-paths/json\"" % (ControllerIP, ControllerPort)
- debug("measurement_clear_all_paths %s" % command)
- result = os.popen(command).read()
- debug("result %s" % result)
- # parsedResult = json.loads(result)
- # debug("parsed %s" % parsedResult)
-
-if __name__ == "__main__":
- usage_msg = "Clear the paths that have been stored for measurement purpose\n"
- usage_msg = usage_msg + "Usage: %s\n" % (sys.argv[0])
- usage_msg = usage_msg + "\n"
-
- # app.debug = False;
-
- # Usage info
- if len(sys.argv) > 1 and (sys.argv[1] == "-h" or sys.argv[1] == "--help"):
- print(usage_msg)
- exit(0)
-
- # Check arguments
-
- # Do the work
- measurement_clear_all_paths()
diff --git a/web/measurement_get_install_paths_time_nsec.py b/web/measurement_get_install_paths_time_nsec.py
deleted file mode 100755
index d64dc49..0000000
--- a/web/measurement_get_install_paths_time_nsec.py
+++ /dev/null
@@ -1,61 +0,0 @@
-#! /usr/bin/env python
-# -*- Mode: python; py-indent-offset: 4; tab-width: 8; indent-tabs-mode: t; -*-
-
-import pprint
-import os
-import sys
-import subprocess
-import json
-import argparse
-import io
-import time
-
-from flask import Flask, json, Response, render_template, make_response, request
-
-#
-# TODO: remove this! We don't use JSON argument here!
-# curl http://127.0.0.1:8080/wm/flow/delete/{"value":"0xf"}/json'
-#
-
-## Global Var ##
-ControllerIP="127.0.0.1"
-ControllerPort=8080
-
-DEBUG=0
-pp = pprint.PrettyPrinter(indent=4)
-
-app = Flask(__name__)
-
-## Worker Functions ##
-def log_error(txt):
- print '%s' % (txt)
-
-def debug(txt):
- if DEBUG:
- print '%s' % (txt)
-
-# @app.route("/wm/flow/measurement-get-install-paths-time-nsec/json")
-def measurement_get_install_paths_time_nsec():
- command = "curl -s \"http://%s:%s/wm/flow/measurement-get-install-paths-time-nsec/json\"" % (ControllerIP, ControllerPort)
- debug("measurement_get_install_paths_time_nsec %s" % command)
- result = os.popen(command).read()
- print '%s nsec' % (result)
- # parsedResult = json.loads(result)
- # debug("parsed %s" % parsedResult)
-
-if __name__ == "__main__":
- usage_msg = "Get the measured time to install the stored flow paths\n"
- usage_msg = usage_msg + "Usage: %s\n" % (sys.argv[0])
- usage_msg = usage_msg + "\n"
-
- # app.debug = False;
-
- # Usage info
- if len(sys.argv) > 1 and (sys.argv[1] == "-h" or sys.argv[1] == "--help"):
- print(usage_msg)
- exit(0)
-
- # Check arguments
-
- # Do the work
- measurement_get_install_paths_time_nsec()
diff --git a/web/measurement_get_per_flow_install_time.py b/web/measurement_get_per_flow_install_time.py
deleted file mode 100755
index bf2bcc7..0000000
--- a/web/measurement_get_per_flow_install_time.py
+++ /dev/null
@@ -1,61 +0,0 @@
-#! /usr/bin/env python
-# -*- Mode: python; py-indent-offset: 4; tab-width: 8; indent-tabs-mode: t; -*-
-
-import pprint
-import os
-import sys
-import subprocess
-import json
-import argparse
-import io
-import time
-
-from flask import Flask, json, Response, render_template, make_response, request
-
-#
-# TODO: remove this! We don't use JSON argument here!
-# curl http://127.0.0.1:8080/wm/flow/delete/{"value":"0xf"}/json'
-#
-
-## Global Var ##
-ControllerIP="127.0.0.1"
-ControllerPort=8080
-
-DEBUG=0
-pp = pprint.PrettyPrinter(indent=4)
-
-app = Flask(__name__)
-
-## Worker Functions ##
-def log_error(txt):
- print '%s' % (txt)
-
-def debug(txt):
- if DEBUG:
- print '%s' % (txt)
-
-# @app.route("/wm/flow/measurement-get-per-flow-install-time/json")
-def measurement_get_per_flow_install_time():
- command = "curl -s \"http://%s:%s/wm/flow/measurement-get-per-flow-install-time/json\"" % (ControllerIP, ControllerPort)
- debug("measurement_get_per_flow_install_time %s" % command)
- result = os.popen(command).read()
- print '%s' % (result)
- # parsedResult = json.loads(result)
- # debug("parsed %s" % parsedResult)
-
-if __name__ == "__main__":
- usage_msg = "Get the measured time per flow to install each stored flow path\n"
- usage_msg = usage_msg + "Usage: %s\n" % (sys.argv[0])
- usage_msg = usage_msg + "\n"
-
- # app.debug = False;
-
- # Usage info
- if len(sys.argv) > 1 and (sys.argv[1] == "-h" or sys.argv[1] == "--help"):
- print(usage_msg)
- exit(0)
-
- # Check arguments
-
- # Do the work
- measurement_get_per_flow_install_time()
diff --git a/web/measurement_install_paths.py b/web/measurement_install_paths.py
deleted file mode 100755
index d99070e..0000000
--- a/web/measurement_install_paths.py
+++ /dev/null
@@ -1,67 +0,0 @@
-#! /usr/bin/env python
-# -*- Mode: python; py-indent-offset: 4; tab-width: 8; indent-tabs-mode: t; -*-
-
-import pprint
-import os
-import sys
-import subprocess
-import json
-import argparse
-import io
-import time
-
-from flask import Flask, json, Response, render_template, make_response, request
-
-#
-# TODO: remove this! We don't use JSON argument here!
-# curl http://127.0.0.1:8080/wm/flow/delete/{"value":"0xf"}/json'
-#
-
-## Global Var ##
-ControllerIP="127.0.0.1"
-ControllerPort=8080
-
-DEBUG=0
-pp = pprint.PrettyPrinter(indent=4)
-
-app = Flask(__name__)
-
-## Worker Functions ##
-def log_error(txt):
- print '%s' % (txt)
-
-def debug(txt):
- if DEBUG:
- print '%s' % (txt)
-
-# @app.route("/wm/flow/measurement-install-paths/<num-threads>/json")
-def measurement_install_paths(num_threads):
- command = "curl -s \"http://%s:%s/wm/flow/measurement-install-paths/%s/json\"" % (ControllerIP, ControllerPort, num_threads)
- debug("measurement_install_paths %s" % command)
- result = os.popen(command).read()
- debug("result %s" % result)
- # parsedResult = json.loads(result)
- # debug("parsed %s" % parsedResult)
-
-if __name__ == "__main__":
- usage_msg = "Install flow paths and start measurements\n"
- usage_msg = usage_msg + "Usage: %s <num-threads>\n" % (sys.argv[0])
- usage_msg = usage_msg + "\n"
- usage_msg = usage_msg + " Arguments:\n"
- usage_msg = usage_msg + " <num-threads> Number of threads to use to install the flows\n"
-
- # app.debug = False;
-
- # Usage info
- if len(sys.argv) > 1 and (sys.argv[1] == "-h" or sys.argv[1] == "--help"):
- print(usage_msg)
- exit(0)
-
- # Check arguments
- if len(sys.argv) < 2:
- log_error(usage_msg)
- exit(1)
- num_threads = int(sys.argv[1], 0)
-
- # Do the work
- measurement_install_paths(num_threads)
diff --git a/web/measurement_process.py b/web/measurement_process.py
deleted file mode 100755
index 3187299..0000000
--- a/web/measurement_process.py
+++ /dev/null
@@ -1,59 +0,0 @@
-#! /usr/bin/env python
-# -*- Mode: python; py-indent-offset: 4; tab-width: 8; indent-tabs-mode: t; -*-
-
-import functools
-import math
-import sys
-
-## {{{ http://code.activestate.com/recipes/511478/ (r1)
-
-def percentile(N, percent, key=lambda x:x):
- """
- Find the percentile of a list of values.
-
- @parameter N - is a list of values. Note N MUST BE already sorted.
- @parameter percent - a float value from 0.0 to 1.0.
- @parameter key - optional key function to compute value from each element of N.
-
- @return - the percentile of the values
- """
- if not N:
- return None
- k = (len(N)-1) * percent
- f = math.floor(k)
- c = math.ceil(k)
- if f == c:
- return key(N[int(k)])
- d0 = key(N[int(f)]) * (c-k)
- d1 = key(N[int(c)]) * (k-f)
- return d0+d1
-
-# median is 50th percentile.
-# median = functools.partial(percentile, percent=0.5)
-## end of http://code.activestate.com/recipes/511478/ }}}
-
-if __name__ == "__main__":
-
- dict = {}
-
- #
- # Read the data from the stdin, and store it in a dictionary.
- # The dictionary uses lists as values.
- #
- data = sys.stdin.readlines()
- for line in data:
- words = line.split()
- thread_n = int(words[0])
- msec = float(words[1])
- dict.setdefault(thread_n, []).append(msec)
-
- #
- # Compute and print the values: median (50-th), 10-th, and 90-th
- # percentile:
- # <key> <median> <10-percentile> <90-percentile>
- #
- for key, val_list in sorted(dict.items()):
- val_10 = percentile(sorted(val_list), 0.1)
- val_50 = percentile(sorted(val_list), 0.5)
- val_90 = percentile(sorted(val_list), 0.9)
- print "%s %s %s %s" % (str(key), str(val_50), str(val_10), str(val_90))
diff --git a/web/measurement_run.py b/web/measurement_run.py
deleted file mode 100755
index 80d0517..0000000
--- a/web/measurement_run.py
+++ /dev/null
@@ -1,104 +0,0 @@
-#! /usr/bin/env python
-# -*- Mode: python; py-indent-offset: 4; tab-width: 8; indent-tabs-mode: t; -*-
-
-import os
-import string
-import subprocess
-import time
-
-# flow_n = 252
-# threads_n = [1, 2, 3, 4, 5, 10, 20, 30, 40, 50, 100]
-# iterations_n = 10
-
-flow_n = 1
-threads_n = [1]
-iterations_n = 10
-# iterations_n = 100
-
-# flow_n = 42
-# flow_n = 420
-# flow_n = 1008
-
-def run_command(cmd):
- """
- - Run an external command, and return a tuple: stdout as the
- first argument, and stderr as the second argument.
- - Returns None if error.
- """
- try:
- pr = subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
- ret_tuple = pr.communicate();
- if pr.returncode:
- print "%s failed with error code: %s" % (cmd, str(pr.returncode))
- return ret_tuple
- except OSError:
- print "OS Error running %s" % cmd
-
-def run_install_paths(flowdef_filename):
- # Prepare the flows to measure
- cmd = "web/measurement_store_flow.py -f " + flowdef_filename
- os.system(cmd)
-
-def run_measurement(thread_n):
- # Install the Flow Paths
- cmd = ["web/measurement_install_paths.py", str(thread_n)]
- run_command(cmd)
-
- # Get the measurement data and print it
- cmd = "web/measurement_get_install_paths_time_nsec.py"
- r = run_command(cmd) # Tuple: [<stdout>, <stderr>]
- res = r[0].split() # Tuple: [<num>, nsec]
- nsec_str = res[0]
- msec = float(nsec_str) / (1000 * 1000)
-
- # Get the measurement data and print it
- cmd = "web/measurement_get_per_flow_install_time.py"
- r = run_command(cmd) # Tuple: [<stdout>, <stderr>]
- res = r[0]
- print res
-
- # Keep checking until all Flow Paths are installed
- while True:
- # time.sleep(3)
- cmd = ["web/get_flow.py", "all"]
- r = run_command(cmd)
- if string.count(r[0], "FlowPath") != flow_n:
- continue
- if string.find(r[0], "NOT") == -1:
- break
-
- # Remove the installed Flow Paths
- cmd = ["web/delete_flow.py", "all"]
- run_command(cmd)
-
- # Keep checking until all Flows are removed
- while True:
- # time.sleep(3)
- cmd = ["web/get_flow.py", "all"]
- r = run_command(cmd)
- if r[0] == "":
- break
-
- return msec
-
-
-if __name__ == "__main__":
-
- # Initial cleanup
- cmd = "web/measurement_clear_all_paths.py"
- run_command(cmd)
-
- # Install the Flow Paths to measure
- flowdef_filename = "web/flowdef_8node_" + str(flow_n) + ".txt"
- run_install_paths(flowdef_filename)
-
- # Do the work
- for thread_n in threads_n:
- for n in range(iterations_n):
- msec = run_measurement(thread_n)
- # Format: <number of threads> <time in ms>
- print "%d %f" % (thread_n, msec / flow_n)
-
- # Cleanup on exit
- cmd = "web/measurement_clear_all_paths.py"
- run_command(cmd)
diff --git a/web/measurement_store_flow.py b/web/measurement_store_flow.py
deleted file mode 100755
index 0e39465..0000000
--- a/web/measurement_store_flow.py
+++ /dev/null
@@ -1,471 +0,0 @@
-#! /usr/bin/env python
-# -*- Mode: python; py-indent-offset: 4; tab-width: 8; indent-tabs-mode: t; -*-
-
-import copy
-import pprint
-import os
-import sys
-import subprocess
-import json
-import argparse
-import io
-import time
-
-from flask import Flask, json, Response, render_template, make_response, request
-
-## Global Var ##
-ControllerIP = "127.0.0.1"
-ControllerPort = 8080
-ReadFromFile = ""
-
-DEBUG=0
-pp = pprint.PrettyPrinter(indent=4)
-
-app = Flask(__name__)
-
-## Worker Functions ##
-def log_error(txt):
- print '%s' % (txt)
-
-def debug(txt):
- if DEBUG:
- print '%s' % (txt)
-
-def measurement_store_path_flow(flow_path):
- flow_path_json = json.dumps(flow_path)
-
- try:
- command = "curl -s -H 'Content-Type: application/json' -d '%s' http://%s:%s/wm/flow/measurement-store-path/json" % (flow_path_json, ControllerIP, ControllerPort)
- debug("measurement_store_path_flow %s" % command)
- result = os.popen(command).read()
- debug("result %s" % result)
- # parsedResult = json.loads(result)
- # debug("parsed %s" % parsedResult)
- except:
- log_error("Controller IF has issue")
- exit(1)
-
-def extract_flow_args(my_args):
- # Check the arguments
- if len(my_args) < 6:
- log_error(usage_msg)
- exit(1)
-
- # Extract the mandatory arguments
- my_flow_id = my_args[0]
- my_installer_id = my_args[1]
- my_src_dpid = my_args[2]
- my_src_port = my_args[3]
- my_dst_dpid = my_args[4]
- my_dst_port = my_args[5]
-
- #
- # Extract the "flowPathFlags", "match" and "action" arguments
- #
- flowPathFlags = 0L
- match = {}
- matchInPortEnabled = True # NOTE: Enabled by default
- actions = []
- actionOutputEnabled = True # NOTE: Enabled by default
- idx = 6
- while idx < len(my_args):
- action = {}
- arg1 = my_args[idx]
- idx = idx + 1
- # Extract the second argument
- if idx >= len(my_args):
- error_arg = "ERROR: Missing or invalid '" + arg1 + "' argument"
- log_error(error_arg)
- log_error(usage_msg)
- exit(1)
- arg2 = my_args[idx]
- idx = idx + 1
-
- if arg1 == "flowPathFlags":
- if "DISCARD_FIRST_HOP_ENTRY" in arg2:
- flowPathFlags = flowPathFlags + 0x1
- if "KEEP_ONLY_FIRST_HOP_ENTRY" in arg2:
- flowPathFlags = flowPathFlags + 0x2
- elif arg1 == "matchInPort":
- # Mark whether ACTION_OUTPUT action is enabled
- matchInPortEnabled = arg2 in ['True', 'true']
- # inPort = {}
- # inPort['value'] = int(arg2, 0)
- # match['inPort'] = inPort
- ## match['matchInPort'] = True
- elif arg1 == "matchSrcMac":
- srcMac = {}
- srcMac['value'] = arg2
- match['srcMac'] = srcMac
- # match['matchSrcMac'] = True
- elif arg1 == "matchDstMac":
- dstMac = {}
- dstMac['value'] = arg2
- match['dstMac'] = dstMac
- # match['matchDstMac'] = True
- elif arg1 == "matchEthernetFrameType":
- match['ethernetFrameType'] = int(arg2, 0)
- # match['matchEthernetFrameType'] = True
- elif arg1 == "matchVlanId":
- match['vlanId'] = int(arg2, 0)
- # match['matchVlanId'] = True
- elif arg1 == "matchVlanPriority":
- match['vlanPriority'] = int(arg2, 0)
- # match['matchVlanPriority'] = True
- elif arg1 == "matchSrcIPv4Net":
- srcIPv4Net = {}
- srcIPv4Net['value'] = arg2
- match['srcIPv4Net'] = srcIPv4Net
- # match['matchSrcIPv4Net'] = True
- elif arg1 == "matchDstIPv4Net":
- dstIPv4Net = {}
- dstIPv4Net['value'] = arg2
- match['dstIPv4Net'] = dstIPv4Net
- # match['matchDstIPv4Net'] = True
- elif arg1 == "matchIpProto":
- match['ipProto'] = int(arg2, 0)
- # match['matchIpProto'] = True
- elif arg1 == "matchIpToS":
- match['ipToS'] = int(arg2, 0)
- # match['matchIpToS'] = True
- elif arg1 == "matchSrcTcpUdpPort":
- match['srcTcpUdpPort'] = int(arg2, 0)
- # match['matchSrcTcpUdpPort'] = True
- elif arg1 == "matchDstTcpUdpPort":
- match['dstTcpUdpPort'] = int(arg2, 0)
- # match['matchDstTcpUdpPort'] = True
- elif arg1 == "actionOutput":
- # Mark whether ACTION_OUTPUT action is enabled
- actionOutputEnabled = arg2 in ['True', 'true']
- # If ACTION_OUTPUT is explicitly enabled, add an entry with a fake
- # port number. We need this entry to preserve the action ordering.
- if actionOutputEnabled == True:
- actionOutput = {}
- outPort = {}
- outPort['value'] = 0xffff
- actionOutput['port'] = outPort
- actionOutput['maxLen'] = 0
- action['actionOutput'] = actionOutput
- # action['actionType'] = 'ACTION_OUTPUT'
- actions.append(action)
- #
- elif arg1 == "actionSetVlanId":
- vlanId = {}
- vlanId['vlanId'] = int(arg2, 0)
- action['actionSetVlanId'] = vlanId
- # action['actionType'] = 'ACTION_SET_VLAN_VID'
- actions.append(copy.deepcopy(action))
- elif arg1 == "actionSetVlanPriority":
- vlanPriority = {}
- vlanPriority['vlanPriority'] = int(arg2, 0)
- action['actionSetVlanPriority'] = vlanPriority
- # action['actionType'] = 'ACTION_SET_VLAN_PCP'
- actions.append(copy.deepcopy(action))
- elif arg1 == "actionStripVlan":
- stripVlan = {}
- stripVlan['stripVlan'] = arg2 in ['True', 'true']
- action['actionStripVlan'] = stripVlan
- # action['actionType'] = 'ACTION_STRIP_VLAN'
- actions.append(copy.deepcopy(action))
- elif arg1 == "actionSetEthernetSrcAddr":
- ethernetSrcAddr = {}
- ethernetSrcAddr['value'] = arg2
- setEthernetSrcAddr = {}
- setEthernetSrcAddr['addr'] = ethernetSrcAddr
- action['actionSetEthernetSrcAddr'] = setEthernetSrcAddr
- # action['actionType'] = 'ACTION_SET_DL_SRC'
- actions.append(copy.deepcopy(action))
- elif arg1 == "actionSetEthernetDstAddr":
- ethernetDstAddr = {}
- ethernetDstAddr['value'] = arg2
- setEthernetDstAddr = {}
- setEthernetDstAddr['addr'] = ethernetDstAddr
- action['actionSetEthernetDstAddr'] = setEthernetDstAddr
- # action['actionType'] = 'ACTION_SET_DL_DST'
- actions.append(copy.deepcopy(action))
- elif arg1 == "actionSetIPv4SrcAddr":
- IPv4SrcAddr = {}
- IPv4SrcAddr['value'] = arg2
- setIPv4SrcAddr = {}
- setIPv4SrcAddr['addr'] = IPv4SrcAddr
- action['actionSetIPv4SrcAddr'] = setIPv4SrcAddr
- # action['actionType'] = 'ACTION_SET_NW_SRC'
- actions.append(copy.deepcopy(action))
- elif arg1 == "actionSetIPv4DstAddr":
- IPv4DstAddr = {}
- IPv4DstAddr['value'] = arg2
- setIPv4DstAddr = {}
- setIPv4DstAddr['addr'] = IPv4DstAddr
- action['actionSetIPv4DstAddr'] = setIPv4DstAddr
- # action['actionType'] = 'ACTION_SET_NW_DST'
- actions.append(copy.deepcopy(action))
- elif arg1 == "actionSetIpToS":
- ipToS = {}
- ipToS['ipToS'] = int(arg2, 0)
- action['actionSetIpToS'] = ipToS
- # action['actionType'] = 'ACTION_SET_NW_TOS'
- actions.append(copy.deepcopy(action))
- elif arg1 == "actionSetTcpUdpSrcPort":
- tcpUdpSrcPort = {}
- tcpUdpSrcPort['port'] = int(arg2, 0)
- action['actionSetTcpUdpSrcPort'] = tcpUdpSrcPort
- # action['actionType'] = 'ACTION_SET_TP_SRC'
- actions.append(copy.deepcopy(action))
- elif arg1 == "actionSetTcpUdpDstPort":
- tcpUdpDstPort = {}
- tcpUdpDstPort['port'] = int(arg2, 0)
- action['actionSetTcpUdpDstPort'] = tcpUdpDstPort
- # action['actionType'] = 'ACTION_SET_TP_DST'
- actions.append(copy.deepcopy(action))
- elif arg1 == "actionEnqueue":
- # TODO: Implement ACTION_ENQUEUE
- actionEnqueue = {}
- # actionEnqueue['queueId'] = int(arg2, 0)
- # enqueuePort = {}
- # enqueuePort['value'] = int(arg3, 0)
- # actionEnqueue['port'] = enqueuePort
- # action['actionEnqueue'] = actionEnqueue
- # # action['actionType'] = 'ACTION_ENQUEUE'
- # actions.append(copy.deepcopy(action))
- #
- else:
- log_error("ERROR: Unknown argument '%s'" % (arg1))
- log_error(usage_msg)
- exit(1)
-
- return {
- 'my_flow_id' : my_flow_id,
- 'my_installer_id' : my_installer_id,
- 'my_src_dpid' : my_src_dpid,
- 'my_src_port' : my_src_port,
- 'my_dst_dpid' : my_dst_dpid,
- 'my_dst_port' : my_dst_port,
- 'flowPathFlags' : flowPathFlags,
- 'match' : match,
- 'matchInPortEnabled' : matchInPortEnabled,
- 'actions' : actions,
- 'actionOutputEnabled' : actionOutputEnabled
- }
-
-def compute_flow_path(parsed_args, data_path):
-
- my_flow_id = parsed_args['my_flow_id']
- my_installer_id = parsed_args['my_installer_id']
- myFlowPathFlags = parsed_args['flowPathFlags']
- match = parsed_args['match']
- matchInPortEnabled = parsed_args['matchInPortEnabled']
- actions = parsed_args['actions']
- actionOutputEnabled = parsed_args['actionOutputEnabled']
- my_data_path = copy.deepcopy(data_path)
-
- flow_id = {}
- flow_id['value'] = my_flow_id
- installer_id = {}
- installer_id['value'] = my_installer_id
- flowPathFlags = {}
- flowPathFlags['flags'] = myFlowPathFlags
-
- flowEntryActions = {}
-
- flow_path = {}
- flow_path['flowId'] = flow_id
- flow_path['installerId'] = installer_id
- flow_path['flowPathFlags'] = flowPathFlags
-
- if (len(match) > 0):
- flow_path['flowEntryMatch'] = copy.deepcopy(match)
-
- #
- # Add the match conditions to each flow entry
- #
- if (len(match) > 0) or matchInPortEnabled:
- idx = 0
- while idx < len(my_data_path['flowEntries']):
- if matchInPortEnabled:
- inPort = my_data_path['flowEntries'][idx]['inPort']
- match['inPort'] = copy.deepcopy(inPort)
- # match['matchInPort'] = True
- my_data_path['flowEntries'][idx]['flowEntryMatch'] = copy.deepcopy(match)
- idx = idx + 1
-
-
- if (len(actions) > 0):
- flowEntryActions['actions'] = copy.deepcopy(actions)
- flow_path['flowEntryActions'] = flowEntryActions
-
- #
- # Set the actions for each flow entry
- # NOTE: The actions from the command line are aplied
- # ONLY to the first flow entry.
- #
- # If ACTION_OUTPUT action is enabled, then apply it
- # to each flow entry.
- #
- if (len(actions) > 0) or actionOutputEnabled:
- idx = 0
- while idx < len(my_data_path['flowEntries']):
- if idx > 0:
- actions = [] # Reset the actions for all but first entry
- action = {}
- outPort = my_data_path['flowEntries'][idx]['outPort']
- actionOutput = {}
- actionOutput['port'] = copy.deepcopy(outPort)
- # actionOutput['maxLen'] = 0 # TODO: not used for now
- action['actionOutput'] = copy.deepcopy(actionOutput)
- # action['actionType'] = 'ACTION_OUTPUT'
- actions.append(copy.deepcopy(action))
- flowEntryActions = {}
- flowEntryActions['actions'] = copy.deepcopy(actions)
-
- my_data_path['flowEntries'][idx]['flowEntryActions'] = flowEntryActions
- idx = idx + 1
-
- flow_path['dataPath'] = my_data_path
- debug("Flow Path: %s" % flow_path)
- return flow_path
-
-def measurement_store_paths(parsed_args):
- idx = 0
- while idx < len(parsed_args):
- data_path = {}
- src_dpid = {}
- src_port = {}
- dst_dpid = {}
- dst_port = {}
- src_switch_port = {}
- dst_switch_port = {}
- flow_entries = []
-
- src_dpid['value'] = parsed_args[idx]['my_src_dpid']
- src_port['value'] = parsed_args[idx]['my_src_port']
- dst_dpid['value'] = parsed_args[idx]['my_dst_dpid']
- dst_port['value'] = parsed_args[idx]['my_dst_port']
- src_switch_port['dpid'] = src_dpid
- src_switch_port['port'] = src_port
- dst_switch_port['dpid'] = dst_dpid
- dst_switch_port['port'] = dst_port
-
- data_path['srcPort'] = copy.deepcopy(src_switch_port)
- data_path['dstPort'] = copy.deepcopy(dst_switch_port)
- data_path['flowEntries'] = copy.deepcopy(flow_entries)
-
- #
- # XXX: Explicitly disable the InPort matching, and
- # the Output action, because they get in the way
- # during the compute_flow_path() processing.
- #
- parsed_args[idx]['matchInPortEnabled'] = False
- parsed_args[idx]['actionOutputEnabled'] = False
-
- flow_path = compute_flow_path(parsed_args[idx], data_path)
- measurement_store_path_flow(flow_path)
-
- idx = idx + 1
-
-
-if __name__ == "__main__":
- usage_msg = "Store Flow Paths into ONOS for measurement purpose.\n"
- usage_msg = usage_msg + "\n"
- usage_msg = usage_msg + "Usage: %s [Flags] <flow-id> <installer-id> <src-dpid> <src-port> <dest-dpid> <dest-port> [Flow Path Flags] [Match Conditions] [Actions]\n" % (sys.argv[0])
- usage_msg = usage_msg + "\n"
- usage_msg = usage_msg + " Flags:\n"
- usage_msg = usage_msg + " -f <filename> Read the flow(s) to install from a file\n"
- usage_msg = usage_msg + " File format: one line per flow starting with <flow-id>\n"
- usage_msg = usage_msg + "\n"
- usage_msg = usage_msg + " Flow Path Flags:\n"
- usage_msg = usage_msg + " flowPathFlags <Flags> (flag names separated by ',')\n"
- usage_msg = usage_msg + "\n"
- usage_msg = usage_msg + " Known flags:\n"
- usage_msg = usage_msg + " DISCARD_FIRST_HOP_ENTRY : Discard the first-hop flow entry\n"
- usage_msg = usage_msg + " KEEP_ONLY_FIRST_HOP_ENTRY : Keep only the first-hop flow entry\n"
- usage_msg = usage_msg + "\n"
- usage_msg = usage_msg + " Match Conditions:\n"
- usage_msg = usage_msg + " matchInPort <True|False> (default to True)\n"
- usage_msg = usage_msg + " matchSrcMac <source MAC address>\n"
- usage_msg = usage_msg + " matchDstMac <destination MAC address>\n"
- usage_msg = usage_msg + " matchEthernetFrameType <Ethernet frame type>\n"
- usage_msg = usage_msg + " matchVlanId <VLAN ID>\n"
- usage_msg = usage_msg + " matchVlanPriority <VLAN priority>\n"
- usage_msg = usage_msg + " matchSrcIPv4Net <source IPv4 network address>\n"
- usage_msg = usage_msg + " matchDstIPv4Net <destination IPv4 network address>\n"
- usage_msg = usage_msg + " matchIpProto <IP protocol>\n"
- usage_msg = usage_msg + " matchIpToS <IP ToS (DSCP field, 6 bits)>\n"
- usage_msg = usage_msg + " matchSrcTcpUdpPort <source TCP/UDP port>\n"
- usage_msg = usage_msg + " matchDstTcpUdpPort <destination TCP/UDP port>\n"
- usage_msg = usage_msg + "\n"
- usage_msg = usage_msg + " Actions:\n"
- usage_msg = usage_msg + " actionOutput <True|False> (default to True)\n"
- usage_msg = usage_msg + " actionSetVlanId <VLAN ID>\n"
- usage_msg = usage_msg + " actionSetVlanPriority <VLAN priority>\n"
- usage_msg = usage_msg + " actionStripVlan <True|False>\n"
- usage_msg = usage_msg + " actionSetEthernetSrcAddr <source MAC address>\n"
- usage_msg = usage_msg + " actionSetEthernetDstAddr <destination MAC address>\n"
- usage_msg = usage_msg + " actionSetIPv4SrcAddr <source IPv4 address>\n"
- usage_msg = usage_msg + " actionSetIPv4DstAddr <destination IPv4 address>\n"
- usage_msg = usage_msg + " actionSetIpToS <IP ToS (DSCP field, 6 bits)>\n"
- usage_msg = usage_msg + " actionSetTcpUdpSrcPort <source TCP/UDP port>\n"
- usage_msg = usage_msg + " actionSetTcpUdpDstPort <destination TCP/UDP port>\n"
- usage_msg = usage_msg + " Actions (not implemented yet):\n"
- usage_msg = usage_msg + " actionEnqueue <dummy argument>\n"
-
- # app.debug = False;
-
- # Usage info
- if len(sys.argv) > 1 and (sys.argv[1] == "-h" or sys.argv[1] == "--help"):
- print(usage_msg)
- exit(0)
-
- #
- # Check the flags
- #
- start_argv_index = 1
- idx = 1
- while idx < len(sys.argv):
- arg1 = sys.argv[idx]
- idx = idx + 1
- if arg1 == "-f":
- if idx >= len(sys.argv):
- error_arg = "ERROR: Missing or invalid '" + arg1 + "' argument"
- log_error(error_arg)
- log_error(usage_msg)
- exit(1)
- ReadFromFile = sys.argv[idx]
- idx = idx + 1
- start_argv_index = idx
- else:
- break;
-
- #
- # Read the arguments from a file or from the remaining command line options
- #
- my_lines = []
- if len(ReadFromFile) > 0:
- f = open(ReadFromFile, "rt")
- my_line = f.readline()
- while my_line:
- if len(my_line.rstrip()) > 0 and my_line[0] != "#":
- my_token_line = my_line.rstrip().split()
- my_lines.append(my_token_line)
- my_line = f.readline()
- else:
- my_lines.append(copy.deepcopy(sys.argv[start_argv_index:]))
-
- #
- # Initialization
- #
- last_data_paths = []
- parsed_args = []
- idx = 0
- while idx < len(my_lines):
- last_data_path = []
- last_data_paths.append(copy.deepcopy(last_data_path))
- #
- # Parse the flow arguments
- #
- my_args = my_lines[idx]
- parsed_args.append(copy.deepcopy(extract_flow_args(my_args)))
-
- idx = idx + 1
-
- #
- measurement_store_paths(parsed_args)