This Protocol has a lot of information on the Internet, so I will not post the source code here. I want to talk about the problems I encountered during the compilation process and sort out my ideas.
First, the Protocol is easy to understand. A node sends packets at a specified time. After receiving the packets, the receiving node calculates the RTT value and returns an ECHO packet to the receiving node. Finally, the RTT value is recorded in the out [] Array Using the TCL. eval function.
In the compilation process, I encountered two problems: off_ip _ is not defined. The solution to this error is to define off_ip _ first _. That is:
Int off_ip _ = hdr_ip: offset ();
The second problem is that no match for 'operator> 'in' hdrip-> SRC _> * (Address: instance (). nodeshift _ [1],...
I checked a lot of information and found that it may be due to the version. It must be written as hdrip-> SRC _. ADDR _> address: instance (). nodeshift _ [1].
(Schedck: instance (). Clock ()-HDR-> send_time) * 1000 );
In this way, the compilation is successful.
In fact, ns2.29 has added the ping protocol. In the/apps/folder, you can directly write scripts for testing.
Finally, let's turn to the question about the send function, which I didn't understand when writing the protocol.
Because the OTCL method of send is not defined in Agent/ping, pingagent: Command will be called through cmd, parameter
Is "send"
// Send the packet
Send (Pkt, 0 );
The implementation of "send" on the parent agent of "send" is as follows:
Void send (packet * P, Handler * h) {target _-> Recv (p, H );}
In this case, the Recv function of the subclass pingagent is called.
In the Recv function of pingagent, there is a Tcl. eval (out) Call. At this time, the out value contains Recv. Therefore, it will eventually call
Recv of the otcl process added in the test script.
Do you understand? In fact, you can trace the code stream to know the entire process, or even the specific value of out.