blob: db1f81cc6010e2b555599d276762cdd70c165590 [file] [log] [blame]
Masayoshi Kobayashif04afb32013-04-06 06:49:03 +00001#! /usr/bin/env python
2import sys
3import time
4import os
Masayoshi Kobayashif9ccc382013-04-07 04:06:41 +00005import re
Pavlin Radoslavov092d0e22013-04-07 05:42:51 +00006import json
Masayoshi Kobayashif04afb32013-04-06 06:49:03 +00007
Masayoshi Kobayashif04afb32013-04-06 06:49:03 +00008ping_cnt=3
Masayoshi Kobayashif9ccc382013-04-07 04:06:41 +00009wait1=ping_cnt
10wait2=10
Masayoshi Kobayashif04afb32013-04-06 06:49:03 +000011
Pavlin Radoslavov092d0e22013-04-07 05:42:51 +000012CONFIG_FILE=os.getenv("HOME") + "/ONOS/web/config.json"
13
14def read_config():
15 global controllers
16 f = open(CONFIG_FILE)
17 conf = json.load(f)
18 controllers = conf['controllers']
19 f.close()
Masayoshi Kobayashif04afb32013-04-06 06:49:03 +000020
Masayoshi Kobayashif9ccc382013-04-07 04:06:41 +000021def do_pingall():
Masayoshi Kobayashif04afb32013-04-06 06:49:03 +000022
Masayoshi Kobayashif9ccc382013-04-07 04:06:41 +000023 pid=os.getpid()
24 os.popen("rm -f /tmp/ping.*")
Masayoshi Kobayashif04afb32013-04-06 06:49:03 +000025
Masayoshi Kobayashif9ccc382013-04-07 04:06:41 +000026 filename = sys.argv[1]
27 f = open(filename, 'r')
28 nr_ping = 0
29 for line in f:
30 if line[0] != "#":
Masayoshi Kobayashif9ccc382013-04-07 04:06:41 +000031 fid=int(line.strip().split()[0])
Pavlin Radoslavov092d0e22013-04-07 05:42:51 +000032# logfile="/tmp/ping.pid%d.%d" % (pid, fid)
Masayoshi Kobayashif9ccc382013-04-07 04:06:41 +000033 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 cmd="echo \"Pingall flow %d : 192.168.%d.%d -> 192.168.%d.%d\" > %s" % (fid, src_nwid, src_hostid, dst_nwid, dst_hostid,logfile)
41 os.popen(cmd)
Pavlin Radoslavov092d0e22013-04-07 05:42:51 +000042 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)
43 print cmd
Masayoshi Kobayashif9ccc382013-04-07 04:06:41 +000044 result = os.popen(cmd).read()
45 time.sleep(0.2)
46 nr_ping = nr_ping + 1
Masayoshi Kobayashif04afb32013-04-06 06:49:03 +000047
Masayoshi Kobayashif9ccc382013-04-07 04:06:41 +000048 f.close()
49 return nr_ping
Masayoshi Kobayashif04afb32013-04-06 06:49:03 +000050
Masayoshi Kobayashif9ccc382013-04-07 04:06:41 +000051def wait_ping_finish(nr_ping):
52 print "all pings started.. waiting for completion (%d sec)" % (wait1)
53 time.sleep(wait1)
54 cmd="cat /tmp/ping.* | grep \"packet loss\" |wc -l"
55 for i in range(wait2):
56 nr_done = int(os.popen(cmd).read())
57 if nr_done == nr_ping:
58 break
59 print "%d ping finished" % nr_done
60 time.sleep(1)
61
62 return nr_done
Masayoshi Kobayashif04afb32013-04-06 06:49:03 +000063
Masayoshi Kobayashif9ccc382013-04-07 04:06:41 +000064def report(nr_ping, nr_done):
65 cmd='cat /tmp/ping.* | grep " 0% packet loss" |wc -l'
66 nr_success = int(os.popen('cat /tmp/ping.* | grep " 0% packet loss" |wc -l').read())
67 nr_incomplete = nr_ping - nr_done
68 nr_fail = nr_done - nr_success
69
70 print "Pingall Result: success %d fail %d incomplete %d" % (nr_success, nr_fail, nr_incomplete)
71 if nr_fail > 0 or nr_incomplete > 0:
72 for i in range(nr_ping):
73 cmd="cat /tmp/ping.%d | head -n 1" % (i+1)
74 flow_desc = os.popen(cmd).read().strip()
75
76 cmd="cat /tmp/ping.%d | grep \"packet loss\"" % (i+1)
77 result = os.popen(cmd).read().strip()
78
79 if not re.search(" 0% packet loss", result):
80 print "flow # %d %s : %s" % (i+1, flow_desc, result)
81
82if __name__ == "__main__":
Pavlin Radoslavov092d0e22013-04-07 05:42:51 +000083 read_config()
Masayoshi Kobayashif9ccc382013-04-07 04:06:41 +000084 nr_ping=do_pingall()
85 nr_done=wait_ping_finish(nr_ping)
86 report(nr_ping, nr_done)