# An Efficient Adaptive Data-Link-Layer Architecture for LoRa Networks
## 4 Data Link Layer Design
### MAC Protocol  
This section describes the implemented medium access control (MAC) protocol, which controls the insertion of end nodes into the star LoRa network controlled by a given packet forwarder, defines the uplink data transmission time from each end node to the packet forwarder, and provides the transmission of downlink acknowledgments (ACKs) that allow the end nodes to adapt their SF and transmission power dynamically (according to the ADL mechanism described in the next section). Most of the energy required by a wireless node is consumed by its MAC protocol [22], so its optimization is fundamental. This energy consumption is high when the node is in the active mode (either transmitting, receiving or idle) and very low in the sleep mode; therefore, the MAC protocol should ensure that the node stays in active mode only for short periods. Figure 5: LoRa parameter calculator flowchart. The main potential sources of energy waste in a MAC protocol are collisions, protocol overhead, and idle listening. A collision is a superposition (either total or partial) of the transmissions of different nodes. In this case, the energy is wasted because the receiver normally is unable to decode the packets, resulting in packet loss. The distributed ALOHA protocol has low overhead but is very vulnerable to collisions. Distributed contention-based MAC protocols, such as carrier sense multiple access (CSMA), are less vulnerable to collisions but at the cost of higher protocol overhead (carrier sense and random bakeoff periods), and they are not able to avoid all collisions. On the other hand, the proposed centralized reservation-based MAC protocol is collision-free since each slot is reserved to a single end node. It also has low protocol overhead, since it does not perform carrier sense or backoffs. With this protocol, after the initial slot allocation, an end node only needs to wake up periodically to sample its sensors, transmit its data packet and, sporadically (as explained in the next section), receive an ACK packet, which means that it can sleep the rest of the time to save energy. The third main source of energy waste, idle listening, occurs when a node stays active waiting to receive data packets destined for it. This may be the case, for example, when some end nodes are actuator nodes instead of sensor nodes. In this case, with conventional ALOHA or CSMA protocols, the node would need to be active all the time waiting for new data, whereas with our MAC protocol, the node would only need to be active during its slot at the superframe, sleeping the rest of the time. As referred above, most of the energy of an end node is spent when the node is in active mode. Since the proposed MAC protocol minimizes the protocol overhead and eliminates collisions and idle listening, the active mode is used almost exclusively for the transmission of data packets during the steady-state operation of the end node, which means that its energy consumption becomes proportional to the ToA. The proposed MAC protocol is divided into two key parts: slot allocation and data transmission. The first part starts with an allocation request from the end node, which is followed by an allocation response from the packet forwarder. After that, the node may send data periodically at the start of its allocated slot in every superframe. The superframe period (\(T_{s}\)) of the MAC protocol is set by the network administrator taking into account the requirements of the application. With homogeneous end nodes, it corresponds to the data transmission interval required by the end nodes, whereas with heterogeneous nodes it can be set to the minimum data transmission interval required among all end nodes, and those with less demanding timing requirements may use their allocated slots only when necessary. Considering that each node sends data at a predefined slot of the superframe, by limiting the number of nodes per LoRa network, a suitable scheduling can be defined.