SlideShare una empresa de Scribd logo
1 de 27
Descargar para leer sin conexión
An Introduction to
Network Simulator
Dr. Ajit K Nayak
Dept of CSIT, ITER
S‘O’A University, BBSR
Part II
• Introducing OTcl
• Working with NS2
Basics of OTcl - I
• Class is used to register a class name.
– Unlike C++, there is no class body where all members of
the class are declared/defined.
– i.e. once the class is registered, the member functions
and data members can be declared anywhere in the
script with the use of the class name and self variable.
• instproc is used to define a member function.
• init is the name of constructor.
• self is equivalent to the ‘this’ keyword of C++.
• instvar is used to declare a data member.
• superclass is used to specify the parent class in case
of inheritance.
NS-2/AN/Intro/ 4
Basics of OTcl - II
• Object initialization:
– set ctr [ new Counter ]
• ctr is an object of class Counter
• It calls the constructor to initialize the instance
variables.
• Method invocation:
– $ctr increment
• invokes the method increment of class Counter
– puts [ $ctr getValue ]
• invokes the method getValue of class Counter and
prints the value returned from the member function
NS-2/AN/Intro/ 5
NS-2/AN/Intro/ 6
Example – Class-Object (I)
# Create a class called "mom" and add a member function called
"greet"
Class Mom
Mom instproc greet {} {
$self instvar age
puts “$age years old mom say: ntHow are
you doing?”
}
# Create a child class of "mom" called "kid" and override the
member function "greet"
Class Kid -superclass Mom
Kid instproc greet {} {
$self instvar age
puts “$age years old kid say: ntWhat’s
up, dude?”
}
Example – Class-Object (II)
NS-2/AN/Intro/ 7
# Create a mom and a kid object & set age for each
set mom [new Mom]
$mom set age 45
set kid [new Kid]
$kid set age 15
# Calling member function "greet" of each object
$mom greet
$kid greet
Output:
45 year old mom say:
How are you doing?
15 year old kid say:
what’s up dude?
Task I
• Execute the previous OTcl program.
• Fill in the spaces provided to complete the OTcl
program below, execute the program and note the
output
Class Real
Real instproc init {x} { # constructor
$self instvar value
set value $x
}
Real instproc multiply { x } {
... FILL IN: multiply val and x then print ...
}
Real instproc divide {x} {
$self instvar value
... FILL IN: divide val and x then print result...
}
NS-2/AN/Intro/ 8
Task I contd.
Class Integer -superclass Real
Integer instproc divide {x} {
... FILL IN ...
}
set realA [new Real 12.3]
set realB [new Real 0.5]
$realA multiply $realB
$realA divide $realB
set integerA [new Integer 12]
set integerB [new Integer 5]
$integerA multiply $integerB
$integerA divide $integerB
NS-2/AN/Intro/ 9
NS2 Programming Structure
• Create the event scheduler
• Turn on tracing
• Create network topology
• Create transport connections
• Generate traffic
– Traffic source
– Traffic sink
– Connection between source & sink
• Run the simulation
NS-2/AN/Intro/ 10
Creating the event scheduler
• Create event scheduler
– set ns [new Simulator]
• Schedule an event
– syntax: $ns at <time> <event>
– $ns at 5.0 “finish”
• Start Scheduler
– $ns run
NS-2/AN/Intro/ 11
proc finish {} {
global ns nf
close $nf
exec nam out.nam &
exit 0
}
Tracing (outputs)
• Packet/Event Trace
– $ns trace-all[open out.tr w]
• NAM Trace (Network Animator)
– set nf [open out.nam w]
– $ns namtrace-all $nf
NS-2/AN/Intro/ 12
Creating topology
(Two nodes connected by a link)
• Creating nodes
– set n0 [$ns node]
– set n1 [$ns node]
• Creating link between
nodes
– syntax: $ns <link_type> <node1> <node2>
<bandwidth> <delay> <queueType>
– $ns duplexlink $n0 $n1 1Mb 10ms DropTail
NS-2/AN/Intro/ 13
Program for two node network
1. Create a file named
twoNode.tcl and add the
following contents in it.
set ns [new Simulator]
set nf [open twoNode.nam w]
$ns namtrace-all $nf
set n0 [$ns node]
set n1 [$ns node]
$ns duplex-link $n0 $n2
100Mb 5ms DropTail
$ns run
NS-2/AN/Intro/ 14
2. Save and exit from the editor,
Now execute the program with
following command in command
line
ns twoNode.tcl
3. This will generate
twoNode.nam. To see the
visualization, issue the following
command in command line
nam twoNode.nam &
Color
• Nodes Colour:
– $node color blue ;#creates a blue color
node
– (Other colors are red, green, chocolate
etc.)
• Node Shape:
– $node shape box ;#creates a square
shaped node
– (Other shapes are circle, box, hexagon )
• $n0 add-mark m0 blue box ;# creates
a concentric circle over node n0
• $ns at 2.0 $n0 delete-mark m0" ;#
deletes the mark at simulation time 2
sec.
• Node Label:
– $n0 label Router ;# labels n0 as a Router
NS-2/AN/Intro/ 15
• Link Colour:
• $ns duplex-link-op $n0 $n1 color
green"
link from n0 to n1 becomes green
• Link Label:
• $ns duplex-link-op $n0 $n1 label
point-to-point“
link is labelled as point-to- point
• Link Orientation:
• $ns duplex-link-op $n(0) $n(1)
orient right
the link is drawn horizontally from
n0 to n1
• $ns duplex-link-op $n(1) $n(2)
orient left
• ( up, down, right-up, left-down,
60deg)
Task II
• Execute the twoNode.tcl
• Create a ring network of 3 nodes with
adjacent nodes of different color and red
color links between them.
NS-2/AN/Intro/ 16
Sending data (UDP)
• Create UDP source agent (transport
connection)
– set udp [new Agent/UDP]
– $ns attach-agent $n0 $udp
• Create UDP sink agent
– set null [new Agent/Null]
– $ns attach-agent $n1 $null
• Connect two transport (source-sink) agents
– $ns connect $udp $null
NS-2/AN/Intro/ 17
Sending data contd.
• Create CBR traffic source on the top of UDP
agent (Application)
– set cbr [new Application/Traffic/CBR]
– $cbr attach-agent $udp
• Start and stop of data transmission
– $ns at 0.5 “$cbr start”
– $ns at 4.5 “$cbr stop”
NS-2/AN/Intro/ 18
Complete Program
set ns [new Simulator]
set n0 [$ns node]
set n1 [$ns node]
$ns trace-all [open
twoNode.tr w]
set nf [open twoNode.nam w]
$ns namtrace-all $nf
$ns duplex-link $n0 $n1
100Kb 10ms DropTail
set udp [new Agent/UDP]
$ns attach-agent $n0 $udp
set null [new Agent/Null]
$ns attach-agent $n1 $null
$ns connect $udp $null
NS-2/AN/Intro/ 19
set cbr [new
Application/Traffic/CBR]
$cbr attach-agent $udp
$ns at 0.1 “$cbr start”
$ns at 2.35 “$cbr stop”
$ns at 2.4 “finish”
proc finish {} {
global nf ; close $nf
exec nam twoNode.nam &
exit 0
}
$ns run
Sending data (TCP)
• Create TCP agent and attach it to the node
– set tcp0 [new Agent/TCP]
– $ns attach-agent $n0 $tcp0
• Create a Null Agent and attach it to the node
– set null0 [new Agent/TCPSink]
– $ns attach-agent $n1 $null0
• Connect the agents
– $ns connect $tcp0 $null0
• Trafic on the top of TCP (FTP or Telnet)
– set ftp [new Application/FTP]
– $ftp attach-agent $tcp0 OR
– set telnet [new Application/Telnet]
– $telnet attach-agent $tcp0
Task III
1)Execute modified twoNode.tcl
and observe the animation
output.
2) Excute the same usng TCP and
ftp .
Output? (twoNode.tr)
+ 1 0 1 cbr 500 ------- 0 0.0 1.0 0 0
- 1 0 1 cbr 500 ------- 0 0.0 1.0 0 0
+ 1.005 0 1 cbr 500 ------- 0 0.0 1.0 1 1
- 1.005 0 1 cbr 500 ------- 0 0.0 1.0 1 1
+ 1.01 0 1 cbr 500 ------- 0 0.0 1.0 2 2
- 1.01 0 1 cbr 500 ------- 0 0.0 1.0 2 2
r 1.014 0 1 cbr 500 ------- 0 0.0 1.0 0 0
+ 1.015 0 1 cbr 500 ------- 0 0.0 1.0 3 3
- 1.015 0 1 cbr 500 ------- 0 0.0 1.0 3 3
r 1.019 0 1 cbr 500 ------- 0 0.0 1.0 1 1
+ 1.02 0 1 cbr 500 ------- 0 0.0 1.0 4 4
- 1.02 0 1 cbr 500 ------- 0 0.0 1.0 4 4
r 1.024 0 1 cbr 500 ------- 0 0.0 1.0 2 2
Explaining Output (I)
• Column 1: events
– +: enqueue
– -: dequeue
– r: receive
– d: drop
• Column 2:
– Time of event
• Column 3 & 4:
– Trace between which two nodes?
Explaining Output (II)
• Column 5,6:
– Packet type, Packet size
• Column 7-14:
– Flags used for ECN (not used here)
• Column 15:
– IP flow identifier (IPv6)
• Column 16,17:
– Source & Destination address
• Column 18,19:
– Sequence number, unique packet identifier
Suggested Readings
• OTcl Tutorials
– http://www.tcl.tk/man/tcl8.5/tutorial/tcltutorial.h
tml
• NS-2 Tutorials
– http://www.isi.edu/nsnam/ns/tutorial
– http://nile.wpi.edu/NS/
– NS Manual
NS-2/AN/Intro/ 26
Thank You
End of Part II

