Commit 0b0c79d
committed
ospfv3: add packet serializer incl. checksumMode and packet format fixes
Add Ospfv3PacketSerializer (RFC 5340 Appendix A), modelled on the OSPFv2
serializer: the 16-octet common header, the Hello, Database Description, Link
State Request, Link State Update and Link State Acknowledgement packets, the
20-octet LSA header, and the Router, Network, Inter-Area-Prefix, Link and
Intra-Area-Prefix LSA bodies (the LSA types the model originates), plus the
fixed-size address-prefix encodings. Byte counts match the lengths the OSPFv3
implementation assigns (Ospfv3Common.h). The address slots are written for
whatever the L3Address fields hold (IPv6, IPv4-instance, or unset) so both
address families serialize.
Wire it into the version-dispatching ospf::OspfPacketSerializer (the v3 case
was a TODO stub).
Add tests/unit/OSPFv3_serializer.test: a byte-exact serialize->deserialize
round-trip for every packet type and every supported LSA. Verified that the
serialize path also runs cleanly (computed checksums/FCS) across all
examples/ospfv3/* simulations; existing OSPFv3 fingerprints are unchanged.
Fix: originate Router-LSAs without uninitialized gap entries
Ospfv3Area::originateRouterLSA() indexed the Router-LSA's router entries by the
interface index i (setRoutersArraySize(i+1); setRouters(i, ...)). When an
interface contributes no entry (e.g. a host-facing or down interface), this
left an uninitialized gap entry in the array; and when a point-to-point link
had several full neighbors, each overwrote the same index i. The gap entries
carried garbage (e.g. a non-deterministic neighborRouterID), which corrupted
the SPF input and made the serialized Router-LSA bytes non-deterministic.
Append each entry at the current array size instead, so the array holds exactly
the real entries with no gaps and no overwrites.
Fix: deterministic Router-LSA / retransmitted-LSU serialization
Two packet-length bugs left OSPFv3 ~tND non-deterministic, so the ospfv3
examples could only carry tplx;~tNl until now:
1. Ospfv3Area::originateRouterLSA() never set the LSA's lsaLength field, unlike
every other originate*LSA. The deserializer derives the router-entry count
from lsaLength, so a Router-LSA serialized with lsaLength=0 was malformed and
self-inconsistent. Set it from calculateLSASize().
2. Ospfv3Neighbor::retransmitUpdatePacket() based the LSU length on
OSPFV3_HEADER_LENGTH + OSPFV3_LSA_HEADER_LENGTH (16+20) instead of the OSPF
header plus the 4-octet "# LSAs" field (16+4), as prepareUpdatePacket() does.
This overcounted chunkLength by 16 octets, so the chunk serializer padded
every retransmitted LSU with 16 uninitialized, run-to-run-varying bytes --
the actual source of the ~tND drift. Also set the packet-length header field,
which this builder left at 0.
Make OSPFv3 emit standards-compliant, dissectable wire packets:
- Address prefixes: encode as the variable-length ((PrefixLength+31)/32)
32-bit words (RFC 5340 A.4.1) instead of a fixed 16-octet slot. The fixed
encoding made the serialized length exceed the declared chunk length, so
debug builds aborted on the chunk-length check for every prefix-bearing
LSA (e.g. multi-area examples in the statistical tests).
- LSA header LS Type: emit the full 16-bit value with the U bit and S1/S2
flooding-scope bits (RFC 5340 A.4.2.1): Router=0x2001, Network=0x2002,
Inter-Area-Prefix=0x2003, AS-External=0x4005, Link=0x0008, etc.
- OSPF packet checksum: compute the Internet checksum over the IPv6
upper-layer pseudo-header followed by the packet (RFC 5340 2.5) in
Ospfv3Process::sendPacket, where the addresses are known.
- LSA "LS checksum": add a Fletcher checksum utility (RFC 1008) and stamp
each self-originated LSA at origination (RFC 2328 12.1.7); received LSAs
already carry the originator's checksum.
- Packet framing: set the OSPF header Packet Length on LS Request and LS
Acknowledgement packets, set the LSA count on retransmitted LS Updates,
and accumulate (instead of resetting per LSA) the packet length in
prepareUpdatePacket so multi-LSA updates are sized correctly.
Verified with tshark: a captured multi-area trace (2155 packets, all
message and LSA types) dissects with zero malformed packets and all packet
and LSA checksums valid.
Gate packet and LSA checksum computation behind a checksumMode parameter
Follow the OSPFv2 / UDP / ICMPv6 convention instead of computing the OSPFv3 packet
and LSA checksums unconditionally:
- Add a checksumMode parameter (@enum("declared", "computed"), default "declared")
to the Ospfv3 module, threaded through Ospfv3Splitter to each Ospfv3Process.
- Move the checksum logic into Ospfv3Checksum (setOspfChecksum / setLsaChecksum),
mirroring ospfv2/Ospfv2Checksum. In "declared" mode the field carries a sentinel
(no per-send serialization cost); in "computed" mode it holds the real value:
the RFC 5340 2.5 packet checksum over the IPv6 pseudo-header, and the RFC 2328
12.1.7 Fletcher LS checksum. The packet checksum still has to be done in the
module (Ospfv3Process::sendPacket) since it needs the addresses, as in UDP/TCP.1 parent 0c88925 commit 0b0c79d
17 files changed
Lines changed: 1210 additions & 9 deletions
File tree
- src/inet
- common/checksum
- routing
- ospf_common
- ospfv3
- interface
- neighbor
- process
- tests/unit
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
184 | 184 | | |
185 | 185 | | |
186 | 186 | | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
187 | 206 | | |
188 | 207 | | |
189 | 208 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
29 | 39 | | |
30 | 40 | | |
31 | 41 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
15 | 18 | | |
16 | 19 | | |
17 | 20 | | |
| |||
37 | 40 | | |
38 | 41 | | |
39 | 42 | | |
40 | | - | |
41 | | - | |
| 43 | + | |
| 44 | + | |
42 | 45 | | |
43 | 46 | | |
44 | 47 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| 28 | + | |
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
0 commit comments