Modify Trace File on ns-2

to reduce your trace file size or clear what you want to to see or analyse trace file easily first of all you should learn how to rerad trace file then you can modify your trace file as follows.

Modified folders: ns-2/trace/cmu-trace.cc, cmu-trace.h

1.Add new format type in cmu-trace.h.
class CMUTrace : public Trace {
public:

……
void format_x(Packet *p, int offset);

};

2. Defined new format type in cmu-trace.cc.
……
//
#include
……

void CMUTrace::format_x(Packet *p, int offset)
{
struct hdr_ip *ih = HDR_IP(p);
hdr_iett *hdr = hdr_iett::access(p);
double x = 0.0, y = 0.0, z = 0.0;
char op = (char) type_;
node_->getLoc(&x, &y, &z);
FILE * pFile;
int src = Address::instance().get_nodeaddr(ih->saddr());
pFile = fopen (“myfile.tr”,”a”);//if you want to have net values you should save the current .tr and .nam //thats why you should geberate new file to save your trace file lines…

if (op == ‘r’ && src!=src_)
{
switch (hdr->x_pt)
{

case xxxxx:

fprintf (pFile, “%.9f %d %d %s\n”,Scheduler::instance().clock(), // packet reception time
src, // packet src
src_, // packet receiver
x_packet_type_names[hdr->x_pt] //packet type
);
}

break;
default : {;}
}

}
fclose (pFile);
}

If you get an error “Segmentation fault” pls check your file read and write operation…

If you get “Floating point exception” pls check your numerical values. Maybe you missed somthing in your rpogram.
For example; may be you are trying to divide your number to the ZERO
may be you are trying to generate a random index from your array even it is not get any value in it.

