Skip to main content

PyTorch Code for Simple Neural Networks for MNIST Dataset

SUMO, Open Street Maps and NS2 - A Real Traffic Simulation

SUMO is the Simulation of Urban mobility software that enables to simulate the road traffic. Open Street map (www.openstreetmap.org)  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 http://www.openstreetmap.org 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 guindy.net.xml

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 guindy.net.xml --type-file osmPolyconvert.typ.xml -o guindy.poly.xml



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

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

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

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


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/traceExporter.py --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 guindy.tr 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
SaveSave

Comments

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

    ReplyDelete
  2. Hello Sir,

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

    SORTING LISTS ...DONE!
    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"

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

    ReplyDelete
  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

    ReplyDelete
  5. when i run polyconvert --osm-files guindy.osm --net-file guindy.net.xml --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

    ReplyDelete
  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 ?

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

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

    How can I solve this?
    Thanks.

    ReplyDelete
  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?

    ReplyDelete
  9. undefined reference to symbol 'pthread_mutexattr_settype@@GLIBC_2.2.5'
    //lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
    collect2: error: ld returned 1 exit status
    Makefile:445: recipe for target 'sumo-gui' failed
    make[3]: *** [sumo-gui] Error 1
    make[3]: Leaving directory '/home/user15/sumo-0.12.3/src'
    Makefile:496: recipe for target 'all-recursive' failed
    make[2]: *** [all-recursive] Error 1
    make[2]: Leaving directory '/home/user15/sumo-0.12.3/src'
    Makefile:360: recipe for target 'all' failed
    make[1]: *** [all] Error 2
    make[1]: Leaving directory '/home/user15/sumo-0.12.3/src'
    Makefile:265: recipe for target 'all-recursive' failed
    make: *** [all-recursive] Error 1



    trid to install SUMO 0.12.3 in ubuntu 16
    .04 lts... during make command above error came... how to resolve it sir... please help

    ReplyDelete
  10. please give all files of drive link

    ReplyDelete
  11. please sir give me all files drive link

    ReplyDelete

Post a Comment

Popular posts from this blog

Installing ns3 in Ubuntu 22.04 | Complete Instructions

In this post, we are going to see how to install ns-3.36.1 in Ubuntu 22.04. You can follow the video for complete details Tools used in this simulation: NS3 version ns-3.36.1  OS Used: Ubuntu 22.04 LTS Installation of NS3 (ns-3.36.1) There are some changes in the ns3 installation procedure and the dependencies. So open a terminal and issue the following commands Step 1:  Prerequisites $ sudo apt update In the following packages, all the required dependencies are taken care and you can install all these packages for the complete use of ns3. $ sudo apt install g++ python3 python3-dev pkg-config sqlite3 cmake python3-setuptools git qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools gir1.2-goocanvas-2.0 python3-gi python3-gi-cairo python3-pygraphviz gir1.2-gtk-3.0 ipython3 openmpi-bin openmpi-common openmpi-doc libopenmpi-dev autoconf cvs bzr unrar gsl-bin libgsl-dev libgslcblas0 wireshark tcpdump sqlite sqlite3 libsqlite3-dev  libxml2 libxml2-dev libc6-dev libc6-dev-i386 libclang-dev llvm-

Installation of NS2 (ns-2.35) in Ubuntu 20.04

Installation of NS2 (ns-2.35) in Ubuntu 20.04 LTS Step 1: Install the basic libraries like      $] sudo apt install build-essential autoconf automake libxmu-dev Step 2: install gcc-4.8 and g++-4.8 open the file using sudo mode $] sudo nano /etc/apt/sources.list Include the following line deb http://in.archive.ubuntu.com/ubuntu bionic main universe $] sudo apt update $] sudo apt install gcc-4.8 g++-4.8 Step 3:  Unzip the ns2 packages to home folder $] tar zxvf ns-allinone-2.35.tar.gz $] cd ns-allinone-2.35/ns-2.35 Modify the following make files. ~ns-2.35/Makefile.in Change @CC@ to gcc-4.8 change @CXX@ to g++-4.8 ~nam-1.15/Makefile.in ~xgraph-12.2/Makefile.in ~otcl-1.14/Makefile.in Change in all places  @CC@ to gcc-4.8 @CPP@ or @CXX@ to g++-4.8 open the file: ~ns-2.35/linkstate/ls.h Change at the Line no 137  void eraseAll() { erase(baseMap::begin(), baseMap::end()); } to This void eraseAll() { this->erase(baseMap::begin(), baseMap::end()); } All changes made Step 4: Open a new termi

Installation of NS2 in Ubuntu 22.04 | NS2 Tutorial 2

NS-2.35 installation in Ubuntu 22.04 This post shows how to install ns-2.35 in Ubuntu 22.04 Operating System Since ns-2.35 is too old, it needs the following packages gcc-4.8 g++-4.8 gawk and some more libraries Follow the video for more instructions So, here are the steps to install this software: To download and extract the ns2 software Download the software from the following link http://sourceforge.net/projects/nsnam/files/allinone/ns-allinone-2.35/ns-allinone-2.35.tar.gz/download Extract it to home folder and in my case its /home/pradeepkumar (I recommend to install it under your home folder) $ tar zxvf ns-allinone-2.35.tar.gz or Right click over the file and click extract here and select the home folder. $ sudo apt update $ sudo apt install build-essential autoconf automake libxmu-dev gawk To install gcc-4.8 and g++-4.8 $ sudo gedit /etc/apt/sources.list make an entry in the above file deb http://in.archive.ubuntu.com/ubuntu/ bionic main universe $ sudo apt update Since, it&#