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