Add bridges s1-s3 to topology and explain some details
This commit is contained in:
+34
-21
@@ -6,20 +6,23 @@ linuxrouter.py: Example network with Linux IP router
|
|||||||
This example converts a Node into a router using IP forwarding
|
This example converts a Node into a router using IP forwarding
|
||||||
already built into Linux.
|
already built into Linux.
|
||||||
|
|
||||||
The topology contains a router with three IP subnets:
|
The example topology creates a router and three IP subnets:
|
||||||
- 192.168.1.0/24 (interface IP: 192.168.1.1)
|
|
||||||
- 172.16.0.0/12 (interface IP: 172.16.0.1)
|
|
||||||
- 10.0.0.0/8 (interface IP: 10.0.0.1)
|
|
||||||
|
|
||||||
It also contains three hosts, one in each subnet:
|
- 192.168.1.0/24 (r0-eth1, IP: 192.168.1.1)
|
||||||
- h1 (IP: 192.168.1.100)
|
- 172.16.0.0/12 (r0-eth2, IP: 172.16.0.1)
|
||||||
- h2 (IP: 172.16.0.100)
|
- 10.0.0.0/8 (r0-eth3, IP: 10.0.0.1)
|
||||||
- h3 (IP: 10.0.0.100)
|
|
||||||
|
|
||||||
Routing entries can be added to the routing tables of the
|
Each subnet consists of a single host connected to
|
||||||
hosts or router using the "ip route add" or "route add" command.
|
a single switch:
|
||||||
See the man pages for more details.
|
|
||||||
|
|
||||||
|
r0-eth1 - s1-eth1 - h1-eth0 (IP: 192.168.1.100)
|
||||||
|
r0-eth2 - s2-eth1 - h2-eth0 (IP: 172.16.0.100)
|
||||||
|
r0-eth3 - s3-eth1 - h3-eth0 (IP: 10.0.0.100)
|
||||||
|
|
||||||
|
The example relies on default routing entries that are
|
||||||
|
automatically created for each interface. Additional
|
||||||
|
routes may be added to the router or hosts by executing
|
||||||
|
'ip route' or 'route' commands on the router or hosts.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from mininet.topo import Topo
|
from mininet.topo import Topo
|
||||||
@@ -42,29 +45,39 @@ class LinuxRouter( Node ):
|
|||||||
|
|
||||||
|
|
||||||
class NetworkTopo( Topo ):
|
class NetworkTopo( Topo ):
|
||||||
"A simple topology of a router with three subnets (one host in each)."
|
"A LinuxRouter connecting three IP subnets"
|
||||||
|
|
||||||
def build( self, **_opts ):
|
def build( self, **_opts ):
|
||||||
router = self.addNode( 'r0', cls=LinuxRouter, ip='192.168.1.1/24' )
|
|
||||||
|
defaultIP='192.168.1.1/24' # IP address for r0-eth1
|
||||||
|
router = self.addNode( 'r0', cls=LinuxRouter, ip=defaultIP )
|
||||||
|
|
||||||
|
s1, s2, s3 = [ self.addSwitch( s ) for s in 's1', 's2', 's3' ]
|
||||||
|
|
||||||
|
self.addLink( s1, router, intfName2='r0-eth1',
|
||||||
|
params2={ 'ip' : defaultIP } ) # for clarity
|
||||||
|
self.addLink( s2, router, intfName2='r0-eth2',
|
||||||
|
params2={ 'ip' : '172.16.0.1/12' } )
|
||||||
|
self.addLink( s3, router, intfName2='r0-eth3',
|
||||||
|
params2={ 'ip' : '10.0.0.1/8' } )
|
||||||
|
|
||||||
h1 = self.addHost( 'h1', ip='192.168.1.100/24',
|
h1 = self.addHost( 'h1', ip='192.168.1.100/24',
|
||||||
defaultRoute='via 192.168.1.1' )
|
defaultRoute='via 192.168.1.1' )
|
||||||
h2 = self.addHost( 'h2', ip='172.16.0.100/12',
|
h2 = self.addHost( 'h2', ip='172.16.0.100/12',
|
||||||
defaultRoute='via 172.16.0.1' )
|
defaultRoute='via 172.16.0.1' )
|
||||||
h3 = self.addHost( 'h3', ip='10.0.0.100/8',
|
h3 = self.addHost( 'h3', ip='10.0.0.100/8',
|
||||||
defaultRoute='via 10.0.0.1' )
|
defaultRoute='via 10.0.0.1' )
|
||||||
self.addLink( h1, router, intfName2='r0-eth1',
|
|
||||||
params2={ 'ip' : '192.168.1.1/24' } )
|
for h, s in [ (h1,s1), (h2,s2), (h3,s3) ]:
|
||||||
self.addLink( h2, router, intfName2='r0-eth2',
|
self.addLink( h, s )
|
||||||
params2={ 'ip' : '172.16.0.1/12' } )
|
|
||||||
self.addLink( h3, router, intfName2='r0-eth3',
|
|
||||||
params2={ 'ip' : '10.0.0.1/8' } )
|
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
"Test linux router"
|
"Test linux router"
|
||||||
topo = NetworkTopo()
|
topo = NetworkTopo()
|
||||||
net = Mininet( topo=topo, controller=None ) # no controller needed
|
net = Mininet( topo=topo ) # controller is used by s1-s3
|
||||||
net.start()
|
net.start()
|
||||||
info( '*** Routing Table on Router\n' )
|
info( '*** Routing Table on Router:\n' )
|
||||||
print net[ 'r0' ].cmd( 'route' )
|
print net[ 'r0' ].cmd( 'route' )
|
||||||
CLI( net )
|
CLI( net )
|
||||||
net.stop()
|
net.stop()
|
||||||
|
|||||||
Reference in New Issue
Block a user