Más contenido relacionado

Destacado

Innovation is almost impossible for older companies
Innovation is almost impossible for older companiesInnovation is almost impossible for older companies
Innovation is almost impossible for older companies
Sebastien Juras
 
03 administracion de requisitos
03 administracion de requisitos03 administracion de requisitos
03 administracion de requisitos
Ricardo Quintero
 
Uml Omg Fundamental Certification 3
Uml Omg Fundamental Certification 3Uml Omg Fundamental Certification 3
Uml Omg Fundamental Certification 3
Ricardo Quintero
 
Uml Omg Fundamental Certification 2
Uml Omg Fundamental Certification 2Uml Omg Fundamental Certification 2
Uml Omg Fundamental Certification 2
Ricardo Quintero
 

Destacado (20)

Operating Systems Part III-Memory Management
Operating Systems Part III-Memory ManagementOperating Systems Part III-Memory Management
Operating Systems Part III-Memory Management
 
The badguy summary
The badguy   summaryThe badguy   summary
The badguy summary
 
Innovation is almost impossible for older companies
Innovation is almost impossible for older companiesInnovation is almost impossible for older companies
Innovation is almost impossible for older companies
 
Software Engineering an Introduction
Software Engineering an IntroductionSoftware Engineering an Introduction
Software Engineering an Introduction
 
