Statistics
| Branch: | Tag: | Revision:

mininet / examples / hwintf.py @ edf60032

History | View | Annotate | Download (1.14 KB)

1
#!/usr/bin/python
2

    
3
"""
4
This example shows how to add an interface (for example a real
5
hardware interface) to a network after the network is created.
6
"""
7

    
8
import re
9

    
10
from mininet.cli import CLI
11
from mininet.log import setLogLevel, info, error
12
from mininet.net import Mininet
13
from mininet.topolib import TreeTopo
14
from mininet.util import quietRun
15

    
16
def checkIntf( intf ):
17
    "Make sure intf exists and is not configured."
18
    if ( ' %s:' % intf ) not in quietRun( 'ip link show' ):
19
        error( 'Error:', intf, 'does not exist!\n' )
20
        exit( 1 )
21
    ips = re.findall( r'\d+\.\d+\.\d+\.\d+', quietRun( 'ifconfig ' + intf ) )
22
    if ips:
23
        error( 'Error:', intf, 'has an IP address,'
24
               'and is probably in use!\n' )
25
        exit( 1 )
26

    
27
if __name__ == '__main__':
28
    setLogLevel( 'info' )
29

    
30
    newIntf = 'eth1'
31
    info( '*** Checking', newIntf, '\n' )
32
    checkIntf( newIntf )
33

    
34
    info( '*** Creating network\n' )
35
    net = Mininet( topo=TreeTopo( depth=1, fanout=2 ) )
36

    
37
    switch = net.switches[ 0 ]
38
    info( '*** Adding', newIntf, 'to switch', switch.name, '\n' )
39
    switch.addIntf( newIntf )
40

    
41
    net.start()
42
    CLI( net )
43
    net.stop()