NS2 Program For TCP
NS2 Program For TCP
Ns2:
- An open source event discrete network simulator is known as Ns2.
- Ns2 is developed in C++ and OTcl languages.
- OTcl script is used to initiate the event scheduler
- C++ to reduce packet and event processing time.
- NS-2 works under Linux, Mac, and windows
Steps NS2 Program For TCP:
- Define the scenario to simulate:
- Create the simulator object
- { Turn on tracing }
- Setup the network nodes {and links }
- Setup the routing mechanism
- Create transport connections
- Setup user applications
- Schedule data transmission
- Stop the simulation
- Execute the OTcl script in a Linux shell: ns example.tcl
- Extract the results from the trace files: awk, xgraph, nam, matlab, etc . .
Creation of TCl script:
- To schedule an event
- To terminate a Tcl scenario, we need to call the Exit command
- A finish procedure to dump the traces and to close the files
- Creation of nodes and links
- Next step is to create transport agents
NS2 Program For TCP:
- TCP/IP communications can appear to be daunting at first.
- It is actually a very simple communication tool.
- It defines the details of how data is sent and received through network adapters or hubs.
- Transmission Control Protocol (TCP) makes sure all packets arrive safely
- It retransmitting them if necessary
TCP Retransmission:
It happens in two cases:
- ACK not received
- Duplicate ACK received
Code for FTP over TCP connection:
#Setup a FTP over TCP connection
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP
$ns at 1.0 “$ftp start”
$ns at 124.0 “$ftp stop”
# next procedure gets two arguments: the name of the
# tcp source node, will be called here “tcp”,
# and the name of output file.
proc plotWindow {tcpSource file} {
global ns
set time 0.1
set now [$ns now]
set cwnd [$tcpSource set cwnd_]
set wnd [$tcpSource set window_]
puts $file “$now $cwnd”
$ns at [expr $now+$time] “plotWindow $tcpSource $file” }
$ns at 0.1 “plotWindow $tcp $winfile”
$ns at 125.0 “finish”
$ns run
NS2 Program For TCP