network: protocol numbers are defined in multiple places
This is a secondary issue, but it often drives me crazy: the protocol numbers are defined in multiple places.
This might be mildly acceptable for IPv4, UDP, and so on, but when it comes to EtherTypes and conversions it's not that obvious.
I'll make an example, so you'll be totally confused [Ennio Flaiano].
- IPv6 does have protocol number (it's 6, unsurprisingly).
- IPv6 does have an 802 protocol number (0x86DD), defined in https://www.iana.org/assignments/ieee-802-numbers/ieee-802-numbers.xhtml
- IPv6 does have a PPP protocol number (0x0057), defined in https://www.iana.org/assignments/ppp-numbers/ppp-numbers.xml
So far so good (but you know where I'm going to land).
PPP needs to get the frame protocol number and convert it to its own protocol number - but it only sees the 802 protocol number, so it must handle 0x86DD. Where it is defined?
➜ ns-3-dev git:(UanFix6LoW) ✗ cppgrep 0x86DD src
src/lte/model/epc-pgw-application.cc:453: protocol = 0x86DD;
src/uan/model/uan-header-common.cc:26:static const uint16_t IPV6_PROT_NUMBER = 0x86DD;
src/internet/model/ipv6-l3-protocol.cc:58:const uint16_t Ipv6L3Protocol::PROT_NUMBER = 0x86DD;
src/internet/model/ipv6-l3-protocol.h:73: * \brief The protocol number for IPv6 (0x86DD).
src/point-to-point/model/point-to-point-net-device.cc:660: return 0x86DD; // IPv6
src/point-to-point/model/point-to-point-net-device.cc:675: case 0x86DD:
ANS: in the internet
model, so ppp
re-defines it because it can't depend on internet
. Surprise, also lte
uses it, hardcoded. For IPv4 this is even worse, 0x800 is hardcoded / redefined in multiple places.
Moreover, if one wants to be pedantic, const uint16_t Ipv6L3Protocol::PROT_NUMBER = 0x86DD;
is wrong, the IPv6 protocol number is 6, 0x86DD is the 802 protocol number for IPv6.
Fast forward, long story short.
My proposal is to add one (or more) files to network/utils
, starting with:
-
src/network/utils/iana-IEEE-802-numbers.h
, and -
src/network/utils/iana-ppp-dll-numbers.h
.
Further files can be added if necessary.
This would limit the hardcoding, allow more simple searches for occurrences in the codebase, and simplify the development.
Changing the existing modules can be done in a relaxed way, i.e., there's no need to go scavenging for occurrences, but when we modify something we can leverage the existing definitions.