Beispiel #1
0
    def update_data(self):
        """
        Update redis (caches config)
        Pulls the table references for each interface.
        """
        self.route_dest_map = {}
        self.route_dest_list = []

        self.db_conn.connect(mibs.APPL_DB)
        route_entries = self.db_conn.keys(mibs.APPL_DB, "ROUTE_TABLE:*")
        if not route_entries:
            return

        for route_entry in route_entries:
            routestr = route_entry.decode()
            ipnstr = routestr[len("ROUTE_TABLE:"):]
            if ipnstr == "0.0.0.0/0":
                ipn = ipaddress.ip_network(ipnstr)
                ent = self.db_conn.get_all(mibs.APPL_DB,
                                           routestr,
                                           blocking=True)
                nexthops = ent[b"nexthop"].decode()
                ifnames = ent[b"ifname"].decode()
                for nh, ifn in zip(nexthops.split(','), ifnames.split(',')):
                    ## Ignore non front panel interfaces
                    ## TODO: non front panel interfaces should not be in APPL_DB at very beginning
                    ## This is to workaround the bug in current sonic-swss implementation
                    if ifn == "eth0" or ifn == "lo" or ifn == "docker0":
                        continue
                    sub_id = ip2tuple_v4(ipn.network_address) + ip2tuple_v4(
                        ipn.netmask) + (self.tos, ) + ip2tuple_v4(nh)
                    self.route_dest_list.append(sub_id)
                    self.route_dest_map[sub_id] = ipn.network_address.packed

        self.route_dest_list.sort()
Beispiel #2
0
    def update_data(self):
        """
        Update redis (caches config)
        Pulls the table references for each interface.
        """
        self.route_dest_map = {}
        self.route_dest_list = []

        self.db_conn.connect(mibs.APPL_DB)
        route_entries = self.db_conn.keys(mibs.APPL_DB, "ROUTE_TABLE:*")

        for route_entry in route_entries:
            routestr = route_entry.decode()
            ipnstr = routestr[len("ROUTE_TABLE:"):]
            if ipnstr == "0.0.0.0/0":
                ipn = ipaddress.ip_network(ipnstr)
                ent = self.db_conn.get_all(mibs.APPL_DB,
                                           routestr,
                                           blocking=True)
                nexthops = ent[b"nexthop"].decode()
                for nh in nexthops.split(','):
                    sub_id = ip2tuple_v4(ipn.network_address) + ip2tuple_v4(
                        ipn.netmask) + (self.tos, ) + ip2tuple_v4(nh)
                    self.route_dest_list.append(sub_id)
                    self.route_dest_map[sub_id] = ipn.network_address.packed

        self.route_dest_list.sort()
    def update_data(self):
        """
        Update redis (caches config)
        Pulls the table references for each interface.
        """
        self.route_dest_map = {}
        self.route_dest_list = []

        ## The nexthop for loopbacks should be all zero
        for loip in self.loips:
            sub_id = ip2tuple_v4(loip) + (255, 255, 255,
                                          255) + (self.tos, ) + (0, 0, 0, 0)
            self.route_dest_list.append(sub_id)
            self.route_dest_map[sub_id] = self.loips[loip].packed

        # Get list of front end asic namespaces for multi-asic platform.
        # This list will be empty for single asic platform.
        front_ns = multi_asic.get_all_namespaces()['front_ns']
        ipnstr = "0.0.0.0/0"
        ipn = ipaddress.ip_network(ipnstr)
        route_str = "ROUTE_TABLE:0.0.0.0/0"

        for db_conn in Namespace.get_non_host_dbs(self.db_conn):
            # For multi-asic platform, proceed to get routes only for
            # front end namespaces.
            # For single-asic platform, front_ns will be empty list.
            if front_ns and db_conn.namespace not in front_ns:
                continue
            port_table = multi_asic.get_port_table_for_asic(db_conn.namespace)
            ent = db_conn.get_all(mibs.APPL_DB, route_str, blocking=False)
            if ent is None:
                continue
            nexthops = ent["nexthop"]
            ifnames = ent["ifname"]
            for nh, ifn in zip(nexthops.split(','), ifnames.split(',')):
                ## Ignore non front panel interfaces
                ## TODO: non front panel interfaces should not be in APPL_DB at very beginning
                ## This is to workaround the bug in current sonic-swss implementation
                if ifn == "eth0" or ifn == "lo" or ifn == "docker0":
                    continue

                # Ignore internal asic routes
                if multi_asic.is_port_channel_internal(ifn, db_conn.namespace):
                    continue
                if (ifn in port_table
                        and multi_asic.PORT_ROLE in port_table[ifn]
                        and port_table[ifn][multi_asic.PORT_ROLE]
                        == multi_asic.INTERNAL_PORT):
                    continue

                sub_id = ip2tuple_v4(ipn.network_address) + ip2tuple_v4(
                    ipn.netmask) + (self.tos, ) + ip2tuple_v4(nh)
                self.route_dest_list.append(sub_id)
                self.route_dest_map[sub_id] = ipn.network_address.packed

        self.route_dest_list.sort()
