blob: baca785da3d7da1f7248e38b39ee3c420b04ba84 [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"
6RestIP="onosdevz1"
7RestPort="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
13#nr_links=(switch[1]+switch[2]+switch[3]+switch[4]+switch[5]+switch[6]+switch[7]+len(switch)-1+8)*2
14nr_links= (49 + 24 * 6 + 7 + 8) * 2
15
Masayoshi Kobayashiecf9c472013-04-03 19:17:49 +000016def get_json(url):
17 print url
Masayoshi Kobayashi76949e22013-04-03 12:00:04 +000018 try:
Masayoshi Kobayashiecf9c472013-04-03 19:17:49 +000019 command = "curl -s %s" % (url)
Masayoshi Kobayashi76949e22013-04-03 12:00:04 +000020 result = os.popen(command).read()
Masayoshi Kobayashiecf9c472013-04-03 19:17:49 +000021 parsedResult = json.loads(result)
Masayoshi Kobayashi76949e22013-04-03 12:00:04 +000022 except:
Masayoshi Kobayashiecf9c472013-04-03 19:17:49 +000023 print "REST IF %s has issue" % command
24 parsedResult = ""
Masayoshi Kobayashi76949e22013-04-03 12:00:04 +000025
Masayoshi Kobayashiecf9c472013-04-03 19:17:49 +000026 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
32def 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 Kobayashi76949e22013-04-03 12:00:04 +000039 print "switch: total %d switches" % len(parsedResult)
40 cnt = []
Masayoshi Kobayashiecf9c472013-04-03 19:17:49 +000041 active = []
Masayoshi Kobayashi76949e22013-04-03 12:00:04 +000042 for r in range(8):
43 cnt.append(0)
Masayoshi Kobayashiecf9c472013-04-03 19:17:49 +000044 active.append(0)
Masayoshi Kobayashi76949e22013-04-03 12:00:04 +000045 for s in parsedResult:
Masayoshi Kobayashiecf9c472013-04-03 19:17:49 +000046 if s['dpid'] in core_switches:
47 nw_index = 0
Masayoshi Kobayashi76949e22013-04-03 12:00:04 +000048 else:
Masayoshi Kobayashiecf9c472013-04-03 19:17:49 +000049 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 Kobayashi76949e22013-04-03 12:00:04 +000055 for r in range(8):
Masayoshi Kobayashiecf9c472013-04-03 19:17:49 +000056 print "switch: network %d : %d switches %d active" % (r+1, cnt[r], active[r])
Masayoshi Kobayashi76949e22013-04-03 12:00:04 +000057 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 Kobayashiecf9c472013-04-03 19:17:49 +000059
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 Kobayashi76949e22013-04-03 12:00:04 +000062
63def check_link():
Masayoshi Kobayashiecf9c472013-04-03 19:17:49 +000064 url = "http://%s:%s/wm/core/topology/links/json" % (RestIP, RestPort)
65 parsedResult = get_json(url)
66
67 if parsedResult == "":
68 return
69
Masayoshi Kobayashi76949e22013-04-03 12:00:04 +000070 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
95def check_mastership():
Masayoshi Kobayashiecf9c472013-04-03 19:17:49 +000096 url = "http://%s:%s/wm/registry/switches/json" % (RestIP, RestPort)
97 parsedResult = get_json(url)
98
99 if parsedResult == "":
100 return
101
Masayoshi Kobayashi76949e22013-04-03 12:00:04 +0000102 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
115def check_controllers():
Masayoshi Kobayashiecf9c472013-04-03 19:17:49 +0000116 url = "http://%s:%s/wm/registry/controllers/json" % (RestIP, RestPort)
117 parsedResult = get_json(url)
Masayoshi Kobayashi76949e22013-04-03 12:00:04 +0000118
Masayoshi Kobayashiecf9c472013-04-03 19:17:49 +0000119 if parsedResult == "":
120 return
121
Masayoshi Kobayashi76949e22013-04-03 12:00:04 +0000122 unique=list(set(parsedResult))
123 if len(unique) != 8:
124 print "controller fail: there are %d controllers" % (len(parsedResult))
125
126if __name__ == "__main__":
127 check_switch()
128 check_link()
129 check_mastership()
130 check_controllers()