3 __author__ = "Jan Medved"
4 __copyright__ = "Copyright(c) 2014, Cisco Systems, Inc."
5 __license__ = "New-style BSD"
6 __email__ = "jmedved@cisco.com"
10 from flow_config_blaster import FlowConfigBlaster, get_json_from_file
11 from inventory_crawler import InventoryCrawler
12 from config_cleanup import cleanup_config_odl
15 def wait_for_stats(crawler, exp_found, timeout, delay):
17 Waits for the ODL stats manager to catch up. Polls ODL inventory every
18 <delay> seconds and compares the retrieved stats to the expected values. If
19 stats collection has not finished within <timeout> seconds, the test is
21 :param crawler: Inventory crawler object
22 :param exp_found: Expected value for flows found in the network
23 :param timeout: Max number of seconds to wait for stats collector to
25 :param delay: poll interval for inventory
29 print 'Waiting for stats to catch up:'
31 crawler.crawl_inventory()
32 print ' %d, %d' % (crawler.reported_flows, crawler.found_flows)
33 if crawler.found_flows == exp_found or total_delay > timeout:
38 if total_delay < timeout:
39 print 'Stats collected in %d seconds.' % total_delay
41 print 'Stats collection did not finish in %d seconds. Aborting...' % total_delay
44 if __name__ == "__main__":
45 ############################################################################
46 # This program executes an ODL performance test. The test is executed in
49 # 1. The specified number of flows is added in the 'add cycle' (uses
50 # flow_config_blaster to blast flows)
51 # 2. The network is polled for flow statistics from the network (using the
52 # inventory_crawler.py script) to make sure that all flows have been
53 # properly programmed into the network and the ODL statistics collector
54 # can properly read them
55 # 3. The flows are deleted in the flow cycle. Deletion happens either in
56 # 'bulk' (using the config_cleanup) script or one by one (using the
57 # flow_config_blaster 'delete' method)
58 ############################################################################
60 parser = argparse.ArgumentParser(description='Flow programming performance test: First adds and then deletes flows '
61 'into the config tree, as specified by optional parameters.')
63 parser.add_argument('--host', default='127.0.0.1',
64 help='Host where odl controller is running (default is 127.0.0.1)')
65 parser.add_argument('--port', default='8181',
66 help='Port on which odl\'s RESTCONF is listening (default is 8181)')
67 parser.add_argument('--cycles', type=int, default=1,
68 help='Number of flow add/delete cycles; default 1. Both Flow Adds and Flow Deletes are '
69 'performed in cycles. <THREADS> worker threads are started in each cycle and the cycle '
70 'ends when all threads finish. Another cycle is started when the previous cycle finished.')
71 parser.add_argument('--threads', type=int, default=1,
72 help='Number of request worker threads to start in each cycle; default=1. '
73 'Each thread will add/delete <FLOWS> flows.')
74 parser.add_argument('--flows', type=int, default=10,
75 help='Number of flows that will be added/deleted by each worker thread in each cycle; '
77 parser.add_argument('--fpr', type=int, default=1,
78 help='Flows-per-Request - number of flows (batch size) sent in each HTTP request; '
80 parser.add_argument('--delay', type=int, default=2,
81 help='Time (seconds) to between inventory polls when waiting for stats to catch up; default=1')
82 parser.add_argument('--timeout', type=int, default=100,
83 help='The maximum time (seconds) to wait between the add and delete cycles; default=100')
84 parser.add_argument('--delete', dest='delete', action='store_true', default=True,
85 help='Delete all added flows one by one, benchmark delete '
87 parser.add_argument('--bulk-delete', dest='bulk_delete', action='store_true', default=False,
88 help='Delete all flows in bulk; default=False')
89 parser.add_argument('--auth', dest='auth', action='store_true',
90 help="Use authenticated access to REST (username: 'admin', password: 'admin'); default=False")
91 parser.add_argument('--startflow', type=int, default=0,
92 help='The starting Flow ID; default=0')
93 parser.add_argument('--file', default='',
94 help='File from which to read the JSON flow template; default: no file, use a built in '
97 in_args = parser.parse_args()
100 if in_args.file != '':
101 flow_template = get_json_from_file(in_args.file)
105 ic = InventoryCrawler(in_args.host, in_args.port, 0, 'operational', in_args.auth, False)
107 fct = FlowConfigBlaster(in_args.host, in_args.port, in_args.cycles, in_args.threads, in_args.fpr,
108 16, in_args.flows, in_args.startflow, in_args.auth)
109 # Get the baseline stats. Required in Step 3 to validate if the delete
110 # function gets the controller back to the baseline
112 reported = ic.reported_flows
113 found = ic.found_flows
116 print ' Reported flows: %d' % reported
117 print ' Found flows: %d' % found
119 # Run through <CYCLES> add cycles, where <THREADS> threads are started in
120 # each cycle and <FLOWS> flows are added from each thread
123 print '\n*** Total flows added: %d' % fct.get_ok_flows()
124 print ' HTTP[OK] results: %d\n' % fct.get_ok_rqsts()
126 # Wait for stats to catch up
127 wait_for_stats(ic, found + fct.get_ok_flows(), in_args.timeout, in_args.delay)
129 # Run through <CYCLES> delete cycles, where <THREADS> threads are started
130 # in each cycle and <FLOWS> flows previously added in an add cycle are
131 # deleted in each thread
132 if in_args.bulk_delete:
133 print '\nDeleting all flows in bulk:'
134 sts = cleanup_config_odl(in_args.host, in_args.port, in_args.auth)
136 print ' Failed to delete flows, code %d' % sts
138 print ' All flows deleted.'
140 print '\nDeleting flows one by one\n ',
142 print '\n*** Total flows deleted: %d' % fct.get_ok_flows()
143 print ' HTTP[OK] results: %d\n' % fct.get_ok_rqsts()
145 # Wait for stats to catch up back to baseline
146 wait_for_stats(ic, found, in_args.timeout, in_args.delay)