Simulation and Analysis of SMAC Protocol using NS-2

Guided By: Prof. Sachin Gajjar

Prepared By: Pravin Gareta (08BEC156) Malav Mehta (08BEC159)

‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡ Introduction of our project NAM AWK Gnuplot S-MAC S-MAC implementation in NS-2 Changes made in TCL scripts Conclusion References

Introduction of Project
For our project we need three things : 1. NS-2 2. Knowledge of AWK programming 3. Gnuplot NS stands for Network Simulator and it extensively used by network research community. Users can define arbitrary network topologies composed of nodes, routers, links and shared medium. A rich set of protocol objects can then be attached to nodes, usually as agents. Ns-2 is written in C++, with an Otcl interpreter as a frontend.

Ns-2 is open-source software and free to use for all users. Due to its open source nature, a user can modify parameters at different layers, create his or her own applications, and develop new protocol. AWK programming like the c++ language. After running the TCL script in the NS-2 we get output in two forms : 1. We can visualize output in NAM editor. 2. We can analyze output using trace file For trace file analysis we need a awk programming support

NAM : Network Animator

AWK example


BEGIN { clear; rec = 0; send = 0; }{ if ( $1 == "+" && $5== cbr" && $3=="0") { send = send +$6; } if ( $1 == "r" && $5== cbr" && $4=="3" ) { rec = rec + $6; } } END{ printf("\n packet Send %d", send) >>"thr.log"; printf("\n packet Recv %d", rec) >> "thr.log"; printf("\n packet Drop %d", send -rec) >> "thr.log"; printf("\n packet efficiency %f", (send/rec)*100) >> "thr.log";


0.2 0.4 0.5 1.0 1.5 2.0 2.5 3.0 86.67 96.36 96.49 99.300 100.00 100.00 100.00 100.00 (This is a data of Link BW and Efficiency)

Gnuplot Script
set title "Link BW and Rate" set xlabel "Link BW" set ylabel "Rate" set xrange [0:3] set yrange [70:110] set xtics 0.5 set ytics 5 plot "thr7.log" using 1:2 title "packet" with linespoints pause -1 "Hit return to continue"

S-MAC stands for Sensor Medium Access Channel. In a WSN: ³energy conservation and self-configuration are primary goals...´ Major sources of Energy waste: Collision: corrupted packets must be retransmitted and it increases energy consumption. Overhearing:picking up packets that are destined to other nodes. Idle Listening : Listening to receive possible traffic that is not sent

Basic Features of S-MAC
Listen and Sleep Periodically according to the schedule. Both Physical and Virtual Carrier Sense Overhearing Avoidance RTS/CTS Mechanism Synchronization Algorithm Neighbor discovery

Simulating S-MAC with NS-2
Changes made in NS-2 : If your NS release is 2.30 and above then it is not problem for running the s-mac program. If your ns version is 2.29 and below then you have to download a file from the site listed below: Put this file into these path : ns-2/trace/ These file is for the detailed trace analysis of the program

S-MAC Parameter Settings

In TCL script: Mac/SMAC set syncFlag_ 1 Mac/SMAC set dutyCycle_ 10

Common Settings For Simulation
Topology : In this simulation we have used a 2 node topology one is source and another is sink. Traffic pattern: We attached the UDP agent and CBR Traffic source to the source node. AIM: In this simulation we have compare the IEEE 802.11 and S-MAC protocol. Both are same except S-MAC having the some differences from 802.11.

S-MAC Trace Format

First field indicate event type : ‡ Send(s) ‡ Receive(r) ‡ Drop(d) ‡ Forward(f) Time Event

Id of the node on which event takes place Layer where these event happen ‡ AGT(Agent) ‡ RTR(Router) ‡IFQ(Interface Queue) ‡MAC(mac) Fifth field is reserved for special event 6th field indicate global sequence number for packet 7th represented by packet type Here CBR represents that it is data source generated by CBR Traffic source.

The ninth field including three numbers in brackets concerns MAC layer information. Originally, there will be four numbers in the brackets. But S-MAC revises this format. The first number is the duration field of this packet. In Fig. the duration field of this RTS packet is 0.11 s, which is the remaining time reserved for the coming transmission. The second number stands for the MAC address of the receiver of this packet, and the third number for the sender. The above nine fields are common for all s-mac format.

Measurement of Energy Consumption
We run the TCL script and get the trace file. Form the trace file we compare the ideal energy of both S-MAC and IEEE 802.11 Because for s-mac periodic sleep and listen is employed so, obviously energy consumption of s-mac is low compared to the 802.11 These is shown in the Gnuplot also :

Measurement of delay vs. energy consumption
Here we change the duty cycle of s-mac in the TCL file. We take first duty cycle 10% For the second case we have taken it 20% So, basically we changed the listen period of the program by changing the dutycycle. We get the result that as a listen time is small energy consumption is less and delay is more. So, S-MAC is trade off between delay and energy and it is shown in the Gnuplot.

Traffic Variation vs. energy consumption
For the traffic variation we change the CBR traffic interval from 0.001 to 10s. And note that 0.001s is high traffic case and 10s is the low traffic case. We see that for s-mac there is no such variation for high or low traffic means s-mac will adjust its sleep period according to the situation. While for 802.11 energy consumption is large.

Energy consumption at Intermediate node
Here we design a 3 node topology 1 node are sender and 1 node are sink and 1 is router. Here we compare the ideal energy state of the intermediate node. For s-mac variation of energy consumption at an intermediate node is very less while for 802.11 it is large variation. These is shown in the graph.

Changes made in TCL script

During the project work, we have done the following two main tasks. 1. We learn NS-2 then simulate S-MAC in ns-2.34 and found out how S-MAC works. 2. We have compare the s-mac protocol with the IEEE 802.11. Through analyzing the simulation results, we have the following conclusions:

S-MAC with periodic sleep efficiently reduces the energy consumptions due to idle listening. However, periodic sleeping increases latency and reduces throughput. So, s-mac is a trade off between energy and delay.

[1] W. Ye, J. Heidemann, and D. Estrin. An energyefficient MAC protocol for wireless sensor networks. [2] M. Greis. Tutorial for the network simulator ns. [3] The Network Simulator: Building Ns web page. [4] NsNam Site Search web page. [5] J. Chung and M. Claypool. NS by example [6] Smac-users -- Discussions by users of S-MAC web page.