Psychology explains the power of Storytelling
Psychology explains the power of StorytellingPsychology explains the power of Storytelling
Psychology explains the power of Storytelling
 
Manual 02
Manual 02Manual 02
Manual 02
 
Software Engineering :Behavioral Modelling - I Sequence diagram
Software Engineering :Behavioral Modelling - I Sequence diagram Software Engineering :Behavioral Modelling - I Sequence diagram
Software Engineering :Behavioral Modelling - I Sequence diagram
 
03 administracion de requisitos
03 administracion de requisitos03 administracion de requisitos
03 administracion de requisitos
 
The Bad Guy in your company and how have him under control
The Bad Guy in your company and how have him under controlThe Bad Guy in your company and how have him under control
The Bad Guy in your company and how have him under control
 
The Ultimate gift
The Ultimate giftThe Ultimate gift
The Ultimate gift
 
01 conceptos de diseño
01 conceptos de diseño01 conceptos de diseño
01 conceptos de diseño
 
Uml Omg Fundamental Certification 3
Uml Omg Fundamental Certification 3Uml Omg Fundamental Certification 3
Uml Omg Fundamental Certification 3
 
Database Programming using SQL
Database Programming using SQLDatabase Programming using SQL
Database Programming using SQL
 
Uml Omg Fundamental Certification 2
Uml Omg Fundamental Certification 2Uml Omg Fundamental Certification 2
Uml Omg Fundamental Certification 2
 
