Masayoshi Kobayashi | 76949e2 | 2013-04-03 12:00:04 +0000 | [diff] [blame] | 1 | #! /usr/bin/env python |
| 2 | import json |
| 3 | import os |
| 4 | |
| 5 | urls="http://localhost:8080/wm/core/topology/switches/all/json http://localhost:8080/wm/core/topology/links/json http://localhost:8080/wm/registry/controllers/json http://localhost:8080/wm/registry/switches/json" |
Masayoshi Kobayashi | 95c3053 | 2013-04-03 19:33:48 +0000 | [diff] [blame] | 6 | RestIP=os.environ.get("ONOS_CLUSTER_BASENAME")+"1" |
Masayoshi Kobayashi | 76949e2 | 2013-04-03 12:00:04 +0000 | [diff] [blame] | 7 | RestPort="8080" |
| 8 | |
| 9 | core_switches=["00:00:00:00:ba:5e:ba:11", "00:00:00:00:00:00:ba:12", "00:00:20:4e:7f:51:8a:35", "00:00:00:00:ba:5e:ba:13", "00:00:00:08:a2:08:f9:01", "00:00:00:16:97:08:9a:46"] |
| 10 | correct_nr_switch=[6,50,25,25,25,25,25,25] |
| 11 | correct_intra_link=[16, 98, 48, 48, 48, 48, 48, 48] |
| 12 | |
Masayoshi Kobayashi | 95c3053 | 2013-04-03 19:33:48 +0000 | [diff] [blame] | 13 | |
Masayoshi Kobayashi | 76949e2 | 2013-04-03 12:00:04 +0000 | [diff] [blame] | 14 | #nr_links=(switch[1]+switch[2]+switch[3]+switch[4]+switch[5]+switch[6]+switch[7]+len(switch)-1+8)*2 |
| 15 | nr_links= (49 + 24 * 6 + 7 + 8) * 2 |
| 16 | |
Masayoshi Kobayashi | ecf9c47 | 2013-04-03 19:17:49 +0000 | [diff] [blame] | 17 | def get_json(url): |
| 18 | print url |
Masayoshi Kobayashi | 76949e2 | 2013-04-03 12:00:04 +0000 | [diff] [blame] | 19 | try: |
Masayoshi Kobayashi | ecf9c47 | 2013-04-03 19:17:49 +0000 | [diff] [blame] | 20 | command = "curl -s %s" % (url) |
Masayoshi Kobayashi | 76949e2 | 2013-04-03 12:00:04 +0000 | [diff] [blame] | 21 | result = os.popen(command).read() |
Masayoshi Kobayashi | ecf9c47 | 2013-04-03 19:17:49 +0000 | [diff] [blame] | 22 | parsedResult = json.loads(result) |
Masayoshi Kobayashi | 76949e2 | 2013-04-03 12:00:04 +0000 | [diff] [blame] | 23 | except: |
Masayoshi Kobayashi | ecf9c47 | 2013-04-03 19:17:49 +0000 | [diff] [blame] | 24 | print "REST IF %s has issue" % command |
| 25 | parsedResult = "" |
Masayoshi Kobayashi | 76949e2 | 2013-04-03 12:00:04 +0000 | [diff] [blame] | 26 | |
Masayoshi Kobayashi | ecf9c47 | 2013-04-03 19:17:49 +0000 | [diff] [blame] | 27 | if type(parsedResult) == 'dict' and parsedResult.has_key('code'): |
| 28 | print "REST %s returned code %s" % (command, parsedResult['code']) |
| 29 | parsedResult = "" |
| 30 | |
| 31 | return parsedResult |
| 32 | |
| 33 | def check_switch(): |
| 34 | url="http://%s:%s/wm/core/topology/switches/all/json" % (RestIP, RestPort) |
| 35 | parsedResult = get_json(url) |
| 36 | |
| 37 | if parsedResult == "": |
| 38 | return |
| 39 | |
Masayoshi Kobayashi | 76949e2 | 2013-04-03 12:00:04 +0000 | [diff] [blame] | 40 | print "switch: total %d switches" % len(parsedResult) |
| 41 | cnt = [] |
Masayoshi Kobayashi | ecf9c47 | 2013-04-03 19:17:49 +0000 | [diff] [blame] | 42 | active = [] |
Masayoshi Kobayashi | 76949e2 | 2013-04-03 12:00:04 +0000 | [diff] [blame] | 43 | for r in range(8): |
| 44 | cnt.append(0) |
Masayoshi Kobayashi | ecf9c47 | 2013-04-03 19:17:49 +0000 | [diff] [blame] | 45 | active.append(0) |
Masayoshi Kobayashi | 76949e2 | 2013-04-03 12:00:04 +0000 | [diff] [blame] | 46 | for s in parsedResult: |
Masayoshi Kobayashi | ecf9c47 | 2013-04-03 19:17:49 +0000 | [diff] [blame] | 47 | if s['dpid'] in core_switches: |
| 48 | nw_index = 0 |
Masayoshi Kobayashi | 76949e2 | 2013-04-03 12:00:04 +0000 | [diff] [blame] | 49 | else: |
Masayoshi Kobayashi | ecf9c47 | 2013-04-03 19:17:49 +0000 | [diff] [blame] | 50 | nw_index =int(s['dpid'].split(':')[-2], 16) - 1 |
| 51 | cnt[nw_index] += 1 |
| 52 | |
| 53 | if s['state'] == "ACTIVE": |
| 54 | active[nw_index] += 1 |
| 55 | |
Masayoshi Kobayashi | 76949e2 | 2013-04-03 12:00:04 +0000 | [diff] [blame] | 56 | for r in range(8): |
Masayoshi Kobayashi | ecf9c47 | 2013-04-03 19:17:49 +0000 | [diff] [blame] | 57 | print "switch: network %d : %d switches %d active" % (r+1, cnt[r], active[r]) |
Masayoshi Kobayashi | 76949e2 | 2013-04-03 12:00:04 +0000 | [diff] [blame] | 58 | if correct_nr_switch[r] != cnt[r]: |
| 59 | print "switch fail: network %d should have %d switches but has %d" % (r+1, correct_nr_switch[r], cnt[r]) |
Masayoshi Kobayashi | ecf9c47 | 2013-04-03 19:17:49 +0000 | [diff] [blame] | 60 | |
| 61 | if correct_nr_switch[r] != active[r]: |
| 62 | print "switch fail: network %d should have %d active switches but has %d" % (r+1, correct_nr_switch[r], active[r]) |
Masayoshi Kobayashi | 76949e2 | 2013-04-03 12:00:04 +0000 | [diff] [blame] | 63 | |
| 64 | def check_link(): |
Masayoshi Kobayashi | ecf9c47 | 2013-04-03 19:17:49 +0000 | [diff] [blame] | 65 | url = "http://%s:%s/wm/core/topology/links/json" % (RestIP, RestPort) |
| 66 | parsedResult = get_json(url) |
| 67 | |
| 68 | if parsedResult == "": |
| 69 | return |
| 70 | |
Masayoshi Kobayashi | 76949e2 | 2013-04-03 12:00:04 +0000 | [diff] [blame] | 71 | print "link: total %d links (correct : %d)" % (len(parsedResult), nr_links) |
| 72 | intra = [] |
Masayoshi Kobayashi | 95c3053 | 2013-04-03 19:33:48 +0000 | [diff] [blame] | 73 | interlink=0 |
Masayoshi Kobayashi | 76949e2 | 2013-04-03 12:00:04 +0000 | [diff] [blame] | 74 | for r in range(8): |
| 75 | intra.append(0) |
| 76 | |
| 77 | for s in parsedResult: |
| 78 | if s['src-switch'] in core_switches: |
| 79 | src_nw = 1 |
| 80 | else: |
| 81 | src_nw =int(s['src-switch'].split(':')[-2], 16) |
| 82 | |
| 83 | if s['dst-switch'] in core_switches: |
| 84 | dst_nw = 1 |
| 85 | else: |
| 86 | dst_nw =int(s['dst-switch'].split(':')[-2], 16) |
| 87 | |
| 88 | src_swid =int(s['src-switch'].split(':')[-1], 16) |
| 89 | dst_swid =int(s['dst-switch'].split(':')[-1], 16) |
| 90 | if src_nw == dst_nw: |
| 91 | intra[src_nw - 1] = intra[src_nw - 1] + 1 |
Masayoshi Kobayashi | 95c3053 | 2013-04-03 19:33:48 +0000 | [diff] [blame] | 92 | else: |
Masayoshi Kobayashi | 50f22a1 | 2013-04-03 19:35:42 +0000 | [diff] [blame] | 93 | interlink += 1 |
Masayoshi Kobayashi | 76949e2 | 2013-04-03 12:00:04 +0000 | [diff] [blame] | 94 | |
| 95 | for r in range(8): |
| 96 | if intra[r] != correct_intra_link[r]: |
| 97 | print "link fail: network %d should have %d intra links but has %d" % (r+1, correct_intra_link[r], intra[r]) |
| 98 | |
Masayoshi Kobayashi | 95c3053 | 2013-04-03 19:33:48 +0000 | [diff] [blame] | 99 | if interlink != 14: |
| 100 | print "link fail: There should be %d intra links (uni-directional) but %d" % (14, interlink) |
| 101 | |
Masayoshi Kobayashi | 76949e2 | 2013-04-03 12:00:04 +0000 | [diff] [blame] | 102 | def check_mastership(): |
Masayoshi Kobayashi | ecf9c47 | 2013-04-03 19:17:49 +0000 | [diff] [blame] | 103 | url = "http://%s:%s/wm/registry/switches/json" % (RestIP, RestPort) |
| 104 | parsedResult = get_json(url) |
| 105 | |
| 106 | if parsedResult == "": |
| 107 | return |
| 108 | |
Masayoshi Kobayashi | 76949e2 | 2013-04-03 12:00:04 +0000 | [diff] [blame] | 109 | for s in parsedResult: |
| 110 | #print s,len(s),s[0]['controllerId'] |
| 111 | ctrl=parsedResult[s][0]['controllerId'] |
| 112 | if s in core_switches: |
| 113 | nw = 1 |
| 114 | else: |
| 115 | nw =int(s.split(':')[-2], 16) |
| 116 | |
| 117 | if len(parsedResult[s]) > 1: |
| 118 | print "ownership fail: switch %s has more than 1 ownership" % (s) |
| 119 | elif int(ctrl[-1]) != nw: |
| 120 | print "ownership fail: switch %s is owened by %s" % (s, ctrl) |
| 121 | |
| 122 | def check_controllers(): |
Masayoshi Kobayashi | ecf9c47 | 2013-04-03 19:17:49 +0000 | [diff] [blame] | 123 | url = "http://%s:%s/wm/registry/controllers/json" % (RestIP, RestPort) |
| 124 | parsedResult = get_json(url) |
Masayoshi Kobayashi | 76949e2 | 2013-04-03 12:00:04 +0000 | [diff] [blame] | 125 | |
Masayoshi Kobayashi | ecf9c47 | 2013-04-03 19:17:49 +0000 | [diff] [blame] | 126 | if parsedResult == "": |
| 127 | return |
| 128 | |
Masayoshi Kobayashi | 76949e2 | 2013-04-03 12:00:04 +0000 | [diff] [blame] | 129 | unique=list(set(parsedResult)) |
| 130 | if len(unique) != 8: |
| 131 | print "controller fail: there are %d controllers" % (len(parsedResult)) |
| 132 | |
| 133 | if __name__ == "__main__": |
| 134 | check_switch() |
| 135 | check_link() |
| 136 | check_mastership() |
| 137 | check_controllers() |