Skip to main content

PyTorch Code for Simple Neural Networks for MNIST Dataset

HTTP and FTP Simulation in NS2

HTTP and FTP Simulation in NS2


  • Network Simulator-2
  • Operating System – LINUX (UBUNTU)



  • 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

Computer Network HTTP


  • 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:

Computer Network 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.

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


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 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


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

NS2 Output


Popular posts from this blog

Installing ns3 in Ubuntu 22.04 | Complete Instructions

In this post, we are going to see how to install ns-3.36.1 in Ubuntu 22.04. You can follow the video for complete details Tools used in this simulation: NS3 version ns-3.36.1  OS Used: Ubuntu 22.04 LTS Installation of NS3 (ns-3.36.1) There are some changes in the ns3 installation procedure and the dependencies. So open a terminal and issue the following commands Step 1:  Prerequisites $ sudo apt update In the following packages, all the required dependencies are taken care and you can install all these packages for the complete use of ns3. $ sudo apt install g++ python3 python3-dev pkg-config sqlite3 cmake python3-setuptools git qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools gir1.2-goocanvas-2.0 python3-gi python3-gi-cairo python3-pygraphviz gir1.2-gtk-3.0 ipython3 openmpi-bin openmpi-common openmpi-doc libopenmpi-dev autoconf cvs bzr unrar gsl-bin libgsl-dev libgslcblas0 wireshark tcpdump sqlite sqlite3 libsqlite3-dev  libxml2 libxml2-dev libc6-dev libc6-dev-i386 libclang-dev llvm-

Installation of NS2 (ns-2.35) in Ubuntu 20.04

Installation of NS2 (ns-2.35) in Ubuntu 20.04 LTS Step 1: Install the basic libraries like      $] sudo apt install build-essential autoconf automake libxmu-dev Step 2: install gcc-4.8 and g++-4.8 open the file using sudo mode $] sudo nano /etc/apt/sources.list Include the following line deb bionic main universe $] sudo apt update $] sudo apt install gcc-4.8 g++-4.8 Step 3:  Unzip the ns2 packages to home folder $] tar zxvf ns-allinone-2.35.tar.gz $] cd ns-allinone-2.35/ns-2.35 Modify the following make files. ~ns-2.35/ Change @CC@ to gcc-4.8 change @CXX@ to g++-4.8 ~nam-1.15/ ~xgraph-12.2/ ~otcl-1.14/ Change in all places  @CC@ to gcc-4.8 @CPP@ or @CXX@ to g++-4.8 open the file: ~ns-2.35/linkstate/ls.h Change at the Line no 137  void eraseAll() { erase(baseMap::begin(), baseMap::end()); } to This void eraseAll() { this->erase(baseMap::begin(), baseMap::end()); } All changes made Step 4: Open a new termi

Installation of NS2 in Ubuntu 22.04 | NS2 Tutorial 2

NS-2.35 installation in Ubuntu 22.04 This post shows how to install ns-2.35 in Ubuntu 22.04 Operating System Since ns-2.35 is too old, it needs the following packages gcc-4.8 g++-4.8 gawk and some more libraries Follow the video for more instructions So, here are the steps to install this software: To download and extract the ns2 software Download the software from the following link Extract it to home folder and in my case its /home/pradeepkumar (I recommend to install it under your home folder) $ tar zxvf ns-allinone-2.35.tar.gz or Right click over the file and click extract here and select the home folder. $ sudo apt update $ sudo apt install build-essential autoconf automake libxmu-dev gawk To install gcc-4.8 and g++-4.8 $ sudo gedit /etc/apt/sources.list make an entry in the above file deb bionic main universe $ sudo apt update Since, it&#