blob: 7dc69f806c5bede325fc473002024f95d988d4be [file] [log] [blame]
Ubuntu454eedf2013-04-08 05:13:26 +00001#! /usr/bin/env python
2import sys
3import time
4import os
5import re
6import json
7
Masayoshi Kobayashi8ca3d322013-04-08 07:43:24 +00008ping_cnt=10
Ubuntu454eedf2013-04-08 05:13:26 +00009wait1=ping_cnt
10wait2=10
11
12CONFIG_FILE=os.getenv("HOME") + "/ONOS/web/config.json"
13
14def read_config():
15 global controllers, cluster_basename
16 f = open(CONFIG_FILE)
17 conf = json.load(f)
18 controllers = conf['controllers']
19 cluster_basename = conf['cluster_basename']
20 f.close()
21
22def do_pingall(nwid):
23 pid=os.getpid()
24 os.popen("rm -f /tmp/ping.*")
25
26 filename = sys.argv[1]
27 f = open(filename, 'r')
28 nr_ping = 0
29 fids=[]
30 for line in f:
31 if line[0] != "#":
32 fid=int(line.strip().split()[0])
33 logfile="/tmp/ping.%d" % (fid)
34 src_dpid=line.strip().split()[2]
35 dst_dpid=line.strip().split()[4]
36 src_nwid=int(src_dpid.split(':')[-2], 16)
37 dst_nwid=int(dst_dpid.split(':')[-2], 16)
38 src_hostid=int(src_dpid.split(':')[-1], 16)
39 dst_hostid=int(dst_dpid.split(':')[-1], 16)
40
41 if src_nwid == nwid:
42 cmd="echo \"Pingall flow %d : 192.168.%d.%d -> 192.168.%d.%d\" > %s" % (fid, src_nwid, src_hostid, dst_nwid, dst_hostid,logfile)
43 os.popen(cmd)
44# cmd="ssh %s \'${HOME}/ONOS/test-network/mininet/mrun host%d \'ping -c %d -W 1 192.168.%d.%d\'\' >> %s 2>&1 &" % (controllers[src_nwid-1], src_hostid, ping_cnt, dst_nwid, dst_hostid,logfile)
45 cmd="${HOME}/ONOS/test-network/mininet/mrun host%d \'ping -c %d -W 1 192.168.%d.%d\' >> %s 2>&1 &" % (src_hostid, ping_cnt, dst_nwid, dst_hostid,logfile)
46 print cmd
47 result = os.popen(cmd).read()
48# time.sleep(0.2)
49 fids.append(fid)
50 nr_ping = nr_ping + 1
51
52 f.close()
53 return fids
54
55def wait_ping_finish(nr_ping):
56 print "all pings started.. waiting for completion (%d sec)" % (wait1)
57 time.sleep(wait1)
58 cmd="cat /tmp/ping.* | grep \"packet loss\" |wc -l"
59 for i in range(wait2):
60 nr_done = int(os.popen(cmd).read())
61 if nr_done == nr_ping:
62 break
63 print "%d ping finished" % nr_done
64 time.sleep(1)
65
66 return nr_done
67
68def report(fids, nr_done):
69 cmd='cat /tmp/ping.* | grep " 0% packet loss" |wc -l'
70 nr_success = int(os.popen('cat /tmp/ping.* | grep " 0% packet loss" |wc -l').read())
71 nr_incomplete = len(fids) - nr_done
72 nr_fail = nr_done - nr_success
73
74 print "Pingall Result: success %d fail %d incomplete %d" % (nr_success, nr_fail, nr_incomplete)
75 if nr_fail > 0 or nr_incomplete > 0:
76 for i in fids:
77 cmd="cat /tmp/ping.%d | head -n 1" % (i)
78 flow_desc = os.popen(cmd).read().strip()
79
80 cmd="cat /tmp/ping.%d | grep \"packet loss\"" % (i)
81 result = os.popen(cmd).read().strip()
82
83 if not re.search(" 0% packet loss", result):
84 print "flow # %d %s : %s" % (i, flow_desc, result)
85
86if __name__ == "__main__":
87 read_config()
88 hostname=os.popen('hostname').read().strip()
89 nwid=int(hostname.replace("%s" % cluster_basename, ""))
90 fids=do_pingall(nwid)
91 nr_done=wait_ping_finish(len(fids))
92 report(fids, nr_done)