NS2 SIMULATION CODE FOR WIRELESS WIRED

      Ns2 Simulation Code for Wireless Wired is our major service, started for the benefit of young minds, who are also starving to achieve their part of success in their career. Generally, students approach us regarding NS-2 code also for their projects, assignments or lab cycles. We provide complete code support along with all necessary support, they expect from us. Students prefer us also due to our standard service and guidance support. We have served students from nearly 120+ countries with also our code support and guidance. To work with NS-2 simulation project, one must also aware of basic language fundamentals [C++ and OTCL] of NS-2.

If you don’t have any knowledge about NS-2, nothing to worry, refer our complete articles available in this site, you will be the Master of NS-2. In this article, we also have focused on steps involved in Ns2 Simulation Code for Wireless Wired along with a sample code. Refer this and also for further doubts and queries, approach us anytime.

Steps involved in NS-2 Wireless Simulation

Create a Simulator Object:
  • This is the first and also foremost step, which involves the following command:

                 Set ns [ new simulator ]

Create GOD [General operation Direction]:
  • Any two nodes can also transmit data if they lie in the range of each other.
  • If one node moves way from the range of another, connection also gets terminated. For this reason GOD is used in NS-2.
  • For every wireless simulation, GOD must created. It also keeps the information about each node.
  • While creating GOD, number of nodes must be specified as it also reserves memory space for those nodes for storing their information.
 General Syntax:

Create god < number of nodes >

To create topography object:
  • It is also defined to determine the area in which the mobile host can move.
General syntax:

set   topog  [new  Topography]// to create object of Topography class

$topog  load_Flatgrid  < X >  & tl; Y>// Specify the boundary area

Configuring attributes for node:
  • To configure a node in Wireless simulation, we also need to define the following attributes i.e. Addressing types, Propagation type, Queue[Drop tail or Priority queue],link layer type, physical interface, Antenna type , channel, topography instance, mobile IP, wired routing, energy model, also Router trace, agent trace, Mac trace etc. For better information about this refer our other articles.
  • Now , lets see the commands also used for moving nodes:
Random motion for Wireless Node:

$ [node instance]  random – motion 0 [or 1]

1- Random motion turned on

0- Random motion off

To Set the Node position[Set X, Y, Z   where, Z position=0]

$ [node instance]  set  X  < x-cord >

$ [node instance]  set  Y  < y-cord >

$ [node instance]  set  Z < z-cord >

To Set the Node Movement:    

$ [ simulator instance]  at  $ [node instance] set dest  <X>  <Y> <Speed>

For ex: $ ns 1.3 $n1 set dest 200 300 30

To set the radius of the Node:

[node instance]  radius  < r >

For ex. $n1 radius 40

To set the distance between the Nodes:         

[god  instance]  set dist <node number> <node number>  < hopcount >

For ex: $ god 1 2 3

To attach application and agent:

-To attach an agent to the node, it must be first created using the following command,

         $ [ simulator   instance ]  attach-agent [ node  instance ] [ agent  instance ]

-Two types of Applications are used[Traffic generator and simulated applications]

  • Traffic generators[CBR, Trace, Exponential traffic generator, pareto generator etc]
  • Simulated Applications[Telnet, FTP]
  • General command:
//For traffic generator

Application / Traffic / Exponential
Application / Traffic / Pareto

//For Simulated Applications

Application / FTP

Application / Telnet

Create link between them to connect:
  • Links can be simplex or full duplex links.
  • To create a link between nodes in NS2, general command is

$ns   simplex link/duplex  link [ nodeinstance1 ] [ nodeinstance2 ] bandwidth  delay  Q-Type

Sample NS2 code for Wireless Network Coding[Route Optimization]:

set val(chan)       Channel/WirelessChannel

setval(prop)       Propagation/TwoRayGround

set val(netif)      Phy/WirelessPhy

setval(mac)        Mac/802_11

set val(ifq)        Queue/DropTail/PriQueue

setval(ll)         LL

set val(ant)        Antenna/OmniAntenna

setval(x)              800

set val(y)              800

setval(ifqlen)         50

set val(seed)           0.0

setval(rp)   VOIP

set val(nn)             40

setval(cp)             cbr

set val(sc)             scen

setval(len)            len

set val(stop)           7.1

setval(traffic)        tcp

set val(rxPower)        5.5

setval(txPower)        5.5

set val(energymodel)    EnergyModel

setval(initialenergy)  1000

set val(sleeppower)     0.00005

setval(ener)           500

set val(energy)         cal

setval(freq)           node

set val(traffic)        tcp

setns_                        [new Simulator]

LL set mindelay_                50us

LLset delay_                                    25us

LL set bandwidth_               0

Agent/Null set sport_                      0

Agent / Null set dport_                      0

Agent/CBR set sport_                      0

Agent / CBR set dport_                     0

Agent/TCPSink set sport_   0

Agent / TCPSink set dport_  0

Agent/TCP set sport_                       0

Agent / TCP set dport_                      0

Agent/TCP set packetSize_            512

Queue/DropTail/PriQueue set Prefer_Routing_Protocols    1

