SlideShare a Scribd company logo
STUDY OF ALOHA PROTOCOL USING NS2 NETWORK
               JAVA PROGRAM
Program:

set ns [new Simulator]
#Tell the simulator to use dynamic routing
$ns rtproto DV
$ns macType Mac/Sat/UnslottedAloha

#Open the nam trace file
set nf [open aloha.nam w]
$ns namtrace-all $nf

#Open the output files
set f0 [open aloha.tr w]
$ns trace-all $f0

#Define a 'finish' procedure
proc finish {} {
global ns f0 nf
$ns flush-trace

#Close the trace file
close $f0
close $nf

 #Call xgraph to display the results
exec nam aloha.nam &
exit 0 }

# 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 duplex links between nodes with bandwidth and distance
$ns duplex-link $n0 $n4 1Mb 50ms DropTail
$ns duplex-link $n1 $n4 1Mb 50ms DropTail
$ns duplex-link $n2 $n5 1Mb 1ms DropTail
$ns duplex-link $n3 $n5 1Mb 1ms DropTail
$ns duplex-link $n4 $n5 1Mb 50ms DropTail
$ns duplex-link $n2 $n3 1Mb 50ms DropTail

# Create a duplex link between nodes 4 and 5 as queue position
$ns duplex-link-op $n4 $n5 queuePos 0.5

#Create a UDP agent and attach it to node n(0)
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0

# Create a CBR traffic source and attach it to udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0

#Create a Null agent (a traffic sink) and attach it to node n(3)
set null0 [new Agent/Null]
$ns attach-agent $n2 $null0

#Connect the traffic source with the traffic sink
$ns connect $udp0 $null0

#Schedule events for the CBR agent and the network dynamics
 $ns at 0.5 "$cbr0 start"
$ns rtmodel-at 1.0 down $n5 $n2
$ns rtmodel-at 2.0 up $n5 $n2
$ns at 4.5 "$cbr0 stop"

#Call the finish procedure after 5 seconds of simulation time
$ns at 5.0 "finish"

#Run the simulation
$ns run
Ad

More Related Content

What's hot (6)

An introduction to MongoDB
An introduction to MongoDBAn introduction to MongoDB
An introduction to MongoDB
César Trigo
 
Chapter1 introduction
Chapter1 introductionChapter1 introduction
Chapter1 introduction
Dinesh K
 
Tips and Tricks of Toad for Oracle 10.6
Tips and Tricks of Toad for Oracle 10.6Tips and Tricks of Toad for Oracle 10.6
Tips and Tricks of Toad for Oracle 10.6
Dsunte Wilson
 
Top 40 sql queries for testers
Top 40 sql queries for testersTop 40 sql queries for testers
Top 40 sql queries for testers
tlvd
 
Trees in data structures
Trees in data structuresTrees in data structures
Trees in data structures
ASairamSairam1
 
SQL practice questions - set 3
SQL practice questions - set 3SQL practice questions - set 3
SQL practice questions - set 3
Mohd Tousif
 
An introduction to MongoDB
An introduction to MongoDBAn introduction to MongoDB
An introduction to MongoDB
César Trigo
 
Chapter1 introduction
Chapter1 introductionChapter1 introduction
Chapter1 introduction
Dinesh K
 
Tips and Tricks of Toad for Oracle 10.6
Tips and Tricks of Toad for Oracle 10.6Tips and Tricks of Toad for Oracle 10.6
Tips and Tricks of Toad for Oracle 10.6
Dsunte Wilson
 
Top 40 sql queries for testers
Top 40 sql queries for testersTop 40 sql queries for testers
Top 40 sql queries for testers
tlvd
 
Trees in data structures
Trees in data structuresTrees in data structures
Trees in data structures
ASairamSairam1
 
SQL practice questions - set 3
SQL practice questions - set 3SQL practice questions - set 3
SQL practice questions - set 3
Mohd Tousif
 

Viewers also liked (6)

Ns2programs
Ns2programsNs2programs
Ns2programs
Meenakshi Devi
 
Network lab manual
Network lab manualNetwork lab manual
Network lab manual
Prabhu D
 
Aloha
AlohaAloha
Aloha
mangal das
 
Working with NS2
Working with NS2Working with NS2
Working with NS2
chanchal214
 
Protocol implementation on NS2
Protocol implementation on NS2Protocol implementation on NS2
Protocol implementation on NS2
amreshrai02
 
