7/24/2019 Network Simulator 2 Report File
1/13
M.S.RAMAIAH INSTITUTE OF TECHNOLOGY
DEPARTMENT OF INFORMATION SCIENCE AND ENGINEERING
(Autonomous Institute Affiliated to TU!
I"YA SOU"HA# M. S. R Na$a%# M. S. R. I. T. &ost# 'an$alo%e )*++),
CERTIFICATE
This is to certify that the following stuents! who were wor"ing uner #y guiance! ha$e
co#%lete their wor" as %er #y satisfaction with the to%ic Network Simulation 2-
OTcl script in wired network&
Anu%oo- R MS/IS+0
A1inas2 R MS/IS+3*
44444444444444444444
Signature of the GuieM%. Mani Se52a% S RAssistant Professor!
De%t& of ISE! MSRIT!'angalore()*
7/24/2019 Network Simulator 2 Report File
2/13
7/24/2019 Network Simulator 2 Report File
3/13
Network Simulator 2 - OTcl script in wired network
Introduction
NS (network simulator) is a discrete eventnetwork simulators, specifcally ns-
1, ns-2and ns-3. All o them are discrete-event network simulator, primarily used
in research and teaching. ns- is ree sotware, pu!licly availa!le under the "N#
"$%v& license or research, development, and use. 'he goal o the ns- proect is to
create an open simulation environment or networking research that will !e
preerred inside the research community.
t should !e aligned with the simulation needs o modern networking
research.
t should encourage community contri!ution, peer review, and validation o
the sotware.
Since the process o creation o a network simulator that contains a su*cient
num!er o high-+uality validated, tested and actively maintained models re+uires a
lot o work, ns- proect spreads this workload over a large community o users and
developers. 'his is the popular simulator in scientifc environment and other popular
network simulators are
"lomosim #%A, /#0 $arse, /o!ile Simulation mostly
1$N2' commercial sotware, graphical interace, not ree0
Two Languages: C++, OTcl
1'cl short or /' 1!ect 'cl, an e3tension to 'cl4'k or o!ect-oriented
programming.
5 #sed to !uild the network structure and topology which is ust the surace o your
simulatoion0
5 2asily to confgure your network parameters0
http://en.wikipedia.org/wiki/Discrete_event_simulationhttp://en.wikipedia.org/wiki/Network_simulationhttp://en.wikipedia.org/wiki/Free_softwarehttp://en.wikipedia.org/wiki/Discrete_event_simulationhttp://en.wikipedia.org/wiki/Network_simulationhttp://en.wikipedia.org/wiki/Free_software7/24/2019 Network Simulator 2 Report File
4/13
5 Not enough or research schemes and protocol architecture adaption.
C++: ost im!ortant and kernel !art o" t#e NS2
5 'o implement the kernel o the architecture o the protocol designs0
5 6rom the packet 7ow view, the processes run on a single node0
5 'o change or 8comment out9 the e3isting protocols running in NS&0
5 :etails o your research scheme.
$rotocols%odels su!!orted &' NS2
5 ;ired Networking
7/24/2019 Network Simulator 2 Report File
5/13
) sim!le NS simulation scri!t: and e*!lains w#at eac# line does:
Breate a simulator o!ect
set ns Cnew SimulatorD
B:efne di?erent colors or data 7ows (or NA/)
Ens color F @lue
Ens color &
7/24/2019 Network Simulator 2 Report File
6/13
B:efne a GfnishG procedure
proc fnish HI H
glo!al ns n
Ens 7ush-trace
Blose the NA/ trace fle
close En
B23ecute NA/ on the trace fle
e3ec nam out.nam J
e3it K
I
Breate our nodes
set nK CEns nodeD
set nF CEns nodeD
set n& CEns nodeD
set n CEns nodeD
Breate links !etween the nodes
Ens duple3-link EnK En& &/! FKms :rop'ail
Ens duple3-link EnF En& &/! FKms :rop'ail
Ens duple3-link En& En F.L/! &Kms :rop'ail
BSet >ueue SiMe o link (n&-n) to FK
Ens +ueue-limit En& En FK
B"ive node position (or NA/)
Ens duple3-link-op EnK En& orient right-down
Ens duple3-link-op EnF En& orient right-up
Ens duple3-link-op En& En orient right
B/onitor the +ueue or link (n&-n). (or NA/)
7/24/2019 Network Simulator 2 Report File
7/13
Ens duple3-link-op En& En +ueue$os K.
BSetup a '$ connection
set tcp Cnew Agent4'$D
Etcp set classO &
Ens attach-agent EnK Etcp
set sink Cnew Agent4'$SinkD
Ens attach-agent En Esink
Ens connect Etcp Esink
Etcp set fdO F
BSetup a 6'$ over '$ connection
set tp Cnew Application46'$D
Etp attach-agent Etcp
Etp set typeO 6'$
BSetup a #:$ connection
set udp Cnew Agent4#:$D
Ens attach-agent EnF Eudp
set null Cnew Agent4NullD
Ens attach-agent En Enull
Ens connect Eudp Enull
Eudp set fdO &
BSetup a @< over #:$ connection
set c!r Cnew Application4'ra*c4@
7/24/2019 Network Simulator 2 Report File
8/13
Ec!r set randomO alse
BSchedule events or the @< and 6'$ agents
Ens at K.F PEc!r startP
Ens at F.K PEtp startP
Ens at Q.K PEtp stopP
Ens at Q. PEc!r stopP
B:etach tcp and sink agents (not really necessary)
Ens at Q. PEns detach-agent EnK Etcp 0 Ens detach-agent En EsinkP
Ball the fnish procedure ater seconds o simulation time
Ens at .K PfnishP
B$rint @< packet siMe and interval
puts P@< packet siMe R CEc!r set packetOsiMeODP
puts P@< interval R CEc!r set intervalODP
B
7/24/2019 Network Simulator 2 Report File
9/13
7/24/2019 Network Simulator 2 Report File
10/13
7/24/2019 Network Simulator 2 Report File
11/13
7/24/2019 Network Simulator 2 Report File
12/13
In general, an NS scri!t starts wit# making a Simulator o&ect instance
set nsCnew SimulatorD generates an NS simulator o!ect instance, and
assigns it to varia!le ns.
nitialiMe the packet ormat (ignore this or now)
reate a scheduler (deault is calendar scheduler)
Select the deault address ormat (ignore this or now)
'he PSimulatorP o!ect has mem!er unctions that do the ollowing
reate compound o!ects such as nodes and links (descri!ed later) onnect network component o!ects created (e3. attach-agent)
Set network component parameters (mostly or compound o!ects)
reate connections !etween agents (e3. make connection !etween a PtcpPand PsinkP)
Speciy NA/ display options
2tc.
$nscolor fd color is to set color o the packets or a 7ow specifed !y the7ow id (fd). 'his mem!er unction o PSimulatorP o!ect is or the NA/display, and has no e?ect on the actual simulation.
$nsnamtrace-all fle-descriptor 'his mem!er unction tells the simulator torecord simulation traces in NA/ input ormat. t also gives the fle name thatthe trace will !e written to later !y the command $ns7ush-trace. Similarly,the mem!er unction trace-allis or recording the simulation trace in ageneral ormat.
proc fnishHI is called ater this simulation is over !y the command $nsat.K PfnishP. n this unction, post-simulation processes are specifed.
set n0C$nsnodeD 'he mem!er unction nodecreates a node.
$nsduple3-link node1 node2 bandwidth delay queue-type creates two
simple3 links o specifed !andwidth and delay, and connects the twospecifed nodes.
$ns+ueue-limit node1 node2 number 'his line sets the +ueue limit o thetwo simple3 links that connect nodeF and node& to the num!er specifed.
$nsduple3-link-op node1 node2 ... 'he ne3t couple o lines are used or theNA/ display. 'o see the e?ects o these lines, users can comment these linesout and try the simulation.
7/24/2019 Network Simulator 2 Report File
13/13
Now t#at t#e &asic network setu! is done, t#e ne*t t#ing to do is tosetu! trac agents suc# as TC$ and ./$, trac sources suc# as 0T$and C
set tcpCnewAgent/T!D 'his line shows how to create a '$ agent. @ut ingeneral, users can create any agent or tra*c sources in this way. Agents and
tra*c sources are in act !asic o!ects (not compound o!ects), mostlyimplemented in and linked to 1'cl. 'hereore, there are no specifcSimulator o!ect mem!er unctions that create these o!ect instances. 'ocreate agents or tra*c sources, a user should know the class names theseo!ects (Agent4'$, Agnet4'$Sink, Application46'$ and so on).
$nsattach-agent node agent 'he attach-agentmem!er unction attaches anagent o!ect created to a node o!ect. Actually, what this unction does is callthe attachmem!er unction o specifed node, which attaches the givenagent to itsel. 'hereore, a user can do the same thing !y, or e3ample, EnKattach Etcp
$nsconnect agent1 agent2 Ater two agents that will communicate witheach other are created, the ne3t thing is to esta!lish a logical networkconnection !etween them. 'his line esta!lishes a network connection !ysetting the destination address to each othersG network and port address pair.
Assuming that all the network confguration is done, the ne3t thing to do is write asimulation scenario (i.e. simulation scheduling). 'he Simulator o!ect has manyscheduling mem!er unctions. =owever, the one that is mostly used is the ollowing
$nsat time "string" 'his mem!er unction o a Simulator o!ect makes thescheduler (schedulerO is the varia!le that points the scheduler o!ect created
!y Cnew SchedulerD command at the !eginning o the script) to schedule thee3ecution o the specifed string at given simulation time. 6ore3ample, $nsat 0.1 "$cbr start"will make the scheduler call a startmem!erunction o the @< tra*c source o!ect, which starts the @< to transmitdata.
Ater all network confguration, scheduling and post-simulation procedurespecifcations are done, the only thing let is to run the simulation. 'his isdone !y $nsrun.
THANK YOU.