Masayoshi Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 1 | #! /usr/bin/env python |
| 2 | import json |
| 3 | import sys |
| 4 | import os |
| 5 | import re |
| 6 | from check_status import * |
| 7 | import time |
| 8 | |
Masayoshi Kobayashi | a85ae64 | 2013-04-08 09:39:37 +0000 | [diff] [blame] | 9 | basename=os.getenv("ONOS_CLUSTER_BASENAME") |
Masayoshi Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 10 | operation=["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 Kobayashi | a85ae64 | 2013-04-08 09:39:37 +0000 | [diff] [blame] | 11 | wait1=30 |
| 12 | wait2=60 |
Masayoshi Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 13 | |
| 14 | def check_by_pingall(): |
| 15 | buf = "" |
Masayoshi Kobayashi | bdbf22d | 2013-04-08 07:44:11 +0000 | [diff] [blame] | 16 | cmd = "pingall-speedup.sh %s" % (flowdef) |
Masayoshi Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 17 | 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 | |
| 25 | def link_change_core(op): |
| 26 | cmd = "dsh -w %s1 \"sudo ifconfig %s\"" % (basename, op) |
| 27 | os.popen(cmd) |
| 28 | print cmd |
| 29 | |
| 30 | def 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 | |
| 38 | def 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 | |
| 45 | def 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 Kobayashi | bdbf22d | 2013-04-08 07:44:11 +0000 | [diff] [blame] | 54 | def dump_flowgetall(tag): |
| 55 | url="http://%s:%s/wm/flow/getall/json" % (RestIP, RestPort) |
| 56 | filename = "rest-flow-getall-log.%s.log" % tag |
Masayoshi Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 57 | dump_json(url, filename) |
| 58 | |
Masayoshi Kobayashi | bdbf22d | 2013-04-08 07:44:11 +0000 | [diff] [blame] | 59 | def 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 Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 68 | url = "http://%s:%s/wm/core/topology/links/json" % (RestIP, RestPort) |
Masayoshi Kobayashi | bdbf22d | 2013-04-08 07:44:11 +0000 | [diff] [blame] | 69 | filename = "rest-link-log.%s.log" % tag |
Masayoshi Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 70 | dump_json(url, filename) |
| 71 | |
| 72 | url = "http://%s:%s/wm/registry/switches/json" % (RestIP, RestPort) |
Masayoshi Kobayashi | bdbf22d | 2013-04-08 07:44:11 +0000 | [diff] [blame] | 73 | filename = "rest-reg-sw-log.%s.log" % tag |
Masayoshi Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 74 | dump_json(url, filename) |
| 75 | |
| 76 | url = "http://%s:%s/wm/registry/controllers/json" % (RestIP, RestPort) |
Masayoshi Kobayashi | bdbf22d | 2013-04-08 07:44:11 +0000 | [diff] [blame] | 77 | filename = "rest-reg-ctrl-log.%s.log" % tag |
Masayoshi Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 78 | dump_json(url, filename) |
| 79 | |
| 80 | url = "http://%s:%s/wm/flow/getsummary/0/0/json" % (RestIP, RestPort) |
Masayoshi Kobayashi | bdbf22d | 2013-04-08 07:44:11 +0000 | [diff] [blame] | 81 | filename = "rest-flow-getsummary-log.%s.log" % tag |
Masayoshi Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 82 | dump_json(url, filename) |
| 83 | |
Masayoshi Kobayashi | bdbf22d | 2013-04-08 07:44:11 +0000 | [diff] [blame] | 84 | |
| 85 | def check_and_log(tag): |
Masayoshi Kobayashi | a85ae64 | 2013-04-08 09:39:37 +0000 | [diff] [blame] | 86 | global cur_nr_controllers |
| 87 | buf = "" |
| 88 | buf += "check by pingall\n" |
Masayoshi Kobayashi | bdbf22d | 2013-04-08 07:44:11 +0000 | [diff] [blame] | 89 | (code, result) = check_by_pingall() |
| 90 | if code == 0: |
Masayoshi Kobayashi | a85ae64 | 2013-04-08 09:39:37 +0000 | [diff] [blame] | 91 | buf += "ping success %s\n" % (result) |
Masayoshi Kobayashi | bdbf22d | 2013-04-08 07:44:11 +0000 | [diff] [blame] | 92 | else: |
Masayoshi Kobayashi | a85ae64 | 2013-04-08 09:39:37 +0000 | [diff] [blame] | 93 | buf += "pingall failed\n" |
| 94 | buf += "%s\n" % (result) |
Masayoshi Kobayashi | bdbf22d | 2013-04-08 07:44:11 +0000 | [diff] [blame] | 95 | 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 Kobayashi | a85ae64 | 2013-04-08 09:39:37 +0000 | [diff] [blame] | 110 | ferror.write(check_controllers(cur_nr_controllers)[1]) |
Masayoshi Kobayashi | bdbf22d | 2013-04-08 07:44:11 +0000 | [diff] [blame] | 111 | ferror.close() |
| 112 | |
Masayoshi Kobayashi | a85ae64 | 2013-04-08 09:39:37 +0000 | [diff] [blame] | 113 | return (code, buf) |
Masayoshi Kobayashi | bdbf22d | 2013-04-08 07:44:11 +0000 | [diff] [blame] | 114 | |
Masayoshi Kobayashi | a85ae64 | 2013-04-08 09:39:37 +0000 | [diff] [blame] | 115 | def plog(string): |
| 116 | global logf |
| 117 | print string |
| 118 | logf.write(string+"\n") |
Masayoshi Kobayashi | bdbf22d | 2013-04-08 07:44:11 +0000 | [diff] [blame] | 119 | |
Masayoshi Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 120 | if __name__ == "__main__": |
Masayoshi Kobayashi | a85ae64 | 2013-04-08 09:39:37 +0000 | [diff] [blame] | 121 | 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 Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 147 | (code, result) = check_by_pingall() |
Masayoshi Kobayashi | a85ae64 | 2013-04-08 09:39:37 +0000 | [diff] [blame] | 148 | |
| 149 | plog(result) |
| 150 | |
Masayoshi Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 151 | print result |
| 152 | k = raw_input('hit any key>') |
| 153 | |
Masayoshi Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 154 | for cycle in range(1000): |
| 155 | for n, op in enumerate(operation): |
Masayoshi Kobayashi | a85ae64 | 2013-04-08 09:39:37 +0000 | [diff] [blame] | 156 | plog("==== Cycle %d operation %d ====: %s" % (cycle, n, os.popen('date').read())) |
Masayoshi Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 157 | link_change_core(op) |
Masayoshi Kobayashi | a85ae64 | 2013-04-08 09:39:37 +0000 | [diff] [blame] | 158 | 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 Kobayashi | bdbf22d | 2013-04-08 07:44:11 +0000 | [diff] [blame] | 172 | if not code == 0: |
Masayoshi Kobayashi | a85ae64 | 2013-04-08 09:39:37 +0000 | [diff] [blame] | 173 | 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 Kobayashi | bdbf22d | 2013-04-08 07:44:11 +0000 | [diff] [blame] | 180 | 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 Kobayashi | a85ae64 | 2013-04-08 09:39:37 +0000 | [diff] [blame] | 187 | logf.close() |