wcn_emulator / test_code / ping.py @ 2a8b9496
History | View | Annotate | Download (1.64 KB)
1 |
|
---|---|
2 |
import sys |
3 |
sys.path.append('../')
|
4 |
from network_builder import * |
5 |
from os import kill, path, makedirs |
6 |
from matplotlib.pyplot import ion |
7 |
from random import sample, randint |
8 |
|
9 |
from test_generic import * |
10 |
|
11 |
class pingTest(MininetTest): |
12 |
|
13 |
def __init__(self, mininet, duration=10): |
14 |
|
15 |
super(pingTest, self).__init__(mininet, path, duration) |
16 |
|
17 |
|
18 |
def launchPing(self, host): |
19 |
|
20 |
idps = randint(0,100) |
21 |
logfile = self.prefix + host.name.split('_')[0] + \ |
22 |
"-" + str(idps) + "_ping_$(date +%s).log" |
23 |
|
24 |
cmd = "ping " + self.destination |
25 |
params = {} |
26 |
params['>'] = logfile
|
27 |
params['2>'] = logfile
|
28 |
|
29 |
return self.bgCmd(host, True, cmd, |
30 |
*reduce(lambda x, y: x + y, params.items()) ) |
31 |
|
32 |
def runTest(self): |
33 |
info("*** Launching Ping test\n")
|
34 |
info("Data folder: "+self.prefix+"\n") |
35 |
|
36 |
for h in self.getAllHosts(): |
37 |
if h.defaultIntf().ip != self.destination: |
38 |
self.launchPing(h)
|
39 |
|
40 |
info("Waiting completion...\n")
|
41 |
self.wait(self.duration, log_resources={'net': 'netusage.csv'}) |
42 |
self.killAll()
|
43 |
|
44 |
class pingRandomTest(pingTest): |
45 |
|
46 |
def __init__(self, mininet, name, args): |
47 |
|
48 |
duration = int(args["duration"]) |
49 |
super(pingRandomTest, self).__init__(mininet, duration) |
50 |
self.destination = self.getHostSample(1)[0].defaultIntf().ip |
51 |
self.setPrefix(name)
|
52 |
|
53 |
class pingNode0Test(pingTest): |
54 |
|
55 |
def __init__(self, mininet, name, args): |
56 |
|
57 |
duration = int(args["duration"]) |
58 |
super(pingRandomTest, self).__init__(mininet, duration) |
59 |
self.destination = self.net.value()[0].defaultIntf().ip |
60 |
self.setPrefix(name)
|
61 |
|