HTTP and FTP Simulation in NS2
HARDWARE / SOFTWARE REQUIRED:
- Network Simulator-2
- Operating System – LINUX (UBUNTU)
THEORY:
HTTP:
- HTTP stands for Hypertext Transfer Protocol.
- It is a protocol used to access the data on the World Wide Web (www).
- The HTTP protocol can be used to transfer the data in the form of plain text, hypertext, audio, video, and so on.
- This protocol is known as HyperText Transfer Protocol because of its efficiency which allows us to use it in a hypertext environment where there are rapid jumps from one document to another document.
- HTTP is similar to FTP as it also transfers files from one host to another host. However, HTTP is simpler than FTP as HTTP uses only one connection, i.e., no control connection to transfer the files.
- HTTP is used to carry the data in the form of a MIME-like format.
Features of HTTP:
- Connectionless protocol: HTTP is a connectionless protocol. HTTP client initiates a request and waits for a response from the server. When the server receives the request, the server processes the request and sends back the response to the HTTP client after which the client disconnects the connection. The connection between client and server exists only during the current request and response time only.
- Media independent: HTTP protocol is media independent as data can be sent as long as both the client and server know how to handle the data content. It is required for both the client and server to specify the content type in the MIME-type header.
- Stateless: HTTP is a stateless protocol as both the client and server know each other only during the current request. Due to the nature of the protocol, both the client and server do not retain the information between various requests of the web pages.
HTTP Transactions
FTP
- FTP stands for File transfer protocol.
- FTP is a standard internet protocol provided by TCP/IP used for transmitting files from one host to another.
- It is mainly used for transferring web page files from their creator to the computer that acts as a server for other computers on the internet.
- It is also used for downloading files to computers from other servers.
Objectives of FTP
- It provides the sharing of files.
- It is used to encourage the use of remote computers.
- It transfers the data more reliably and efficiently.
Although transferring files from one system to another is very simple and straightforward, sometimes it can cause problems. For example, two systems may have different file conventions. Two systems may have different ways of representing text and data. Two systems may have different directory structures. FTP protocol overcomes these problems by establishing two connections between hosts. One connection is used for data transfer, and another connection is used for the control connection.
Mechanism of FTP
The above figure shows the basic model of the FTP. The FTP client has three components: the user interface, the control process, and the data transfer process. The server has two components: the server control process and the server data transfer process.
There are two types of connections in FTP:
Control Connection: The control connection uses very simple rules for communication. Through control connection, we can transfer a line of command or line of response at a time. The control connection is made between the control processes. The control connection remains connected during the entire interactive FTP session.
Data Connection: The Data Connection uses very complex rules as data types may vary. The data connection is made between data transfer processes. The data connection opens when a command comes for transferring the files and closes when the file is transferred.
FTP Clients
- FTP client is a program that implements a file transfer protocol that allows you to transfer files between two hosts on the internet.
- It allows a user to connect to a remote host and upload or download the files.
- It has a set of commands that we can use to connect to a host, transfer the files between you and your host, and close the connection.
- The FTP program is also available as a built-in component in a Web browser. This GUI-based FTP client makes the file transfer very easy and also does not require remembering the FTP commands.
ALGORITHM:
1. Create a simulator object
2. Open a nam trace file and define the finish procedure then close the trace file, and execute nam
on the trace file.
3. Create two nodes that form a network numbered from 0 to 1
4. Create duplex links between the nodes n(0) to n(1)
5. Setup TCP Connection between n(0) and n(1)
6. Apply FTP Traffic over TCP.
7. Schedule events and run the program
PROGRAM
This script is created by NSG2 beta1
#===================================
# Simulation parameters setup
#===================================
setval(stop) 10.5 ;# time of simulation end
#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]
#Open the NS trace file
set tracefile [open httpex.tr w]
$ns trace-all $tracefile
#Open the NAM trace file
setnamfile [open httpex.nam w]
$ns namtrace-all $namfile
#===================================
# Nodes Definition
#===================================
#Create 6 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]
#===================================
# Links Definition
#===================================
#Createlinks between nodes
$ns duplex-link $n0 $n2 100.0Mb 10ms SFQ
$ns queue-limit $n0 $n2 50
$ns duplex-link $n3 $n2 100.0Mb 10ms SFQ
$ns queue-limit $n3 $n2 50
$ns duplex-link $n1 $n2 100.0Mb 10ms SFQ
$ns queue-limit $n1 $n2 50
$ns duplex-link $n3 $n4 100.0Mb 10ms SFQ
$ns queue-limit $n3 $n4 50
$ns duplex-link $n3 $n5 100.0Mb 10ms SFQ
$ns queue-limit $n3 $n5 50
#Give node position (for NAM)
$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n3 $n2 orient left
$ns duplex-link-op $n1 $n2 orient right-up
$ns duplex-link-op $n3 $n4 orient right-up
$ns duplex-link-op $n3 $n5 orient right-down
#===================================
# Agents Definition
#===================================
#Setup a TCP connection
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set sink3 [new Agent/TCPSink]
$ns attach-agent $n5 $sink3
$ns connect $tcp0 $sink3
$tcp0 set packetSize_ 1500
#Setup a TCP connection
set tcp1 [new Agent/TCP]
$ns attach-agent $n4 $tcp1
set sink2 [new Agent/TCPSink]
$ns attach-agent $n1 $sink2
$ns connect $tcp1 $sink2
$tcp1 set packetSize_ 1500
#Setup a UDP connection
set udp4 [new Agent/UDP]
$ns attach-agent $n2 $udp4
set null5 [new Agent/Null]
$ns attach-agent $n5 $null5
$ns connect $udp4 $null5
$udp4 set packetSize_ 48
#===================================
# Applications Definition
#===================================
#Setup a FTP Application over TCP connection
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ns at 1.0 "$ftp0 start"
$ns at 10.0 "$ftp0 stop"
#Setup a FTP Application over TCP connection
set ftp1 [new Application/FTP]
$ftp1 attach-agent $tcp1
$ns at 1.0 "$ftp1 start"
$ns at 10.0 "$ftp1 stop"
#Setup a CBR Application over UDP connection
set cbr2 [new Application/Traffic/CBR]
$cbr2 attach-agent $udp4
$cbr2 set packetSize_ 48
$cbr2 set interval_ 50ms
$cbr2 set random_ null
$ns at 1.0 "$cbr2 start"
$ns at 10.0 "$cbr2 stop"
#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefilenamfile
$ns flush-trace
close $tracefile
close $namfile
execnamhttp.nam&
exit 0
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run
NS2 Simulation |
Comments
Post a Comment