Sunday, March 30, 2008

Creating connections using ns-2

When two nodes want to communicate, it is necessary that a connection is established between them. While a connection is defined, it necessary to classify the nodes as either source or sink. The node that is sending the data is defined as the source and node that is receiving the data is defined as the destination. The following are the commands that are used to define the source and sink.

set source [new Agent/UDP]

set sink [new Agent/null] (or)

set sink [new Agent/LossMonitor]

LossMonitor is a class in ns that is used to monitor the packet loss occurring in the receiver. After the source and sink have been defined, they have to be attached to the nodes. The command used to attach the nodes with the agents is,

$ns attach-agent $node_(0) $source

After the nodes have been created and the agents have been attached, a connection is established between the source and the sink using the following command,

$ns connect $source $sink

No comments: