Add a new, simple, basic, L3 protocol, with the protocol number 99, which should be registered on the node.
Ask the L3 protocol to send a ping-like packet and receive a response in the running example.
No routing, addressing are needed. It merely needs to be able to send a ‘ping-like’ packet to the NetDevice, and receive a packet (destined to protocol 99) from a NetDevice. A simple print on the screen at the send and receive moment is enough to show a working implementation.
Key Elements of the Solution
Declare the correct protocol number in the HypotheticalL3Protocol.
Make a systems print at the Handler Receive for the HypotheticalL3Protocol. This callback will be registered later to bind the node and the NetDevice.
Expose an interface for sending the packet to target NetDevice, note that this is just for patch.
Instantiate the Node, NetDevice, HypotheticalL3Protocol and aggregate them to the Node.
Register the protocol handler. This is the key of the patch. NS-3 uses extensively the callback mechanism to split module dependencies. Since we could not know a priori the protocol to handle the incoming packets received at NetDevice, we need this indirection that would allow us to flexibly specify the handler during the simulation.
Ask the a hypothetical L3 protocol to directly call methods on a NetDevice (e.g., Send()) to perform operations. The LoopBackNetDevice will trigger the HypotheticalL3Protocol Handler since it is registered and the protocol number of the packet received match the registered protocol number, i.e., 99.
Check the terminal prints and verify that the packet is sent top-down and bottom-up.
Creating the Patch
We could just use the UNIX diff tool as this is a simple patch. I created a GitHub Gist to store the patch.
For complicated patches, the Rietveld tool could be used.