Skip to content

Commit bf8f331

Browse files
New mctpd test for AssignBridgeStatic d-bus method
* Simulate a Bridge with downstream endpoints * Assign Bridge EID and allocate endpoint IDs for certain pool size from pool start Signed-off-by: Faizan Ali <[email protected]>
1 parent 43afc24 commit bf8f331

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

tests/mctpd/__init__.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ async def handle_mctp_control(self, sock, addr, data):
318318
# Set Endpoint ID
319319
(op, eid) = data[2:]
320320
self.eid = eid
321-
data = bytes(hdr + [0x00, 0x00, self.eid, 0x00])
321+
data = bytes(hdr + [0x00, 0x01 if len(self.bridged_eps) > 0 else 0x00, self.eid, len(self.bridged_eps)])
322322
await sock.send(raddr, data)
323323

324324
elif opcode == 2:
@@ -337,6 +337,18 @@ async def handle_mctp_control(self, sock, addr, data):
337337
data = bytes(hdr + [0x00, len(types)] + types)
338338
await sock.send(raddr, data)
339339

340+
elif opcode == 8:
341+
# Allocate Endpoint IDs
342+
(_, _, _, pool_size, pool_start) = data
343+
num_eps = min(pool_size, len(self.bridged_eps))
344+
data = bytes(hdr + [0x00, 0x00, num_eps, pool_start])
345+
346+
# Assign sequential EIDs starting from pool_start
347+
for ep in range(num_eps):
348+
self.bridged_eps[ep].eid = pool_start + ep
349+
350+
await sock.send(raddr, data)
351+
340352
else:
341353
await sock.send(raddr, bytes(hdr + [0x05])) # unsupported command
342354

tests/test_mctpd.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,3 +686,48 @@ async def test_add_interface(dbus, mctpd):
686686
assert eid == static_eid
687687
assert new
688688
assert mctpd.system.lookup_route(net, static_eid).iface == iface
689+
690+
""" Test bridge endpoint EID assignment and downstream endpoint EID allocation
691+
692+
Tests that:
693+
- Bridge endpoint can be assigned a static EID
694+
- Downstream endpoints get sequential EIDs from pool start
695+
"""
696+
async def test_assign_bridge_static(dbus, mctpd):
697+
iface = mctpd.system.interfaces[0]
698+
ep = mctpd.network.endpoints[0]
699+
700+
bridge_eid = 12
701+
pool_start = 13
702+
pool_size = 2
703+
704+
# Set up bridged endpoints as undiscovered EID 0
705+
for i in range(pool_size):
706+
br_ep = Endpoint(iface, bytes(), eid=pool_start + i, types=[0, 2])
707+
ep.add_bridged_ep(br_ep)
708+
mctpd.network.add_endpoint(br_ep)
709+
710+
mctp = await mctpd_mctp_iface_obj(dbus, iface)
711+
712+
(eid, net, path, new, msg) = await mctp.call_assign_bridge_static(
713+
ep.lladdr, # physaddr
714+
bridge_eid, # static_eid
715+
pool_start, # pool_start
716+
pool_size # pool_size
717+
)
718+
719+
# Assert for assigned bridge endpoint ID
720+
assert eid == bridge_eid
721+
assert path == f'/au/com/codeconstruct/mctp1/networks/1/endpoints/{bridge_eid}'
722+
assert new
723+
724+
# Bridge Simulation : Add routes and neighbours and assert for downstream endpoints
725+
# static neighbour; no gateway route support at present
726+
net = await mctpd_mctp_network_obj(dbus, iface.net)
727+
for i in range(pool_size):
728+
br_ep = ep.bridged_eps[i]
729+
await mctpd.system.add_route(mctpd.system.Route(iface, br_ep.eid, 1))
730+
await mctpd.system.add_neighbour(mctpd.system.Neighbour(iface, ep.lladdr, br_ep.eid))
731+
(path, new) = await net.call_learn_endpoint(br_ep.eid)
732+
assert path == f'/au/com/codeconstruct/mctp1/networks/1/endpoints/{br_ep.eid}'
733+
assert new

0 commit comments

Comments
 (0)