示例#1
0
文件: CustomTopo.py 项目: ycui/sdn_02
    def __init__(self, linkopts1, linkopts2, linkopts3, fanout=2, **opts):
        # Initialize topology and default options
        Topo.__init__(self, **opts)

        # Create switches and hosts
        c_switch   = self.addSwitch('cs1')
        a_switches = [ self.addSwitch('as%s' % s) for s in irange(1,fanout)     ]
        e_switches = [ self.addSwitch('es%s' % s) for s in irange(1,fanout ** 2)]
        hosts      = [ self.addHost('h%s' % h) for h in irange( 1, fanout  ** 3)]

        # Connect between c_switch and a_switches
        for a_switch in a_switches:
            self.addLink(c_switch,a_switch,**linkopts1)

        # Connect between a_switches and e_switches
        count = 0
        for e_switch in e_switches:
            selector = count / fanout
            self.addLink(e_switch,a_switches[selector],**linkopts2)
            count = count + 1

        # Connect between e_switches and hosts
        count = 0
        for host in hosts:
            selector = count / fanout
            self.addLink(host,e_switches[selector],**linkopts3)
            count = count + 1
示例#2
0
def createTopo():
	topo=Topo()

        swCore1 = topo.addSwitch('s1')

	## Ajuste do parametro de fanout da rede
	fanout = 2

        # Switches counter
        lastSW = 2
        lastHost = 1

        # Aggregation switches loop
        for i in irange (1, fanout):
                swAggregL = topo.addSwitch('s%s' % lastSW)
                topo.addLink(swCore1, swAggregL)
                lastSW += 1

                # Edge switches loop
                for j in irange (1, fanout):
                        swEdge = topo.addSwitch('s%s' % lastSW)
                        topo.addLink(swAggregL, swEdge)
                        lastSW += 1

                        # Hosts loop
                        for k in irange (1, fanout):
                                host = topo.addHost('h%s' % lastHost)
                                topo.addLink(swEdge, host)
                                lastHost += 1
	
	return topo
    def __init__(self, linkopts1, linkopts2, linkopts3, fanout=2, **opts):
    #def __init__(self, fanout=3, **opts):
        # Initialize topology and default options
        Topo.__init__(self, **opts)

	jj = 1
	kk = 1
	coreSwitch = self.addSwitch('c1')
	for i in irange(1, fanout):
		aggSwitch = self.addSwitch('a%s' % i)
		self.addLink(aggSwitch,coreSwitch,**linkopts1)
		link_ae = 1
		for j in irange(jj, fanout * fanout):
			edgeSwitch = self.addSwitch('e%s' % j)
			if link_ae <= fanout:
				self.addLink(edgeSwitch,aggSwitch,**linkopts2)
				link_ae += 1
			else:
				break
			link_eh = 1
			for k in irange(kk, fanout * fanout * fanout):
				host = self.addHost('h%s' % k)
				if link_eh <= fanout:
					self.addLink(host,edgeSwitch,**linkopts3)
					link_eh += 1
				else:
					break
			kk = kk + fanout
		jj = jj + fanout
示例#4
0
    def __init__(self, linkopts1, linkopts2, linkopts3, fanout=2, **opts):
        # Initialize topology and default options
        Topo.__init__(self, **opts)

        self.fonout = fanout

        # Add core switch
        cs_switch = self.addSwitch('cs%s' % 1)

        # Add aggregation switches
        for i in irange(1, fanout):
            as_switch = self.addSwitch('as%s' % i)
            self.addLink(as_switch, cs_switch, **linkopts1)
            as_parent_switch = as_switch
 
            # Add edge switches
            for j in irange(1, fanout):
                es_num = i * fanout - 2 + j
                es_switch = self.addSwitch('es%s' % es_num, **linkopts2)
                self.addLink(es_switch, as_parent_switch)
                es_parent_switch = es_switch
 
                # Add hosts
                for k in irange(1, fanout):
                    host_num = es_num * fanout - 2 + k
                    host = self.addHost('h%s' % host_num, cpu=.5/fanout)
                    self.addLink(host, es_parent_switch, **linkopts3)
示例#5
0
    def __init__(self, linkopts1, linkopts2, linkopts3, fanout=2, **opts):
        # Initialize topology and default options
        Topo.__init__(self, **opts)
        aggregation = []
        edge = []
        host = []

        self.linkopts = [ linkopts1, linkopts2, linkopts3 ]

        # Create core switch
        core = self.addSwitch('c1')

        # Aggregation switches
        for i in irange(1, fanout):
            aggregation.append(self.addSwitch('a%s' % (len(aggregation) + 1)))
            self.addLink(core, aggregation[-1], **linkopts1)

            # Edge switches
            for j in irange(1, fanout):
                edge.append(self.addSwitch('e%s' % (len(edge) + 1)))
                self.addLink(aggregation[-1], edge[-1], **linkopts2)

                # Hosts
                for k in irange(1, fanout):
                    host.append(self.addHost('h%s' % (len(host) + 1)))
                    self.addLink(host[-1], edge[-1], **linkopts3)
示例#6
0
文件: topo.py 项目: pantuza/mininet
    def __init__(self, k=2, n=1, **opts):
        """Init.
           k: number of switches
           n: number of hosts per switch
           hconf: host configuration options
           lconf: link configuration options"""

        super(LinearTopo, self).__init__(**opts)

        self.k = k
        self.n = n

        lastSwitch = None
        for i in irange(1, k):
            # Add switch
            switch = self.addSwitch('s%s' % i)
            # Add hosts to switch
            for j in irange(1, n):
              hostNum = (i-1)*n + j
              host = self.addHost('h%s' % hostNum)
              self.addLink(host, switch)
            # Connect switch to previous
            if lastSwitch:
                self.addLink(switch, lastSwitch)
            lastSwitch = switch
示例#7
0
文件: topo.py 项目: ActiveCK/mininet
    def __init__(self, k=2, n=1, **opts):
        """Init.
           k: number of switches
           n: number of hosts per switch
           hconf: host configuration options
           lconf: link configuration options"""

        super(LinearTopo, self).__init__(**opts)

        self.k = k
        self.n = n

        if n == 1:
            genHostName = lambda i, j: 'h%s' % i
        else:
            genHostName = lambda i, j: 'h%ss%d' % (j, i)


        lastSwitch = None
        for i in irange(1, k):
            # Add switch
            switch = self.addSwitch('s%s' % i)
            # Add hosts to switch
            for j in irange(1, n):
                host = self.addHost(genHostName(i, j))
                self.addLink(host, switch)
            # Connect switch to previous
            if lastSwitch:
                self.addLink(switch, lastSwitch)
            lastSwitch = switch
    def __init__(self, linkopts1, linkopts2, linkopts3, fanout=2, **opts):
        # Initialize topology and default options
        Topo.__init__(self, **opts)

        # Add your logic here ...

        chooser = lambda dict, para, default: para in dict and dict[para] or default
        #add core switch:
        core_switch = self.addSwitch('c1')
        #add agg switch
        for i in irange(1, fanout):
            agg_switch = self.addSwitch('a%s'%i)
            loss = chooser(linkopts1, 'loss', 1)
            max_queue_size = chooser(linkopts1, 'max_queue_size', 1000)
            use_htb = chooser(linkopts1, 'use_htb', True)
            self.addLink(core_switch, agg_switch, bw=linkopts1['bw'], delay=linkopts1['delay'], loss=loss, max_queue_size=max_queue_size, use_htb=use_htb)
            #add edge switches
            for j in irange(1, fanout):
                edge_switch = self.addSwitch('e%s'%((i-1)*fanout+j))
                loss = chooser(linkopts2, 'loss', 1)
                max_queue_size = chooser(linkopts2, 'max_queue_size', 1000)
                use_htb = chooser(linkopts2, 'use_htb', True)
                self.addLink(agg_switch, edge_switch, bw=linkopts2['bw'], delay=linkopts2['delay'], loss=loss, max_queue_size=max_queue_size, use_htb=use_htb)
                #add hosts:
                for k in irange(1, fanout):
                    host = self.addHost('h%s'%(((i-1)*fanout+j-1)*fanout+k))
                    loss = chooser(linkopts3, 'loss', 1)
                    max_queue_size = chooser(linkopts3, 'max_queue_size', 1000)
                    use_htb = chooser(linkopts3, 'use_htb', True)
                    self.addLink(edge_switch, host, bw=linkopts3['bw'], delay=linkopts3['delay'], loss=loss, max_queue_size=max_queue_size, use_htb=use_htb)
    def __init__(self, linkopts1, linkopts2, linkopts3, fanout=2, **opts):
        # Initialize topology and default options
        Topo.__init__(self, **opts)
        
        # Add your logic here ...

        # changed LinearTopo to TreeTopo, not sure what difference this makes)
        super(CustomTopo, self).__init__(**opts)

        self.fanout = fanout
        switchFanOut = fanout
        edgeSwitchFanOut = fanout
        hostFanOut = fanout



        #lastSwitch = None
        # create core switch
        coreSwitch = self.addSwitch('c1')

        #now start logic of creating tree under the root (i.e. core switch)
        for asfo in irange(1, switchFanOut):
            aggSwitch = self.addSwitch('a%s' % asfo)
            for esfo in irange(1+fanout*(asfo-1), edgeSwitchFanOut+fanout*(asfo-1)):
                edgeSwitch = self.addSwitch('e%s' % esfo)
                for hfo in irange(1+fanout*(esfo-1), hostFanOut+fanout*(esfo-1)):
                    host = self.addHost('h%s' % hfo)
                    self.addLink(host, edgeSwitch, **linkopts3)
                self.addLink(edgeSwitch, aggSwitch, **linkopts2)
            self.addLink(coreSwitch, aggSwitch, **linkopts1)
