Exemplo n.º 1
0
    def update_data(self):
        """
        Update redis (caches config)
        Pulls the table references for each interface.
        """
        self.vlanmac_ifindex_map = {}
        self.vlanmac_ifindex_list = []

        fdb_strings = Namespace.dbs_keys(self.db_conn, mibs.ASIC_DB, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY:*")
        if not fdb_strings:
            return

        for s in fdb_strings:
            fdb_str = s.decode()
            try:
                fdb = json.loads(fdb_str.split(":", maxsplit=2)[-1])
            except ValueError as e:  # includes simplejson.decoder.JSONDecodeError
                mibs.logger.error("SyncD 'ASIC_DB' includes invalid FDB_ENTRY '{}': {}.".format(fdb_str, e))
                break

            ent = Namespace.dbs_get_all(self.db_conn, mibs.ASIC_DB, s, blocking=True)
            # Example output: oid:0x3a000000000608
            bridge_port_id = ent[b"SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID"][6:]
            if bridge_port_id not in self.if_bpid_map:
                continue
            port_id = self.if_bpid_map[bridge_port_id]

            vlanmac = self.fdb_vlanmac(fdb)
            self.vlanmac_ifindex_map[vlanmac] = mibs.get_index(self.if_id_map[port_id])
            self.vlanmac_ifindex_list.append(vlanmac)
        self.vlanmac_ifindex_list.sort()
Exemplo n.º 2
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()
Exemplo n.º 3
0
    def reinit_data(self):
        self.entity_to_oid_map.clear()
        # retrieve the initial list of entity in db
        key_info = Namespace.dbs_keys(self.mib_updater.statedb, mibs.STATE_DB,
                                      self.get_key_pattern())
        if key_info:
            keys = [entry for entry in key_info]
        else:
            keys = []

        # update cache with initial data
        for key in keys:
            # extract entity name
            name = key.split(mibs.TABLE_NAME_SEPARATOR_VBAR)[-1]
            self._update_entity_cache(name)
Exemplo n.º 4
0
    def reinit_data(self):
        """
        Reinit data, clear cache
        """

        # clear cache
        self.ent_phy_sensor_type_map = {}
        self.ent_phy_sensor_scale_map = {}
        self.ent_phy_sensor_precision_map = {}
        self.ent_phy_sensor_value_map = {}
        self.ent_phy_sensor_oper_state_map = {}

        transceiver_dom_encoded = Namespace.dbs_keys(
            self.statedb, mibs.STATE_DB, self.TRANSCEIVER_DOM_KEY_PATTERN)
        if transceiver_dom_encoded:
            self.transceiver_dom = [entry for entry in transceiver_dom_encoded]
Exemplo n.º 5
0
    def reinit_data(self):
        """
        Re-initialize all data.
        """

        # reinit cache
        self.physical_classes_map = {}
        self.physical_description_map = {}
        self.physical_hw_version_map = {}
        self.physical_serial_number_map = {}
        self.physical_mfg_name_map = {}
        self.physical_model_name_map = {}

        # update interface maps
        _, self.if_alias_map, _, _ = \
            Namespace.get_sync_d_from_all_namespace(mibs.init_sync_d_interface_tables, Namespace.init_namespace_dbs())

        device_metadata = mibs.get_device_metadata(self.statedb[0])
        chassis_sub_id = (self.CHASSIS_ID, )
        self.physical_entities = [chassis_sub_id]

        if not device_metadata or not device_metadata.get(
                b"chassis_serial_number"):
            chassis_serial_number = ""
        else:
            chassis_serial_number = device_metadata[b"chassis_serial_number"]

        self.physical_classes_map[chassis_sub_id] = PhysicalClass.CHASSIS
        self.physical_serial_number_map[chassis_sub_id] = chassis_serial_number

        # retrieve the initial list of transceivers that are present in the system
        transceiver_info = Namespace.dbs_keys(self.statedb, mibs.STATE_DB,
                                              self.TRANSCEIVER_KEY_PATTERN)
        if transceiver_info:
            self.transceiver_entries = [entry.decode() \
                for entry in transceiver_info]
        else:
            self.transceiver_entries = []

        # update cache with initial data
        for transceiver_entry in self.transceiver_entries:
            # extract interface name
            interface = transceiver_entry.split(
                mibs.TABLE_NAME_SEPARATOR_VBAR)[-1]
            self._update_transceiver_cache(interface)
Exemplo n.º 6
0
    def reinit_data(self):
        """
        Subclass update loopback information
        """
        self.loips = {}

        loopbacks = Namespace.dbs_keys(self.db_conn, mibs.APPL_DB, "INTF_TABLE:lo:*")
        if not loopbacks:
            return

        ## Collect only ipv4 lo interfaces
        for loopback in loopbacks:
            lostr = loopback
            loipmask = lostr[len("INTF_TABLE:lo:"):]
            loip = loipmask.split('/')[0]
            ipa = ipaddress.ip_address(loip)
            if isinstance(ipa, ipaddress.IPv4Address):
                self.loips[loip] = ipa
Exemplo n.º 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

        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()
                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()
Exemplo n.º 8
0
    def reinit_data(self):
        """
        Reinit data, clear cache
        """

        # clear cache
        self.ent_phy_sensor_type_map = {}
        self.ent_phy_sensor_scale_map = {}
        self.ent_phy_sensor_precision_map = {}
        self.ent_phy_sensor_value_map = {}
        self.ent_phy_sensor_oper_state_map = {}

        transceiver_dom_encoded = Namespace.dbs_keys(
            self.statedb, mibs.STATE_DB, self.TRANSCEIVER_DOM_KEY_PATTERN)
        if transceiver_dom_encoded:
            self.transceiver_dom = [entry for entry in transceiver_dom_encoded]

        # for FAN, PSU and thermal sensors, they are in host namespace DB, to avoid iterating all namespace DBs,
        # just get data from host namespace DB, which is self.statedb[0].
        fan_sensor_encoded = self.statedb[HOST_NAMESPACE_DB_IDX].keys(
            self.statedb[HOST_NAMESPACE_DB_IDX].STATE_DB,
            self.FAN_SENSOR_KEY_PATTERN)
        if fan_sensor_encoded:
            self.fan_sensor = [entry for entry in fan_sensor_encoded]

        psu_sensor_encoded = self.statedb[HOST_NAMESPACE_DB_IDX].keys(
            self.statedb[HOST_NAMESPACE_DB_IDX].STATE_DB,
            self.PSU_SENSOR_KEY_PATTERN)
        if psu_sensor_encoded:
            self.psu_sensor = [entry for entry in psu_sensor_encoded]

        thermal_sensor_encoded = self.statedb[HOST_NAMESPACE_DB_IDX].keys(
            self.statedb[HOST_NAMESPACE_DB_IDX].STATE_DB,
            self.THERMAL_SENSOR_KEY_PATTERN)
        if thermal_sensor_encoded:
            self.thermal_sensor = [entry for entry in thermal_sensor_encoded]