I'm a newer in Mininet, I started my topology with CLI command: "sudo mn", after that, I'm adding some hosts and switches... but I want to save it for the next time.
How can I do it?
Example:
http://i1360.photobucket.com/albums/r653/HKati/Capture%20drsquoeacutecran%202016-04-23%20agrave%2007.08.02_zpsxcmh4u6s.png
I'm not sure if I got your question correctly but you can define your topology within a script:
Example my_topology.py
from mininet.topo import Topo
class MyTopo( Topo ):
def __init__( self ):
Topo.__init__( self )
# Add hosts and switches
left_host = self.addHost( 'h1' )
right_host = self.addHost( 'h2' )
left_switch = self.addSwitch( 's0' )
right_switch = self.addSwitch( 's2' )
# Add links
self.addLink( leftHost, left_switch, bw=10, delay='10ms', loss=0, max_queue_size=1000 )
self.addLink( left_switch, right_switch, bw=10, delay='10ms', loss=0, max_queue_size=1000 )
self.addLink( right_switch, rightHost, bw=10, delay='10ms', loss=0, max_queue_size=1000 )
topos = { 'mytopo': ( lambda: MyTopo() ) }
Then you can start it with
mn --custom my_topology.py --topo mytopo --link tc,bw=10,delay=10ms
Related
I am having trouble connecting the switch to the controller in mininet. I use python script.
My script is the following.
The file name is test.py.
#!/usr/bin/python
from mininet.cli import CLI
from mininet.topo import Topo
from mininet.net import Mininet
from mininet.util import dumpNodeConnections
from mininet.node import Controller, OVSSwitch, RemoteController, OVSBridge
from mininet.log import setLogLevel
class test_Topo(Topo):
def build(self):
s1 = self.addSwitch( 's1')
s2 = self.addSwitch( 's2')
h1 = self.addHost( 'h1' )
h2 = self.addHost( 'h2' )
n1 = self.addHost( 'n1' )
self.addLink( s1, s2 )
self.addLink( s1, h1 )
self.addLink( s1, h2 )
self.addLink( s2, n1 )
def test():
topo = test_Topo()
net = Mininet(topo, build=False, waitConnected=True, switch=OVSSwitch, controller=Controller)
c0 = net.addController( 'c0', port=6633 )
c1 = net.addController('c1', port=6634)
net.build()
s1 = net.get('s1')
s2 = net.get('s2')
c0.start()
c1.start()
s1.start([c0])
s2.start([c1])
net.start()
net.pingAll()
CLI( net )
net.stop()
if __name__ == '__main__':
setLogLevel('info')
test()
I want to have each switch connected to a different controller.
I ran the script with the following command.
sudo python3 test.py
The result is the following.
*** Creating network
*** Adding hosts:
h1 h2 n1
*** Adding switches:
s1 s2
*** Adding links:
(s1, h1) (s1, h2) (s1, s2) (s2, n1)
*** Configuring hosts
h1 h2 n1
*** Starting controller
c0 c1
*** Starting 2 switches
s1 s2 ...
*** Waiting for switches to connect
The connection does not end permanently after the message
*** Waiting for switches to connect
is displayed.
I referred to this code.
https://github.com/mininet/mininet/blob/master/examples/controllers.py
https://github.com/mininet/mininet/blob/master/examples/controllers2.py
I can't understand why switch can't connect the controller in my code.
I apologize for my poor English.
I am using mininet to simulate a linear topology, 3 switches connected to each other and one host connected to each switch. Looks like this.
I used the mobility script provided on github to perform mobility within mininet. The script uses the default controller of Mininet.
Now I would like to use a remote Opendaylight controller to perform the mobility, or more specifically to move h1 from s1 to s2 and then back to s2.
My code is a modified version of the original mobility script. Changes are in the mobilityTest() method and the CLI was added for debugging.
#!/usr/bin/python
"""
Simple example of Mobility with Mininet
(aka enough rope to hang yourself.)
We move a host from s1 to s2, s2 to s3, and then back to s1.
Gotchas:
The reference controller doesn't support mobility, so we need to
manually flush the switch flow tables!
Good luck!
to-do:
- think about wifi/hub behavior
- think about clearing last hop - why doesn't that work?
"""
from mininet.node import RemoteController
from mininet.net import Mininet
from mininet.node import OVSSwitch
from mininet.topo import LinearTopo
from mininet.log import info, output, warn, setLogLevel
from mininet.examples.clustercli import CLI
from random import randint
import time
class MobilitySwitch( OVSSwitch ):
"Switch that can reattach and rename interfaces"
def delIntf( self, intf ):
"Remove (and detach) an interface"
port = self.ports[ intf ]
del self.ports[ intf ]
del self.intfs[ port ]
del self.nameToIntf[ intf.name ]
def addIntf( self, intf, rename=False, **kwargs ):
"Add (and reparent) an interface"
OVSSwitch.addIntf( self, intf, **kwargs )
intf.node = self
if rename:
self.renameIntf( intf )
def attach( self, intf ):
"Attach an interface and set its port"
port = self.ports[ intf ]
if port:
if self.isOldOVS():
self.cmd( 'ovs-vsctl add-port', self, intf )
else:
self.cmd( 'ovs-vsctl add-port', self, intf,
'-- set Interface', intf,
'ofport_request=%s' % port )
self.validatePort( intf )
def validatePort( self, intf ):
"Validate intf's OF port number"
ofport = int( self.cmd( 'ovs-vsctl get Interface', intf,
'ofport' ) )
if ofport != self.ports[ intf ]:
warn( 'WARNING: ofport for', intf, 'is actually', ofport,
'\n' )
def renameIntf( self, intf, newname='' ):
"Rename an interface (to its canonical name)"
intf.ifconfig( 'down' )
if not newname:
newname = '%s-eth%d' % ( self.name, self.ports[ intf ] )
intf.cmd( 'ip link set', intf, 'name', newname )
del self.nameToIntf[ intf.name ]
intf.name = newname
self.nameToIntf[ intf.name ] = intf
intf.ifconfig( 'up' )
def moveIntf( self, intf, switch, port=None, rename=True ):
"Move one of our interfaces to another switch"
self.detach( intf )
self.delIntf( intf )
switch.addIntf( intf, port=port, rename=rename )
switch.attach( intf )
def printConnections( switches ):
"Compactly print connected nodes to each switch"
for sw in switches:
output( '%s: ' % sw )
for intf in sw.intfList():
link = intf.link
if link:
intf1, intf2 = link.intf1, link.intf2
remote = intf1 if intf1.node != sw else intf2
output( '%s(%s) ' % ( remote.node, sw.ports[ intf ] ) )
output( '\n' )
def moveHost( host, oldSwitch, newSwitch, newPort=None ):
"Move a host from old switch to new switch"
hintf, sintf = host.connectionsTo( oldSwitch )[ 0 ]
oldSwitch.moveIntf( sintf, newSwitch, port=newPort )
return hintf, sintf
def mobilityTest():
"A simple test of mobility"
info( '* Simple mobility test\n' )http://localhost:8181/restconf/operational/opendaylight-inventory:nodes/
net = Mininet( topo=LinearTopo( 3 ), controller=lambda a: RemoteController( a, ip='127.0.0.1', port=6653), switch=MobilitySwitch )
info( '* Starting network:\n' )
net.start()
printConnections( net.switches )
info( '* Testing network\n' )
time.sleep( 3 )
net.pingAll()
info( '* Identifying switch interface for h1\n' )
h1, old = net.get( 'h1', 's1' )
CLI( net )
for s in 2, 3, 1:
new = net[ 's%d' % s ]
port = randint( 10, 20 )
info( '* Moving', h1, 'from', old, 'to', new, 'port', port, '\n' )
hintf, sintf = moveHost( h1, old, new, newPort=port )
info( '*', hintf, 'is now connected to', sintf, '\n' )
info( '* Clearing out old flows\n' )
for sw in net.switches:
sw.dpctl( 'del-flows' )
info( '* Add flow rule\n' )
CLI( net )
info( '* New network:\n' )
printConnections( net.switches )
info( '* Testing connectivity:\n' )
net.pingAll()
old = new
net.stop()
if __name__ == '__main__':
setLogLevel( 'info' )
mobilityTest()
When running the script the linear topology is set up successfully, which I can see in the delux GUI of the ODL controller. I can also ping between all hosts.
The problem occurs when mobility is performed and h1 is connected to s2.
Pinging does not work anymore.
Populating the flow-tables with a flow-rule to the controller did not solve the problem.
mininet> dpctl add-flow "table=0, priority=100,dl_type=0x88cc actions=CONTROLLER:65535"
*** s1 ------------------------------------------------------------------------
*** s2 ------------------------------------------------------------------------
*** s3 ------------------------------------------------------------------------
mininet> dpctl dump-flows
*** s1 ------------------------------------------------------------------------
NXST_FLOW reply (xid=0x4):
cookie=0x0, duration=7.914s, table=0, n_packets=0, n_bytes=0, idle_age=7, priority=100,dl_type=0x88cc actions=CONTROLLER:65535
*** s2 ------------------------------------------------------------------------
NXST_FLOW reply (xid=0x4):
cookie=0x0, duration=7.916s, table=0, n_packets=1, n_bytes=85, idle_age=2, priority=100,dl_type=0x88cc actions=CONTROLLER:65535
*** s3 ------------------------------------------------------------------------
NXST_FLOW reply (xid=0x4):
cookie=0x0, duration=7.917s, table=0, n_packets=1, n_bytes=85, idle_age=2, priority=100,dl_type=0x88cc actions=CONTROLLER:65535
mininet> pingall
*** Ping: testing ping reachability
h1 -> X X
h2 -> X X
h3 -> X X
*** Results: 100% dropped (0/6 received)
Then I monitored with tcpdump all interfaces when I try to ping from h1 to h2, which are now both connected to s2. h1 sends out an ARP request, which is received by the s2 switch, but this switch s2 is not forwarding the ARP request to the other switches and hosts.
I would like to know why my ping does not work anymore after performing mobility.
Any help is highly appreciated.
Thanks
I am attempting to set up a network in which 3 hosts (h1, h2, h3, on different networks) can ping each other through the 2 routers (r1, r2) that separate them.
h1 -> r1 -> h2 -> r2 -> h3 -> r3 -> internet
I found this, to guide me through 2 hosts and 1 router but when I add r2 on the other side of h2, r2 doesn't response to anything, and it isn't able to ping anything OR I can get the following bidirectional pairs:
(h1, r1) (h2, r2)
This code gives me a non-responsive/mute r2:
#!/usr/bin/python
from mininet.topo import Topo
from mininet.net import Mininet
from mininet.node import Node
from mininet.log import setLogLevel, info
from mininet.cli import CLI
class LinuxRouter( Node ):
"A Node with IP forwarding enabled."
def config( self, **params ):
super( LinuxRouter, self).config( **params )
# Enable forwarding on the router
self.cmd( 'sysctl net.ipv4.ip_forward=1' )
def terminate( self ):
self.cmd( 'sysctl net.ipv4.ip_forward=0' )
super( LinuxRouter, self ).terminate()
class NetworkTopo( Topo ):
"A LinuxRouter connecting three IP subnets"
def build( self, **_opts ):
robIP = '10.1.1.14/24' # IP address for r0-eth1
richIP = '10.4.4.46/24'
robert = self.addNode( 'r0', cls=LinuxRouter, ip=robIP, defaultRoute='via 10.4.4.14' )
richard = self.addNode( 'r1', cls=LinuxRouter, ip=richIP, defaultRoute='via 10.6.6.46' )
alice = self.addHost( 'h1', ip='10.1.1.17/24', defaultRoute='via 10.1.1.14' )
bob = self.addHost( 'h2', ip='10.4.4.48/24', defaultRoute='via 10.4.4.14' )
self.addLink( alice, robert, intfName2='r0-eth1', params2={ 'ip' : '10.1.1.14/24' } )
self.addLink( bob, robert, intfName2='r1-eth1', params2={ 'ip' : '10.4.4.14/24' } )
self.addLink( bob, richard, intfName2='r0-eth2', params2={ 'ip' : '10.4.4.46/24' } )
def run():
"Test linux router"
topo = NetworkTopo()
net = Mininet( topo=topo ) # controller is used by s1-s3
net.start()
info( '*** Routing Table on Router:\n' )
print net[ 'r0' ].cmd( 'route' )
CLI( net )
net.stop()
if __name__ == '__main__':
setLogLevel( 'info' )
run()
If I transpose these 2 lines I get the 2 bidirectional pairs.
self.addLink( bob, richard, intfName2='r1-eth1', params2={ 'ip' : '10.4.4.46/24' } )
self.addLink( bob, robert, intfName2='r0-eth2', params2={ 'ip' : '10.4.4.14/24' } )
I don't even know if this problem is my bad code, or if it's a configuration I haven't done on the routers that's causing it.
I just need to be able to pingall with no loss.
i want something like this using web2py routing :
domain.com/App/controller/view/args?profile Id=XX
domain.com/App/profile Id/controller/view/args
i try this code :
routes_in = (
('/App-name/(?P<any>.*)/$c/$f/', '/App-name/$c/$f/\g<any>'),
)
routes_out = (
('/App-name/$c/$f/\g<any>', '/App-name/(?P<any>.*)/$c/$f/'),
)
thank you
its work now
routes_in = (
('/admin','/admin'),
('/admin/$anything','/admin/$anything'),
('/$app/appadmin','/$app/appadmin'),
('/$app/appadmin/$anything','/$app/appadmin/$anything'),
('/Appname/$profileid/','/Appname/default/index/$profileid'),
('/Appname/$profileid/$c/$f/','/Appname/$c/$f/$profileid'),
('/Appname/$profileid/$c/$f/$arg1','/Appname/$c/$f/$arg1/$profileid'),
('/Appname/$profileid/$c/$f/$arg1/$arg2','/Appname/$c/$f/$arg1/$arg2/$profileid'),
)
routes_out = (
('/admin','/admin'),
('/admin/$anything','/admin/$anything'),
('/$app/appadmin','/$app/appadmin'),
('/$app/appadmin/$anything','/$app/appadmin/$anything'),
('/Appname/default/index/$profileid','/Appname/$profileid/'),
('/Appname/$c/$f/$profileid','/Appname/$profileid/$c/$f/'),
('/Appname/$c/$f/$arg1/$profileid','/Appname/$profileid/$c/$f/$arg1'),
('/Appname/$c/$f/$arg1/$arg2/$profileid','/Appname/$profileid/$c/$f/$arg1/$arg2'),
)
I've written a little app in web.py and it works fine. It also delivers some images that are generated and dumped into a folder inside the static dir.
I also want to be able to show the list of files and folders inside static. How do I enable listview?
Typically you don't quite "enable" it. But there are a couple of choices you have.
1) Integrate it into your favorite webserver as a module. Here is how to run it as a FastCGI in lighttpd. There are also options for integrating with Apache.
see webpy.org for more info
server.modules += ( "mod_fastcgi" )
server.modules += ( "mod_rewrite" )
fastcgi.server = ( "/code.py" =>
(( "socket" => "/tmp/fastcgi.socket",
"bin-path" => "/path-to/webpy-app/code.py",
"max-procs" => 1,
"bin-environment" => (
"REAL_SCRIPT_NAME" => ""
),
"check-local" => "disable"
))
)
url.rewrite-once = (
"^/favicon.ico$" => "/static/favicon.ico",
"^/static/(.*)$" => "/static/$1",
"^/(.*)$" => "/code.py/$1",
)
2) Or write code in your python app to handle it.
class list:
def GET(self,irl):
thisfile = inspect.getfile(inspect.currentframe())
thispath = os.path.dirname(os.path.abspath(thisfile))
dir = os.listdir("%s/static/%s"%(thispath,irl))
rel = irl
files = []
folds = []
for item in dir:
if os.path.isfile("%s/static/%s/%s"%(thispath,irl,item)):
files.append(item)
elif item!='res':
folds.append(item)
return render.list(rel,folds,files)
...and in the template...
$def with (rel,folds,files)
...
$if len(folds)>0:
$for fold in folds:
<a class='fold' href='/list$rel/$fold'>$fold</a>
...
$if len(files)>0:
$for file in files:
<a class='file' href='/$rel/$file'>$file</a>