ALOHA Protocol (in detail)
ALOHA Protocol (in detail)ALOHA Protocol (in detail)
ALOHA Protocol (in detail)
Hinal Lunagariya
 
Network lab manual
Network lab manualNetwork lab manual
Network lab manual
Prabhu D
 
Working with NS2
Working with NS2Working with NS2
Working with NS2
chanchal214
 
Protocol implementation on NS2
Protocol implementation on NS2Protocol implementation on NS2
Protocol implementation on NS2
amreshrai02
 
ALOHA Protocol (in detail)
ALOHA Protocol (in detail)ALOHA Protocol (in detail)
ALOHA Protocol (in detail)
Hinal Lunagariya
 
Ad

Similar to Study of aloha protocol using ns2 network java proram (20)

Cs757 ns2-tutorial-exercise
Cs757 ns2-tutorial-exerciseCs757 ns2-tutorial-exercise
Cs757 ns2-tutorial-exercise
Pratik Joshi
 
ns-simple.pdf
ns-simple.pdfns-simple.pdf
ns-simple.pdf
Jayaprasanna4
 
ns2-lecture.ppt
ns2-lecture.pptns2-lecture.ppt
ns2-lecture.ppt
AnniModgil
 
NS2-tutorial.pdf
NS2-tutorial.pdfNS2-tutorial.pdf
NS2-tutorial.pdf
srinivasa gowda
 
NS2-tutorial.ppt
NS2-tutorial.pptNS2-tutorial.ppt
NS2-tutorial.ppt
Wajath
 
Ns2 ns3 training in mohali
Ns2 ns3 training in mohaliNs2 ns3 training in mohali
Ns2 ns3 training in mohali
Arwinder paul singh
 
Introduction to ns2
Introduction to ns2Introduction to ns2
Introduction to ns2
ProfDrSharadSharma
 
NS2 Demo PPT for configuring networks.pptx
NS2 Demo PPT for configuring networks.pptxNS2 Demo PPT for configuring networks.pptx
NS2 Demo PPT for configuring networks.pptx
ERPraven
 
Ns 2 Network Simulator An Introduction
Ns 2 Network Simulator An IntroductionNs 2 Network Simulator An Introduction
Ns 2 Network Simulator An Introduction
Jaipur National University, Jaipur, Rajasthan, India
 
link-state-routing-3.pdf
link-state-routing-3.pdflink-state-routing-3.pdf
link-state-routing-3.pdf
Jayaprasanna4
 
Ns tutorial
Ns tutorialNs tutorial
Ns tutorial
SAMMMATHEW
 
NS2 (1).docx
NS2 (1).docxNS2 (1).docx
NS2 (1).docx
SanjayDharmaraj
 
Ns network simulator
Ns network simulatorNs network simulator
Ns network simulator
Dr. Edwin Hernandez
 
Network Simulator Tutorial
Network Simulator TutorialNetwork Simulator Tutorial
Network Simulator Tutorial
cscarcas
 
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
Selvaraj Seerangan
 
B.Tech. Lab Record for Data Communication & Computer Networks
B.Tech.  Lab Record for  Data Communication & Computer NetworksB.Tech.  Lab Record for  Data Communication & Computer Networks
B.Tech. Lab Record for Data Communication & Computer Networks
swapnilherage
 
Ns2: OTCL - PArt II
Ns2: OTCL - PArt IINs2: OTCL - PArt II
Ns2: OTCL - PArt II
Ajit Nayak
 
Ns2
Ns2Ns2
Ns2
varsha mohite
 
Ns2
Ns2Ns2
Ns2
varsha mohite
 
NS-2 Tutorial
NS-2 TutorialNS-2 Tutorial
NS-2 Tutorial
code453
 
Ad

More from Meenakshi Devi (6)

Good habits
Good habitsGood habits
Good habits
Meenakshi Devi
 
Mapping Problem Domain Objects to Object-Persistence Formats(OOAD)
Mapping Problem Domain Objects to Object-Persistence Formats(OOAD)Mapping Problem Domain Objects to Object-Persistence Formats(OOAD)
Mapping Problem Domain Objects to Object-Persistence Formats(OOAD)
Meenakshi Devi
 
Mobile computing seminar
Mobile computing seminarMobile computing seminar
Mobile computing seminar
Meenakshi Devi
 
Ant colony optimization
Ant colony optimizationAnt colony optimization
Ant colony optimization
Meenakshi Devi
 
Asychronous transfer mode(atm)
Asychronous transfer mode(atm)Asychronous transfer mode(atm)
Asychronous transfer mode(atm)
Meenakshi Devi
 
