How to calculate the Packet Delivery Ratio for CoAP message in cooja simulator?

Description

The packet delivery ratio is the ratio of packets successfully received to the total sent data packets.

   Border router location:
home/contiki/examples/ipv6/
rpl-border-router

   Open motes menu >> add
motes >> create new motes type

   Connect the router to server.
In terminal at above location.

   make-connect-router-cooja

   Start the simulation.

   Now reload the (.csc)
file in cooja network simulator.

   After successful compilation
new terminal will be open.

(i.e).simulation script editor.

   Edit script file,

  After complete the simulation,
save it desired location (.csc)
file will be created.

  Add the following script code
into that file to calculate
metrics.

Code:

org.contikios.cooja.plugins.
ScriptRunner

< script>TIMEOUT(300000, log.log
("Performance Calculation" + "\n"));

packetsReceived= new Array();

packetsSent = new Array();

timeReceived = new Array();

timeSent = new Array();

count = new Array();

nodeCount = 27;

data_length = 23;

senderID = 0;

receiverID = 0;

PDR=0;

e_count = 0;

for(i = 3; i <= nodeCount; i++)

{

packetsReceived[i] = 0;

packetsSent[i] = 0;

timeSent[i] = 0;

timeReceived[i] = 0;

}

while(1) {

YIELD();

msgArray = msg.split(' ');

if(msgArray[0].equals("Sending"))

{

if(msgArray.length == 5)

{

// sent packet

senderID = parseInt(msgArray[4]);

packetsSent[senderID]++;

timeSent[senderID] = time;

}

}

if(msgArray[0].equals("Got"))

{

if(msgArray.length == 6)

{

receiverID = parseInt(msgArray[5]);

packetsReceived[receiverID]++;

timeReceived[receiverID] = time;

log.log("receiverID "
+ receiverID + " PacketReceived= "
+packetsReceived[receiverID] + "\n");

if (timeReceived[receiverID] > 0)

{

count[receiverID]++

}

totalReceived = totalSent = 0;

totalclient=0;

for(i = 3; i <= nodeCount; i++)

{

totalclient++;

totalReceived += packetsReceived[i];

totalSent += packetsSent[i];

log.log("MoteID= " + i + "
ReceivedPackets= " + packetsReceived[i] +
" SendingPackets= " + packetsSent[i]
+ "\n");

}

log.log(" Generated Packets
" + totalSent + "\n");

log.log(" ReceivedPackets "
+ totalReceived + "\n");

PDR=(totalReceived / totalSent)
* 100

log.log("Packet Delivery Ratio"
+ PDR + "\n");

}

}

}

Now reload the (.csc) file in
cooja network simulator.

After successful compilation
new terminal will be open.

(i.e).simulation script editor.

  Connect the server and
start the simulation.

  It will display the packet
delivery ratio (PDR) in details.

  >> Save the script editor
output . it calculates ,

  i.Generated packets

  ii.Received packets

  iii.Packet Delivery Ratio

7a

  To plot the graph for
performance evaluation with collected
data packet information.

  Matplotlip.pyplot
using this tool we can plot
the graph.

  Open terminal >>enter
ipython>>enter following code.

Code:

import numpy as np

import matplotlib

import matplotlib.pyplot as plt

x = [10, 15, 20, 25, 30]

y1 = [137, 125, 116, 88, 105]

y2 = [228, 230, 195, 146, 108]

y3 = [187, 182, 163, 118, 116]

plt.plot(x,y1,linewidth=2.5,
marker='s', markersize=9,
fillstyle='top',

markerfacecoloralt ='tan',
linestyle='-', color='teal',
label = 'CACC')

plt.plot(x,y2,linewidth=2.5,
marker='D', markersize=9,
fillstyle='top',

markerfacecoloralt ='tan',
linestyle='-', color='blue'
,label = 'COCOA+')

plt.plot(x,y3,linewidth=2.5,
marker='p', markersize=9,
fillstyle='top',

markerfacecoloralt ='tan',
linestyle='-', color='maroon
',label = 'COAP')

plt.xlabel('Data Transmission
Interval')

plt.ylabel
('PacketLoss(packets)')

plt.rc('font',family=
'Times New Roman')

plt.rcParams.update
({'font.size':14})

plt.legend(loc='center
', prop={'size':14})

plt.grid()

plt.show()

Note: Modify your collected
data into your saved file before you
enter into plotting data.

In terminal,

Ipython >> enter codes>>enter

7b

To create border router motes

home/user/contiki/examples/ipv6/
rpl-border-router/border-router.c

   After compilation press enter
it will generate graph and save it.

7c
Leave Comment

Your email address will not be published. Required fields are marked *

clear formSubmit