Example #1
0
    def __init__(self, numnodes, linkprob = 0.35, seed = None,
                 ipv4prefix = '10.0.0.0/8', ipv6prefix = 'a::/64'):
        assert numnodes > 1
        Topology.__init__(self, numnodes)

        if seed is not None:
            random.seed(seed)

        self.net = self.session.addobj(cls = pycore.nodes.WlanNode)

        p4 = ipaddr.IPv4Prefix(ipv4prefix)
        p6 = ipaddr.IPv6Prefix(ipv6prefix)

        for i in xrange(numnodes):
            addrlist = ['%s/%s' % (p4.addr(i + 1), 32),
                        '%s/%s' % (p6.addr(i + 1), 128)]
            self.n[i].newnetif(self.net, addrlist = addrlist, ifname = 'eth0')

        # connect nodes with probability linkprob
        for i in xrange(numnodes):
            netif = self.n[i].netif(0)
            for j in xrange(i + 1, numnodes):
                r = random.random()
                if r < linkprob:
                    self.net.link(netif, self.n[j].netif(0))
            if not self.net._linked[netif]:
                # force one link to avoid partitions
                j = i
                while j == i:
                    j = random.randint(0, numnodes - 1)
                self.net.link(netif, self.n[j].netif(0))
Example #2
0
    def __init__(self,
                 numnodes,
                 ipv4prefix='10.0.0.0/30',
                 ipv6prefix='a::/126'):
        assert numnodes > 1
        Topology.__init__(self, numnodes)

        self.net = []
        p4 = ipaddr.IPv4Prefix(ipv4prefix)
        p6 = ipaddr.IPv6Prefix(ipv6prefix)

        self.net.append(self.session.addobj(cls=pycore.nodes.SwitchNode))
        addrlist = [
            '%s/%s' % (p4.addr(1), p4.prefixlen),
            '%s/%s' % (p6.addr(1), p6.prefixlen)
        ]
        self.n[0].newnetif(self.net[0], addrlist=addrlist, ifname='eth0')

        for i in xrange(1, numnodes - 1):
            addrlist = [
                '%s/%s' % (p4.addr(2), p4.prefixlen),
                '%s/%s' % (p6.addr(2), p6.prefixlen)
            ]
            self.n[i].newnetif(self.net[i - 1],
                               addrlist=addrlist,
                               ifname='eth0')
            p4 += 1
            p6 += 1
            self.net.append(self.session.addobj(cls=pycore.nodes.SwitchNode))
            addrlist = [
                '%s/%s' % (p4.addr(1), p4.prefixlen),
                '%s/%s' % (p6.addr(1), p6.prefixlen)
            ]
            self.n[i].newnetif(self.net[i], addrlist=addrlist, ifname='eth1')

        i += 1
        addrlist = [
            '%s/%s' % (p4.addr(2), p4.prefixlen),
            '%s/%s' % (p6.addr(2), p6.prefixlen)
        ]
        self.n[i].newnetif(self.net[i - 1], addrlist=addrlist, ifname='eth0')
Example #3
0
    def __init__(self,
                 numnodes,
                 linkprob=0.35,
                 seed=None,
                 ipv4prefix='10.0.0.0/8',
                 ipv6prefix='a::/64'):
        assert numnodes > 1
        Topology.__init__(self, numnodes)

        if seed is not None:
            random.seed(seed)

        self.net = self.session.addobj(cls=pycore.nodes.WlanNode)

        p4 = ipaddr.IPv4Prefix(ipv4prefix)
        p6 = ipaddr.IPv6Prefix(ipv6prefix)

        for i in xrange(numnodes):
            addrlist = [
                '%s/%s' % (p4.addr(i + 1), 32),
                '%s/%s' % (p6.addr(i + 1), 128)
            ]
            self.n[i].newnetif(self.net, addrlist=addrlist, ifname='eth0')

        # connect nodes with probability linkprob
        for i in xrange(numnodes):
            netif = self.n[i].netif(0)
            for j in xrange(i + 1, numnodes):
                r = random.random()
                if r < linkprob:
                    self.net.link(netif, self.n[j].netif(0))
            if not self.net._linked[netif]:
                # force one link to avoid partitions
                j = i
                while j == i:
                    j = random.randint(0, numnodes - 1)
                self.net.link(netif, self.n[j].netif(0))
Example #4
0
 def __init__(self, specifications):
     Topology.__init__(self, specifications)
Example #5
0
    def __init__(self, m, n,
                 ipv4prefix = '10.0.0.0/30', ipv6prefix = 'a::/126'):
        assert m > 1
        assert n > 0
        Topology.__init__(self, m * n)

        p4 = ipaddr.IPv4Prefix(ipv4prefix)
        p6 = ipaddr.IPv6Prefix(ipv6prefix)

        class NetConfig(object):
            def __init__(self, net, ipv4prefix, ipv6prefix):
                self.net = net
                self.ipv4prefix = ipv4prefix
                self.ipv6prefix = ipv6prefix

        for i in xrange(n):
            for j in xrange(m):
                node = self.n[i * n + j]
                ifindex = 0

                # network above
                if j > 0:
                    above = self.n[i * n + j - 1]
                    netcfg = above.netcfg_below
                    addrlist = ['%s/%s' % (netcfg.ipv4prefix.addr(2),
                                           netcfg.ipv4prefix.prefixlen),
                                '%s/%s' % (netcfg.ipv6prefix.addr(2),
                                           netcfg.ipv6prefix.prefixlen)]
                    node.newnetif(netcfg.net, addrlist = addrlist,
                                  ifname = 'eth%s' % ifindex)
                    ifindex += 1
                    node.netcfg_above = above.netcfg_below

                # network to the left
                if i > 0:
                    left = self.n[(i - 1) * n + j]
                    netcfg = left.netcfg_right
                    addrlist = ['%s/%s' % (netcfg.ipv4prefix.addr(2),
                                           netcfg.ipv4prefix.prefixlen),
                                '%s/%s' % (netcfg.ipv6prefix.addr(2),
                                           netcfg.ipv6prefix.prefixlen)]
                    node.newnetif(netcfg.net, addrlist = addrlist,
                                  ifname = 'eth%s' % ifindex)
                    ifindex += 1
                    node.netcfg_left = left.netcfg_right

                # network to the right
                if i < n - 1:
                    net = self.session.addobj(cls = pycore.nodes.SwitchNode)
                    netcfg = NetConfig(net, p4, p6)
                    p4 += 1
                    p6 += 1
                    addrlist = ['%s/%s' % (netcfg.ipv4prefix.addr(1),
                                           netcfg.ipv4prefix.prefixlen),
                                '%s/%s' % (netcfg.ipv6prefix.addr(1),
                                           netcfg.ipv6prefix.prefixlen)]
                    node.newnetif(netcfg.net, addrlist = addrlist,
                                  ifname = 'eth%s' % ifindex)
                    ifindex += 1
                    node.netcfg_right = netcfg

                # network below
                if j < m - 1:
                    net = self.session.addobj(cls = pycore.nodes.SwitchNode)
                    netcfg = NetConfig(net, p4, p6)
                    p4 += 1
                    p6 += 1
                    addrlist = ['%s/%s' % (netcfg.ipv4prefix.addr(1),
                                           netcfg.ipv4prefix.prefixlen),
                                '%s/%s' % (netcfg.ipv6prefix.addr(1),
                                           netcfg.ipv6prefix.prefixlen)]
                    node.newnetif(netcfg.net, addrlist = addrlist,
                                  ifname = 'eth%s' % ifindex)
                    ifindex += 1
                    node.netcfg_below = netcfg