11
11
in multi-asic platform.
12
12
"""
13
13
SONIC_ETHERNET_BP_RE_PATTERN = "^Ethernet-BP(\d+)$"
14
+ SONIC_VLAN_RE_PATTERN = "^Vlan(\d+)$"
14
15
SONIC_PORTCHANNEL_RE_PATTERN = "^PortChannel(\d+)$"
15
16
SONIC_MGMT_PORT_RE_PATTERN = "^eth(\d+)$"
16
17
17
18
18
19
class BaseIdx :
19
20
ethernet_base_idx = 1
21
+ vlan_interface_base_idx = 2000
20
22
ethernet_bp_base_idx = 9000
21
23
portchannel_base_idx = 1000
22
24
mgmt_port_base_idx = 10000
@@ -25,6 +27,7 @@ def get_index(if_name):
25
27
"""
26
28
OIDs are 1-based, interfaces are 0-based, return the 1-based index
27
29
Ethernet N = N + 1
30
+ Vlan N = N + 2000
28
31
Ethernet_BP N = N + 9000
29
32
PortChannel N = N + 1000
30
33
eth N = N + 10000
@@ -36,13 +39,15 @@ def get_index_from_str(if_name):
36
39
"""
37
40
OIDs are 1-based, interfaces are 0-based, return the 1-based index
38
41
Ethernet N = N + 1
42
+ Vlan N = N + 2000
39
43
Ethernet_BP N = N + 9000
40
44
PortChannel N = N + 1000
41
45
eth N = N + 10000
42
46
"""
43
47
patterns = {
44
48
SONIC_ETHERNET_RE_PATTERN : BaseIdx .ethernet_base_idx ,
45
49
SONIC_ETHERNET_BP_RE_PATTERN : BaseIdx .ethernet_bp_base_idx ,
50
+ SONIC_VLAN_RE_PATTERN : BaseIdx .vlan_interface_base_idx ,
46
51
SONIC_PORTCHANNEL_RE_PATTERN : BaseIdx .portchannel_base_idx ,
47
52
SONIC_MGMT_PORT_RE_PATTERN : BaseIdx .mgmt_port_base_idx
48
53
}
@@ -103,3 +108,44 @@ def get_vlan_id_from_bvid(db, bvid):
103
108
104
109
return vlan_id
105
110
111
+ def get_rif_port_map (db ):
112
+ """
113
+ Get the RIF port mapping from ASIC DB
114
+ """
115
+ db .connect ('ASIC_DB' )
116
+ rif_keys_str = db .keys ('ASIC_DB' , "ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE:*" )
117
+ if not rif_keys_str :
118
+ return {}
119
+
120
+ rif_port_oid_map = {}
121
+ for rif_s in rif_keys_str :
122
+ rif_id = rif_s .lstrip (b"ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE:oid:0x" )
123
+ ent = db .get_all ('ASIC_DB' , rif_s , blocking = True )
124
+ if b"SAI_ROUTER_INTERFACE_ATTR_PORT_ID" in ent :
125
+ port_id = ent [b"SAI_ROUTER_INTERFACE_ATTR_PORT_ID" ].lstrip (b"oid:0x" )
126
+ rif_port_oid_map [rif_id ] = port_id
127
+
128
+ return rif_port_oid_map
129
+
130
+ def get_vlan_interface_oid_map (db ):
131
+ """
132
+ Get Vlan Interface names and sai oids
133
+ """
134
+ db .connect ('COUNTERS_DB' )
135
+ rif_name_map = db .get_all ('COUNTERS_DB' , 'COUNTERS_RIF_NAME_MAP' , blocking = True )
136
+ rif_type_name_map = db .get_all ('COUNTERS_DB' , 'COUNTERS_RIF_TYPE_MAP' , blocking = True )
137
+
138
+ if not rif_name_map or not rif_type_name_map :
139
+ return {}
140
+
141
+ oid_pfx = len ("oid:0x" )
142
+ vlan_if_name_map = {}
143
+
144
+ for if_name , sai_oid in rif_name_map .items ():
145
+ # Check if RIF is l3 vlan interface
146
+ if rif_type_name_map [sai_oid ] == b'SAI_ROUTER_INTERFACE_TYPE_VLAN' :
147
+ # Check if interface name is in style understood to be a SONiC interface
148
+ if get_index (if_name ):
149
+ vlan_if_name_map [sai_oid [oid_pfx :]] = if_name
150
+
151
+ return vlan_if_name_map
0 commit comments