LoRaWAN Anti-collision Algorithm Based on Dynamic Frame-slotted ALOHA

With the exponential growth of IoT devices, new challenges have been placed on the scalability and reliability of LoRa networks. At present, the collision problem of the LoRa network is serious. This is because its MAC layer protocol LoRaWAN is mainly based on the pure ALOHA mechanism, which is too simple to handle the collision. The dynamic frame-slotted ALOHA algorithm is optimized on the pure ALOHA algorithm, which can effectively reduce the collision. Therefore, this paper combines the dynamic frame-slotted ALOHA algorithm with LoRaWAN to dynamically divide one cycle into multiple frames. Through the LoRa preamble detection technology, the intra-frame slots are divided into idle time slots, single time slots and collision time slots. According to the number of slots, the optimal frame length of the next frame is estimated. Besides, the paper studies the initial frame length ratio. The simulation experiment is carried out on the LoRaWAN model on ns-3, which verifies that the algorithm can effectively improve the Packet Delivery Ration and System Efficiency.


Introduction
With the rapid development of the Internet of Things, new application areas are emerging. Traditional MTM technology is no longer sufficient, so LPWAN (Low Power Wide Area Network) came into being. Compared with WiFi, Bluetooth and Zigbee, LPWAN is a revolutionary IoT wireless access technology with long distance, low power consumption and low cost. It can accommodate many nodes and is suitable for devices like wireless sensor nodes using batteries to transmit small amounts of data [1] . LoRa (Long Range) is a LPWAN technology based on unlicensed spectrum below 1GHz released by Semtech in 2013 [2] . LoRaWAN is the MAC layer protocol of LoRa technology, which is formulated and released by the International LoRa Alliance [3] . Since LoRaWAN is based on the ALOHA pay-as-you-go mechanism [4] , the probability of collisions is high. Reference [5] proposes a TDMA-based LoRa network, which sets unique labels for terminal devices and completes transmissions in their respective time slots to avoid collisions. However, this polling mechanism does not have a retransmission mechanism when the node fails to upload. In [6], for the shortcomings of the classic polling protocol, a TDMA time slot allocation protocol with dynamic retransmission and differential service mechanism is proposed. In [7], an improved data anti-collision algorithm CD-ALOHA is proposed, which utilizes the multiple accessibility of orthogonal spreading codes while preserving the competitive backoff mechanism of ALOHA algorithm. Based on the competition retreat mechanism, the literature [8] proposed a binary exponential backoff algorithm. The data ISCME 2019 Journal of Physics: Conference Series 1486 (2020) 032045 IOP Publishing doi:10.1088/1742-6596/1486/3/032045 2 transmission process was described by a simple state machine. Based on the 18000-6C protocol, the literature [4] proposes to combine the ALOHA anti-collision algorithm based on the Q algorithm with LoRaWAN, and achieves the adaptation through testing, which improves the fairness and throughput of the LoRa network. Since the pure ALOHA protocol is too simple in collision processing, this paper proposes an optimal frame length anti-collision algorithm to improve network reliability and system performance by combining dynamic frame-slotted ALOHA anti-collision algorithm with LoRaWAN protocol.

LoRa and LoRaWAN
LoRa is a spread spectrum modulation technique on physical layer, while LoRaWAN protocol specifies the sending and receiving rules of the MAC layer of LoRa devices, including the frame format used by the terminal to communicate with the gateway (requesting connection frames, data frames, etc.), the receiving window of the terminal device, the MAC command of the gateway, retransmission mechanism, rate adaptation mechanism, error control mechanism, etc [3] .

2.1Network Architecture and Terminal
LoRa usually uses a star network. The gateway is directly connected to the node and can connect to hundreds of terminal nodes. An endpoint can upload data to a web server through one or more gateways.
LoRaWAN specifies three terminal device types, Class A, Class B, and Class C. In Class A, the terminal actively sends a message to the gateway according to its own requirements. The gateway can only reply one of the two short-term downlink receiving windows that follow the uplink transmission of the terminal [9] . In addition to the random reception window of Class A, the terminal in Class B opens another receiving window at the specified time. The terminal needs to receive a time synchronization beacon from the gateway. The receiving window of the Class C terminal is only turned off briefly during transmission and keeps open for other time. Therefore, Class C consumes more power than Class A and B, but the delay of the server issuing the terminal is also the shortest [10] .

2.2Retransmission and Rate-adaptation Mechanism
Different frequency bands and rates can be selected for communication between nodes and gateways. The selection of different rates is mainly determined by selecting the SF (Spreading Factor) [11] . Usually, devices with farther distances need to select a larger SF to obtain higher sensitivity, but at the same time the transmission rate will be lower [12] .
The LoRa terminal node can set the number of retransmissions after the data packet fails to be sent, usually 0 to 7 times. When the number of retransmissions is used up and acknowledgement is still not received, the rate is reduced to obtain a longer transmission distance.

3.1Dynamic Frame-slotted ALOHA Agrithm
The DFAA(Dynamic Frame-slotted ALOHA Algorithm) is based on the frame-slotted ALOHA, by dynamically adjusting the frame length after the initial frame. The algorithm first sets the initial frame length according to the total number of nodes. After the first transmission, the number of nodes that are not successfully transmitted is estimated in order to dynamically set the length of next frame. The key of the algorithm is the calculation of the optimal frame length. If the frame length is too short, the probability of collision will increase. If the frame length is too long, the time slot will be wasted [13] .
The optimal frame length for different amount of nodes is generally the slot length multiplied by the number of nodes. F = t * n (1) F is the frame length, t is the length of one slot, and n is the number of nodes. After the end of one frame, the next frame length is set according to the number of nodes that have not been successfully transmitted. The estimation algorithms for the number of nodes that are not successfully transmitted due to collisions include minimum estimation method, Poisson estimation method, collision probability estimation method, Chebyshev estimation method, etc.. Without considering the calculation difficulty, this paper gives priority to the use of Chebyshev estimation algorithm which has high precision.

