Trac­ing Ve­hic­u­lar Mo­bil­ity in ns-3

ns-3 is free sim­u­la­tion soft­ware that’s meant for ed­u­ca­tional, re­search and de­vel­op­ment pur­poses. It has a num­ber of high qual­ity, tested and val­i­dated mod­els, and is backed by a large com­mu­nity of de­vel­op­ers and users.

OpenSource For You - - Open Gurus -

The ns-3 sim­u­la­tor is an open source project meant for ed­u­ca­tional and de­vel­op­ment pur­poses. It is also used to en­act dis­crete-event sim­u­la­tion. Prac­ti­cal im­ple­men­ta­tion or ex­per­i­men­tal test­ing of new pro­to­cols on real-world net­works is not al­ways pos­si­ble. ns-3 helps to ab­stract real-world en­ti­ties and al­lows to sim­u­late, as well as to com­pute com­plex cal­cu­la­tions on huge net­works of com­puter sys­tems. It can be treated as a real-time net­work emu­la­tor, as it can sim­u­late sce­nar­ios on re­al­is­tic data. It pro­vides a plat­form for de­vel­op­ers to build sim­u­la­tion mod­els and can com­pre­hend ev­ery sin­gle step, i.e., the en­tire work­flow of the sim­u­la­tion, from con­fig­u­ra­tion to the col­lec­tion and anal­y­sis of traces.

The ns-3 project in­cludes and sup­ports var­i­ous real-world pro­to­cols and its im­ple­men­ta­tions. It sup­ports var­i­ous rout­ing pro­to­cols, which in­clude OLSR, AODV and many more for IP-based ap­pli­ca­tions on IP net­works. It also sup­ports nonIP based net­work sim­u­la­tion. The ns-3 sim­u­la­tor ma­jorly in­volves mod­els for Wi-Fi, WiMax and LTE.

Mo­bil­ity pro­vi­sion in the ns-3 sim­u­la­tor

The ns-3 sim­u­la­tor pro­vides sup­port for mo­bil­ity in the form of mo­bil­ity mod­els and helper classes. Mo­bil­ity mod­els are used to track and per­pet­u­ate the cur­rent po­si­tion and speed of an ob­ject. Mo­bil­ity helper classes are used to place nodes and set up mo­bil­ity mod­els. Users com­mu­ni­cate with the mo­bil­ity sys­tem us­ing the mo­bil­ity helper classes as they in­te­grate a mo­bil­ity model and po­si­tion al­lo­ca­tor, and can be used along with a node con­tainer to in­stall mo­bil­ity func­tions on a set of nodes. The ns-3 sim­u­la­tor pro­vides a ns-2 mo­bil­ity helper class, which al­lows it to in­ter­pret the ns-2 file for­mat of the trace file. The fol­low­ing state­ments show the ns-2 trace file for­mat:

$node_ (node num­ber) set X_ x

$node_ (node num­ber) set Y_ y

$node_ (node num­ber) set Z_ z

$ns_ at $time $node_ (node num­ber) set­dest x2 y2 speed $ns_ at $time $node_ (node num­ber) set­dest x3 y3 speed $ns_ at $time $node_ (node num­ber) set­dest x4 y4 speed $ns_ at $time $node_ (node num­ber) set­dest x5 y5 speed

In the above traces, x and y are ini­tial po­si­tions while z spec­i­fies the speed in m/s. These are ini­tialised us­ing the set state­ments. The com­mand set­dest is used to de­fine the new po­si­tion (x2, y2) of the node at the given time ($time), which

thus in­structs the node to prop­a­gate to its new po­si­tion. If the node reaches its des­ti­na­tion, it will pause there; or it may also hap­pen that the sim­u­la­tion ends be­fore. In that case, the node will not be able to reach the des­ti­na­tion. Also, some­times a new des­ti­na­tion is set dur­ing a course to a lo­ca­tion; in that sce­nario, the node will change course to the new des­ti­na­tion in be­tween.

SUMO

