Now to add the Two nodes to the simulation area and add the link to it. The concept of adding the components in NS2 is just like the OSI model. Its like you already have IP layers ready, above that you want to add an agent and a traffic generator. In this example we added a UDP agent and CBR(Constant Bit Rate) traffic generator to it, which will generate a constant traffic for the system.

This is the sender side, on the reciver side we can use a sink which will just accept the traffic and sink it. In case of TCP traffic, we need to have a TCP receiver, since we are using UCP traffic, am creating the UDP sink. This will create a scenario and play it by sending it the data. We will get to see the NAM of this example and start the simulation after the assigned time. So the code is quite self explanatory. So here it