Archive for the ‘Computer Networks’ Category

Pre-Requisite: Installation of NS2 on Debian

Aim: To Simulate following Topology.

Topology Description

  1. Network consists of 4 nodes (n0, n1, n2, n3).
  2. The duplex links between n0 and n2, and n1 and n2 have 2 Mbps of bandwidth and 10 ms of delay.
  3. The duplex link between n2 and n3 has 1.7 Mbps of bandwidth and 20 ms of delay.
  4. Each node uses a DropTail queue, of which the maximum size is 10.
  5. A “tcp” agent is attached to n0, and a connection is established to a tcp “sink” agent attached to n3.
  6. As default, the maximum size of a packet that a “tcp” agent can generate is 1KByte.
  7. A tcp “sink” agent generates and sends ACK packets to the sender (tcp agent) and frees the received packets.
  8. A “udp” agent that is attached to n1 is connected to a “null” agent attached to n3.
  9. A “null” agent just frees the packets received.
  10. A “ftp” and a “cbr” traffic generator are attached to “tcp” and “udp” agents respectively,
  11. The  “cbr” is configured to generate 1 KByte packets at the rate of 1 Mbps.
  12. The “cbr” is set to start at 0.1 sec and stop at 4.5 sec, and “ftp” is set to start at 1.0 sec and stop at 4.0 sec.


  1. Create a file called simple.tcl in ns2 directory which is in all-in-one package directory.
  2. Place the following code in simple.tcl file.
  3. Go to ns prompt
  4. type: ns simple.tcl


#Create a simulator object
set ns [new Simulator]

#Define different colors for data flows (for NAM)
$ns color 1 Blue
$ns color 2 Red

#Open the NAM trace file
set nf [open out.nam w]
$ns namtrace-all $nf