Sim­u­la­tion of Ur­ban Mo­bil­ity (SUMO) is an open source traffic sim­u­la­tion pack­age that in­cludes net-im­port and de­mand mod­el­ling com­po­nents. Many re­search top­ics, like the route choice and the sim­u­la­tion of ve­hic­u­lar com­mu­ni­ca­tion or traffic light al­go­rithms, are stud­ied with the help of SUMO. The frame­work of SUMO serves in var­i­ous projects like traffic man­age­ment strate­gies or to sim­u­late au­to­matic driv­ing. Sim­u­la­tions in SUMO com­prise timedis­crete and space-con­tin­u­ous ve­hi­cle move­ments, multi-lane high­ways and streets, traffic lights, Open GL for the graph­i­cal in­ter­face and fast ex­e­cu­tion speed. SUMO is edge-based, can op­er­ate with other ap­pli­ca­tions at run time, has porta­bil­ity and de­tec­tor-based out­puts.

The flow of the in­te­gra­tion of SUMO traces with ns-3 for mo­bil­ity pro­vi­sion­ing is shown in Fig­ure 1.

Con­struct­ing a sce­nario in SUMO

In or­der to gen­er­ate traffic with the help of the SUMO sim­u­la­tor, a sce­nario or net­work needs to be cre­ated. SUMO Street Net­work con­sists of nodes (junc­tions) and edges (streets con­nect­ing the junc­tions). SUMO Sim­u­la­tor re­quires .nod.xml and .edg.xml to de­fine the junc­tions and streets join­ing them.

The nod.xml file con­tains the lo­ca­tion (x and y co­or­di­nates) of junc­tions. An ex­am­ple is given be­low:

first.nod.xml <nodes> <node id=”1” x=”-300.0” y=”5.0” /> <node id=”2” x=”+300.0” y=”5.0” /> <node id=”3” x=”5.0” y=”-300.0” /> <node id=”4” x=”5.0” y=”+300.0” /> <node id=”5” x=”5.0” y=”5.0” /> </nodes>

To join the above nodes, edges are de­fined in the edg.xml file us­ing the tar­get node ID and source node ID. An ex­am­ple is given be­low:

first.edg.xml

<edges>

<edge from=”1” id=”A” to=”4” /> <edge from=”4” id=”B” to=”2” /> <edge from=”2” id=”C” to=”5” /> <edge from=”5” id=”D” to=”3” /> <edge from=”2” id=”E” to=”3” /> </edges>

To build a net­work, the above de­fined node file and edge file are re­quired. And us­ing the net­con­vert util­ity, a net.xml file is gen­er­ated as fol­lows:

$net­con­vert ­n first.nod.xml ­e first.edge.xml ­o net­work.net.xml

Ve­hi­cles in the traffic are de­fined with route data in the rou.xml file. For ex­am­ple:

first.rou.xml

<routes>

<vType id=”Bo­ogyA” length=”5.75” maxSpeed=”90.0” sigma=”0.4” /> <vType id=”Bo­ogyB” length=”7.5” maxSpeed=”60.0” sigma=”0.7” /> <route id=”rou01” edges=”A B C D”/>

<route id=”rou02” edges=”A B E”/>

<ve­hi­cle de­part=”0” id=”v0” route=”rou01” type=”Bo­ogyA” color=”1,0,0” />

<ve­hi­cle de­part=”1” id=”v1” route=”rou02” type=”Bo­ogyA” /> <ve­hi­cle de­part=”2” id=”v2” route=”rou01” type=”Bo­ogyA” /> <ve­hi­cle de­part=”3” id=”v3” route=”rou02” type=”Bo­ogyA” /> <ve­hi­cle de­part=”5” id=”v4” route=”rou01” type=”Bo­ogyA” /> <ve­hi­cle de­part=”6” id=”v5” route=”rou02” type=”Bo­ogyA” /> <ve­hi­cle de­part=”7” id=”v6” route=”rou01” type=”Bo­ogyA” /> <ve­hi­cle de­part=”8” id=”v7” route=”rou02” type=”Bo­ogyA” /> <ve­hi­cle de­part=”9” id=”v8” route=”rou01” type=”Bo­ogyA” /> <ve­hi­cle de­part=”11” id=”v9” route=”rou02” type=”Bo­ogyA” /> <ve­hi­cle de­part=”14” id=”v10” route=”rou01” type=”Bo­ogyA”/> <ve­hi­cle de­part=”16” id=”v11” route=”rou01” type=”Bo­ogyA”/> <ve­hi­cle de­part=”17” id=”v12” route=”rou01” type=”Bo­ogyB” color=”1,0,0” />

