blob: e377a551438375b28a9ab587eb228096429fb3c8 [file] [log] [blame]
Masayoshi Kobayashif04afb32013-04-06 06:49:03 +00001#! /usr/bin/env python
2import sys
3import time
4import os
5
6hosts=['onosdevz1', 'onosdevz2', 'onosdevz3', 'onosdevz4', 'onosdevz5', 'onosdevz6', 'onosdevz7', 'onosdevz8']
7filename = sys.argv[1]
8
9ping_cnt=3
10wait=ping_cnt
11
12os.popen("rm -f /tmp/ping*")
13
14f = open(filename, 'r')
15nr_ping = 0
16for line in f:
17 if line[0] != "#":
18 fid=int(line.strip().split()[0])
19 src_dpid=line.strip().split()[2]
20 dst_dpid=line.strip().split()[4]
21 src_nwid=int(src_dpid.split(':')[-2], 16)
22 dst_nwid=int(dst_dpid.split(':')[-2], 16)
23 src_hostid=int(src_dpid.split(':')[-1], 16)
24 dst_hostid=int(dst_dpid.split(':')[-1], 16)
25 cmd="echo \"192.168.%d.%d -> 192.168.%d.%d\" > /tmp/ping.%d" % (src_nwid, src_hostid, dst_nwid, dst_hostid,fid)
26 os.popen(cmd)
27 cmd="ssh %s \'${HOME}/ONOS/test-network/mininet/mrun host%d \'ping -c %d -W 1 192.168.%d.%d\'\' >> /tmp/ping.%d 2>&1 &" % (hosts[src_nwid-1], src_hostid, ping_cnt, dst_nwid, dst_hostid,fid)
28# print cmd
29 result = os.popen(cmd).read()
30 time.sleep(0.2)
31 nr_ping = nr_ping + 1
32
33print "waiting for ping(s) to finish (%d sec)" % (wait)
34time.sleep(wait)
35cmd="cat /tmp/ping.* | grep loss |wc -l"
36wait_cnt=0
37while 1:
38 nr_done = int(os.popen(cmd).read())
39 if nr_done == nr_ping or wait_cnt > 10:
40 break
41 print "%d ping finished" % nr_done
42 time.sleep(1)
43 wait_cnt += 1
44
45cmd='cat /tmp/ping.* | grep " 0% packet loss" |wc -l'
46nr_success = int(os.popen(cmd).read())
47
48if nr_success != nr_ping:
49 print "fail: %d ping(s) failed (finished %d total %d)" % (nr_done - nr_success, nr_done, nr_ping)
50else:
51 print "success: all %d ping(s) got through" % (nr_success)
52
53for i in range(nr_ping):
54 cmd="cat /tmp/ping.%d | grep loss | awk '{print $6}'" % (i+1)
55 cmd2="cat /tmp/ping.%d | head -n 1" % (i+1)
56 result = os.popen(cmd).read().strip()
57 result2 = os.popen(cmd2).read().strip()
58 if result != "0%":
59 print "flow # %d fail (%s)" % (i+1, result2)
60
61f.close()