-
Notifications
You must be signed in to change notification settings - Fork 86
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
[port_util] add get_rif_port_map, get_vlan_interface_oid_map #78
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,12 +11,14 @@ | |
in multi-asic platform. | ||
""" | ||
SONIC_ETHERNET_BP_RE_PATTERN = "^Ethernet-BP(\d+)$" | ||
SONIC_VLAN_RE_PATTERN = "^Vlan(\d+)$" | ||
SONIC_PORTCHANNEL_RE_PATTERN = "^PortChannel(\d+)$" | ||
SONIC_MGMT_PORT_RE_PATTERN = "^eth(\d+)$" | ||
|
||
|
||
class BaseIdx: | ||
ethernet_base_idx = 1 | ||
vlan_interface_base_idx = 2000 | ||
ethernet_bp_base_idx = 9000 | ||
portchannel_base_idx = 1000 | ||
mgmt_port_base_idx = 10000 | ||
|
@@ -25,6 +27,7 @@ def get_index(if_name): | |
""" | ||
OIDs are 1-based, interfaces are 0-based, return the 1-based index | ||
Ethernet N = N + 1 | ||
Vlan N = N + 2000 | ||
Ethernet_BP N = N + 9000 | ||
PortChannel N = N + 1000 | ||
eth N = N + 10000 | ||
|
@@ -36,13 +39,15 @@ def get_index_from_str(if_name): | |
""" | ||
OIDs are 1-based, interfaces are 0-based, return the 1-based index | ||
Ethernet N = N + 1 | ||
Vlan N = N + 2000 | ||
Ethernet_BP N = N + 9000 | ||
PortChannel N = N + 1000 | ||
eth N = N + 10000 | ||
""" | ||
patterns = { | ||
SONIC_ETHERNET_RE_PATTERN: BaseIdx.ethernet_base_idx, | ||
SONIC_ETHERNET_BP_RE_PATTERN: BaseIdx.ethernet_bp_base_idx, | ||
SONIC_VLAN_RE_PATTERN: BaseIdx.vlan_interface_base_idx, | ||
SONIC_PORTCHANNEL_RE_PATTERN: BaseIdx.portchannel_base_idx, | ||
SONIC_MGMT_PORT_RE_PATTERN: BaseIdx.mgmt_port_base_idx | ||
} | ||
|
@@ -103,3 +108,44 @@ def get_vlan_id_from_bvid(db, bvid): | |
|
||
return vlan_id | ||
|
||
def get_rif_port_map(db): | ||
""" | ||
Get the RIF port mapping from ASIC DB | ||
""" | ||
db.connect('ASIC_DB') | ||
rif_keys_str = db.keys('ASIC_DB', "ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE:*") | ||
if not rif_keys_str: | ||
return {} | ||
|
||
rif_port_oid_map = {} | ||
for rif_s in rif_keys_str: | ||
rif_id = rif_s.lstrip(b"ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE:oid:0x") | ||
ent = db.get_all('ASIC_DB', rif_s, blocking=True) | ||
if b"SAI_ROUTER_INTERFACE_ATTR_PORT_ID" in ent: | ||
port_id = ent[b"SAI_ROUTER_INTERFACE_ATTR_PORT_ID"].lstrip(b"oid:0x") | ||
rif_port_oid_map[rif_id] = port_id | ||
|
||
return rif_port_oid_map | ||
|
||
def get_vlan_interface_oid_map(db): | ||
""" | ||
Get Vlan Interface names and sai oids | ||
""" | ||
db.connect('COUNTERS_DB') | ||
rif_name_map = db.get_all('COUNTERS_DB', 'COUNTERS_RIF_NAME_MAP', blocking=True) | ||
rif_type_name_map = db.get_all('COUNTERS_DB', 'COUNTERS_RIF_TYPE_MAP', blocking=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also check None? #Closed |
||
|
||
if not rif_name_map or not rif_type_name_map: | ||
return {} | ||
|
||
oid_pfx = len("oid:0x") | ||
vlan_if_name_map = {} | ||
|
||
for if_name, sai_oid in rif_name_map.items(): | ||
# Check if RIF is l3 vlan interface | ||
if rif_type_name_map[sai_oid] == b'SAI_ROUTER_INTERFACE_TYPE_VLAN': | ||
# Check if interface name is in style understood to be a SONiC interface | ||
if get_index(if_name): | ||
vlan_if_name_map[sai_oid[oid_pfx:]] = if_name | ||
|
||
return vlan_if_name_map |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@prsunny @judyjoseph do you think it leaves enough indexes to portchannels in multiple-ASIC case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel 1000 port channel interfaces should be good enough even for Chassis. But I am looking to see why the vlan_interface_base_idx is defined .. is it for this API get_vlan_interface_oid_map() ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this just simply leaves a gap from 6000-9000 after
2000+4094
, why not start from 4000?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2K BaseIdx is what our Arch and Guohan agreed on. If there is any concern about the size of pool, should discuss with them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@judyjoseph
Theoretically index can be used anywhere where a numeric identification for interface is needed.
In my case I am using it for interface ID in the SNMP Interface MIB (RFC1213).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm .. I see that the index range discussion already happened.