Beispiel #4
0
    def update_data(self):
        """
        Update redis (caches config)
        Pulls the table references for each interface.
        """
        self.nexthop_map = {}
        self.route_list = []

        route_entries = Namespace.dbs_keys(self.db_conn, mibs.APPL_DB, "ROUTE_TABLE:*")
        if not route_entries:
            return

        for route_entry in route_entries:
            routestr = route_entry.decode()
            ipnstr = routestr[len("ROUTE_TABLE:"):]
            if ipnstr == "0.0.0.0/0":
                ipn = ipaddress.ip_network(ipnstr)
                ent = Namespace.dbs_get_all(self.db_conn, mibs.APPL_DB, routestr, blocking=True)
                nexthops = ent[b"nexthop"].decode()
                for nh in nexthops.split(','):
                    # TODO: if ipn contains IP range, create more sub_id here
                    sub_id = ip2tuple_v4(ipn.network_address)
                    self.route_list.append(sub_id)
                    self.nexthop_map[sub_id] = ipaddress.ip_address(nh).packed
                    break # Just need the first nexthop

        self.route_list.sort()
Beispiel #5
0
    def update_data(self):
        """
        Update redis (caches config)
        Pulls the table references for each interface.
        """
        self.nexthop_map = {}
        self.route_list = []

        self.db_conn.connect(mibs.APPL_DB)
        route_entries = self.db_conn.keys(mibs.APPL_DB, "ROUTE_TABLE:*")
        if not route_entries:
            return

        for route_entry in route_entries:
            routestr = route_entry.decode()
            ipnstr = routestr[len("ROUTE_TABLE:"):]
            if ipnstr == "0.0.0.0/0":
                ipn = ipaddress.ip_network(ipnstr)
                ent = self.db_conn.get_all(mibs.APPL_DB, routestr, blocking=True)
                nexthops = ent[b"nexthop"].decode()
                for nh in nexthops.split(','):
                    # TODO: if ipn contains IP range, create more sub_id here
                    sub_id = ip2tuple_v4(ipn.network_address)
                    self.route_list.append(sub_id)
                    self.nexthop_map[sub_id] = ipaddress.ip_address(nh).packed
                    break # Just need the first nexthop

        self.route_list.sort()
    def _update_arp_info(self, dev, mac, ip):
        if_index = mibs.get_index_from_str(dev)
        if if_index is None: return

        mactuple = mac_decimals(mac)
        machex = ''.join(chr(b) for b in mactuple)
        # if MAC is all zero
        #if not any(mac): continue

        iptuple = ip2tuple_v4(ip)

        subid = (if_index, ) + iptuple
        self.arp_dest_map[subid] = machex
        self.arp_dest_list.append(subid)
Beispiel #7
0
    def update_data(self):
        """
        Update redis (caches config)
        Pulls the table references for each interface.
        """
        self.route_dest_map = {}
        self.route_dest_list = []

        ## The nexthop for loopbacks should be all zero
        for loip in self.loips:
            sub_id = ip2tuple_v4(loip) + (255, 255, 255, 255) + (self.tos,) + (0, 0, 0, 0)
            self.route_dest_list.append(sub_id)
            self.route_dest_map[sub_id] = self.loips[loip].packed

        self.db_conn.connect(mibs.APPL_DB)
        route_entries = self.db_conn.keys(mibs.APPL_DB, "ROUTE_TABLE:*")
        if not route_entries:
            return

        for route_entry in route_entries:
            routestr = route_entry.decode()
            ipnstr = routestr[len("ROUTE_TABLE:"):]
            if ipnstr == "0.0.0.0/0":
                ipn = ipaddress.ip_network(ipnstr)
                ent = self.db_conn.get_all(mibs.APPL_DB, routestr, blocking=True)
                nexthops = ent[b"nexthop"].decode()
                ifnames = ent[b"ifname"].decode()
                for nh, ifn in zip(nexthops.split(','), ifnames.split(',')):
                    ## Ignore non front panel interfaces
                    ## TODO: non front panel interfaces should not be in APPL_DB at very beginning
                    ## This is to workaround the bug in current sonic-swss implementation
                    if ifn == "eth0" or ifn == "lo" or ifn == "docker0": continue
                    sub_id = ip2tuple_v4(ipn.network_address) + ip2tuple_v4(ipn.netmask) + (self.tos,) + ip2tuple_v4(nh)
                    self.route_dest_list.append(sub_id)
                    self.route_dest_map[sub_id] = ipn.network_address.packed

        self.route_dest_list.sort()
Beispiel #8
0
    def update_data(self):
        self.arp_dest_map = {}
        self.arp_dest_list = []
        for entry in python_arptable.get_arp_table():
            dev = entry['Device']
            mac = entry['HW address']
            ip = entry['IP address']

            if_index = mibs.get_index_from_str(dev)
            if if_index is None: continue

            mactuple = mac_decimals(mac)
            machex = ''.join(chr(b) for b in mactuple)
            # if MAC is all zero
            #if not any(mac): continue

            iptuple = ip2tuple_v4(ip)

            subid = (if_index, ) + iptuple
            self.arp_dest_map[subid] = machex
            self.arp_dest_list.append(subid)
        self.arp_dest_list.sort()
Beispiel #9
0
    def update_data(self):
        self.arp_dest_map = {}
        self.arp_dest_list = []
        for entry in python_arptable.get_arp_table():
            dev = entry['Device']
            mac = entry['HW address']
            ip = entry['IP address']

            if_index = mibs.get_index_from_str(dev)
            if if_index is None: continue

            mactuple = mac_decimals(mac)
            machex = ''.join(chr(b) for b in mactuple)
            # if MAC is all zero
            #if not any(mac): continue

            iptuple = ip2tuple_v4(ip)

            subid = (if_index,) + iptuple
            self.arp_dest_map[subid] = machex
            self.arp_dest_list.append(subid)
        self.arp_dest_list.sort()