示例#10
0
    def __init__( self, N, bw, **params ):

        # Initialize topology
        Topo.__init__( self, **params )

        # Create switches and hosts
        hosts = [ self.addHost( 'h%s' % h )
                  for h in irange( 1, N ) ]
        switches = [ self.addSwitch( 's%s' % s )
                     for s in irange( 1, N - 1 ) ]

        # Wire up switches
        last = None
        for switch in switches:
            if last:
                self.addLink( last, switch, 
                              bw=bw, delay='1ns', loss=0, use_htb=True)
            last = switch

        # Wire up hosts
        self.addLink( hosts[ 0 ], switches[ 0 ], 
                      bw=bw, delay='1ms', loss=0, use_htb=True)
        for host, switch in zip( hosts[ 1: ], switches ):
            self.addLink( host, switch, 
                          bw=bw, delay='1ms', loss=0, use_htb=True)
示例#11
0
    def __init__(self, k, l, **opts):
        """Init.
            k: number of switches (and hosts)
            hconf: host configuration options
            lconf: link configuration options"""

        super(dcSpineLeafTopo, self).__init__(**opts)

        self.k = k
        self.l = l

        for i in irange(0, k-1):
            spineSwitch = self.addSwitch('s%s%s' % (1,i+1))
            spineList.append(spineSwitch)

        for i in irange(0, l-1):
            leafSwitch = self.addSwitch('l%s%s' % (2, i+1))

            leafList.append(leafSwitch)
            host1 = self.addHost('h%s' % (i+1))
            #host12 = self.addHost('h%s' % (i+1))
            #hosts1 = [ net.addHost( 'h%d' % n ) for n in 3, 4 ]

            "connection of the hosts to the left tor switch "
            self.addLink(host1, leafSwitch, **link_host_leaf)
            #self.addLink(host12, leafSwitch)

        for i in irange(0, k-1):
            for j in irange(0, l-1): #this is to go through the leaf switches
                self.addLink(spineList[i], leafList[j], **link_spine_leaf)
    def build( self, k=2, n=1,delay=None, **_opts):
        """k: number of switches
           n: number of hosts per switch"""
        self.k = k
        self.n = n

        if n == 1:
            genHostName = lambda i, j: 'h%s' % i
        else:
            genHostName = lambda i, j: 'h%ss%d' % ( j, i )

        lastSwitch = None
        for i in irange( 1, k ):
            # Add switch
            switch = self.addSwitch( 's%s' % i )
            # Add hosts to switch
            for j in irange( 1, n ):
                host = self.addHost( genHostName( i, j ) )
                if delay != None:
                  self.addLink( host, switch, delay=delay, use_htb=True)
                else:
                  self.addLink( host, switch)
            # Connect switch to previous
            if lastSwitch:
                if delay != None:
                  self.addLink( switch, lastSwitch, delay=delay, use_htb=True )
                else:
                  self.addLink( switch, lastSwitch )
            lastSwitch = switch
示例#13
0
 def __init__(self, linkopts1, linkopts2,linkopts3,fanout, **opts):
     Topo.__init__(self, **opts)
     self.linkopts1 = linkopts1
     self.linkopts2 = linkopts2
     self.linkopts3 = linkopts3
     self.fanout = fanout
     s=[]
     h=[]
     l=[1]
     a=0
     c=0
     for i in irange(1,1+fanout+fanout**2):
         switch = self.addSwitch('s%s' % i)
         s.append(switch)
     for i in irange(1,fanout**3):
         host = self.addHost('h%s' % i)
         h.append(host)
     for i in range(fanout-1):
         a=a+fanout+1
         l.append(a+1)
     for i in l:
         link = self.addLink(s[0], s[i],**linkopts1)
     for i in l:
         b=0
         for j in irange(1,fanout):
             link = self.addLink(s[i],s[b+i+1],**linkopts2)
             for k in irange(1,fanout):
                 link = self.addLink(h[c],s[b+i+1],**linkopts3)
                 c=c+1
             b=b+1
示例#14
0
   	def __init__(self, linkopts1, linkopts2, linkopts3, fanout=2, **opts):
        	# Initialize topology and default options
        	Topo.__init__(self, **opts)
        	# Add your logic here ...
		
		sw_list_access = []
		sw_list_edge = []
		core_switch = self.addSwitch('c1')
		sw_id = 0
		for i in irange (1, fanout):
			sw_id = sw_id + 1
			access_switch = self.addSwitch('a%s' %sw_id)
			self.addLink(core_switch, access_switch, **linkopts1)
			sw_list_access.append(access_switch)
	
		sw_id = 0
		for sw in sw_list_access:
			for i in irange (1, fanout):
				sw_id = sw_id + 1
				edge_switch = self.addSwitch('e%s' %sw_id)
				self.addLink(edge_switch, sw, **linkopts2)
				sw_list_edge.append(edge_switch)

		h_id = 0
		for sw in sw_list_edge:
			for i in irange (1, fanout):
				h_id = h_id + 1
				host = self.addHost('h%s' %h_id)
				self.addLink(host, sw, **linkopts3) 
示例#15
0
文件: federated.py 项目: eriksore/sdn
    def __init__( self, N,  **params ):
    
    	Topo.__init__( self,  **params )
    	
    	hosts1 = [ self.addHost( 'h%d' % n ) 
    			for n in irange( 1, 2 ) ]
	hosts2 = [ self.addHost( 'h%d' % n ) 
    			for n in irange( 3, 4 ) ]
    	hosts3 = [ self.addHost( 'h%d' % n ) 
    			for n in irange( 5, 6 ) ]
    	hosts4 = [ self.addHost( 'h%d' % n ) 
    			for n in irange( 7, 8 ) ]
	switches = [ self.addSwitch( 's%s' % s ) 
			for s in irange( 1, 6 ) ]
		
	for h in hosts1:
		self.addLink( s2, h )
	for h in hosts2:
		self.addLink( s3, h )
	for h in hosts3:
		self.addLink( s5, h )
	for h in hosts4:
		net.addLink( s6, h )
	self.addLink( s1, s2 )
	self.addLink( s1, s4 )
	self.addLink( s1, s3 )
	self.addLink( s4, s5 )
	self.addLink( s4, s6 )
