You are on page 1of 9

EC316 WIRELESS SENSOR NETWORKS

EC316 WIRELESS SENSOR NETWORKS

SUBMITTED TO: Ms. KRITI SUNEJA

SUBMITTED BY: SHIVAM


(2K18/EC/160)

WIRELESS SENSOR NETWORKS FILE


(G3 GROUP)

Shivam (2K18/EC/160) 1
EC316 WIRELESS SENSOR NETWORKS

INDEX
S.no Experiment Date Remarks
1 To become familiar with 12-01-21
Wireless Sensor Networks.
2 To understand the differences 18-01-21
between Ad Hoc network and
WSN.

3 To implement MACA protocol 28-01-21


using MATLAB/SCI LAB.

4 To implementMACAW
protocol using MATLAB/SCI
11-02-21

LAB.

Shivam (2K18/EC/160) 2
EC316 WIRELESS SENSOR NETWORKS

EXPERIMENT 4
Aim: To Implement MACAW protocol using MATLAB/SCI LAB.
Tools Required: MATLAB/SCI LAB
Theory:
Multiple Access with Collision Avoidance for Wireless (MACAW) is a medium access
control (MAC) protocol broadly utilized in ad hoc network systems. Besides, it is the
establishment of numerous other MAC protocols utilized in wireless sensor systems (WSN).
The IEEE 802.11 RTS/CTS system is received from this protocol. It utilizes RTS-CTS-DS-
DATA-ACK frame succession for moving information, once in a while went before by a
RTS-RRTS frame arrangement, in view to give answer for the concealed node problem.
Although protocol dependent on MACAW, are S-MAC, MACAW doesn’t utilize carrier
sense.
Features :
 The problem in MACA that if there are two sender and two receiver A, B, C and D
respectively.
 If B has send RTS to C and D at the same time and but only send data upon receiving
CTS from C.
 Now A wants to send data to D but will not able to send because it will sense that D is
currently busy and will increase the backoff counter (for how much time A will wait
before re-transmitting) value by twice because of which it will get stuck in a loop
until the D gets free.

Shivam (2K18/EC/160) 3
EC316 WIRELESS SENSOR NETWORKS

 Blockage data trade between pairwise stations, prompting better clog control and
backoff approaches

Advantages over MACA :


 The sender detects the bearer to see and transmits a RTS (Request To Send) if no
close by station transmits a RTS.
 The fairness of MACAW is much better than MACA.
 It handle hidden and exposed node problem better than MACA.
 ACK signal is send to the MAC layer, after every data frame.
 It also incorporate carrier detecting to additionally diminish collision
 Irregular pause and re-attempt transmission at each message level, rather than at
each node level.
Working :
 This problem is solved by Multiple Access with Collision Avoidance for Wireless
protocol because it introduces packet containing current transmission nodes’s
backoff counter value to be copied into the other sender node. This will reduce the
wait time very significantly.
 MACAW also introduce two new data frame DS(Data-Sending) which provides
information about the length of the incoming DATA frame and RRTS(Request for
Request to Send) which acts as a proxy to RTS.

Example :
A successful transmission in case of MACAW will look like :
Shivam (2K18/EC/160) 4
EC316 WIRELESS SENSOR NETWORKS

 RTS from A to B
 CTS from B to A
 DS from A to B
 DATA frame from A to B
 ACK from B to A.

A successful transmission in case of MACAW with RRTS will look like :


 RTS from A to B

 RRTS from B to A

 RTS from A to B

 CTS from B to A

 DS from A to B

 DATA frame from A to B

 ACK from B to A.

Shivam (2K18/EC/160) 5
EC316 WIRELESS SENSOR NETWORKS

CODE:
N = input('enter number of nodes'); % Choose Number of NODES in range 1 to 200.
Packet_size = input('enter the packet size') * 8; % Choose Packet Size in Bytes.
T = input('enter the simulation time') * 10^-3; % Choose Simulation time.
total_time = 0;
count = 0;
good_time = 0;
data_rate = 6 * 10^6; % Data Rate of 6 Mbps.
packet_time = Packet_size / data_rate;
slot_size = 9 * (10^-6); % Slot Size of 9μs.
j = 1;
simulation_count = 0;
CW_min = 30; % Minimum Contention Window, for every collision we will reduce CW to
Cwmin.
CW = 30; % For every successful transmission we will double CW.
collision_flag = 0; % To check if collision occurred or not.
r = (randi([0,CW_min],N,1)) * 10^-6; % Counter for N Nodes.

while total_time < T


[M,I] = min(r);
simulation_count = simulation_count + 1;

for i = 1:N
if (M == r(i)) % To find the Node with Minimal Counter.
count = count + 1; % If there are multiple nodes with minimum counter that would cause
collision.
collision_index(j) =i;
j = j + 1;
end
end

if count > 1 % Occurrence of Collision.


collision_flag = 1; % Setting collision flag to 1.
Shivam (2K18/EC/160) 6
EC316 WIRELESS SENSOR NETWORKS

end

if collision_flag ~= 1 % no collision
good_time = good_time + packet_time;
if CW < 1 % For the Node which transmitted first update CW and then choose new
counter.
CW = 1.5;
end
r(I) = (randi([0,CW],1,1)) * 10^-6;

else
CW=CW-1; % For every transmission reduce the contention window by 1.
end

for i = 1:N %For every nodes that collided ,first update CW and choose new counter
if (M == r(i))
r(i) = (randi([0,CW],1,1)) * 10^-6;
end
end

total_time = total_time +packet_time;


end
for i = 1:N % Update counters of all nodes that didn’t collide
for j =1:size(collision_index)
if(i ~=collision_index(j))
r(i) = r(i) - slot_size;
end
end
%CW=CW-1;
count = 0;
collision_flag = 0;
end % End while loop
utility = good_time / total_time;
fprintf('Number of Nodes: %d ; Packet Size: %d ; Simulation Time(s):%d \n
Utilization: ', N,Packet_size, T);
disp(utility);

OUTPUT:

Shivam (2K18/EC/160) 7
EC316 WIRELESS SENSOR NETWORKS

Shivam (2K18/EC/160) 8
EC316 WIRELESS SENSOR NETWORKS

Result: Successfully implemented MACAW protocol.

Shivam (2K18/EC/160) 9

You might also like