TCL File Explanation

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

EXPLANATION OF TCL FILE CODE

set ns [new Simulator] -> here set is a command ns is a pointer variable new is command and
Simulator is inbuilt class inside ns

How to deal to deal with output files


Types of file
1) Trace file -> filename.tr
2) Nam file -> filename.nam

To create trace file


set tracefile1 [open out.tr w]-> w is write mode
$ns trace-all $tracefile1 -> trace-all traces all the events in the flow

To create nam file


set namfile1 [open out.nam w]-> w is write mode
$ns namtrace-all $namfile1

To terminate define finish procedure


1. proc finish{} {
a. global ns tracefile1 namfile1 -> global: these two can be use anywhere
b. $ns flush-race
c. close $tracefile
d. close $namfile
e. exe nam out.nam &
f. exit 0-> 0 indicates a clean exit
}

Start the simulator and End the program


$ns run -> Starts the simulation

$ns at 125.0 "finish" -> after 125 second i am ending it

How to create an inter simulator and when to start and when to stop
1. set n1[new Node] -> Node is the object or class which is available in the NS2
2. set n2[new Node]

Nodes are created now how to connect them


$ns duplex-line $n1 $n2 10Mb 10ms Drop Tail -> connecting n1 with n2 through duplex link
with bandwidth 10Mb a delay in transmission is 10ms Drop tail is used with conjunction
window if the buffer capacity of output window exceeded then the last packet arrived is lost and
here we use drop tail

Set the capacity of the Buffer


#Set queue size of the link
$ns queue-limit $n1 $n2 20 -> maximum limit of the queue is 20 it can hold maximum 20
packets

AGENTS
Link is established now on what kind of service they should work on
For connection full oriented we use TCP
For connection less service we will be using UDP
1) TCP-FTP
2) UDP-CBR
SETTING A TCP CONNECTION

1. set tcp[new Agent/TCP] -> setting a tcp pointer variable to the tcp agent
2. $ns attach-agent $n1 $tcp -> attach tcp agent to n1 n1 becomes the tcp agent (sending tcp
agent)
3. set sink [new Agent/TCPSink] destination can be initialized by using the TCPSink
4. $ns attach-agent $n2 $sink
5. $ns connect $tcp $sink -> we will connect both by using this connect keywork
6. $tcp set fid_1 -> fid is flowid it is used to differentiate between sending and receiving
data (n data flows which are happening at the same time)
7. $tcp set packetSize_552 -> if we don't send the packet size then we it will be by default
1k (1000)
FTP
File transfer protocol is a standard mechanism provided by internet for transferring files from
one host to another
FTTP use the service of TCP
Port 21 is use for control connection and post 20 is use for data transfer

1. Set ftp [new Application/FTP]


2. $ftp attach-agent $tcp
Connectionless Service/ UDP
1. #set udp [new Agent/UDP]
2. $ns attach-agent $n1 $udp -> sender node
3. $set null [new Agent/Null]
4. $ns attach-agent $n2 $null -> receiver node
5. $ns connect $udp $null
6. $udp set fid_2

Constant Bit Rate (CBR)

 CBR is a trem used in telecommunication relating to quality of service


 CBR encoding means that the rate at which output data should be consumed is constant
 CBR is useful for streaming multimedia content

# set up cbr over udp


1. Set cbr [new Application/Traffic/CBR]
2. $cbr attach-agent $udp
3. $cbr set packetSize_1000
4. $cbr set rate_0.01Mb
5. $cbr set random_false -> it is used to control the noise over the data if set random then it
will allow some noise and block some noise and if it is false then it will not block the
noise
Scheduling The Events
Event are handled by using the $ns at command
1. $ns at 0.1 ‘cbr start’ -> at point 0.1 sec start cbr
2. $ns at 1.0 ‘ftp start’
3. $ns at 124.0 “ftp stop”
4. $ns at 124.5 “cbr stop”
Network Animator( NAM )
#Giving positions to the nodes in NAM
$ns duplex-link-op $n0 $n2 orient-right-down
$ns duplex-link-op $n1 $n2 orient-right-up

You might also like