blob: e5960d96a3e09330eebe55d884e274fce8a34d64 [file] [log] [blame]
carlosmscabralf40ecd12013-02-01 18:15:58 -02001#!/usr/bin/python
2
3"""
4This example shows how to add an interface (for example a real
5hardware interface) to a network after the network is created.
6"""
7
8import re
9
10from mininet.cli import CLI
11from mininet.log import setLogLevel, info, error
12from mininet.net import Mininet
13from mininet.link import Intf
14from mininet.topolib import TreeTopo
15from mininet.util import quietRun
16
17def checkIntf( intf ):
18 "Make sure intf exists and is not configured."
19 if ( ' %s:' % intf ) not in quietRun( 'ip link show' ):
20 error( 'Error:', intf, 'does not exist!\n' )
21 exit( 1 )
22 ips = re.findall( r'\d+\.\d+\.\d+\.\d+', quietRun( 'ifconfig ' + intf ) )
23 if ips:
24 error( 'Error:', intf, 'has an IP address,'
25 'and is probably in use!\n' )
26 exit( 1 )
27
28if __name__ == '__main__':
29 setLogLevel( 'info' )
30
31 intfName = 'eth1'
32 info( '*** Checking', intfName, '\n' )
33 checkIntf( intfName )
34
35 info( '*** Creating network\n' )
36 net = Mininet( topo=TreeTopo( depth=1, fanout=2 ) )
37
38 switch = net.switches[ 0 ]
39 info( '*** Adding hardware interface', intfName, 'to switch',
40 switch.name, '\n' )
41 _intf = Intf( intfName, node=switch )
42
43 info( '*** Note: you may need to reconfigure the interfaces for '
44 'the Mininet hosts:\n', net.hosts, '\n' )
45
46 net.start()
47 CLI( net )
48 net.stop()