Software Engineering :UML class diagrams
Software Engineering :UML class diagramsSoftware Engineering :UML class diagrams
Software Engineering :UML class diagrams
 
Perfiles UML
Perfiles UMLPerfiles UML
Perfiles UML
 
INNOVATION IS NOT AN OPTION
INNOVATION IS NOT AN OPTIONINNOVATION IS NOT AN OPTION
INNOVATION IS NOT AN OPTION
 
Computer Fundamentals & Intro to C Programming module i
Computer Fundamentals & Intro to C Programming module iComputer Fundamentals & Intro to C Programming module i
Computer Fundamentals & Intro to C Programming module i
 
Parallel programming using MPI
Parallel programming using MPIParallel programming using MPI
Parallel programming using MPI
 
Software Engineering : OOAD using UML
Software Engineering : OOAD using UMLSoftware Engineering : OOAD using UML
Software Engineering : OOAD using UML
 

Similar a Ns2: OTCL - PArt II

NS2-tutorial.ppt
NS2-tutorial.pptNS2-tutorial.ppt
NS2-tutorial.ppt
Wajath
 
NS-2 Tutorial
NS-2 TutorialNS-2 Tutorial
NS-2 Tutorial
code453
 

Similar a Ns2: OTCL - PArt II (20)

NS2-tutorial.ppt
NS2-tutorial.pptNS2-tutorial.ppt
NS2-tutorial.ppt
 
Network Simulator Tutorial
Network Simulator TutorialNetwork Simulator Tutorial
Network Simulator Tutorial
 
Working with NS2
Working with NS2Working with NS2
Working with NS2
 
Ns network simulator
Ns network simulatorNs network simulator
Ns network simulator
 
NS2-tutorial.pdf
NS2-tutorial.pdfNS2-tutorial.pdf
NS2-tutorial.pdf
 
Cs757 ns2-tutorial-exercise
Cs757 ns2-tutorial-exerciseCs757 ns2-tutorial-exercise
Cs757 ns2-tutorial-exercise
 
Ns tutorial
Ns tutorialNs tutorial
Ns tutorial
 
Ns2 ns3 training in mohali
Ns2 ns3 training in mohaliNs2 ns3 training in mohali
Ns2 ns3 training in mohali
 
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
 
ns2-lecture.ppt
ns2-lecture.pptns2-lecture.ppt
ns2-lecture.ppt
 
Ns 2 Network Simulator An Introduction
Ns 2 Network Simulator An IntroductionNs 2 Network Simulator An Introduction
Ns 2 Network Simulator An Introduction
 
ns2-training material
ns2-training materialns2-training material
ns2-training material
 
Tut hemant ns2
Tut hemant ns2Tut hemant ns2
Tut hemant ns2
 
NS2 (1).docx
NS2 (1).docxNS2 (1).docx
NS2 (1).docx
 
~Ns2~
~Ns2~~Ns2~
~Ns2~
 
NS-2 Tutorial
NS-2 TutorialNS-2 Tutorial
NS-2 Tutorial
 
Ns2pre
Ns2preNs2pre
Ns2pre
 
Ns2: Introduction - Part I
Ns2: Introduction - Part INs2: Introduction - Part I
Ns2: Introduction - Part I
 
cscn1819.pdf
cscn1819.pdfcscn1819.pdf
cscn1819.pdf
 
Introduction to ns2
Introduction to ns2Introduction to ns2
Introduction to ns2
 

Más de Ajit Nayak

Más de Ajit Nayak (18)

Software Engineering : Software testing
Software Engineering : Software testingSoftware Engineering : Software testing
Software Engineering : Software testing
 
Software Engineering : Requirement Analysis & Specification
Software Engineering : Requirement Analysis & SpecificationSoftware Engineering : Requirement Analysis & Specification
Software Engineering : Requirement Analysis & Specification
 
