Advertisement
Iam_Sandeep

topology

May 14th, 2022
718
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.57 KB | None | 0 0
  1.     import sys
  2.     from nest.experiment import *
  3.     from nest.topology import *
  4.     from topo_helper import topo_helper
  5.     from nest.topology.address_helper import AddressHelper
  6.  
  7.     class PodError(Exception):
  8.         def __init__(self,message):
  9.             self.message=message
  10.  
  11.  
  12.     class Pod:
  13.         def __init__(self,k,net,bw,delay):
  14.  
  15.             self.agg_switches=[Switch('as'+str(i+1)) for i in range(k/2)]
  16.             self.edge_switches=[Switch('as'+str(i+1)) for i in range(k/2)]
  17.             t=k**3/4
  18.  
  19.             self.hosts=[Node('h'+str(i+1)) for i in range(t)]
  20.             '''
  21.            Connections between host to Edge switch
  22.            '''
  23.             for i,switch in enumerate(self.edge_switches):
  24.                 start=i*(k/2)
  25.                 for j in range(start,start+k/2):
  26.                     with net:
  27.                         (i1,i2)=connect(switch,self.hosts[j])
  28.                         i1.set_attributes(bw, delay)
  29.                    
  30.  
  31.             '''
  32.            Connectins between edge switch to agg switch
  33.            '''
  34.             for a_switch in self.agg_switches:
  35.                 for e_switch in self.edge_switches:
  36.                     with net:
  37.                         (i1,i2)=connect(a_switch,e_switch)
  38.                         i1.set_attributes(bw, delay)
  39.                    
  40.  
  41.  
  42.  
  43.     class Fat_tree_helper(topo_helper):
  44.         def __init__(self,k,nid,bw='100mbit',delay='1ms'):
  45.            
  46.             super().__init__(bw,delay)
  47.  
  48.             if k<0:
  49.                 raise PodError("Negative pod count")
  50.             elif k%2==1:
  51.                 raise PodError("Odd pod count")
  52.  
  53.             self.pod_cnt=k
  54.             self.core_cnt=(k//2)**2
  55.             self.core_switches=[Switch('cs'+str(i+1)) for i in range(self.core_cnt)]
  56.  
  57.             self.nid=Network(nid)
  58.             self.blocks=[Pod(k,nid)]*k
  59.  
  60.  
  61.  
  62.             bw=topo_helper.get_bandwidth()
  63.             delay=topo_helper.get_delay()
  64.  
  65.             '''
  66.            Connections betwween core switch to agg switch
  67.            '''
  68.  
  69.             for block in self.blocks:
  70.                 start=0
  71.                 for s in block.agg_switches:
  72.                     for i in range(start,start+k/2):
  73.                         t=self.core_switches[i]
  74.                         with self.nid:
  75.                             (i1,i2)=connect(s,t)
  76.                             i1.set_attributes(bw, delay)
  77.  
  78.  
  79.                     start+=(k/2)
  80.            
  81.             AddressHelper.assign_address()
  82.  
  83.        
  84.      
  85.         def __str__(self):
  86.             return "This is Fat tree class"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement