blob: 62c3933c70fbcd3f565d059c92b28cff2f8d249e [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
9flowdef="flowdef_8node_252.txt"
Masayoshi Kobayashibdbf22d2013-04-08 07:44:11 +000010basename="onosdevt"
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +000011operation=["sw3-eth4 down","sw4-eth4 down","sw4-eth3 down","sw3-eth4 up","sw1-eth2 down","sw4-eth4 up","sw4-eth3 up","sw1-eth2 up"]
12
13def check_by_pingall():
14 buf = ""
Masayoshi Kobayashibdbf22d2013-04-08 07:44:11 +000015 cmd = "pingall-speedup.sh %s" % (flowdef)
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +000016 result = os.popen(cmd).read()
17 buf += result
18
19 if re.search("fail 0", result):
20 return (0, buf)
21 else:
22 return (1, buf)
23
24def link_change_core(op):
25 cmd = "dsh -w %s1 \"sudo ifconfig %s\"" % (basename, op)
26 os.popen(cmd)
27 print cmd
28
29def check_flow_nmap():
30 buf = ""
31 buf += os.popen("date").read()
32 print "dump all flows from network map"
33 cmd = "dsh -w %s1 \"cd ONOS/web; ./get_flow.py all\"" % cluster_basename
34 buf += os.popen(cmd).read()
35 return (0, buf)
36
37def check_flow_raw():
38 buf = ""
39 print "dump all flows from switches"
40 cmd = "dsh \"cd ONOS/scripts; ./showflow.sh\""
41 buf += os.popen(cmd).read()
42 return (0, buf)
43
44def dump_json(url, filename):
45 f = open(filename, 'w')
46 buf = ""
47 command = "curl -s %s" % (url)
48 result = os.popen(command).read()
49 buf += json.dumps(json.loads(result), sort_keys = True, indent = 2)
50 f.write(buf)
51 f.close()
52
Masayoshi Kobayashibdbf22d2013-04-08 07:44:11 +000053def dump_flowgetall(tag):
54 url="http://%s:%s/wm/flow/getall/json" % (RestIP, RestPort)
55 filename = "rest-flow-getall-log.%s.log" % tag
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +000056 dump_json(url, filename)
57
Masayoshi Kobayashibdbf22d2013-04-08 07:44:11 +000058def check_rest(tag):
59 url="http://%s:%s/wm/flow/getall/json" % (RestIP, RestPort)
60 filename = "rest-flow-getall-log.%s.log" % tag
61 dump_json(url, filename)
62
63 url="http://%s:%s/wm/core/topology/switches/all/json" % (RestIP, RestPort)
64 filename = "rest-sw-log.%s.log" % tag
65 dump_json(url, filename)
66
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +000067 url = "http://%s:%s/wm/core/topology/links/json" % (RestIP, RestPort)
Masayoshi Kobayashibdbf22d2013-04-08 07:44:11 +000068 filename = "rest-link-log.%s.log" % tag
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +000069 dump_json(url, filename)
70
71 url = "http://%s:%s/wm/registry/switches/json" % (RestIP, RestPort)
Masayoshi Kobayashibdbf22d2013-04-08 07:44:11 +000072 filename = "rest-reg-sw-log.%s.log" % tag
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +000073 dump_json(url, filename)
74
75 url = "http://%s:%s/wm/registry/controllers/json" % (RestIP, RestPort)
Masayoshi Kobayashibdbf22d2013-04-08 07:44:11 +000076 filename = "rest-reg-ctrl-log.%s.log" % tag
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +000077 dump_json(url, filename)
78
79 url = "http://%s:%s/wm/flow/getsummary/0/0/json" % (RestIP, RestPort)
Masayoshi Kobayashibdbf22d2013-04-08 07:44:11 +000080 filename = "rest-flow-getsummary-log.%s.log" % tag
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +000081 dump_json(url, filename)
82
Masayoshi Kobayashibdbf22d2013-04-08 07:44:11 +000083
84def check_and_log(tag):
85 print "check by pingall"
86 (code, result) = check_by_pingall()
87 if code == 0:
88 print "ping success %s" % (result)
89 else:
90 print "pingall failed"
91 print "%s" % (result)
92 error = "error-log.%s.log" % tag
93 rawflow = "raw-flow-log.%s.log" % tag
94
95 ferror = open(error, 'w')
96 ferror.write(result)
97
98 fraw = open(rawflow,'w')
99 fraw.write(check_flow_raw()[1])
100 fraw.close()
101
102 check_rest(tag)
103
104 ferror.write(check_switch()[1])
105 ferror.write(check_link()[1])
106 ferror.write(check_switch_local()[1])
107 ferror.write(check_controllers(8)[1])
108 ferror.close()
109
110 return code
111
112
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +0000113if __name__ == "__main__":
114 print "%s" % check_switch()[1]
115 print "%s" % check_link()[1]
116 print "%s" % check_controllers(8)[1]
117 (code, result) = check_by_pingall()
118 print result
119 k = raw_input('hit any key>')
120
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +0000121 for cycle in range(1000):
122 for n, op in enumerate(operation):
Masayoshi Kobayashibdbf22d2013-04-08 07:44:11 +0000123 print "==== Cycle %d operation %d ====: %s" % (cycle, n, os.popen('date').read())
Masayoshi Kobayashie4a551d2013-04-07 04:56:09 +0000124 link_change_core(op)
125 print "wait 30 sec"
126 time.sleep(30)
Masayoshi Kobayashibdbf22d2013-04-08 07:44:11 +0000127 print "check and log: %s" % os.popen('date').read()
128 code = check_and_log("%d.%d.1" % (cycle,n))
129 print "done: %s" % os.popen('date').read()
130 if not code == 0:
131 print "wait another 60 sec"
132 time.sleep(60)
133 print "check and log: %s" % os.popen('date').read()
134 code = check_and_log("%d.%d.2" % (cycle,n))
135 print "done: %s" % os.popen('date').read()
136 if code == 0:
137 tag = "%d.%d.2" % (cycle,n)
138 dump_flowgetall(tag)
139 rawflow = "raw-flow-log.%s.log" % tag
140 fraw = open(rawflow,'w')
141 fraw.write(check_flow_raw()[1])
142 fraw.close()