Update and rename MantenerFIFO to MantenerFIFO.md
[vsorcdistro/.git] / mininet / examples / hwintf.py
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 import sys
10
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
17
18 def checkIntf( intf ):
19     "Make sure intf exists and is not configured."
20     config = quietRun( 'ifconfig %s 2>/dev/null' % intf, shell=True )
21     if not config:
22         error( 'Error:', intf, 'does not exist!\n' )
23         exit( 1 )
24     ips = re.findall( r'\d+\.\d+\.\d+\.\d+', config )
25     if ips:
26         error( 'Error:', intf, 'has an IP address,'
27                'and is probably in use!\n' )
28         exit( 1 )
29
30 if __name__ == '__main__':
31     setLogLevel( 'info' )
32
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 )
36
37     info( '*** Checking', intfName, '\n' )
38     checkIntf( intfName )
39
40     info( '*** Creating network\n' )
41     net = Mininet( topo=TreeTopo( depth=1, fanout=2 ) )
42
43     switch = net.switches[ 0 ]
44     info( '*** Adding hardware interface', intfName, 'to switch',
45           switch.name, '\n' )
46     _intf = Intf( intfName, node=switch )
47
48     info( '*** Note: you may need to reconfigure the interfaces for '
49           'the Mininet hosts:\n', net.hosts, '\n' )
50
51     net.start()
52     CLI( net )
53     net.stop()