Revision e0bf8ece

View differences:

examples/bind.py
38 38
from mininet.node import Host
39 39
from mininet.cli import CLI
40 40
from mininet.topo import SingleSwitchTopo
41
from mininet.log import setLogLevel, info, debug
41
from mininet.log import setLogLevel, info
42 42

  
43 43
from functools import partial
44 44

  
examples/clusterSanity.py
5 5
'''
6 6

  
7 7
from mininet.examples.cluster import MininetCluster
8
from mininet.log import info, setLogLevel
8
from mininet.log import setLogLevel
9 9
from mininet.examples.clustercli import ClusterCLI as CLI
10 10
from mininet.topo import SingleSwitchTopo
11 11

  
examples/clustercli.py
32 32
                import networkx as nx
33 33
                import matplotlib.pyplot as plt
34 34
                import pygraphviz
35
                assert pygraphviz  # silence pyflakes
35 36
            except:
36 37
                error( 'plot requires networkx, matplotlib and pygraphviz - '
37 38
                       'please install them and try again\n' )
......
40 41
        g = nx.Graph()
41 42
        mn = self.mn
42 43
        servers, hosts, switches = mn.servers, mn.hosts, mn.switches
43
        hlen, slen = len( hosts ), len( switches )
44 44
        nodes = hosts + switches
45 45
        g.add_nodes_from( nodes )
46 46
        links = [ ( link.intf1.node, link.intf2.node )
examples/cpu.py
8 8
from mininet.node import CPULimitedHost
9 9
from mininet.topolib import TreeTopo
10 10
from mininet.util import custom, waitListening
11
from mininet.log import setLogLevel, output, info
11
from mininet.log import setLogLevel, info
12 12

  
13
from time import sleep
14 13

  
15 14
def bwtest( cpuLimits, period_us=100000, seconds=5 ):
16 15
    """Example/test of link and CPU bandwidth limits
examples/intfOptions.py
1
#!/usr/bin/python
2

  
3
'''
4
example of using various TCIntf options.
5
reconfigures a single interface using intf.config()
6
to use different traffic control commands to test
7
bandwidth, loss, and delay
8
'''
9

  
10
from mininet.net import Mininet
11
from mininet.log import setLogLevel, info
12
from mininet.link import TCLink
13

  
14
def intfOptions():
15
    "run various traffic control commands on a single interface"
16
    net = Mininet( autoStaticArp=True )
17
    net.addController( 'c0' )
18
    h1 = net.addHost( 'h1' )
19
    h2 = net.addHost( 'h2' )
20
    s1 = net.addSwitch( 's1' )
21
    link1 = net.addLink( h1, s1, cls=TCLink )
22
    link2 = net.addLink( h2, s1 )
23
    net.start()
24
    
25
    # flush out latency from reactive forwarding delay
26
    net.pingAll()
27

  
28
    info( '\n*** Configuring one intf with bandwidth of 5 Mb\n' )
29
    link1.intf1.config( bw=5 )
30
    info( '\n*** Running iperf to test\n' )
31
    net.iperf()
32

  
33
    info( '\n*** Configuring one intf with loss of 50%\n' )
34
    link1.intf1.config( loss=50 )
35
    info( '\n' )
36
    net.iperf( ( h1, h2 ), l4Type='UDP' )
37
    
38
    info( '\n*** Configuring one intf with delay of 15ms\n' )
39
    link1.intf1.config( delay='15ms' )
40
    info( '\n*** Run a ping to confirm delay\n' )
41
    net.pingPairFull()
42
    
43
    info( '\n*** Done testing\n' )
44
    net.stop()
45

  
46
if __name__ == '__main__':
47
    setLogLevel( 'info' )
48
    intfOptions()
examples/linuxrouter.py
27 27
from mininet.node import Node
28 28
from mininet.log import setLogLevel, info
29 29
from mininet.cli import CLI
30
from mininet.util import irange
31 30

  
32 31
class LinuxRouter( Node ):
33 32
    "A Node with IP forwarding enabled."
examples/mobility.py
22 22
from mininet.net import Mininet
23 23
from mininet.node import OVSSwitch
24 24
from mininet.topo import LinearTopo
25
from mininet.util import quietRun
26 25
from mininet.log import output, warn
27 26

  
28 27
from random import randint
29
from re import findall
30 28

  
31 29

  
32 30
class MobilitySwitch( OVSSwitch ):
examples/multiLink.py
1
#!/usr/bin/python
2

  
3
"""
4
This is a simple example that demonstrates multiple links
5
between nodes.
6
"""
7

  
8
from mininet.cli import CLI
9
from mininet.log import lg, info
10
from mininet.net import Mininet
11
from mininet.topo import Topo
12
    
13
def runMultiLink():
14
    
15
    topo = simpleMultiLinkTopo( n=2 )
16
    net = Mininet( topo=topo )
17
    net.start()
18
    CLI( net )
19
    net.stop()
20

  
21
class simpleMultiLinkTopo( Topo ):
22

  
23
    def __init__( self, n, **kwargs ):
24
        Topo.__init__( self, **kwargs )
25

  
26
        h1, h2 = self.addHost( 'h1' ), self.addHost( 'h2' )
27
        s1 = self.addSwitch( 's1' )
28
        
29
        for _ in range( n ):
30
            self.addLink( s1, h1 )
31
            self.addLink( s1, h2 )
32

  
33
if __name__ == '__main__':
34
    lg.setLogLevel( 'info' )
35
    runMultiLink()
examples/multilink.py
6 6
"""
7 7

  
8 8
from mininet.cli import CLI
9
from mininet.log import lg, info
9
from mininet.log import setLogLevel
10 10
from mininet.net import Mininet
11 11
from mininet.topo import Topo
12 12
    
......
31 31
            self.addLink( s1, h2 )
32 32

  
33 33
if __name__ == '__main__':
34
    lg.setLogLevel( 'info' )
34
    setLogLevel( 'info' )
35 35
    runMultiLink()
examples/numberedports.py
9 9
from mininet.net import Mininet
10 10
from mininet.node import Controller
11 11
from mininet.log import setLogLevel, info, warn
12
from mininet.node import Node
13 12

  
14 13
def validatePort( switch, intf ):
15 14
    "Validate intf's OF port number"
......
48 47
    net.addLink( h4, s1 )
49 48
    net.addLink( h5, s1, port1 = 1, port2 = 9 ) # specify a different port to connect host 5 to on the switch.
50 49

  
51
    root = Node( 'root', inNamespace=False )
52 50
    info( '*** Starting network\n' )
53 51
    net.start()
54 52

  
examples/simpleperf.py
40 40
    dumpNodeConnections(net.hosts)
41 41
    print "Testing bandwidth between h1 and h4"
42 42
    h1, h4 = net.getNodeByName('h1', 'h4')
43
    results = net.iperf( ( h1, h4 ), l4Type='UDP' )
43
    net.iperf( ( h1, h4 ), l4Type='UDP' )
44 44
    net.stop()
45 45

  
46 46
if __name__ == '__main__':
examples/test/test_intfOptions.py
1
#!/usr/bin/env python
2

  
3
"""
4
Test for intfOptions.py
5
"""
6

  
7
import unittest
8
import pexpect
9
import sys
10

  
11
class testIntfOptions( unittest.TestCase ):
12

  
13
    def testIntfOptions( self ):
14
        "verify that intf.config is correctly limiting traffic"
15
        p = pexpect.spawn( 'python -m mininet.examples.intfOptions ' )
16
        tolerance = .8
17
        opts = [ "Results: \['([\d\.]+) .bits/sec",
18
                 "Results: \['10M', '([\d\.]+) .bits/sec",
19
                 "h(\d+)->h(\d+): (\d)/(\d), rtt min/avg/max/mdev ([\d\.]+)/([\d\.]+)/([\d\.]+)/([\d\.]+) ms",
20
                 pexpect.EOF ]
21
        while True:
22
            index = p.expect( opts, timeout=600 )
23
            if index == 0:
24
                bw = float( p.match.group( 1 ) )
25
                self.assertGreaterEqual( bw, float( 5 * tolerance ) )
26
                self.assertLessEqual( bw, float( 5 + 5 * ( 1 - tolerance ) ) )
27
            elif index == 1:
28
                BW = 10
29
                measuredBw = float( p.match.group( 1 ) )
30
                loss = ( measuredBw / BW ) * 100
31
                self.assertGreaterEqual( loss, 50 * tolerance )
32
                self.assertLessEqual( loss,  50 + 50 * ( 1 - tolerance ) )
33
            elif index == 2:
34
                delay = float( p.match.group( 6 ) )
35
                self.assertGreaterEqual( delay, 15 * tolerance )
36
                self.assertLessEqual( delay,  15 + 15 * ( 1 - tolerance ) )
37
            else:
38
                break
39

  
40

  
41
if __name__ == '__main__':
42
    unittest.main()
examples/test/test_multiLink.py
1
#!/usr/bin/env python
2

  
3
'''
4
Test for multiple links between nodes
5
validates mininet interfaces against systems interfaces
6
'''
7

  
8
import unittest
9
import pexpect
10

  
11
class testMultiLink( unittest.TestCase ):
12

  
13
    prompt = 'mininet>'
14

  
15
    def testMultiLink(self):
16
        p = pexpect.spawn( 'python -m mininet.examples.multiLink' )
17
        p.expect( self.prompt )
18
        p.sendline( 'intfs' )
19
        p.expect( 's(\d): lo' )
20
        intfsOutput = p.before
21
        # parse interfaces from mininet intfs, and store them in a list
22
        hostToIntfs = intfsOutput.split( '\r\n' )[ 1:3 ]
23
        intfList = []
24
        for hostToIntf in hostToIntfs:
25
            intfList += [ intf for intf in 
26
                          hostToIntf.split()[1].split(',') ]
27

  
28
        # get interfaces from system by running ifconfig on every host
29
        sysIntfList = []
30
        opts = [ 'h(\d)-eth(\d)', self.prompt ]
31
        p.expect( self.prompt )
32
        
33
        p.sendline( 'h1 ifconfig' )
34
        while True:
35
            p.expect( opts )
36
            if p.after == self.prompt:
37
                break
38
            sysIntfList.append( p.after )
39

  
40
        p.sendline( 'h2 ifconfig' )
41
        while True:
42
            p.expect( opts )
43
            if p.after == self.prompt:
44
                break
45
            sysIntfList.append( p.after )
46

  
47
        failMsg = ( 'The systems interfaces and mininet interfaces\n'
48
                    'are not the same' )
49

  
50
        self.assertEqual( sysIntfList, intfList, msg=failMsg )
51
        p.sendline( 'exit' )
52
        p.wait()
53

  
54
if __name__ == '__main__':
55
        unittest.main()
mininet/test/test_switchdpidassignment.py
37 37
        name of the switch does not contin a digit. Also verify the 
38 38
        exception message."""
39 39
        with self.assertRaises( Exception ) as raises_cm:
40
            switch = Mininet( Topo(), self.switchClass, Host, Controller ).addSwitch( 'A' )
40
            Mininet( Topo(), self.switchClass, Host, Controller ).addSwitch( 'A' )
41 41
        self.assertEqual(raises_cm.exception.message, 'Unable to derive '
42 42
                         'default datapath ID - please either specify a dpid '
43 43
                         'or use a canonical switch name such as s23.')

Also available in: Unified diff