示例#16
0
 def __init__(self, linkopts1={}, linkopts2={}, linkopts3={}, fanout=2, **opts):
     # Initialize topology and default options
     Topo.__init__(self, **opts)
     
     # Add your logic here ...
     
     # Add CORE
     core = self.addSwitch('c1')
     
     # Aux variables to count switches and hosts used to assign names
     acount = 1
     ecount = 1
     hcount = 1
     
     # Add Agreggation
     for i in irange(1, fanout):
         #name = str(acount + int(i))
         AggSwitch = self.addSwitch('a%s' % acount)
         self.addLink( core, AggSwitch, **linkopts1)
         acount += 1
         # Add Edge
         for j in irange(1,fanout):
             #name = str(ecount + int(j))
             EdgeSwitch = self.addSwitch('e%s' % ecount)
             self.addLink( AggSwitch, EdgeSwitch, **linkopts2)
             ecount += 1
             # Add hosts
             for k in irange(1, fanout):
                 #name = str(hcount + int(k))
                 host = self.addHost('h%s' % hcount)
                 self.addLink( EdgeSwitch, host, **linkopts3)
                 hcount += 1
示例#17
0
    def __init__(self, linkopts1, linkopts2, linkopts3, fanout=2, **opts):
        # Initialize topology and default options
        Topo.__init__(self, **opts)

        # Add your logic here ...
        self.fanout = fanout
        currentHost = 1
        currentEdge = 1
        currentAgg = 1

        # Core Layer
        coreSW = self.addSwitch('c1', cpu=.5/fanout)

        for a in irange(1, fanout):
            # Aggregation Layer
            aggSW = self.addSwitch('a%s' % currentAgg)
            self.addLink(aggSW, coreSW, bw=linkopts1['bw'], delay=linkopts1['delay'], loss=1, max_queue_size=1000, use_htb=True)
            currentAgg += 1
            for e in irange(1, fanout):
                # Edge Layer
                edgeSW = self.addSwitch('e%s' % currentEdge)
                self.addLink(edgeSW, aggSW, bw=linkopts2['bw'], delay=linkopts2['delay'], loss=1, max_queue_size=1000, use_htb=True)
                currentEdge += 1
                for h in irange(1, fanout):
                    # Host Layer
                    host = self.addHost('h%s' % currentHost, cpu=.5/fanout)
                    self.addLink(host, edgeSW, bw=linkopts3['bw'], delay=linkopts3['delay'], loss=1, max_queue_size=1000, use_htb=True)
                    currentHost += 1
示例#18
0
文件: topology.py 项目: mvneves/mremu
    def __init__( self, N, M, **params ):

        # Initialize topology
        Topo.__init__( self, **params )

        print ""
        # Create switches and hosts
        switches = []
        hosts = []
        for s in irange(1, N):
            print 's%s' % s
            switch = self.addSwitch('s%s' % s)
            switches.append(switch)
            for h in irange(1, M):
                print 's%sh%s' % (s, h)
                host = self.addHost('s%sh%s' % (s, h))
                hosts.append(host)
                print 's%sh%s-s%s' % (s, h, s)
                # Wire up hosts
                self.addLink(switch, host)
        print switches
        print hosts

        # Wire up switches
        last = None
        for switch in switches:
            if last:
                self.addLink( last, switch )
                self.addLink( last, switch )
                print last + "-" + switch
            last = switch
示例#19
0
 def build( self, k=2, **_opts ):
     if(emulationEnvironment.isWiFi):
         "k: number of hosts"
         self.k = k
         baseStation = self.addBaseStation( 'ap1' )
         for h in irange( 1, k ):
             host = self.addHost( 'sta%s' % h )
             self.addLink( host, baseStation )
     else:
         "k: number of hosts"
         self.k = k
         switch = self.addSwitch( 's1' )
         for h in irange( 1, k ):
             host = self.addHost( 'h%s' % h )
             self.addLink( host, switch )
示例#20
0
 def build( self, k=2, **_opts ):
     if(Node.isWireless):
         "k: number of hosts"
         self.k = k
         baseStation = self.addBaseStation( 'bs1' )
         for h in irange( 1, k ):
             host = self.addHost( 'sta%s' % h )
             self.addLink( host, baseStation )
     else:
         "k: number of hosts"
         self.k = k
         switch = self.addSwitch( 's1' )
         for h in irange( 1, k ):
             host = self.addHost( 'h%s' % h )
             self.addLink( host, switch )
示例#21
0
 def build( self, k=2, n=1, **_opts):
     
     if(Node.isWireless):
         """k: number of switches
            n: number of hosts per switch"""
         self.k = k
         self.n = n
         Node.wirelessRadios = k*2
         if n == 1:
             genHostName = lambda i, j: 'sta%s' % i
         else:
             genHostName = lambda i, j: 'sta%sap%d' % ( j, i )
 
         lastBaseStation = None
         for i in irange( 1, k ):
             # Add baseStation
             baseStation = self.addBaseStation( 'ap%s' % i, ssid='ssid_ap%s' % i )
             # Add hosts to baseStation
             for j in irange( 1, n ):
                 host = self.addHost( genHostName( i, j ) )
                 self.addLink( host, baseStation )
             # Connect baseStation to previous
             if lastBaseStation:
                 self.addLink( baseStation, lastBaseStation )
             lastBaseStation = baseStation
     else:
         """k: number of switches
            n: number of hosts per switch"""
         self.k = k
         self.n = n
        
         if n == 1:
             genHostName = lambda i, j: 'h%s' % i
         else:
             genHostName = lambda i, j: 'h%ss%d' % ( j, i )
 
         lastSwitch = None
         for i in irange( 1, k ):
             # Add switch
             switch = self.addSwitch( 's%s' % i )
             # Add hosts to switch
             for j in irange( 1, n ):
                 host = self.addHost( genHostName( i, j ) )
                 self.addLink( host, switch )
             # Connect switch to previous
             if lastSwitch:
                 self.addLink( switch, lastSwitch )
             lastSwitch = switch
示例#22
0
 def build( self, k=2, **_opts ):
     isWiFi = _opts.get('isWiFi')
     if isWiFi:
         "k: number of hosts"
         self.k = k
         baseStation = self.addBaseStation( 'ap1' )
         for h in irange( 1, k ):
             host = self.addHost( 'sta%s' % h )
             self.addLink( host, baseStation )
     else:
         "k: number of hosts"
         self.k = k
         switch = self.addSwitch( 's1' )
         for h in irange( 1, k ):
             host = self.addHost( 'h%s' % h )
             self.addLink( host, switch )
示例#23
0
   def __init__(self, k=4, **opts):
       """Init.
           k: number of switches (and hosts)
           hconf: host configuration options
           lconf: link configuration options"""

       super(CustomTopo, self).__init__(**opts)

       self.k = k

       lastSwitch = None
       firstSwitch = None
       for i in irange(1, k):
	   j = 1;
           host1 = self.addHost('h%s_%s' % (i,j))
           j = j + 1;
           host2 = self.addHost('h%s_%s' % (i,j))
           switch = self.addSwitch('s%s' % i)
           if (i == 1):
               firstSwitch = switch
           self.addLink( host1, switch)
           self.addLink( host2, switch)
           if lastSwitch:
               self.addLink( switch, lastSwitch)
           if (i == k):
               router = self.addSwitch('r1')
               self.addLink(switch, router)
               self.addLink(lastSwitch, router)
           lastSwitch = switch

       self.addLink(switch, firstSwitch)
