Pages

Sunday 11 November 2012

Adding a new module and Recompiling NS2 using “Make” command

To add a module in Ns-2 is not a simple task especially for beginner. There are two cases in which the NS2 need to be recompiled.
1. Modifying the existing algorithm (use the same header and the C++ source files)
2. Adding new files/Protocols (adding new header and C++ source files)

 Modifying the Existing Algorithm:
Step 1: open the shell prompt and go to the ns-allinone-2.34/ns-2.34/ folder(there are 3 makefiles, Makefile.vc, Makefile, Makefile.in, for adding any new file should be done at the Makefile.in file)
Step 2: Once the existing algorithm is changed, go to step 1.
Step 3: execute the following command,
make clean
make depend
make
If you have no errors in the modified code, then the compilation will be success and NS will be created, else you may get errors, which needs to be fixed.
Step 4: Test your TCL script for the new algorithm.

Adding New Protocol:
Step 1: open the shell prompt and go to the /home/user/ns-allinone-2.34/ns-2.34/ folder(there are 3 makefiles namely Makefile.vc, Makefile, Makefile.in, for adding any new file should be done at the Makefile.in file)

Step 2: You may create new header and C++ source files for your new proposed algorithm and hence you need to tell that information to the Makefile.in (which is available in ns-allinone-2.34/ns-2.34/).

Step 3: Put all your files inside a respective folder under the folder /home/user/ns-allinone-2.34/ns-2.34/

Step 4: Now open the Makefile.in using any editor (usually vi or gedit) and add the folder information to the OBJ_CC variable)

Step 5: anywhere inside the OBJ_CC variable, put the New file/folder information.
For example:  "newfolder/newfile.o  \"

Step 6: after editing the file entry, follow these procedures:
  1. Go to NS2 location in terminal (If you are using ns-allinone-2.xx, then go to  ns-allinone-2.xx/ns2x)
  2. Then type "./configure" in terminal (The Makefile will be replaced with modified one.)
  3. Then type "make clean" (*optional))[use this, If you want to recompile the whole ns2. This will remove all the object files in NS2].
  4.  Then type "make" [this will make all object files which are missing]
 If you have no errors in your modified code, then the compilation will be success, else you may get errors, which needs to be corrected.

Step 7: Now test your TCL script for the new protocol.

