3

So I wrote a python file creating the single topology ( just to check if custom topology works) without using any controller at first. the code goes:

#!/usr/bin/python

from mininet.node import CPULimitedHost, Host, Node
from mininet.node import OVSSwitch
from mininet.topo import Topo

class Single1(Topo):

"Single Topology"

def __init__(self):
    "Create Fat tree Topology"

    Topo.__init__(self)

    #Add hosts

    h1 = self.addHost('h1', cls=Host, ip='10.0.0.1', defaultRoute=None)
    h2 = self.addHost('h2', cls=Host, ip='10.0.0.2', defaultRoute=None)
    h3 = self.addHost('h3', cls=Host, ip='10.0.0.3', defaultRoute=None)




    #Add switches
    s1 = self.addSwitch('s1', cls=OVSSwitch)



    #Add links


self.addLink(h1,s1)
self.addLink(h2,s1)
self.addLink(h3,s1)


topos = { 'mytopo': (lambda: Single1() ) }

Pingall doesn't work when I run :

sudo mn --custom single.py --topo mytopo

Although it does work for predefined 'single' topology. Could someone help me with the problem?

sushmita das
  • 93
  • 1
  • 9

3 Answers3

3

This is an older question and probably no longer of interest to the original poster, but I landed here from a mininet related search so I thought I'd provide a working example in case other folks find there way here in the future.

First, there are a number of indentation problems with the posted code, but those are simple to correct.

Next, the logic has been implemented in Single1.__init__, but at least according to the documentation this should be in the build method.

Correcting both of those issues and removing the unnecessary use of host=Host and defaultRoute=None in the addHost calls gives us:

#!/usr/bin/python

from mininet.node import OVSSwitch
from mininet.topo import Topo

class Single1(Topo):

    "Single Topology"

    def build(self):
        "Create Fat tree Topology"

        #Add hosts
        h1 = self.addHost('h1', ip='10.0.0.1')
        h2 = self.addHost('h2', ip='10.0.0.2')
        h3 = self.addHost('h3', ip='10.0.0.3')

        #Add switches
        s1 = self.addSwitch('s1', cls=OVSSwitch)

        #Add links
        self.addLink(h1,s1)
        self.addLink(h2,s1)
        self.addLink(h3,s1)


topos = { 'mytopo': Single1 }

The above code will run without errors and build the topology, but will probably still present the original problem: using cls=OVSSwitch when creating the switch means that Mininet expects there to exist an OpenFlow controller to manage the switch, which in general won't exist by default.

The simplest solution is to change:

s1 = self.addSwitch('s1', cls=OVSSwitch)

To:

s1 = self.addSwitch('s1', cls=OVSBridge)

With this change, Mininet will configure a "standalone" switch that doesn't require an explicit controller, and we will have the expected connectivity. The final version of the code looks like:

#!/usr/bin/python

from mininet.topo import Topo
from mininet.node import OVSBridge

class Single1(Topo):

    "Single Topology"

    def build(self):
        "Create Fat tree Topology"

        #Add hosts
        h1 = self.addHost('h1', ip='10.0.0.1')
        h2 = self.addHost('h2', ip='10.0.0.2')
        h3 = self.addHost('h3', ip='10.0.0.3')

        #Add switches
        s1 = self.addSwitch('s1', cls=OVSBridge)

        #Add links
        self.addLink(h1,s1)
        self.addLink(h2,s1)
        self.addLink(h3,s1)


topos = { 'mytopo': Single1 }

And running it looks like:

[root@servera ~]# mn --custom example.py --topo mytopo
*** Creating network
*** Adding controller
*** Adding hosts:
h1 h2 h3
*** Adding switches:
s1
*** Adding links:
(h1, s1) (h2, s1) (h3, s1)
*** Configuring hosts
h1 h2 h3
*** Starting controller
c0
*** Starting 1 switches
s1 ...
*** Starting CLI:
mininet> h1 ping -c2 h2
PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data.
64 bytes from 10.0.0.2: icmp_seq=1 ttl=64 time=0.320 ms
64 bytes from 10.0.0.2: icmp_seq=2 ttl=64 time=0.051 ms

--- 10.0.0.2 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1009ms
rtt min/avg/max/mdev = 0.051/0.185/0.320/0.134 ms
mininet>
larsks
  • 277,717
  • 41
  • 399
  • 399
  • Thanks for the suggestion. I am having error to start switch (OVSBridge) with `net.get('s1').start()`. What input parameter should I put in "start" function? (for the "OVSSwitch", I could run `net.get('s1').start([c0])`) – Cloud Cho Jul 21 '23 at 23:23
  • 1
    I'm not calling `start` anywhere here; you should open a new question. Include sufficient code to reproduce the problem you're asking about. Feel free to leave a link to the new question here and I'll take a look. – larsks Jul 21 '23 at 23:27
  • Thanks. I will try more on my error. If I hit the wall, I will post my question. – Cloud Cho Jul 22 '23 at 02:02
0

By default, Mininet emulates the switches by Open VSwitch. And if not connected to a controller, OVS will act like a normal L2 switch with its default rules. That's the reason you can do pingall().

However, I also get into problems that Mininet hosts can't ping each other even if they are actually connected. After a few days I find that it takes time for mininet links to get ready. So if you wait about 30 seconds then call pingall(), it should act normally I think.

tgudtk
  • 39
  • 5
-1

The hosts must be in same subnet in order to avoid routing protocols. Otherwise you need static routes

dside
  • 98
  • 7