Merge "Add missing comma to list, related to 16559"
[integration/test.git] / test / tools / odl-mdsal-clustering-tests / clustering-performance-test / flow_config_blaster.py
index 9a1ae165f69a16f9bb98d574b305d1825b6912ca..52b53eb1e6b93f34a315e385608f8c8b05fd9561 100755 (executable)
@@ -7,10 +7,11 @@ __email__ = "jmedved@cisco.com"
 from random import randrange
 import json
 import argparse
-import requests
 import time
 import threading
 import re
+
+import requests
 import netaddr
 
 
@@ -74,7 +75,6 @@ class FlowConfigBlaster(object):
 
         self.ip_addr = Counter(int(netaddr.IPAddress('10.0.0.1')) + startflow)
 
-
         self.print_lock = threading.Lock()
         self.cond = threading.Condition()
         self.threads_done = 0
@@ -82,7 +82,6 @@ class FlowConfigBlaster(object):
         for i in range(self.nthreads):
             self.flows[i] = {}
 
-
     def get_num_nodes(self, session):
         """
         Determines the number of OF nodes in the connected mininet network. If mininet is not connected, the default
@@ -110,13 +109,12 @@ class FlowConfigBlaster(object):
 
         return nodes
 
-
-    def add_flow(self, session, tid, node, flow_id, ipaddr):
+    def add_flow(self, session, node, flow_id, ipaddr):
         """
         Adds a single flow to the config data store via REST
         """
-        flow_data = self.json_template % (tid + flow_id, 'TestFlow-%d' % flow_id, 65000,
-                                          str(flow_id), 65000, str(netaddr.IPAddress(ipaddr)))
+        flow_data = self.json_template % (flow_id, 'TestFlow-%d' % flow_id, 65000, str(flow_id), 65000,
+                                          str(netaddr.IPAddress(ipaddr)))
         # print flow_data
         flow_url = self.url_template % (node, flow_id)
         # print flow_url
@@ -128,7 +126,6 @@ class FlowConfigBlaster(object):
 
         return r.status_code
 
-
     def add_flows(self, start_flow, tid):
         """
         Adds flows into the ODL config space. This function is executed by a worker thread
@@ -148,7 +145,7 @@ class FlowConfigBlaster(object):
                 node_id = randrange(1, n_nodes + 1)
                 flow_id = tid * (self.ncycles * self.nflows) + flow + start_flow + self.startflow
                 self.flows[tid][flow_id] = node_id
-                sts = self.add_flow(s, tid, node_id, flow_id, self.ip_addr.increment())
+                sts = self.add_flow(s, node_id, flow_id, self.ip_addr.increment())
                 try:
                     add_res[sts] += 1
                 except KeyError:
@@ -175,16 +172,9 @@ class FlowConfigBlaster(object):
         with self.cond:
             self.cond.notifyAll()
 
-
     def delete_flow(self, session, node, flow_id):
         """
         Deletes a single flow from the ODL config data store via REST
-
-        :param session:
-        :param url_template:
-        :param node:
-        :param flow_id:
-        :return:
         """
         flow_url = self.url_template % (node, flow_id)
 
@@ -195,7 +185,6 @@ class FlowConfigBlaster(object):
 
         return r.status_code
 
-
     def delete_flows(self, start_flow, tid):
         """
         Deletes flow from the ODL config space that have been added using the 'add_flows()' function. This function is
@@ -239,11 +228,10 @@ class FlowConfigBlaster(object):
         with self.cond:
             self.cond.notifyAll()
 
-
     def run_cycle(self, function):
         """
         Runs an add or delete cycle. Starts a number of worker threads that each add a bunch of flows. Work is done
-        in context of the worker threads
+        in context of the worker threads.
         """
 
         for c in range(self.ncycles):
@@ -264,16 +252,16 @@ class FlowConfigBlaster(object):
 
             with self.print_lock:
                 print '    Total success rate: %.2f, Total rate: %.2f' % (
-                      self.ok_rate.value, self.total_rate.value)
-                measured_rate = self.nthreads * self.nflows * self.ncycles / t.secs
+                    self.ok_rate.value, self.total_rate.value)
+                measured_rate = (self.nthreads * self.nflows) / t.secs
                 print '    Measured rate:      %.2f (%.2f%% of Total success rate)' % \
                       (measured_rate, measured_rate / self.total_rate.value * 100)
+                print '    Measured time:      %.2fs' % t.secs
                 self.threads_done = 0
 
             self.ok_rate.value = 0
             self.total_rate.value = 0
 
-
     def add_blaster(self):
         self.run_cycle(self.add_flows)
 
@@ -288,18 +276,22 @@ class FlowConfigBlaster(object):
 
 
 def get_json_from_file(filename):
+    """
+    Get a flow programming template from a file
+    :param filename: File from which to get the template
+    :return: The json flow template (string)
+    """
     with open(filename, 'r') as f:
         read_data = f.read()
     return read_data
 
 
 if __name__ == "__main__":
-
     JSON_FLOW_MOD1 = '''{
         "flow-node-inventory:flow": [
             {
                 "flow-node-inventory:cookie": %d,
-                "flow-node-inventory:cookie_mask": 65535,
+                "flow-node-inventory:cookie_mask": 4294967295,
                 "flow-node-inventory:flow-name": "%s",
                 "flow-node-inventory:hard-timeout": %d,
                 "flow-node-inventory:id": "%s",