48 thoughts on “Modify Trace File on ns-2

    • hdr_iett is just a packet name… you can’t find because we generated it…It means you can generate new type of packet pr packet header..

  1. dear sir i try to using emulation facility in NS-2,
    but i got error “Floating point exception” .Based from your blog,
    Can you explain to me where i’ve to check numerical values, in my tcl simulation script or the others folder in ns2?
    i’m using ns2 version 2.33 and i try to implements greedy perimeter stateless routing (gpsr) .Thanks for your attention.

    • Floating point exception means you are trying to devide something to zero… but it is not exact answer just such an example of getting that error message.
      In ns-2 there is no any (my observation) division problem just you chech your calculation for example maybe you are trying to find a number in your array even if your array is empty this is just an example i couldnt know what is the exact answer but YOU SHOULD CHECHK YOUR CALCULATION debug your code…

  2. Hello Sir,

    I don’t want the new format. I just want to do some changes in the current format. Thats it.
    So, how could it be done?

  3. dear sir, i have one entry in packet cmn header that is channelindex_, i want to display that value in trace file too. how can i display that?
    thanks

  4. Hi There,

    I have ns-2.29 installed on my pc i want to analyse energy parameters on the aodv and dsr routing protocols using awk scripts.
    My tcl file is giving me errors anytime i run them,have you pls got any tcl files that incorporates energy parameters and also how to go abt the analysis. do you think i need to upgrade the version of my ns-2 as i think most of my errors are compatability issues as im using vista.
    Thanks and ope to hear frm u soon.

  5. Sir,
    I am facing of problem of floating point exception in modified aodv.cc file.please let me know how to handle it.
    regards
    Umang

    • I also faced that problem… I found solution as checking my calculations and I realized that my array doesnt have any value and I my calculation try to use for division. thats why you should check your calculation. maybe you try to divide some number to zero or something like that.
      because ns-2 doesnt have any problem about calculation…
      (at least thats was my problem because this error mesaage like error no meaning )

  6. i am using ns 2.29
    and i want to know the trace file format and how to read it to extract information from it using awk
    example:
    s 0.505582352 _5_ RTR — 0 AODV 237 [0 ffffffff 2 800] ——- [5:255 -1:255 29 0] [0×2 2 1 [4 0] [2 4]] (REQUEST)
    s 0.506864067 _3_ RTR — 0 AODV 237 [0 ffffffff 2 800] ——- [3:255 -1:255 29 0] [0×2 2 1 [4 0] [2 4]] (REQUEST)
    r 0.508346725 _2_ RTR — 0 AODV 196 [13a 2 4 800] ——- [4:255 2:255 30 2] [0×4 1 [4 4] 10.000000] (REPLY)
    s 0.508346725 _2_ RTR — 0 cbr 520 [0 0 0 0] ——- [2:0 4:0 30 4] [0] 0 0
    s 0.510000000 _2_ AGT — 2 cbr 500 [0 0 0 0] ——- [2:0 4:0 32 0] [2] 0 0
    r 0.510000000 _2_ RTR — 2 cbr 500 [0 0 0 0] ——- [2:0 4:0 32 0] [2] 0 0
    s 0.510000000 _2_ RTR — 2 cbr 520 [0 0 0 0] ——- [2:0 4:0 30 4] [2] 0 0
    what each field means.
    please reply me as soon as possible.
    thanks

  7. hello sir.
    i want to calculate energy consumed by the nodes……so i m in need of awk file for energy..pls do the needful……..

  8. Hi
    if i want to send my own traffic ,I mean NS2 read the content of a file and send them ,like a log if video ,Do you know what should I do ??

  9. Hi
    if i want to send my own traffic ,I mean NS2 read the content of a file and send them ,like a log if video ,Do you know what should I do ??

  10. hello sir……………….
    i am calculating throughput and delay for AODV tcl script……………but am unable to verify whether the generated output is correct or not……………….pls help me

  11. hi my dear friend
    i have many question in ns.

    1) how i can simulate a webserver (how code or command or class & objects?)

    2) how i can install gnuplot?
    - how i can show the output analyze file, in gnuplot? (how code or command?)

    3) if i use SCTP Protocol&Agent,how should i do? (how code or command?)

    very thanks…

  12. Hi i’m new user to ns2 and i want to piggyback or combine two packets at a time and then send those packets in the multicast networks. Is it possible by ns2?

  13. Dear Sir
    I wanted to know how can I run a ns2 project if I have common, mac, tcl, tcl and trace folders in a project with their respectictive codes in a certain project.
    Thank you.

  14. hi sir
    i too need awk file for energy consumption for AODV and AOMDV..tel me how to view enerrgy information in old trace format..

  15. sir i want to change my trace file in this format “s -t 1.000000000 -Hs 0 -Hd -2 -Ni 0 -Nx 252.64 -Ny 235.76 -Nz 0.00 -Ne -1.000000 -Nl AGT -Nw — -Ma 0 -Md 0 -Ms 0
    -Mt 0 -Is 0.0 -Id 1.0 -It cbr -Il 512 -If 0 -Ii 0 -Iv 32 -Pn cbr -Pi 0 -Pf 0 -Po 4″ How could it possible where i need to change please explain me ……….

  16. Hi,
    i’ve simulated a flat wsn of 5 nodes with mobility ( mobility pattern is generated using bonnmotion tool) and sink is placed in the middle of the sensing field of 100x100m. the trace output shows that all the application level packets get dropped and 0 packets received at the sink. the reason of packet drop is either ARP or NRTE, trace output also shows the exact movement of sensor nodes as provided. please guide whats wrong with the simulation that sink is not receiving any data.
    regards,
    najma

  17. Hi,
    I used NS2.34 in linux, I work with a ring topology traffic multicast. In the tcl code I used join/leave, in the trace file there are prune.
    The problem is that I can not remove the prune in the trace file. Please help me if possible to remove the prune.
    Thank you for your help

    • In order to have custom trace file there are some setting change or commands. I dont remeber exactly whic one the solution but you can change the trrace file library and rebuild it again. Please read ns-2 document Tracing section

  18. Respected,
    I want to utilize energy trace from old trace format of sensor node, but unable to get it.
    So will you pls provide me some guidance regarding the same.

  19. hey hilal ,,hope u r fine :)..
    i tried to modify ns2 energy model , i added life time function, that calculate life time of specific node at specific time ..then i tried to print lifetime value in my trace file (in case of using energy model).. to get the following output in my trace file ..” [energy xx.xxx ei 0.xxx es 0.xxx et x.xxx er x.xxx lifetime 0.xxx]”
    1- in cmu-trace.cc file (line 345) ,i changed sprintf command line to be as the following ”
    sprintf(pt_->buffer() + offset,
    “[energy %f ei %.3f es %.3f et %.3f er %.3f lifetime %f] “,
    thisnode->energy_model()->energy(),
    thisnode->energy_model()->ei(),
    thisnode->energy_model()->es(),
    thisnode->energy_model()->et(),
    thisnode->energy_model()->er(),
    thisnode->energy_model()->lt());
    2- i recompiled ns2 using make command and i did’t get any errors..

    MY PROBLEM IS : when i simulate a simple script using energy model ..lifetime doesn’t appear in my trace file ..& i don’t know the reason of this .. do i have to change something else for example? ..
    hope that u can help me in this situation..

    regards,
    Dalia Elewely

    • Hi, if u read ns2 pdf it should tell what u need to do, also u can read the post related with the trace file. I do not have comp currently for this reason i couldnt provide the elaborated answer :(

  20. Hi mam,
    I’m working on aodv routing protocol. Initially, in network deployment phase every node should broadcast packets for a certain period of time. This should be done before aodv routing protocol starts. Mam how can i get all broadcasting details in trace file. Mam i need your help. Waiting for your replay.

    regards,
    Ajay

    • When u do tracing all the data are automaticlly stored in the trace file.,, of course after u run nam….
      As an advice please try extremely simple
      Examples before u dive into…. Enty of examples in ns2 example folder….

  21. hello hilalkaratoy,
    I need your help, I’m trying to evaluate energy for DSR,DSDV and AODV respectively. I’m having problem with DSDV, when I play in nam I can not the traffic flow between senders and destination therefore in the trace file there are alot of drop packets. do you have any idea what is wrong?
    FYI: using same scenario for others was fine

    thanks

  22. I’m learning ns2 and I got the error “floating point exception” when I am trying to simulate
    ” simple-wireless.tcl” which is an example located into [ns2.34/tcl/ex folder] and dont change anything of that file.

    Would you plz help me, what type of issues may cause this problem.

    Thanks

    • Do u provide any input? Else print the internal parameter and see which parameter causes this error, also u can pick up another example or simplfy the current one…
      I run the example tcl files they were fine…

  23. Hi, I m simulating leach protocol to find the movement of node’s if any using getvel() function. I m getting floating point exception error during tcl script execution. I’ve not used any function except the methods available on the web for finding node’s position, energy and velocity during simulation. Please guide how to resolve this issue?

  24. Hi
    I going to add 1 octet to my paquet (size=512) so means that in this ligne : $cbr set packetSize_ 512 : add 8 to 512 or what ?????

    • There could be
      loop somewhere, or
      time you set could be more than you think, or
      there is another node communicating with it or
      you have mistaken to read the trace file

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s