Greedymethod
GreedymethodGreedymethod
Greedymethod
Meenakshi Devi
 
Mapping Problem Domain Objects to Object-Persistence Formats(OOAD)
Mapping Problem Domain Objects to Object-Persistence Formats(OOAD)Mapping Problem Domain Objects to Object-Persistence Formats(OOAD)
Mapping Problem Domain Objects to Object-Persistence Formats(OOAD)
Meenakshi Devi
 
Mobile computing seminar
Mobile computing seminarMobile computing seminar
Mobile computing seminar
Meenakshi Devi
 
Ant colony optimization
Ant colony optimizationAnt colony optimization
Ant colony optimization
Meenakshi Devi
 
Asychronous transfer mode(atm)
Asychronous transfer mode(atm)Asychronous transfer mode(atm)
Asychronous transfer mode(atm)
Meenakshi Devi
 

Recently uploaded (20)

CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales moduleHow To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
Celine George
 
MCQS (EMERGENCY NURSING) DR. NASIR MUSTAFA
MCQS (EMERGENCY NURSING) DR. NASIR MUSTAFAMCQS (EMERGENCY NURSING) DR. NASIR MUSTAFA
MCQS (EMERGENCY NURSING) DR. NASIR MUSTAFA
Dr. Nasir Mustafa
 
Origin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theoriesOrigin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theories
PrachiSontakke5
 
The role of wall art in interior designing
The role of wall art in interior designingThe role of wall art in interior designing
The role of wall art in interior designing
meghaark2110
 
Peer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docx
Peer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docxPeer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docx
Peer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docx
19lburrell
 
Rebuilding the library community in a post-Twitter world
Rebuilding the library community in a post-Twitter worldRebuilding the library community in a post-Twitter world
Rebuilding the library community in a post-Twitter world
Ned Potter
 
Botany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic ExcellenceBotany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic Excellence
online college homework help
 
libbys peer assesment.docx..............
libbys peer assesment.docx..............libbys peer assesment.docx..............
libbys peer assesment.docx..............
19lburrell
 
COPA Apprentice exam Questions and answers PDF
COPA Apprentice exam Questions and answers PDFCOPA Apprentice exam Questions and answers PDF
COPA Apprentice exam Questions and answers PDF
SONU HEETSON
 
Module 1: Foundations of Research
Module 1: Foundations of ResearchModule 1: Foundations of Research
Module 1: Foundations of Research
drroxannekemp
 
Module_2_Types_and_Approaches_of_Research (2).pptx
Module_2_Types_and_Approaches_of_Research (2).pptxModule_2_Types_and_Approaches_of_Research (2).pptx
Module_2_Types_and_Approaches_of_Research (2).pptx
drroxannekemp
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 
INSULIN.pptx by Arka Das (Bsc. Critical care technology)
INSULIN.pptx by Arka Das (Bsc. Critical care technology)INSULIN.pptx by Arka Das (Bsc. Critical care technology)
INSULIN.pptx by Arka Das (Bsc. Critical care technology)
ArkaDas54
 
INQUISITORS School Quiz Prelims 2025.pptx
INQUISITORS School Quiz Prelims 2025.pptxINQUISITORS School Quiz Prelims 2025.pptx
INQUISITORS School Quiz Prelims 2025.pptx
SujatyaRoy
 
Search Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo SlidesSearch Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo Slides
Celine George
 
The History of Kashmir Lohar Dynasty NEP.ppt
The History of Kashmir Lohar Dynasty NEP.pptThe History of Kashmir Lohar Dynasty NEP.ppt
The History of Kashmir Lohar Dynasty NEP.ppt
Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
antiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidenceantiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidence
PrachiSontakke5
 
How to Use Upgrade Code Command in Odoo 18
How to Use Upgrade Code Command in Odoo 18How to Use Upgrade Code Command in Odoo 18
How to Use Upgrade Code Command in Odoo 18
Celine George
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales moduleHow To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
Celine George
 
MCQS (EMERGENCY NURSING) DR. NASIR MUSTAFA
MCQS (EMERGENCY NURSING) DR. NASIR MUSTAFAMCQS (EMERGENCY NURSING) DR. NASIR MUSTAFA
MCQS (EMERGENCY NURSING) DR. NASIR MUSTAFA
Dr. Nasir Mustafa
 
Origin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theoriesOrigin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theories
PrachiSontakke5
 
