Add Ping Protocol

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.