3.2Algorithm Implementation
In LoRaWAN, the communication between the node and the gateway can only be successful or failed. However, the preamble detection technology can divide the failure into idle slot and collision slot, that is, whether the LoRa preamble is detected through the channel. If there is a preamble, it is a collision slot, else it is an idle slot.
Through the Chebyshev estimation algorithm [14] , when the frame length is F, the idle slot, the single slot, and the collision slot are respectively c0、c1、ck, and the estimated number of nodes is n. The expected values of the idle slots, single slots, and collision slots corresponding to the theoretically different values of n are calculated as c0 ' 、c1 ' 、ck ' . The relationship between the expected value and F and n is shown in equation (2): When the difference between the expected value and the actual value is the smallest, the corresponding n value is taken as the estimated number of nodes [16]. Which is the minimum value of (3): According to the estimated number n and the number of successfully transmitted nodes c1, the number of nodes that have not been successfully transmitted is n-c1, and is brought into equation (1) to calculate the optimal frame length of the next frame.

3.3Result of Experiment
The experiment is based on the LoRa network model on ns3 provided by [11], including LoRa's channel model SpectrumChannel, and the physical layer LoRaWANPhy and MAC layer LoRaWANMac of the Class A node and the gateway, and the device layer LoRaWANNetDevice of the terminal node and gateway, as well as the application layer LoRaWANEndDeviceApplication of the terminal node, LoRaWANGatewayApplication of the gateway, and a simple network server LoRaWANNetworkServer. They can basically simulate a real LoRa network. The specific architecture is shown in the following figure:  gateway, that is, PDR = the number of successfully transmitted packets / the total number of packets sent. It is a statistical measure of correctly transmitting packets , which reflects the reliability and congestion of a network.
Another evaluation criterion called system efficiency is the ratio of the number of successfully transmitted time slots to the total number of time slots, i.e., system efficiency = number of successfully transmitted time slots / total number of time slots, reflecting the overall performance of the system.
On the ns-3, the relationship between PDR, system efficiency and period length of pure ALOHA and DFAA (Dynamic Frame-slotted ALOHA Algorithm) is simulated. The results are shown in Figure  2 and Figure 3.  Figure 2, when the number of nodes is 1000 and 2000, the PDR of the DFAA is always higher than the PDR of the pure ALOHA algorithm as the period length increases; and Figure  3 shows that about system efficiency, the DFAA is slightly lower than the pure ALOHA algorithm. At this time, since the system efficiency mainly depends on the time slot utilization, all the nodes in the pure ALOHA algorithm are only sent once, but the nodes that failed to transmit are sent again in the DFAA. The total number of transmissions in the latter is more than the former, so the total number of slots corresponds is more. When the period is short, there is no absolute advantage in the transmission success rate of the DFAA. Therefore, the system efficiency is slightly lower than the pure ALOHA protocol at first; When the period length reaches a certain length and continues to increase, the advantages of the DFAA gradually emerge, and the system efficiency begins to be higher than the pure ALOHA algorithm.

3.4Research on Initial Frame Length
In a LoRa network, when the number of nodes is constant, the PDR has a correlation with the period length. The relationship is that the longer the period, the higher the PDR. However, if the period is set too long, the channel utilization rate will be low. When the period is short, the initial frame length is set mainly considering the length of the period, that is, the proportion of the total period length. In the following experiments, it is assumed that the period length is fixed, and the initial frame length ratio is a variable value (for example, 0.1,0.2,0.3,…,0.9), all nodes in the first frame complete the transmission, the node that failed to transmit continues to transmit in the next frame. The simulation shows the PDR when the number of nodes with fixed period length is 1000 and 2000, and the initial frame length accounts for the total period length is different.  Fig. 4. The results show that when the number of nodes is 1000 and the period is 1000s, the PDR reaches the maximum when the initial frame length is 70%; when the period is 500s, the PDR reaches the maximum when the initial frame length is 60%. When the number of nodes is 2000 and the period is 2000s, the PDR reaches the maximum value when the initial frame length is 50%; when the period is 1000s, the PDR reaches the maximum when the initial frame length is 60%. This is because the number of nodes to be sent in the initial frame is higher than the number of nodes that are resent in the next frame due to transmission failure, so the initial frame length should be longer than 50% of the total period, and sufficient length should be left to complete the transmission of the remaining nodes. Generally, the PDR is higher when the initial frame length accounts for 50%-70% of the total period.

Conclusion
This paper describes the LoRaWAN technology in detail, and analyzes the shortcomings of the current LoRaWAN network in collision processing, and then proposes to combine the dynamic frame-slotted ALOHA anti-collision algorithm with LoRaWAN by adapting the algorithm through preamble detection technology. Next, use the Chebyshev estimation method to calculate the optimal frame length of the next frame. Then the paper studies the dynamic frame ratio in depth. The simulation test on ns-3 shows that the PDR of LoRaWAN can be improved by about 9%, the system efficiency can be improved by about 7%, and the preferred initial frame ratio is 50%-70%. It can be seen that the algorithm can improve the reliability of LoRaWAN and the overall performance of the system, and has certain significance to the development LoRaWAN communication technology.