Performance scripts modifications. Added 2 scripts, modified 2 scripts.
[integration.git] / test / tools / odl-mdsal-clustering-tests / clustering-performance-test / flow_add_delete_test.py
1 #!/usr/bin/python
2
3 __author__ = "Jan Medved"
4 __copyright__ = "Copyright(c) 2014, Cisco Systems, Inc."
5 __license__ = "New-style BSD"
6 __email__ = "jmedved@cisco.com"
7
8 import argparse
9 import time
10 from flow_config_blaster import FlowConfigBlaster
11 from inventory_crawler import InventoryCrawler
12 from config_cleanup import cleanup_config
13
14
15
16 if __name__ == "__main__":
17
18     JSON_FLOW_MOD1 = '''{
19         "flow-node-inventory:flow": [
20             {
21                 "flow-node-inventory:cookie": %d,
22                 "flow-node-inventory:cookie_mask": 65535,
23                 "flow-node-inventory:flow-name": "%s",
24                 "flow-node-inventory:hard-timeout": %d,
25                 "flow-node-inventory:id": "%s",
26                 "flow-node-inventory:idle-timeout": %d,
27                 "flow-node-inventory:installHw": false,
28                 "flow-node-inventory:instructions": {
29                     "flow-node-inventory:instruction": [
30                         {
31                             "flow-node-inventory:apply-actions": {
32                                 "flow-node-inventory:action": [
33                                     {
34                                         "flow-node-inventory:drop-action": {},
35                                         "flow-node-inventory:order": 0
36                                     }
37                                 ]
38                             },
39                             "flow-node-inventory:order": 0
40                         }
41                     ]
42                 },
43                 "flow-node-inventory:match": {
44                     "flow-node-inventory:ipv4-destination": "%s/32",
45                     "flow-node-inventory:ethernet-match": {
46                         "flow-node-inventory:ethernet-type": {
47                             "flow-node-inventory:type": 2048
48                         }
49                     }
50                 },
51                 "flow-node-inventory:priority": 2,
52                 "flow-node-inventory:strict": false,
53                 "flow-node-inventory:table_id": 0
54             }
55         ]
56     }'''
57
58
59     parser = argparse.ArgumentParser(description='Flow programming performance test: First adds and then deletes flows '
60                                                  'into the config tree, as specified by optional parameters.')
61
62     parser.add_argument('--host', default='127.0.0.1',
63                         help='Host where odl controller is running (default is 127.0.0.1)')
64     parser.add_argument('--port', default='8181',
65                         help='Port on which odl\'s RESTCONF is listening (default is 8181)')
66     parser.add_argument('--flows', type=int, default=10,
67                         help='Number of flow add/delete requests to send in each cycle; default 10')
68     parser.add_argument('--cycles', type=int, default=1,
69                         help='Number of flow add/delete cycles to send in each thread; default 1')
70     parser.add_argument('--threads', type=int, default=1,
71                         help='Number of request worker threads, default=1. '
72                              'Each thread will add/delete nflows.')
73     parser.add_argument('--nodes', type=int, default=16,
74                         help='Number of nodes if mininet is not connected; default=16. If mininet is connected, '
75                              'flows will be evenly distributed (programmed) into connected nodes.')
76     parser.add_argument('--delay', type=int, default=2,
77                         help='Time to wait between the add and delete cycles; default=0')
78     parser.add_argument('--timeout', type=int, default=100,
79                         help='The maximum time to wait between the add and delete cycles; default=100')
80     parser.add_argument('--delete', dest='delete', action='store_true', default=True,
81                         help='Delete all added flows one by one, benchmark delete '
82                              'performance.')
83     parser.add_argument('--bulk-delete', dest='bulk_delete', action='store_true', default=False,
84                         help='Delete all flows in bulk; default=False')
85     parser.add_argument('--auth', dest='auth', action='store_true',
86                         help="Use authenticated access to REST (username: 'admin', password: 'admin'); default=False")
87     parser.add_argument('--startflow', type=int, default=0,
88                         help='The starting Flow ID; default=0')
89
90     in_args = parser.parse_args()
91
92     # Initialize
93     ic = InventoryCrawler(in_args.host, in_args.port, 0, 'operational', in_args.auth, False)
94
95     fct = FlowConfigBlaster(in_args.host, in_args.port, in_args.cycles, in_args.threads, in_args.nodes,
96                             in_args.flows, in_args.startflow, in_args.auth, JSON_FLOW_MOD1)
97
98     # Get baseline stats
99     ic.crawl_inventory()
100     reported = ic.reported_flows
101     found = ic.found_flows
102
103     print 'Baseline:'
104     print '   Reported nodes: %d' % reported
105     print '   Found nodes:    %d' % found
106
107     # Run through <cycles>, where <threads> are started in each cycle and <flows> are added from each thread
108     fct.add_blaster()
109
110     print '\n*** Total flows added: %s' % fct.get_total_flows()
111     print '    HTTP[OK] results:  %d\n' % fct.get_ok_flows()
112
113     # Wait for stats to catch up
114     total_delay = 0
115     exp_found = found + fct.get_ok_flows()
116     exp_reported = reported + fct.get_ok_flows()
117
118     print 'Waiting for stats to catch up:'
119     while True:
120         ic.crawl_inventory()
121         print '   %d, %d' %(ic.reported_flows, ic.found_flows)
122         if ic.found_flows == exp_found or total_delay > in_args.timeout:
123             break
124         total_delay += in_args.delay
125         time.sleep(in_args.delay)
126
127     if total_delay < in_args.timeout:
128         print 'Stats collected in %d seconds.' % total_delay
129     else:
130         print 'Stats collection did not finish in %d seconds. Aborting...' % total_delay
131
132     # Run through <cycles>, where <threads> are started in each cycle and <flows> previously added in an add cycle are
133     # deleted in each thread
134     if in_args.bulk_delete:
135         print '\nDeleting all flows in bulk:\n   ',
136         cleanup_config(in_args.host, in_args.port, in_args.auth)
137     else:
138        print '\nDeleting flows one by one\n   ',
139        fct.delete_blaster()
140
141     # Wait for stats to catch up
142     total_delay = 0
143
144     print '\nWaiting for stats to catch up:'
145     while True:
146         ic.crawl_inventory()
147         if ic.found_flows == found or total_delay > in_args.timeout:
148             break
149         total_delay += in_args.delay
150         print '   %d, %d' %(ic.reported_flows, ic.found_flows)
151         time.sleep(in_args.delay)
152
153     if total_delay < in_args.timeout:
154         print 'Stats collected in %d seconds.' % total_delay
155     else:
156         print 'Stats collection did not finish in %d seconds. Aborting...' % total_delay