Restore iperf test
Also simplify test running.
This commit is contained in:
+4
-16
@@ -117,29 +117,17 @@ class MininetRunner(object):
|
|||||||
controller_params = ControllerParams(0x0a000000, 8) # 10.0.0.0/8
|
controller_params = ControllerParams(0x0a000000, 8) # 10.0.0.0/8
|
||||||
mn = Mininet(topo, switch, host, controller, controller_params)
|
mn = Mininet(topo, switch, host, controller, controller_params)
|
||||||
|
|
||||||
if self.options.test != 'build':
|
test = self.options.test
|
||||||
|
if test != 'build':
|
||||||
if self.options.test == 'cli':
|
if test == 'cli':
|
||||||
mn.interact()
|
mn.interact()
|
||||||
elif self.options.test == 'ping_all':
|
|
||||||
mn.start()
|
|
||||||
dropped = mn.ping_test(verbose = True)
|
|
||||||
lg.info("*** Test results: %i%% dropped\n", dropped)
|
|
||||||
mn.stop()
|
|
||||||
elif self.options.test == 'ping_pair':
|
|
||||||
mn.start()
|
|
||||||
hosts_unsorted = sorted(mn.topo.hosts())
|
|
||||||
hosts = [hosts_unsorted[0], hosts_unsorted[1]]
|
|
||||||
dropped = mn.ping_test(hosts = hosts, verbose = True)
|
|
||||||
lg.info("*** Test results: %i%% dropped\n", dropped)
|
|
||||||
elif test == 'all':
|
elif test == 'all':
|
||||||
mn.start()
|
mn.start()
|
||||||
mn.ping()
|
mn.ping()
|
||||||
mn.iperf()
|
mn.iperf()
|
||||||
mn.stop()
|
mn.stop()
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError('unknown test: %s' %
|
mn.run(test)
|
||||||
self.options.test)
|
|
||||||
|
|
||||||
elapsed = float(time.time() - start)
|
elapsed = float(time.time() - start)
|
||||||
print ('completed in %0.3f seconds' % elapsed)
|
print ('completed in %0.3f seconds' % elapsed)
|
||||||
|
|||||||
+70
-16
@@ -324,7 +324,7 @@ class Mininet(object):
|
|||||||
'''Perform a complete start/test/stop cycle.'''
|
'''Perform a complete start/test/stop cycle.'''
|
||||||
self.start()
|
self.start()
|
||||||
lg.info('*** Running test\n')
|
lg.info('*** Running test\n')
|
||||||
result = test(self, **params)
|
result = getattr(self, test)(**params)
|
||||||
self.stop()
|
self.stop()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@@ -340,11 +340,10 @@ class Mininet(object):
|
|||||||
sent, received = int(m.group(1)), int(m.group(2))
|
sent, received = int(m.group(1)), int(m.group(2))
|
||||||
return sent, received
|
return sent, received
|
||||||
|
|
||||||
def ping_test(self, hosts = None, verbose = False):
|
def ping(self, hosts = None):
|
||||||
'''Ping between all specified hosts.
|
'''Ping between all specified hosts.
|
||||||
|
|
||||||
@param hosts list of host DPIDs
|
@param hosts list of host DPIDs
|
||||||
@param verbose verbose printing
|
|
||||||
@return ploss packet loss percentage
|
@return ploss packet loss percentage
|
||||||
'''
|
'''
|
||||||
#self.start()
|
#self.start()
|
||||||
@@ -354,9 +353,9 @@ class Mininet(object):
|
|||||||
ploss = None
|
ploss = None
|
||||||
if not hosts:
|
if not hosts:
|
||||||
hosts = self.topo.hosts()
|
hosts = self.topo.hosts()
|
||||||
|
lg.info('*** Ping: testing ping reachability\n')
|
||||||
for node_dpid in hosts:
|
for node_dpid in hosts:
|
||||||
node = self.nodes[node_dpid]
|
node = self.nodes[node_dpid]
|
||||||
if verbose:
|
|
||||||
lg.info('%s -> ' % node.name)
|
lg.info('%s -> ' % node.name)
|
||||||
for dest_dpid in hosts:
|
for dest_dpid in hosts:
|
||||||
dest = self.nodes[dest_dpid]
|
dest = self.nodes[dest_dpid]
|
||||||
@@ -370,26 +369,79 @@ class Mininet(object):
|
|||||||
node.cmdPrint('route')
|
node.cmdPrint('route')
|
||||||
exit( 1 )
|
exit( 1 )
|
||||||
lost += sent - received
|
lost += sent - received
|
||||||
if verbose:
|
|
||||||
lg.info(('%s ' % dest.name) if received else 'X ')
|
lg.info(('%s ' % dest.name) if received else 'X ')
|
||||||
if verbose:
|
|
||||||
lg.info('\n')
|
lg.info('\n')
|
||||||
ploss = 100 * lost / packets
|
ploss = 100 * lost / packets
|
||||||
if verbose:
|
lg.info("*** Results: %i%% dropped (%d/%d lost)\n" %
|
||||||
lg.info('%d%% packet loss (%d/%d lost)\n' % (ploss, lost, packets))
|
(ploss, lost, packets))
|
||||||
#flush()
|
|
||||||
#self.stop()
|
|
||||||
return ploss
|
return ploss
|
||||||
|
|
||||||
|
def ping_all(self):
|
||||||
|
'''Ping between all hosts.'''
|
||||||
|
self.ping()
|
||||||
|
|
||||||
|
def ping_pair(self):
|
||||||
|
'''Ping between first two hosts, useful for testing.'''
|
||||||
|
hosts_sorted = sorted(self.topo.hosts())
|
||||||
|
hosts = [hosts_sorted[0], hosts_sorted[1]]
|
||||||
|
self.ping(hosts = hosts)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _parseIperf(iperfOutput):
|
||||||
|
'''Parse iperf output and return bandwidth.
|
||||||
|
|
||||||
|
@param iperfOutput string
|
||||||
|
@return result string
|
||||||
|
'''
|
||||||
|
r = r'([\d\.]+ \w+/sec)'
|
||||||
|
m = re.search(r, iperfOutput)
|
||||||
|
if m:
|
||||||
|
return m.group(1)
|
||||||
|
else:
|
||||||
|
raise Exception('could not parse iperf output')
|
||||||
|
|
||||||
|
def iperf(self, hosts = None, verbose = False):
|
||||||
|
'''Run iperf between two hosts.
|
||||||
|
|
||||||
|
@param hosts list of host DPIDs; if None, uses opposite hosts
|
||||||
|
@param verbose verbose printing
|
||||||
|
@return results two-element array of server and client speeds
|
||||||
|
'''
|
||||||
|
if not hosts:
|
||||||
|
hosts_sorted = sorted(self.topo.hosts())
|
||||||
|
hosts = [hosts_sorted[0], hosts_sorted[-1]]
|
||||||
|
else:
|
||||||
|
assert len(hosts) == 2
|
||||||
|
host0 = self.nodes[hosts[0]]
|
||||||
|
host1 = self.nodes[hosts[1]]
|
||||||
|
lg.info('*** Iperf: testing bandwidth between ')
|
||||||
|
lg.info("%s and %s\n" % (host0.name, host1.name))
|
||||||
|
host0.cmd('killall -9 iperf')
|
||||||
|
server = host0.cmd('iperf -s &')
|
||||||
|
if verbose:
|
||||||
|
lg.info('%s\n' % server)
|
||||||
|
client = host1.cmd('iperf -t 5 -c ' + host0.IP())
|
||||||
|
if verbose:
|
||||||
|
lg.info('%s\n' % client)
|
||||||
|
server = host0.cmd('killall -9 iperf')
|
||||||
|
if verbose:
|
||||||
|
lg.info('%s\n' % server)
|
||||||
|
result = [self._parseIperf(server), self._parseIperf(client)]
|
||||||
|
lg.info('*** Results: %s\n' % result)
|
||||||
|
return result
|
||||||
|
|
||||||
def interact(self):
|
def interact(self):
|
||||||
'''Start network and run our simple CLI.'''
|
'''Start network and run our simple CLI.'''
|
||||||
self.run(MininetCLI)
|
self.start()
|
||||||
|
result = MininetCLI(self)
|
||||||
|
self.stop()
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
class MininetCLI(object):
|
class MininetCLI(object):
|
||||||
'''Simple command-line interface to talk to nodes.'''
|
'''Simple command-line interface to talk to nodes.'''
|
||||||
cmds = ['?', 'help', 'nodes', 'net', 'sh', 'ping_all', 'exit', \
|
cmds = ['?', 'help', 'nodes', 'net', 'sh', 'ping_all', 'exit', \
|
||||||
'ping_pair'] #'iperf'
|
'ping_pair', 'iperf']
|
||||||
|
|
||||||
def __init__(self, mininet):
|
def __init__(self, mininet):
|
||||||
self.mn = mininet
|
self.mn = mininet
|
||||||
@@ -442,13 +494,15 @@ class MininetCLI(object):
|
|||||||
|
|
||||||
def ping_all(self, args):
|
def ping_all(self, args):
|
||||||
'''Ping between all hosts.'''
|
'''Ping between all hosts.'''
|
||||||
self.mn.ping_test(verbose = True)
|
self.mn.ping_all()
|
||||||
|
|
||||||
def ping_pair(self, args):
|
def ping_pair(self, args):
|
||||||
'''Ping between first two hosts, useful for testing.'''
|
'''Ping between first two hosts, useful for testing.'''
|
||||||
hosts_unsorted = sorted(self.mn.topo.hosts())
|
self.mn.ping_pair()
|
||||||
hosts = [hosts_unsorted[0], hosts_unsorted[1]]
|
|
||||||
self.mn.ping_test(hosts = hosts, verbose = True)
|
def iperf(self, args):
|
||||||
|
'''Simple iperf test between two hosts.'''
|
||||||
|
self.mn.iperf()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
'''Read and execute commands.'''
|
'''Read and execute commands.'''
|
||||||
|
|||||||
Reference in New Issue
Block a user