Advertisement
core_st

Mininet/Python custom tree

Jul 9th, 2013
1,167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.28 KB | None | 0 0
  1. from mininet.topo import Topo
  2. from mininet.net import Mininet
  3. from mininet.util import dumpNodeConnections
  4. from mininet.log import setLogLevel
  5.  
  6. class CustomTopo(Topo):
  7.     "Simple Data Center Topology"
  8.  
  9.     "linkopts - (1:core, 2:aggregation, 3: edge) parameters"
  10.     "fanout - number of child switch per parent switch"
  11.     def __init__(self, depth=2, fanout=2, **opts):
  12.         # Initialize topology and default options
  13.         Topo.__init__(self, **opts)
  14.        
  15.         #core_switch = self.addSwitch('c1')
  16.         switches = {} #map {depth_level : [list of nodes]}
  17.         hosts = []
  18.         parend_id = 0
  19.         switches[0] = list()
  20.         switches[0].append(self.addSwitch('s1'))
  21.  
  22.         for s in range(1, depth): #last is host level
  23.             switches[s] = list() #initialize list for dict
  24.             for sw in range(0,fanout**s):
  25.                 switch_id = fanout**s+sw
  26.                 switches[s].append(self.addSwitch('s%s'%(switch_id)))
  27.                 self.addLink(switches[s][-1],switches[s-1][sw//fanout])
  28.  
  29.        
  30.         for h in range(0, fanout**depth):
  31.             hosts.append(self.addHost('h%s'%(h+1)))
  32.             self.addLink(hosts[-1],switches[depth-1][h//fanout])
  33.  
  34.                    
  35. topos = { 'custom': ( lambda: CustomTopo(depth=2,fanout=2) ) }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement