blob: 8889c1fdb13cf49b877de86d8e3683b954a0153a [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")
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +000010operation=["sw3-eth4 down","sw4-eth4 down","sw4-eth3 down","sw3-eth4 up","sw1-eth2 down","sw4-eth4 up","sw4-eth3 up","sw1-eth2 up"]
Masayoshi Kobayashia85ae642013-04-08 09:39:37 +000011wait1=30
12wait2=60
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +000013
14def check_by_pingall():
15 buf = ""
Masayoshi Kobayashibdbf22d2013-04-08 07:44:11 +000016 cmd = "pingall-speedup.sh %s" % (flowdef)
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +000017 result = os.popen(cmd).read()
18 buf += result
19
20 if re.search("fail 0", result):
21 return (0, buf)
22 else:
23 return (1, buf)
24
25def link_change_core(op):
26 cmd = "dsh -w %s1 \"sudo ifconfig %s\"" % (basename, op)
27 os.popen(cmd)
28 print cmd
29
30def check_flow_nmap():
31 buf = ""
32 buf += os.popen("date").read()
33 print "dump all flows from network map"
34 cmd = "dsh -w %s1 \"cd ONOS/web; ./get_flow.py all\"" % cluster_basename
35 buf += os.popen(cmd).read()
36 return (0, buf)
37
38def check_flow_raw():
39 buf = ""
40 print "dump all flows from switches"
41 cmd = "dsh \"cd ONOS/scripts; ./showflow.sh\""
42 buf += os.popen(cmd).read()
43 return (0, buf)
44
45def dump_json(url, filename):
46 f = open(filename, 'w')
47 buf = ""
48 command = "curl -s %s" % (url)
49 result = os.popen(command).read()
50 buf += json.dumps(json.loads(result), sort_keys = True, indent = 2)
51 f.write(buf)
52 f.close()
53
Masayoshi Kobayashibdbf22d2013-04-08 07:44:11 +000054def dump_flowgetall(tag):
55 url="http://%s:%s/wm/flow/getall/json" % (RestIP, RestPort)
56 filename = "rest-flow-getall-log.%s.log" % tag
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +000057 dump_json(url, filename)
58
Masayoshi Kobayashibdbf22d2013-04-08 07:44:11 +000059def check_rest(tag):
60 url="http://%s:%s/wm/flow/getall/json" % (RestIP, RestPort)
61 filename = "rest-flow-getall-log.%s.log" % tag
62 dump_json(url, filename)
63
64 url="http://%s:%s/wm/core/topology/switches/all/json" % (RestIP, RestPort)
65 filename = "rest-sw-log.%s.log" % tag
66 dump_json(url, filename)
67
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +000068 url = "http://%s:%s/wm/core/topology/links/json" % (RestIP, RestPort)
Masayoshi Kobayashibdbf22d2013-04-08 07:44:11 +000069 filename = "rest-link-log.%s.log" % tag
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +000070 dump_json(url, filename)
71
72 url = "http://%s:%s/wm/registry/switches/json" % (RestIP, RestPort)
Masayoshi Kobayashibdbf22d2013-04-08 07:44:11 +000073 filename = "rest-reg-sw-log.%s.log" % tag
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +000074 dump_json(url, filename)
75
76 url = "http://%s:%s/wm/registry/controllers/json" % (RestIP, RestPort)
Masayoshi Kobayashibdbf22d2013-04-08 07:44:11 +000077 filename = "rest-reg-ctrl-log.%s.log" % tag
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +000078 dump_json(url, filename)
79
80 url = "http://%s:%s/wm/flow/getsummary/0/0/json" % (RestIP, RestPort)
Masayoshi Kobayashibdbf22d2013-04-08 07:44:11 +000081 filename = "rest-flow-getsummary-log.%s.log" % tag
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +000082 dump_json(url, filename)
83
Masayoshi Kobayashibdbf22d2013-04-08 07:44:11 +000084
85def check_and_log(tag):
Masayoshi Kobayashia85ae642013-04-08 09:39:37 +000086 global cur_nr_controllers
87 buf = ""
88 buf += "check by pingall\n"
Masayoshi Kobayashibdbf22d2013-04-08 07:44:11 +000089 (code, result) = check_by_pingall()
90 if code == 0:
Masayoshi Kobayashia85ae642013-04-08 09:39:37 +000091 buf += "ping success %s\n" % (result)
Masayoshi Kobayashibdbf22d2013-04-08 07:44:11 +000092 else:
Masayoshi Kobayashia85ae642013-04-08 09:39:37 +000093 buf += "pingall failed\n"
94 buf += "%s\n" % (result)
Masayoshi Kobayashibdbf22d2013-04-08 07:44:11 +000095 error = "error-log.%s.log" % tag
96 rawflow = "raw-flow-log.%s.log" % tag
97
98 ferror = open(error, 'w')
99 ferror.write(result)
100
101 fraw = open(rawflow,'w')
102 fraw.write(check_flow_raw()[1])
103 fraw.close()
104
105 check_rest(tag)
106
107 ferror.write(check_switch()[1])
108 ferror.write(check_link()[1])
109 ferror.write(check_switch_local()[1])
Masayoshi Kobayashia85ae642013-04-08 09:39:37 +0000110 ferror.write(check_controllers(cur_nr_controllers)[1])
Masayoshi Kobayashibdbf22d2013-04-08 07:44:11 +0000111 ferror.close()
112
Masayoshi Kobayashia85ae642013-04-08 09:39:37 +0000113 return (code, buf)
Masayoshi Kobayashibdbf22d2013-04-08 07:44:11 +0000114
Masayoshi Kobayashia85ae642013-04-08 09:39:37 +0000115def plog(string):
116 global logf
117 print string
118 logf.write(string+"\n")
Masayoshi Kobayashibdbf22d2013-04-08 07:44:11 +0000119
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +0000120if __name__ == "__main__":
Masayoshi Kobayashia85ae642013-04-08 09:39:37 +0000121 global logf, cur_nr_controllers
122
123 cur_nr_controllers = 8
124
125 argvs = sys.argv
126 if len(argvs) == 5:
127 log_filename = sys.argv[1]
128 flowdef = sys.argv[2]
129 wait1 = int(sys.argv[3])
130 wait2 = int(sys.argv[4])
131 else:
132 print "usage: %s log_filename flowdef_filename wait1 wait2" % sys.argv[0]
133 print " wait1: wait time (sec) to check ping after change"
134 print " wait2: additional wait time (sec) if the first check failed"
135 sys.exit(1)
136
137 logf = open(log_filename, 'w', 0)
138
139 plog("flow def: %s" % flowdef)
140 plog("wait1 : %d" % wait1)
141 plog("wait2 : %d" % wait2)
142
143 plog(check_switch()[1])
144 plog(check_link()[1])
145 plog(check_controllers(cur_nr_controllers)[1])
146
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +0000147 (code, result) = check_by_pingall()
Masayoshi Kobayashia85ae642013-04-08 09:39:37 +0000148
149 plog(result)
150
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +0000151 print result
152 k = raw_input('hit any key>')
153
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +0000154 for cycle in range(1000):
155 for n, op in enumerate(operation):
Masayoshi Kobayashia85ae642013-04-08 09:39:37 +0000156 plog("==== Cycle %d operation %d ====: %s" % (cycle, n, os.popen('date').read()))
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +0000157 link_change_core(op)
Masayoshi Kobayashia85ae642013-04-08 09:39:37 +0000158 plog(op)
159
160 plog("wait %d sec" % wait1)
161 time.sleep(wait1)
162 plog("check and log: %s" % os.popen('date').read())
163
164 tstart=int(time.time())
165 (code, result) = check_and_log("%d.%d.1" % (cycle,n))
166 plog(result)
167 plog("done: %s" % os.popen('date').read())
168 tend=int(time.time())
169
170 tdelta=tend-tstart
171
Masayoshi Kobayashibdbf22d2013-04-08 07:44:11 +0000172 if not code == 0:
Masayoshi Kobayashia85ae642013-04-08 09:39:37 +0000173 wait = max(0, wait2 - tdelta)
174 plog("took %d sec for check and log. wait another %d sec" % (tdelta, wait))
175 time.sleep(wait)
176 plog("check and log: %s" % os.popen('date').read())
177 (code, result) = check_and_log("%d.%d.2" % (cycle,n))
178 plog(result)
179 plog("done: %s" % os.popen('date').read())
Masayoshi Kobayashibdbf22d2013-04-08 07:44:11 +0000180 if code == 0:
181 tag = "%d.%d.2" % (cycle,n)
182 dump_flowgetall(tag)
183 rawflow = "raw-flow-log.%s.log" % tag
184 fraw = open(rawflow,'w')
185 fraw.write(check_flow_raw()[1])
186 fraw.close()
Masayoshi Kobayashia85ae642013-04-08 09:39:37 +0000187 logf.close()