#Define a 'finish' procedure
proc finish {} {
 global ns nf
 $ns flush-trace
 #Close the NAM trace file
 close $nf
 #Execute NAM on the trace file
 exec nam out.nam &
 exit 0

#Create four nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]

#Create links between the nodes
$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns duplex-link $n2 $n3 1.7Mb 20ms DropTail

#Set Queue Size of link (n2-n3) to 10
$ns queue-limit $n2 $n3 10

#Give node position (for NAM)
$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n1 $n2 orient right-up
$ns duplex-link-op $n2 $n3 orient right

#Monitor the queue for link (n2-n3). (for NAM)
$ns duplex-link-op $n2 $n3 queuePos 0.5

#Setup a TCP connection
set tcp [new Agent/TCP]
$tcp set class_ 2
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $n3 $sink
$ns connect $tcp $sink
$tcp set fid_ 1

#Setup a FTP over TCP connection
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP

#Setup a UDP connection
set udp [new Agent/UDP]
$ns attach-agent $n1 $udp
set null [new Agent/Null]
$ns attach-agent $n3 $null
$ns connect $udp $null
$udp set fid_ 2

#Setup a CBR over UDP connection
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set type_ CBR
$cbr set packet_size_ 1000
$cbr set rate_ 1mb
$cbr set random_ false

#Schedule events for the CBR and FTP agents
$ns at 0.1 "$cbr start"
$ns at 1.0 "$ftp start"
$ns at 4.0 "$ftp stop"
$ns at 4.5 "$cbr stop"

#Detach tcp and sink agents (not really necessary)
$ns at 4.5 "$ns detach-agent $n0 $tcp ; $ns detach-agent $n3 $sink"

#Call the finish procedure after 5 seconds of simulation time
$ns at 5.0 "finish"

#Print CBR packet size and interval
puts "CBR packet size = [$cbr set packet_size_]"
puts "CBR interval = [$cbr set interval_]"

#Run the simulation
$ns run


Pre-Requisite: Install Debian GNU/Linux

STEP  1: Download Network Simulator Setup.

Download NS2 All In One Package from following link:


Official Website:


STEP 2: Place the file in your home directory and extract the tar file

$ tar -xzvf ns-allinone-2.31.tar.gz

Note: This tutorial was designed using 2.31 version.
Please don't forget to replace 2.31 to 2.34 in following commands

STEP 3: Go to folder where tar file is extracted.

$ cd ns-allinone-2.31

STEP 4: Insert Debian DVD for dependency components.

$ sudo apt-get install build-essential autoconf automake libxmu-dev
$ sudo apt-get install -f build-essential
libxt-dev libxt6 libsm-dev libsm6 libice-dev libice6 libxmu-dev

STEP 5: Install NS2 using following command.

Note: This process will take some time.

STEP 6: Set environment variables

$ gedit ~/.bashrc

Add the following lines to the end of it.

Dont forget to replace "/home/bharat with your directory path.

Example: /home/yourname/




STEP 7: Make changes

$ source ~/.bashrc

STEP 8: Check Installation Success

$ ns

If you type ns command on shell, then a "%" will appear on the screen.
That means NS2 is successfully installed.

STEP 9: Exit to Linux prompt


Type "exit" to quit the mode and back to "$"

STEP 10: Validation of NS2 Installation.

Go to network simulator directory inside the all in one
package and execute following command.

$ cd ns-2.31
$ ./validate

Note: Be patient till validation gets successful.

What is Packet Tracer?

Packet Tracer is a standalone, medium-fidelity, simulation-based learning environment for networking novices to design, configure, and troubleshoot computer networks at a CCNA-level of complexity. Packet Tracer supports student and instructor creation of simulations, visualizations, and animations of networking phenomena.

Like any simulation, Packet Tracer relies on a simplified model of networking devices and protocols. However, real computer networks remain the benchmark for understanding network behavior. Packet Tracer was created to help address the “digital divide” in networking education, where many students and teachers lack access to equipment, bandwidth, and interactive modes of learning networking.

Note: Let me assume you have some knowledge on routing.


(Click on image to enlarge)

Required Network


  1. Start Packet Tracer
  2. Click on Routers in left bottom and drag 3 router model called 2621M onto the workspace
  3. Above model have 2 fast Ethernet ports.
  4. We have to add WIC-2T module to the router
  5. Switch off the router and drag the module in given 2 places in router back panel.
  6. WIC-2t Module:

The 2-port asynchronous/synchronous serial network module provides flexible multi-protocol support, with each port individually configurable in synchronous or asynchronous mode, offering mixed-media dial support in a single chassis. Applications for Asynchronous/Synchronous support include: Low speed WAN aggregation (up to 128 Kbps), dial-up modem support, Async or Sync connections to management ports of other equipment, and transport of legacy protocols such as Bi-sync and SDLC.

  1. Connect all routers using connection medium. Select automatic medium so that serial ports can be used.
  2. Assume center router be ISP side router and remaining 2 as Mumbai side router and the other as Delhi side router.
  3. Drag the switch of type 2960-24TT as shown.
  4. Drag the generic hosts and connect all of them.
  5. Now the topology is created like shown.
  6. Red dots indicate down-state and green dots indicate up-state.

Part 1: Designing the Network

Part 2: Configuring the Routers

What is a port?

In computer networking, a port is an application-specific or process-specific software construct serving as a communications endpoint, providing a multiplexing  service. It is used by Transmission Control Protocol (TCP) and User Datagram Protocol (UDP).

A port number is a 16-bit unsigned integer, thus ranging from 0 to 65535.

A specific port is identified by its number, commonly known as the port number, the IP address with which it is associated, and the protocol used for communication.

Why do we need ports?

To support multitasking. Ports enable multiple programs to share a single physical network connection simultaneously, as opposed to having only one program using the connection for a long period of time.

In multitasking, multiple programs need to contact other programs on other computers over the network all at the same time, using ports and sockets.

Where do we specify port number so that packet knows which port to enter?

Transport Layer protocols, such as TCP, UDP specify a source and destination port number in their packet headers.

What is Binding?

A process associates its network input or output channels each with a particular port number, a process known as binding, to send and receive data. The operating system’s networking software has the task of transmitting outgoing data from all application ports onto the network, and forwarding arriving network packets to a process by matching the packets IP address and port numbers.

What is Listening?

Applications implementing common services often use specifically reserved, well-known port numbers for receiving service requests from client hosts. This process is known as listening and involves the receipt of a request on the well-known port and reestablishing one-to-one server-client communications on another private port, so that other clients may also contact the well-known service port.

The well-known ports are defined by convention overseen by the Internet Assigned Numbers Authority (IANA), cf. list of TCP and UDP port numbers.

What are Sockets?

Processes create associations with transport protocol ports by means of sockets. A socket is the software structure used as the transport end-point. It is created by the operating system for the process and bound to a socket address which consists of a combination of a port number and an IP address.

What is Port scanning?

Because different services commonly listen on different port numbers, the practice of attempting to connect to a range of ports in sequence on a single computer is commonly known as port scanning.

This is usually associated either with malicious cracking attempts or with network administrators looking for possible vulnerabilities to help prevent such attacks. Port connection attempts are frequently monitored and logged by computers. The technique of port knocking uses a series of port connections (knocks) from a client computer to enable a server connection.

An example for the use of ports is the Internet serving Web content through port 80, using available web servers like IIS or Apache.

Port numbers can occasionally be seen in the Uniform Resource Locator (URL) of a website or other services.

By default, HTTP uses port 80 and HTTPS uses port 443,

but a URL like http://www.localhost:8080/ specifies that the web site is served by the HTTP server on port 8080.

The port numbers are divided into three ranges: the well-known ports, the registered ports, and the dynamic or private ports. The well-known ports are those from 0 through 1023. Examples include:

21: FTP

23: Telnet

25: SMTP

53: Domain Name System

80: World Wide Web HTTP

443: HTTP over Transport Layer Security/Secure Sockets Layer

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 50 other followers

What I am Upto Now

Follow Me On Twitter

Blog Stats

  • 78,395 hits

Live Traffic

My Paintings

%d bloggers like this: