Amazing technological breakthrough possible @S-Logix pro@slogix.in

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • pro@slogix.in
  • +91- 81240 01111

Social List

How to do data transmission between nodes using UDP in NS2?

Description

In a wireless network, nodes communicate using the communication model that consists of UDP agent, Null agent, and CBR traffic. The sender node is attached to the UDP agent while the receiver node is attached to the Null agent. The connection between UDP agent and a Null agent is established using the keyword “connect”. Transport agent (UDP) and application (CBR) are connected using the keyword “attach-agent”. The CBR traffic object generates the data packet (traffic) based on a deterministic rate. The generated data packets are constant in size. The coding in sample4.tcl illustrates the data transmission between two nodes.

Sample Code

#Filename: sample4.tcl

#******************************Defining Communication Between node0 and all nodes ****************************8

# Defining a transport agent for sending
set udp [new Agent/UDP]

# Attaching transport agent to sender node
$ns attach-agent $node_(0) $udp

# Defining a transport agent for receiving
set null [new Agent/Null]

# Attaching transport agent to receiver node
$ns attach-agent $node_(1) $null

#Connecting sending and receiving transport agents
$ns connect $udp $null

#Defining Application instance
set cbr [new Application/Traffic/CBR]

# Attaching transport agent to application agent
$cbr attach-agent $udp

#Packet size in bytes and interval in seconds definition
$cbr set packetSize_ 512
$cbr set interval_ 0.1

# data packet generation starting time
$ns at 1.0 "$cbr start"

# data packet generation ending time
#$ns at 6.0 "$cbr stop"

Screenshots

data transmission between nodes using UDP in NS2