示例#24
0
    def __init__(self, n=2, h=1, **opts):
        Topo.__init__(self, **opts)

        # set up inet switch
        inetSwitch = self.addSwitch('s0')
        # add inet host
        inetHost = self.addHost('h0')
        self.addLink(inetSwitch, inetHost)

        # add local nets
        for i in irange(1, n):
            inetIntf = 'nat%d-eth0' % i
            localIntf = 'nat%d-eth1' % i
            localIP = '192.168.%d.1' % i
            localSubnet = '192.168.%d.0/24' % i
            natParams = { 'ip' : '%s/24' % localIP }
            # add NAT to topology
            nat = self.addNode('nat%d' % i, cls=NAT, subnet=localSubnet, 
                               inetIntf=inetIntf, localIntf=localIntf)
            switch = self.addSwitch('s%d' % i)
            # connect NAT to inet and local switches
            self.addLink(nat, inetSwitch, intfName1=inetIntf)
            self.addLink(nat, switch, intfName1=localIntf, params1=natParams)
            # add host and connect to local switch
            host = self.addHost('h%d' % i, 
                                ip='192.168.%d.100/24' % i, 
                                defaultRoute='via %s' % localIP)
            self.addLink(host, switch)
示例#25
0
文件: topo.py 项目: loox-/mininet
 def build( self, k=2, **opts ):
     "k: number of hosts"
     self.k = k
     switch = self.addSwitch( 's1' )
     for h in irange( 1, k ):
         host = self.addHost( 'h%s' % h )
         self.addLink( host, switch )
示例#26
0
文件: services.py 项目: ARCCN/nps
    def __init__( self, N, S, **params ):

        Topo.__init__( self, **params )

        switch = self.addSwitch('s0')
        #server host for sample
        hs = self.addHost( 'hs%s' % '0' )
        self.addLink(hs, switch)

        for sw in irange( 1, S):
            hosts = [ self.addHost( 'h%s' % h ) for h in irange( (sw-1)*N+1, sw*N ) ]
            switchS = self.addSwitch('s'+str(sw)) 
            print(switchS)
            self.addLink(switch, switchS)
            for host in hosts:
                self.addLink(host, switchS)
示例#27
0
    def __init__(self, k=2, **opts):
        """Init.
           k: number of switches (and hosts)
           hconf: host configuration options
           lconf: link configuration options"""

        super(LinearTopo, self).__init__(**opts)

        self.k = k

        lastSwitch = None
	#print "sys argument",sys.argv[2]
	host_counter = int(sys.argv[2])
        for i in irange(1, k):
            #host = self.addHost('h%s' % i)
            #self.addLink( host, switch)
            if not lastSwitch:
		    for h in range(host_counter):
			host = self.addHost('h%s' %(h+1))
            	        switch = self.addSwitch('s%s' % i)
            	        self.addLink( host, switch)
 
		    '''host1 = self.addHost('h%s' % i)
        	    host2 = self.addHost('h%s' % (i+1))
            	    switch = self.addSwitch('s%s' % i)
            	    self.addLink( host1, switch)
                    self.addLink( host2, switch)'''
	    else:
		    host3 = self.addHost('h%s' % (host_counter+1))		
            	    switch = self.addSwitch('s%s' % i)
            	    self.addLink( host3, switch)

            if lastSwitch:
                self.addLink( switch, lastSwitch)
            lastSwitch = switch
示例#28
0
def servers(hosts):
    serverips = []
    for i in irange(1,8):
	    for host in hosts:
	        if "server%d" % i in host.name.lower():
		        serverips.append(host.ip)
				hosts.remove(host)
	def __init__(self, k=Y, **opts):
		"""Init.
		k: number of switches (and hosts)
		hconf: host configuration options
		lconf: link configuration options"""
		super(LinearTopo, self).__init__(**opts)
		self.k =k
		lastSwitch =None
		t=1
		first=None
		for i in irange(1, k):
			host1 =self.addHost('h%s'%t)
			t=t+1
			host2=self.addHost('h%s'%t)
			t=t+1
			switch =self.addSwitch('s%s'%i)
			if i==1:
			    first=switch
			self.addLink(host1, switch, bw=1, delay='5ms', loss=1, max_queue_size=1000, use_htb=True)
			self.addLink(host2, switch, bw=2)

			if lastSwitch:
				self.addLink(switch, lastSwitch)
			lastSwitch =switch
		self.addLink(switch,first)
	        '''making the circular topology above'''
    def __init__(self, k=2, **opts):
        """Init.
           k: number of switches (and hosts)
           hconf: host configuration options
           lconf: link configuration options"""

        super(LinearTopo, self).__init__(**opts)

        self.k = k

        lastSwitch = None
        for i in irange(1, k):
            host = self.addHost('h%s' % i, cpu=.5 / k)
            switch = self.addSwitch('s%s' % i)
            # 10 Mbps, 5ms delay, 1% loss, 1000 packet queue

            self.addLink(
                host,
                switch,
                bw=10,
                delay='5ms',
                loss=1,
                max_queue_size=1000,
                use_htb=True)
            if lastSwitch:
                self.addLink(
                    switch,
                    lastSwitch,
                    bw=10,
                    delay='5ms',
                    loss=1,
                    max_queue_size=1000,
                    use_htb=True)
            lastSwitch = switch
示例#31
0
    def __init__(self, k=2, **opts):
        super(FatTopo, self).__init__(**opts)
        Corek = k
        hk = int(k / 2)
        Cs = []
        As = []
        Es = []
        Hs = []

        # generate the core switches and assign the dpid
        for i in irange(1, int(Corek * Corek / 4)):
            row = int((i - 1) / hk)
            col = (i - 1) % hk
            dpid = hk * 10000 + row * 100 + col
            Cs.append(self.addSwitch('crSw%s' % (i - 1), dpid=int2dpid(dpid)))
            print('crSw%s - %s' % ((i - 1), dpid))

        # generate the aggregation switches and assign the dpid
        for i in irange(1, Corek):
            for j in irange(1, int(Corek / 2)):
                pod = (i - 1)
                switch = j + hk - 1
                dpid = pod * 10000 + switch * 100 + 1
                As.append(
                    self.addSwitch('agSw%s%s' % ((i - 1), (j - 1)),
                                   dpid=int2dpid(dpid)))
                print('agSw%s%s - %s' % ((i - 1), (j - 1), dpid))

        # generate the edge switches and assign the dpid
        for i in irange(1, Corek):
            for j in irange(1, int(Corek / 2)):
                pod = i - 1
                switch = j - 1
                dpid = pod * 10000 + switch * 100 + 1
                Es.append(
                    self.addSwitch('edSw%s%s' % ((i - 1), (j - 1)),
                                   dpid=int2dpid(dpid)))
                print('EgSw%s%s - %s' % ((i - 1), (j - 1), dpid))

        # generate the hosts and assign the ip address
        for i in irange(1, int(Corek * Corek * Corek / 4)):
            Hs.append(
                self.addHost(
                    'h%s' % (i - 1),
                    ip='10.%s.%s.%s/8' %
                    ((int((i - 1) / int(Corek * Corek / 4))),
                     int((i - 1) / int(Corek / 2) % int(Corek / 2)), 2 +
                     (i - 1) % int(Corek / 2))))

        # connect the host with corresponding edge switch
        counter = 0
        for i in irange(1, int(Corek * Corek / 2)):
            connect = 0
            while connect < int(Corek / 2):
                self.addLink(Es[i - 1], Hs[counter], connect, 0)
                counter += 1
                connect += 1

        # connect the aggregation switch with corresponding edge switch
        for i in irange(1, int(Corek * Corek / 2)):
            offset = int((i - 1) / int(Corek / 2)) * int(Corek / 2) - 1
            for j in irange(1, int(Corek / 2)):
                self.addLink(As[i - 1], Es[j + offset], j - 1,
                             (i - 1) % int(Corek / 2) + int(Corek / 2))

        # connect the core switch with corresponding aggregation switch
        for i in irange(1, int(Corek * Corek / 4)):
            offset = int((i - 1) / int(Corek / 2))
            j = 0
            counter = 0
            while j < (Corek * int(Corek / 2)):
                self.addLink(Cs[i - 1], As[j + offset], counter,
                             (i - 1) % int(Corek / 2) + int(Corek / 2))
                j += int(Corek / 2)
                counter += 1
