adding example and test for intf.config
This commit is contained in:
Executable
+49
@@ -0,0 +1,49 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
'''
|
||||||
|
example of using various TCIntf options.
|
||||||
|
reconfigures a single interface using intf.config()
|
||||||
|
to use different traffic control commands to test
|
||||||
|
bandwidth, loss, and delay
|
||||||
|
'''
|
||||||
|
|
||||||
|
from mininet.net import Mininet
|
||||||
|
from mininet.log import setLogLevel, info
|
||||||
|
from mininet.link import TCLink
|
||||||
|
|
||||||
|
def intfOptions():
|
||||||
|
"run various traffic control commands on a single interface"
|
||||||
|
net = Mininet()
|
||||||
|
net.addController( 'c0' )
|
||||||
|
h1 = net.addHost( 'h1' )
|
||||||
|
h2 = net.addHost( 'h2' )
|
||||||
|
s1 = net.addSwitch( 's1' )
|
||||||
|
link1 = net.addLink( h1, s1, cls=TCLink )
|
||||||
|
link2 = net.addLink( h2, s1 )
|
||||||
|
net.start()
|
||||||
|
|
||||||
|
# flush out latency from reactive forwarding delay
|
||||||
|
net.pingAll()
|
||||||
|
|
||||||
|
info( '\n*** Configuring one intf with bandwidth of 5 Mb\n' )
|
||||||
|
link1.intf1.config( bw=5 )
|
||||||
|
info( '\n*** Running iperf to test\n' )
|
||||||
|
net.iperf()
|
||||||
|
|
||||||
|
info( '\n*** Configuring one intf with loss of 50%\n' )
|
||||||
|
link1.intf1.config( loss=50 )
|
||||||
|
info( '\n*** Running 20 pings to test\n' )
|
||||||
|
info( net.hosts[ 0 ].cmd( 'ping -c 20 -i .2 10.0.0.2' ) )
|
||||||
|
|
||||||
|
|
||||||
|
info( '\n*** Configuring one intf with delay of 15ms\n' )
|
||||||
|
link1.intf1.config( delay='15ms' )
|
||||||
|
info( '\n*** Run a ping to confirm delay' )
|
||||||
|
net.pingPairFull()
|
||||||
|
|
||||||
|
info( '\n*** Done testing\n' )
|
||||||
|
net.stop()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
setLogLevel( 'info' )
|
||||||
|
intfOptions()
|
||||||
Executable
+45
@@ -0,0 +1,45 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
"""
|
||||||
|
Test for intfOptions.py
|
||||||
|
"""
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
import pexpect
|
||||||
|
import sys
|
||||||
|
|
||||||
|
class testIntfOptions( unittest.TestCase ):
|
||||||
|
|
||||||
|
def testIntfOptions( self ):
|
||||||
|
"verify that intf.config is correctly limiting traffic"
|
||||||
|
p = pexpect.spawn( 'python -m mininet.examples.intfOptions ' )
|
||||||
|
tolerance = .8
|
||||||
|
opts = [ "Results: \['([\d\.]+) .bits/sec",
|
||||||
|
"(\d+) packets transmitted, (\d+) received, (\d+)% packet loss, time (\d+)ms",
|
||||||
|
"h(\d+)->h(\d+): (\d)/(\d), rtt min/avg/max/mdev ([\d\.]+)/([\d\.]+)/([\d\.]+)/([\d\.]+) ms",
|
||||||
|
pexpect.EOF ]
|
||||||
|
while True:
|
||||||
|
index = p.expect( opts, timeout=600 )
|
||||||
|
if index == 0:
|
||||||
|
bw = float( p.match.group( 1 ) )
|
||||||
|
self.assertGreaterEqual( bw, float( 5 * tolerance ) )
|
||||||
|
self.assertLessEqual( bw, float( 5 + 5 * ( 1 - tolerance ) ) )
|
||||||
|
elif index == 1:
|
||||||
|
loss = int( p.match.group( 3 ) )
|
||||||
|
msg = ( "testing packet loss at 50%\n",
|
||||||
|
"this test will sometimes fail\n",
|
||||||
|
"ran 20 pings accross network\n",
|
||||||
|
"packet loss is %d%%\n\n"
|
||||||
|
% loss )
|
||||||
|
self.assertGreaterEqual( loss, 50 * .8, msg )
|
||||||
|
self.assertLessEqual( loss, 50 + 50 * ( 1 - tolerance ), msg )
|
||||||
|
elif index == 2:
|
||||||
|
delay = float( p.match.group( 6 ) )
|
||||||
|
self.assertGreaterEqual( delay, 15 * .8 )
|
||||||
|
self.assertLessEqual( delay, 15 + 15 * ( 1 - tolerance ) )
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
Reference in New Issue
Block a user