Skip to content

Commit 055fd37

Browse files
Add tests for dynamic bridge eid and downstream eid assignment
Add new test for validating AssignEndpoint D-Bus method to verify bridge endpoint EID allocation being contiguous to its downstream eids. - Add test_assign_dynamic_bridge_eid() for bridge simulation testing - Simulate bridge with some downstream endpoints in test framework - Test EID allocation of bridge and downstream being contiguous Signed-off-by: Faizan Ali <[email protected]>
1 parent f4fa636 commit 055fd37

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

tests/mctpenv/__init__.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ async def handle_mctp_control(self, sock, addr, data):
348348
# Set Endpoint ID
349349
(op, eid) = data[2:]
350350
self.eid = eid
351-
data = bytes(hdr + [0x00, 0x00, self.eid, 0x00])
351+
data = bytes(hdr + [0x00, 0x01 if len(self.bridged_eps) > 0 else 0x00, self.eid, len(self.bridged_eps)])
352352
await sock.send(raddr, data)
353353

354354
elif opcode == 2:
@@ -367,6 +367,18 @@ async def handle_mctp_control(self, sock, addr, data):
367367
data = bytes(hdr + [0x00, len(types)] + types)
368368
await sock.send(raddr, data)
369369

370+
elif opcode == 8:
371+
# Allocate Endpoint IDs
372+
(_, _, _, pool_size, pool_start) = data
373+
num_eps = min(pool_size, len(self.bridged_eps))
374+
data = bytes(hdr + [0x00, 0x00, num_eps, pool_start])
375+
376+
# Assign sequential EIDs starting from pool_start
377+
for ep in range(num_eps):
378+
self.bridged_eps[ep].eid = pool_start + ep
379+
380+
await sock.send(raddr, data)
381+
370382
else:
371383
await sock.send(raddr, bytes(hdr + [0x05])) # unsupported command
372384

tests/test_mctpd.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,3 +831,42 @@ async def test_interface_rename_with_peers(dbus, mctpd):
831831
# ensure the endpoint persists after rename
832832
ep_obj = await dbus.get_proxy_object(MCTPD_C, ep_path)
833833
assert ep_obj is not None
834+
""" Test bridge endpoint dynamic EID assignment and downstream
835+
endpoint EID allocation
836+
837+
Tests that:
838+
- Bridge endpoint can be assigned a dynamic EID
839+
- Downstream endpoints get contiguous EIDs after bridge's own eid
840+
"""
841+
async def test_assign_dynamic_bridge_eid(dbus, mctpd):
842+
iface = mctpd.system.interfaces[0]
843+
mctp = await mctpd_mctp_iface_obj(dbus, iface)
844+
ep = mctpd.network.endpoints[0]
845+
846+
pool_size = 2
847+
848+
# Set up bridged endpoints as undiscovered EID 0
849+
for i in range(pool_size):
850+
br_ep = Endpoint(iface, bytes(), types=[0, 2])
851+
ep.add_bridged_ep(br_ep)
852+
mctpd.network.add_endpoint(br_ep)
853+
854+
mctp = await mctpd_mctp_iface_obj(dbus, iface)
855+
856+
# dynamic EID assigment for dev1
857+
(eid, _, path, new) = await mctp.call_assign_endpoint(
858+
ep.lladdr,
859+
)
860+
861+
assert new
862+
# Assert for assigned bridge endpoint ID
863+
assert path == f'/au/com/codeconstruct/mctp1/networks/1/endpoints/{eid}'
864+
assert new
865+
866+
net = await mctpd_mctp_network_obj(dbus, iface.net)
867+
for i in range(pool_size):
868+
br_ep = ep.bridged_eps[i]
869+
#check if the downstream endpoint eid is contiguous to the bridge endpoint eid
870+
assert (eid + i + 1) == br_ep.eid
871+
(path, new) = await net.call_learn_endpoint(br_ep.eid)
872+
assert path == f'/au/com/codeconstruct/mctp1/networks/1/endpoints/{br_ep.eid}'

0 commit comments

Comments
 (0)