Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get port configuration from ConfigDB instead of AppDB #157

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/sonic_ax_impl/mibs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,20 @@ def lldp_entry_table(if_name):
return b'LLDP_ENTRY_TABLE:' + if_name


def if_entry_table(if_name):
def if_entry_table_app_db(if_name):
"""
:param if_name: given interface to cast.
:return: PORT_TABLE key.
"""
return b'PORT_TABLE:' + if_name

def if_entry_table_config_db(if_name):
"""
:param if_name: given interface to cast.
:return: PORT key.
"""
return b'PORT|' + if_name


def lag_entry_table(lag_name):
"""
Expand Down Expand Up @@ -270,7 +277,7 @@ def init_sync_d_interface_tables(db_conn):
if_alias_map = dict()

for if_name in if_name_map:
if_entry = db_conn.get_all(APPL_DB, if_entry_table(if_name), blocking=True)
if_entry = db_conn.get_all(CONFIG_DB, if_entry_table_config_db(if_name), blocking=True)
if_alias_map[if_name] = if_entry.get(b'alias', if_name)

logger.debug("Chassis name map:\n" + pprint.pformat(if_alias_map, indent=2))
Expand Down
8 changes: 2 additions & 6 deletions src/sonic_ax_impl/mibs/ieee802_1ab.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,11 @@ def reinit_data(self):

def _get_if_entry(self, if_name):
if_table = ""

# Once PORT_TABLE will be moved to CONFIG DB
# we will get entry from CONFIG_DB for all cases
db = mibs.APPL_DB
db = mibs.CONFIG_DB
if if_name in self.if_name_map:
if_table = mibs.if_entry_table(if_name)
if_table = mibs.if_entry_table_config_db(if_name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we cannot get everything from APP_DB? As you mentioned, "oper_status" is only in APP_DB. Also if there is no config_db entry for MTU, then there is a default 9100 MTU created only in APP_DB table.

elif if_name in self.mgmt_oid_name_map.values():
if_table = mibs.mgmt_if_entry_table(if_name)
db = mibs.CONFIG_DB
else:
return None

Expand Down
28 changes: 26 additions & 2 deletions src/sonic_ax_impl/mibs/ietf/rfc1213.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,8 @@ def _get_if_entry(self, sub_id):
if_table = mibs.mgmt_if_entry_table(self.mgmt_oid_name_map[oid])
db = mibs.CONFIG_DB
elif oid in self.oid_name_map:
if_table = mibs.if_entry_table(self.oid_name_map[oid])
if_table = mibs.if_entry_table_config_db(self.oid_name_map[oid])
db = mibs.CONFIG_DB
else:
return None

Expand All @@ -377,6 +378,26 @@ def _get_if_entry_state_db(self, sub_id):

return Namespace.dbs_get_all(self.db_conn, db, if_table, blocking=False)

def _get_if_entry_app_db(self, sub_id):
"""
:param oid: The 1-based sub-identifier query.
:return: the DB entry for the respective sub_id.
"""
oid = self.get_oid(sub_id)
if not oid:
return

if_table = ""
db = mibs.APPL_DB
if oid in self.oid_name_map:
if_name = self.oid_name_map[oid]
if_table = mibs.if_entry_table_app_db(if_name)
else:
return None

return Namespace.dbs_get_all(self.db_conn, db, if_table, blocking=False)


def _get_status(self, sub_id, key):
"""
:param sub_id: The 1-based sub-identifier query.
Expand All @@ -396,8 +417,11 @@ def _get_status(self, sub_id, key):
# Once PORT_TABLE will be moved to CONFIG DB
# we will get rid of this if-else
# and read oper status from STATE_DB
if self.get_oid(sub_id) in self.mgmt_oid_name_map and key == b"oper_status":
oid = self.get_oid(sub_id)
if oid in self.mgmt_oid_name_map and key == b"oper_status":
entry = self._get_if_entry_state_db(sub_id)
elif oid in self.oid_name_map and key == b"oper_status":
entry = self._get_if_entry_app_db(sub_id)
else:
entry = self._get_if_entry(sub_id)

Expand Down
3 changes: 2 additions & 1 deletion src/sonic_ax_impl/mibs/ietf/rfc2863.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ def _get_if_entry(self, sub_id):
if_table = mibs.mgmt_if_entry_table(self.mgmt_oid_name_map[oid])
db = mibs.CONFIG_DB
elif oid in self.oid_name_map:
if_table = mibs.if_entry_table(self.oid_name_map[oid])
if_table = mibs.if_entry_table_config_db(self.oid_name_map[oid])
db = mibs.CONFIG_DB
else:
return None

