Advertisement
core_st

Untitled

Jul 10th, 2013
1,606
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. """Custom topology script for Mininet
  2.  
  3. Creates custom tree with parameters depth and fanout (count of childs per parent node)
  4. Use: mn --custom %PATH to script%/%script_name%.py --topo custom
  5.  
  6. """
  7.  
  8. from mininet.topo import Topo
  9. from mininet.net import Mininet
  10. from mininet.util import dumpNodeConnections
  11. from mininet.log import setLogLevel
  12.  
  13. class CustomTopo(Topo):
  14.    
  15.     # fanout - number of child switch per parent switch"
  16.    
  17.     def __init__(self, depth=2, fanout=2, **opts):
  18.         # Initialize topology and default options
  19.         Topo.__init__(self, **opts)
  20.        
  21.         #core_switch = self.addSwitch('c1')
  22.         switches = {} #map {depth_level : [list of nodes]}
  23.         hosts = []
  24.         parend_id = 0
  25.         switches[0] = list()
  26.         switches[0].append(self.addSwitch('s1'))
  27.  
  28.         for s in range(1, depth): #last is host level
  29.             switches[s] = list() #initialize list for dict
  30.             for sw in range(0,fanout**s):
  31.                 switch_id = fanout**s+sw
  32.                 switches[s].append(self.addSwitch('s%s'%(switch_id)))
  33.                 self.addLink(switches[s][-1],switches[s-1][sw//fanout])
  34.  
  35.        
  36.         for h in range(0, fanout**depth):
  37.             hosts.append(self.addHost('h%s'%(h+1)))
  38.             self.addLink(hosts[-1],switches[depth-1][h//fanout])
  39.  
  40.                    
  41. topos = { 'custom': ( lambda: CustomTopo(depth=2,fanout=2) ) }  # set params here
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement