#!/usr/bin/python
from mininet.net import Mininet
from mininet.node import Controller,RemoteController
from mininet.node import OVSKernelSwitch
from mininet.node import UserSwitch
from mininet.cli import CLI
from mininet.log import setLogLevel
from mininet.link import Link, TCLink
def topology():
"Create a
network."
net = Mininet(
controller=RemoteController, link=TCLink, switch=OVSKernelSwitch )
print "***
Creating nodes"
h1 = net.addHost(
'h1', mac='00:00:00:00:00:01', ip='0.0.0.0' )
h2 = net.addHost(
'h2', mac='00:00:00:00:00:02', ip='192.168.10.1/24' )
h3 = net.addHost(
'h3', mac='00:00:00:00:00:03', ip='192.168.10.2/24' )
h4 = net.addHost(
'h4', mac='00:00:00:00:00:04', ip='192.168.20.1/24' )
h5 = net.addHost(
'h5', mac='00:00:00:00:00:05', ip='192.168.20.2/24' )
h6 = net.addHost(
'h6', mac='00:00:00:00:00:06', ip='0.0.0.0' )
c7 =
net.addController( 'c7', controller=RemoteController, ip='127.0.0.1', port=6633
)
print "***
Creating links"
Link(h1, h2,
intfName1='h1-eth0')
Link(h1, h3,
intfName1='h1-eth1')
Link(h1, h4,
intfName1='h1-eth2')
Link(h1, h5,
intfName1='h1-eth3')
Link(h1, h6,
intfName1='h1-eth4', intfName2='h6-eth0')
net.build()
h1.cmd("sudo
ifconfig h1-eth0 0")
h1.cmd("sudo
ifconfig h1-eth1 0")
h1.cmd("sudo
ifconfig h1-eth2 0")
h1.cmd("sudo
ifconfig h1-eth3 0")
h1.cmd("sudo
ifconfig h1-eth4 0")
h1.cmd("sudo
brctl addbr brvlan10")
h1.cmd("sudo
brctl addif brvlan10 h1-eth0")
h1.cmd("sudo
brctl addif brvlan10 h1-eth1")
h1.cmd("sudo
brctl addbr brvlan20")
h1.cmd("sudo
brctl addif brvlan20 h1-eth2")
h1.cmd("sudo
brctl addif brvlan20 h1-eth3")
h1.cmd("sudo
vconfig add h1-eth4 10")
h1.cmd("sudo
vconfig add h1-eth4 20")
h1.cmd("sudo
brctl addif brvlan10 h1-eth4.10")
h1.cmd("sudo
brctl addif brvlan20 h1-eth4.20")
h1.cmd("sudo
ifconfig h1-eth4.10 up")
h1.cmd("sudo
ifconfig h1-eth4.20 up")
h1.cmd("sudo
ifconfig brvlan10 up")
h1.cmd("sudo
ifconfig brvlan20 up")
h6.cmd("sudo
vconfig add h6-eth0 10")
h6.cmd("sudo
vconfig add h6-eth0 20")
h6.cmd("sudo
ifconfig h6-eth0.10 192.168.10.254 netmassk 255.255.255.0 up")
h6.cmd("sudo
ifconfig h6-eth0.20 192.168.20.254 netmassk 255.255.255.0 up")
h6.cmd("sudo
echo 1 > /proc/sys/net/ipv4/ip_forward")
h2.cmd("sudo
ip route add 192.168.20.0/24 via 192.168.10.254 dev h2-eth0")
h3.cmd("sudo
ip route add 192.168.20.0/24 via 192.168.10.254 dev h3-eth0")
h4.cmd("sudo
ip route add 192.168.10.0/24 via 192.168.20.254 dev h4-eth0")
h5.cmd("sudo
ip route add 192.168.10.0/24 via 192.168.20.254 dev h5-eth0")
c7.start()
print "***
Running CLI"
CLI( net )
print "***
Stopping network"
net.stop()
if __name__ == '__main__':
setLogLevel(
'info' )
topology()
EmoticonEmoticon