示例#32
0
 def addSwitches():
     return [self.addSwitch('s%s' % i) for i in irange(1, n)]
示例#33
0
setLogLevel('info')





"Datacenter topology with 4 hosts per rack, 4 racks, and a root switch"
controllerIP = repr(os.environ.get('CONTROLLER_IP'))
self = Containernet(controller=RemoteController)
info('*** Adding controller at '+ controllerIP + '\n')
self.addController('c0', controller=RemoteController, ip=controllerIP, port=6653)


self.racks = []
rootSwitch = self.addSwitch('s1')
for i in irange(1, 2):
    rack = self.buildRack(i)
    self.racks.append(rack)
    for switch in rack:
        self.addLink(rootSwitch, switch)


"Build a rack of hosts with a top-of-rack switch"

dpid = (loc * 16) + 1
switch = self.addSwitch('s1r%s' % loc, dpid='%x' % dpid)

for n in irange(1, 5):
    #host = self.addHost( 'h%sr%s' % ( n, loc ) )
    #host = self.addHost('h%sr%s' % (n, loc), dimage="ubuntu:trusty")
    host = self.addDocker('h%sr%s', dimage="acksec/dc26", environment={"CONTROLLER_IP": controllerIP}, working_dir="/root")
def stringBandwidthTest(host_class, controller_class, link_class, size, tdf,
                        data_file):
    "Check bandwidth at various lengths along a switch chain."

    topo_class = StringTestTopo(size)

    net = Mininet(topo=topo_class,
                  host=host_class,
                  switch=OVSKernelSwitch,
                  controller=controller_class,
                  waitConnected=True,
                  link=link_class)
    net.start()

    src, dst = net.hosts[0], net.hosts[1]
    print "*** testing basic connectivity"
    net.ping([src, dst])

    if tdf == 1:
        num_pings = 3
        for i in irange(1, num_pings):
            ping_result = list(net.pingFull([src, dst]))
            rttavg = ping_result[0][2][3]
        data_file.write("%s\t" % rttavg)
        data_file.flush()

    print "*** testing bandwidth"
    print "testing", src, "<->", dst

    num_rounds = 8
    #cli_results = []
    ser_results = []
    omit = 1
    time = 11
    start = timeit.default_timer()
    for i in irange(1, num_rounds):
        bandwidth = net.iperf([src, dst],
                              l4Type='TCP',
                              format='m',
                              time=time,
                              omit=omit)
        flush()
        serout = bandwidth[0]
        cliout = bandwidth[1]

        if len(serout) > 0:
            serDataStr, unit = serout.split(" ")
            serData = float(serDataStr)
            if serData > 0.1:
                ser_results.append(serData)

        #if len(cliout) > 0:
        #cliDataStr, unit = cliout.split(" ")
        #cliData = float(cliDataStr)
        #if cliData > 0.1:
        #cli_results.append( cliData )

    end = timeit.default_timer()
    elapsed = end - start
    print "elapsed: %s\n" % elapsed
    # unit = Mbits/sec
    #avgCliBw = numpy.mean( cli_results )
    #stdevCliBw = numpy.std( cli_results )
    maxSerBw = numpy.amax(ser_results)
    minSerBw = numpy.amin(ser_results)
    if len(ser_results) >= 10:
        ser_results.remove(maxSerBw)
        ser_results.remove(minSerBw)

    avgSerBw = numpy.mean(ser_results)
    stdevSerBw = numpy.std(ser_results)
    print "Avg = %f" % avgSerBw
    print "Std = %f" % stdevSerBw
    #data_file.write("%s\t%s\t%s\t%s\t%s\n" % (size, avgCliBw, stdevCliBw, maxCliBw, minCliBw))
    data_file.write("%s\t%s\t%s\t%s\n" % (size, avgSerBw, stdevSerBw, elapsed))
    data_file.flush()
    net.stop()
    return avgSerBw, stdevSerBw
示例#35
0
    def buildRouter(self, network, r, create_edge, create_srs):
        r.name = r.name.encode('ascii', 'ignore')

        router = network.addSwitch(r.name + '-rtr',
                                   dpid=self.padDpid(r.self_dpid))

        nat = network.addSwitch(r.name + '-nat', dpid=self.padDpid(r.nat_dpid))
        network.addLink(router, nat, **self.linkopts)

        translator = network.addSwitch(r.name + '-tr',
                                       dpid=self.padDpid(r.tr_dpid))
        acl_table = network.addSwitch(r.name + '-acl',
                                      dpid=self.padDpid(r.acl_dpid))
        vlan = network.addSwitch(r.name + '-vlan',
                                 dpid=self.padDpid(r.vlan_dpid))

        for (i, s) in enumerate(r.subnets):
            s.gw = s.gw.encode('ascii', 'ignore')
            N = i + 1
            inPt = 2 * N - 1
            outPt = 2 * N
            rtrPt = N + 1

            network.addLink(vlan,
                            acl_table,
                            port1=r.num_physical + N,
                            port2=inPt,
                            **self.linkopts)
            network.addLink(acl_table,
                            translator,
                            port1=outPt,
                            port2=inPt,
                            **self.linkopts)
            network.addLink(translator,
                            router,
                            port1=outPt,
                            port2=rtrPt,
                            **self.linkopts)

            if not create_srs:
                continue

        for p in r.ports:
            # Not a vlan tag
            if p.vlan_type == '':

                s = filter(lambda x: p.id in x.physical_portid, r.subnets)[0]

                srs = self.subnetRootSwitch[subnetStr(s.addr, s.mask)]
                network.addLink(srs, vlan, port2=p.id, **self.linkopts)

                # if there's room for hosts, add an edge switch with some hosts!
                if s.mask < 30 and create_edge:
                    self.globalEdgeSwCount += 1
                    edge_switch = network.addSwitch(
                        's' + str(self.globalEdgeSwCount))
                    network.addLink(srs, edge_switch, **self.linkopts)

                    for h in irange(1, self.numHostsPerSubnet):
                        self.globalHostCount += 1
                        name = "host%d" % self.globalHostCount
                        ip = self.nextSubnetHost(s.addr, s.mask, s.gw)

                        host = network.addHost(
                            name,
                            ip='%s/%d' % (ip, s.mask),
                            defaultRoute='dev %s-eth0 via %s' % (name, s.gw))
                        network.addLink(host, edge_switch, **self.linkopts)

            elif p.vlan_type.lower() == 'access':
                s = filter(lambda x: p.id in x.physical_portid, r.subnets)

                if len(s) == 0:
                    print "Warning! %s:%s is not in a subnet!" % (r.name,
                                                                  p.name)
                    continue
                s = s[0]

                if s.mask < 30 and create_edge:
                    self.globalHostCount += 1
                    name = "host%d" % self.globalHostCount
                    ip = self.nextSubnetHost(s.addr, s.mask, s.gw)

                    host = network.addHost(name,
                                           ip='%s/%d' % (ip, s.mask),
                                           defaultRoute='dev %s-eth0 via %s' %
                                           (name, s.gw))

                    network.addLink(host, vlan, port2=p.id, **self.linkopts)

            elif p.vlan_type.lower() == 'trunk':
                self.trunkPorts[r.name.lower(), p.name.lower()] = p.id
