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