OLSR simulation in ns2


 
Thread Tools Search this Thread
Special Forums IP Networking OLSR simulation in ns2
# 1  
Old 12-19-2011
OLSR simulation in ns2

# Create the simulator object that we need in order to run NS
set ns [new Simulator]


# Set the parameters that we will use for wireless communications
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 model
set val(ifqlen) 10 ;# max packet in ifq
set val(rp) DSR ;# routing protocol
set val(x) 1000 ;# X dimension of topography
set val(y) 1000 ;# Y dimension of topography
set val(nn) 4 ;# number of mobile nodes

# Open a trace file
set f [open distant.tr w]
$ns trace-all $f
$ns use-newtrace

#Open the nam trace file
set nf [open out_2a.nam w]
$ns namtrace-all $nf
$ns namtrace-all-wireless $nf $val(x) $val(y)

# Create the topology of the world. In this case, flat with dimensions defined above.
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)

# The God object is an all seeing entity that needs to know how many nodes are present.
create-god $val(nn)

# Create a wireless channel
set chan_1_ [new $val(chan)]

Mac/802_11 set RTSThreshold_ 0

# Configure the nodes so that when we create them they are ready to do wireless.
$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) \
-channel $chan_1_ \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace OFF \
-movementTrace ON

# Create the 4 nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]

# define color index
$ns color 1 blue
$ns color 0 red
$n(0) color blue
$ns at 0 "$n(0) color blue"
$n(2) color green
$ns at 0 "$n(2) color green"

# Position the nodes in the world
$n0 set X_ 100
$n0 set Y_ 600
$n0 set Z_ 0

$n1 set X_ 300
$n1 set Y_ 600
$n1 set Z_ 0

$n2 set X_ 100
$n2 set Y_ 100
$n2 set Z_ 0

$n3 set X_ 300
$n3 set Y_ 100
$n3 set Z_ 0


#Setup 2 UDP connection
set udp1 [new Agent/UDP]
set dst1 [new Agent/Null]
$udp1 set fid_ 1

set udp2 [new Agent/UDP]
set dst2 [new Agent/Null]
$udp2 set fid_ 2

#Setup 2 CBR over UDP connection
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp1
$cbr set type_ CBR
$cbr set packet_size_ 1000
$cbr set rate_ 250k
$cbr set random_ false

set cbr1 [new Application/Traffic/CBR]
$cbr1 attach-agent $udp2
$cbr1 set type_ CBR
$cbr1 set packet_size_ 1000
$cbr1 set rate_ 250k
$cbr1 set random_ false

# Connect the flow
$ns attach-agent $n0 $udp1
$ns attach-agent $n1 $dst1
$ns connect $udp1 $dst1

$ns attach-agent $n2 $udp2
$ns attach-agent $n3 $dst2
$ns connect $udp2 $dst2

#Show the movement of the nodes


$ns at 0.00 "$n0 setdest 100 100 0"
$ns at 0.00 "$n2 setdest 100 600 0"
$ns at 5.00 "$n0 setdest 100 100 10"
$ns at 5.00 "$n2 setdest 100 600 10"

# Start the FTP flow
$ns at 0.00 "$cbr start"
$ns at 0.00 "$cbr1 start"

# Run the simulation for 0 minute and 50 second
$ns at 50.0 "finish"

#Define a 'finish' procedure
proc finish {} {
global ns nf
$ns flush-trace
#Close the trace file
close $nf
#Execute nam on the trace file
exec nam out.nam &
exit 0
}

$ns run

Can anyone help me to change the above tcl script to use OLSR routing protocol. in the simplest possible way.

Thank you in advance.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

'Make' command error in olsr

Hi guys..i'm a newbie here and i really need your help urgently..currently i want to run a 'make' command in Ubuntu..But this error occurs: gcc -Wall -Wextra -Wold-style-definition -Wdeclaration-after-statement -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -Waggregate-return... (5 Replies)
Discussion started by: naz1406
5 Replies

2. Homework & Coursework Questions

regarding adding fields to DSR protocol in ns2.34

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: want to add field to route cache and packet of DSR routing protocol in ns2.34, add field, DSR package in ns2.34... (2 Replies)
Discussion started by: khubalkar
2 Replies

3. Programming

regarding adding fields to DSR protocol in ns2.34

hi i am student doing project in ns2.34. i hav to add field in route cache and packet of DSR routing protocol. which files hv to be changed...pl help me (1 Reply)
Discussion started by: khubalkar
1 Replies

4. IP Networking

Issue with Ns2.29

Hello, I am a beginner in Ns2 . I'am trying to run the example attached bu I have this errors : Simulation is running ... please wait ... can't read "Node_(7)": no such element in array while executing "return $Node_($id)" (procedure "_o3" line 3) (Simulator get-node-by-id... (0 Replies)
Discussion started by: Yotta15
0 Replies

5. IP Networking

Issue with ns2 - no throughput data

Hello, First time poster here hoping to get some help with ns2. I've recently started using ns2(first time user) but I'm having difficulty getting the results I'm after. I am trying to set up a network with wireless nodes(5-15 nodes) and then use xgraph to display a timing diagram,... (0 Replies)
Discussion started by: UnicksMan
0 Replies

6. UNIX for Advanced & Expert Users

ns2 simulator with gcc compiler using only 1 processor(?)

Hi! I am using the ns2.31 simulator in Ubuntu 9.04. I have developed my program and when I simulate it (calling ns2 from Ubuntu default shell, that uses gcc), I notice that only 1 of the 2 processors available in my notebook seems to be used (simulations are very heavy and my notebook stays... (5 Replies)
Discussion started by: Alice236
5 Replies

7. Shell Programming and Scripting

TCL in NS2

Hi all, I wrote a TCL script in NS2 which involves running multiple Voice and video sessions. Am not able to troubleshoot one error at all. Can anyone please help me please. I am ready to send the documents if possible. please please help me guys !! I am trying to solve the problem since... (0 Replies)
Discussion started by: mehera
0 Replies

8. Programming

Simulation using C/C++ and Java

Hi, I'm just start to learning simulate a network protocol using C/C++ and Java from scratch. Actually, I want to make two nodes can communicate using TCP and UDP protocol, for example http connection and video streaming, respectively. Can anyone help me find several references or guidance... (0 Replies)
Discussion started by: nica
0 Replies

9. IP Networking

Installing NS2 On Ubuntu Machine

I have to work with NS2 (Network Simulator)and i have to install it beforeusing it on Manets Simulations. Can some one Help me on this topic? Thank's (1 Reply)
Discussion started by: hakim19
1 Replies

10. Shell Programming and Scripting

AWK help for traces in NS2

Hello Everyone, I'm a very new user to both NS-2 and awk and struggling quite a bit. I have a created a wireless trace in NS2 which is of the format as given below: s 0.029290548 _1_ RTR --- 0 message 32 ------- s 1.119926192 _0_ RTR --- 1 message 32 ------- M 10.00000 0 (5.00,... (2 Replies)
Discussion started by: cyberalienfreak
2 Replies
Login or Register to Ask a Question