Suppose you are given a task to write a code for designing a network. What you will think at first?
First you may think about placing a node. But what will be its data type? a node has many properties such as its position (X and Y coordinates), speed, direction towards which it is moving, energy etc. Hence, there is a need of a data structure. A class containing all these variable will have to be created and an object of the class will be representing one node.
Secondly, a packet should be created. Similar to the node, packet also has various properties such as its id, size, packet type (data packet or control packet) etc. A class containing all these variables will have to be created and an object of that class will represent one packet.
Similarly, other components of a network such as channel, queue etc. will have to be created and all these components should be arranged in such a way that the packet should flow as in an original network.
Now, all these classes and related variables and functions are already there in the network simulator. You just have to learn to use them.
Components of network simulator – 2
There are mainly four components we need to understand about network simulator.
1. Tcl script (Tool command language) : It is used to create a scenario. For placing nodes at a particular place, for creating links between nodes and to define properties of nodes, channel, etc. Tcl scripts also defines several protocols to be used such as , MAC protocol to be used (802.11 or 802.15.4 etc.), routing protocols(AODV, DSDV etc.), transport layer protocol (UDP/TCP).
2. C++ : It contains the source code for all the nodes or protocols used in Tcl script. C++ source codes are connected to Tcl script through a Tcl hook.
3. Trace and NAM file: These are two output files generated in ns2. Trace file contains all the events happened during simulation. such as when a packet is transmitted from which node or through which layer or on which channel. NAM file is similar to trace file but it is used to see the animation of simulation events.
4. AWK: It reads the trace file row wise and calculates the performance parameters of the network using trace file.