Skip to main content

How to simulate ad hoc network in NS-2 ?

set ns_ [new Simulator]
set val(x) 800 ;# X dimension of topology
set val(y) 800 ;# Y dimension of topology
set val(nn) 50 ;# Number of node
set val(stop) 150.0 ;# Simulation time
set val(routing) AODV
set qtype Queue/DropTail/PriQueue
#set qtype CMUPriQueue # This queue will be used for DSR
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
set tracefd [open w]
$ns_ trace-all $tracefd
$ns_ use-newtrace
set namtrace [open out.nam w]
$ns_ namtrace-all-wireless $namtrace $val(x) $val(y)
set windowsVsTime2 [open w]
# Main Program
# ======================================================================
set god_ [create-god $val(nn)]

# Initialize Global Variables

#global node setting

$ns_ node-config -adhocRouting $val(routing) \
-llType LL \
-macType Mac/802_11\
-ifqType $qtype \
-ifqLen 50 \
-antType Antenna/OmniAntenna \
-propType Propagation/TwoRayGround \
-phyType Phy/WirelessPhy \
-channelType Channel/WirelessChannel \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-energyModel EnergyModel\
-rxPower 0.3\
-txPower 0.6\
-initialEnergy 100\
#-idlePower 712e-6 \
#-sleepPower 144e-9\
# -sensePower 0.0175/
Phy/WirelessPhy set CPThresh_ 10.0
Phy/WirelessPhy set CSThresh_ 3.65262e-10 ;#250m
Phy/WirelessPhy set RXThresh_ 3.65262e-10 ;#250m
Phy/WirelessPhy set Rb_ 2*1e6
Phy/WirelessPhy set Pt_ 3.00
Phy/WirelessPhy set freq_ 2.4e+7
Phy/WirelessPhy set L_ 1.0

#Create the specified number of nodes
for {set i 0} { $i < $val(nn) } {incr i} {
set node_($i) [$ns_ node]
source scen-50 # Number of Nodes Download this file and put in the same directory that configures nodes position.

for {set i 0} {$i < $val(nn) } {incr i} {
$ns_ initial_node_pos $node_($i) 30

set tcp1 [new Agent/TCP/Newreno]
$ns_ attach-agent $node_(1) $tcp1

set ftp1 [new Application/FTP]
$ftp1 attach-agent $tcp1

set sink1 [new Agent/TCPSink]
$ns_ attach-agent $node_(2) $sink1

$ns_ connect $tcp1 $sink1

$ns_ at 0.5 "$ftp1 start"
$ns_ at 140.0 "$ftp1 stop"

set tcp2 [new Agent/TCP/Newreno]
$ns_ attach-agent $node_(3) $tcp2

set ftp2 [new Application/FTP]
$ftp2 attach-agent $tcp2

set sink2 [new Agent/TCPSink]
$ns_ attach-agent $node_(4) $sink2

$ns_ connect $tcp2 $sink2

$ns_ at 0.5 "$ftp2 start"
$ns_ at 140.0 "$ftp2 stop"

set tcp3 [new Agent/TCP/Newreno]
$ns_ attach-agent $node_(5) $tcp3

set ftp3 [new Application/FTP]
$ftp3 attach-agent $tcp3

set sink3 [new Agent/TCPSink]
$ns_ attach-agent $node_(6) $sink3

$ns_ connect $tcp3 $sink3

$ns_ at 0.5 "$ftp3 start"
$ns_ at 140.0 "$ftp3 stop"

set tcp4 [new Agent/TCP/Newreno]
$ns_ attach-agent $node_(7) $tcp4

set ftp4 [new Application/FTP]
$ftp4 attach-agent $tcp4

set sink4 [new Agent/TCPSink]
$ns_ attach-agent $node_(8) $sink4

$ns_ connect $tcp4 $sink4

$ns_ at 0.5 "$ftp4 start"
$ns_ at 140.0 "$ftp4 stop"

proc plotWindow {tcpSource file} {
global ns_
set time 0.1
set now [$ns_ now]
set cwnd [ $tcpSource set cwnd_ ]
puts $file "$now $cwnd"
$ns_ at [expr $now+$time ] "plotWindow $tcpSource $file" }
$ns_ at 1.1 "plotWindow $tcp1 $windowsVsTime2"
for {set i 0} {$i < $val(nn) } {incr i} {
$ns_ at $val(stop) "$node_($i) reset ";
$ns_ at $val(stop) "stop"
$ns_ at [expr $val(stop)+ 0.1 ] "puts \"end simulation\" ; $ns_ halt"
proc stop {} {
global ns_ tracefd
$ns_ flush-trace
close $tracefd
# Tell nodes when the simulation ends

for {set i 0} {$i < $val(nn) } {incr i} {
$ns_ at $val(stop).0 "$node_($i) reset";
$ns_ at $val(stop).000 "$ns_ halt"
$ns_ run

Popular posts from this blog

What Are Growth Hacking Strategies?

Growth hacking refers to grab the user base by continuous experiment on all available marketing channels and products to rapid improvement of a business.
From above definition, it  is difficult to distinguish growth hacking from marketing strategy, giving examples  is better way to understand what is growth hacking.
Best examples of growth hacking.
1- Drop box- Drop box is considered to be one of the best examples of growth hacking, strategy of  drop box that a user want to increase its file storage size
drop box provides two options invite your friends or purchase storage, further human basic nature is that they like free things so users invite their friends and later some of them purchase too,  so here drop box spreading its business without spending a dollar  and also growing business.

2- Reliance Jio Infocomm Limited (Jio)- This is ever great example in cellular service sector that reliance grab millions of users in 3 months after providing 3 moths free services it made a huge user …

5 Growth Hacking Srategies In Blogging

In my previous article on growth hacking  What Are Growth Hacking Strategies? .  I presented some case studies that how some online businesses grew without spending millions of dollars on advertising, this growth hacking strategies can also be applied for blogging to increase visitors on the blog, further, in simple words growth hacking  is a rapid experiments  to apply all the tactics and appropriate technologies to   increase audiences. In blogging, growth hacking strategy can also be applied, here I will present some tactics that bloggers are applying before growth hacking word was formulated and some are need to be applied.

1. Do experiment on your content- In most  cases, users like simple sentences, but if you introduce few difficult words readers my welcome, some quotes that matches with your article can grab the attention of users. Further, it is fact  that 70% of word in English  are of French origin, you can introduce some French words and french speaking countries, like Fr…

Plagiarism in Blogging is Serious : How to Detect and Avoid

Most of the bloggers focus on SEO (Search Engine Optimisation), bounce rate, web traffic, clicks, page RPM, impression RPM, theme of the blog, plug-ins and finally total earnings, further, these are important parameters, however, knowingly or unknowingly they do not care about plagiarism which is very serious and can destroy blogging carrier. It happens with newbie they copy and post others articles and think that nobody is noticing, on the other hand, matured blogger can also make mistake and their article may be plagiarised.
To avoid plagiarism, both should use plagiarism detection softwares.
Moreover, there are several tools available to avoid plagiarism. In this article, first, I will describe what is plagiarism, second, types of plagiarism, third, how to avoid it ?
What is plagiarism ?
First Definition " Plagiarism is the act of taking another person's writing, conversation, song, or even idea and passing it off as your own [1]".
Second Definition " To …