Expand Down
6 changes: 4 additions & 2 deletions tests/mock_tables/appl_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -473,12 +473,14 @@
"PORT_TABLE:Ethernet0": {
"description": "snowflake",
"alias": "etp1",
"speed": 100000
"speed": 100000,
"oper_status": "up"
},
"PORT_TABLE:Ethernet4": {
"description": "snowflake",
"alias": "etp2",
"speed": 100000
"speed": 100000,
"oper_status": "down"
},
"PORT_TABLE:Ethernet8": {
"description": "snowflake",
Expand Down
20 changes: 20 additions & 0 deletions tests/mock_tables/asic0/config_db.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,22 @@
{
"PORT|Ethernet0": {
"description": "snowflake",
"alias": "etp1",
"speed": 100000
},
"PORT|Ethernet4": {
"description": "snowflake",
"alias": "etp2",
"speed": 100000
},
"PORT|Ethernet-BP0": {
"description": "snowflake",
"alias": "etp3",
"speed": 100000
},
"PORT|Ethernet-BP4": {
"description": "snowflake",
"alias": "etp4",
"speed": 100000
}
}
2 changes: 1 addition & 1 deletion tests/mock_tables/asic1/appl_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"PORT_TABLE:Ethernet-BP12": {
"description": "snowflake",
"alias": "etp8",
"speed": 1000
"speed": 1000
},
"ROUTE_TABLE:0.0.0.0/0": {
"ifname": "Ethernet8,Ethernet12",
Expand Down
17 changes: 17 additions & 0 deletions tests/mock_tables/asic1/config_db.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@
{
"PORT|Ethernet8": {
"description": "snowflake",
"alias": "etp5",
"speed": 100000
},
"PORT|Ethernet12": {
"speed": 1000,
"alias": "etp6"
},
"PORT|Ethernet-BP8": {
"alias": "etp7"
},
"PORT|Ethernet-BP12": {
"description": "snowflake",
"alias": "etp8",
"speed": 1000
}
}
20 changes: 20 additions & 0 deletions tests/mock_tables/asic2/config_db.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,22 @@
{
"PORT|Ethernet-BP16": {
"description": "backplane",
"alias": "etp9",
"speed": 100000
},
"PORT|Ethernet-BP20": {
"description": "backplane",
"alias": "etp10",
"speed": 100000
},
"PORT|Ethernet-BP24": {
"description": "backplane",
"alias": "etp11",
"speed": 100000
},
"PORT|Ethernet-BP28": {
"description": "backplane",
"alias": "etp12",
"speed": 100000
}
}
160 changes: 160 additions & 0 deletions tests/mock_tables/config_db.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,164 @@
{
"PORT|Ethernet0": {
"description": "snowflake",
"alias": "etp1",
"speed": 100000,
"admin_status": "down"
},
"PORT|Ethernet4": {
"description": "snowflake",
"alias": "etp2",
"speed": 100000,
"admin_status": "up"
},
"PORT|Ethernet8": {
"description": "snowflake",
"alias": "etp3",
"speed": 100000
},
"PORT|Ethernet12": {
"description": "snowflake",
"alias": "etp4",
"speed": 100000
},
"PORT|Ethernet16": {
"description": "snowflake",
"alias": "etp5",
"speed": 100000
},
"PORT|Ethernet20": {
"description": "snowflake",
"alias": "etp6",
"speed": 100000
},
"PORT|Ethernet24": {
"description": "snowflake",
"alias": "etp7",
"speed": 100000
},
"PORT|Ethernet28": {
"description": "snowflake",
"alias": "etp8",
"speed": 100000
},
"PORT|Ethernet32": {
"description": "snowflake",
"alias": "etp9",
"speed": 100000
},
"PORT|Ethernet36": {
"description": "snowflake",
"alias": "etp10",
"speed": 100000
},
"PORT|Ethernet40": {
"description": "snowflake",
"alias": "etp11",
"speed": 100000
},
"PORT|Ethernet44": {
"description": "snowflake",
"alias": "etp12",
"speed": 100000
},
"PORT|Ethernet48": {
"description": "snowflake",
"alias": "etp13",
"speed": 100000
},
"PORT|Ethernet52": {
"description": "snowflake",
"alias": "etp14",
"speed": 100000
},
"PORT|Ethernet56": {
"description": "snowflake",
"alias": "etp15",
"speed": 100000
},
"PORT|Ethernet60": {
"description": "snowflake",
"alias": "etp16",
"speed": 100000
},
"PORT|Ethernet64": {
"description": "snowflake",
"alias": "etp17",
"speed": 100000
},
"PORT|Ethernet68": {
"description": "snowflake",
"alias": "etp18",
"speed": 100000
},
"PORT|Ethernet72": {
"description": "snowflake",
"alias": "etp19",
"speed": 100000
},
"PORT|Ethernet76": {
"description": "snowflake",
"alias": "etp20",
"speed": 100000
},
"PORT|Ethernet80": {
"description": "snowflake",
"alias": "etp21",
"speed": 100000
},
"PORT|Ethernet84": {
"description": "snowflake",
"alias": "etp22",
"speed": 100000
},
"PORT|Ethernet88": {
"description": "snowflake",
"alias": "etp23",
"speed": 100000
},
"PORT|Ethernet92": {
"description": "snowflake",
"alias": "etp24",
"speed": 100000
},
"PORT|Ethernet96": {
"description": "snowflake",
"alias": "etp25",
"speed": 100000
},
"PORT|Ethernet100": {
"description": "snowflake",
"alias": "etp26",
"speed": 100000
},
"PORT|Ethernet104": {
"description": "snowflake",
"alias": "etp27",
"speed": 100000
},
"PORT|Ethernet108": {
"description": "snowflake",
"alias": "etp28",
"speed": 100000
},
"PORT|Ethernet112": {
"description": "snowflake",
"alias": "etp29",
"speed": 100000
},
"PORT|Ethernet116": {
"speed": 1000,
"alias": "etp30"
},
"PORT|Ethernet120": {
"description": "snowflake",
"alias": "et31"
},
"PORT|Ethernet124": {
"description": "snowflake",
"alias": "etp32",
"speed": 100000
},
"MGMT_PORT|eth0": {
"description": "snowflake",
"speed": 1000
Expand Down
Loading