74 comments:

  1. Hi Mr.

    could you help me?! how to get signal strength in aodv.cc ?

    help me please ...

    best regards
    khozaimi

    ReplyDelete
    Replies
    1. The posttranslational modification of eukaryotic proteins by the addition of isoprenyl lipids at their C-termimi was first observed in the 1970s and 1980s. Peptide C-Terminal Modification

      Delete
  2. Hi! I would like to implement SPIN protocol and Tinysec Protocol in ns2.29

    Kindly give me insight to the above

    Regards
    John

    ReplyDelete
  3. hi,
    I define a new protocol in NS name Buddy. I create 3 files Buddy.cpp, Buddy.h and Buddy_packet.h
    after run make command, i get some errors for i.e
    Buddy.h: error: ip.h: No such file or directory
    i use ip.h header file in Buddy.h
    although ip.h is not missing, this error happen.
    is it possible to help me?

    Reply

    ReplyDelete
    Replies
    1. Yeh, u need to include the ip.h file....
      in the mean time, you have to define the new packet structure in the packet.h too else how it will recognize your packet i.e. buddy_packet, during run time...

      So, just go to ip.h and packet.h and see, there are few packet definitions already exists, in the similar way, you need to define for your packet too.... now compile the NS, and proceed...

      All the best.. :)

      Delete
  4. Hello! I followed the the first one (Modifying the Existing Algorithm:) but get error like
    g++ -Wl,-export-dynamic -o common/ptypes2tcl common/ptypes2tcl.o
    ./common/ptypes2tcl > gen/ptypes.cc
    /bin/sh: 1: cannot create gen/ptypes.cc: Permission denied
    make: *** [gen/ptypes.cc] Error 2
    how should i fix this error plz help rozbajracharya@gmail.com

    ReplyDelete
  5. hi, i have added new module in ns2.33 but aftr 'make' am getting error like
    make: *** [common/scheduler.o] Error 1
    can u plzz help me to resolve this error

    ReplyDelete
    Replies
    1. HI,

      As you have added new modules/files and running the MAKE command, However, your ns code is not able to create "scheduler.o" file which is located in the common folder. There might have some error or dependency missing in Scheduler.cc or in Schedule.h. Please check it care fully and proceed . Good Luck

      Delete
    2. thank you
      while running tcl file for new module i am getting error as
      warning: no class variable Tracefile::debug_

      see tcl-object.tcl in tclcl for info about this warning.

      warning: no class variable Agent/RTP_v2::ptype_

      see tcl-object.tcl in tclcl for info about this warning.

      could not stat starwars.nsformat
      Segmentation fault
      can u help??

      Delete
  6. Hai sir,
    I want to modify the TFRC protocol specification. so I modify the code in dccp_tfrc.cc file. I didn't change anything in Makefile.in. Then I execute the above commands. There is no change in results of thet code. That's why am having doubt is it correct process or not. If not Please tell me correct procedure for make a file. Please reply me sir as early as possible.

    ReplyDelete
  7. Sir

    I want to integrate the new code in ns2 using the instructions in http://sce.uhcl.edu/transa/Sourcecode/NS-2_Security_Node_Document.doc‎

    But there is not mentioned.... where to place the files ..

    I am trying to run but it is showing the error in recompiling using make

    Gaurav Kumar
    leo_gaurav@rediffmail.com

    ReplyDelete
  8. Hi..
    I make the steps to make my new module working but when I try to call it “$ns duplex-link $N $D 2Mb 1ms LAS”, I got error “invalid command name "Queue/LAS"”


    invalid command name "Queue/LAS"
    while executing
    "Queue/LAS create _o16 "
    invoked from within
    "catch "$className create $o $args" msg"
    invoked from within
    "if [catch "$className create $o $args" msg] {
    if [string match "__FAILED_SHADOW_OBJECT_" $msg] {
    delete $o
    return ""
    }
    global errorInfo
    error "class $..."
    (procedure "new" line 3)
    invoked from within
    "new Queue/$qtype"
    ("default" arm line 3)
    invoked from within
    "switch -exact $qtype {
    ErrorModule {
    if { [llength $args] > 0 } {
    set q [eval new $qtype $args]
    } else {
    set q [new $qtype Fid]
    }
    }
    intserv {
    set qtyp..."
    (procedure "_o3" line 14)
    (Simulator simplex-link line 14)
    invoked from within
    "_o3 simplex-link _o10 _o13 2Mb 1ms LAS"
    ("eval" body line 1)
    invoked from within
    "eval $self simplex-link $n1 $n2 $bw $delay $type $args"
    (procedure "_o3" line 8)
    (Simulator duplex-link line 8)
    invoked from within
    "$ns duplex-link $N $D 2Mb 1ms LAS"
    (file "LAS.tcl" line 29)


    I don’t know where I have to make changes.
    Please, help me about that

    Thank you

    ReplyDelete
    Replies
    1. BTW, what is the new module you are trying to add???
      In your case, it seems your object file for the Queue/LAS is not generated properly.
      please check the installation procedure...

      Thank you..!!
      Hema

      Delete
  9. the above problem am facing please help me sir.

    ReplyDelete
  10. hello sir i want a new protocol called atcp but the file is not compelling i tryed many methods including ur proposed above method sir will u help me sir

    ReplyDelete
  11. sir i got make.in file.but it is empty.i have to change cc file of aodv.plz help me. give proper steps for it

    ReplyDelete
    Replies
    1. Modifying the Existing Algorithm, you just add the new piece of code in the respective CC file and the go to the terminal and follow the steps given in Modifying the Existing Algorithm:" part only. if you open the Make file, it will show nothing... this is just an executable file.

      The "Makefile.in" contains all the dependencies and from there we just run the ./configure command to get the new MAKE file.

      for you case just make changes in the aodv.cc file and run the three necessary commands, i.e make clean, make depend and make. this much will reflect the changes you have made..

      Thank you..!! HK :)

      Delete
  12. i had copied existing red.cc red.h in queue and renamed as mdred.cc mdred.h ,and performed above given steps,and also executed the tcl script with mdred .it executed correctly but when i added the new varibles to mdred.h and mdred.cc and again performnig the above steps, i executed tcl scipt as before but it is showing segmentation fault how to remove.y i am getting this error how to solve it

    ReplyDelete
    Replies
    1. segmentation fault usually comes, when you access variables that are not initialized properly. I guess the error is with the new variables. please go to place where you declared the new variables, make the changes carefully and you also need to reflect the necessary changes in other related files as well.

      Hema. :)

      Delete
  13. hi how to create clusters in tcl and to choose cluster head

    ReplyDelete
    Replies
    1. Hi,

      In general cluster are two types: static and dynamic.


      Static Cluster can be formed by placing all nodes fixed and selecting few nodes as cluster heads and, data exchange between cluster headscab be achomplished using any clustering algorithm. This can be done using the TCL Script. Please find the URL, where you will find the TCL code for LEACH (popular sensor network protocol). Just go through it and learn how to form statc cluster using TCL scprit.

      http://www.codeforge.com/read/238167/leach.tcl__html

      For Dynamic cluster, youi have to use the random movement feature and is bit difficult. But this can also be implemented using NS2. Here you need to make some changes in the core code of the NS.

      Hope i have answered your quetion. :)

      --
      Hema

      Delete
  14. hello,
    this post to add new module in ns2 is really helpful.
    i am working on a project to add a new code and i applied the steps for adding new module, obj file is created successfully in the respective folder but when i tried tcl file with ns command it shows 'Segmentation Fault'.
    i removed the added file, tried to recompile ns again. the prior codes which have been running successfully are showing the same error when executing.

    can you please tell me the solution.. i only know that ns is not completely generated.
    thank you..

    ReplyDelete
    Replies
    1. hi please let me know what module you are trying to implement ,have you tried the same with any other tcl script

      Delete
    2. Dear Anonymous,

      Thank you very much for your complements.. :)

      As the obj file is created successfully, there is no problem with the procedure. There may have some bugs in the new code itself (Say array was accessed wrongly or variables which are not declared correctly are accessed during the execution),

      Please go through the newly added code and check carefully for the bugs. Placing checkpoints (i.e. using printf() statements) and checking is an hit and trail method to find the location of the segmentation fault...

      All the best... :)

      --
      Hema

      Delete
    3. hi,

      Thanks for the suggestions..
      The "segmentation fault" is coming for even typing ns only, after running ./configure and make commands... seems ns is crashed (I have not executed my code yet). Before that ns is working properly. nam and xgraph is working fine everytime.
      Is it possible that any flag setting or any path setting changed ?
      After reinstalling ns2, previous scripts work fine.





      Delete
    4. In your case, it seems you have some bug in the new patch or module you are adding to NS. What is the new module you are trying to add?? Please make sure the patch is in working condition.

      Delete
  15. I must thank you for providing guidance on ns2.I am facing an issue.I have installed ns2.31 with crn patch.Now, if I use make depend and make command,it says permission denied.Please help me out.I use ubuntu 13.10.I find locks on certain folders in allinone folder.

    ReplyDelete
    Replies
    1. Dear Gokul Krishnan,

      Are you doing the installation is SuperUser mode??? if not just switch to it and try. I have installed CRN patch few time too.. i never encountered this problem.... For more information for Patching CRN in NS you can follow one of my old posting. The link pasted bellow. Still if you have more quires please post them here clearly.. happy to answer

      http://2bytes4u.blogspot.in/2012/11/cognitive-radio-cognitive-network-crcn.html

      All the best.. :)

      --
      Hema

      Delete
    2. Thanks for helping me out.I have now installed ns-allinone-2.31 with crcn patch.I want to add database capability to it while assigning channels for mobile nodes.I have completed accessing database tables from tcl script.I want to provide channel selection capability using the channel usage history and assigning it based on idle time.Please help me out to find the location where modifications are to be made.Thanking you

      Delete
    3. Hi, You can store the channel usage history in a separate file(may be .txt file) and require to implement the new channel selection capability in the in the .cc files. The best place add the part of the code is the MAC protocol file you are supposed to use for simulation. In the code itself you have to access the "channel usage history file" and perform the selection part. To the best of my knowledge, this the MAC file is the best place to adopt the selection changes.

      All the best... :)

      Delete
  16. Sir,
    I made some changes in .cc files and now i want to run make command it will give error trace/trace-ip.o: file not recognized: file trucncated collect2: ld returned 1 exit status

    please help

    ReplyDelete
    Replies
    1. Have you made any changes in the trace files?? If yes, be sure the changes do not contain any errors which are not allowing the creation of object file (.o file). You have an error with generation of the "trace-ip.cc"'s object file. Also check in the "Makefile.in", you might have made some changes unknowingly.

      Delete
  17. if i execute make clean command the i get the following error
    make: *** No rule to make target `clean'. Stop.

    ReplyDelete
    Replies
    1. Navigate to the folder, where your NS files are present. Then execute the "make clean" command.

      Delete
    2. I navigated to the folder ns-allinone-2.xx/ns2x and executed the command and I'm still getting the same error.

      Delete
    3. Use the terminal and navigate to the NS folder (where your ns executable is present) and run the following commands and reply me with the errors you are getting.

      ns (after executing this you should get a "%" symbol in your terminal. Otherwise your installation is not successful)
      and
      make clean

      Delete
  18. hello sir..i am working with the aggregating clustering with AODV. ,but confused how to start, If u provide me tcl script of clustering in MANET , i shall be very much obliged to you.

    ReplyDelete
    Replies
    1. Hi,
      For aggregating clustering with AODV, Only TCL script is not enough you have to make changes in the AODV.CC file well. Then, using the TCL script to call the function responsible for aggregating clustering. The clustering logic should be placed in AODV.CC file

      Sorry, currently i don't have any files with me. Probable you will get the logic on some in some research article.

      You are welcome to discuss if any more issues are there. Thank you..!!

      Delete
    2. That clustering algorithm should be in leach protocol thanks !!!!

      Delete
  19. hi Sir:
    Can you help to do this problem?
    invalid command name "Queue/Blue"
    while executing
    "Queue/Blue create _o246 "
    invoked from within
    "catch "$className create $o $args" msg"
    invoked from within
    "if [catch "$className create $o $args" msg] {
    if [string match "__FAILED_SHADOW_OBJECT_" $msg] {
    delete $o
    return ""
    }
    global errorInfo
    error "class $..."
    (procedure "new" line 3)
    invoked from within
    "new Queue/$qtype"
    ("default" arm line 3)
    invoked from within
    "switch -exact $qtype {
    ErrorModule {
    if { [llength $args] > 0 } {
    set q [eval new $qtype $args]
    } else {
    set q [new $qtype Fid]
    }
    }
    intserv {
    set qtyp..."
    (procedure "_o3" line 14)
    (Simulator simplex-link line 14)
    invoked from within
    "$ns simplex-link $n1 $n2 1Mbps 100ms Blue"
    (file "blue.tcl" line 41)
    I installed the AQM of Blue in the ubuntu 12.04 and used the ns-2.35.
    I changed Makefile.in and ns-default.tcl ns-lib.tcl and added the ip.h blue.cc blue.h.
    It still have this problem.
    How should I do now?
    Please help me.
    Thank you.

    ReplyDelete
  20. if i execute make clean command the i get the following error
    make: *** No rule to make target `clean'. Stop.

    ReplyDelete
  21. what is that error sir iam give ns in terminal get i am % symbols sir so i am got installation is sucessfully installed.why i am get the error pls help me......please egarly waiting for your response......

    ReplyDelete
  22. its coming on aodv.cc file modification after compile that i make clean,make,make install all are coming so i get make: *** No rule to make target `clean'. Stop....this error at any time

    ReplyDelete
    Replies
    1. perform the following in superuser mode.
      make sure you have .o files in the folders. if yes run the following commands.
      make clean
      make depend
      make

      Still, you are getting any more errors, just post it here. I will try to add more if any require.

      Delete
  23. how to perform superuser mode ..tel me clearly sir ....

    ReplyDelete
  24. sir i do this sir
    cd/home/ns-allinone-2.35/ns-2.35
    cd /home/dharman/ns-2.xx/ns-xx
    make clean
    make:***** no rules to make target 'make clean'.stop
    make depend
    make:***** no rules to make target 'depend'.stop
    make
    make:***** no rules to make target 'make'.stop
    ./configure
    its working but finally configure:error Installation of tcl seems incomplate or cant be fount automatically..
    please correct problem by telling configure with tcl is using argument ---with-tcl=/path/to/package(perhaps after installing it),
    or package is is not require,diasble it with--tcl=no.
    please help me sir i how to solve thsis solution.any changes i can do path setting..

    ReplyDelete
    Replies
    1. ./configure --with-tcl-ver=8.5 (or 8.4 whatever u have ) <-- it works for me

      Delete
    2. Hey,
      Could you solve this error?
      If Yes, than please do post the solution. As i am stuck at same place.
      Waiting for your help.
      Thank you..
      Mirali

      Delete
    3. ./configure --with-tcl-ver=8.5


      use this command instead ./configure

      Delete
  25. i can add aodv.cc aodv.h add malicious node in ns-2.35 folder .how to run and get object file sir please help me sir its very urget to my project work .and lot of forum to say my error but no reply sir pls find out what is that problem

    ReplyDelete
    Replies
    1. can u send me yr codes to me i am also finding malicious nodes i am new to ns-2 i want to find the neighbor position any one send the code to me plzzzzzzzzz my mail id ramya.sns@gmail.com

      Delete
    2. please mail me my mail id is "viratharish921@gmail.com" i can solve this issue

      Delete
  26. sir again i get this error sir please help me

    ReplyDelete
  27. i want to add a new module queue to NS2.
    i made changes into ns-compact.tcl, ns-queue.tcl, ns-default.tcl, ns-route.tcl, ns-lib.tcl, but object file o did not create.(i had done make). please help me completely.

    tankyou.

    ReplyDelete
  28. hiii... i am new to ns-2 i want to find the neighbor position any one send the code to me plzzzzzzzzz my mail id ramya.sns@gmail.com

    ReplyDelete
  29. i 'm new to ns 2 , when i'm try to run ./configure command in terminal i got error like this ..
    -------------------------------------------------------------------------------------
    configure: error: Installation of tcl seems incomplete or can't be found automatically.
    Please correct the problem by telling configure where tcl is
    using the argument --with-tcl=/path/to/package
    (perhaps after installing it),
    or the package is not required, disable it with --with-tcl=no.
    ----------------------------------------------------------------------------------

    after that i run this command
    ./configure --with-tcl-ver=8.5
    it gives me this output
    -------------------------------------------------------------------------
    configure: creating ./config.status
    config.status: creating Makefile
    config.status: creating tcl/lib/ns-autoconf.tcl
    config.status: creating indep-utils/webtrace-conv/ucb/Makefile
    config.status: creating indep-utils/webtrace-conv/dec/Makefile
    config.status: creating indep-utils/webtrace-conv/nlanr/Makefile
    config.status: creating indep-utils/webtrace-conv/epa/Makefile
    config.status: creating indep-utils/cmu-scen-gen/setdest/Makefile
    config.status: creating autoconf.h
    config.status: autoconf.h is unchanged
    ---------------------------------------------------------------------

    anyone has solution? pls ack me.
    Thanks in advance

    ReplyDelete
  30. I am new to ns2.
    I have created a new agent and I made all the changes in makefile.in and packet.h files. But when I execute the script, it gives me the following error

    invalid command name "Agent/Crnca"
    while executing
    "Agent/Crnca set scheme 2"

    Can anybody please help me??

    ReplyDelete
  31. I get error when i execute the following command
    make clean
    make depend
    make
    of
    "*** No rule to make target 'clean'. Stop.

    ReplyDelete
    Replies
    1. hello every one sometimes this crn patch works in ns-allinone 3.21 version only thanks!!!

      Delete
  32. Hi when I run make depend I get an error as pcap.h no such file or directory... Plz help

    ReplyDelete
  33. This comment has been removed by the author.

    ReplyDelete
  34. This comment has been removed by the author.

    ReplyDelete
  35. Hi sir,

    I want to fix the number of packets for transmission from node1 to node2 in wireless scenario. Like i need to transmit only 50 packets from node 1 to 2. If this is possible please send me the tcl script sir

    my mailid: gowthamsankarss@gmail.com

    ReplyDelete
  36. How can we send audio packets in NS -2 ?

    ReplyDelete
  37. sir, how to use protocols given in src folder ?

    ReplyDelete
  38. 1)I want to debug tcp.cc file,and want to see all printf statement what are there in traceall () function .Is there any way to do this?
    2) when I recompile ns2 with ./configure make,make clean it executes ,/configure well but for the rest two it gives an error like
    make:***** no rules to make target 'make clean'.stop
    Please guide me in this regard

    ReplyDelete
    Replies
    1. To see all the options in the traceall() function, you have to manually either dump them into a file or print them on the output screen. The earlier option is a better one to analyze easily.

      Regarding the error, The steps are as follows:
      > make clean
      > make depend
      > make

      Make depend is also important as it creates the necessary dependencies for creating the object file. Try the above sequence of commands.

      Delete
  39. I tries to add a new protocol in ns2.35. the command .configure and make clean is done but when I tries to make I encountered some error.
    the error is mcbrp/mcbrp.cc:171:11: error: ‘dmux_’ was not declared in this scope
    dmux_->recv(p, 0);
    ^
    mcbrp/mcbrp.cc:180:34: error: ‘rtable_’ was not declared in this scope
    nsaddr_t next_hop = rtable_.lookup(ih->daddr());
    ^
    mcbrp/mcbrp.cc:181:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if (next_hop == IP_BROADCAST) {
    ^
    mcbrp/mcbrp.cc:185:33: error: ‘debug’ was not declared in this scope
    ih->daddr());
    ^
    mcbrp/mcbrp.cc:186:43: error: ‘drop’ was not declared in this scope
    drop(p, DROP_RTR_NO_ROUTE);
    ^
    mcbrp/mcbrp.cc:192:41: error: ‘target_’ was not declared in this scope
    Scheduler::instance().schedule(target_, p, 0.0);
    what sould I do.

    ReplyDelete
    Replies
    1. Does the new protocol have any associated header files, where the function declaration is done. Do check for the same and add them in the Makefile.in as well.

      Check, where the "rtable_.lookup" declaration/definition is located and add all the files in the makefile. Hope this will suffice the purpose for a clean compilation.

      Delete
  40. This comment has been removed by the author.

    ReplyDelete
  41. I NEED HELP PLZ, I get error when i execute the following command
    ./configure
    make clean
    make
    /home/yasser/ns-allinone-2.35/tclcl-1.20/tclcl.h: In member function ‘void Tcl::result(const char*)’:
    /home/yasser/ns-allinone-2.35/tclcl-1.20/tclcl.h:90:44: error: ‘Tcl_Interp {aka struct Tcl_Interp}’ has no member named ‘result’
    inline void result(const char* p) { tcl_->result = (char*)p; }
    ^~~~~~
    Makefile:93: recipe for target 'webcache/pagepool.o' failed
    make: *** [webcache/pagepool.o] Error 1
    what shouls i do.

    ReplyDelete
    Replies
    1. What patch/module you are adding into the NS? It seems, your patch have some problem with the variable declaration. Check the code in tclcl.h carefully.

      Delete
  42. Hi

    After ./configure operation when I enter the commands make clean or make, it shows commands commence before first target. stop,

    Can u help me with this?

    ReplyDelete