Common C ++ and Tcl commands for NS2.

Source: Internet
Author: User

In the simulation of NS2. some TCL commands or fixed C ++ usage are often used repeatedly. The preliminary summary is as follows:

TCL command:
$ NS at time task
$ NS simple-Link
$ NS Duble-Link

C ++:
Get the current TCL Interpreter: TCL & TCL = TCL: instance ();
Execute the specified command in C ++: TCL. ev1c ()
Obtain the current time: Double cur = simulator: instance (). Clock ();

Commands related to node processing: 1. Obtain the specified header: method 1. HDR _ *: Access (packet); Method 2: Macro HDR _ * (packet)

# Define hdr_cen (p) (hdr_cen: Access (p ))
# Define hdr_arp (p) (hdr_arp: Access (p ))
# Define hdr_mac (p) (hdr_mac: Access (p ))
# Define hdr_mac802_11 (p) (hdr_mac802_11 *) hdr_mac: Access (p ))
# Define hdr_mac_tdma (p) (hdr_mac_tdma *) hdr_mac: Access (p ))
# Define hdr_smac (p) (hdr_smac *) hdr_mac: Access (p ))
# Define hdr_ll (p) (hdr_ll: Access (p ))
# Define hdr_hdlc (p) (hdr_hdlc *) hdr_ll: Access (p ))
# Define hdr_ip (p) (hdr_ip: Access (p ))
# Define hdr_rtp (p) (hdr_rtp: Access (p ))
# Define hdr_tcp (p) (hdr_tcp: Access (p ))
# Define hdr_sctp (p) (hdr_sctp: Access (p ))
# Define hdr_sr (p) (hdr_sr: Access (p ))
# Define hdr_tfrc (p) (hdr_tfrc: Access (p ))
# Define hdr_tora (p) (hdr_tora: Access (p ))
# Define hdr_imep (p) (hdr_imep: Access (p ))
# Define hdr_cdiff (p) (hdr_cdiff: Access (p)/* chalermak's Diffusion */
// # Define hdr_diff (p) (hdr_diff: Access (p)/* scadd's diffusion ported into NS */
# Define hdr_lms (p) (hdr_lms: Access (p ))

2. Obtain the reference of the C ++ object based on the global ID value of the passed object.
Tclobject: Lookup (*)
Here, the input value is the Globally Unique id value corresponding to each tclobject. It usually appears in the form of _ O + integer, such as _ O4
In fact, the ID value of tclobbject is passed in through O-> name (argv [0]) in the create_shadow function. The value of this argv [0] Is In The OTCL script, when the new OTCL object is executed, it is returned by the getid method of the splitobject of OTCL;
Therefore, if we can obtain the specific type of tclobject and know its globally unique id value, we can get it through TCL: Lookup (ID, then, convert it to a specific type. (In fact, lookup is a non-static member function implemented in the Tcl class. tclobject is only called indirectly through the static instance of the Tcl class. What's interesting is that, when each tclobject object is stored, it is also implemented through the non-static member function enter of the Tcl class)

A node has a GETID, But it returns the node ID corresponding to the node location (by default). It is different from the global ID. Therefore, even if the node id value is obtained, the reference of the actual C ++ image of the node cannot be obtained.

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.