How to properly set custom bandwidth in mininet? - python

I am trying to set the bandwidth to 1.7MBps, but it is not working. I saw to use argument --link=tc,bw=1.7 so I did and it is still not working. When I use commands in the mininet console to see the bandwidth, it's way too big but I found out it is kind of okay, that it isn't working properly. I am calculating bandwidths from ports stats and the highest I got so far was 0.4MBps. I
also added CPU to my virtual machine, did not help.
What am I doing wrong?
The traffic is generated by downloading data with clients from servers.
(Also I am using RYU's switch: simple_switch_stp_13 and controller ofctl_rest.)
#IMPORTS#
limit=1.7
OVSSwitch14 = partial(OVSSwitch, protocols='OpenFlow13')
class SingleSwitchTopo(Topo):
def build(self):
origin = self.addHost('origin', ip='10.11.0.1')
se1 = self.addHost('se1', ip='10.11.0.2')
se2 = self.addHost('se2', ip='10.11.0.3')
#adding cients
client1 = self.addHost('client1', ip='10.11.0.11')
client2 = self.addHost('client2', ip='10.11.0.12')
client3 = self.addHost('client3', ip='10.11.0.13')
client4 = self.addHost('client4', ip='10.11.0.14')
client5 = self.addHost('client5', ip='10.11.0.15')
client6 = self.addHost('client6', ip='10.11.0.16')
#adding switches
s1 = self.addSwitch('s1')
s2 = self.addSwitch('s2')
s3 = self.addSwitch('s3')
s4 = self.addSwitch('s4')
s5 = self.addSwitch('s5')
s6 = self.addSwitch('s6')
#adding links
self.addLink(s1, se1, cls=TCLink, bw=limit)
self.addLink(s1, s3, cls=TCLink, bw=limit)
self.addLink(s2, client1, cls=TCLink,bw=limit)
self.addLink(s2, origin, cls=TCLink,bw=limit)
self.addLink(s2, s4, cls=TCLink, bw=limit)
self.addLink(s3, client2, cls=TCLink, bw=limit)
self.addLink(s3, s4, cls=TCLink, bw=limit)
self.addLink(s4, client3, cls=TCLink, bw=limit)
self.addLink(s4, s5, cls=TCLink, bw=limit)
self.addLink(s4, s6, cls=TCLink, bw=limit)
self.addLink(s5, se2, cls=TCLink, bw=limit)
self.addLink(s2, s3, cls=TCLink, bw=limit)
self.addLink(s6, client4, cls=TCLink, bw=limit)
self.addLink(s6, client5, cls=TCLink, bw=limit)
self.addLink(s3, client6, cls=TCLink, bw=limit)
mgsw = self.addSwitch('s66766') # DPID used for the Management switch
def setup():
"Start Network"
topo = SingleSwitchTopo()
OVSSwitch14 = partial(OVSSwitch, protocols='OpenFlow13')
net = Mininet(topo=topo, ipBase='10.11.0.0/24', switch=OVSSwitch14, controller=RemoteController,autoSetMacs=True, xterms=True , link=TCLink)
for h in net.hosts:
info('Disabling IPV6 for ' + str(h) + '\n')
h.cmd("sysctl -w net.ipv6.conf.all.disable_ipv6=1")
h.cmd("sysctl -w net.ipv6.conf.default.disable_ipv6=1")
h.cmd("sysctl -w net.ipv6.conf.lo.disable_ipv6=1")
h.cmd("echo ''")
net.start()
net.pingAll()
net.pingAll()
CLI(net)
if __name__ == '__main__':
setLogLevel('info')
setup()

so the mistake was kind of dumb. when setting a bandwidth in mininet you set it in Mbit/s, not Mbytes/s. Therefore I had to convert MB/s to Mb/s, which in my case is 13.6Mb = 1.7 MB

Related

trouble in connecting to opendaylight using python API

I tried this code in python to connect to controller:
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():
net = Mininet( controller=RemoteController, link=TCLink, switch=OVSKernelSwitch )
# Add hosts and switches
h1 = net.addHost( 'h1', ip="10.0.1.10/24", mac="00:00:00:00:00:01" )
h2 = net.addHost( 'h2', ip="10.0.2.10/24", mac="00:00:00:00:00:02" )
r1 = net.addHost( 'r1')
s1 = net.addSwitch( 's1')
s2 = net.addSwitch( 's2')
c0 = net.addController( 'c0', controller=RemoteController, ip='192.168.19.132', port=6633 )
net.addLink( r1, s1 )
net.addLink( r1, s2 )
net.addLink( h1, s1 )
net.addLink( h2, s2 )
net.build()
c0.start()
s1.start( [c0] )
s2.start( [c0] )
r1.cmd("ifconfig r1-eth0 0")
r1.cmd("ifconfig r1-eth1 0")
r1.cmd("ifconfig r1-eth0 hw ether 00:00:00:00:01:01")
r1.cmd("ifconfig r1-eth1 hw ether 00:00:00:00:01:02")
r1.cmd("ip addr add 10.0.1.1/24 brd + dev r1-eth0")
r1.cmd("ip addr add 10.0.2.1/24 brd + dev r1-eth1")
r1.cmd("echo 1 > /proc/sys/net/ipv4/ip_forward")
h1.cmd("ip route add default via 10.0.1.1")
h2.cmd("ip route add default via 10.0.2.1")
s1.cmd("ovs-ofctl add-flow s1 priority=1,arp,actions=flood")
s1.cmd("ovs-ofctl add-flow s1 priority=65535,ip,dl_dst=00:00:00:00:01:01,actions=output:1")
s1.cmd("ovs-ofctl add-flow s1 priority=10,ip,nw_dst=10.0.1.0/24,actions=output:2")
s2.cmd("ovs-ofctl add-flow s2 priority=1,arp,actions=flood")
s2.cmd("ovs-ofctl add-flow s2 priority=65535,ip,dl_dst=00:00:00:00:01:02,actions=output:1")
s2.cmd("ovs-ofctl add-flow s2 priority=10,ip,nw_dst=10.0.2.0/24,actions=output:2")
print ("*** Running CLI")
CLI( net )
print ("*** Stopping network")
net.stop()
if __name__ == '__main__':
setLogLevel( 'info' )
topology()
but when I check dlux in browser it doesn't show any nodes.
if I use CLI and set the topology using sudo mn and give it the ip of my controller then it works.
why doesn't it work with python?
I used ubuntu 20.04 and my opendaylight version is nitrogen.
thanks in advance
You need to be more specific with defining your remote controller. If you have the controller installed on the same Linux host as Mininet had been installed on, then you need to define you controller IP and port like below. I used this script with ODL Lithium version and it worked with no problem.
#!/usr/bin/env python
from mininet.net import Mininet
from mininet.link import TCIntf
from mininet.node import CPULimitedHost
from mininet.topolib import TreeTopo
from mininet.util import custom, quietRun
from mininet.log import setLogLevel, info
from mininet.cli import CLI
from mininet.node import RemoteController
from mininet.link import TCLink
setLogLevel( 'info' )
net = Mininet( link=TCLink )
c0 = net.addController(name='c0' ,
controller=RemoteController ,
ip='localhost',
port=6653) // # the port for newer versions might be different
s1 = net.addSwitch('s1', protocols='OpenFlow13')
s2 = net.addSwitch('s2', protocols='OpenFlow13')
net.addLink(s1, s2, delay='50ms')
net.addLink(s1, s2, bw=0.2)
net.addLink(s1, s2)
net.start()
CLI(net)

Mininet-wifi Cannot import name OVSKernelAP with Python

I am building a SDN network using Mininet-Wifi and I have this smallnetwork as a test just to learn more about Python, so I this code to run
!/usr/bin/python
from mininet.net import Mininet
from mininet.node import Controller, RemoteController, OVSKernelAP
from mininet.link import TCLink
from mininet.cli import CLI
from mininet.log import setLogLevel
def topology():
"Create a network."
net = Mininet( controller=Controller, link=TCLink, accessPoint=OVSKernelAP )
print "*** Creating nodes"
h1 = net.addHost( 'h1', mac='00:00:00:00:00:01', ip='10.0.0.1/8' )
h2 = net.addHost( 'h2', mac='00:00:00:00:00:11', ip='10.0.1.1/8' )
sta1 = net.addStation( 'sta1', mac='00:00:00:00:00:02', ip='10.0.0.2/8', position='50,50,0' )
sta2 = net.addStation( 'sta2', mac='00:00:00:00:00:03', ip='10.0.0.3/8', position='40,50,0')
sta3 = net.addStation( 'sta3', mac='00:00:00:00:00:04', ip='10.0.0.4/8', position='20,50,0' )
ap1 = net.addAccessPoint( 'ap1', ssid= 'new-ssid', mode= 'g', channel= '5',
position='25,50,0', range='35' )
ap2 = net.addAccessPoint( 'ap2', ssid= 'new-ssid', mode= 'g', channel= '5',
position='75,50,0', range='35' )
c1 = net.addController( 'c1' )
s1 = net.addSwitch('s1')
#net.runAlternativeModule('../module/mac80211_hwsim.ko')
print "*** Configuring wifi nodes"
net.configureWifiNodes()
print "*** Associating and Creating links"
net.addLink(ap1, s1)
net.addLink(ap2, s1)
net.addLink(s1, c1)
#net.addLink(ap1, ap2)
net.addLink(s1, h1)
net.addLink(s1, h2)
net.addLink(ap1, sta1)
net.addLink(ap1, sta2)
net.addLink(ap1, sta3)
print "*** Starting network"
net.build()
c1.start()
ap1.start( [c1] )
ap2.start( [c1] )
"""uncomment to plot graph"""
net.plotGraph(max_x=100, max_y=100)
net.startMobility(startTime=0)
net.mobility(sta1, 'start', time=1, position='0.0,50.0,0.0')
net.mobility(sta1, 'stop', time=30, position='100.0,50.0,0.0')
net.stopMobility(stopTime=31)
print "*** Running CLI"
CLI( net )
print "*** Stopping network"
net.stop()
if __name__ == '__main__':
setLogLevel( 'info' )
topology()
And after runing "sudo mn --custom test.py" (My file name is test.py ) I get the error.
Caught Excepcion. Cleaning up... ImportError: cannot import name OVSKernelAP
What Can i do? I have mininet and mininet-wifi already installed.
The main source of your error is in lines 3 to 7. With Mininet-wifi you just need to import the following:
from mininet.log import setLogLevel, info
from mn_wifi import CLI
from mn_wifi import Mininet_wifi
That's all you need to import. You might have a few more errors such as the minimum range of your access points should be 116m and s1 and ap1 will have the same DPID so you should change s1 to s3

Mininet Python - Issues With Pinging Other Hosts Within Custom Topology

Info
Host OS: Windows 10
First Attempt Guest OS: Mininet-VM
Second Attempt Guest OS: Ubuntu(VM)
VM Software: Virtual Box
Libraries: Mininet Python API
Issue
Good day,
I'm having some issues with a my customized topology when using Mininet.
Initially, I used Mininet's recommended Mininet-VM and it works fine for the default command generated topologies(i.e.: linear, tree, reversed, etc).
However, when I wish to run my own topology I'm unable to ping any other host(see code below).
Commands:
"sudo python3 custom_topology.py
Mininet>pingall
I thought it might be an issue with the image of Mininet-VM itself and so I tried running the same script within Ubuntu(with Mininet installed of course) and ran into the same issue.
In any case, I've looked around stackoverflow(references below) and none of the solutions worked for me. Although, some have suggested to use the POX controller instead of the default one, but I'm quite ignorant on how it works as well as how to implement it.
Any help would be appreciated.
Cheers!
Result
Topology Diagram
Mid-Level API Code
from mininet.net import Mininet
from mininet.cli import CLI
from mininet.link import TCLink
from mininet.util import dumpNodeConnections
from mininet.node import Controller
net = Mininet(controller=Controller, link=TCLink)
h1 = net.addHost('h1')
h2 = net.addHost('h2')
h3 = net.addHost('h3')
h4 = net.addHost('h4')
h5 = net.addHost('h5')
h6 = net.addHost('h6')
h7 = net.addHost('h7')
h8 = net.addHost('h8')
s1 = net.addSwitch('s1')
s2 = net.addSwitch('s2')
s3 = net.addSwitch('s3')
s4 = net.addSwitch('s4')
s5 = net.addSwitch('s5')
s6 = net.addSwitch('s6')
c0 = net.addController('c0')
net.addLink(h1, s1)
net.addLink(h2, s2)
net.addLink(h3, s3)
net.addLink(h4, s4)
net.addLink(h5, s4)
net.addLink(h6, s5)
net.addLink(h7, s5)
net.addLink(h8, s6)
net.addLink(s1, s2, bw=10, delay='0ms')
net.addLink(s2, s3, bw=10, delay='0ms')
net.addLink(s3, s4, bw=100, delay='5ms')
net.addLink(s4, s5, bw=100, delay='5ms')
net.addLink(s5, s6, bw=100, delay='0ms')
net.addLink(s6, s1, bw=10, delay='0ms')
net.start()
print( "Dumping host connections" )
dumpNodeConnections( net.hosts )
dumpNodeConnections( net.switches )
CLI(net)
net.stop()
References
StackOverflow Post 1
StackOverflow Post 2
StackOverflow Post 3
Official Mininet Website
Issue: The default controller within Mininet cannot handle loops within a topology. To fix this, we'll need to use the POX controller and some additional configuration for the switches.
You will need to run two terminals:
one terminal will run POX controller as ./pox.py forwarding.hub
the other terminal will run your custom topology python script
Please look at references #5 and #6, they display some decent examples
Code Solution
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")
h1 = net.addHost( 'h1', mac='00:00:00:00:00:01', ip='10.0.0.1/24' )
h2 = net.addHost( 'h2', mac='00:00:00:00:00:02', ip='10.0.0.2/24' )
h3 = net.addHost( 'h3', mac='00:00:00:00:00:03', ip='10.0.0.3/24' )
h4 = net.addHost( 'h4', mac='00:00:00:00:00:04', ip='10.0.0.4/24' )
h5 = net.addHost( 'h5', mac='00:00:00:00:00:05', ip='10.0.0.5/24' )
h6 = net.addHost( 'h6', mac='00:00:00:00:00:06', ip='10.0.0.6/24' )
h7 = net.addHost( 'h7', mac='00:00:00:00:00:07', ip='10.0.0.7/24' )
h8 = net.addHost( 'h8', mac='00:00:00:00:00:08', ip='10.0.0.8/24' )
s1 = net.addSwitch( 's1' )
s2 = net.addSwitch( 's2' )
s3 = net.addSwitch( 's3' )
s4 = net.addSwitch( 's4' )
s5 = net.addSwitch( 's5' )
s6 = net.addSwitch( 's6' )
c7 = net.addController( 'c7', controller=RemoteController,
ip='127.0.0.1', port=6633 )
print("*** Creating links")
net.addLink( h1, s1 )
net.addLink( h2, s2 )
net.addLink( h3, s3 )
net.addLink( h4, s4 )
net.addLink( h5, s4 )
net.addLink( h6, s5 )
net.addLink( h7, s5 )
net.addLink( h8, s6 )
net.addLink( s1, s2, cls=TCLink, bw=10 )
net.addLink( s2, s3, cls=TCLink, bw=10 )
net.addLink( s3, s4, cls=TCLink, bw=100, delay='5ms' )
net.addLink( s4, s5, cls=TCLink, bw=100, delay='5ms' )
net.addLink( s5, s6, cls=TCLink, bw=100 )
net.addLink( s6, s1, cls=TCLink, bw=10 )
print("*** Starting network")
net.build()
c7.start()
s1.start( [c7] )
s2.start( [c7] )
s3.start( [c7] )
s4.start( [c7] )
s5.start( [c7] )
s6.start( [c7] )
# Configuring switches
s1.cmd("sh ovs-ofctl add-flow s1 priority=1,arp,actions=flood")
s1.cmd("ovs-ofctl add-flow s1
priority=10,ip,nw_dst=10.0.1.0/24,actions=output:1")
s1.cmd("ovs-ofctl add-flow s1
priority=10,ip,nw_dst=10.0.2.0/24,actions=output:2")
s1.cmd("ovs-ofctl add-flow s1
priority=10,ip,nw_dst=10.0.3.0/24,actions=output:3")
s1.cmd("ovs-ofctl add-flow s1
priority=10,ip,nw_dst=10.0.4.0/24,actions=output:3")
s1.cmd("ovs-ofctl add-flow s1
priority=10,ip,nw_dst=10.0.5.0/24,actions=output:3")
s1.cmd("ovs-ofctl add-flow s1
priority=10,ip,nw_dst=10.0.6.0/24,actions=output:2")
s1.cmd("ovs-ofctl add-flow s1
priority=10,ip,nw_dst=10.0.7.0/24,actions=output:2")
s1.cmd("ovs-ofctl add-flow s1
priority=10,ip,nw_dst=10.0.8.0/24,actions=output:2")
s2.cmd("sh ovs-ofctl add-flow s1 priority=1,arp,actions=flood")
s2.cmd("ovs-ofctl add-flow s1
priority=10,ip,nw_dst=10.0.1.0/24,actions=output:3")
s2.cmd("ovs-ofctl add-flow s1
priority=10,ip,nw_dst=10.0.2.0/24,actions=output:1")
s2.cmd("ovs-ofctl add-flow s1
priority=10,ip,nw_dst=10.0.3.0/24,actions=output:2")
s2.cmd("ovs-ofctl add-flow s1 priority=10,ip,nw_dst=10.0.4.0/24,actions=output:2")
s2.cmd("ovs-ofctl add-flow s1 priority=10,ip,nw_dst=10.0.5.0/24,actions=output:2")
s2.cmd("ovs-ofctl add-flow s1 priority=10,ip,nw_dst=10.0.6.0/24,actions=output:3")
s2.cmd("ovs-ofctl add-flow s1 priority=10,ip,nw_dst=10.0.7.0/24,actions=output:3")
s2.cmd("ovs-ofctl add-flow s1 priority=10,ip,nw_dst=10.0.8.0/24,actions=output:3")
s3.cmd("sh ovs-ofctl add-flow s1 priority=1,arp,actions=flood")
s3.cmd("ovs-ofctl add-flow s1 priority=10,ip,nw_dst=10.0.1.0/24,actions=output:3")
s3.cmd("ovs-ofctl add-flow s1 priority=10,ip,nw_dst=10.0.2.0/24,actions=output:3")
s3.cmd("ovs-ofctl add-flow s1 priority=10,ip,nw_dst=10.0.3.0/24,actions=output:1")
s3.cmd("ovs-ofctl add-flow s1 priority=10,ip,nw_dst=10.0.4.0/24,actions=output:2")
s3.cmd("ovs-ofctl add-flow s1 priority=10,ip,nw_dst=10.0.5.0/24,actions=output:2")
s3.cmd("ovs-ofctl add-flow s1 priority=10,ip,nw_dst=10.0.6.0/24,actions=output:2")
s3.cmd("ovs-ofctl add-flow s1 priority=10,ip,nw_dst=10.0.7.0/24,actions=output:2")
s3.cmd("ovs-ofctl add-flow s1 priority=10,ip,nw_dst=10.0.8.0/24,actions=output:3")
s4.cmd("sh ovs-ofctl add-flow s1 priority=1,arp,actions=flood")
s4.cmd("ovs-ofctl add-flow s1 priority=10,ip,nw_dst=10.0.1.0/24,actions=output:2")
s4.cmd("ovs-ofctl add-flow s1 priority=10,ip,nw_dst=10.0.2.0/24,actions=output:2")
s4.cmd("ovs-ofctl add-flow s1 priority=10,ip,nw_dst=10.0.3.0/24,actions=output:2")
s4.cmd("ovs-ofctl add-flow s1 priority=10,ip,nw_dst=10.0.4.0/24,actions=output:1")
s4.cmd("ovs-ofctl add-flow s1 priority=10,ip,nw_dst=10.0.5.0/24,actions=output:4")
s4.cmd("ovs-ofctl add-flow s1 priority=10,ip,nw_dst=10.0.6.0/24,actions=output:3")
s4.cmd("ovs-ofctl add-flow s1 priority=10,ip,nw_dst=10.0.7.0/24,actions=output:3")
s4.cmd("ovs-ofctl add-flow s1 priority=10,ip,nw_dst=10.0.8.0/24,actions=output:3")
s5.cmd("sh ovs-ofctl add-flow s1 priority=1,arp,actions=flood")
s5.cmd("ovs-ofctl add-flow s1 priority=10,ip,nw_dst=10.0.1.0/24,actions=output:3")
s5.cmd("ovs-ofctl add-flow s1 priority=10,ip,nw_dst=10.0.2.0/24,actions=output:3")
s5.cmd("ovs-ofctl add-flow s1 priority=10,ip,nw_dst=10.0.3.0/24,actions=output:3")
s5.cmd("ovs-ofctl add-flow s1 priority=10,ip,nw_dst=10.0.4.0/24,actions=output:2")
s5.cmd("ovs-ofctl add-flow s1 priority=10,ip,nw_dst=10.0.5.0/24,actions=output:2")
s5.cmd("ovs-ofctl add-flow s1 priority=10,ip,nw_dst=10.0.6.0/24,actions=output:1")
s5.cmd("ovs-ofctl add-flow s1 priority=10,ip,nw_dst=10.0.7.0/24,actions=output:4")
s5.cmd("ovs-ofctl add-flow s1 priority=10,ip,nw_dst=10.0.8.0/24,actions=output:3")
s6.cmd("sh ovs-ofctl add-flow s1 priority=1,arp,actions=flood")
s6.cmd("ovs-ofctl add-flow s1 priority=10,ip,nw_dst=10.0.1.0/24,actions=output:3")
s6.cmd("ovs-ofctl add-flow s1 priority=10,ip,nw_dst=10.0.2.0/24,actions=output:3")
s6.cmd("ovs-ofctl add-flow s1 priority=10,ip,nw_dst=10.0.3.0/24,actions=output:3")
s6.cmd("ovs-ofctl add-flow s1 priority=10,ip,nw_dst=10.0.4.0/24,actions=output:2")
s6.cmd("ovs-ofctl add-flow s1 priority=10,ip,nw_dst=10.0.5.0/24,actions=output:2")
s6.cmd("ovs-ofctl add-flow s1 priority=10,ip,nw_dst=10.0.6.0/24,actions=output:2")
s6.cmd("ovs-ofctl add-flow s1 priority=10,ip,nw_dst=10.0.7.0/24,actions=output:2")
s6.cmd("ovs-ofctl add-flow s1
priority=10,ip,nw_dst=10.0.8.0/24,actions=output:1")
print("*** Running CLI")
CLI( net )
print("*** Stopping network")
net.stop()
if __name__ == '__main__':
setLogLevel( 'info' )
topology()
References
Dr. Chih-Heng Ke's Post #1
Dr. Chih-Heng Ke's Post #2

Creating a topology using python

I want to build a mininet topology using python API. My topology is supposed to have 2 controllers, 3 switches and each switch will have several hosts connected to it (number of connected hosts is 2, 4, 1 respectively). Here is the code:
#!/usr/bin/python
import time
from mininet.net import Mininet
from mininet.node import Controller, OVSKernelSwitch, RemoteController
from mininet.cli import CLI
from mininet.log import setLogLevel, info
def net():
net = Mininet(controller=RemoteController, switch=OVSKernelSwitch)
c1 = net.addController('c1', controller=RemoteController, ip="127.0.0.1", port=6653)
c2 = net.addController('c2', controller=RemoteController, ip="127.0.0.1", port=7753)
s_n = 3 #number of switches
c_n = 2 #number of controllers
hosts = []
amount = [2, 4, 1] # number of hosts that each switch has
info( "*** Creating switches\n" )
switches = [ net.addSwitch( 's%s' % s ) for s in range( 1, s_n ) ]
index1 = 0
L_in = 0
index2 = 0
info( "*** Creating hosts\n" )
for s in switches:
L_in = (L_in + 1)
if L_in <= len(amount):
index1 = (index2 + 1)
index2 = (index1 + amount[L_in]) - 1
hosts = [ net.addHost( 'h%s' % n ) for n in ( index1, index2 ) ]
for h in hosts:
net.addLink( s, h )
else:
break
# Wire up switches
last = None
for switch in switches:
if last:
net.addLink( last, switch )
last = switch
net.build()
c1.start()
c2.start()
for sw in switches[:c_n]:
sw.start( [c1] )
for sw in switches[c_n:]:
sw.start( [c2] )
net.start()
CLI( net )
net.stop()
if __name__ == '__main__':
setLogLevel( 'info' )
net()
But when I run the code, it is not working correctly. For example, I expect 3 switches, but 2 switches are created. I expect 7 hosts, but 4 hosts are created. The connection between hosts and switches is not correct, too. Here is the output:
*** Creating switches
*** Creating hosts
*** Configuring hosts
h1 h4 h5 h5
*** Starting controller
c1 c2
*** Starting 2 switches
s1 s2 ...
*** Starting CLI:
mininet> net
h1 h1-eth0:s1-eth1
h4 h4-eth0:s1-eth2
h5 h5-eth0:s2-eth2
h5 h5-eth0:s2-eth2
s1 lo: s1-eth1:h1-eth0 s1-eth2:h4-eth0 s1-eth3:s2-eth3
s2 lo: s2-eth1:h5-eth0 s2-eth2:h5-eth0 s2-eth3:s1-eth3
c1
c2
A number of problems here.
range(1, n) produces numbers from 1 no n-1, not to n.
You define function net that will shadow the previous (imported?) definition of module net. Call it make_net or something.
Explicit loop indices like L_in is almost always a bad idea, same as non-descriptive names as index2.
Something like this should give you the idea:
n_switches = 3
hosts_per_switch = [2, 4, 1]
switches = [addSwitch("s%d" % n + 1) for n in range(n_switches)]
for (switch, number_of_hosts) in zip(switches, hosts_per_switch): # Pair them.
hosts = [addHost("h%d" % n + 1) for n in range(number_of_hosts)]
for host in hosts:
addLink(switch, host)

Mininet-wifi custom topology

At first I want wanted to create a complex topology (more switches connected to each other) but even this simple one is not working. I am not able to get a working connection eg. 'h1 ping h2'
Here is the topology:
He is the script that should create the equivalent topology:
!/usr/bin/python
"""
Setting the position of Nodes (only for Stations and Access Points) and providing mobility.
"""
from mininet.net import Mininet
from mininet.node import Controller, RemoteController, OVSKernelAP
from mininet.link import TCLink
from mininet.cli import CLI
from mininet.log import setLogLevel
def topology():
"Create a network."
net = Mininet( controller=Controller, link=TCLink, accessPoint=OVSKernelAP )
print "*** Creating nodes"
h1 = net.addHost( 'h1', mac='00:00:00:00:00:01', ip='10.0.0.1/8' )
h2 = net.addHost( 'h2', mac='00:00:00:00:00:11', ip='10.0.1.1/8' )
sta1 = net.addStation( 'sta1', mac='00:00:00:00:00:02', ip='10.0.0.2/8', position='50,50,0' )
sta2 = net.addStation( 'sta2', mac='00:00:00:00:00:03', ip='10.0.0.3/8', position='40,50,0')
sta3 = net.addStation( 'sta3', mac='00:00:00:00:00:04', ip='10.0.0.4/8', position='20,50,0' )
ap1 = net.addAccessPoint( 'ap1', ssid= 'new-ssid', mode= 'g', channel= '5', position='25,50,0', range='35' )
ap2 = net.addAccessPoint( 'ap2', ssid= 'new-ssid', mode= 'g', channel= '5', position='75,50,0', range='35' )
c1 = net.addController( 'c1' )
s1 = net.addSwitch('s1')
#net.runAlternativeModule('../module/mac80211_hwsim.ko')
print "*** Configuring wifi nodes"
net.configureWifiNodes()
print "*** Associating and Creating links"
net.addLink(ap1, s1)
net.addLink(ap2, s1)
net.addLink(s1, c1)
#net.addLink(ap1, ap2)
net.addLink(s1, h1)
net.addLink(s1, h2)
net.addLink(ap1, sta1)
net.addLink(ap1, sta2)
net.addLink(ap1, sta3)
print "*** Starting network"
net.build()
c1.start()
ap1.start( [c1] )
ap2.start( [c1] )
"""uncomment to plot graph"""
net.plotGraph(max_x=100, max_y=100)
net.startMobility(startTime=0)
net.mobility(sta1, 'start', time=1, position='0.0,50.0,0.0')
net.mobility(sta1, 'stop', time=30, position='100.0,50.0,0.0')
net.stopMobility(stopTime=31)
print "*** Running CLI"
CLI( net )
print "*** Stopping network"
net.stop()
if __name__ == '__main__':
setLogLevel( 'info' )
topology()
As already said, I am not able to even ping h1 and h2 :(
I even tried to use RemoteController but got the same result.
Any idea what might be wrong?
Please consider the changes below:
from mininet.node import Controller, RemoteController, OVSKernelAP, OVSSwitch
net = Mininet( controller=Controller, link=TCLink, accessPoint=OVSKernelAP, switch=OVSSwitch )
c1 = net.addController( 'c1', controller=Controller )
s3 = net.addSwitch('s3')
Remove:
net.addLink(s1, c1)
Add:
s3.start( [c1] )
Please note that if you set both ap and switch with the same ID (e.g. s1, ap1), they will have the same DPID by default. So, I had to rename s1 to s3. On the other hand you may define the DPID as a parameter when you add the node whether you want.

Categories

Resources