You are on page 1of 8

TCP, UDP, FTP over TCP

In creating simulations in NS2, the three basic terms are:


Traffic Sources: application layer protocols (FTP, Telnet) Agents: Transport Layer Protocols (FTP, UDP) Nodes: End Systems

Sources need to be attached to agents and agents to nodes

Create a TCP agent: where TCP agent is an object of and specify its class Agent/TCP
set tcp [new Agent/TCP]

Specify the type of packet


$tcp set class_ 2

Attach agent object created to a node object using the attach-agent member function.
$ns attach-agent $n0 $tcp

This function calls the attach member function of specified nodes which attaches given agent to itself.

Create TCP sink agent: it generates and sends ACK packets to the sender and terminate or frees the received packets
set sink [new Agent/TCPSink]

Use the attach-agent member function to specify which node will act as a sink agent as
$ns attach-agent $n3 $sink

Establish logical network connection between the two agents created


$ns connect $tcp $sink

Set the color of the packet


$tcp set fid_ 1

Create UDP agent as


set udp [new Agent/UDP]

Use attach-agent member function to attach agent created to node object


$ns attach-agent $n1 $udp

Create a null agent: this agent will the receive the packets and frees them
set null [new Agent/Null]

To attach null agent to UDP agent use the attachagent member function as
$ns attach-agent $n3 $null

Establish logical network connection between the two agents created


$ns connect $udp $null

Set the color of the packet


$udp set fid_ 2

Create an FTP agent


set ftp [new Application/FTP]

Each agent object has a member function attachagent that attaches a traffic source object to itself
$ftp attach-agent $tcp

You might also like