TCL Script for My NS-2 Project

This is my simple tcl script for our project research by using NS-2.34. In this project, we are going to combine 2 protocols, AODV+ and R-AODV,  our proposed protocol called AODV-UI.

Here is the tcl script.


Code:

#=============================================================================
# ABDUSY SYARIF
# TCL AODV DESIGN
#=============================================================================
set opt(namfile)         nam_aodv_out.nam
set opt(tracefile)       trace-new-aodv_m5_h2.tr
set val(chan)    Channel/WirelessChannel;    #channel type
set val(prop)    Propagation/TwoRayGround;   #radio-propagation model
set val(netif)   Phy/WirelessPhy;            #network interface type
set val(mac)     Mac/802_11;                 #MAC type
set val(ifq)     Queue/DropTail/PriQueue;    #interface queue type
set val(ifqlen)  50;                         #max nbr of packets in ifq
set val(ll)      LL;                         #link layer type
set val(ant)     Antenna/OmniAntenna;        #antenna type
set val(adhocRP) AODV;                       #routing protocol
set val(x)       1000;                        #x dimension of the topography
set val(y)       800;                        #y dimension of the topography
set val(stop)    600.0;                       #simulation time
set val(mobility) "mobil5_4"
set val(start-src)     1
set val(stop-src)     600
set nbrOfWirelessNodes   5
set nbrOfWiredNodes      4
set nbrOfGateways        2
#set val(gw_discovery) reactive;                #gateway discovery method

Download the full tcl script here.

Advertisements

Tags: , , , , , , ,

