Pavlin Radoslavov | 07eecc7 | 2013-04-02 22:54:19 +0000 | [diff] [blame] | 1 | #! /usr/bin/env python |
| 2 | import sys |
Pavlin Radoslavov | 06869f0 | 2013-04-03 11:58:22 +0000 | [diff] [blame] | 3 | import time |
Pavlin Radoslavov | 07eecc7 | 2013-04-02 22:54:19 +0000 | [diff] [blame] | 4 | import os |
| 5 | |
Pavlin Radoslavov | 06869f0 | 2013-04-03 11:58:22 +0000 | [diff] [blame] | 6 | hosts=['onosdevz1', 'onosdevz2', 'onosdevz3', 'onosdevz4', 'onosdevz5', 'onosdevz6', 'onosdevz7', 'onosdevz8'] |
Pavlin Radoslavov | 07eecc7 | 2013-04-02 22:54:19 +0000 | [diff] [blame] | 7 | filename = sys.argv[1] |
| 8 | |
Pavlin Radoslavov | 06869f0 | 2013-04-03 11:58:22 +0000 | [diff] [blame] | 9 | ping_cnt=3 |
| 10 | wait=ping_cnt |
| 11 | |
Pavlin Radoslavov | 07eecc7 | 2013-04-02 22:54:19 +0000 | [diff] [blame] | 12 | f = open(filename, 'r') |
Pavlin Radoslavov | 06869f0 | 2013-04-03 11:58:22 +0000 | [diff] [blame] | 13 | nr_ping = 0 |
Pavlin Radoslavov | 07eecc7 | 2013-04-02 22:54:19 +0000 | [diff] [blame] | 14 | for 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 Radoslavov | 06869f0 | 2013-04-03 11:58:22 +0000 | [diff] [blame] | 23 | 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 Radoslavov | 07eecc7 | 2013-04-02 22:54:19 +0000 | [diff] [blame] | 27 | result = os.popen(cmd).read() |
Pavlin Radoslavov | 06869f0 | 2013-04-03 11:58:22 +0000 | [diff] [blame] | 28 | nr_ping = nr_ping + 1 |
| 29 | |
| 30 | print "waiting for ping(s) to finish (%d sec)" % (wait) |
| 31 | time.sleep(wait) |
| 32 | cmd="cat /tmp/ping.* | grep loss |wc -l" |
| 33 | while 1: |
| 34 | result = int(os.popen(cmd).read()) |
| 35 | if result == nr_ping: |
| 36 | break |
| 37 | |
| 38 | cmd='cat /tmp/ping.* | grep " 0% packet loss" |wc -l' |
| 39 | result = int(os.popen(cmd).read()) |
| 40 | if result != nr_ping: |
| 41 | print "fail: %d ping(s) failed (out of %d)" % (nr_ping - result, nr_ping) |
| 42 | else: |
| 43 | print "success: all %d ping(s) got through" % (result) |
| 44 | |
| 45 | for 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 Radoslavov | 07eecc7 | 2013-04-02 22:54:19 +0000 | [diff] [blame] | 52 | |
| 53 | f.close() |