Esempio n. 1
0
File: main.py Progetto: presto53/bcc
    def start(self):
        # each entry is tuple of ns_ipdb, out_ifc, in_ifc
        host_info = []
        for i in range(0, num_hosts):
            print("Launching host %i of %i" % (i + 1, num_hosts))
            ipaddr = "172.16.1.%d/24" % (100 + i)
            host_info.append(
                self._create_ns("host%d" % i, ipaddr=ipaddr,
                                disable_ipv6=True))
            if multicast:
                cmd = ["python", "tunnel.py", str(i)]
            else:
                cmd = [
                    "python", "tunnel_mesh.py",
                    str(num_hosts),
                    str(i),
                    str(dhcp)
                ]
            p = NSPopen(host_info[i][0].nl.netns, cmd, stdin=PIPE)
            self.processes.append(p)
        with self.ipdb.create(ifname="br-fabric", kind="bridge") as br:
            for host in host_info:
                br.add_port(host[1])
            br.up()

        # get host0 bridge ip's
        host0_br_ips = []
        if dhcp == 1:
            print("Waiting for host0 br1/br2 ip addresses available")
            for j in range(0, 2):
                retry = -1
                ip_out = None
                while retry < 0:
                    check = Popen([
                        "ip", "netns", "exec", "host0", "ip", "addr", "show",
                        "br%d" % j
                    ],
                                  stdout=PIPE,
                                  stderr=PIPE)
                    ip_out = check.stdout.read()
                    checkip = "99.1.%d" % j
                    retry = ip_out.find(checkip)
                p = re.compile(("99.1.%d." % j) + "\d+")
                host0_br_ips.append(p.findall(ip_out)[0])
        else:
            host0_br_ips.append("99.1.0.1")
            host0_br_ips.append("99.1.1.1")

        # traffic test
        print("Validating connectivity")
        for i in range(1, num_hosts):
            for j in range(0, 2):
                retry = -1
                while retry < 0:
                    check = Popen([
                        "ip", "netns", "exec",
                        "host%d" % i, "ip", "addr", "show",
                        "br%d" % j
                    ],
                                  stdout=PIPE,
                                  stderr=PIPE)
                    out = check.stdout.read()
                    checkip = "99.1.%d" % j
                    retry = out.find(checkip)
                print("VNI%d between host0 and host%d" % (10000 + j, i))
                call([
                    "ip", "netns", "exec",
                    "host%d" % i, "ping", host0_br_ips[j], "-c", "3", "-i",
                    "0.2", "-q"
                ])