Skip to content

Commit 5d918b1

Browse files
committed
fix(internet): narrow IGMP's id() to self, per owner's post-merge ruling
IGMPv1/IGMPv2 (#2444) shipped with the family-inclusive id() shape -- ('IGMP', 'IGMPv1') / ('IGMP', 'IGMPv2') -- but the owner's ruling is that IGMP narrows to self, like IP/IPsec's AH and ESP: - IGMP.id() is now ('IGMPv1', 'IGMPv2'), members only, dropping the family name. - IGMPv1.id() and IGMPv2.id() are now ('IGMPv1',) and ('IGMPv2',) alone. Selector matching for the bare 'IGMP' string is unaffected: it still resolves via the registry key's own expansion (IGMP class plus its id()), the same mechanism that already makes 'IPsec' select an AH or ESP layer. Verified directly against a real parsed IGMPv1 layer: 'IGMP' in layer, 'IGMPv1' in layer and layer == 'IGMPv1' all still True, 'IGMPv2' in layer still False. Recorded the ruling in protocol-family-grouping.rst, which previously had no IGMP entry at all. Verified: tests/protocols/internet/test_igmp_unit.py, test_dispatch_registry_unit.py, test_conventions_doc_claims.py and test_public_api.py all pass clean (91 tests, 1163 subtests).
1 parent d66df71 commit 5d918b1

5 files changed

Lines changed: 23 additions & 16 deletions

File tree

‎docs/source/contributing/conventions/protocol-family-grouping.rst‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ The member list takes either of these forms:
2121
:class:`~pcapkit.protocols.internet.esp.ESP` are not in it, since they belong to
2222
the separate abstract :class:`~pcapkit.protocols.internet.ipsec.IPsec`, whose
2323
:meth:`~pcapkit.protocols.internet.ipsec.IPsec.id` is ``('AH', 'ESP')``.
24+
:meth:`IGMP.id() <pcapkit.protocols.internet.igmp.IGMP.id>` is the same shape,
25+
``('IGMPv1', 'IGMPv2')``, and each version narrows further still, to itself alone
26+
(:ref:`protocol-family-shapes`). Owner's ruling.
2427
* **The base's own name, then the members.**
2528
:meth:`VLAN.id() <pcapkit.protocols.link.vlan.VLAN.id>` is
2629
``('VLAN', 'C_Tag', 'S_Tag')``,
@@ -65,7 +68,9 @@ Member Shapes
6568
* - Narrow to self
6669
- the member's own name only
6770
- :class:`~pcapkit.protocols.internet.ah.AH` ``('AH',)``,
68-
:class:`~pcapkit.protocols.internet.esp.ESP` ``('ESP',)``
71+
:class:`~pcapkit.protocols.internet.esp.ESP` ``('ESP',)``;
72+
:class:`IGMPv1 <pcapkit.protocols.internet.igmpv1.IGMP>` ``('IGMPv1',)`` and
73+
:class:`IGMPv2 <pcapkit.protocols.internet.igmpv2.IGMP>` ``('IGMPv2',)``
6974
* - Family-inclusive
7075
- the member's label plus the family name
7176
- :class:`~pcapkit.protocols.link.c_tag.C_Tag` ``('C_Tag', 'VLAN')``,

‎pcapkit/protocols/internet/igmp.py‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,17 @@ def length(self) -> 'Literal[8]':
8282
##########################################################################
8383

8484
@classmethod
85-
def id(cls) -> 'tuple[Literal["IGMP"], Literal["IGMPv1"], Literal["IGMPv2"]]':
85+
def id(cls) -> 'tuple[Literal["IGMPv1"], Literal["IGMPv2"]]':
8686
"""Index ID of the protocol.
8787
8888
Returns:
89-
Index ID of the protocol, the family name and both versions; the
90-
concrete IGMPv1 and IGMPv2 classes narrow it to their own version.
89+
Index ID of the protocol, both versions; IGMP narrows to self like
90+
:class:`~pcapkit.protocols.internet.ipsec.IPsec`, so the concrete
91+
IGMPv1 and IGMPv2 classes narrow further still, to their own
92+
version alone.
9193
9294
"""
93-
return ('IGMP', 'IGMPv1', 'IGMPv2')
95+
return ('IGMPv1', 'IGMPv2')
9496

9597
def read(self, length: 'Optional[int]' = None, **kwargs: 'Any') -> '_PT':
9698
"""Read Internet Group Management Protocol.

‎pcapkit/protocols/internet/igmpv1.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ def version(self) -> 'Literal[1]':
4343
##########################################################################
4444

4545
@classmethod
46-
def id(cls) -> 'tuple[Literal["IGMP"], Literal["IGMPv1"]]': # type: ignore[override]
46+
def id(cls) -> 'tuple[Literal["IGMPv1"]]': # type: ignore[override]
4747
"""Index ID of the protocol.
4848
4949
Returns:
50-
Index ID of the protocol, the family name and the version.
50+
Index ID of the protocol, narrowed to its own version alone.
5151
5252
"""
53-
return ('IGMP', 'IGMPv1')
53+
return ('IGMPv1',)

‎pcapkit/protocols/internet/igmpv2.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ def version(self) -> 'Literal[2]':
4343
##########################################################################
4444

4545
@classmethod
46-
def id(cls) -> 'tuple[Literal["IGMP"], Literal["IGMPv2"]]': # type: ignore[override]
46+
def id(cls) -> 'tuple[Literal["IGMPv2"]]': # type: ignore[override]
4747
"""Index ID of the protocol.
4848
4949
Returns:
50-
Index ID of the protocol, the family name and the version.
50+
Index ID of the protocol, narrowed to its own version alone.
5151
5252
"""
53-
return ('IGMP', 'IGMPv2')
53+
return ('IGMPv2',)

‎tests/protocols/internet/test_igmp_unit.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -340,20 +340,20 @@ def test_id_and_version(self) -> None:
340340
from pcapkit.protocols.internet.igmpv1 import IGMP as IGMPv1
341341
from pcapkit.protocols.internet.igmpv2 import IGMP as IGMPv2
342342

343-
self.assertEqual(IGMPv1.id(), ('IGMP', 'IGMPv1'))
344-
self.assertEqual(IGMPv2.id(), ('IGMP', 'IGMPv2'))
343+
self.assertEqual(IGMPv1.id(), ('IGMPv1',))
344+
self.assertEqual(IGMPv2.id(), ('IGMPv2',))
345345
self.assertEqual(object.__new__(IGMPv1).version, 1)
346346
self.assertEqual(object.__new__(IGMPv2).version, 2)
347347

348348
def test_base_id_covers_both_versions(self) -> None:
349349
from pcapkit.protocols.internet.igmp import IGMP
350350

351-
self.assertEqual(IGMP.id(), ('IGMP', 'IGMPv1', 'IGMPv2'))
351+
self.assertEqual(IGMP.id(), ('IGMPv1', 'IGMPv2'))
352352

353353
def test_each_version_narrows_the_base_id(self) -> None:
354354
v1, v2 = igmp_class('IGMPv1'), igmp_class('IGMPv2')
355-
self.assertEqual(v1.id(), ('IGMP', 'IGMPv1'))
356-
self.assertEqual(v2.id(), ('IGMP', 'IGMPv2'))
355+
self.assertEqual(v1.id(), ('IGMPv1',))
356+
self.assertEqual(v2.id(), ('IGMPv2',))
357357
self.assertNotIn('IGMPv2', v1.id())
358358
self.assertNotIn('IGMPv1', v2.id())
359359

0 commit comments

Comments
 (0)