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" |
| 10 | basename="onosdevz" |
| 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 = "" |
| 15 | cmd = "dsh -w %s1 \"cd ONOS/web; ./pingallm.py %s\"" % (basename, flowdef) |
| 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 | |
| 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 | |
| 54 | def check_rest(cycle, n): |
| 55 | url="http://%s:%s/wm/core/topology/switches/all/json" % (RestIP, RestPort) |
| 56 | filename = "rest-sw-log.%d.%d.log" % (cycle, n) |
| 57 | dump_json(url, filename) |
| 58 | |
| 59 | filename = "rest-link-log.%d.%d.log" % (cycle, n) |
| 60 | url = "http://%s:%s/wm/core/topology/links/json" % (RestIP, RestPort) |
| 61 | dump_json(url, filename) |
| 62 | |
| 63 | url = "http://%s:%s/wm/registry/switches/json" % (RestIP, RestPort) |
| 64 | filename = "rest-reg-sw-log.%d.%d.log" % (cycle, n) |
| 65 | dump_json(url, filename) |
| 66 | |
| 67 | url = "http://%s:%s/wm/registry/controllers/json" % (RestIP, RestPort) |
| 68 | filename = "rest-reg-ctrl-log.%d.%d.log" % (cycle, n) |
| 69 | dump_json(url, filename) |
| 70 | |
| 71 | url = "http://%s:%s/wm/flow/getsummary/0/0/json" % (RestIP, RestPort) |
| 72 | filename = "rest-flow-log.%d.%d.log" % (cycle, n) |
| 73 | dump_json(url, filename) |
| 74 | |
| 75 | |
| 76 | def log(cycle, n, nr_ctrl): |
| 77 | error = "error-log.%d.%d.log" % (cycle, n) |
| 78 | nmapflow = "nmap-flow-log.%d.%d.log" % (cycle, n) |
| 79 | rawflow = "raw-flow-log.%d.%d.log" % (cycle, n) |
| 80 | |
| 81 | f = open(error, 'w') |
| 82 | f.write(result) |
| 83 | f.write(check_switch()[1]) |
| 84 | f.write(check_link()[1]) |
| 85 | f.write(check_switch_all(nr_ctrl)[1]) |
| 86 | f.write(check_controllers(nr_ctrl)[1]) |
| 87 | f.close() |
| 88 | |
| 89 | f = open(nmapflow,'w') |
| 90 | f.write(check_flow_nmap()[1]) |
| 91 | f.close() |
| 92 | |
| 93 | f = open(rawflow,'w') |
| 94 | f.write(check_flow_raw()[1]) |
| 95 | f.close() |
| 96 | check_rest(cycle,n) |
| 97 | |
| 98 | |
| 99 | opration=['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'] |
| 100 | nr_controllers=[8, 7, 6, 5, 4, 8, 8] |
| 101 | |
| 102 | if __name__ == "__main__": |
| 103 | print "%s" % check_switch()[1] |
| 104 | print "%s" % check_link()[1] |
| 105 | print "%s" % check_controllers(8)[1] |
| 106 | (code, result) = check_by_pingall() |
| 107 | print result |
| 108 | k = raw_input('hit any key>') |
| 109 | |
| 110 | for cycle in range(1000): |
| 111 | for n, op in enumerate(operation): |
| 112 | print "==== Cycle %d operation %d ====" % (cycle, n) |
| 113 | print op |
| 114 | os.popen(op) |
| 115 | print "wait 30 sec" |
| 116 | time.sleep(30) |
| 117 | |
| 118 | print "check by pingall" |
| 119 | (code, result) = check_by_pingall() |
| 120 | if code == 0: |
| 121 | print "ping success %s" % (result) |
| 122 | else: |
| 123 | print "pingall failed (%d, %d). Collecting logs" % (cycle, n) |
| 124 | log(cycle, n, nr_controllers[n]) |
| 125 | |
| 126 | |
| 127 | |