示例#36
0
 def addHosts():
     h = n * k
     return [self.addHost('h%s' % i) for i in irange(1, h)]
示例#37
0
def run_dasdn_expt(net, n):
    "Run experiment"
    print 'thread %s is running...' % threading.current_thread().name


    # 创建5个节点的可变时间 (n)
    if args.time !=-1:
        TRANS_SECONDS = [args.time*0.5, args.time, args.time*0.5, args.time*1.5, args.time]
        if (len(TRANS_SECONDS) < args.n): # 检查节点时间长度
            output("节点可变时间的数据不足,长度 %d < n(%d) , exit ... " %(len(TRANS_SECONDS), args.n))
            exit()
    else:
        TRANS_NUMS = [args.num_mb*0.5, args.num_mb, args.num_mb*1.5, args.num_mb*2, args.num_mb*0.5]

    WASTE_TIMES = [0, 0, 5, 0, 0] # 是否存在空闲时间

    print 'len: WASTE_TIMES %d' % len(WASTE_TIMES)
    print 'len: TRANS_SECONDS %d' % len(TRANS_SECONDS)


    # Start the bandwidth and cwnd monitors in the background
    monitors = []

    monitor = Process(target=monitor_devs_ng,
                      args=('%s/bwm.txt' % args.dir, 1.0))
    monitor.start()
    monitors.append(monitor)

    monitor = Process(target=monitor_cpu, args=('%s/cpu.txt' % args.dir,))
    monitor.start()
    monitors.append(monitor)

    # monitor = Process(target=monitor_qlen, args=('s1-eth1', 0.01, '%s/qlen_s1-eth1.txt' % (args.dir)))
    # monitor.start()
    # monitors.append(monitor)

    start_tcpprobe()

    # Get receiver and clients
    recvr = net.getNodeByName('h99')
    clients = [net.getNodeByName('h%s' % i)
                for i in irange(1, n)]
    cprint("Receiver: %s" % recvr, 'magenta')
    cprint("Clients: " + ', '.join([str(c) for c in clients]),
           'magenta')

    # Start the receiver
    port = 5001
    recvr.cmd('iperf -s -p', port,
              '> %s/iperf_server.txt' % args.dir, '&')

    waitListening(clients[0], recvr, port)


    for i in range(n):
        # for c in clients:
        c = clients[i]
        waste_time = WASTE_TIMES[i]

        sleep(1+waste_time)

        cmd = ['iperf',
               '-c', recvr.IP(),
               '-p', port,
               '-i', 1,  # reporting interval
               '-Z reno',  # use TCP Reno
               #'-yc', # report output as comma-separated values
               ]

        outfile = {}

        outfile[c] = '%s/iperf_%s.txt' % (args.dir, c.name)
        # Ugh, this is a bit ugly....
        redirect = ['>', outfile[c]]

        if args.time != -1 :
            seconds = TRANS_SECONDS[i]
            cmd += ['-t', seconds ]  # change -t seconds to -d num_bytes seconds * 75000000
            output(cmd , "\n")
            c.sendCmd(cmd + redirect, printPid=False) # background cmd
            output(' client %s connect with %d seconds, waste %d seconds ..\n' % (c, seconds, waste_time))
            #sleep(seconds)
            #output(' client %s start ... \n' % c )
            progress(seconds) # 读秒等待
        else:
            num_mb = TRANS_NUMS[i]
            cmd += ['-d', "%sM" % (num_mb) ]  # change -t seconds to -d num_bytes seconds * 75000000
            output(cmd , "\n")
            c.cmd(cmd + redirect, printPid=False)  # foreground cmd

    # Start command line for debug
    if args.cli:
        CLI(net)

    # Count down time
    # progress(seconds * n)

    # Wait for clients to complete
    # If you don't do this, iperfs may keep running!
    output('Waiting for clients to complete...\n')
    for c in clients:
        c.waitOutput(verbose=True)

    recvr.cmd('kill %iperf')

    # Shut down monitors
    for monitor in monitors:
	monitor.terminate()
    stop_tcpprobe()
    def __init__(self, linkopts1, linkopts2, linkopts3, k=2, **opts):

        #linkopts1 = performance parameters for the links between core and aggregation switches
        #linkopts2 = performance parameters for the links between aggregation and edge switches
        #linkopts3 = performance parameters for the links between edge switches and host

        super(FatTreeTopology, self).__init__(**opts)
        self.fanout = k
        self.pods = []
        self.cores = []
        self.countHosts = 0
        self.countSwitch = 0
        self.hostForPod = 0
        self.switchPerLayer = (self.fanout / 2)
        self.edgeHostConn = 0
        self.edgeAggConn = 0
        self.aggCoreConn = 0
        self.numCores = 0

        #Creates Core Switches
        countCores = (self.fanout / 2)**2
        for i in irange(1, countCores):
            self.countSwitch += 1
            coreSwitch = self.addSwitch("s%s" % (self.countSwitch),
                                        cls=OVSKernelSwitch,
                                        failMode='standalone')
            self.cores.append(coreSwitch)
            self.numCores += 1

        #Creates Pods + Hosts
        for i in irange(1, self.fanout):
            self.pods.append(self.createPod(i, linkopts2, linkopts3))

        #Links Core Switches to Pods
        count = 0  #Core switch Position
        for i in self.cores:
            for j in self.pods:
                if count < (self.fanout / 2):
                    self.addLink(j.layers[0][((self.fanout / 2) / 2) - 1], i,
                                 **linkopts1)
                else:
                    self.addLink(j.layers[0][((self.fanout / 2) / 2)], i,
                                 **linkopts1)
                self.aggCoreConn += 1
            count += 1

        self.corePodConn = self.numCores * k

        print("\n---------------------%s-ary fat tree  ---------------" %
              self.fanout)
        print("number of pods                            : %s" % self.fanout)
        print("hosts per pod                             : %s" %
              self.hostForPod)
        print("number of switches per layer in pod       : %s" %
              self.switchPerLayer)
        print("number of switch ports in pod             : %s" % self.fanout)
        print("edge switch-host connections              : %s" %
              self.edgeHostConn)
        print("edge switch-aggregation switch connections: %s" %
              self.edgeAggConn)
        print("aggregation switch-core switch connections: %s" %
              self.aggCoreConn)
        print("number of core switches                   : %s" % self.numCores)
        print("number of pods core switches connect to   : %s" %
              self.corePodConn)
        print("total number of hosts                     : %s" %
              self.countHosts)
        print("-----------------------------------------------------")
