# LoRaWAN Behaviour Analysis through Dataset Traffic Investigation
## 4 LoRaWAN Analysis
### Performance of De-Duplication Procedure  
In a LoRaWAN, each time the NS sends a downlink packet it has to select the gateway that will forward the packet to the end-device, that operation is simple when it receives a non-duplicate uplink packet, in this case the NS will select the gateway from which it has received the uplink packet. However, in a multi-gateway network, a packet sent by a device could be received by more than one gateway. All the duplicate packets are then forwarded by the gateways to the NS. In this scenario, the NS has to operate a packet de-duplication, in which only one packet among the multiple copies is kept and forwarded to the Application Server [4]. Moreover, the gateway which received the de-duplicated packet, is the one selected to send a downlink packet to the device, if needed. LoRaWAN specifications do not specify the procedure that the NS should follow to operate de-duplication and gateway selection. One possible criterion the select one gateway is to choose the one that has forwarded the uplink packet with higher SNR [17] or the higher _RSSI_. In order to collect all the uplink packets, the NS opens a time window of duration \(T_{D}\) when a new and unseen packet is observed. This window is called de-duplication window. In LoRaWAN specification there are no fixed values to assign to \(T_{D}\), however some of the most known open source implementations of LoRaWAN NS [13; 18] use the value \(T_{D}=200\) ms.  
To investigate the behaviour of duplicate packets, we analyse the packets as if we were a NS performing a deduplication procedure, carefully selecting the value of \(T_{D}\). Figure 15 represents two cases of de-duplication, in both cases there are three duplicates of the packet \(P\) but the two differ on the duration of the de-duplication window. In the upper scheme, \(T_{D}\) is such that all the duplicates are taken into account for the de-duplication procedure, so in this case all the duplicates are deleted and only one response is sent. The inconvenient in this first case is that \(T_{D}\) is too big, in fact the network server, after receiving packet \(P\) by gateway 3, waits for a long time before to perform the de-duplication even if there are no more duplicates. Figure 14: Plot of CDF of end-devices in the function of the percentage of the duty-cycle with zoom on duty-cycle percentage range [0, 0.5]. In the complete graph, the blue line represents the duty-cycle constraint of 1% while in the zoom the green line represents the duty-cycle of 0.1% and the correspondent CDF of 0.91. In the second case, represented in Figure 15, there are two de-duplication windows of time \(T^{\prime}_{D}\) and in this case two duplicates are considered in the the first de-duplication and the last arrived duplicate arrives in the second de-duplication window. Since the duplicates are divided in two de-duplication windows the network server will delete the duplicate in the first de-duplication window and consider the third duplicate as wrong packet because it has an already used frame counter. In this case, the network server may not wait enough to chose the best gateway to forward the response. Our goal is to find a good trade-off for \(T_{D}\) that will be used by the NS. First, we search for the duplicate packets and analyse the time \(T_{F}\) where the first duplicate appears and the time \(T_{L}\) where the last duplicate appears, for each group of duplicate frames. Then, we have used these values to compute the optimal de-duplication window duration for each duplicate packet p as follow:  
\[T^{p}_{D}=T^{p}_{L}-T^{p}_{F}\]  
After computing the optimal de-duplication window duration for each group of duplicates, we plot the distribution of the optimal de-duplication window time over the quantity of groups of duplicates.