The role of wall art in interior designing
The role of wall art in interior designingThe role of wall art in interior designing
The role of wall art in interior designing
meghaark2110
 
Peer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docx
Peer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docxPeer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docx
Peer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docx
19lburrell
 
Rebuilding the library community in a post-Twitter world
Rebuilding the library community in a post-Twitter worldRebuilding the library community in a post-Twitter world
Rebuilding the library community in a post-Twitter world
Ned Potter
 
Botany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic ExcellenceBotany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic Excellence
online college homework help
 
libbys peer assesment.docx..............
libbys peer assesment.docx..............libbys peer assesment.docx..............
libbys peer assesment.docx..............
19lburrell
 
COPA Apprentice exam Questions and answers PDF
COPA Apprentice exam Questions and answers PDFCOPA Apprentice exam Questions and answers PDF
COPA Apprentice exam Questions and answers PDF
SONU HEETSON
 
Module 1: Foundations of Research
Module 1: Foundations of ResearchModule 1: Foundations of Research
Module 1: Foundations of Research
drroxannekemp
 
Module_2_Types_and_Approaches_of_Research (2).pptx
Module_2_Types_and_Approaches_of_Research (2).pptxModule_2_Types_and_Approaches_of_Research (2).pptx
Module_2_Types_and_Approaches_of_Research (2).pptx
drroxannekemp
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 
INSULIN.pptx by Arka Das (Bsc. Critical care technology)
INSULIN.pptx by Arka Das (Bsc. Critical care technology)INSULIN.pptx by Arka Das (Bsc. Critical care technology)
INSULIN.pptx by Arka Das (Bsc. Critical care technology)
ArkaDas54
 
INQUISITORS School Quiz Prelims 2025.pptx
INQUISITORS School Quiz Prelims 2025.pptxINQUISITORS School Quiz Prelims 2025.pptx
INQUISITORS School Quiz Prelims 2025.pptx
SujatyaRoy
 
Search Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo SlidesSearch Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo Slides
Celine George
 
antiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidenceantiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidence
PrachiSontakke5
 
How to Use Upgrade Code Command in Odoo 18
How to Use Upgrade Code Command in Odoo 18How to Use Upgrade Code Command in Odoo 18
How to Use Upgrade Code Command in Odoo 18
Celine George
 

Study of aloha protocol using ns2 network java proram

  • 1. STUDY OF ALOHA PROTOCOL USING NS2 NETWORK JAVA PROGRAM Program: set ns [new Simulator] #Tell the simulator to use dynamic routing $ns rtproto DV $ns macType Mac/Sat/UnslottedAloha #Open the nam trace file set nf [open aloha.nam w] $ns namtrace-all $nf #Open the output files set f0 [open aloha.tr w] $ns trace-all $f0 #Define a 'finish' procedure proc finish {} { global ns f0 nf $ns flush-trace #Close the trace file close $f0 close $nf #Call xgraph to display the results exec nam aloha.nam & exit 0 } # 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]
  • 2. # Create duplex links between nodes with bandwidth and distance $ns duplex-link $n0 $n4 1Mb 50ms DropTail $ns duplex-link $n1 $n4 1Mb 50ms DropTail $ns duplex-link $n2 $n5 1Mb 1ms DropTail $ns duplex-link $n3 $n5 1Mb 1ms DropTail $ns duplex-link $n4 $n5 1Mb 50ms DropTail $ns duplex-link $n2 $n3 1Mb 50ms DropTail # Create a duplex link between nodes 4 and 5 as queue position $ns duplex-link-op $n4 $n5 queuePos 0.5 #Create a UDP agent and attach it to node n(0) set udp0 [new Agent/UDP] $ns attach-agent $n0 $udp0 # Create a CBR traffic source and attach it to udp0 set cbr0 [new Application/Traffic/CBR] $cbr0 set packetSize_ 500 $cbr0 set interval_ 0.005 $cbr0 attach-agent $udp0 #Create a Null agent (a traffic sink) and attach it to node n(3) set null0 [new Agent/Null] $ns attach-agent $n2 $null0 #Connect the traffic source with the traffic sink $ns connect $udp0 $null0 #Schedule events for the CBR agent and the network dynamics $ns at 0.5 "$cbr0 start" $ns rtmodel-at 1.0 down $n5 $n2 $ns rtmodel-at 2.0 up $n5 $n2 $ns at 4.5 "$cbr0 stop" #Call the finish procedure after 5 seconds of simulation time $ns at 5.0 "finish" #Run the simulation $ns run
  翻译: