Skip to content

Commit b4ac97f

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 Allocate Endpoint control message support with new endpoint property for allocated pool size also assign dynamic eid contiguous to bridge during Allocate Endpoint control message. Signed-off-by: Faizan Ali <[email protected]>
1 parent 3c5e306 commit b4ac97f

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

tests/mctpenv/__init__.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,9 @@ def __init__(self, iface, lladdr, ep_uuid = None, eid = 0, types = None):
303303
self.eid = eid
304304
self.types = types or [0]
305305
self.bridged_eps = []
306+
self.pool_size = 0
307+
self.allocated_pool = None # [start, size]
308+
306309
# keyed by (type, type-specific-instance)
307310
self.commands = {}
308311

@@ -348,7 +351,9 @@ async def handle_mctp_control(self, sock, addr, data):
348351
# Set Endpoint ID
349352
(op, eid) = data[2:]
350353
self.eid = eid
351-
data = bytes(hdr + [0x00, 0x00, self.eid, 0x00])
354+
self.pool_size = len(self.bridged_eps)
355+
alloc_status = 0x01 if self.pool_size > 0 else 0x00
356+
data = bytes(hdr + [0x00, alloc_status, self.eid, self.pool_size])
352357
await sock.send(raddr, data)
353358

354359
elif opcode == 2:
@@ -367,6 +372,23 @@ async def handle_mctp_control(self, sock, addr, data):
367372
data = bytes(hdr + [0x00, len(types)] + types)
368373
await sock.send(raddr, data)
369374

375+
elif opcode == 8:
376+
# Allocate Endpoint IDs
377+
(_, _, _, pool_size, pool_start) = data
378+
alloc_status = 0x00
379+
if self.allocated_pool is not None:
380+
alloc_status = 0x01
381+
else:
382+
num_eps = min(pool_size, self.pool_size)
383+
self.allocated_pool = [pool_start, num_eps]
384+
# Assign sequential EIDs starting from pool_start
385+
for ep in range(num_eps):
386+
self.bridged_eps[ep].eid = self.allocated_pool[0] + ep
387+
388+
data = bytes(hdr + [0x00, alloc_status,
389+
self.allocated_pool[1], self.allocated_pool[0]])
390+
await sock.send(raddr, data)
391+
370392
else:
371393
await sock.send(raddr, bytes(hdr + [0x05])) # unsupported command
372394

tests/test_mctpd.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,3 +926,42 @@ async def test_config_dyn_eid_range_max(nursery, dbus, sysnet):
926926

927927
res = await mctpd.stop_mctpd()
928928
assert res == 0
929+
930+
""" Test bridge endpoint dynamic EID assignment and downstream
931+
endpoint EID allocation
932+
933+
Tests that:
934+
- Bridge endpoint can be assigned a dynamic EID
935+
- Downstream endpoints get contiguous EIDs after bridge's own eid
936+
"""
937+
async def test_assign_dynamic_bridge_eid(dbus, mctpd):
938+
iface = mctpd.system.interfaces[0]
939+
mctp = await mctpd_mctp_iface_obj(dbus, iface)
940+
ep = mctpd.network.endpoints[0]
941+
pool_size = 2
942+
943+
# Set up bridged endpoints as undiscovered EID 0
944+
for i in range(pool_size):
945+
br_ep = Endpoint(iface, bytes(), types=[0, 2])
946+
ep.add_bridged_ep(br_ep)
947+
mctpd.network.add_endpoint(br_ep)
948+
949+
mctp = await mctpd_mctp_iface_obj(dbus, iface)
950+
951+
# dynamic EID assigment for dev1
952+
(eid, _, path, new) = await mctp.call_assign_endpoint(
953+
ep.lladdr,
954+
)
955+
956+
assert new
957+
assert ep.allocated_pool[0] == eid + 1
958+
assert ep.allocated_pool[1] == pool_size
959+
960+
# check if we can assign non-bridged endpoint dev2, eid from
961+
#bridge's already assigned pool
962+
dev2 = Endpoint(iface, bytes([0x1e]))
963+
mctpd.network.add_endpoint(dev2)
964+
with pytest.raises(asyncdbus.errors.DBusError) as ex:
965+
await mctp.call_assign_endpoint_static(dev2.lladdr, ep.eid + 1)
966+
967+
assert str(ex.value) == "EID belongs to another MCTP bridge pool"

0 commit comments

Comments
 (0)