BCA / B.Tech 12 min read

Sending Traffics Through NS2 Links

Sending Traffics NS2 Links in Hindi 


  • The process of sending data between nodes in a wired network in NS2 is done in a systematic way. It includes creating nodes, establishing links between them, adding traffic agents, and generating traffic. 
  • After setting up and running the simulation, you can evaluate the network's performance by analyzing the traffic. 
  • This process is extremely important for network researchers and students, as it provides an effective way to understand networking protocols and their functionality.
  • Using NS2 (Network Simulator 2) to send data between nodes in a wired network is an important part of the simulation. This process simulates the functioning of the network, which helps us to understand how
  •  data packets are transmitted between different nodes. In this article, we will understand in detail how data is sent through links using NS2 in a wired network.

Process of sending data in a wired network:

1. Introduction to wired networks: In a wired network, nodes are connected to each other through physical cables. This network provides high speed and reliability, so that large-scale data transmission can be done without any interruption. NS2 is used to simulate this process.

2. Simulation setup: A simulation setup is required to send data between nodes in a wired network. The simulation setup includes the process of creating nodes, establishing links between them, and connecting traffic agents to the nodes.

3. Creating the simulator and nodes: First, you need to create a simulator object and nodes in NS2:

# Creating the simulator object
set ns [new Simulator]

# Creating the nodes
set node1 [$ns node]
set node2 [$ns node]
set node3 [$ns node]
Here, we have created three nodes (node1, node2, and node3), which we will link together later.

4. Establishing links: Now, it is necessary to create physical links between the nodes. In NS2, you can connect the nodes using the duplex-link command and determine the characteristics of the link, such as bandwidth and latency.

# Creating links between the nodes
$ns duplex-link $node1 $node2 1Mb 10ms DropTail
$ns duplex-link $node2 $node3 1Mb 10ms DropTail
In this:

1Mb represents the bandwidth, i.e., the speed of data transfer.
10ms represents the latency, i.e., the time it takes for data to reach from one node to another.
DropTail is a queue management policy that states that if the queue becomes full, new packets will be dropped.

5. Creating and attaching agents: To send data, we need to connect traffic agents to the nodes. Generally, TCP (Transmission Control Protocol) or UDP (User Datagram Protocol) agents are used. For example, we can use TCP:

# Creating a TCP agent
set tcp0 [new Agent/TCP]
$ns attach-agent $node1 $tcp0

# Connecting the TCP agent to another node
set sink [new Agent/TCPSink]
$ns attach-agent $node2 $sink

In this:

tcp0 is a TCP agent that is attached to node1.
sink is a TCP Sink agent, which is attached to node2 and will receive TCP data.

6. Traffic generation: Now, you need to generate traffic, so that data packets can be exchanged between the nodes. For this, you will need to use a traffic pattern, such as FTP or CBR (Constant Bit Rate). Example:

# Connecting the FTP application to the TCP agent
set ftp [new Application/FTP]
$ftp attach-agent $tcp0
$ns at 1.0 "$ftp start"
$ns at 5.0 "$ftp stop"
In this:

The FTP (File Transfer Protocol) application is connected to the tcp0 agent, which will send data from node1.
The data transfer will start at 1 second of simulation time and stop at 5 seconds.

7. Setting the simulation time and running it: Once all the nodes, agents, and traffic are set, you need to set the simulation time and then run the simulation.

# Simulation end time
$ns at 6.0 "finish"
proc finish {} {
    global ns
    $ns halt
}

# Running the simulation
$ns run
This simulation will run for 6 seconds and then end.

8. Tracing and NAM animation: You can create a trace file to trace the traffic during the simulation, which can be used for analysis later. You can also use NAM (Network Animator) to see the network animation:

# Creating a trace file
set tracefile [open out.tr w]
$ns trace-all $tracefile

# Creating a NAM animation file
set namfile [open out.nam w]
$ns namtrace-all $namfile

9. Analysis of results: After the simulation, the trace file can be analyzed, from which you can see various parameters such as packet transfer, latency, packet loss, and throughput. You can also observe the network activities through a graphical interface by running the NAM file.

In this Chapter

Sending Traffics Through NS2 Links
Auto-Configuration and Anycast
Modified EUI-64 | What is Modified EUI-64?
Architecture of Mobile Computing
Wireless LAN in Hindi | What is Wireless LAN?
Wireless User Devices
MAC Protocol | What is MAC Protocol?
IEEE 802.11 | What is IEEE 802.11
Mobile IP | What is Mobile IP
Wireless TCP/IP
Unicast & Multicast Communication
Bluetooth | What is Bluetooth?
NS2 & NAM | What are NS2 and NAM?
Purpose & installation of NS2 & NAM
Background of NS2 & NAM
Architecture of NS2 & NAM
Interface of OTcl & C++
Trace Files & Formats
Protocol Support of NS2
Simulation Object of NS2 & NAM
Basic Syntax of NS2 & NAM
Node Creation of NS2 & NAM
Running NS2 & NAM
Finish Procedure NS2 & NAM
Invoking external commands within NS2
Nodes & Agents of NS2 & NAM
NS2 Commands
Creating Links in Wired Network
Setting Link Parameters
Routing Protocol Support of NS2
Scenarios in Wired Networks
Additional Parameters
Setting node positions
God object & topography
Protocol Support
Scenarios in Wireless Networks
What is the Internet? Difference Between Intranet and Extranet
Types of Internet
OSI Model and its Layers
Computer Network (CN) All Important Questions and Answers in English (MDSU)
BCA | Computer Network | 2025 Paper | MDSU Exam Paper
Importance of the Layer Model in Computer Networks
Network Classification
Network Topology
Network Switching & Components
Ethernet
Token Ring
Basic Networking Concepts & Cabling
What is a Computer in English?
Bridges in Computer Networks
Routers in Computer Networks
Gateways in Computer Networks
Public & Private Networks
FDMA (Frequency Division Multiple Access)
BCA | CN(Computer Network) Paper | 2023 MDSU Exam Paper
What is World Wide Web (WWW)
TDMA, SDMA, CDMA
Personal Communication System | What is PCS
IPv4 | What is IPv4?
Subnetting IPv4 Address
Casting in IPv4
Private IPv4 Addressing
IPv4 Address Scheme
IPv6 Addressing Scheme
Types of IPv6 Addressing