2 __author__ = "Jan Medved"
3 __copyright__ = "Copyright(c) 2014, Cisco Systems, Inc."
4 __license__ = "New-style BSD"
5 __email__ = "jmedved@cisco.com"
7 from flow_config_blaster import FlowConfigBlaster
14 class FlowConfigBlasterFLE(FlowConfigBlaster):
16 FlowConfigBlaster, Floodlight Edition; Uses the Floodlight Static Flow Entry Pusher REST API to inject flows.
19 'switch': "00:00:00:00:00:00:00:01",
24 "dst-ip": "10.0.0.1/32",
26 "actions": "output=flood"
29 def __init__(self, host, port, ncycles, nthreads, nnodes, nflows, startflow):
30 FlowConfigBlaster.__init__(self, host, port, ncycles, nthreads, nnodes, nflows, startflow, False, '')
32 # Create the service URL
33 self.url = 'http://' + self.host + ":" + self.port + '/wm/staticflowentrypusher/json'
35 def get_num_nodes(self, session):
37 Determines the number of nodes in the network. Overrides the get_num_nodes method in FlowConfigBlaster.
41 url = 'http://' + self.host + ":" + self.port + '/wm/core/controller/switches/json'
44 r = session.get(url, headers=self.getheaders, stream=False)
46 if r.status_code == 200:
48 nodes = len(json.loads(r.content))
54 def add_flow(self, session, node, flow_id, ipaddr):
56 Adds a flow. Overrides the add_flow method in FlowConfigBlaster.
63 self.flow['switch'] = "00:00:00:00:00:00:00:%s" % '{0:02x}'.format(node)
64 self.flow['name'] = 'TestFlow-%d' % flow_id
65 self.flow['cookie'] = str(flow_id)
66 self.flow['dst-ip'] = "%s/32" % str(netaddr.IPAddress(ipaddr))
68 flow_data = json.dumps(self.flow)
72 r = session.post(self.url, data=flow_data, headers=self.putheaders, stream=False)
75 def delete_flow(self, session, node, flow_id):
77 Deletes a flow. Overrides the delete_flow method in FlowConfigBlaster.
83 f = {'name': 'TestFlow-%d' % flow_id}
84 flow_data = json.dumps(f)
86 r = session.delete(self.url, data=flow_data, headers=self.getheaders)
90 if __name__ == "__main__":
92 parser = argparse.ArgumentParser(description='Flow programming performance test for Floodlight: First adds and '
93 'then deletes flows using the Static Flow Entry Pusher REST API.')
95 parser.add_argument('--host', default='127.0.0.1',
96 help='Host where the controller is running (default is 127.0.0.1)')
97 parser.add_argument('--port', default='8080',
98 help='Port on which the controller\'s RESTCONF is listening (default is 8080)')
99 parser.add_argument('--cycles', type=int, default=1,
100 help='Number of flow add/delete cycles; default 1. Both Flow Adds and Flow Deletes are '
101 'performed in cycles. <THREADS> worker threads are started in each cycle and the cycle '
102 'ends when all threads finish. Another cycle is started when the previous cycle finished.')
103 parser.add_argument('--threads', type=int, default=1,
104 help='Number of request worker threads to start in each cycle; default=1. '
105 'Each thread will add/delete <FLOWS> flows.')
106 parser.add_argument('--flows', type=int, default=10,
107 help='Number of flows that will be added/deleted by each worker thread in each cycle; '
109 parser.add_argument('--nodes', type=int, default=16,
110 help='Number of nodes if mininet is not connected; default=16. If mininet is connected, '
111 'flows will be evenly distributed (programmed) into connected nodes.')
112 parser.add_argument('--delay', type=int, default=0,
113 help='Time (in seconds) to wait between the add and delete cycles; default=0')
114 parser.add_argument('--no-delete', dest='delete', action='store_false',
115 help='Do not perform the delete cycle.')
116 parser.add_argument('--startflow', type=int, default=0,
117 help='The starting Flow ID; default=0')
119 in_args = parser.parse_args()
121 fct = FlowConfigBlasterFLE(in_args.host, in_args.port, in_args.cycles, in_args.threads, in_args.nodes,
122 in_args.flows, in_args.startflow)
124 # Run through <cycles>, where <threads> are started in each cycle and <flows> are added from each thread
127 print '\n*** Total flows added: %s' % fct.get_total_flows()
128 print ' HTTP[OK] results: %d\n' % fct.get_ok_flows()
130 if in_args.delay > 0:
131 print '*** Waiting for %d seconds before the delete cycle ***\n' % in_args.delay
132 time.sleep(in_args.delay)
134 # Run through <cycles>, where <threads> are started in each cycle and <flows> previously added in an add cycle are
135 # deleted in each thread