4 This example shows how to add an interface (for example a real
5 hardware interface) to a network after the network is created.
11 from mininet.cli import CLI
12 from mininet.log import setLogLevel, info, error
13 from mininet.net import Mininet
14 from mininet.link import Intf
15 from mininet.topolib import TreeTopo
16 from mininet.util import quietRun
18 def checkIntf( intf ):
19 "Make sure intf exists and is not configured."
20 config = quietRun( 'ifconfig %s 2>/dev/null' % intf, shell=True )
22 error( 'Error:', intf, 'does not exist!\n' )
24 ips = re.findall( r'\d+\.\d+\.\d+\.\d+', config )
26 error( 'Error:', intf, 'has an IP address,'
27 'and is probably in use!\n' )
30 if __name__ == '__main__':
33 # try to get hw intf from the command line; by default, use eth1
34 intfName = sys.argv[ 1 ] if len( sys.argv ) > 1 else 'eth1'
35 info( '*** Connecting to hw intf: %s' % intfName )
37 info( '*** Checking', intfName, '\n' )
40 info( '*** Creating network\n' )
41 net = Mininet( topo=TreeTopo( depth=1, fanout=2 ) )
43 switch = net.switches[ 0 ]
44 info( '*** Adding hardware interface', intfName, 'to switch',
46 _intf = Intf( intfName, node=switch )
48 info( '*** Note: you may need to reconfigure the interfaces for '
49 'the Mininet hosts:\n', net.hosts, '\n' )