Software Engineering : Process Models
Software Engineering : Process ModelsSoftware Engineering : Process Models
Software Engineering : Process Models
 
NS2: AWK and GNUplot - PArt III
NS2: AWK and GNUplot - PArt IIINS2: AWK and GNUplot - PArt III
NS2: AWK and GNUplot - PArt III
 
Socket programming using C
Socket programming using CSocket programming using C
Socket programming using C
 
Object Oriented Analysis Design using UML
Object Oriented Analysis Design using UMLObject Oriented Analysis Design using UML
Object Oriented Analysis Design using UML
 
Operating Systems Part I-Basics
Operating Systems Part I-BasicsOperating Systems Part I-Basics
Operating Systems Part I-Basics
 
Operating Systems Part II-Process Scheduling, Synchronisation & Deadlock
Operating Systems Part II-Process Scheduling, Synchronisation & DeadlockOperating Systems Part II-Process Scheduling, Synchronisation & Deadlock
Operating Systems Part II-Process Scheduling, Synchronisation & Deadlock
 
Introduction to database-Transaction Concurrency and Recovery
Introduction to database-Transaction Concurrency and RecoveryIntroduction to database-Transaction Concurrency and Recovery
Introduction to database-Transaction Concurrency and Recovery
 
Introduction to database-Formal Query language and Relational calculus
Introduction to database-Formal Query language and Relational calculusIntroduction to database-Formal Query language and Relational calculus
Introduction to database-Formal Query language and Relational calculus
 
Introduction to database-Normalisation
Introduction to database-NormalisationIntroduction to database-Normalisation
Introduction to database-Normalisation
 
Introduction to database-ER Model
Introduction to database-ER ModelIntroduction to database-ER Model
Introduction to database-ER Model
 
Computer Networks Module III
Computer Networks Module IIIComputer Networks Module III
Computer Networks Module III
 
Computer Networks Module II
Computer Networks Module IIComputer Networks Module II
Computer Networks Module II
 
Computer Networks Module I
Computer Networks Module IComputer Networks Module I
Computer Networks Module I
 
Object Oriented Programming using C++ Part III
Object Oriented Programming using C++ Part IIIObject Oriented Programming using C++ Part III
Object Oriented Programming using C++ Part III
 
Object Oriented Programming using C++ Part I
Object Oriented Programming using C++ Part IObject Oriented Programming using C++ Part I
Object Oriented Programming using C++ Part I
 
Object Oriented Programming using C++ Part II
Object Oriented Programming using C++ Part IIObject Oriented Programming using C++ Part II
Object Oriented Programming using C++ Part II
 

Último

Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
Kamal Acharya
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptx
chumtiyababu
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Último (20)

Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
 
PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and properties
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
Moment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilMoment Distribution Method For Btech Civil
Moment Distribution Method For Btech Civil
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptx
 
Wadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptxWadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptx
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planes
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
 

