Skip to content

Commit

Permalink
[rfc4363]: Update FDB logics per change of the SAI (sonic-net#37)
Browse files Browse the repository at this point in the history
In SAI 1.0, the FDB entry no longer contains the port ID. Instead,
it contains the bridge port ID which then corelates to the port ID.

Signed-off-by: Shu0T1an ChenG <shuche@microsoft.com>
  • Loading branch information
Shuotian Cheng authored Sep 21, 2017
1 parent 186a4f6 commit 45e4e78
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 46 deletions.
37 changes: 22 additions & 15 deletions src/sonic_ax_impl/mibs/ietf/rfc4363.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,23 @@ def reinit_data(self):
self.prev_if_id_map = self.if_id_map
self.invalid_port_oids = set()

## Note: get the bridge port ID to port ID mapping
## In FDB entry, the bridge port ID is available which is one-to-one mapping with port ID
## TODO: LAG in VLAN is to be supported
self.if_bpid_map = {}
self.db_conn.connect(mibs.ASIC_DB)
bridge_port_strings = self.db_conn.keys(mibs.ASIC_DB, "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT:*")

if not bridge_port_strings:
return

for s in bridge_port_strings:
# Example output: ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT:oid:0x3a000000000616
bridge_port_id = s[45:]
ent = self.db_conn.get_all(mibs.ASIC_DB, s, blocking=True)
port_id = ent[b"SAI_BRIDGE_PORT_ATTR_PORT_ID"][6:]
self.if_bpid_map[bridge_port_id] = port_id

def update_data(self):
"""
Update redis (caches config)
Expand All @@ -56,22 +73,12 @@ def update_data(self):
break

ent = self.db_conn.get_all(mibs.ASIC_DB, s, blocking=True)
port_oid = ent[b"SAI_FDB_ENTRY_ATTR_PORT_ID"]
if port_oid.startswith(b"oid:0x"):
port_oid = port_oid[6:]

## Note: broadcom SAI 0.94 behavior
## Some FDB_ENTRY's port_oid starts with 0x2 is LAG. The whole FDB_ENTRY is not expected,
## and should be ignored here
## TODO: revisit logic here for LAG in VLAN
if port_oid not in self.if_id_map:
## Reduce the logger amount by remember it in a set
if port_oid not in self.invalid_port_oids:
self.invalid_port_oids.add(port_oid)
mibs.logger.info("SyncD 'ASIC_DB' includes a FDB_ENTRY '{}' with an invalid interface id '{}'.".format(fdb_str, port_oid))
continue
# Example output: oid:0x3a000000000608
bridge_port_id = ent[b"SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID"][6:]
port_id = self.if_bpid_map[bridge_port_id]

vlanmac = fdb_vlanmac(fdb)
self.vlanmac_ifindex_map[vlanmac] = mibs.get_index(self.if_id_map[port_oid])
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()

Expand Down
38 changes: 12 additions & 26 deletions tests/mock_tables/asic_db.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,20 @@
{
"ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY:{\"mac\":\"52:54:00:DE:B3:91\",\"vlan\":\"4092\"}": {
"SAI_FDB_ENTRY_ATTR_PORT_ID": "oid:0x100000000001b",
"ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY:{\"bridge_id\":\"oid:0x0\",\"bridge_type\":\"SAI_FDB_ENTRY_BRIDGE_TYPE_1Q\",\"mac\":\"7C:FE:90:80:9F:04\",\"switch_id\":\"oid:0x21000000000000\",\"vlan\":\"1000\"}": {
"SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID": "oid:0x3a000000000616",
"SAI_FDB_ENTRY_ATTR_TYPE": "SAI_FDB_ENTRY_TYPE_DYNAMIC"
},
"ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY:{\"mac\":\"52:54:00:93:A5:61\",\"vlan\":\"1\"}": {
"SAI_FDB_ENTRY_ATTR_PORT_ID": "oid:0x100000000001b",
"ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY:{\"bridge_id\":\"oid:0x0\",\"bridge_type\":\"SAI_FDB_ENTRY_BRIDGE_TYPE_1Q\",\"mac\":\"7C:FE:90:80:9F:06\",\"switch_id\":\"oid:0x21000000000000\",\"vlan\":\"1000\"}": {
"SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID": "oid:0x3a000000000608",
"SAI_FDB_ENTRY_ATTR_TYPE": "SAI_FDB_ENTRY_TYPE_DYNAMIC"
},
"ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY:{\"mac\":\"52:54:00:9E:94:6F\",\"vlan\":\"4091\"}": {
"SAI_FDB_ENTRY_ATTR_PORT_ID": "oid:0x1000000000005",
"SAI_FDB_ENTRY_ATTR_TYPE": "SAI_FDB_ENTRY_TYPE_DYNAMIC"
},
"ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY:{\"mac\":\"52:54:00:81:6D:86\",\"vlan\":\"4093\"}": {
"SAI_FDB_ENTRY_ATTR_PORT_ID": "oid:0x100000000000b",
"SAI_FDB_ENTRY_ATTR_TYPE": "SAI_FDB_ENTRY_TYPE_DYNAMIC"
},
"ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY:{\"mac\":\"7C:FE:90:80:9F:5C\",\"vlan\":\"1000\"}": {
"SAI_FDB_ENTRY_ATTR_PORT_ID": "oid:0x100000000001b",
"SAI_FDB_ENTRY_ATTR_TYPE": "SAI_FDB_ENTRY_TYPE_DYNAMIC"
"ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT:oid:0x3a000000000616": {
"SAI_BRIDGE_PORT_ATTR_TYPE": "SAI_BRIDGE_PORT_TYPE_PORT",
"SAI_BRIDGE_PORT_ATTR_PORT_ID": "oid:0x1000000000006",
"SAI_BRIDGE_PORT_ATTR_ADMIN_STATE": "true"
},
"ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY:{\"mac\":\"52:54:00:9E:94:6F\",\"vlan\":\"1\"}": {
"SAI_FDB_ENTRY_ATTR_PORT_ID": "oid:0x100000000001b",
"SAI_FDB_ENTRY_ATTR_TYPE": "SAI_FDB_ENTRY_TYPE_DYNAMIC"
},
"ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY:{\"mac\":\"52:54:00:E4:27:F7\",\"vlan\":\"1\"}": {
"SAI_FDB_ENTRY_ATTR_PORT_ID": "oid:0x100000000001b",
"SAI_FDB_ENTRY_ATTR_TYPE": "SAI_FDB_ENTRY_TYPE_DYNAMIC"
},
"ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY:{\"mac\":\"00:1C:73:44:58:46\",\"vlan\":\"4078\"}": {
"SAI_FDB_ENTRY_ATTR_PORT_ID": "oid:0x2000000000578",
"SAI_FDB_ENTRY_ATTR_TYPE": "SAI_FDB_ENTRY_TYPE_DYNAMIC"
"ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT:oid:0x3a000000000608": {
"SAI_BRIDGE_PORT_ATTR_TYPE": "SAI_BRIDGE_PORT_TYPE_PORT",
"SAI_BRIDGE_PORT_ATTR_PORT_ID": "oid:0x1000000000008",
"SAI_BRIDGE_PORT_ATTR_ADMIN_STATE": "true"
}
}
10 changes: 5 additions & 5 deletions tests/test_fdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def setUpClass(cls):
cls.lut = MIBTable(SonicMIB)

def test_getpdu(self):
oid = ObjectIdentifier(20, 0, 0, 0, (1, 3, 6, 1, 2, 1, 17, 7, 1, 2, 2, 1, 2, 1000, 124, 254, 144, 128, 159, 92))
oid = ObjectIdentifier(20, 0, 0, 0, (1, 3, 6, 1, 2, 1, 17, 7, 1, 2, 2, 1, 2, 1000, 124, 254, 144, 128, 159, 4))
get_pdu = GetPDU(
header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0),
oids=[oid]
Expand All @@ -37,7 +37,7 @@ def test_getpdu(self):
value0 = response.values[0]
self.assertEqual(value0.type_, ValueType.INTEGER)
self.assertEqual(str(value0.name), str(oid))
self.assertEqual(value0.data, 49)
self.assertEqual(value0.data, 113)

def test_getnextpdu(self):
get_pdu = GetNextPDU(
Expand All @@ -54,11 +54,11 @@ def test_getnextpdu(self):
n = len(response.values)
value0 = response.values[0]
self.assertEqual(value0.type_, ValueType.INTEGER)
self.assertEqual(value0.data, 49)
self.assertEqual(value0.data, 113)

def test_getnextpdu_exactmatch(self):
# oid.include = 1
oid = ObjectIdentifier(20, 0, 1, 0, (1, 3, 6, 1, 2, 1, 17, 7, 1, 2, 2, 1, 2, 1000, 124, 254, 144, 128, 159, 92))
oid = ObjectIdentifier(20, 0, 1, 0, (1, 3, 6, 1, 2, 1, 17, 7, 1, 2, 2, 1, 2, 1000, 124, 254, 144, 128, 159, 4))
get_pdu = GetNextPDU(
header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0),
oids=[oid]
Expand All @@ -73,7 +73,7 @@ def test_getnextpdu_exactmatch(self):
self.assertEqual(value0.type_, ValueType.INTEGER)
print("test_getnextpdu_exactmatch: ", str(oid))
self.assertEqual(str(value0.name), str(oid))
self.assertEqual(value0.data, 49)
self.assertEqual(value0.data, 113)

def test_getpdu_noinstance(self):
get_pdu = GetPDU(
Expand Down

0 comments on commit 45e4e78

Please sign in to comment.