Exemple #1
0
    def build_birt(switch=None, domain=None):
        """
        Build bit index routing table
        :param switch: switch for which the birt should be calculated
        :param domain: domain for which the birt should be build
        :return: birt in format {bfr-id: [dest prefix, nbr prefix]
        """
        # {bfr-id: [dest prefix, nbr prefix]
        birt = {}
        for destination in TopologyManager.get_topology(domain).get_nodes():
            if destination != switch:
                destination_device = TopologyManager.get_device(destination)

                if destination_device.get_type(
                ) == "Host":  # dont calculate entry for host
                    continue

                try:
                    next_hop = TopologyManager.get_next_hop(
                        switch, destination, domain)
                    birt[destination_device.get_bfr_id(domain)] = [
                        destination_device.get_ip(),
                        next_hop.get_ip()
                    ]
                except NextHopNotFound:  # maybe a path towards the destination is not yet learned
                    continue

        return birt
Exemple #2
0
    def update_ipv4_entries(self, switch=None):
        """
        Update ipv4 entries based on shortest path on switch
        :param switch: switch where ipv4 entries will be installed
        :return:
        """

        paths = TopologyManager.get_paths(domain_id=0)
        valid_entries = []

        cur_dev = TopologyManager.get_device(switch)

        for dst in [d for d in paths.get(switch, {})
                    if d != switch]:  # don't check path from i->i
            # get the next_hop towards the destination along the shortest path
            dst_dev = TopologyManager.get_device(dst)
            next_hop = TopologyManager.get_next_hop(start_node=switch,
                                                    destination_node=dst,
                                                    domain_id=0)

            port = cur_dev.get_device_to_port(next_hop.get_name())

            entry = TableEntry(
                switch=switch,
                match_fields={
                    "hdr.ipv4.dstAddr": (str(dst_dev.get_ip()), 32),
                    "meta.ports.status":
                    (BierComputation.id_to_bitstring(id=int(port)),
                     BierComputation.id_to_bitstring(id=int(port)))
                },
                action_name="ingress.ipv4_c.forward",
                action_params={"port": int(port)},
                priority=1)

            if TableEntryManager.handle_table_entry(
                    manager=self.table_manager,
                    table_name="ingress.ipv4_c.ipv4",
                    table_entry=entry):
                Log.async_debug("Installed IPv4 forwarding rule for", switch,
                                "->", dst)

            valid_entries.append(entry.match_fields)

        # Add decap entry
        entry = TableEntry(
            switch=cur_dev.get_name(),
            match_fields={"hdr.ipv4.dstAddr": (str(cur_dev.get_ip()), 32)},
            action_name="ingress.ipv4_c.decap",
            priority=1)

        if TableEntryManager.handle_table_entry(
                manager=self.table_manager,
                table_name="ingress.ipv4_c.ipv4",
                table_entry=entry):
            Log.async_debug("Installed IPv4 decap rule for", switch)

        valid_entries.append(entry.match_fields)

        return valid_entries
Exemple #3
0
    def build_bift(switch=None, domain=0):
        """
        Generates the bit index forwarding table
        :param switch: Switch for which the table should be calculated
        :param domain: Domain for which the bift should be build
        :return: bift {bfr-id: [fbm, nextHop]
        """
        birt = BierComputation.build_birt(switch=switch, domain=domain)

        # {bfr-id: [fbm, nextHop]
        bift = {}

        for dest in birt:
            fbm = BierComputation.get_fbm(birt=birt,
                                          next_hop_prefix=birt.get(dest)[1])
            destination = TopologyManager.get_device_by_domain_and_id(
                domain, dest)

            next_hop = TopologyManager.get_next_hop(switch, destination,
                                                    domain)

            bift[dest] = [fbm, next_hop.get_name()]
        return bift