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>