Create a custom topology shown as figure 1 and run in Mininet
Create a python file
vi ~/minint/custom/multi-hosts.py
from mininet.topo import Topo
class MyTopo( Topo ):
"Simple topology example."
def __init__( self ):
"Create custom topo."
# Initialize topology
Topo.__init__( self )
# Add hosts and switches
Host1 = self.addHost( 'h1' )
Host2 = self.addHost( 'h2' )
Host3 = self.addHost( 'h3' )
Host4 = self.addHost( 'h4' )
Switch1 = self.addSwitch('s1')
Switch2 = self.addSwitch('s2')
# Add links
self.addLink( Host1, Switch1 )
self.addLink( Host2, Switch1 )
self.addLink( Host3, Switch2 )
self.addLink( Host4, Switch2 )
self.addLink( Switch1, Switch2 )
topos = { 'mytopo': ( lambda: MyTopo() ) }
Start the topology and enter Mininet CLI
run
mininet@mininet-vm:~$ sudo mn --custom ./mininet/custom/multi-hosts.py --topo=mytopo
***Creating network
***Adding controller
***Adding hosts:
h1 h2 h3 h4
***Adding switches:
s1 s2
***Adding links:
(h1, s1) (h2, s1) (h3, s2) (h4, s2) (s1, s2)
***Configuring hosts
h1 h2 h3 h4
***Starting controller
c0
***Starting 2 switches
s1 s2
***Starting CLI:
mininet>
Display nodes
mininet> nodes
available nodes are:
c0 h1 h2 h3 h4 s1 s2
Display links
mininet> links
h1-eth0<->s1-eth1 (OK OK)
h2-eth0<->s1-eth2 (OK OK)
h3-eth0<->s2-eth1 (OK OK)
h4-eth0<->s2-eth2 (OK OK)
s1-eth3<->s2-eth3 (OK OK)
Display net
mininet> net
h1 h1-eth0:s1-eth1
h2 h2-eth0:s1-eth2
h3 h3-eth0:s2-eth1
h4 h4-eth0:s2-eth2
s1 lo: s1-eth1:h1-eth0 s1-eth2:h2-eth0 s1-eth3:s2-eth3
s2 lo: s2-eth1:h3-eth0 s2-eth2:h4-eth0 s2-eth3:s1-eth3
c0
Display h1's interface configuration
mininet> h1 ifconfig
h1-eth0 Link encap:Ethernet HWaddr 8e:4f:d8:24:e1:e6
inet addr:10.0.0.1 Bcast:10.255.255.255 Mask:255.0.0.0
inet6 addr: fe80::8c4f:d8ff:fe24:e1e6/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:17 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1326 (1.3 KB) TX bytes:648 (648.0 B)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)