|
4 | 4 |
|
5 | 5 | Covers :attr:`LinuxSLL.__proto__ <pcapkit.protocols.link.linux_sll.LinuxSLL.__proto__>` |
6 | 6 | as shipped, dispatch through it and through the EtherType path from both versions, |
| 7 | +a parse stopping at either version on either path (#2532), |
7 | 8 | the ``__index__`` of the classes it reaches, and the registrars of it and of |
8 | 9 | :class:`~pcapkit.protocols.link.frad.FRAD`'s and |
9 | 10 | :class:`~pcapkit.protocols.link.netlink.Netlink`'s registries. |
@@ -138,25 +139,73 @@ def test_an_empty_payload_is_no_payload_on_either_path(self) -> None: |
138 | 139 | raw = header(0x0800, arphrd) |
139 | 140 | self.assertIsInstance(version(raw, len(raw)).payload, NoPayload) |
140 | 141 |
|
141 | | - def test_a_stop_at_this_layer_still_parses_a_registered_arphrd_type(self) -> None: |
142 | | - """The order the NOTE in ``LinuxSLL._import_next_layer`` records. |
| 142 | + def _stops(self, version): # type: ignore[no-untyped-def] |
| 143 | + """Each spelling of a stop at ``version``: its layer, family and own name or class.""" |
| 144 | + from pcapkit.protocols.link.linux_sll import LinuxSLL |
| 145 | + |
| 146 | + return ({'layer': 'Link'}, {'layer': 'link'}, {'protocol': 'LinuxSLL'}, |
| 147 | + {'protocol': version.__name__}, {'protocol': LinuxSLL}, {'protocol': version}) |
143 | 148 |
|
144 | | - Stopping at the link layer or at the version keeps an EtherType payload |
145 | | - :class:`~pcapkit.protocols.misc.raw.Raw`, while a registered |
146 | | - ``arphrd_type`` is still dispatched. |
147 | | - """ |
| 149 | + def test_a_stop_at_this_layer_keeps_a_registered_arphrd_type_raw(self) -> None: |
| 150 | + """The registry path stops as the EtherType path does (#2532).""" |
148 | 151 | from pcapkit.const.linux.arphrd import ARPHRD |
| 152 | + from pcapkit.protocols.misc.raw import Raw |
| 153 | + |
| 154 | + for version, header, alias in self._versions(): |
| 155 | + for name, (payload, _) in CASES.items(): |
| 156 | + for stop in self._stops(version): |
| 157 | + with self.subTest(version=version.__name__, arphrd=name, stop=stop): |
| 158 | + raw = header(0x0800, getattr(ARPHRD, name)) + payload |
| 159 | + parsed = version(raw, len(raw), **stop) |
| 160 | + self.assertEqual(parsed.protochain.chain, f'{alias}:Raw') |
| 161 | + self.assertIsInstance(parsed.payload, Raw) |
| 162 | + self.assertEqual(parsed.payload.data, payload) |
| 163 | + self.assertEqual(parsed.payload.info.protocol, 0x0800) |
| 164 | + self.assertEqual(parsed.data, raw) |
| 165 | + self.assertEqual(version.from_data(parsed.info).data, raw) |
| 166 | + |
| 167 | + # Without a length, the whole payload is the next layer's. |
| 168 | + again = parsed._import_next_layer(parsed.protocol) |
| 169 | + self.assertIsInstance(again, Raw) |
| 170 | + self.assertEqual(again.data, payload) |
| 171 | + |
| 172 | + def test_a_stop_at_this_layer_keeps_an_ethertype_raw(self) -> None: |
| 173 | + """The Raw is named after the EtherType it would have dispatched on.""" |
| 174 | + from pcapkit.const.reg.ethertype import EtherType |
| 175 | + from pcapkit.protocols.misc.raw import Raw |
149 | 176 |
|
150 | 177 | for version, header, alias in self._versions(): |
151 | | - for stop in ({'layer': 'Link'}, {'protocol': version.__name__}): |
| 178 | + for stop in self._stops(version): |
152 | 179 | with self.subTest(version=version.__name__, stop=stop): |
153 | 180 | raw = header(0x0800, 1) + IPV4 |
154 | | - self.assertEqual(version(raw, len(raw), **stop).protochain.chain, |
| 181 | + parsed = version(raw, len(raw), **stop) |
| 182 | + self.assertEqual(parsed.protochain.chain, |
155 | 183 | f'{alias}:Internet_Protocol_version_4') |
| 184 | + self.assertIsInstance(parsed.payload, Raw) |
| 185 | + self.assertEqual(parsed.payload.data, IPV4) |
| 186 | + self.assertIs(parsed.payload.info.protocol, |
| 187 | + EtherType.Internet_Protocol_version_4) |
| 188 | + self.assertEqual(parsed.data, raw) |
| 189 | + self.assertEqual(version.from_data(parsed.info).data, raw) |
| 190 | + |
| 191 | + def test_a_stop_at_another_protocol_still_dispatches_here(self) -> None: |
| 192 | + """The other version's name and a protocol further in do not stop this layer.""" |
| 193 | + from pcapkit.const.linux.arphrd import ARPHRD |
| 194 | + |
| 195 | + frad = CASES['FRAD'][0] |
| 196 | + for version, header, alias in self._versions(): |
| 197 | + other = 'LinuxSLL2' if version.__name__ == 'LinuxSLL1' else 'LinuxSLL1' |
| 198 | + for stop, chain in (({'protocol': other}, 'FRAD:IPv4:UDP'), |
| 199 | + ({'protocol': 'FRAD'}, 'FRAD:Raw')): |
| 200 | + with self.subTest(version=version.__name__, stop=stop): |
| 201 | + raw = header(0x0800, ARPHRD.FRAD) + frad |
| 202 | + parsed = version(raw, len(raw), **stop) |
| 203 | + self.assertEqual(parsed.protochain.chain, f'{alias}:{chain}') |
| 204 | + self.assertEqual(version.from_data(parsed.info).data, raw) |
156 | 205 |
|
157 | | - raw = header(0x0800, ARPHRD.NETLINK) + CASES['NETLINK'][0] |
| 206 | + raw = header(0x0800, 1) + IPV4 |
158 | 207 | self.assertEqual(version(raw, len(raw), **stop).protochain.chain, |
159 | | - f'{alias}:Netlink:Raw') |
| 208 | + f'{alias}:IPv4:UDP') |
160 | 209 |
|
161 | 210 | def test_index_is_the_arphrd_type_that_dispatches_here(self) -> None: |
162 | 211 | from pcapkit.const.linux.arphrd import ARPHRD |
|
0 commit comments