[Question]

Dear Professor,
        I saw your ppt(Lab 5) on the Internet about OpenFlow.
        What if I want a topology that contain two switch s1 and s2 and 4 hosts.    h1 h2 linked to s1 ; s1 linked to s2 ; h3 h4 linked to s2  . But h1 can only communicate to h3, h2 can only communicate to h4.
I’m just confused about how to add rules to the ports.
Really looking forward to your reply.
Best Wishes,

 

 

[Answer]

 

mininet-script (1104.py)

#!/usr/bin/python

 

"""

Script created by VND - Visual Network Description (SDN version)

"""

from mininet.net import Mininet

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

    s1 = net.addSwitch( 's1', listenPort=6673, mac='00:00:00:00:00:01' )

    s2 = net.addSwitch( 's2', listenPort=6674, mac='00:00:00:00:00:02' )

    h1 = net.addHost( 'h1', mac='00:00:00:00:00:11', ip='10.0.0.1/8' )

    h2 = net.addHost( 'h2', mac='00:00:00:00:00:12', ip='10.0.0.2/8' )

    h3 = net.addHost( 'h3', mac='00:00:00:00:00:13', ip='10.0.0.3/8' )

    h4 = net.addHost( 'h4', mac='00:00:00:00:00:14', ip='10.0.0.4/8' )

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

 

    print "*** Creating links"

    net.addLink(s1, h1)

    net.addLink(s1, h2)

    net.addLink(s1, s2)

    net.addLink(s2, h3)

    net.addLink(s2, h4)

 

    print "*** Starting network"

    net.build()

    c8.start()

    s2.start( [c8] )

    s1.start( [c8] )

 

    print "*** Running CLI"

    CLI( net )

 

    print "*** Stopping network"

    net.stop()

 

if __name__ == '__main__':

    setLogLevel( 'info' )

    topology()

 

pyretic controller-route_1104.py

from pyretic.lib.corelib import*

from pyretic.lib.std import *

 

ip1 = IPAddr('10.0.0.1')

ip2 = IPAddr('10.0.0.2')

ip3 = IPAddr('10.0.0.3')

ip4 = IPAddr('10.0.0.4')

 

#h1-s1-s2-h3

route1 = ((match(switch=1) >> fwd(3)) +

          (match(switch=2) >> fwd(2)))

 

#h3-s2-s1-h1

route2 = ((match(switch=2) >> fwd(1)) +

          (match(switch=1) >> fwd(1)))

 

#h2-s1-s2-h4

route3 = ((match(switch=1) >> fwd(3)) +

          (match(switch=2) >> fwd(3)))

 

#h4-s2-s1-h2

route4 = ((match(switch=2) >> fwd(1)) +

          (match(switch=1) >> fwd(2)))

 

myroute = (((match(srcip=ip1) & match(dstip=ip3)) >> route1) +

           ((match(srcip=ip3) & match(dstip=ip1)) >> route2) +

           ((match(srcip=ip2) & match(dstip=ip4)) >> route3) +

           ((match(srcip=ip4) & match(dstip=ip2)) >> route4))

 

def main():

   return myroute

 

 

 

 

 

 

 

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

Department of Computer Science and Information Engineering,

National Quemoy University, Kinmen, Taiwan.