Antenna/OmniAntenna set X_ 0

Antenna / OmniAntenna set Y_ 0

Antenna/OmniAntenna set Z_ 1.5

Antenna / OmniAntenna set Gt_ 1.0

Antenna/OmniAntenna set Gr_ 1.0

Phy / WirelessPhy set CPThresh_ 10.0

Phy/WirelessPhy set CSThresh_ 1.559e-11

Phy / WirelessPhy set RXThresh_ 3.652e-10

Phy/WirelessPhy set Rb_ 2*1e6

Phy / WirelessPhy set Pt_ 0.2818

Phy/WirelessPhy set freq_ 914e+6

Phy / WirelessPhy set L_ 1.0

set topo          [new Topography]

settracefd      [open Route_Optimization.tr w]

set namtrace    [open Route_Optimization.nam w]

$ns_ trace-all $tracefd

$ ns_ namtrace-all-wireless $namtrace $val(x) $val(y)

$topo load_flatgrid $val(x) $val(y)

set god_ [create-god $val(nn)]

source $val(len)

$ns_ node-config -adhocRouting $val(adhocrouting) \

-llType $val(ll) \

-macType $val(mac) \

-ifqType $val(ifq) \

-ifq Len $val(ifqlen) \

-antType $val(ant) \

-propType $val(prop) \

-phyType $val(netif) \

-channelType $val(chan) \

-topoInstance $topo \

-agentTrace ON \

-routerTrace ON \

-macTrace ON

for {set i 0} {$i < $val(nn) } {incr i} {

set node_($i) [$ns_ node]

$node_($i) random-motion 0

}

source$val(cp)

source $val(sc)

$ns_ initial_node_pos $node_(0) 20

$ ns_ initial_node_pos $node_(1) 20

$ns_ initial_node_pos $node_(2) 20

$ ns_ initial_node_pos $node_(3) 20

$ns_ initial_node_pos $node_(4) 20

$ ns_ initial_node_pos $node_(5) 20

$ns_ initial_node_pos $node_(6) 20

$ ns_ initial_node_pos $node_(7) 20

$ns_ initial_node_pos $node_(8) 20

$ ns_ initial_node_pos $node_(9) 20

$ns_ initial_node_pos $node_(10) 20

$ ns_ initial_node_pos $node_(11) 20

$ns_ initial_node_pos $node_(12) 20

$ ns_ initial_node_pos $node_(13) 20

$ns_ initial_node_pos $node_(14) 20

$ ns_ initial_node_pos $node_(15) 20

$ns_ initial_node_pos $node_(16) 20

$ ns_ initial_node_pos $node_(17) 20

$ns_ initial_node_pos $node_(18) 20

$ ns_ initial_node_pos $node_(19) 20

$ns_ initial_node_pos $node_(20) 20

$ ns_ initial_node_pos $node_(21) 20

$ns_ initial_node_pos $node_(22) 20

$ ns_ initial_node_pos $node_(23) 20

$ns_ initial_node_pos $node_(24) 20

$ ns_ initial_node_pos $node_(25) 20

$ns_ initial_node_pos $node_(26) 20

$ ns_ initial_node_pos $node_(27) 20

$ns_ initial_node_pos $node_(28) 20

$ ns_ initial_node_pos $node_(29) 20

$ns_ initial_node_pos $node_(30) 20

$ ns_ initial_node_pos $node_(31) 20

$ns_ initial_node_pos $node_(32) 20

$ ns_ initial_node_pos $node_(33) 20

$ns_ initial_node_pos $node_(34) 20

$ ns_ initial_node_pos $node_(35) 20

$ns_ initial_node_pos $node_(36) 20

$ ns_ initial_node_pos $node_(37) 20

$ns_ initial_node_pos $node_(38) 20

$ ns_ initial_node_pos $node_(39) 20

for {set i 0} {$i < $val(nn) } {incr i} {

$ns_ at $val(stop).0 “$node_($i) reset”;

}

proc finish {} {

global ns_ tracefd namtrace

close $tracefd

close$namtrace

exec nam Route_Optimization.nam &

}

$ns_ at $val(stop).0001 “finish”

$ ns_ at  $val(stop).0002 “puts \”NS EXITING…\” ; $ns_ halt”

puts $tracefd “M 0.0 nn $val(nn) x $val(x) y $val(y) rp $val(adhocrouting)”

puts$tracefd “M 0.0 sc $val(sc) cp $val(cp) seed $val(seed)”

puts $tracefd “M 0.0 prop $val(prop) ant $val(ant)”

puts “Starting Simulation…”

$ns_ run

     We also have provided an overview about how to create wireless simulation in NS2. Along with it, we also have provided one sample code for your better understanding. If you feel to have further guidance or tutoring support in NS2, also approach our experts through online. You can also approach us also for code support regarding any particular topic, project or assignment. We also will offer you our all round support with the help of our experts and dedicated professionals.

MAKE LEARNING AS YOUR PASSION ………………………………..

AS WE ARE THERE NOW ………………………………..

WITH OUR DEDICATION AND SUPPORT FOR YOUR BETTERMENT…..