cleaned up and commented test_simpleperf.py
This commit is contained in:
@@ -1,10 +1,12 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
"""TEST"""
|
"""
|
||||||
|
Test for simpleperf.py
|
||||||
|
"""
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
import pexpect
|
import pexpect
|
||||||
from time import sleep
|
import re
|
||||||
from mininet.log import setLogLevel
|
from mininet.log import setLogLevel
|
||||||
from mininet.net import Mininet
|
from mininet.net import Mininet
|
||||||
from mininet.node import CPULimitedHost
|
from mininet.node import CPULimitedHost
|
||||||
@@ -13,24 +15,36 @@ from mininet.link import TCLink
|
|||||||
from mininet.examples.simpleperf import SingleSwitchTopo
|
from mininet.examples.simpleperf import SingleSwitchTopo
|
||||||
|
|
||||||
class testSimplePerf( unittest.TestCase ):
|
class testSimplePerf( unittest.TestCase ):
|
||||||
"Test ping with single switch topology (common code)."
|
|
||||||
|
|
||||||
|
|
||||||
def testE2E( self ):
|
def testE2E( self ):
|
||||||
results = [ "Results:", pexpect.EOF, pexpect.TIMEOUT ]
|
"Run the example and verify ping and iperf results"
|
||||||
p = pexpect.spawn( 'python -m mininet.examples.simpleperf' )
|
p = pexpect.spawn( 'python -m mininet.examples.simpleperf' )
|
||||||
index = p.expect( results, timeout=600 )
|
# check ping results
|
||||||
self.assertEqual( index, 0 )
|
p.expect( "Results: (\d+)% dropped", timeout=120 )
|
||||||
|
loss = int( p.match.group( 1 ) )
|
||||||
|
self.assertTrue( loss > 0 and loss < 100 )
|
||||||
|
# check iperf results
|
||||||
|
p.expect( "Results: \['([\d\.]+) .bits/sec", timeout=480 )
|
||||||
|
bw = float( p.match.group( 1 ) )
|
||||||
|
self.assertTrue( bw > 0 )
|
||||||
p.wait()
|
p.wait()
|
||||||
|
|
||||||
def testTopo( self ):
|
def testTopo( self ):
|
||||||
|
"""Import SingleSwitchTopo from example and test connectivity between two hosts
|
||||||
|
Note: this test may fail very rarely because it is non-deterministic
|
||||||
|
i.e. links are configured with 10% packet loss, but if we get unlucky and
|
||||||
|
none or all of the packets are dropped, the test will fail"""
|
||||||
topo = SingleSwitchTopo( n=4 )
|
topo = SingleSwitchTopo( n=4 )
|
||||||
net = Mininet(topo=topo,
|
net = Mininet( topo=topo, host=CPULimitedHost, link=TCLink )
|
||||||
host=CPULimitedHost, link=TCLink)
|
|
||||||
net.start()
|
net.start()
|
||||||
h1, h4 = net.get( 'h1', 'h4' )
|
h1, h4 = net.get( 'h1', 'h4' )
|
||||||
h1.cmd( 'ping -c 1 %s' % h4.IP() )
|
# have h1 ping h4 ten times
|
||||||
|
expectStr = '(\d+) packets transmitted, (\d+) received, (\d+)% packet loss'
|
||||||
|
output = h1.cmd( 'ping -c 10 %s' % h4.IP() )
|
||||||
|
m = re.search( expectStr, output )
|
||||||
|
loss = int( m.group( 3 ) )
|
||||||
net.stop()
|
net.stop()
|
||||||
|
self.assertTrue( loss > 0 and loss < 100 )
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
setLogLevel( 'warning' )
|
setLogLevel( 'warning' )
|
||||||
|
|||||||
Reference in New Issue
Block a user