The simulation of S-MAC protocol is incomplete unless we analyze its energy consumption. We are interested on Analysis of Average energy consumption and energy consumption in each sensor node. I am going to present here a perl script that calculates the energy consumption of each node and average energy consumption.
# ============================================
# Average energy consume for new wireless revised trace format
# ============================================
# take input
$infile=$ARGV[0];
# open data file
open (DATA,"<$infile") || die "Can't open $infile $!";
# some looping condition
while (<DATA>) {
@x = split(' ');
# checking if column is r,s,d or f and column 1 is -t
if (($x[1] eq '-t')&&(($x[0] eq 's')||($x[0] eq 'r')||($x[0] eq 'd')||($x[0] eq 'f'))){
# column 8 is for node id. column 16 is node energy
if ($x[8] eq '0'){
$enerygy_0=$x[16];
}
if ($x[8] eq '1'){
$enerygy_1=$x[16];
}
if ($x[8] eq '2'){
$enerygy_2=$x[16];
}
if ($x[8] eq '3'){
$enerygy_3=$x[16];
}
if ($x[8] eq '4'){
$enerygy_4=$x[16];
}
if ($x[8] eq '5'){
$enerygy_5=$x[16];
}
if ($x[8] eq '6'){
$enerygy_6=$x[16];
}
if ($x[8] eq '7'){
$enerygy_7=$x[16];
}
if ($x[8] eq '8'){
$enerygy_8=$x[16];
}
if ($x[8] eq '9'){
$enerygy_9=$x[16];
}
}
}
# Total initial energy in this case is 500. So we subtract from 500 to calculate energy remain
# Define it as you defined in your tcl script '$ns_ node-config -initialEnergy 500 \'
# print Energy consumed by each node.
print "Energy consume of 0 node: \t\t",(500-$enerygy_0),"\tJoule\n";
print "Energy consume of 1 node: \t\t",(500-$enerygy_1),"\tJoule\n";
print "Energy consume of 2 node: \t\t",(500-$enerygy_2),"\tJoule\n";
print "Energy consume of 3 node: \t\t",(500-$enerygy_3),"\tJoule\n";
print "Energy consume of 4 node: \t\t",(500-$enerygy_4),"\tJoule\n";
print "Energy consume of 5 node: \t\t",(500-$enerygy_5),"\tJoule\n";
print "Energy consume of 6 node: \t\t",(500-$enerygy_6),"\tJoule\n";
print "Energy consume of 7 node: \t\t",(500-$enerygy_7),"\tJoule\n";
print "Energy consume of 8 node: \t\t",(500-$enerygy_8),"\tJoule\n";
print "Energy consume of 9 node: \t\t",(500-$enerygy_9),"\tJoule\n";
# calculate average energy consume
# Total initial energy of all 10 nodes=500J*10=5000J, so we subtract from 5000.
$average_energy_consume=((5000-($enerygy_0+$enerygy_1+$enerygy_2+$enerygy_3+$enerygy_4+$enerygy_5+$enerygy_6+$enerygy_7+$enerygy_8+$enerygy_9))/10);
$total_pkt_in_byte=$pkt_recv_cnt*512;
# print average energy consume
print "Average energy consume:\t", $average_energy_consume,"\n";
close DATA;
exit(0);
# ============================================
For 10 linear nodes, i have simulated the average energy consumed. The graph is as given below:
figure1: Average energy consumed vs Packet inter-sending time of transmitter
The nature of curve suggest us that 5% duty cycle consumes less energy than 10% duty cycle, 10% duty cycle consumes less energy than 15% duty cycle, and so on. Hence no periodic sleep consumes greater energy. The reason behind this is very simple, 5% duty cycle node only listens for 5% of its hearing cycle and hence consumes less energy, whereby no periodic sleep always listens and consumes more energy. The intermediate duty cycles fall in between them.
Taking about traffic, the graph suggests that more traffic (pkt inter sending time 1,2,3) has more energy consume and less traffic (pkt inter sending time 8,9,10) has less energy consume; which seems obvious since more traffic means more pkt to send and sending more pkt requires more energy to consume. Similarly, less traffic is less number of packet to send, and sending less number of packets requires less energy to consume.
As i am doing project on analysis of S-MAC protocol, suggestions are hearty welcomed. You can mail me at shrestha.sp11 at gmail dot com.