Its all about Network Simulations, Internet of Things, Sensor Networks, Programming, etc

Network Simulator 2

Network Simulator 3

Post Page Advertisement [Top]

SUMO is the Simulation of Urban mobility software that enables to simulate the road traffic. Open Street map (  provides the xml based .osm file for any part of the world selected through their website. #openstreetmap

#SUMO can able to convert the osm file to its native xml file. The post tells you the simulation of a real traffic network and how it is ported to #ns2 for network animation and tracing.

Step 1: Prerequisites

  • SUMO to be installed - in my case I installed sumo this way 
sudo add-apt-repository pap:sumo/stable
sudo apt-get update
sudo apt-get install sumo sumo-doc sumo-tools

Also, Download the sumo source sumo-src-0.26.tar.gz from this link and unzip or untar it to the home directory (/home/pradeepkumar). There are some python files that are needed to generate random trips and to export xml files to tcl files. the commands sumo, sumo-gui will run only the graphical simulation.
Once the software is unzipped, set the SUMO_HOME in the environment, Open /home/pradeepkumar/.profile (for Linux Mint) and /home/pradeepkumar/.bashrc (for Ubuntu) and give this command (in my case the home is pradeepkumar, it might be different for you)
export SUMO_HOME=/home/pradeepkumar/sumo-0.26.0 

Step 2: Steps to create a Traffic

  1. Open browser and type and search a particular area and click export in the top. 
  2. click "Manually select an area" and select the area (as shown in the video below) and click export again (it will download a file called map.osm, rename this file as per your convenience)
  3. Open the terminal and type the commands one by one (assume my file name is guindy.osm, so i maintain the same file name guindy for all the xml files)
$] netconvert --osm-files guindy.osm -o

Now, copy the osmPolyconvert.typ.xml from the $SUMO_HOME/data/typemap/ and copy it to the folder where you put all the files. 

$] polyconvert --osm-files guindy.osm --net-file --type-file osmPolyconvert.typ.xml -o guindy.poly.xml

$] python $SUMO_HOME/tools/ -n -r guindy.rou.xml -e 100 -l

Now, create a new file (to be named as guindy.sumo.cfg) and paste the following lines 

         <net-file value=""/>
<route-files value="guindy.rou.xml"/>
         <additional-files value="guindy.poly.xml"/>
<begin value="0"/>
<end value="100"/>
<step-length value="0.1"/>

Now you can run the above using sumo-gui guindy.sumo.cfg (now you can see as per the following screenshot)

Step 3: Exporting to NS2
from sumo trace to ns2, here is the step to do
Open terminal and type the following commands,

$] sumo -c guindy.sumo.cfg --fcd-output guindy.sumo.xml

$] python /home/pradeepkumar/sumo-0.26.0/tools/ --fcd-input guindy.sumo.xml --ns2config-output guindy.tcl --ns2activity-output activity.tcl --ns2mobility-output mobility.tcl​

This will generate three tcl files (guindy.tcl, activity.tcl and mobility.tcl). Among this activity.tcl might not be needed, but mobility.tcl file is mandatory)

The generated guindy.tcl have to be modified or altered as per the networking parameters like routing protocol, Mac layer, physical layer, link layer, etc.

You can see the following video for all the instructions.

A Sample TCL File for your Use

Here is the guindy.tcl file, you can use it for your purpose
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(ll)             LL                         ;# link layer type
set val(ant)            Antenna/OmniAntenna        ;# antenna model
set val(ifqlen)         50                         ;# max packet in ifq
set val(nn)            41                          ;# number of mobilenodes
set val(rp)             AODV                       ;# routing protocol
set opt(x) 4707
set opt(y) 3002
# ======================================================================
# Main Program
# ======================================================================

# Initialize Global Variables
set ns_ [new Simulator]
set tracefd     [open w]
$ns_ trace-all $tracefd

set namf [open guindy.nam w]
$ns_ namtrace-all-wireless $namf $opt(x) $opt(y)
# set up topography object
set topo       [new Topography]

$topo load_flatgrid $opt(x) $opt(y)
# Create God
create-god $val(nn)

#  Create the specified number of mobilenodes [$val(nn)] and "attach" them
#  to the channel. 
#  Here two nodes are created : node(0) and node(1)

# configure node

        $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 ON
for {set i 0} {$i < $val(nn) } {incr i} {
set node_($i) [$ns_ node]
$node_($i) random-motion 0 ;# disable random motion
$ns_ initial_node_pos $node_($i) 20



source mobility.tcl

set tcp [new Agent/TCP]
$tcp set class_ 2
set sink [new Agent/TCPSink]
$ns_ attach-agent $node_(0) $tcp
$ns_ attach-agent $node_(22) $sink
$ns_ connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns_ at 10.0 "$ftp start" 

# Tell nodes when the simulation ends
for {set i 0} {$i < $val(nn) } {incr i} {
    $ns_ at 100.0 "$node_($i) reset";
$ns_ at 100.0 "stop"
$ns_ at 100.01 "puts \"NS EXITING...\" ; $ns_ halt"
proc stop {} {
    global ns_ tracefd
    $ns_ flush-trace
    close $tracefd

puts "Starting Simulation..."
$ns_ run

Just comment below if you need any queries (the above video will give you full information).
T S Pradeep Kumar


  1. Thank you sir ..
    excellent helpfull sumo-vanets tutorial in research

  2. Hello Sir,

    Could you please help me to resolve the issue is faced while following the above instructions.

    ns: _o86 setdest 801806.63 1459904.04 0.00:
    (_o86 cmd line 1)
    invoked from within
    "_o86 cmd setdest 801806.63 1459904.04 0.00"
    invoked from within
    "catch "$self cmd $args" ret"
    invoked from within
    "if [catch "$self cmd $args" ret] {
    set cls [$self info class]
    global errorInfo
    set savedInfo $errorInfo
    error "error when calling class $cls: $args" $..."
    (procedure "_o86" line 2)
    (SplitObject unknown line 2)
    invoked from within
    "_o86 setdest 801806.63 1459904.04 0.00"

  3. Sir, how can I solve this error: couldn't read file "mobility.tcl": no such file or directory
    while executing

  4. Sir, how to solve this error while running the tcl file for ns2

    couldn't read file "mobility.tcl": no such file or directory
    while executing

  5. when i run polyconvert --osm-files guindy.osm --net-file --type-file osmPolyconvert.typ.xml -o guindy.poly.xml, on ubuntu terminal i faced Error: unable to open primary document entity '/home/aye/simulation/osmPolyconvert.typ.xml' how can i fix it? please these is urgent

  6. hello sir, i have the sumo-0.12.3 can i do this simulation with this version or i need the sumo-0.23 ?

  7. Dear,
    I am getting this error when running
    ns guindy.tcl

    wrong # args: should be "set varName ?newValue?"
    while executing
    "set tracefd [open w]
    (file "guindy.tcl" line 63)

    How can I solve this?

  8. Hello sir,
    Please help. Want to convert my trace file(.tr) into a .csv or into excel format(.xls, xlsx) for machine learning purposes?


Bottom Ad [Post Page]