61 Responses to “TCL Script for My NS-2 Project”

  1. computer running slow Says:

    I can see you’re an expert on TCL Script for My NS-2 Project | Abdusy Syarif! I am starting up a website in the near future, and your post can be very useful for me. Thanks for all your input. With very best wishes x

    Liked by 1 person

  2. ravi Says:

    thanks a lot sir ,
    but we have problem while executing progrmm
    pls help me

    ravi@ravi-desktop:~$ ns aodv3.tcl
    num_nodes is set 7
    INITIALIZE THE LIST xListHead
    couldn’t read file “mobil5_4”: no such file or directory
    while executing
    “source.orig mobil5_4”
    (“uplevel” body line 1)
    invoked from within
    “uplevel source.orig [list $fileName]”
    invoked from within
    “if [$instance_ is_http_url $fileName] {
    set buffer [$instance_ read_url $fileName]
    uplevel eval $buffer
    } else {
    uplevel source.orig [list $fileName]
    …”
    (procedure “source” line 8)
    invoked from within
    “source $val(mobility)”
    (file “aodv3.tcl” line 130)

    thank you

    Like

    • abdusy Says:

      You need a file called mobile5_4. You can create it by using setdest function.

      Like

      • Anil Says:

        i ran the setdest function in ../cmu-scen-gen/setdest
        ./setdest -n 5 -p 2.0 -s 10.0 -t 100 -x 100 – y 150 > mobil5_4
        i got the following error:
        assertion “speed != 0.0” failed: file “setdest.cc”, line 595
        Aborted ( core dumped)
        plzz help

        Like

      • Narendra Says:

        hi
        can you tell me how to link files generated in setdest function with tcl script
        as i am getting same error as ravi above

        Like

  3. abdusy syarif Says:

    Please choose, which one you will use in your simulation.

    usage:

    ./setdest -v -n -p -M
    -t -x -y

    OR

    ./setdest -v -n -s -m -M
    -t -P -p -x -y

    Like

  4. Narendra Says:

    how to run setdest function, i installed ns2.34 in /user/local/
    so when i tried running .sh file getting errors like
    [root@localhost pr]# ./make-scenario.sh
    ‘movement’ is a directory
    /user/local/ns-allinone-2.23/ns-2.23/indep-utils/cmu-scen-gen/setdest/setdest does not exist or is not executable
    [root@localhost pr]#
    whats the solution for this

    Like

  5. abdusy syarif Says:

    please read the manual how to use ‘setdest’. After you create a mobility file using ‘setdest’ utility, you can copy / call the mobility file in your tcl script.

    Like

  6. Anil Says:

    hey i have been following your blog lately, you have done some great work in NS2. i am too working on it and i need some help. there is an energy model available in ns2, do u know the tcl script that i should run to get the results from it

    Like

  7. abdusy syarif Says:

    You can use a simple tcl script in ns-allinone-2.xx/ns-2.xx/tcl/ex/wireless-newnode-energy.tcl

    Like

  8. Narendra Says:

    hi,
    can you tell me how to write tcl script for aodv that includes node movement or mobility,and cbr/tcp traffic and should show data transfer between source and destination node…

    Like

  9. Anil Says:

    #Create a simulator object
    set ns [new Simulator]

    #Open the nam trace file
    set nf [open out.nam w]
    $ns namtrace-all $nf

    #Define a ‘finish’ procedure
    proc finish {} {
    global ns nf
    $ns flush-trace
    #Close the trace file
    close $nf
    #Execute nam on the trace file
    exec nam out.nam &
    exit 0
    }

    #Create nodes

    set n0 [$ns node]
    set n1 [$ns node]
    set n2 [$ns node]
    set n3 [$ns node]
    set n4 [$ns node]
    set n5 [$ns node]
    set n6 [$ns node]
    set n7 [$ns node]

    #Create a duplex link between the nodes
    $ns duplex-link $n0 $n1 1Mb 10ms DropTail
    $ns duplex-link $n1 $n2 1Mb 10ms DropTail
    $ns duplex-link $n2 $n3 1Mb 10ms DropTail
    $ns duplex-link $n0 $n4 1Mb 10ms DropTail
    $ns duplex-link $n0 $n5 1Mb 10ms DropTail
    $ns duplex-link $n5 $n6 1Mb 10ms DropTail
    $ns duplex-link $n6 $n7 1Mb 10ms DropTail
    $ns duplex-link $n7 $n3 1Mb 10ms DropTail
    $ns duplex-link $n4 $n5 1Mb 10ms DropTail

    $ns duplex-link-op $n0 $n1 orient right-down
    $ns duplex-link-op $n1 $n2 orient right
    $ns duplex-link-op $n2 $n3 orient right-up
    $ns duplex-link-op $n0 $n4 orient right
    $ns duplex-link-op $n0 $n5 orient right-up
    $ns duplex-link-op $n5 $n6 orient right-
    $ns duplex-link-op $n6 $n7 orient right-down
    $ns duplex-link-op $n7 $n3 orient right-down
    $ns duplex-link-op $n4 $n5 orient up

    #Create a UDP agent and attach it to node n0
    set udp0 [new Agent/UDP]
    $ns attach-agent $n0 $udp0
    # Create a CBR traffic source and attach it to udp0
    set cbr0 [new Application/Traffic/CBR]
    $cbr0 set packetSize_ 500
    $cbr0 set interval_ 0.005
    $cbr0 attach-agent $udp0
    #Create a UDP agent and attach it to node n1
    set udp1 [new Agent/UDP]
    $ns attach-agent $n1 $udp1
    # Create a CBR traffic source and attach it to udp1
    set cbr1 [new Application/Traffic/CBR]
    $cbr1 set packetSize_ 500
    $cbr1 set interval_ 0.005
    $cbr1 attach-agent $udp1
    set null0 [new Agent/Null]
    $ns attach-agent $n3 $null0

    $ns connect $udp0 $null0
    $ns connect $udp1 $null0

    $ns at 0.5 “$cbr0 start”
    $ns at 1.0 “$cbr1 start”
    $ns at 4.0 “$cbr1 stop”
    $ns at 4.5 “$cbr0 stop”

    $udp0 set class_ 1
    $udp1 set class_ 2
    $ns color 1 Blue
    $ns color 2 Red
    $ns color 2 Red

    #Call the finish procedure after 5 seconds of simulation time
    $ns at 50.0 “finish”

    #Run the simulation
    $ns run

    …..
    i have written this code…the route it follows is from 0 to 3 via node 1.
    now i want it send packets using the route 0 to 3 via node 5
    (i.e 0-5-6-7-3)..how do i do that..plzz help

    Like

  10. yat Says:

    i can’t see any option of R-AODV, is it done in AODV or in the .cc file?

    And how the mechanism of switching between protocol?

    Like

    • abdusy syarif Says:

      It’s done in .cc. The mechanisme of R-AODV you can read from http://elmurod.net/sfiles/r-aodv.pdf

      Like

      • yat Says:

        can you pass me the .cc code? is it two different file (aodv.cc and r_aodv.cc) and somehow you calling from one another.or it’s done in aodv.cc alone?

        appreciate if you can email me the code…i’m doing something similiar in OLSR+DTN protocol..

        Like

      • yat Says:

        can you send me the .cc file? do you:

        1. calling each other from aodv.cc and r_aodv.cc file (two seperate file)?

        2. Putting the mechanism in aodv.cc file?

        I want to know the way combining two routing protocols together..

        Like

  11. Hassabu M. Ahmed Says:

    Hi everyone here!
    I need your help in my graduation project, which is about “GNDA: Detecing good neighbor nodes in ad hoc routing protocol”. I need the implementaion code (TCL) in ns-2, which is based on AODV. Any help will be appreciated!

    Like

  12. vicky Says:

    hi sir may i know how to implement mobile 5.4 package in ns2.34 please let me to know this detail .. reply me as soon as possible

    Like

  13. Hassabu M. Ahmed Says:

    Hi! I need your urgent help. plz! help me to finish my GP. I need to implement the attached flowchart in AODV using ns2.34.

    Like

  14. Hassabu M. Ahmed Says:

    The flowchart (GNDA flowchart) is found here:

    Like

  15. Ali Says:

    I have to create a Gateway Node which will act as a bridge between two ad-hoc nodes whereas both are running different protocols. I will appreciate if you guide i.e how to achieve/create this type of Gateway node. Can we do in tcl script or have to create in C++ ?. Is there any implementation of Gateway available which can be modified to solve the above problem.
    Will really appreciate your help.

    Thanks in advanvce

    Like

    • abdusy syarif Says:

      Hi Ali, you could refer to AODV+ or AODV-UU.

      Like

      • Ali Ray Says:

        Hi Syarif,
        In the above script:
        1- mobile nodes are communicating with wired nodes via gateways and no communication between mobile nodes.
        2- In script, there is only one routing protocol i.e. AODV and doesn’t show communication between different mobile routing protocols?
        3- The functionality of basestation is not clear, does it transform the packets from source to destination type. Can you explain or any good material on its internal functionality.

        Objective: I want to communicate between AODV and DSR via Gateway/Router/Basestation (whatever its called in ns-2).
        Your help will be highly appreciated.

        Thanks

        Like

  16. mamta Says:

    hi,
    can you tell me how to write tcl script for aodv that includes node movement or mobility,and cbr/tcp traffic and should show packet loss between source and destination node…

    Like

  17. saqib Says:

    AODV+ .. salam dear brother . You are doing great job by sharing codes unlike others. Brother , can you mail me whole code for Aodv+ protocol . i need to enhance it , MAy be will enhance in terms of load .. If you having souce code in NS3 , that will be most useful else ns2 will also work..

    Like

  18. tom Says:

    Hello sir,
    I am currently working on a project of detection and prevention of blackhole in clustered manet. It would be of great help if you could guide me as to where to start with and where can i get code for clustering the manet and implementing a blackhole attack?

    Like

  19. tom Says:

    Sir but i wanted the code for formation of a clustered manet first. Thank you for the link but it seems that author has only evaluated the performance under a static topology. i wanted it for a cluster based manet. or can you provide me the code for introducing a blackhole in a manet atleast?

    Like

  20. deepak Says:

    Sir, can i get any code inorder to form clusters based on aodv protocol?

    Like

  21. Neelu Says:

    sir,i am a post graduate student and I’m working in ns2 to design a 3-D network topology.I want to check parameters like area and energy,How is it possible in ns2?ALso is there any way to change routing algorithm in ns2 for wired networks?

    Like

  22. durga Says:

    Sir,I am a Mtech student and I’m doing a project on wireless mesh network.I need a running tcl script for designing wireless mesh network with mesh clients,routers and gateways. It would be of great help if you provide me the code because with this I will be able to proceed further with my project.

    Like

  23. P.Sreedevi Says:

    Hi sir, we(B.Tech final year) are doing project based on clustering using AODV protocol in MANETS. Initially we tried to execute your code in ns2, but it is not executed. It is showing some errors. Can you please provide us if they are any other codes related to clustering using gateways.

    Like

  24. sivaranjani chandrasekar Says:

    I run your program. I am getting error as num_nodes 7 and showing error in LL. what are the changes to be done to run the program without getting error

    Like

  25. Manjusha Says:

    dear sir can u help me in blackhole attack prevention in MANETs. i need a tcl script in blackhole attack prevention using BHAPSC algorithm… can u plz help me out sir.

    Like

  26. Manjusha Says:

    sir plz do help me out with my project.. i would be really grateful if u could reply me as early as possible…

    Like

  27. Nivetha Says:

    Sir, I am doing my project on UnderWater Acoustic Communication.
    We Successfully Installed AQUASIM… But How do we do Clustering among the Nodes?

    Like

  28. Foram Patel Says:

    hello sir, i have used your tcl script. but destination can’t receive message. i got DROP_RTR_QFULL. can you please help me.

    Like

  29. Nithin K.B Says:

    Hai,

    Can you provide the code for efficient neighbour discovery in AODV routing in ns2…

    Regards,
    Nithin K B

    Like

  30. SK Says:

    Hi sir,

    It’s great to see you helping others with NS2. I’m a postgraduate student seeking for help in Energy model (optimization of energy) for linear topology. Do share if there are any relevant NS2 scripts which will benefit for linear topology.

    Thank you.

    Regards,
    SK

    Like

  31. Yojana Singh Says:

    HELLO SIR,I NEED NS2 SOURCE CODE FOR CLUSTERING OF NODES IN WSN.CAN YOU PLEASE SEND IT TO ME ON MY EMAIL ID-
    yojanasingh91@gmail.com

    Like

  32. anitha Says:

    hello sir i need ns2 coding for load balanced clustering in wireless sensor network using genetic algorithm.can u please send that coding to my mail-anisolaiammal@gmail.com

    Like

  33. Homepage Says:

    … [Trackback]

    […] Read More here: abdusyarif.net/2011/01/19/tcl_script_for_my_ns-2_project/ […]

    Like

  34. Harpreet Kaur Says:

    Hello sir,i need code in ns2 tcl script for creating cluster and cluster head selection on the basis of node degree,can you pls mail me the code hpreet1405@gmail.com

    Like

  35. ilakkiya Says:

    Hello sir, i have run the above code but am not getting any output , the trace file contain nothing . help me to solve this problem.

    Like

  36. kavi bharathi Says:

    hii sir
    can u tell me tcl script for aodv-uu routing protocol based elliptic curve cryptograhpy algorithm

    Like

  37. Ajibesin Caleb Adejare Says:

    Hi Sir or Ma. My name is Ajibesin Caleb Adejare doing my master program on manet routing protocols. I have problem in running my Tcl Script for mobile ad-hoc network. When i running your code above on my ns 2, it complains the following:

    num_nodes is set 7
    invalid command name “-llType”
    while executing
    “-llType $val(ll)
    file “p.tcl” line 86

    Pls, provide me with solution to the above. Thank you.

    Like

  38. Prem Says:

    Please help me out from this problem, i.e,
    Segmentation fault (core dumped) while running nam file in ns2
    how to resolve this

    Like

  39. Ajibesin Caleb Adejare Says:

    When i use awk script for trace file, for throughput value i got -0.0. awk script for end to end delay, routing overhead, packet delivery ratio and average jitter complain of bug or give error message. Pls, what is solution?

    Like

  40. Ajibesin Caleb Adejare Says:

    When i used perl script for trace file, it gives me zero for send packet, receive packet, drop packet and soon. Pls, what is solution?

    Like

  41. Ajibesin Caleb Adejare Says:

    Another problem is that the tcl script i am using can only work for aodv and dsr but it can’t work for zrp. And i need a tcl script that can work for the three routing protocol. What is solution?

    Like

  42. Ajibesin Caleb Adejare Says:

    I mean it complain for zrp but it is not for aodv and dsr. Thank you for your respond.

    Liked by 1 person

  43. Ajibesin Caleb Adejare Says:

    Packet Sent:0
    Packet Received:0awk: pd.awk:21: (FILENAME=simple-dsdv2.tr FNR=34919) fatal: division by zero attempted

    pls, i need solution to this not the afformenttioned again. When i run my awk script for packet delivery ratio, i obtained zero and it complain division by zero attempted. Pls, provide with solution. Thank you very much.

    Like

  44. Ajibesin Caleb Adejare Says:

    Pls, can you give me detail or ideal of how to install zrp on my ns 2. Thank you u for previous reply. I am grateful

    Like

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


%d bloggers like this: