Simulating a Mobile Adhoc Network

Steps for conducting the experiment

General Instructions

Follow are the steps to be followed in general to perform the experiments in Advanced Network Technologies Virtual Lab.

  1. Read the theory about the experiment
  2. View the simulation provided for a chosen, related problem
  3. Take the self evaluation to judge your understanding (optional, but recommended)
  4. Go to the exercises section, choose a problem, and carefully read the problem description
  5. Write a script (or make necessary changes) to simulate the desired scenario in the code editor just below the problem statement
  6. Click on the 'Run' button to execute the simulation script
  7. Simulation with ns2: If the simulation was successful, and was instructed to create a trace file, contents of the trace file would be displayed in the area below the 'Run' button
  8. Simulation with ns3: If the simulation was successful, output of the program would be displayed in the area below the 'Run' button
  9. A trace file generated as a result of simulation with ns2 could be used for certain kind of analysis, which would be discussed in a later section

Experiment Specific Instructions

  1. The problem statement is presented on the 'Exercises' page, which you have to simulate with ns2.
  2. Provide the information for different types of layers such as: channel, radio-propagation model, network interface, MAC, interface queue type, link layer, antenna, topography, Max packet in ifq, routing protocol used, number of mobilenodes used, simulation time etc.
  3. 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) CMUPriQueue; # Interface queue type 
    set val(ll) LL; # Link layer type 
    set val(ant) Antenna/OmniAntenna; # Antenna type 
    set val(x) 600; # X dimension of the topography 
    set val(y) 500; # Y dimension of the topography 
    set val(ifqlen) 50; # Max packet in ifq 
    set val(rp) DSDV; # Ad-hoc routing protocol 
    set val(nn) 3; # Number of mobilenodes 
    set val(stop) 150.0; # simulation time 
  4. Define global variables for creating simulator trace file objects as required:
  5. Described in previous experiments.

  6. Create General Operation Director(GOD) such as:
  7. set god_ [create-god $val(nn)]

    GOD stores smallest number of hops from one node to another node. This is autometically generated by scenario file.

  8. Configure different options for a mobile node to be created:
  9. $ns_ node-config -adhocRouting $val(rp) \ 
    -llType $val(ll) \ 
    -macType $val(mac) \ 
    -ifqType $val(ifq) \ 
    -ifqLen $val(ifqlen) \ 
    -antType $val(ant) \ 
    -propType $val(prop) \ 
    -phyType $val(netif) \ 
    -channelType $val(chan) \ 
    -topoInstance $topo \ 
    -agentTrace ON \ 
    -routerTrace ON \ 
    -macTrace OFF \
    -movementTrace OFF

    The four last option in node configuration can either be ON or OFF based on the condition of the mobile nodes. The agent trace will give the trace of TCP, routerTrace provides tracing of packets used in routing, macTrace is used to trace MAC protocol packets and movementTrace is used to allow tracing the motion of nodes for nam.

  10. Create mobile nodes
  11. set node(0) [$ns node]
  12. Generate topology
  13. Assign trafic pattern for the network
  14. Define a finish procedure
  15. Set the start and stop time for the simulator
  16. Following is the sample code to create a network with two mobile nodes

    # Create a new simulator object.
    set ns [new Simulator]
    # ----- Setup wireless environment. ----
    set wireless_tracefile [open w]
    set topography [new Topography]
    $ns trace-all $wireless_tracefile
    $ns namtrace-all-wireless $namfile 700 700
    $topography load_flatgrid 700 700
    # Create God
    set god_ [create-god 2]
    #global node setting
    $ns node-config -adhocRouting DSR \
                     -llType LL \
                     -macType Mac/802_11 \
                     -ifqType CMUPriQueue \
                     -ifqLen 50 \
                     -antType Antenna/OmniAntenna \
                     -propType Propagation/TwoRayGround \
                     -phyType Phy/WirelessPhy \
                     -channel [new Channel/WirelessChannel] \
                     -topoInstance $topography \
                     -agentTrace ON \
                     -routerTrace OFF \
                     -macTrace ON
    # Create wireless nodes
    set node(0) [$ns node]
    $node(0) set X_ 150
    $node(0) set Y_ 300
    $node(0) set Z_ 0.0
    $node(0) color "black"
    $ns initial_node_pos $node(0) 30.000000
    set node(1) [$ns node]
    $node(1) set X_ 300
    $node(1) set Y_ 500
    $node(1) set Z_ 0.0
    $node(1) color "black"
    $ns initial_node_pos $node(1) 30.000000
    # Node movement patterns
    $ns at 4.0 "$node(1) setdest 300.0 500.0 5.0"
    $ns at 4.0 "$god_ set-dist 0 1 1"
    # Create links between nodes.
    for {set i 0} {$i < $val(nn)}{incr i}
        set node_($i) [$ns_node]
        $node_($i) random-motion 0;
    # Create agents.
    set tcp [new Agent/TCP]
    $tcp set class_ 2
    set sink [new Agent/TCPSink]
    $ns attach-agent $node(0) $tcp
    $ns attach-agent $node(1) $sink
    $ns connect $tcp $sink
    set ftp [new Application/FTP]
    $ftp attach-agent $tcp
    $ns at 3.0 "$ftp start" 
    # Tell nodes when the simulation ends
    $ns at 10.000000 "$node(0) reset";
    $ns at 10.000000 "$node(1) reset";
    # Connect agents.
    # Run the simulation
    proc finish {} {
    	global ns 
    	$ns flush-trace
    	exit 0
    $ns at 10.000000 "finish"
    $ns run

    Trace File Analysis

    A simple tool has been provided as part of this lab to analyze the trace files generated after simulation with ns2. A summary of the available options, and usage guide is given below.

    Features List

    Following is a list of functionalities provided by the Trace Analysis tool:

    • Trace file formats: Following trace file formats are being supported:
      • Wired
      • Wireless (new format)
      • Satellite -- currently redirects to wired mode
      • Mixed -- when both wired and wireless connections are present in the simulation
    • General Statistics: To provide some common statistics about the simulation being run. Currently displays only the simulation duration.
      • Inputs: None
      • Output: Text
    • Average Throughput: Computes total # of bytes received by a node over the entire simulation duration
      • Inputs: Node #
      • Output: Number
    • Bytes Received: Plots cumulative count of bytes received by a node over the entire simulation duration
      • Inputs: Node #; for wireless scenario, trace levels (AGT, MAC, RTR)
      • Output: Graph
    • End-to-end Delay: Plots the end-to-end delay delay encountered by packets while moving from a source node to the destination node
      • Inputs: Source node #, destination node #, scaling factor [optional] -- scaling factor helps to amplify the y-axis values
      • Output: Graph
    • Packet Retransmissions: Plots # of retransmission(s) of a given packet occurs between the source and destination nodes
      • Inputs: Source node #, destination node #
      • Output: Graph
    • Hop Count: Plots the # of hops traveled by a packet to reach the destination node from the source node. It counts the destination node as well.
      • Inputs: Source node #, source port #, destination node #, destination port #
      • Output: Graph


    1. For analyzing the problems in the "Satellite Networks" experiment, please use the Wired mode of analysis
    2. Analysis of trace files for mixed mode of simulations (wired & wireless) is not supported currently
    3. Outputs produced do not necessarily have accuracy for scientific publications. In particular, the plot of hop counts may vary a bit from the original count (in wireless mode) in cases when a packet has been forwarded to more than one node.
    4. The tool currently allows only a single instance of a given type of plot. For example, this doesn't let you plot end-to-end delays between multiple (source, destination) node pairs
Decrease font size Increase font size List of experiments