示例#1
0
   def generateTopology(self,**params):
      debug("* Generating topology: "+self.name+"\n")

      if (self.topo == "star") :
         debug("** Creating core switch of star topology.\n")
         sw = Switch(name = "r1")
         self.switch.append(sw)
         for i in range (self.hosts_in_sw): #adding hosts
            hst = Host(name="h"+str(i+1))
            intf_h =  hst.createInterface(ret=True)
            port_sw = sw.addPort(ret= True) #addPort increases n by 1
            # add link
            link = Link(src=sw.name, dst=hst.name,  intf1=port_sw ,intf2= intf_h, 
                         bw = self.bw, delay=self.delay)
            self.link.append(link)
            self.host.append(hst)  #Or, self.host.append(entry)

      elif (self.topo == "tree") :
        k = self.k_ary
        h = self.size  
        #The height h of a k-ary tree does not include the root node
        #with a tree containing only a root node having a height of 0.
        #ttl_sw = ((k**(h+1)) -1) / (k-1)  #formula here
        intf = 0
        sid = 0 #keep cound as we create sw/hosts
        hid = 0  
        for i in range (h+1): #loop on tree height, Just root = height 0.
          #if i==0 and i==h :#root level 3 port
          if i == h:
            debug("  Edge switch level \n")
            for j in range(k**i):
              sw_name = name="r"+str(sid+1)
              sw = Switch(name = sw_name)
              parent = ((sid-1 )/k) +1 #-1 for formula -1 for our positive id
              parent_name = "r"+str(parent)
              debug( "    Switch: " +sw.name+ ", Parent: " +str(parent)+ "\n")
              self.switch.append(sw)
              sid+=1
              
              if (parent>0 ) :  # and i >0; to exclude root node
                #1. create port for urself
                port_child = sw.addPort( ret = True) #addPort increases n by 1
                
                #2. Find parent and create port for parent
                for ps in self.switch:                #s['sw'] is parent of of sw
                  if ps.name == parent_name:
                    port_parent = ps.addPort(ret = True) #addPort increases n by 1
                    #3. add link child_sw <-->parent_sw
                    link = Link(src=ps.name, dst=sw.name, intf1=port_child, intf2= port_parent, bw = self.bw, delay=self.delay )
                    self.link.append(link)
                    break
              for l in range (self.hosts_in_sw): #adding hosts
                hst = Host(name="h"+str(hid+1))
                intf_h =  hst.createInterface(ret=True)
                port_sw = sw.addPort(ret= True) #addPort increases n by 1
                # add link
                link = Link(src=sw.name, dst=hst.name,  intf1=port_sw ,intf2= intf_h, bw = self.bw, delay=self.delay)
                self.link.append(link)
                self.host.append(hst)  #Or, self.host.append(entry)
                hid+=1

          else:                             #These one's dont need host
            for j in range (k**i):
              sw_name = "r"+str(sid+1)
              sw = Switch(name=sw_name)
              parent = ((sid-1 )/k) +1 #-1 for formula -1 for our positive id
              parent_name = "r"+str(parent)
              debug( "    Switch: " +sw.name+ ", parent: " +str(parent)+ "\n")
              #le = {'id':sid+1,'sw': sw}
              if (parent>0): 
                #1. create port for urself
                port_ch =  sw.addPort(ret = True ) #addPort increases n by 1
                #2. create port for parent
                for ps in self.switch: 
                  if ps.name == parent_name:
                    port_pr = ps.addPort(ret =True) #addPort increases n by 1
                    #3. add link       #parent is source
                    link = Link(src=ps.name, dst=sw.name, intf1= port_pr, intf2= port_ch, \
                                bw = self.bw, delay = self.delay)
                    self.link.append(link)
                    break
              self.switch.append(sw)
              sid+=1
              # child node finds their parent and creates 1) a port on their parent node
              #   2) a port/interface in itself 3) creates a link with parent
      return True
示例#2
0
  def getHostSwLinks(self,**params):
    print "\n** Exploring topology"
    if (self.topo == "tree"):
      k = self.k_ary
      h = self.size  
      #The height h of a k-ary tree does not include the root node
      #with a tree containing only a root node having a height of 0.
      #ttl_sw = ((k**(h+1)) -1) / (k-1)  #formula here
      intf = 0
      sid = 0 #keep cound as we create sw/hosts
      hid = 0  
      for i in range (h+1): #loop on tree height, Just root = height 0.
        #if i==0 and i==h :#root level 3 port
        if i == h:
          #print "Edge switch level "
          for j in range(k**i):
            sw_name = name="s"+str(sid+1)
            sw = Switch(name = sw_name)
            parent = ((sid-1 )/k) +1 #-1 for formula -1 for our positive id
            debug( "  Switch: " +sw.name+ ", Parent: " +str(parent)+ "\n")
            #le = {'id':sid+1,'sw': sw}
            #self.switch.append(le)
            self.switch.append(sw)
            sid+=1
            
            if (parent>0 ) :  # and i >0; to exclude root node
              #1. create port for urself
              sw_if_name = sw_name+"-eth"+str(sw.n)
              mac = randomMAC()
              port_child = sw.addPort(mac= mac, ret = True) #addPort increases n by 1
              
              #2. Find parent and create port for parent
              for ps in self.switch:                #s['sw'] is parent of of sw
                if ps.name == "s"+str(parent):
                  mac = randomMAC()
                  #s_if_name = s['sw'].name+"-eth"+str(s['sw'].n)
                  port_parent = ps.addPort(mac= mac, ret = True) #addPort increases n by 1
                  #3. add link child_sw <-->parent_sw
                  link = Link(src=ps.name, dst=sw.name, intf1=port_child, intf2= port_parent)
                  self.link.append(link)
                  break
            for l in range (self.hosts_in_sw): #adding hosts
              hst = Host(name="h"+str(hid+1))
              intf_h =  hst.createInterface( ip_base=self.ip_base, offset=hid+1,\
                                              mac_base = self.mac_base_host, ret=True)
              mac = randomMAC()
              port_sw = sw.addPort( mac= mac, ret= True) #addPort increases n by 1
              # add link
              link = Link(src=sw.name, dst=hst.name,  intf1=port_sw ,intf2= intf_h)
              self.link.append(link)

              #entry = {'id':hid+1, 'h': hst}
              self.host.append(hst)  #Or, self.host.append(entry)
              hid+=1
        
        else:                             #These one's dont need host
          for j in range (k**i):
            sw_name = "s"+str(sid+1)
            sw = Switch(name=sw_name)
            parent = ((sid-1 )/k) +1 #-1 for formula -1 for our positive id
            debug( "  Switch: " +sw.name+ "parent: " +str(parent)+ "\n")
            #le = {'id':sid+1,'sw': sw}
            if (parent>0): 
              #1. create port for urself
              mac = randomMAC()
              
              port_ch =  sw.addPort(mac= mac, ret = True ) #addPort increases n by 1
              #2. create port for parent
              for ps in self.switch: 
                if ps.name == ("s"+str(parent)):
                  mac = randomMAC()
                  port_pr = ps.addPort(mac= mac,ret =True) #addPort increases n by 1
                  #3. add link       #parent is source
                  link = Link(src=ps.name, dst=sw.name, intf1= port_pr, intf2= port_ch)
                  self.link.append(link)
                  break
              
            #entry = {'id':sid+1, 'sw': sw}
            #self.switch.append(entry)
            self.switch.append(sw)
            sid+=1
            # child node finds their parent and creates 1) a port on their parent node
            #   2) a port/interface in itself 3) creates a link with parent
    return True