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") |
| 10 | operation=['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'] |
| 11 | nr_controllers=[8, 7, 6, 5, 4, 8, 8] |
| 12 | |
| 13 | wait1=30 |
| 14 | wait2=60 |
Masayoshi Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 15 | |
| 16 | def check_by_pingall(): |
| 17 | buf = "" |
Masayoshi Kobayashi | a85ae64 | 2013-04-08 09:39:37 +0000 | [diff] [blame] | 18 | cmd = "pingall-speedup.sh %s" % (flowdef) |
Masayoshi Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 19 | 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 | |
| 27 | def link_change_core(op): |
| 28 | cmd = "dsh -w %s1 \"sudo ifconfig %s\"" % (basename, op) |
| 29 | os.popen(cmd) |
| 30 | print cmd |
| 31 | |
Masayoshi Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 32 | def 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 | |
| 40 | def 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 | |
| 47 | def 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 Kobayashi | a85ae64 | 2013-04-08 09:39:37 +0000 | [diff] [blame] | 56 | def dump_flowgetall(tag): |
| 57 | url="http://%s:%s/wm/flow/getall/json" % (RestIP, RestPort) |
| 58 | filename = "rest-flow-getall-log.%s.log" % tag |
Masayoshi Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 59 | dump_json(url, filename) |
| 60 | |
Masayoshi Kobayashi | a85ae64 | 2013-04-08 09:39:37 +0000 | [diff] [blame] | 61 | def 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 Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 70 | url = "http://%s:%s/wm/core/topology/links/json" % (RestIP, RestPort) |
Masayoshi Kobayashi | a85ae64 | 2013-04-08 09:39:37 +0000 | [diff] [blame] | 71 | filename = "rest-link-log.%s.log" % tag |
Masayoshi Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 72 | dump_json(url, filename) |
| 73 | |
| 74 | url = "http://%s:%s/wm/registry/switches/json" % (RestIP, RestPort) |
Masayoshi Kobayashi | a85ae64 | 2013-04-08 09:39:37 +0000 | [diff] [blame] | 75 | filename = "rest-reg-sw-log.%s.log" % tag |
Masayoshi Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 76 | dump_json(url, filename) |
| 77 | |
| 78 | url = "http://%s:%s/wm/registry/controllers/json" % (RestIP, RestPort) |
Masayoshi Kobayashi | a85ae64 | 2013-04-08 09:39:37 +0000 | [diff] [blame] | 79 | filename = "rest-reg-ctrl-log.%s.log" % tag |
Masayoshi Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 80 | dump_json(url, filename) |
| 81 | |
| 82 | url = "http://%s:%s/wm/flow/getsummary/0/0/json" % (RestIP, RestPort) |
Masayoshi Kobayashi | a85ae64 | 2013-04-08 09:39:37 +0000 | [diff] [blame] | 83 | filename = "rest-flow-getsummary-log.%s.log" % tag |
Masayoshi Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 84 | dump_json(url, filename) |
| 85 | |
| 86 | |
Masayoshi Kobayashi | a85ae64 | 2013-04-08 09:39:37 +0000 | [diff] [blame] | 87 | def 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 Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 102 | |
Masayoshi Kobayashi | a85ae64 | 2013-04-08 09:39:37 +0000 | [diff] [blame] | 103 | fraw = open(rawflow,'w') |
| 104 | fraw.write(check_flow_raw()[1]) |
| 105 | fraw.close() |
Masayoshi Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 106 | |
Masayoshi Kobayashi | a85ae64 | 2013-04-08 09:39:37 +0000 | [diff] [blame] | 107 | check_rest(tag) |
Masayoshi Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 108 | |
Masayoshi Kobayashi | a85ae64 | 2013-04-08 09:39:37 +0000 | [diff] [blame] | 109 | 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 Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 114 | |
Masayoshi Kobayashi | a85ae64 | 2013-04-08 09:39:37 +0000 | [diff] [blame] | 115 | return (code, buf) |
Masayoshi Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 116 | |
Masayoshi Kobayashi | a85ae64 | 2013-04-08 09:39:37 +0000 | [diff] [blame] | 117 | def plog(string): |
| 118 | global logf |
| 119 | print string |
| 120 | logf.write(string+"\n") |
Masayoshi Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 121 | |
| 122 | if __name__ == "__main__": |
Masayoshi Kobayashi | a85ae64 | 2013-04-08 09:39:37 +0000 | [diff] [blame] | 123 | 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 Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 146 | (code, result) = check_by_pingall() |
Masayoshi Kobayashi | a85ae64 | 2013-04-08 09:39:37 +0000 | [diff] [blame] | 147 | |
| 148 | plog(result) |
| 149 | |
Masayoshi Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 150 | print result |
| 151 | k = raw_input('hit any key>') |
| 152 | |
| 153 | for cycle in range(1000): |
| 154 | for n, op in enumerate(operation): |
Masayoshi Kobayashi | a85ae64 | 2013-04-08 09:39:37 +0000 | [diff] [blame] | 155 | plog("==== Cycle %d operation %d ====: %s" % (cycle, n, os.popen('date').read())) |
| 156 | # link_change_core(op) |
Masayoshi Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 157 | os.popen(op) |
Masayoshi Kobayashi | a85ae64 | 2013-04-08 09:39:37 +0000 | [diff] [blame] | 158 | plog(op) |
| 159 | cur_nr_controllers = nr_controllers[n] |
Masayoshi Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 160 | |
Masayoshi Kobayashi | a85ae64 | 2013-04-08 09:39:37 +0000 | [diff] [blame] | 161 | plog("wait %d sec" % wait1) |
| 162 | time.sleep(wait1) |
| 163 | plog("check and log: %s" % os.popen('date').read()) |
Masayoshi Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 164 | |
Masayoshi Kobayashi | a85ae64 | 2013-04-08 09:39:37 +0000 | [diff] [blame] | 165 | 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 Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 170 | |
Masayoshi Kobayashi | a85ae64 | 2013-04-08 09:39:37 +0000 | [diff] [blame] | 171 | tdelta=tend-tstart |
Masayoshi Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 172 | |
Masayoshi Kobayashi | a85ae64 | 2013-04-08 09:39:37 +0000 | [diff] [blame] | 173 | 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() |