Ns2: OTCL - PArt II

  • 1. An Introduction to Network Simulator Dr. Ajit K Nayak Dept of CSIT, ITER S‘O’A University, BBSR
  • 2.
  • 3. Part II • Introducing OTcl • Working with NS2
  • 4. Basics of OTcl - I • Class is used to register a class name. – Unlike C++, there is no class body where all members of the class are declared/defined. – i.e. once the class is registered, the member functions and data members can be declared anywhere in the script with the use of the class name and self variable. • instproc is used to define a member function. • init is the name of constructor. • self is equivalent to the ‘this’ keyword of C++. • instvar is used to declare a data member. • superclass is used to specify the parent class in case of inheritance. NS-2/AN/Intro/ 4
  • 5. Basics of OTcl - II • Object initialization: – set ctr [ new Counter ] • ctr is an object of class Counter • It calls the constructor to initialize the instance variables. • Method invocation: – $ctr increment • invokes the method increment of class Counter – puts [ $ctr getValue ] • invokes the method getValue of class Counter and prints the value returned from the member function NS-2/AN/Intro/ 5
  • 6. NS-2/AN/Intro/ 6 Example – Class-Object (I) # Create a class called "mom" and add a member function called "greet" Class Mom Mom instproc greet {} { $self instvar age puts “$age years old mom say: ntHow are you doing?” } # Create a child class of "mom" called "kid" and override the member function "greet" Class Kid -superclass Mom Kid instproc greet {} { $self instvar age puts “$age years old kid say: ntWhat’s up, dude?” }
  • 7. Example – Class-Object (II) NS-2/AN/Intro/ 7 # Create a mom and a kid object & set age for each set mom [new Mom] $mom set age 45 set kid [new Kid] $kid set age 15 # Calling member function "greet" of each object $mom greet $kid greet Output: 45 year old mom say: How are you doing? 15 year old kid say: what’s up dude?
  • 8. Task I • Execute the previous OTcl program. • Fill in the spaces provided to complete the OTcl program below, execute the program and note the output Class Real Real instproc init {x} { # constructor $self instvar value set value $x } Real instproc multiply { x } { ... FILL IN: multiply val and x then print ... } Real instproc divide {x} { $self instvar value ... FILL IN: divide val and x then print result... } NS-2/AN/Intro/ 8
  • 9. Task I contd. Class Integer -superclass Real Integer instproc divide {x} { ... FILL IN ... } set realA [new Real 12.3] set realB [new Real 0.5] $realA multiply $realB $realA divide $realB set integerA [new Integer 12] set integerB [new Integer 5] $integerA multiply $integerB $integerA divide $integerB NS-2/AN/Intro/ 9
  • 10. NS2 Programming Structure • Create the event scheduler • Turn on tracing • Create network topology • Create transport connections • Generate traffic – Traffic source – Traffic sink – Connection between source & sink • Run the simulation NS-2/AN/Intro/ 10
  • 11. Creating the event scheduler • Create event scheduler – set ns [new Simulator] • Schedule an event – syntax: $ns at <time> <event> – $ns at 5.0 “finish” • Start Scheduler – $ns run NS-2/AN/Intro/ 11 proc finish {} { global ns nf close $nf exec nam out.nam & exit 0 }
  • 12. Tracing (outputs) • Packet/Event Trace – $ns trace-all[open out.tr w] • NAM Trace (Network Animator) – set nf [open out.nam w] – $ns namtrace-all $nf NS-2/AN/Intro/ 12
  • 13. Creating topology (Two nodes connected by a link) • Creating nodes – set n0 [$ns node] – set n1 [$ns node] • Creating link between nodes – syntax: $ns <link_type> <node1> <node2> <bandwidth> <delay> <queueType> – $ns duplexlink $n0 $n1 1Mb 10ms DropTail NS-2/AN/Intro/ 13
  • 14. Program for two node network 1. Create a file named twoNode.tcl and add the following contents in it. set ns [new Simulator] set nf [open twoNode.nam w] $ns namtrace-all $nf set n0 [$ns node] set n1 [$ns node] $ns duplex-link $n0 $n2 100Mb 5ms DropTail $ns run NS-2/AN/Intro/ 14 2. Save and exit from the editor, Now execute the program with following command in command line ns twoNode.tcl 3. This will generate twoNode.nam. To see the visualization, issue the following command in command line nam twoNode.nam &
  • 15. Color • Nodes Colour: – $node color blue ;#creates a blue color node – (Other colors are red, green, chocolate etc.) • Node Shape: – $node shape box ;#creates a square shaped node – (Other shapes are circle, box, hexagon ) • $n0 add-mark m0 blue box ;# creates a concentric circle over node n0 • $ns at 2.0 $n0 delete-mark m0" ;# deletes the mark at simulation time 2 sec. • Node Label: – $n0 label Router ;# labels n0 as a Router NS-2/AN/Intro/ 15 • Link Colour: • $ns duplex-link-op $n0 $n1 color green" link from n0 to n1 becomes green • Link Label: • $ns duplex-link-op $n0 $n1 label point-to-point“ link is labelled as point-to- point • Link Orientation: • $ns duplex-link-op $n(0) $n(1) orient right the link is drawn horizontally from n0 to n1 • $ns duplex-link-op $n(1) $n(2) orient left • ( up, down, right-up, left-down, 60deg)
  • 16. Task II • Execute the twoNode.tcl • Create a ring network of 3 nodes with adjacent nodes of different color and red color links between them. NS-2/AN/Intro/ 16
  • 17. Sending data (UDP) • Create UDP source agent (transport connection) – set udp [new Agent/UDP] – $ns attach-agent $n0 $udp • Create UDP sink agent – set null [new Agent/Null] – $ns attach-agent $n1 $null • Connect two transport (source-sink) agents – $ns connect $udp $null NS-2/AN/Intro/ 17
  • 18. Sending data contd. • Create CBR traffic source on the top of UDP agent (Application) – set cbr [new Application/Traffic/CBR] – $cbr attach-agent $udp • Start and stop of data transmission – $ns at 0.5 “$cbr start” – $ns at 4.5 “$cbr stop” NS-2/AN/Intro/ 18
  • 19. Complete Program set ns [new Simulator] set n0 [$ns node] set n1 [$ns node] $ns trace-all [open twoNode.tr w] set nf [open twoNode.nam w] $ns namtrace-all $nf $ns duplex-link $n0 $n1 100Kb 10ms DropTail set udp [new Agent/UDP] $ns attach-agent $n0 $udp set null [new Agent/Null] $ns attach-agent $n1 $null $ns connect $udp $null NS-2/AN/Intro/ 19 set cbr [new Application/Traffic/CBR] $cbr attach-agent $udp $ns at 0.1 “$cbr start” $ns at 2.35 “$cbr stop” $ns at 2.4 “finish” proc finish {} { global nf ; close $nf exec nam twoNode.nam & exit 0 } $ns run
  • 20. Sending data (TCP) • Create TCP agent and attach it to the node – set tcp0 [new Agent/TCP] – $ns attach-agent $n0 $tcp0 • Create a Null Agent and attach it to the node – set null0 [new Agent/TCPSink] – $ns attach-agent $n1 $null0 • Connect the agents – $ns connect $tcp0 $null0 • Trafic on the top of TCP (FTP or Telnet) – set ftp [new Application/FTP] – $ftp attach-agent $tcp0 OR – set telnet [new Application/Telnet] – $telnet attach-agent $tcp0
  • 21. Task III 1)Execute modified twoNode.tcl and observe the animation output. 2) Excute the same usng TCP and ftp .
  • 22.
  • 23. Output? (twoNode.tr) + 1 0 1 cbr 500 ------- 0 0.0 1.0 0 0 - 1 0 1 cbr 500 ------- 0 0.0 1.0 0 0 + 1.005 0 1 cbr 500 ------- 0 0.0 1.0 1 1 - 1.005 0 1 cbr 500 ------- 0 0.0 1.0 1 1 + 1.01 0 1 cbr 500 ------- 0 0.0 1.0 2 2 - 1.01 0 1 cbr 500 ------- 0 0.0 1.0 2 2 r 1.014 0 1 cbr 500 ------- 0 0.0 1.0 0 0 + 1.015 0 1 cbr 500 ------- 0 0.0 1.0 3 3 - 1.015 0 1 cbr 500 ------- 0 0.0 1.0 3 3 r 1.019 0 1 cbr 500 ------- 0 0.0 1.0 1 1 + 1.02 0 1 cbr 500 ------- 0 0.0 1.0 4 4 - 1.02 0 1 cbr 500 ------- 0 0.0 1.0 4 4 r 1.024 0 1 cbr 500 ------- 0 0.0 1.0 2 2
  • 24. Explaining Output (I) • Column 1: events – +: enqueue – -: dequeue – r: receive – d: drop • Column 2: – Time of event • Column 3 & 4: – Trace between which two nodes?
  • 25. Explaining Output (II) • Column 5,6: – Packet type, Packet size • Column 7-14: – Flags used for ECN (not used here) • Column 15: – IP flow identifier (IPv6) • Column 16,17: – Source & Destination address • Column 18,19: – Sequence number, unique packet identifier
  • 26. Suggested Readings • OTcl Tutorials – http://www.tcl.tk/man/tcl8.5/tutorial/tcltutorial.h tml • NS-2 Tutorials – http://www.isi.edu/nsnam/ns/tutorial – http://nile.wpi.edu/NS/ – NS Manual NS-2/AN/Intro/ 26
  • 27. Thank You End of Part II