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 | |
| 9 | flowdef="flowdef_8node_252.txt" |
Masayoshi Kobayashi | bdbf22d | 2013-04-08 07:44:11 +0000 | [diff] [blame^] | 10 | basename="onosdevt" |
Masayoshi Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 11 | 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"] |
| 12 | |
| 13 | def check_by_pingall(): |
| 14 | buf = "" |
Masayoshi Kobayashi | bdbf22d | 2013-04-08 07:44:11 +0000 | [diff] [blame^] | 15 | cmd = "pingall-speedup.sh %s" % (flowdef) |
Masayoshi Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 16 | 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 | |
| 24 | def link_change_core(op): |
| 25 | cmd = "dsh -w %s1 \"sudo ifconfig %s\"" % (basename, op) |
| 26 | os.popen(cmd) |
| 27 | print cmd |
| 28 | |
| 29 | def 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 | |
| 37 | def 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 | |
| 44 | def 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 Kobayashi | bdbf22d | 2013-04-08 07:44:11 +0000 | [diff] [blame^] | 53 | def dump_flowgetall(tag): |
| 54 | url="http://%s:%s/wm/flow/getall/json" % (RestIP, RestPort) |
| 55 | filename = "rest-flow-getall-log.%s.log" % tag |
Masayoshi Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 56 | dump_json(url, filename) |
| 57 | |
Masayoshi Kobayashi | bdbf22d | 2013-04-08 07:44:11 +0000 | [diff] [blame^] | 58 | def 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 Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 67 | url = "http://%s:%s/wm/core/topology/links/json" % (RestIP, RestPort) |
Masayoshi Kobayashi | bdbf22d | 2013-04-08 07:44:11 +0000 | [diff] [blame^] | 68 | filename = "rest-link-log.%s.log" % tag |
Masayoshi Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 69 | dump_json(url, filename) |
| 70 | |
| 71 | url = "http://%s:%s/wm/registry/switches/json" % (RestIP, RestPort) |
Masayoshi Kobayashi | bdbf22d | 2013-04-08 07:44:11 +0000 | [diff] [blame^] | 72 | filename = "rest-reg-sw-log.%s.log" % tag |
Masayoshi Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 73 | dump_json(url, filename) |
| 74 | |
| 75 | url = "http://%s:%s/wm/registry/controllers/json" % (RestIP, RestPort) |
Masayoshi Kobayashi | bdbf22d | 2013-04-08 07:44:11 +0000 | [diff] [blame^] | 76 | filename = "rest-reg-ctrl-log.%s.log" % tag |
Masayoshi Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 77 | dump_json(url, filename) |
| 78 | |
| 79 | url = "http://%s:%s/wm/flow/getsummary/0/0/json" % (RestIP, RestPort) |
Masayoshi Kobayashi | bdbf22d | 2013-04-08 07:44:11 +0000 | [diff] [blame^] | 80 | filename = "rest-flow-getsummary-log.%s.log" % tag |
Masayoshi Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 81 | dump_json(url, filename) |
| 82 | |
Masayoshi Kobayashi | bdbf22d | 2013-04-08 07:44:11 +0000 | [diff] [blame^] | 83 | |
| 84 | def 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 Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 113 | if __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 Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 121 | for cycle in range(1000): |
| 122 | for n, op in enumerate(operation): |
Masayoshi Kobayashi | bdbf22d | 2013-04-08 07:44:11 +0000 | [diff] [blame^] | 123 | print "==== Cycle %d operation %d ====: %s" % (cycle, n, os.popen('date').read()) |
Masayoshi Kobayashi | e4a551d | 2013-04-07 04:56:09 +0000 | [diff] [blame] | 124 | link_change_core(op) |
| 125 | print "wait 30 sec" |
| 126 | time.sleep(30) |
Masayoshi Kobayashi | bdbf22d | 2013-04-08 07:44:11 +0000 | [diff] [blame^] | 127 | 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() |