# Collision Avoidance Resource Allocation for LoRaWAN
## 4 LoRaWAN MAC Proposal  
We propose a resource allocation algorithm with the aim of reducing the number of collisions and therefore increasing network capacity. This solution, called Collision Avoidance Resource Allocation for LoRaWAN networks (CARA), allows end-devices to access the medium with minimal collisions. CARA is based on a distributed scheduling of channels and SFs at the LoRaWAN MAC layer of the end-devices. The Pure-ALOHA medium access protocol is still maintained as detailed in the LoRaWAN specification. The end-devices use this protocol to access the medium, therefore, every time a device has a pending packet to transmit, it will wait for a random amount of time, and, after this period of time, it will send the packet with a certain channel and SF without previously listening to the medium. Taking advantage of the orthogonality of the SFs, the channels \(\times\) SFs space is divided so each pair of values represents an independent \"resource block\". Different end-nodes can simultaneously transmit in different resource blocks without colliding. Taking into account that the ISM frequency band in Europe allows up to 8 LoRa 125 KHz channels configuration and there are 6 different spreading factors, there are a total of 48 orthogonal resource blocks \(RB_{j},j\in\{1,48\}\). Without loss of generality, we assume that the first 6 th resource blocks utilize the first channel and spreading factors from 7 to 12, the second 6 th RBs utilize the second channel and spreading factors from 7 to 12, and so on. Each node will divide the time in windows with a duration of \(T_{window}\). If node \(i\) transmits during the \(k\)-th window, that is, \(t\in\{t_{0}+k\times T_{window},t_{0}+(k+1)\times T_{window}\}\), it will utilize a specific resource block \(RB_{i,k}\). In order to compute which resource block (i.e., channel and spreading factor) has to be used for transmission, that is, \(RB_{i,k}\), the gateway associated to a set of motes will be responsible for assigning to node \(i\) (1) a set of eligible spreading factors \(\overline{SF_{i}}\) and (2) the initial resource block \(RB_{j_{i}}\) for a reference time \(t_{0}\). \(\overline{SF_{i}}=\{s_{i,7},...,s_{i,j},...s_{i,12}\}^{T}\) is a binary vector which represents the spreading factors available to a node \(i\), where \(s_{i,j}\in\{0,1\}\) indicates whether this particular spreading factor can be used or not. With these parameters, the resource block selected by node \(i\) in the \(k\)-th window (starting from \(t_{0}\)) is given by Equation (7). \[RB_{i,k}=RB_{\widehat{j}}\mid\widehat{j}=(j_{i}+k)\text{ mod }\left(8\times \Sigma_{l=7}^{12}s_{i,l}\right), \tag{7}\]  
where \(\widehat{j}\in\{1,8\times\Sigma_{l=7}^{12}s_{i,l}\}\), that is, only the available spreading factors (\(s_{i,\widehat{j}}=1\)) are considered. The procedure for assigning resource blocks to end-devices is shown in Figure 3. When a device wants to join a LoRaWAN network, it will send a \"Join-Request\" message to the gateway. For each new device that joins the network, the gateway reserves a row of the resource block matrix (depicted in Figure 4). The value of this matrix in the \(i\)-th row and the \(k\)-th column is \(RB_{j,k}\), that is, the resource block that node \(i\) will use in window \(k\), that is, \(RB_{matrix}=\left( \begin{array}{cccc}RB_{1,1}&-&RB_{1,k}&...&RB_{1,k}\\ RB_{2,1}&-&RB_{\widehat{k}}&...&RB_{k,k}\\ RB_{3,1}&-&RB_{\widehat{k}}&...&RB_{N,k}\\ \end{array} \right)\). The reserved row can be used by the device to compute the corresponding resource block for a specific window. To generate the row, the device only needs the initial resource block \(RB_{j_{i}}\) and the usable spreading factors \(\overline{SF_{i}}\). Both parameters are calculated by the gateway in order to uniformly distribute the devices among the different resource blocks, and are sent in the \"Join-Accept\" message.