NS2 – Wireless Networks – Simulation Source Code

Wireless Network Setup
The wireless network can be created in NS2 using the components of a mobile node and its configurations in every layer. Nodes can be deployed either randomly or in a deterministic manner in flat-grid network space. Mobility model of the nodes can be created and integrated in the simulation. Data communication between nodes can be configured with transport and application layer agents that are required to be attached to both sender and receiver nodes. Different types of wireless networks such as Mobile ad hoc Network (MANET), Vehicular ad hoc Network (VANET), Wireless Sensor Network (WSN), Cognitive Radio Network (CRN), Wireless Mesh Network, Cellular network, and Heterogeneous network can be simulated subjective to their own protocol specifications and configurations.

Protocols and Configuration parameters
The physical layer facilitates the configuration of channel, interfaces, antenna type, signal propagation model, energy model, error model, and channel fading scheme. In successive layers, different type of interface queues (DropTail, Priority Queue, CMUPriority queue, RED), MAC layer protocols (IEEE 802.11, IEEE 802.15.4, IEEE 802.11p), Network layer protocols (AODV, DSR, DSDV, AOMDV, TORA, OLSR, ZRP, ZBR, FSR, CGSR, CBRP, LEACH, PEGASIS, GPSR, POR), Transport layer protocols (TCP and its variants, UDP, XCP, SCTP, RTP, RTCP, LossMonitor), application layer protocols (FTP, CBR, Exponential, Pareto, RealAudio, Video) can be applied.
Application layer agents have the options for packet size, data rate, data transmission interval, start and stop time of data transmission. The node mobility model can be created with specification of target location and speed. Nodes with different Communication range can be configured. Energy model can be created with specification of initial energy, transmission, reception, idle and sleep power of the nodes. Error model can be created with a random packet loss rate to simulate network interference and fading.

Wireless Network Scenarios
Various wireless network scenarios such as link failure due to mobility, congestion, attacks can be created dynamically at different instances of the simulation period with event-driven simulation capability of NS2.

Animation of Wireless Network
Regarding the animation of wireless network, it supports the labeling, coloring and of the nodes for differentiation. Since nodes share the wireless medium via wireless channel there are no visible physical links in the network name. It is also possible to drag and drop the nodes in NAM tool to view the network in a desired topological manner. Packet transmission between wireless nodes can be viewed during animation. Properties of the packets and links can be seen if they are clicked in NAM. Ongoing network process can be annotated using trace annotate option and it will be displayed at the bottom of network animation window.

Trace file and AWK script for Wireless Network
Trace file generated at the end of simulation follows a specific format for a wireless network that includes event type, time, nodes involved in it, and data specifications such as address of the source, destination, packet type, size, and a sequence number. It can be processed using the wireless network specific AWK scripts for performance analysis.

The aforementioned stuff of NS2 for wireless networks can be tested using the samples given below: