python - Mininet script for generic Tree topology with custom bandwidth links -
previously created mininet topology using command:
sudo mn --topo tree,depth=2,fanout=5 --controller=remote,ip=10.0.0.1,port=6633 --switch ovsk,protocols=openflow13, --link tc,bw=1,delay=10ms
i need specify custom bw
values different links.
how make tree in generic way, specifying depth
, fanout
values treenet
mentioned here? need setlink(int value, src, dest)
modify links of tree created.
till have this:
#!/usr/bin/python functools import partial mininet.cli import cli mininet.link import tclink mininet.log import setloglevel mininet.net import mininet mininet.node import ovskernelswitch mininet.node import remotecontroller mininet.topo import topo mininet.util import dumpnodeconnections class mynet( topo ): def __init__( self ): "create custom topo." # initialize topology topo.__init__( self ) # add hosts h1 = self.addhost( 'h1' ) h2 = self.addhost( 'h2' ) ... h25 = self.addhost( 'h25' ) # add switches s1 = self.addswitch( 's1' ) ... s6 = self.addswitch( 's6' ) # add links self.addlink( s2, s1 ,bw=10) self.addlink( s3, s1 ,bw=10) self.addlink( s4, s1 ,bw=10) self.addlink( s5, s1 ,bw=10) self.addlink( s6, s1 ,bw=10) self.addlink( h1, s2 ,bw=10) self.addlink( h2, s2 ,bw=10) self.addlink( h3, s2 ,bw=10) self.addlink( h4, s2 ,bw=10) self.addlink( h5, s2 ,bw=10) self.addlink( h6, s3 ,bw=10) self.addlink( h7, s3 ,bw=10) self.addlink( h8, s3 ,bw=10) self.addlink( h9, s3 ,bw=10) self.addlink( h10, s3 ,bw=10) self.addlink( h11, s4 ,bw=10) ... self.addlink( h25, s6 ,bw=10) topos = { 'mynet': ( lambda: mynet() ) }
i calling using:
#sudo mn --custom mynet.py --topo mynet --controller=remote,ip=10.0.0.1,port=6633 --switch ovsk,protocols=openflow13 --link tc
here made quickly. seems working. got little topolib.py
the code uses recursion. function addtree() called inside itself.
__author__ = 'ehsan' mininet.node import cpulimitedhost mininet.topo import topo mininet.net import mininet mininet.log import setloglevel, info mininet.node import remotecontroller mininet.cli import cli mininet.link import tclink """ instructions run topo: 1. go directory fil is. 2. run: sudo -e python <file name> in case is: sudo -e python tree_generic_topo.py """ class generictree(topo): """simple topology example.""" def build( self, depth=1, fanout=2 ): # numbering: h1..n, s1..m self.hostnum = 1 self.switchnum = 1 def build( self, depth=1, fanout=2 ): # numbering: h1..n, s1..m self.hostnum = 1 self.switchnum = 1 # build topology self.addtree(depth, fanout) def addtree( self, depth, fanout ): """add subtree starting node n. returns: last node added""" isswitch = depth > 0 if isswitch: node = self.addswitch( 's%s' % self.switchnum ) self.switchnum += 1 _ in range( fanout ): child = self.addtree( depth - 1, fanout ) self.addlink( node, child ) else: node = self.addhost( 'h%s' % self.hostnum ) self.hostnum += 1 return node def run(): c = remotecontroller('c', '0.0.0.0', 6633) # change args of generictree() desired values. them command line. net = mininet(topo=generictree(depth=2, fanout=3), host=cpulimitedhost, controller=none) net.addcontroller(c) net.start() # installstaticflows( net ) cli(net) net.stop() # if script run directly (sudo custom/optical.py): if __name__ == '__main__': setloglevel('info') run()
Comments
Post a Comment