blob: ae777c3c581fd8daf0ba28ef3758f48a4cc2908e [file] [log] [blame]
Masayoshi Kobayashi76949e22013-04-03 12:00:04 +00001#! /usr/bin/env python
2import json
3import os
4
5urls="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 Kobayashi95c30532013-04-03 19:33:48 +00006RestIP=os.environ.get("ONOS_CLUSTER_BASENAME")+"1"
Masayoshi Kobayashi76949e22013-04-03 12:00:04 +00007RestPort="8080"
8
9core_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"]
10correct_nr_switch=[6,50,25,25,25,25,25,25]
11correct_intra_link=[16, 98, 48, 48, 48, 48, 48, 48]
12
Masayoshi Kobayashi95c30532013-04-03 19:33:48 +000013
Masayoshi Kobayashi76949e22013-04-03 12:00:04 +000014#nr_links=(switch[1]+switch[2]+switch[3]+switch[4]+switch[5]+switch[6]+switch[7]+len(switch)-1+8)*2
15nr_links= (49 + 24 * 6 + 7 + 8) * 2
16
Masayoshi Kobayashiecf9c472013-04-03 19:17:49 +000017def get_json(url):
18 print url
Masayoshi Kobayashi76949e22013-04-03 12:00:04 +000019 try:
Masayoshi Kobayashiecf9c472013-04-03 19:17:49 +000020 command = "curl -s %s" % (url)
Masayoshi Kobayashi76949e22013-04-03 12:00:04 +000021 result = os.popen(command).read()
Masayoshi Kobayashiecf9c472013-04-03 19:17:49 +000022 parsedResult = json.loads(result)
Masayoshi Kobayashi76949e22013-04-03 12:00:04 +000023 except:
Masayoshi Kobayashiecf9c472013-04-03 19:17:49 +000024 print "REST IF %s has issue" % command
25 parsedResult = ""
Masayoshi Kobayashi76949e22013-04-03 12:00:04 +000026
Masayoshi Kobayashiecf9c472013-04-03 19:17:49 +000027 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
33def 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 Kobayashi76949e22013-04-03 12:00:04 +000040 print "switch: total %d switches" % len(parsedResult)
41 cnt = []
Masayoshi Kobayashiecf9c472013-04-03 19:17:49 +000042 active = []
Masayoshi Kobayashi76949e22013-04-03 12:00:04 +000043 for r in range(8):
44 cnt.append(0)
Masayoshi Kobayashiecf9c472013-04-03 19:17:49 +000045 active.append(0)
Masayoshi Kobayashi76949e22013-04-03 12:00:04 +000046 for s in parsedResult:
Masayoshi Kobayashiecf9c472013-04-03 19:17:49 +000047 if s['dpid'] in core_switches:
48 nw_index = 0
Masayoshi Kobayashi76949e22013-04-03 12:00:04 +000049 else:
Masayoshi Kobayashiecf9c472013-04-03 19:17:49 +000050 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 Kobayashi76949e22013-04-03 12:00:04 +000056 for r in range(8):
Masayoshi Kobayashiecf9c472013-04-03 19:17:49 +000057 print "switch: network %d : %d switches %d active" % (r+1, cnt[r], active[r])
Masayoshi Kobayashi76949e22013-04-03 12:00:04 +000058 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 Kobayashiecf9c472013-04-03 19:17:49 +000060
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 Kobayashi76949e22013-04-03 12:00:04 +000063
64def check_link():
Masayoshi Kobayashiecf9c472013-04-03 19:17:49 +000065 url = "http://%s:%s/wm/core/topology/links/json" % (RestIP, RestPort)
66 parsedResult = get_json(url)
67
68 if parsedResult == "":
69 return
70
Masayoshi Kobayashi76949e22013-04-03 12:00:04 +000071 print "link: total %d links (correct : %d)" % (len(parsedResult), nr_links)
72 intra = []
Masayoshi Kobayashi95c30532013-04-03 19:33:48 +000073 interlink=0
Masayoshi Kobayashi76949e22013-04-03 12:00:04 +000074 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 Kobayashi95c30532013-04-03 19:33:48 +000092 else:
93 inter += 1
Masayoshi Kobayashi76949e22013-04-03 12:00:04 +000094
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 Kobayashi95c30532013-04-03 19:33:48 +000099 if interlink != 14:
100 print "link fail: There should be %d intra links (uni-directional) but %d" % (14, interlink)
101
Masayoshi Kobayashi76949e22013-04-03 12:00:04 +0000102def check_mastership():
Masayoshi Kobayashiecf9c472013-04-03 19:17:49 +0000103 url = "http://%s:%s/wm/registry/switches/json" % (RestIP, RestPort)
104 parsedResult = get_json(url)
105
106 if parsedResult == "":
107 return
108
Masayoshi Kobayashi76949e22013-04-03 12:00:04 +0000109 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
122def check_controllers():
Masayoshi Kobayashiecf9c472013-04-03 19:17:49 +0000123 url = "http://%s:%s/wm/registry/controllers/json" % (RestIP, RestPort)
124 parsedResult = get_json(url)
Masayoshi Kobayashi76949e22013-04-03 12:00:04 +0000125
Masayoshi Kobayashiecf9c472013-04-03 19:17:49 +0000126 if parsedResult == "":
127 return
128
Masayoshi Kobayashi76949e22013-04-03 12:00:04 +0000129 unique=list(set(parsedResult))
130 if len(unique) != 8:
131 print "controller fail: there are %d controllers" % (len(parsedResult))
132
133if __name__ == "__main__":
134 check_switch()
135 check_link()
136 check_mastership()
137 check_controllers()