The below code creates three nodes
#include "ns3/netanim-module.h"
using namespace ns3;
int main (int argc, char *argv[])
{
/**************************************************************************************
Code to create 3 nodes which represent the 3 computers in simulation
Creates NodeContainer topology helper named 'nodes', which is used to create and manage the nodes in simulation
**************************************************************************************/
NodeContainer nodes;
/**************************************************************************************
Creates 3 nodes using 'Create()' method in NodeContainer topology helper class.
**************************************************************************************/
nodes.Create (3);
/**************************************************************************************
Code to specify boundary of simulation window
**************************************************************************************/
AnimationInterface::SetBoundary (0, 0, 100, 100);
/**************************************************************************************
Netanim application requires a custom trace file.The below code creates a xml file called firstPgm.xml which acts as trace file
**************************************************************************************/
AnimationInterface anim("firstPgm.xml");
/**************************************************************************************
Code to denote first node as FirstNode
**************************************************************************************/
anim.UpdateNodeDescription (0, "FirstNode");
/**************************************************************************************
We can specify the position of a node using SetConstantPosition() in AnimationInterface class .This method requires 3 parameters
1.Node whose position is to be set (From NodeContainer topology helper object we can get a specific node by its index. First node will be in 0th index and we get it using Get() by providing its index)
2.Its x position
3.Its y position
**************************************************************************************/
anim.SetConstantPosition (nodes.Get(0),10.0,10.0 );
/**************************************************************************************
Code to run simulation
**************************************************************************************/
Simulator::Run ();
/**************************************************************************************
Code to clean up simulation
**************************************************************************************/
Simulator::Destroy ();
return 0;
}