示例#1
0
文件: natnet.py 项目: heitorgo1/myfog
    def __init__(self, n=2, **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)
示例#2
0
 def __init__(self, hosts=2, bwlimit=10, lat=0.1, **opts):
     Topo.__init__(self, **opts)
     tor = []
     numLeafes = hosts
     bw = bwlimit
     s = 1
     #bw = 10
     for i in range(numLeafes):
         h = self.addHost('h' + str(i + 1),
                          mac=self.makeMAC(i),
                          ip="10.0.0." + str(i + 1))
         sw = self.addSwitch('s' + str(s),
                             dpid=self.makeDPID(s),
                             **dict(listenPort=(13000 + s - 1)))
         s = s + 1
         self.addLink(h, sw, bw=bw, delay=str(lat) + "ms")
         tor.append(sw)
     toDo = tor  # nodes that have to be integrated into the tree
     while len(toDo) > 1:
         newToDo = []
         for i in range(0, len(toDo), 2):
             sw = self.addSwitch('s' + str(s),
                                 dpid=self.makeDPID(s),
                                 **dict(listenPort=(13000 + s - 1)))
             s = s + 1
             newToDo.append(sw)
             self.addLink(toDo[i], sw, bw=bw, delay=str(lat) + "ms")
             if len(toDo) > (i + 1):
                 self.addLink(toDo[i + 1], sw, bw=bw, delay=str(lat) + "ms")
         toDo = newToDo
         bw = 2.0 * bw
示例#3
0
    def __init__(self, n, **kwargs):
        Topo.__init__(self, **kwargs)

        h1, h2 = self.addHost('h1'), self.addHost('h2')
        s1 = self.addSwitch('s1')

        for _ in range(n):
            self.addLink(s1, h1)
            self.addLink(s1, h2)
示例#4
0
 def __init__(self, n=2, hopts=None, lopts=None):
     if not hopts:
         hopts = {}
     if not lopts:
         lopts = {}
     Topo.__init__(self, hopts=hopts, lopts=lopts)
     switch = self.addSwitch('s1')
     for h in range(n):
         host = self.addHost('h%s' % (h + 1))
         self.addLink(host, switch)
示例#5
0
 def __init__(self, n, dataController=DataController, **kwargs):
     """n: number of data network controller nodes
        dataController: class for data network controllers"""
     Topo.__init__(self, **kwargs)
     # Connect everything to a single switch
     cs0 = self.addSwitch('cs0')
     # Add hosts which will serve as data network controllers
     for i in range(0, n):
         c = self.addHost('c%s' % i, cls=dataController, inNamespace=True)
         self.addLink(c, cs0)
     # Connect switch to root namespace so that data network
     # switches will be able to talk to us
     root = self.addHost('root', inNamespace=False)
     self.addLink(root, cs0)
示例#6
0
    def __init__(self):
        "Create custom topo."

        # Initialize topology
        Topo.__init__(self)

        # Add hosts and switches
        leftHost = self.addHost('h1')
        rightHost = self.addHost('h2')
        leftSwitch = self.addSwitch('s3')
        rightSwitch = self.addSwitch('s4')

        # Add links
        self.addLink(leftHost, leftSwitch)
        self.addLink(leftSwitch, rightSwitch)
        self.addLink(rightSwitch, rightHost)
示例#7
0
    def __init__(self, N, **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)
            last = switch

        # Wire up hosts
        self.addLink(hosts[0], switches[0])
        for host, switch in zip(hosts[1:], switches):
            self.addLink(host, switch)
示例#8
0
 def __init__(self, n=2, lossy=True, **opts):
     Topo.__init__(self, **opts)
     switch = self.addSwitch('s1')
     for h in range(n):
         # Each host gets 50%/n of system CPU
         host = self.addHost('h%s' % (h + 1), cpu=.5 / n)
         if lossy:
             # 10 Mbps, 5ms delay, 10% packet loss
             self.addLink(host,
                          switch,
                          bw=10,
                          delay='5ms',
                          loss=10,
                          use_htb=True)
         else:
             # 10 Mbps, 5ms delay, no packet loss
             self.addLink(host,
                          switch,
                          bw=10,
                          delay='5ms',
                          loss=0,
                          use_htb=True)
示例#9
0
文件: topo.py 项目: heitorgo1/myfog
    def __init__(self, *args, **kwargs):
        Topo.__init__(self, *args, **kwargs)

        self.res_table = ResourcesTable()