blob: 0643cb9e9f2aca1e4aabe814c18f098d42f34b01 [file] [log] [blame]
Pavlin Radoslavov07eecc72013-04-02 22:54:19 +00001#! /usr/bin/env python
2import sys
Pavlin Radoslavov06869f02013-04-03 11:58:22 +00003import time
Pavlin Radoslavov07eecc72013-04-02 22:54:19 +00004import os
5
Pavlin Radoslavov06869f02013-04-03 11:58:22 +00006hosts=['onosdevz1', 'onosdevz2', 'onosdevz3', 'onosdevz4', 'onosdevz5', 'onosdevz6', 'onosdevz7', 'onosdevz8']
Pavlin Radoslavov07eecc72013-04-02 22:54:19 +00007filename = sys.argv[1]
8
Pavlin Radoslavov06869f02013-04-03 11:58:22 +00009ping_cnt=3
10wait=ping_cnt
11
Pavlin Radoslavov07eecc72013-04-02 22:54:19 +000012f = open(filename, 'r')
Pavlin Radoslavov06869f02013-04-03 11:58:22 +000013nr_ping = 0
Pavlin Radoslavov07eecc72013-04-02 22:54:19 +000014for line in f:
15 if line[0] != "#":
16 fid=int(line.strip().split()[0])
17 src_dpid=line.strip().split()[2]
18 dst_dpid=line.strip().split()[4]
19 src_nwid=int(src_dpid.split(':')[-2], 16)
20 dst_nwid=int(dst_dpid.split(':')[-2], 16)
21 src_hostid=int(src_dpid.split(':')[-1], 16)
22 dst_hostid=int(dst_dpid.split(':')[-1], 16)
Pavlin Radoslavov06869f02013-04-03 11:58:22 +000023 cmd="echo \"192.168.%d.%d -> 192.168.%d.%d\" > /tmp/ping.%d" % (src_nwid, src_hostid, dst_nwid, dst_hostid,fid)
24 os.popen(cmd)
25 cmd="ssh %s \'ssh -o StrictHostKeyChecking=no 1.1.%d.1 \'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)
26# print cmd
Pavlin Radoslavov07eecc72013-04-02 22:54:19 +000027 result = os.popen(cmd).read()
Pavlin Radoslavov06869f02013-04-03 11:58:22 +000028 nr_ping = nr_ping + 1
29
30print "waiting for ping(s) to finish (%d sec)" % (wait)
31time.sleep(wait)
32cmd="cat /tmp/ping.* | grep loss |wc -l"
33while 1:
34 result = int(os.popen(cmd).read())
35 if result == nr_ping:
36 break
37
38cmd='cat /tmp/ping.* | grep " 0% packet loss" |wc -l'
39result = int(os.popen(cmd).read())
40if result != nr_ping:
41 print "fail: %d ping(s) failed (out of %d)" % (nr_ping - result, nr_ping)
42else:
43 print "success: all %d ping(s) got through" % (result)
44
45for i in range(nr_ping):
46 cmd="cat /tmp/ping.%d | grep loss | awk '{print $6}'" % (i+1)
47 cmd2="cat /tmp/ping.%d | head -n 1" % (i+1)
48 result = os.popen(cmd).read().strip()
49 result2 = os.popen(cmd2).read().strip()
50 if result != "0%":
51 print "flow # %d fail (%s)" % (i+1, result2)
Pavlin Radoslavov07eecc72013-04-02 22:54:19 +000052
53f.close()