Configure a node as a switch

[Prerequiste]

  sudo apt-get install bridge-utils

 

[Topology]

 

  (n1 ==> switch)

|       |       |

|       |       |

n2     n3     n4

 

[Script]

#!/usr/bin/python

"""

   Experiment to connect three hosts together without switch.     H1---H2---H3

"""

from mininet.net import Mininet

from mininet.node import Controller, RemoteController, OVSKernelSwitch, OVSLegacyKernelSwitch, 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')

    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.10.3/24' )

    c7 = net.addController( 'c7', controller=RemoteController, ip='127.0.0.1', port=6633 )

    print "*** Creating links"

    Link(h1, h2)

    Link(h1, h3, intfName1='h1-eth1')

    Link(h1, h4, intfName1='h1-eth2')

    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 brctl addbr mybr")

    h1.cmd("sudo brctl addif mybr h1-eth0")

    h1.cmd("sudo brctl addif mybr h1-eth1")

    h1.cmd("sudo brctl addif mybr h1-eth2")

    h1.cmd("sudo ifconfig mybr up")

    c7.start()

    print "*** Running CLI"

    CLI( net )

    print "*** Stopping network"

    net.stop()

 

if __name__ == '__main__':

    setLogLevel( 'info' )

    topology()

 

[Execution]

 

 

Dr. Chih-Heng Ke (smallko@gmail.com)

Department of Computer Science and Information Engineering,

National Quemoy University, Kinmen, Taiwan