Search code examples
pythonmininet

How to run this topology and then pingall the hosts. which switch I need to start and what changes should be made to it


# !/usr/bin/env python
from mininet.net import Mininet, CLI
from mininet.node import RemoteController, OVSKernelSwitch, UserSwitch, Host
from mininet.link import TCLink,Link
from mininet.term import makeTerms, makeTerm, runX11
import argparse
import subprocess
net = Mininet(controller=RemoteController, switch=OVSKernelSwitch, link=TCLink)
h1 = net.addHost ( 'h1', mac = '00:00:00:00:00:01', ip = '10.0.0.10' )
h2 = net.addHost ( 'h2', mac = '00:00:00:00:00:02', ip = '10.0.0.20' )
h3 = net.addHost ( 'h3', mac = '00:00:00:00:00:03', ip = '10.0.0.30' )
h4 = net.addHost ( 'h4', mac = '00:00:00:00:00:04', ip = '10.0.0.40' )
h5 = net.addHost ( 'h5', mac = '00:00:00:00:00:05', ip = '10.0.0.50' )
h6 = net.addHost ( 'h6', mac = '00:00:00:00:00:06', ip = '10.0.0.60' )
h7 = net.addHost ( 'h7', mac = '00:00:00:00:00:07', ip = '10.0.0.70' )
s1 = net.addSwitch ( 's1', cls = OVSKernelSwitch, protocols = 'OpenFlow13' )
s2 = net.addSwitch ( 's2', cls = OVSKernelSwitch, protocols = 'OpenFlow13' )
s3 = net.addSwitch ( 's3', cls = OVSKernelSwitch, protocols = 'OpenFlow13' )
s4 = net.addSwitch ( 's4', cls = OVSKernelSwitch, protocols = 'OpenFlow13' )
net.addLink( s1, s2, port1=1, port2=1)
net.addLink( s2, s3, port1=2, port2=2)
net.addLink( s1, s4, port1=2, port2=1)
net.addLink( s3, s4, port1=3, port2=2)
net.addLink( s1, s3, port1=3, port2=1)
net.addLink( s3, h6)
net.addLink( s3, h4)
net.addLink( s3, h5)
net.addLink( s3, h7)
net.addLink( h1, s1)
net.addLink( h2, s1)
net.addLink( h3, s1)
net.addController('c0')
net.start()
CLI(net)
net.stop()

i am using mininet and the pingall provide only connection between h1 and h2 when using simple_switch13 without any changes so which switch should I use or what changes should be made


Solution

  • You have a loop in your topology. If we break the loop by commenting out a couple of the links...

    net.addLink( s1, s2, port1=1, port2=1)
    net.addLink( s2, s3, port1=2, port2=2)
    net.addLink( s1, s4, port1=2, port2=1)
    #net.addLink( s3, s4, port1=3, port2=2)
    #net.addLink( s1, s3, port1=3, port2=1)
    

    ...then pingall succeeds for all hosts:

    mininet> pingall
    *** Ping: testing ping reachability
    h1 -> h2 h3 h4 h5 h6 h7
    h2 -> h1 h3 h4 h5 h6 h7
    h3 -> h1 h2 h4 h5 h6 h7
    h4 -> h1 h2 h3 h5 h6 h7
    h5 -> h1 h2 h3 h4 h6 h7
    h6 -> h1 h2 h3 h4 h5 h7
    h7 -> h1 h2 h3 h4 h5 h6
    *** Results: 0% dropped (42/42 received)
    

    If you want this topology to work with loops, you'll need to use a switch that supports the spanning tree protocol (STP), such as the ryu.app.simple_switch_stp_13. If start a ryu controller using that switch and wait for the ports to ender FORWARD state:

    # ryu-manager ryu.app.simple_switch_stp_13
    ...lots of output...
    ...30 seconds later...
    [STP][INFO] dpid=0000000000000002: [port=1] ROOT_PORT           / FORWARD
    [STP][INFO] dpid=0000000000000002: [port=2] DESIGNATED_PORT     / FORWARD
    [STP][INFO] dpid=0000000000000001: [port=4] DESIGNATED_PORT     / FORWARD
    [STP][INFO] dpid=0000000000000001: [port=1] DESIGNATED_PORT     / FORWARD
    [STP][INFO] dpid=0000000000000001: [port=6] DESIGNATED_PORT     / FORWARD
    [STP][INFO] dpid=0000000000000001: [port=5] DESIGNATED_PORT     / FORWARD
    [STP][INFO] dpid=0000000000000001: [port=2] DESIGNATED_PORT     / FORWARD
    [STP][INFO] dpid=0000000000000001: [port=3] DESIGNATED_PORT     / FORWARD
    [STP][INFO] dpid=0000000000000003: [port=1] ROOT_PORT           / FORWARD
    [STP][INFO] dpid=0000000000000003: [port=5] DESIGNATED_PORT     / FORWARD
    [STP][INFO] dpid=0000000000000003: [port=6] DESIGNATED_PORT     / FORWARD
    [STP][INFO] dpid=0000000000000003: [port=7] DESIGNATED_PORT     / FORWARD
    [STP][INFO] dpid=0000000000000003: [port=4] DESIGNATED_PORT     / FORWARD
    [STP][INFO] dpid=0000000000000003: [port=3] DESIGNATED_PORT     / FORWARD
    [STP][INFO] dpid=0000000000000003: [port=2] NON_DESIGNATED_PORT / BLOCK
    [STP][INFO] dpid=0000000000000004: [port=1] ROOT_PORT           / FORWARD
    [STP][INFO] dpid=0000000000000004: [port=2] NON_DESIGNATED_PORT / BLOCK
    

    Then pingall will suceed even with the loops in your topology.