Skip to content

Commit 28fecd9

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 aedba9a commit 28fecd9

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

tests/mctpenv/__init__.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,10 @@ 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.pool_start = 0
308+
self.allocated_pool_size = 0
309+
306310
# keyed by (type, type-specific-instance)
307311
self.commands = {}
308312

@@ -348,7 +352,9 @@ async def handle_mctp_control(self, sock, addr, data):
348352
# Set Endpoint ID
349353
(op, eid) = data[2:]
350354
self.eid = eid
351-
data = bytes(hdr + [0x00, 0x00, self.eid, 0x00])
355+
self.pool_size = len(self.bridged_eps)
356+
alloc_status = 0x01 if self.pool_size > 0 else 0x00
357+
data = bytes(hdr + [0x00, alloc_status, self.eid, self.pool_size])
352358
await sock.send(raddr, data)
353359

354360
elif opcode == 2:
@@ -367,6 +373,24 @@ async def handle_mctp_control(self, sock, addr, data):
367373
data = bytes(hdr + [0x00, len(types)] + types)
368374
await sock.send(raddr, data)
369375

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

tests/test_mctpd.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,3 +926,48 @@ 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+
958+
# check if we can assign non-bridged endpoint dev2, eid from
959+
#bridge's already assigned pool
960+
dev2 = Endpoint(iface, bytes([0x1e]))
961+
mctpd.network.add_endpoint(dev2)
962+
with pytest.raises(asyncdbus.errors.DBusError) as ex:
963+
await mctp.call_assign_endpoint_static(dev2.lladdr, ep.eid + 1)
964+
965+
assert str(ex.value) == "EID belongs to another MCTP bridge pool"
966+
967+
# check if downstream endpoint EID of dev1 is in allocated pool range
968+
net = await mctpd_mctp_network_obj(dbus, iface.net)
969+
for i in range(pool_size):
970+
br_ep = ep.bridged_eps[i]
971+
assert ep.eid < br_ep.eid <= ep.eid + ep.allocated_pool_size
972+
(_, new) = await net.call_learn_endpoint(br_ep.eid)
973+
assert new

0 commit comments

Comments
 (0)