[ns] node id at the c++ code

P.Reena p050001ee at nitc.ac.in
Mon May 26 03:32:15 PDT 2008


Hi,
I am also a beginer in ns2. But I think I can share some of the tips I
think useful to you:
1)
To get the node id of an intermediate node, you can try to display the
variable "index_" from some where in mac-802_11.cc code. For eg add the
line
printf("id of the current node is %d"\n", index_);
        Don't forget to "make" the ns2, if you have made any chanes to any
c++ code.

        The entry point of mac-802_11.cc for the packet is the recv()
function.
Starting from that function, go through the mac-802_11.cc code, and add
the above line in some suitable place.


2)
If you want to write something to some file, say out1.txt from the
802_11.cc code, indirectly through tcl:
open the file out1.txt from the front end tcl code, and set the file
pointer as fp1 by:
        set fp1        [open out1.txt w]

Then somewhere in the mac-802_11.cc file ( say in the recvDATA()
function), add:

        u_int32_t dst, src, size;
        struct hdr_cmn *ch = HDR_CMN(p);        // access the common
header of the packet
        size = ch->size();

        struct hdr_mac802_11 *dh = HDR_MAC802_11(p);        // access MAC
header of the
packet
        // please refer packet.h/cc in folder ~ns/common
        dst = ETHER_ADDR(dh->dh_ra);
        src = ETHER_ADDR(dh->dh_ta);
        double now = Scheduler::instance().clock();


        Tcl& tcl = Tcl::instance();
        char wrk[150];
        sprintf(wrk, "puts $fp1 \"from recvDATA time=%f  node=%d sorce=%d
dest=%d, size=%d\" \n", now, index_,src, dst, size);
        tcl.eval(wrk);

        This will print the current time, id of the intermediate node,
source and
destination node and size of the CBR packet.
        I think to get the sequence number of that packet, you can print the
variable:
                        dh->dh_scontrol

        Please try it. Hope this may help you

Reena,NITC







More information about the Ns-users mailing list