Skip to content

Commit da41ffc

Browse files
FreddieJheng-quantajk-ozlabs
authored andcommitted
mctpd: Add test for IID behaviour on retries
Add a test to verify that Control Protocol IIDs are re-used on a command retry. [This is based on an originial commit from Freddie Jheng <Freddie.Jheng@quantatw.com>, containing the test cases from that commit. Minor modifications from Jeremy Kerr <jk@codeconstruct.com.au>] Signed-off-by: Freddie Jheng <Freddie.Jheng@quantatw.com> Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
1 parent e2e0afe commit da41ffc

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

tests/test_mctpd.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,6 +1767,54 @@ async def handle_mctp_control(self, sock, addr, data):
17671767
assert res == 0
17681768

17691769

1770+
async def test_query_peer_properties_same_iid_on_retry(nursery, dbus, sysnet):
1771+
"""Verify that retries for query_peer_properties reuse the same IID.
1772+
1773+
Per DSP0237 Table 9, a retry is a retransmission of the same MCTP control
1774+
message and must use the same instance ID (IID) within MT4.
1775+
"""
1776+
1777+
class IIDTrackingEndpoint(Endpoint):
1778+
"""Drop the first Get Message Type Support request, record all IIDs seen."""
1779+
1780+
def __init__(self, *args, **kwargs):
1781+
super().__init__(*args, **kwargs)
1782+
self.seen_iids = []
1783+
self.drop_next = True
1784+
1785+
async def handle_mctp_control(self, sock, addr, data):
1786+
rq = data[0] & 0x80
1787+
opcode = data[1]
1788+
iid = data[0] & 0x1F
1789+
if rq and opcode == 0x05: # Get Message Type Support
1790+
self.seen_iids.append(iid)
1791+
if self.drop_next:
1792+
self.drop_next = False
1793+
return # simulate timeout
1794+
return await super().handle_mctp_control(sock, addr, data)
1795+
1796+
mctpd = MctpdWrapper(dbus, sysnet)
1797+
await mctpd.start_mctpd(nursery)
1798+
1799+
iface = mctpd.system.interfaces[0]
1800+
mctp = await mctpd_mctp_iface_obj(dbus, iface)
1801+
1802+
ep = IIDTrackingEndpoint(iface, bytes([0x1A]), eid=15, types=[0, 1, 2])
1803+
mctpd.network.add_endpoint(ep)
1804+
1805+
await mctp.call_setup_endpoint(ep.lladdr)
1806+
1807+
# Two Get Message Type Support requests: initial + one retry
1808+
assert len(ep.seen_iids) == 2
1809+
# Both must carry the same IID
1810+
assert ep.seen_iids[0] == ep.seen_iids[1], (
1811+
f"IID changed across retry: {ep.seen_iids[0]:#04x} -> {ep.seen_iids[1]:#04x}"
1812+
)
1813+
1814+
res = await mctpd.stop_mctpd()
1815+
assert res == 0
1816+
1817+
17701818
async def test_bridged_endpoint_poll(dbus, sysnet, nursery, autojump_clock):
17711819
"""Test that we use endpoint poll interval from the config and
17721820
that we discover bridged endpoints via polling

0 commit comments

Comments
 (0)