<ve­hi­cle de­part=”18” id=”v13” route=”rou02” type=”Bo­ogyB” /> <ve­hi­cle de­part=”19” id=”v14” route=”rou02” type=”Bo­ogyB” />

<ve­hi­cle de­part=”21” id=”v15” route=”rou01” type=”Bo­ogyB” />

<ve­hi­cle de­part=”22” id=”v16” route=”rou01” type=”Bo­ogyB” />

<ve­hi­cle de­part=”23” id=”v17” route=”rou02” type=”Bo­ogyB” />

<ve­hi­cle de­part=”24” id=”v18” route=”rou02” type=”Bo­ogyB” />

<ve­hi­cle de­part=”27” id=”v19” route=”rou02” type=”Bo­ogyB” />

</routes>

Files first.rou.xml and net­work.net.xml are re­quired to gen­er­ate con­fig­u­ra­tion files for sim­u­lat­ing the traffic on the net­work. The fol­low­ing con­fig­u­ra­tion file is gen­er­ated, which is then used to sim­u­late the sce­nario:

first.sumo.cfg

<con­fig­u­ra­tion>

<in­put>

<net­file value=”net­work.net.xml”/> <route­files value=”first.rou.xml”/> </in­put>

<time>

<be­gin value=”0”/>

<end value=”150”/>

</time>

<time­to­tele­port value=”­1”/> </con­fig­u­ra­tion>

To sim­u­late the sce­nario, the fol­low­ing com­mand is re­quired to be fired from the ter­mi­nal:

$sumo ­c first.sumo.cfg

To vi­su­alise the sim­u­la­tion in the SUMO GUI, use the fol­low­ing com­mand:

$sumo­gui ­c first.sumo.cfg

Gen­er­at­ing traces

SUMO trace files can be gen­er­ated with the help of a .cfg file (con­fig­u­ra­tion file), as fol­lows:

$sumo ­c first.sumo.cfg –fcd­out­put trace.xml

Traces of the ve­hi­cles’ po­si­tion are dumped into the

XML file. These SUMO traces can be used to pro­vide mo­bil­ity to nodes in the ns-3 sim­u­la­tor. The ns-3 sim­u­la­tor pro­vides the ns-2 mo­bil­ity helper class, which can be used to read the move­ments of nodes from trace files. To make use of the SUMO traces gen­er­ated from the SUMO sim­u­la­tor, the XML file needs to be con­verted to a TCL file, which then is pro­vided to the ns-2 mo­bil­ity helper. SUMO pro­vides tools like traceEx­porter.py and traceEx­porter.jar to con­vert SUMO trace to dif­fer­ent file for­mats.

$python $SUMO_HOME/tools/traceEx­porter.py –fcd­in­put trace. xml –ns2­mo­bil­ity­out­put mo­bil­ity.tcl

mo­bil­ity.tcl gen­er­ated above con­tains the po­si­tion and the ve­loc­i­ties of the nodes (ve­hi­cles).

Ren­der­ing SUMO traces in ns-3

Vi­su­al­i­sa­tion through Python Visu­al­izer: The ns-3 sim­u­la­tor pro­vides the ns2-mo­bil­ity-trace.cc file, which takes mo­bil­ity.tcl as the ar­gu­ment along with a num­ber of nodes in the sce­nario and the du­ra­tion of the sim­u­la­tion. At the end of the sim­u­la­tion, it gen­er­ates a log file. The com­mand for ex­e­cut­ing the same is given be­low:

$./waf ­­run “ns2­mo­bil­ity­trace ­­traceFile=path_­to_ tracefile/mo­bil­ity.tcl ­­nodeNum=18 ­­du­ra­tion=200.0 ­­logFile=ns2­mob.log” ­­vis

--vis ren­ders the sim­u­la­tion in Python Visu­al­izer. Visu­al­is­ing the sce­nario in NetAnim: A NetAnim com­pat­i­ble XML file can be gen­er­ated by adding the fol­low­ing lines of code in the file ns2-mo­bil­ity-trace.cc (ns-dev/src/mo­bil­ity/ex­am­ples/).

In­clude the header file:

#in­clude “ns3/netanim­mod­ule.h”

Fig­ure 3: Sim­u­la­tion in pyViz

Fig­ure 2: Sim­u­la­tion in the SUMO GUI

Newspapers in English

Newspapers from India

© PressReader. All rights reserved.