|
9 | 9 | from ax_interface.mib import MIBUpdater
|
10 | 10 | from ax_interface.util import oid2tuple
|
11 | 11 | from sonic_ax_impl import logger
|
| 12 | +from ax_interface.util import mac_decimals |
12 | 13 |
|
13 | 14 | COUNTERS_PORT_NAME_MAP = 'COUNTERS_PORT_NAME_MAP'
|
14 | 15 | COUNTERS_QUEUE_NAME_MAP = 'COUNTERS_QUEUE_NAME_MAP'
|
@@ -174,6 +175,14 @@ def mgmt_if_entry_table(if_name):
|
174 | 175 |
|
175 | 176 | return 'MGMT_PORT|' + if_name
|
176 | 177 |
|
| 178 | +def vlan_if_entry_table(vlan): |
| 179 | + """ |
| 180 | + :param if_name: given interface to cast |
| 181 | + :return: VLAN_TABLE key |
| 182 | + """ |
| 183 | + |
| 184 | + return 'VLAN_TABLE:' + vlan |
| 185 | + |
177 | 186 |
|
178 | 187 | def mgmt_if_entry_table_state_db(if_name):
|
179 | 188 | """
|
@@ -255,6 +264,91 @@ def init_mgmt_interface_tables(db_conn):
|
255 | 264 |
|
256 | 265 | return oid_name_map, if_alias_map
|
257 | 266 |
|
| 267 | +def init_vlan_interface_tables(db_conn, mac=""): |
| 268 | + """ |
| 269 | + Initializes interface maps for vlan ports |
| 270 | + :param db_conn: db connector |
| 271 | + :return: tuple of vlan name to oid map and vlan name to alias map |
| 272 | + """ |
| 273 | + |
| 274 | + db_conn.connect(APPL_DB) |
| 275 | + |
| 276 | + vlan_intf_keys = db_conn.keys(APPL_DB, 'INTF_TABLE:Vlan*') |
| 277 | + |
| 278 | + if not vlan_intf_keys: |
| 279 | + logger.debug('No vlan interfaces found.' ) |
| 280 | + return {},{} |
| 281 | + |
| 282 | + oid_name_map = {} |
| 283 | + oid_mac_map = {} |
| 284 | + for key in vlan_intf_keys: |
| 285 | + vlan = key.split(':')[1] |
| 286 | + index = get_index_from_str(vlan) |
| 287 | + oid_name_map[index] = vlan |
| 288 | + #get mac addr of vlan |
| 289 | + ent = db_conn.get_all(APPL_DB, key) |
| 290 | + if ent and 'mac_addr' in ent: |
| 291 | + mactuple = mac_decimals(ent['mac_addr']) |
| 292 | + oid_mac_map[index] = ''.join(chr(b) for b in mactuple) |
| 293 | + else: |
| 294 | + oid_mac_map[index] = mac |
| 295 | + |
| 296 | + logger.debug('vlan interface map:\n' + pprint.pformat(oid_name_map, indent=2)) |
| 297 | + return oid_name_map, oid_mac_map |
| 298 | + |
| 299 | +def init_mclag_interface_tables(db_conn, mac=""): |
| 300 | + """ |
| 301 | + Initializes interface maps for vlan ports |
| 302 | + :param db_conn: db connector |
| 303 | + :return: tuple of vlan name to oid map and vlan name to alias map |
| 304 | + """ |
| 305 | + |
| 306 | + db_conn.connect(STATE_DB) |
| 307 | + |
| 308 | + intf_keys = db_conn.keys(STATE_DB, 'MCLAG_LOCAL_INTF_TABLE|*') |
| 309 | + |
| 310 | + if not intf_keys: |
| 311 | + logger.debug('No vlan interfaces found.' ) |
| 312 | + return {},{} |
| 313 | + |
| 314 | + oid_name_map = {} |
| 315 | + oid_mac_map = {} |
| 316 | + for key in intf_keys: |
| 317 | + name = key.split('|')[1] |
| 318 | + index = get_index_from_str(name) |
| 319 | + oid_name_map[index] = name |
| 320 | + #get mac addr of vlan |
| 321 | + ent = db_conn.get_all(STATE_DB, key) |
| 322 | + if ent and 'interface_mac' in ent: |
| 323 | + mactuple = mac_decimals(ent['interface_mac']) |
| 324 | + oid_mac_map[index] = ''.join(chr(b) for b in mactuple) |
| 325 | + else: |
| 326 | + oid_mac_map[index] = mac |
| 327 | + |
| 328 | + logger.debug('vlan interface map:\n' + pprint.pformat(oid_name_map, indent=2)) |
| 329 | + return oid_name_map, oid_mac_map |
| 330 | + |
| 331 | +def init_loopback_interface_tables(db_conn): |
| 332 | + """ |
| 333 | + Initializes interface maps for loopback ports |
| 334 | + :param db_conn: db connector |
| 335 | + :return: tuple of loopback name to oid map |
| 336 | + """ |
| 337 | + |
| 338 | + db_conn.connect(CONFIG_DB) |
| 339 | + |
| 340 | + lpbk_intf_keys = db_conn.keys(CONFIG_DB, 'LOOPBACK_INTERFACE|*') |
| 341 | + |
| 342 | + if not lpbk_intf_keys: |
| 343 | + logger.debug('No lpbk interfaces found.' ) |
| 344 | + return {} |
| 345 | + |
| 346 | + lpbk_interfaces = [key.split('|')[1] for key in lpbk_intf_keys] |
| 347 | + oid_name_map = {get_index_from_str(lpbk_name): lpbk_name for lpbk_name in lpbk_interfaces} |
| 348 | + logger.debug('lpbk interface map:\n' + pprint.pformat(oid_name_map, indent=2)) |
| 349 | + |
| 350 | + return oid_name_map |
| 351 | + |
258 | 352 | def init_sync_d_interface_tables(db_conn):
|
259 | 353 | """
|
260 | 354 | Initializes interface maps for SyncD-connected MIB(s).
|
@@ -433,6 +527,8 @@ def init_sync_d_queue_tables(db_conn):
|
433 | 527 | port_name, queue_index = queue_name.split(':')
|
434 | 528 | queue_index = ''.join(i for i in queue_index if i.isdigit())
|
435 | 529 | port_index = get_index_from_str(port_name)
|
| 530 | + if port_index is None: |
| 531 | + continue |
436 | 532 | key = queue_key(port_index, queue_index)
|
437 | 533 | port_queues_map[key] = sai_id
|
438 | 534 |
|
@@ -462,6 +558,29 @@ def init_sync_d_queue_tables(db_conn):
|
462 | 558 |
|
463 | 559 | return port_queues_map, queue_stat_map, port_queue_list_map
|
464 | 560 |
|
| 561 | +def get_config_device_metadata(db_conn): |
| 562 | + """ |
| 563 | + :param db_conn: Sonic DB connector |
| 564 | + :return: device metadata |
| 565 | + """ |
| 566 | + |
| 567 | + DEVICE_METADATA = "DEVICE_METADATA|localhost" |
| 568 | + db_conn.connect(db_conn.CONFIG_DB) |
| 569 | + |
| 570 | + device_metadata = db_conn.get_all(db_conn.CONFIG_DB, DEVICE_METADATA) |
| 571 | + return device_metadata |
| 572 | + |
| 573 | +def get_interface_naming_mode(db_conn): |
| 574 | + """ |
| 575 | + :param db_conn: Sonic DB connector |
| 576 | + :return: device metadata |
| 577 | + """ |
| 578 | + |
| 579 | + device_metadata = get_config_device_metadata(db_conn) |
| 580 | + if device_metadata and 'intf_naming_mode' in device_metadata: |
| 581 | + return device_metadata['intf_naming_mode'] |
| 582 | + return None |
| 583 | + |
465 | 584 | def get_device_metadata(db_conn):
|
466 | 585 | """
|
467 | 586 | :param db_conn: Sonic DB connector
|
|
0 commit comments