blob: 04f83c509e783a44487a9c45fe0e04c5b21b006b [file] [log] [blame]
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +00001#! /usr/bin/env python
2import json
3import sys
4import os
5import re
6from check_status import *
7import time
8
Masayoshi Kobayashia85ae642013-04-08 09:39:37 +00009basename=os.getenv("ONOS_CLUSTER_BASENAME")
10operation=['switch all', 'onos stop 8', 'onos stop 7', 'onos stop 6', 'onos stop 5', 'onos start 5;onos start 6;onos start 7;onos start 8', 'switch local']
11nr_controllers=[8, 7, 6, 5, 4, 8, 8]
12
13wait1=30
14wait2=60
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +000015
16def check_by_pingall():
17 buf = ""
Masayoshi Kobayashia85ae642013-04-08 09:39:37 +000018 cmd = "pingall-speedup.sh %s" % (flowdef)
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +000019 result = os.popen(cmd).read()
20 buf += result
21
22 if re.search("fail 0", result):
23 return (0, buf)
24 else:
25 return (1, buf)
26
27def link_change_core(op):
28 cmd = "dsh -w %s1 \"sudo ifconfig %s\"" % (basename, op)
29 os.popen(cmd)
30 print cmd
31
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +000032def check_flow_nmap():
33 buf = ""
34 buf += os.popen("date").read()
35 print "dump all flows from network map"
36 cmd = "dsh -w %s1 \"cd ONOS/web; ./get_flow.py all\"" % cluster_basename
37 buf += os.popen(cmd).read()
38 return (0, buf)
39
40def check_flow_raw():
41 buf = ""
42 print "dump all flows from switches"
43 cmd = "dsh \"cd ONOS/scripts; ./showflow.sh\""
44 buf += os.popen(cmd).read()
45 return (0, buf)
46
47def dump_json(url, filename):
48 f = open(filename, 'w')
49 buf = ""
50 command = "curl -s %s" % (url)
51 result = os.popen(command).read()
52 buf += json.dumps(json.loads(result), sort_keys = True, indent = 2)
53 f.write(buf)
54 f.close()
55
Masayoshi Kobayashia85ae642013-04-08 09:39:37 +000056def dump_flowgetall(tag):
57 url="http://%s:%s/wm/flow/getall/json" % (RestIP, RestPort)
58 filename = "rest-flow-getall-log.%s.log" % tag
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +000059 dump_json(url, filename)
60
Masayoshi Kobayashia85ae642013-04-08 09:39:37 +000061def check_rest(tag):
62 url="http://%s:%s/wm/flow/getall/json" % (RestIP, RestPort)
63 filename = "rest-flow-getall-log.%s.log" % tag
64 dump_json(url, filename)
65
66 url="http://%s:%s/wm/core/topology/switches/all/json" % (RestIP, RestPort)
67 filename = "rest-sw-log.%s.log" % tag
68 dump_json(url, filename)
69
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +000070 url = "http://%s:%s/wm/core/topology/links/json" % (RestIP, RestPort)
Masayoshi Kobayashia85ae642013-04-08 09:39:37 +000071 filename = "rest-link-log.%s.log" % tag
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +000072 dump_json(url, filename)
73
74 url = "http://%s:%s/wm/registry/switches/json" % (RestIP, RestPort)
Masayoshi Kobayashia85ae642013-04-08 09:39:37 +000075 filename = "rest-reg-sw-log.%s.log" % tag
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +000076 dump_json(url, filename)
77
78 url = "http://%s:%s/wm/registry/controllers/json" % (RestIP, RestPort)
Masayoshi Kobayashia85ae642013-04-08 09:39:37 +000079 filename = "rest-reg-ctrl-log.%s.log" % tag
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +000080 dump_json(url, filename)
81
82 url = "http://%s:%s/wm/flow/getsummary/0/0/json" % (RestIP, RestPort)
Masayoshi Kobayashia85ae642013-04-08 09:39:37 +000083 filename = "rest-flow-getsummary-log.%s.log" % tag
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +000084 dump_json(url, filename)
85
86
Masayoshi Kobayashia85ae642013-04-08 09:39:37 +000087def check_and_log(tag):
88 global cur_nr_controllers
89 buf = ""
90 buf += "check by pingall\n"
91 (code, result) = check_by_pingall()
92 if code == 0:
93 buf += "ping success %s\n" % (result)
94 else:
95 buf += "pingall failed\n"
96 buf += "%s\n" % (result)
97 error = "error-log.%s.log" % tag
98 rawflow = "raw-flow-log.%s.log" % tag
99
100 ferror = open(error, 'w')
101 ferror.write(result)
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +0000102
Masayoshi Kobayashia85ae642013-04-08 09:39:37 +0000103 fraw = open(rawflow,'w')
104 fraw.write(check_flow_raw()[1])
105 fraw.close()
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +0000106
Masayoshi Kobayashia85ae642013-04-08 09:39:37 +0000107 check_rest(tag)
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +0000108
Masayoshi Kobayashia85ae642013-04-08 09:39:37 +0000109 ferror.write(check_switch()[1])
110 ferror.write(check_link()[1])
111 ferror.write(check_switch_local()[1])
112 ferror.write(check_controllers(cur_nr_controllers)[1])
113 ferror.close()
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +0000114
Masayoshi Kobayashia85ae642013-04-08 09:39:37 +0000115 return (code, buf)
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +0000116
Masayoshi Kobayashia85ae642013-04-08 09:39:37 +0000117def plog(string):
118 global logf
119 print string
120 logf.write(string+"\n")
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +0000121
122if __name__ == "__main__":
Masayoshi Kobayashia85ae642013-04-08 09:39:37 +0000123 global logf, cur_nr_controllers
124 argvs = sys.argv
125 if len(argvs) == 5:
126 log_filename = sys.argv[1]
127 flowdef = sys.argv[2]
128 wait1 = int(sys.argv[3])
129 wait2 = int(sys.argv[4])
130 else:
131 print "usage: %s log_filename flowdef_filename wait1 wait2" % sys.argv[0]
132 print " wait1: wait time (sec) to check ping after change"
133 print " wait2: additional wait time (sec) if the first check failed"
134 sys.exit(1)
135
136 logf = open(log_filename, 'w', 0)
137
138 plog("flow def: %s" % flowdef)
139 plog("wait1 : %d" % wait1)
140 plog("wait2 : %d" % wait2)
141
142 plog(check_switch()[1])
143 plog(check_link()[1])
144 plog(check_controllers(8)[1])
145
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +0000146 (code, result) = check_by_pingall()
Masayoshi Kobayashia85ae642013-04-08 09:39:37 +0000147
148 plog(result)
149
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +0000150 print result
151 k = raw_input('hit any key>')
152
153 for cycle in range(1000):
154 for n, op in enumerate(operation):
Masayoshi Kobayashia85ae642013-04-08 09:39:37 +0000155 plog("==== Cycle %d operation %d ====: %s" % (cycle, n, os.popen('date').read()))
156# link_change_core(op)
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +0000157 os.popen(op)
Masayoshi Kobayashia85ae642013-04-08 09:39:37 +0000158 plog(op)
159 cur_nr_controllers = nr_controllers[n]
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +0000160
Masayoshi Kobayashia85ae642013-04-08 09:39:37 +0000161 plog("wait %d sec" % wait1)
162 time.sleep(wait1)
163 plog("check and log: %s" % os.popen('date').read())
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +0000164
Masayoshi Kobayashia85ae642013-04-08 09:39:37 +0000165 tstart=int(time.time())
166 (code, result) = check_and_log("%d.%d.1" % (cycle,n))
167 plog(result)
168 plog("done: %s" % os.popen('date').read())
169 tend=int(time.time())
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +0000170
Masayoshi Kobayashia85ae642013-04-08 09:39:37 +0000171 tdelta=tend-tstart
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +0000172
Masayoshi Kobayashia85ae642013-04-08 09:39:37 +0000173 if not code == 0:
174 wait = max(0, wait2 - tdelta)
175 plog("took %d sec for check and log. wait another %d sec" % (tdelta, wait))
176 time.sleep(wait)
177 plog("check and log: %s" % os.popen('date').read())
178 (code, result) = check_and_log("%d.%d.2" % (cycle,n))
179 plog(result)
180 plog("done: %s" % os.popen('date').read())
181 if code == 0:
182 tag = "%d.%d.2" % (cycle,n)
183 dump_flowgetall(tag)
184 rawflow = "raw-flow-log.%s.log" % tag
185 fraw = open(rawflow,'w')
186 fraw.write(check_flow_raw()[1])
187 fraw.close()
188 logf.close()