示例#39
0
def simple_test():
    """Create and test a simple network"""
    topo = MyTopo(num_sws=switches_per_router)
    net = Mininet(topo,
                  link=TCLink,
                  switch=OVSKernelSwitch,
                  autoSetMacs=True,
                  autoStaticArp=False,
                  controller=lambda name: RemoteController(
                      name, ip=controllerIP, port=6633))
    net.start()

    if monitoring == 1:
        # --- Monitoring
        os.popen('ip link show > ports.txt')
        # '''
        snmp_dev_proc = subprocess.Popen(
            'while sleep %s; do %s; snmpwalk -v 1 -c public -O e localhost 1.3.6.1.2.1.25.2.3.1.6.1;'
            ' snmpwalk -v 1 -c public -O e localhost 1.3.6.1.2.1.25.3.3.1.2; done>> DevStats.txt 2>> err.txt &'
            % (interval, dateCmd),
            shell=True)

        c0 = net.get('c0')
        c0.cmd(
            'snmpd -Lsd -Lf /dev/null -u snmp -I -smux -p /var/run/snmpd.pid -c /etc/snmp/snmpd.conf'
        )
        snmp_con_proc = c0.cmd(
            'while sleep %s; do %s; snmpwalk -v 1 -c public -O e %s 1.3.6.1.2.1.25.2.3.1.6.1;'
            ' snmpwalk -v 1 -c public -O e %s 1.3.6.1.2.1.25.3.3.1.2; done>> ControllerStats.txt 2>> err.txt &'
            % (interval, dateCmd, controllerIP, controllerIP))

        for r in irange(1, numNetworks):
            router = net.get('r%s0' % r)
            router.cmd(
                'snmpd -Lsd -Lf /dev/null -u snmp -I -smux -p /var/run/snmpd.pid -c /etc/snmp/snmpd.conf'
            )
            router.cmd(
                'while sleep %s; do %s; snmpwalk -v 1 -c public -O e %s 1.3.6.1.2.1.2.2.1.16; '
                'done>> Router%sIfOutStats.txt 2>> err.txt &' %
                (interval, dateCmd, router.IP(), r))  # .1.3.6.1.2.1.2.2.1.16
        # '''

    # net.staticArp()
    print "Dumping host connections"
    dumpNodeConnections(net.hosts)

    if CLIon == 1:
        CLI(net)

    coefficient = get_coeff() if no_time_run == 2 else 1

    append_file('coefficients-%s-%s.txt' % (sys.argv[2], sys.argv[3]),
                coefficient)
    start_time = time.time()
    # ------- removed net.pingAll()   ----- replaced with net.staticArp()
    # ------- removed    CLI( net )
    n = int(sys.argv[1])  # getting number of IPerf tests from command line
    ''' ---- Removed 02-01-2018 ---- Invalid after hosts.append()
    hpairs = len(net.hosts)/2
    if n > hpairs:
        print "Number of IPerf tests exceeds host pairs. Reducings tests from %s to %s"  %(n,hpairs)
        n = hpairs
    else:
        print "Number of IPerf tests %s" %n
    '''

    if test_with_data == 1:
        t = {}
        # Creating n threads, one for each iperf session
        for i in range(int(n)):
            dt = DataTraffic()
            t[i] = threading.Thread(target=DataTraffic.get_perf_metrics,
                                    args=(dt, net, i))
            t[i].daemon = True
            t[i].start()
            time.sleep(interval)
        # ----- removed time.sleep(20) ------ replaced with join()

        # Making the current thread wait for all the created threads to complete
        for i in range(int(n)):
            t[i].join()

        for r in irange(1, numNetworks):
            router = net.get('r%s0' % r)
            router.sendInt()
    net.stop()
    if monitoring == 1:
        c0.sendInt()
        snmp_dev_proc.kill()
    # os.kill(int(snmp_con_proc.split()[1]), signal.CTRL_C_EVENT)

    stop_time = time.time()
    print_file('blocked.txt', blocked)
    print_file('dropped.txt', dropped)
    print(stop_time - start_time)
    print os.system(
        '%s >> log.txt; echo %s >> log.txt' %
        (dateCmd, stop_time -
         start_time))  # dummy command to print  seconds of the clock
示例#40
0
def MultipathTreeNet(depth=2, fanout=4, bw=BW, cpu=-1, queue=100):
    "Create an empty network and add nodes to it."
    host = custom(CPULimitedHost, cpu=cpu)
    link = custom(TCLink, bw=bw, max_queue_size=queue)
    net = Mininet(host=host,
                  link=link,
                  switch=OVSKernelSwitch,
                  controller=RemoteController,
                  autoSetMacs=True,
                  autoStaticArp=False)

    info('*** Adding controller\n')
    net.addController('c0')

    info('*** Adding hosts\n')
    switches = []
    allHosts = []
    i = 1

    # Adding hosts
    for n in irange(1, pow(depth, fanout)):
        print "h%s" % n
        host = net.addHost("h%s" % n, ip=("10.0.0.%s/24" % str(i)))
        i = i + 1
        allHosts.append(host)

    info('*** Adding switches\n')
    i = 1
    # Adding switches
    rootSwitches = []
    for n in irange(1, 2):
        print "s%s" % i
        switch = net.addSwitch("s%s" % i)
        rootSwitches.append(switch)
        i = i + 1

    torSwitches = []
    for n in irange(1, 4):
        print "s%s" % i
        switch = net.addSwitch("s%s" % i)
        torSwitches.append(switch)
        i = i + 1

    info('*** Wiring up switches\n')
    # Wiring up switches
    i = 1
    for switch in torSwitches:
        for up in rootSwitches:
            if i == 1:
                bandwidth = bw  #10
            else:
                bandwidth = bw
            #bandwidth=50
            i = i + 1
            link = custom(TCLink, bw=bandwidth, max_queue_size=queue)
            linkObj = net.addLink(up, switch, cls=link)
            print "link=" + str(linkObj)

    info('*** Creating links to hosts\n')
    # Creating links to hosts
    for n in irange(0, 3):
        switch = torSwitches[n]
        for m in irange(0, 3):
            host = allHosts[(n * 4) + m]
            print "linking %s to %s" % (host.name, switch.name)
            net.addLink(host, switch)
            print ""
    return net
示例#41
0
def ShamrockNet(numSwitches=2,
                numHostsFirstSwitch=12,
                numHostsSecondSwitch=4,
                L=1,
                bw=BW,
                cpu=-1,
                queue=100,
                remoteController=True):
    "Create an empty network and add nodes to it."
    host = custom(CPULimitedHost, cpu=cpu)
    link = custom(TCLink, bw=bw, max_queue_size=queue)
    if remoteController is True:
        controller = RemoteController
    else:
        controller = OVSController
    net = Mininet(host=host,
                  link=link,
                  switch=OVSKernelSwitch,
                  controller=controller,
                  autoSetMacs=True,
                  autoStaticArp=False)

    info('*** Adding controller\n')
    if remoteController is True:
        #net.addController('c0', ip='172.16.2.1', port=6633)
        net.addController('c0', ip='127.0.0.1', port=6633)
    else:
        net.addController('c0')

    info('*** Adding hosts\n')
    switches = []
    allHosts = []
    numSwitches = 2
    i = 1

    # Adding hosts
    n = "1"
    hosts = []
    for m in irange(1, numHostsFirstSwitch):
        print "s%sh%s" % (n, m)
        host = net.addHost("s%sh%s" % (n, m), ip=("10.0.0.%s/24" % str(i)))
        i = i + 1
        hosts.append(host)
    allHosts.append(hosts)

    n = "2"
    hosts = []
    for m in irange(1, numHostsSecondSwitch):
        print "s%sh%s" % (n, m)
        host = net.addHost("s%sh%s" % (n, m), ip=("10.0.0.%s/24" % str(i)))
        i = i + 1
        hosts.append(host)
    allHosts.append(hosts)

    info('*** Adding switches\n')
    # Adding switches
    for n in irange(1, numSwitches):
        print "s%s" % n
        switch = net.addSwitch("s%s" % n)
        switches.append(switch)

    info('*** Wiring up switches\n')
    # Wiring up switches
    i = 1
    last = None
    for switch in switches:
        if last:
            for l in irange(1, L):
                #               print "linking %s to %s" % (last.name, switch.name)
                #                if i == 1:
                #                    bandwidth=10
                #                else:
                #                    bandwidth=bw
                #bandwidth=bw
                bandwidth = 1000
                i = i + 1
                link = custom(TCLink, bw=bandwidth, max_queue_size=queue)
                linkObj = net.addLink(last, switch, cls=link)
                print "link=" + str(linkObj)
        last = switch

    info('*** Creating links to hosts\n')
    # Creating links to hosts
    for n in irange(0, numSwitches - 1):
        switch = switches[n]
        for host in allHosts[n]:
            print "linking %s to %s" % (host.name, switch.name)
            net.addLink(host, switch)
            print ""

    return net
    def __init__(self, **opts):

        # Initialize object argument
        super(SDNTopo, self).__init__(*opts)
        self.k = args.nodes
        self.switch_list = []

        # Create the k switches of the mesh topology
        for i in irange(3, self.k + 2):
            new_switch = self.addSwitch(f"s{i}", dpid=f"{i}")
            self.switch_list.append(new_switch)

        # Create the edge switches
        e1 = self.addSwitch("edge1", dpid="101")
        e2 = self.addSwitch("edge2", dpid="102")

        # Create the bridge switches and Links
        s1 = self.addSwitch("s1", dpid="1")
        s2 = self.addSwitch("s2", dpid="2")
        self.addLink(s1, e1, bw=args.bw, loss=args.loss, delay=args.delay)
        self.addLink(s2, e2, bw=args.bw, loss=args.loss, delay=args.delay)

        # Connect the edge switches with 2 switches
        self.addLink(s1, self.switch_list[0], bw=args.bw, loss=args.loss, delay=args.delay)
        self.addLink(s2, self.switch_list[-1], bw=args.bw, loss=args.loss, delay=args.delay)
        if not self.k % 2 and not args.random:
            self.addLink(s2, self.switch_list[-2], bw=args.bw, loss=args.loss, delay=args.delay)

        # Make STP links
        if not args.random:
            # Connect each switch in a defined topology
            for i in range(0, len(self.switch_list) - 2, 2):
                for j in range(1, 3):
                    self.addLink(
                        self.switch_list[i],
                        self.switch_list[i + j],
                        bw=args.bw,
                        loss=args.loss,
                        delay=args.delay,
                    )
        else:
            # Connect each switch with a random previous one
            for i in range(1, len(self.switch_list)):
                connect_switch = random.choice(self.switch_list[:i])
                self.addLink(
                    self.switch_list[i],
                    connect_switch,
                    bw=args.bw,
                    loss=args.loss,
                    delay=args.delay,
                )

        # Add one host to each core switch
        for i in range(args.hosts):
            new_host = self.addHost(f"h{i}", ip=f"10.10.10.{i+1}/24")
            self.addLink(
                new_host,
                self.switch_list[random.randint(0, len(self.switch_list) - 1)],
                bw=args.bw,
                loss=args.loss,
                delay=args.delay,
            )
