1. 2node.tcl
set ns [new Simulator]
#Define different colors for data flows (for NAM)
$ns color 1 Blue
#Open the Trace files
set file1 [open out.tr w]
set winfile [open WinFile w]
$ns trace-all $file1
#Open the NAM trace file
set file2 [open out.nam w]
$ns namtrace-all $file2
#Define a 'finish' procedure
proc finish {} {
global ns file1 file2
$ns flush-trace
close $file1
close $file2
exec nam out.nam &
exit 0
}
#Create six nodes
set n0 [$ns node]
set n1 [$ns node]
#Create links between the nodes
$ns duplex-link $n0 $n1 .3Mb 50ms DropTail
#Set Queue Size of link (n2-n3) to 10
$ns queue-limit $n0 $n1 4
#Setup a TCP connection
set tcp [new Agent/TCP/Newreno]
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink/DelAck]
$ns attach-agent $n1 $sink
$ns connect $tcp $sink
$tcp set fid_ 1
$tcp set window_ 8000
$tcp set packetSize_ 552
#Setup a FTP over TCP connection
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP
$ns at 1.0 "$ftp start"
$ns at 124.0 "$ftp stop"
# next procedure gets two arguments: the name of the
# tcp source node, will be called here "tcp",
# and the name of output file.
proc plotWindow {tcpSource file} {
global ns
set time 0.1
set now [$ns now]
set cwnd [$tcpSource set cwnd_]
set wnd [$tcpSource set window_]
puts $file "$now $cwnd"
$ns at [expr $now+$time] "plotWindow $tcpSource $file" }
$ns at 0.1 "plotWindow $tcp $winfile"
$ns at 125.0 "finish"
$ns run
2. 5node.tcl
set ns [new Simulator]
#Define different colors for data flows (for NAM)
$ns color 1 Blue
$ns color 2 Red
#Open the Trace file
set file1 [open out.tr w]
$ns trace-all $file1
#Open the NAM trace file
set file2 [open out.nam w]
$ns namtrace-all $file2
#Define a 'finish' procedure
proc finish {} {
global ns file1 file2
$ns flush-trace
close $file1
close $file2
exec nam out.nam &
exit 0
}
# Next line should be commented out to have the static routing
$ns rtproto DV
#Create six nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
#Create links between the nodes
$ns duplex-link $n0 $n1 0.3Mb 10ms DropTail
$ns duplex-link $n1 $n2 0.3Mb 10ms DropTail
$ns duplex-link $n2 $n3 0.3Mb 10ms DropTail
$ns duplex-link $n1 $n4 0.3Mb 10ms DropTail
$ns duplex-link $n3 $n5 0.5Mb 10ms DropTail
$ns duplex-link $n4 $n5 0.5Mb 10ms DropTail
#Give node position (for NAM)
$ns duplex-link-op $n0 $n1 orient right
$ns duplex-link-op $n1 $n2 orient right
$ns duplex-link-op $n2 $n3 orient up
$ns duplex-link-op $n1 $n4 orient up-left
$ns duplex-link-op $n3 $n5 orient left-up
$ns duplex-link-op $n4 $n5 orient right-up
#Setup a TCP connection
set tcp [new Agent/TCP/Newreno]
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink/DelAck]
$ns attach-agent $n5 $sink
$ns connect $tcp $sink
$tcp set fid_ 1
#Setup a FTP over TCP connection
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP
$ns rtmodel-at 1.0 down $n1 $n4
$ns rtmodel-at 4.5 up $n1 $n4
$ns at 0.1 "$ftp start"
$ns at 6.0 "finish"
$ns run
hello manas.. i am a P.G student. i am working on Wireless sensor network. i want to implement energy model in Ns2. my project is regarding on "DATA AGGREGATION IN WSN" so. i want implemet data aggregation type tcl so, i could show waste of energy, packets-loss etc. parameters..
ReplyDeleteplease guide me...
thanks in advance.
parth patel
meetparth_1@yahoo.co.in
hello sir i want coding for create mobile nodes and how form clusters in wireless sensor networks by using ns2..
Deletemy mail id is tamilarashi7@gmail.com
Hi parth
ReplyDeleteBest of my knowledge u can implement the how to save energy in wsn .. suppose by using sleep mode etc.. U can follow the below link and the attach material. For ns2 modification u can refer to ns manual, Chapter 19 Energy Model in ns.
http://www.isi.edu/ilense/software/smac/ns2_energy.html
http://www.hindawi.com/journals/es/2011/307079/
http://people.csail.mit.edu/ronny/wireless_psm/readme.html
regards
Manas
hi,i am a M Tech student..i want to do 'recovery based data aggregation in wireless sensor network'..for this i want to use eliptic curve based public key cryptography based algorithm..Is Ns2 support eliptic curve cryptography?? if i get answer for this question only,i can confirm my tool..pls help me..hope ur reply soon to this id josnajose1990@gmail.com ..it is urgent..pls..
ReplyDeleteHey josna..were you able to do it?I'm also in search of it..
DeleteHello sir,
ReplyDeleteI am a M.E student.I need the coding information to how data aggregation using synopsis diffusion approach can be implemented in ns2...
pls help me sir...
my mail id:dineshbabu21@gmail.com
hi sir,
ReplyDeletei am M.E student. Am working with wireless LAN. I want to add 10 nodes in LAN using ns-2. pls help me sir.
mail id : shiny.ssn@gmail.com
hi sir, i am doing M.C.A i am doing a project in that i have to know the energy of the nodes throught the simulation can u guide me...,
ReplyDeleten if possible can u mail me any code through which i can try..., plz
my mail id is : madhavmahesh@gmail.com
Hello sir
ReplyDeleteI'm doing my final year project, your code tcl script for LAN netw work is vey helpful me, what I want to know how to make the output of XGraph? I need to do project the simulation of TCP/IP characteristics, and to analyze and measure the paramaters like throughtput, congestion window, delay, loss ratio., how I want to measure it..
thank you
fatinmasturahmj@yahoo.com
Hi Sir, do you have any idea on communication between 2 different technologies, for example WIFI and Zigbee nodes in ns2?
ReplyDeleteThank you :)
hello sir i want coding for create mobile nodes and how form clusters in wireless sensor networks by using ns2..
ReplyDeletemy mail id is tamilarashi7@gmail.com
hi tamil,
ReplyDeletethis is harvinder and i do the thesis for students in ns2 as well as matlab...
u can contact me at harvinder.949@gmail.com
hello sir.,i want detail for how to use ospf and eigrp protocol in ns2. my id is veejasan@gamil.com
ReplyDeletehello sir ,am yuvasri doing m.Tech final year (wc)
ReplyDeletesir am doing target tracking in WSN under bayesian algorithm technique but am in new in ns2 dont know how to write coding for my concept in tcl language .
sir plz sort out problem .plz send source code for target tracking in WSN using algm (tcl launguage ) else guide me how to wire program for this
yuvasekar7@gmail.com
Can anyone help me out with the tcl scripts for ECDH and session key generation using hash function.
ReplyDeleteHello,
ReplyDeletei am looking out for tcl script to do node authentication in Wireless sensor network using Digital signature and eliptic Curve.
Kindly help me with tcl script or code to perform simulation on ns2.
your blog is very much helpful!!!
Thanks
Varsha