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

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 …

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 …

Questions related to time and work(समय और काम से संबंधित प्रश्न).

X can do a work in 2 days Y can do the same work in 3 days. If  X and Y work together, how many days work will take to be completed ?

   X's one day work = 1/2
       Y's one day work = 1/3
     (X+Y)'s  one day work = ( 1/2 + 1/3)
                                          = 5/6

      Therefore , together X and  Y can complete the work in 6/5 days.

 X  एक  काम 2 दिनों में काम कर सकता है Y तीन दिनों में  कर सकता है। अगर X और Y एक साथ काम करते हैं, तो पूरा करने के कितना समय लगेगा?

    X  का एक दिन का काम = 1/2

       Y  का एक दिन का काम = 1/3

     (X + X) का एक दिन का काम = (1/2 + 1/3)

                                          = 5/6

      इसलिए, एक साथ एक्स और वाई 6/5 दिनों में काम पूरा कर सकते हैं।

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…

Top 5 freelance websites for beginners

On line market places are becoming more and more popular, such as, web development, search engine optimization , video and audio editing, translation, writing services, further, many websites provide a place where clients and service providers can interact and deal on a service or product on some price  on their websites, these forums are called freelance and service provider are called freelancers, moreover, many websites provide place to interact freelancer and clients, here, in this post, I will list some of them which are very popular. Started in 2010, a popular market place especially for digital marketing, writing and translation, programming and tech, video and animation,  graphic and design, business and the minimum price is for per job completion  is $5.  Founded in 1999 and formerly Elance is also very good on line market place for free lancers, further, the jobs are mainly software products and service oriented, writing skills oriented. In addit…

5 HTML Tags That Every Bloggers Should Know

Web content management systems are very smart, a blogger can do many things, such as, adding image in a blog, adding hyper link, changing font colors and sizes, but many bloggers come across the problems  that  they have to use HTML tags. In this post, I will list and describe some useful tags that every bloggers should know.
Description  #1-<a> Anchor tag (Hyper link tag)-  This tag is used to link  web documents, such as, sharing a post , an image or a video, these all internally use hyper link tag. The structure of tag is.
<a href="" >This link points to facebook</a>

#2-<img> tag (Image tag) - This tag is very important form the search engine optimization point of view, because if you are putting an image on your website and use this tag you must use alt attribute, because images and videos takes more time to load than text documents then what happens when text documents are loaded but image are not there will a blank space…

What Is Online Content Marketing? Things Should Be Taken Care In The Content Marketing.

Online content marketing involves creating contents,  such as, articles, videos and webinar   which  drive traffic on website for sailing products by directly or with the help of online advertising.

  As Internet users are growing and their awareness about using websites and mobile applications online presence of businesses are growing and they are using different platforms to advertise their products, such as,  AdWords, AdMobad ad networks under the umbrella of Google or using affiliate marketing, as a result, the opportunities have come for bloggers and webpreneurs to earn money from their content.

Things should be taken care in content marketing.

Content is king is said  by many bloggers that means your content should be important and relevant to target audience.Content should be  unique and does not violate the copyrights, because copyright violation is  considered as a serious issue. Social media  and e-mail marketing platforms should be used in such a manner, so that, your conten…

What Is Web Caching? What Is Importance In SEO?

Web caching is a technique that puts a HTTP cache server  between browser and main server that stores web pages that will be used in future to reduce main server load and decrease web page load time.

What happens when you put a lot of plug-ins, widgets, videos or many image on your website that looks great, however, it increases website load time and affect SEO, to decrease load time web cache server play an important role. Further, when Google indexed web pages and it also keeps a copy of the web page on cache server.

Importance of caching of web pages in SEO

It affects user experience, suppose your website takes  15 seconds more time than your competitor,  in this gap user will switch to your competitor website and your traffic will reduce significantly.

Tools to check web page speed
Google PageSpeed Insights this tool measures your web page speed and gives some suggestions to improve your website speed.

Pingdom Website Speed Test - This website uses ping utility to test speed of  awe…

What Are Dofollow And Nofollow Links In SEO?

Back link is a very important parameter that search engines consider for page
ranking, and Bloggers make back links in many ways, such as, posting their articles on social media, comment on others blog or websites, through guest posting, by directory submission and even some Bloggers  purchase back links ( Google consider purchasing back links as fraud). In addition, back links are of two types do follow and  no follow, do follow means if you post an article on a website then it will be considered as a back link by search engines because website on you have submitted your post consider your link as do follow, on the other hand,  many websites consider URL as spam or advertisement and provides no follow link, and the URL does not help in web's SEO optimization.
However, Google consider any link which  not a spam is signal of the reputation of the website.

Total Pageviews