3 Hosts

 

H1---H2---H3

 

mininet 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', ip='192.168.10.1/24' )

    h2 = net.addHost( 'h2', mac='00:00:00:00:00:02', ip='192.168.10.2/24' )

    h3 = net.addHost( 'h3', mac='00:00:00:00:00:03', ip='192.168.20.2/24' )

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

    print "*** Creating links"

    Link(h1, h2)

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

    net.build()

    h2.cmd('ifconfig h2-eth1 192.168.20.1 netmask 255.255.255.0')

    h1.cmd("sudo echo 1 > /proc/sys/net/ipv4/ip_forward")

    h2.cmd("sudo echo 1 > /proc/sys/net/ipv4/ip_forward")

    h3.cmd("sudo echo 1 > /proc/sys/net/ipv4/ip_forward")

    h1.cmd("sudo ip route add 192.168.20.0/24 via 192.168.10.2 dev h1-eth0")

    h3.cmd("sudo ip route add 192.168.10.0/24 via 192.168.20.1 dev h3-eth0")

    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