示例#43
0
class dcFatTreeTop( Topo ):
	"Linear topology of k switches, with one host per switch."
	def __init__(self, k, **opts): 
		Top.__init__(**opts)
		self.k = k
		link1 = dict(bw=10, delay='1ms', loss=0, max_queue_size=1000, use_htb=True)
		link2 = dict(bw=5, delay='10ms', loss=0, max_queue_size=500, use_htb=True)
		link3 = dict(bw=1, delay='15ms', loss=0, max_queue_size=100, use_htb=True)
		# Creating an array of core switches
		# Adding them in an array so that they can be refered to later
		for i in irange(0, k-1):
			"core switch"
			coreSwitch = self.addSwitch('c%s%s' % (i+1, 0))
			#coreList.insert(i, coreSwitch)
			coreList.append(coreSwitch)
			#lastSwitch = None
		print "entering aggregation switches"
		for i in irange(1, k):
			"aggregation switches"
			aggSwitch1 = self.addSwitch('a%s%s' % (i, 1))
			aggSwitch2 = self.addSwitch('a%s%s' % (i, 3))
			aggList.append(aggSwitch1)
			aggList.append(aggSwitch2)
			torSwitch1 = self.addSwitch('t%s%s' % (i, 2))
			torSwitch2 = self.addSwitch('t%s%s' % (i, 4))
			torList.append(torSwitch1)
			torList.append(torSwitch2)
			"host = self.addHost('h%s%s' % (i, i+1))"
			host11 = self.addHost('h%s%s' % (i, 1))
			host12 = self.addHost('h%s%s' % (i, 2))
			host13 = self.addHost('h%s%s' % (i, 3))
			host14 = self.addHost('h%s%s' % (i, 4))
			#hosts1 = [ net.addHost( 'h%d' % n ) for n in 3, 4 ]
			"connection of the hosts to the left tor switch "
			self.addLink(host11, torSwitch1, **link3)
			self.addLink(host12, torSwitch1, **link3)
			"connection of the hosts to the right tor switch "
			self.addLink(host13, torSwitch2, **link3)
			self.addLink(host14, torSwitch2, **link3)
			"Connection of the the left tor switch to aggregation switches"
			self.addLink(torSwitch1, aggSwitch1, **link2)
			self.addLink(torSwitch1, aggSwitch2, **link2)
			"connection of the the right tor switch to aggregation switches"
			self.addLink(torSwitch2, aggSwitch1, **link2)
			self.addLink(torSwitch2, aggSwitch2, **link2)
		"connect the aggregation switch to top pod core switch"
		if k == 1:
			for r in irange(0, k): #this is to go through the agg switches
				self.addLink(aggList[r], coreList[0])
		else:
			for r in irange(0, (k*2)-1): #this is to go through the agg switches
				if r % 2 == 0: #if agg switch is even then connect to first half
					for j in irange(0, ((k/2)-1)): #this is to go through the core switches
						self.addLink(aggList[r], coreList[j], **link1)
				else:
					for j in irange((k/2), k-1): #this is to go through the core switches
						self.addLink(aggList[r], coreList[j], **link1)
		allList.extend(coreList)
		allList.extend(aggList)
		allList.extend(torList)
	def evenSimpleTest():
		for sw in allList:
			print allList[sw]
	def simpleTest():
		# argument to put in either remote or local controller
		"Create and test a simple network"
		c0 = RemoteController( 'c0', ip='192.168.90.146' )
# the cmap here needs to dynamically take the switch name from the switchLists[] so that it is not static
#cmap = { 'a11': c0, 'a12': c0, 'a21': c0, 'a22': c0, 'a31': c0, 'a32': c0, 'a41': c0, 'a42': c0, 'c11': c0, 'c21': c0, 'c31': c0, 'c41': c0, 't11': c0, 't12': c0, 't21': c0, 't22': c0, 't31': c0, 't32': c0, 't41': c0, 't42': c0}


	class MultiSwitch( OVSSwitch ):
		"Custom Switch() subclass that connects to different controllers"
	def start( self, controllers ):
		return OVSSwitch.start( self, [ cmap[ self.name ] ] )
	#section for handling the differnt argumetns.... simpleTest(arg1, arg2, ...) will take in arguments from user
#	topo = dcFatTreeTopo(k=2)
	topo = dcFatTreeTop(k=2)
	net = Mininet( topo=topo, switch=MultiSwitch, build=False, link=TCLink )
	print "calling Mininet ctor"
	print "connecting all SWITCHES to controller with cmap"
	cString = "{"
	for i in irange(0, len(allList)-1):
		if i != len(allList)-1:
			tempCString = "'" + allList[i] + "'" + " : c0, "
		else:
			tempCString = "'" + allList[i] + "'" + " : c0 "
		cString += tempCString
	cmapString = cString + "}"
#print "wowzer" + cmapString
	cmap = cmapString
	net.addController(c0)
	net.build()
	net.start()
	print "Dumping host connections"
	dumpNodeConnections(net.hosts)
	print "Testing network connectivity"
#def perfTest():
		# if user test argument is active then pick the correct test
	net.pingAll()
	net.pingAll()
	print "Testing bandwidth between h11 and h12..............."
	#h11, h12 = net.get('h11', 'h12')
	#net.iperf((h11, h12)
	#print "Testing bandwidth between h11 and h14..............."
	h11, h14 = net.get('h11', 'h14')
	net.iperf((h11, h14))
	#print "Testing bandwidth between h11 and h16..............."
	h11, h22 = net.get('h11', 'h22')
	net.iperf((h11, h22))
	#print "Testing bandwidth between h11 and h18..............."
	h11, h24 = net.get('h11', 'h24')
	net.iperf((h11, h24))
	# also argument for generating traffic
	# arugment for stat analysis
	CLI( net )
	net.stop()