A Scalable and Energy-Efficient MAC Protocol for Linear Sensor Networks

Linear topologies arise naturally in the context of Internet-of-Things (IoT) applications for smart cities, where the infrastructure itself commonly has a linear or semi-linear structure. This is the case of buildings, public transportation systems, road infrastructure, and utility distribution networks. Given the prevalence of this type of topologies, several Medium Access Control (MAC) protocols have been designed to take advantage of their particular properties. Unfortunately, most of them do not scale well as the node density and the distance in hops to the sink increases. The result is that packets generated many hops away from the sink tend to experience unacceptable high end-to-end delay and low delivery probabilities. This paper introduces HP-MAC, a synchronized duty-cycled MAC protocol for Linear Sensor Networks (LSNs) that assigns transmission priorities to nodes to avoid collisions, through the implementation of distributed elections based on hash functions. HP-MAC also implements a packet queuing scheme that acts as a mechanism to control the amount of network resources allocated to data flows generated at different distances to the sink. This way, packets can reach their destination with loss probability and end-to-end delay that do not depend on their distance to the sink. We use a Discrete-Time Markov Chain (DTMC) to model the performance of the proposed protocol. Numerical solutions of this model show that HP-MAC outperforms state-of-the-art representatives in terms of throughput, end-to-end delay, power consumption, and packet loss probability. These results are validated through extensive discrete-event simulations.


I. INTRODUCTION
The development of smart-city applications requires an infrastructure that physically and virtually interacts with various devices such as sensors and actuators [1]- [3]. In this regard, the Internet of Things (IoT) has become a fundamental technology because, through the use of wireless links, IoT devices can communicate with each other and with the Cloud to implement coordinated operations that provide advanced monitoring and control services [4], [5].
Given the particular characteristics of the urban infrastructure, smart-city applications often require the deployment of Wireless Sensor Networks (WSNs) along linear or semi-linear structures such as utility distribution networks, The associate editor coordinating the review of this manuscript and approving it for publication was Rashid Mehmood . road networks, public transportation systems, and buildings. For instance, in the case of applications for smart mobility and intelligent transportation systems, the road infrastructure is sensed to coordinate urban transport or to manage vehicular traffic [6]. In intelligent utility distribution networks, the infrastructure is sensed to detect leaks or measure user consumption [1]- [3], [7]- [9]. In these scenarios, where the coverage area or the infrastructure itself is linear, the WSNs deployed along with these structures also exhibit a linear topology. These Linear Sensor Networks (LSN) collect information that is transported hop-by-hop to sink nodes that are typically located at one end of the network [10]. Although some variables in these scenarios could be monitored with mobile nodes, there are a lot of phenomena where fixed nodes are an excellent option to this end, hence, this work is focused on LSN's with static nodes.
As is usually the case in WSNs, energy-efficiency is an important design aspect in LSN because it may impact the network lifetime [10], particularly if sensor nodes do not have access to a continuous power supply [9]. Moreover, several authors have identified that MAC protocols play a significant role in this regard [3], [11]- [13]. The designers of LSN have taken advantage of the linear topology of these networks to propose energy-efficient MAC protocols based on Duty-Cycled, Pipelined-Forwarding (DCPF). In DCPF protocols, nodes are organized into grades depending on their distance in hops to the sink. Nodes in the same grade share the same duty cycle, and the pipeline is defined so that nodes in a given grade are in receiving state only when the nodes in the next grade are in transmitting state (see Figure 2). Energy-efficiency comes as a result of reducing idle listening and overhearing periods attained by this synchronized duty cycle [16], [18]- [22]. Unfortunately, as the Related Work Section shows, most previous proposals rely on traditional contention mechanisms that tend to create bottlenecks near the sink, limiting network throughput. Moreover, most MAC protocols for LSNs proposed up to date do not scale well as the distance in hops to the sink increases. Packets generated many hops away from the sink tend to experience unacceptable high end-to-end delays and low delivery probabilities.
As a solution to the contention problem, the authors of [22], [24], [25], [28] have proposed protocols based on hash functions to provide collision-free communications. Even though these collision-free proposals effectively increase the network throughput, they still suffer from reduced performance as the distance in hops to the sink increases. This problem arises because packets from remote nodes are queued in many buffers along the network, competing for transmission at each hop against locally generated packets. As a result, these packets exhibit unacceptable loss probability and endto-end delay levels. To address this problem, some authors (e.g., [29], [30]) have proposed prioritizing packets based on the number of hops required to reach the sink or the packet's deadline. Other authors take the more traditional approach of prioritizing packets by the type of service (e.g., real-time versus elastic) [31]- [33] and do not consider the distance that the packets have to traverse to reach the sink.
This paper presents the Hash-based with Packet prioritization MAC protocol (HP-MAC), a synchronized DCPF protocol particularly suited for Linear Sensor Networks (LSNs). HP-MAC implements distributed elections based on hash functions that assign transmission priorities to nodes in one grade to avoid collisions. HP-MAC also implements a packet queuing scheme that acts as a mechanism to control the amount of network resources assigned to data flows from different grades. This way, even packets generated many hops away from the sink experience high delivery probability and reduced end-to-end delay. Moreover, HP-MAC achieves these features without increasing the signaling overhead or requiring additional synchronization. An analytical model based on a Discrete-Time Markov Chain (DTMC) shows that these characteristics of the proposed protocol increase the LSN capacity while reducing energy consumption and end-to-end delay. All the results provided by our analytical method were validated through extensive discrete-event simulations of the system. The rest of the paper is organized as follows. In Section II we review a representative sample of related work. Then, in Section III, we describe how our protocol works. Based on this description, in Section IV we present the DTMC that models the system. In Section V we derive expressions for the LSN performance parameters. Lastly, we discuss relevant numerical results and present our conclusions in Sections VII and VIII, respectively.

II. RELATED WORK
In [14], W. Ye, et al. represented S-MAC, a Synchronized Duty-Cycled (SDC) MAC protocol for WSN's that has become highly influential in the design of subsequent proposals because of its energy efficiency and simplicity. In addition, Yang, et al. developed a Markov queueing model to analyze SDC-MAC protocols with applications to S-MAC [15]. Based on these works, Tong, et al. introduced the Pipelined Forwarding (PF) feature to SDC protocols by designing a protocol known as DCPF, particularly suited for LSN's [16]. These authors evaluated the DCPF performance in terms of throughput, active time ratio per cycle, and packet delivery latency through a Markov chain model.
Many SDC-MAC protocols for LSNs have been proposed in recent years (e.g., [17]- [21], [23]). These proposals take advantage of the assumption of having a linear or semi-linear topology to provide energy-efficient communications. Unfortunately, most of these protocols still rely on traditional contention mechanisms, which makes them suffer from reduced network capacity and high packet loss probabilities due to packet collisions, particularly under high-node density conditions. Another common property of these proposals is that they usually do not include mechanisms to prioritize packets from remote nodes causing them to suffer from excessive endto-end delay.
To ameliorate the negative impact of contention, some authors have proposed collision-free MAC protocols [22], [24]- [28]. In particular, those based on hash functions have proved to be very effective. Some other authors have proposed mechanisms to reduce the end-to-end delay of specific packets by using multiple techniques to differentiate priorities [29]- [36]. However, except for [22], none of these proposals were designed for LSN.
We provide brief reviews of the works mentioned above in the remainder of this section. node; hence, the network performance can be improved on the premise of not harming its lifetime.
In [18], F. Tong et al. presented an interference analysis of the DCPF protocol (presented in [16]) that provides the distribution of the Signal-to-Interference-plus-Noise Ratio (SINR), as well as the network capacity attained by the protocol.
In [19], Zhang et al. presented the Redundancy DCPF (RDCPF) protocol. This proposal incorporates redundant nodes to reduce the traffic bottlenecks and the excessive energy consumption experienced by nodes located near the sink. Their results show that RDCPF outperforms the existing DCPF protocols in terms of packet delivery latency, average power consumption, network survival time, and energy usage efficiency.
SA-MAC is another DCPF-based protocol [21] where nodes selectively awake depending on the network node density, traffic load conditions, and the state of the nodes' buffers. An analytical model shows that SA-MAC significantly reduces the nodes' energy consumption compared to previous DCPF protocols, particularly under high traffic loads.
In [23], Acosta et al. also analyze a WSN with linear topology. They propose an algorithm based on implicit ACK messages. A transmitting node acknowledges that its packet has been received when it listens that the intended receiver transmits the same packet towards the sink. According to the authors, this scheme achieves better energy consumption and end-to-end delay than protocols with explicit confirmations.

B. COLLISION-FREE MAC PROTOCOLS
In [24], Rajendran et al. propose TRAMA, a scheme composed of an access protocol, a schedule exchange protocol, and an adaptive election algorithm. To avoid collisions, TRAMA implements distributed elections where each node determines transmission priorities for the nodes contending for the channel. TRAMA achieves higher throughput than contention-based protocols, it is well suited for applications that require high delivery guarantees and energy efficiency, but it is limited in delay-sensitive scenarios.
In [25], Camacho-Escoto et al. proposed TEMA, a MAC protocol where, similarly to TRAMA, nodes use a dynamic set of tickets to contend for interference-free access to the channel. TEMA achieves energy efficiency by opportunistically setting the nodes' radios in sleeping mode when nodes lose the election and infer that they are not the intended receivers of the winner. Similar to TRAMA, TEMA does not provide a mechanism to control the end-to-end experienced by packets generated by sources located many hops away from their corresponding destinations.
Villordo-Jimenez et al. [22] presented H-MAC, a MAC protocol specifically designed for LSN that combines the advantages of pipelined scheduling and collision-free channel access based on hash functions. Numerical results show that H-MAC outperforms previous proposals for LSN's in terms of throughput, energy consumption, and delay; however, these results were obtained only through simulations, and no mathematical analysis is presented.
The protocols presented in [26], [27] are examples of recent collision-free MAC protocols that are not based on hash functions. In [26] Alfouzan et al. propose GC-MAC, a collision-free reservation-based MAC protocol for underwater WSN. GC-MAC is based on TDMA and assigns separate time-slots to every sensor node in every two-hop neighborhood. This way, GC-MAC avoids collisions and increases the throughput and energy efficiency compared to contention-based protocols. On the other hand, in [27], Movva and Rao propose a ring-partitioned-based MAC (RP-MAC) protocol to implement an energy-efficient WSN with a mobile sink node. RP-MAC schedules transmissions among adjacent nodes, achieving collision-free data transmission in the network. Like most of the works summarized in this sub-section, GC-MAC and RP-MAC were not designed to operate in LSN.

C. MAC PROTOCOLS WITH PACKET PRIORITIZATION
Recent proposals have addressed the problem of reducing the end-to-end delay experienced by nodes located many hops away from the sink by prioritizing particular packets. In [29], Farhan et al. propose a scheduling algorithm called Long Hop (LH), where packets from remote nodes are prioritized in a queue. Since this strategy reduces remote retransmissions, the overall system performance is improved. Argoubi et al. address a similar problem in [30], but they take into consideration the packet deadline (which depends on the kind of service) to determine their priority in a single queue.
Other proposals employ multiple priority queues (e.g., [31]- [33]); however, the main objective of them is to provide different classes of services and do not consider the distance (in hops) between the source and the sink.
Lastly, some recent works have proposed various techniques to prioritize packets in terms of QoS. In [34], Sakib et al. propose a Timeout Multi-priority based MAC (TMPQ-MAC) protocol that, based on the load variations in the network, dynamically determine the nodes' active time. TMPQ-MAC considers four different packet priorities to reduce delay. In [35], Muzakkari, et al. present an energyefficient and QoS-aware (EEQ) MAC protocol that has an adaptive duty cycle in terms of queue size and packet priority. The authors show that they can improve energy efficiency and extend the lifespan of the WSN. In [36], Thu-Hang, et al. also propose a protocol with differentiated QoS which is based on Carrier Sense Multiple Access p-persistent MAC protocol. Specifically, they propose using different p values for different priority levels. Higher priority packets are more likely to access the shared medium and experience better QoS in terms of delay and reliability.
Unlike these works, we propose using multiple queues to classify packets in terms of their grade of origin. Our strategy is particularly suited for LSN, and our goal is to reduce the delay of packets generated at remote nodes by assigning higher priorities to their queues.

III. HP-MAC PROTOCOL
In this section, we present the characteristics of the LSN under consideration, as well as an overview of the general functioning of the Hash-based with Packet prioritization MAC protocol (HP-MAC) (Section III-A). Then, in Section III-B we describe the use of a strongly 2-universal family of hash functions to avoid collisions among nodes contending for accessing the channel.

A. PROTOCOL OVERVIEW AND CHANNEL STRUCTURE
We assume an LSN with static nodes that are classified into grades according to their corresponding distance in hops to the sink node. Accordingly, we define the grade i as the set of nodes located i hops away from the sink. (see Fig. 1). Similar to previous proposals [16], [21], we assume that nodes acquire information about the constituency of their corresponding grade during an initialization stage. Nodes in the same grade share the same transmitting slot, and hence, they have to contend for the channel.
We assume that all the nodes in the network (except the sink) can locally generate sensory packets and relay packets received from their immediate superior grade.
In the LNS, data packets are disseminated hop-by-hop from nodes at consecutive grades until they reach the sink node. More specifically, packets generated by a node at grade i are forwarded to a node at grade i−1, then to a node in grade i − 2 until reaching the sink node. We consider that nodes identify intended receivers in the following grade towards the sink during the initialization stage, hence, we consider unicast transmissions.
As shown in Fig. 1, HP-MAC nodes are equipped with two independent data queues, a local buffer that is used for queuing locally-generated sensory data and a relay buffer that is used for queuing data packets received from nodes in superior grades. These queues are First-Come First-Served (FCFS), and their length equals K packets.Note that even though a node at grade i only receives packets from nodes in the immediate superior grade (i + 1), as a result of the hop-by-hop transmissions, their relay buffers can store packets generated at grades larger than (i + 1). When a node has packets in both buffers, it selects for transmission a packet from the relay buffer with probability p rel or from the local buffer with probability p loc = 1 − p rel . The value of p rel is chosen to control the priority that relayed packets have over locally-generated ones. If only one buffer has packets, it will be automatically served. To save energy, only nodes with packets-to-send awake during transmitting slots, and nodes with saturated relay buffers do not awake during receiving slots.
We assume that nodes have a single radio that can either be in a sleeping state, a transmitting state, or a receiving state. We are considering a synchronized duty-cycled protocol where nodes share a single wireless channel that is time-slotted and organized into a frame consisting of a fixed number of time slots. As we show in Fig. 2, this frame is composed of a single receiving slot, a single transmitting slot, and a sequence of ξ consecutive sleeping slots.
As we also show in Fig. 2, the frame for nodes in grade i is delayed by exactly one slot in relation to the frame of nodes in grade i + 1. This way, whenever the nodes in grade i are in a transmitting slot, the nodes in the grade i−1 (their potential intended receivers) are in a receiving slot, and, as a result, the delay experienced by a packet traversing from one grade to the next may be as short as one slot. This technique is known as pipeline scheduling [16].
According to the previous information, the cycle duration T c , can be expressed as where T is the slot duration and ξ must be larger than 1 to avoid interference between adjacent grades. Furthermore, notice that the maximum network throughput is 1 T c packets/s, since only one packet can be transmitted between two adjacent grades during one slot.
As also shown in Fig. 2, a slot initiates with a DCF interframe space (DIFS) followed by N minislots of σ seconds, where N is the number of nodes per grade. As explained in Section III-B, these minislots are used by the protocol to identify the winner of the distributed election, namely, the node that will send data during the current slot. Then, the sender (a node in grade i) and its intended receiver (a node in grade i − 1) engage in an RTS-CTS-DATA-ACK exchange. The proposed slot structure includes three Short Interframe Spaces (SIFSs) because both nodes require a SIFS to process their received messages before sending their corresponding replies.
According to the previous description, the slot duration can be expressed as where τ msg is given by and τ difs , τ rts , τ cts , τ data , τ ack and τ sifs are the duration of the messages and time intervals to implement the handshake and the data transmission. In addition to the initialization stage, the sink node must periodically transmit special frames to maintain synchronization, detect node failures, and re-establish sender-receiver links (in case of node failure). 1 We point the reader to [14], and [20] for detailed descriptions of how to implement some of these functions. However, since the sink node sends these special frames in a time scale much larger than the frame duration, their effects are omitted in the proposed analytical model.

B. HASH-BASED MAC PROTOCOL
In HP-MAC, accessing the channel during transmission slots is based on a distributed election. At the beginning of the slot, every awake node in grade i generates a set of N priority tickets, i.e., one ticket for every node in its grade. The value of a given ticket represents that node's priority for accessing the channel. The node with the largest ticket value has the highest priority to transmit.
The value of every ticket is calculated using a hash function from a strongly 2-universal family, which is given by where k ∈ [0, N − 1] is a unique node identifier, p is a prime number that satisfies p ≥ N , and a n , b n ∈ [0, p − 1] are pseudo-random numbers drawn from a uniform distribution [37]. Nodes use a monotonically increasing transmission slot number as the seed for generating the values of a n and b n at each transmission slot. This way, the priority computed by (4) also changes on a per transmission slot basis. Since all the nodes know the current slot number, they compute the same set of tickets in a specific slot, without the need for additional signaling in comparison to traditional contentionbased protocols.
Note that the slot-number counter can wrap around, hence, the nodes cyclically generate the same sequence of priority tickets; however, this do not interfer with the correct network operation because the typical network lifetime is much smaller than the wraparound time. For instance, with a 32-bit counter and the values used in the numerical evaluation, the wraparound time is in the order of decades.
Before accessing the channel, the node with the j-th priority listens to the channel for j − 1 mini-slots. If, during that time, it receives an RTS message from a node with higher priority, it goes to the sleeping state (see Fig. 2). Otherwise, the node transmits its own RTS message to indicate to the remaining nodes that it has a packet to send. Then, this node and its intended receiver engage in a CTS-DATA-ACK exchange. After that, sender and receiver go to the sleeping state for the remaining duration of the slot. The length of this latter sleeping period varies because the length of the listening period also varies.
Despite the simplicity of (4), it has the following desirable properties [25], [38], [39]: • There are no collisions because the input of the hash function depends on unique node identifiers and the current transmission slot number.
• Since the hash function is a dispersion hash function, it generates any permutation of the tickets with the same probability. As a result of the first property, our protocol is collisionfree without requiring additional signaling or synchronization. From the second property, all the participant nodes have the same probability of obtaining the highest (or any other specific) priority at each election.

IV. ANALYTICAL MODEL
In this section, we derive expressions for computing the probability of transmitting and receiving a packet in one cycle (Section IV-A), then, from these results, we propose a Markov chain to represent the state of the two buffers of a node (Section IV-B). Table 1 summarizes the notation used throughout the analysis.

A. TRANSMISSION AND RECEPTION PROBABILITIES
We first derive expressions for computing the probabilities of transmitting a packet from grade i and receiving a packet at grade i during a given cycle, which are denoted by p t (i) and p r (i), respectively. For simplicity, these probabilities are computed in terms of the probability p e,e (i) that both buffers of a particular node are empty at the beginning of a transmitting slot. As we explain later, by defining and solving a DTMC, we can compute p e,e (i).
Please remember that an awake node with the jth priority initiates its transmission only if the j−1 nodes with higher priorities have no packets in their buffers. In addition, note that the probability of obtaining the j-th position in the election is 1 N . As a result, the probability of transmitting, given that the j-th position was obtained, is 1 N p e,e (i) j−1 . By considering all the possible values of j, we obtain where p t (i) is conditioned on the existence of packets in any of the two node's buffers. Now, since the proposed contention mechanism is collision-free, and considering unicast transmissions, a node in grade i receives a packet with probability p r (i), given by We should notice that p r (i) does not model the buffer saturation in the receiving node.
In addition, the probability p b (i) of detecting a busy channel for an awake node is simply the complement of p t (i), hence, B. MARKOV CHAIN MODEL Since (5)- (7) are defined in terms of p e,e (i), in this Section we obtain this probability by modeling the node's buffers through a Discrete-Time Markov Chain (DTMC). Let m and u be the number of packets at the beginning of the transmitting slot, in the relay and local buffers, respectively. We consider that the maximum size of every buffer is K , therefore, m, u ∈ [0 : K ]. The chain states are represented by the duple (m, u), and the transition probability from state (m, u) to state (n, v) is denoted by P (n,v) (m,u) . Notice that this chain has to be solved for every grade i; however, we omitted i in the transition probabilities to simplify the notation. To define the possible transitions, we observe that: • n can not exceed m for more than a unit because only one packet can be received per cycle. The same is true for v and u, since only one packet can be locally generated during one cycle.
• If neither a transmission, a reception nor a new-packet generation occurs during a cycle, then n = m and v = u.
• If n = m − 1, then v = u, because only one packet can be transmitted per cycle. Analogously, if v = u − 1, then n = m. Additionally, we consider that a node locally generates a packet during a cycle with probability a. Considering this, we illustrate all possible transitions in Fig. 3, and define their probabilities in the following equations (8-49), where p t (i) and p r (i) are abbreviated as p t and p r , respectively: The steady-state probabilities of this chain are denoted by π m,u (i). Its solution is unique because the DTMC is irreducible and aperiodic. Note that according to (6), the solution for a given grade, except for i = I , depends on the solution of the immediate superior grade. Therefore, first, we solve for i = I , then we can solve for i = I − 1, and so on, until we find the solution for i = 1. Now, we observe that he probability of having no packets to transmit p e,e (i) = π 0,0 (i); therefore, p t (i) depends on the solution of (8-49), as it can be observed from (5). As a result of this relation between p e,e (i) and p t (i), the system of equations cannot be explicitly solved, and hence, we propose the following iterative numerical solution for each grade i [15], [16], [21]: 1) Calculate p t (i), according to (5), with an arbitrary initial value for p e,e (i). 2) Substitute p t (i) and p r (i) in (8)-(49) and solve the DTMC, for example, through the Gauss-Seidel method [40]. 3) Make p e,e (i) ← π 0,0 (i). 4) Repeat Steps 2 and 3 until p e,e (i) has converged according to certain criteria (e.g., mean squared error within a threshold value). 5) Compute p r (i − 1) according to (6), because it will be required to compute the solution for the next grade. As shown in the following section, we can obtain the network performance parameters by jointly solving (5)- (7) and (8)-(49).
To simplify the notation, we define π l k (i) and π r k (i) as the probabilities that a local and a relay buffer in grade i has k packets, respectively. These probabilities can be computed according to and π r k (i) = N u=0 π k,u (i).

V. PERFORMANCE ANALYSIS
In this section, we derive expressions for energy consumption (Sub-section V-A), throughput and packet-loss probability (Sub-section V-B) and, end-to-end delay (Sub-section V-C).

A. ENERGY CONSUMPTION
Let P tx , P rx and P sp be the average power consumption for a node in transmission, reception and sleeping mode, respectively. These parameters are commonly provided by the hardware manufacturers. In addition, let T tx (i), T rx (i) and T sp (i) be the expected time that a node in grade i spends in transmission, reception and sleeping mode, respectively, during one cycle. Therefore, the expected power consumption for a node in grade i can be calculated as First, to obtain T tx (i), we observe that in the transmitting slot, an awaken node listens to the channel until it detects the transmission of a higher-priority node or until it discovers that the channel is free for transmission; therefore, T tx (i) can be given by where W b (i) and W t (i) represent the expected number of minislots that a node spends before detecting that the channel is busy, or initiating its own transmission, respectively (see Fig. 2).
Since the transmission probability for an awaken node with priority k is p e,e (i) k Np t (i) , W t (i) can be calculated as which can also be expressed as To obtain W b (i), we observe that an awake node listens to a transmission in the k-th mini-slot if: (1) there are at least other k nodes with higher priority, (2) these nodes, with priorities 1 to k − 1 are sleeping, and (3) the node with the k-th priority has packets to transmit, hence, and this expression can be rewritten as On the other hand, to define T rx (i), we observe that a node awakes at the beginning of the reception slot only if its relay buffer is not saturated, which occurs with probability 1 − K j=0 π K ,j (i). If a transmission from the superior grade occurs, the nodes in the current grade are awake during the same time as their corresponding transmitting nodes, i.e., p r (i) σ W t (i + 1) + τ msg ; otherwise, they remain awake until the end of the N mini-slots (see Fig. 2). According to this, T rx (i) can be calculated as And the expected sleeping time per cycle can be calculated as By substituting (53), (58) and (59) in (52), we obtain the expected power consumption for a node in grade i. If we are interested in the expected power consumption per node in the LSN, we evaluate for 2 ≤ i ≤ I . Since we assume that the buffer in the sink node is infinite, for this special case the throughput is given by which equals the network throughput, S. Now, let p l (i) be the probability of losing a packet generated at grade i. This event occurs when the local buffer of the source node or a required relay buffer is saturated.
The rate at which packets are admitted in the local buffer is given by and the probability of admitting a packet in all the relay buffers required to reach the sink is given by 36704 VOLUME 10, 2022 As a result, the rate of packets generated at grade i that reach the sink is Since new packets are generated at grade i at rate Na Tc , p l (i) can be defined as Note that the previous analysis does not consider packet loss due to node failures. This effect can be incorporated into the model by introducing the probability of node failure in (61), (62) and (64).

C. END-TO-END DELAY
Let D i be the expected value of the end-to-end delay experienced by a packet generated at grade i. D i can be computed as the sum of the expected delays experienced at each buffer while traversing from source to sink; hence, it can be expressed as where D l i and D r i are the expected delays in the local and relay buffers in grade i, respectively.
To calculate D l i and D r i , we use the solution of the Markov chain (see Section IV) and Little's Theorem. According to this theorem, the average queue length equals the product of the arrival rate and the average queueing delay. In our scenario, new packets arrive at the local buffer at rate λ l i packets/s, and this rate is given by We can obtain the expected value of the buffer's length from the probability distribution; however, in our analysis, we know this distribution only at specific points, namely, at the beginning of the transmission slots given by π l k (i). Fortunately, between two of these points, the buffer length increases by one unit if a new packet arrives; decreases by one unit if a packet is transmitted; or does not change at all. Because exactly one arrival and one transmission occur per packet, we can determine D l i as follows. First, we use Little's Theorem to obtain the expected buffer's length while assuming that such a length is constant during every cycle. We denote this length by L * i and can be expressed as then, by combining this equation with (68), we obtain the associated delay as, Clearly, D * i does not exactly represent the actual expected delay in a local buffer because it does not include the delay between the arrival of a packet and the beginning of the next cycle whose expected value is T c 2 (see Fig. 4). Furthermore, D * i includes T c − T s units of exceeding delay after a packet transmission, i. e., the time between the end of the transmission slot and the beginning of the next cycle. Then, by including these observations in (71), we obtain To calculate D r i , we follow an analogous method. In this case, however, the arrival rate is proportional to p r (i) instead of a, and there is no delay between the packet arrival and the beginning of the transmission slot. Therefore, we obtain By substituting (71) and (72) in (67), we obtain the expected end-to-end packet delay.

VI. SIMULATION SETTINGS
We validated our analytical model through extensive discreteevent simulations in Matlab. These simulations were executed for 1 × 10 5 cycles for every set of input parameter values. In every cycle and node, we simulated the process of generating sensory packets and all components of the protocol frame, including idle times and protocol messages.
At the beginning of a transmission slot, the simulation generates priority tickets for every node in each grade (including those nodes with no packets to send). The node with the highest priority and packets-to-send (winning node) engages in a CTS-DATA-ACK exchange with its intended receiver while the remaining awake nodes go to sleep. If the winning node has packets in both buffers, it selects a packet with probability p rel from the relay buffer, and with probability VOLUME 10, 2022 1 − p rel from the local buffer; otherwise, it simply transmits a packet from the non-empty buffer.
Once this process is over, we update the statistics related to the packet transmission. Simultaneously, we simulate the reception slot for the next grade. In this case, we identify which nodes have non-saturated queues, execute their corresponding reception events, and update the statistics about the packet reception. We simulate the transmission/reception process between every couple of adjacent nodes, including the process between grade 1 and the sink node.
In parallel with the transmission/reception process, we simulate the data packet arrival process at each node where nodes generate a new packet per cycle with probability a.
In all the transmission/reception events, we consider an ideal channel.

VII. RESULTS AND DISCUSSION
In this section, we present numerical results that characterize the performance of our proposal and that of two representatives of state-of-the-art DCPF protocols, namely, PRI-MAC [16] and SA-MAC [21]. To validate our analytical results, we also evaluate the system through discrete-event simulations as described in Section VI. Table 2 presents the values of the network parameters. The value I = 7 was selected to show the non-homogeneous performance along the LSN topology while avoiding excessive computational load. In addition, the value K = 7 was selected to observe significant variations of both packet loss probability and end-to-end delay. For the remaining parameters, we use values that are commonly used in the literature [15], [16], [21], [22].
In our model, packet arrivals are characterized by the probability a of generating a packet during a cycle. From this probability, we can compute the arrival rate λ as λ = aT cycle , which allows us to compare the performance exhibited by our proposal against that of PRI-MAC and SA-MAC.
To obtain the numerical results, we solved the DTMC for grade I (with I = 7) using the Gauss-Seidel method for a relative error of 1e-4. At this point, the reception probability p r (I ) equals 0 because nodes at the last grade do not receive packets from other nodes. From this solution we can obtain the value of p r (I − 1), and then, solve the DTMC for grade I − 1. We continue with this strategy until solving the DTMC for grade 1. Figs. 5-8 present the results provided by the analytical model when we evaluate the effect of the probability p rel of selecting a packet from the relay buffer on the network performance. These figures also show the results of the simulationbased experiments for the same scenarios. As discussed in the following paragraphs, the results provided by these two methods are consistent.
From Fig. 5, we observe that p rel does not affect the network throughput because this probability is not related to the network capacity or the packet arrival rate. Moreover, this is true for all the evaluated values of N . On the other hand, N significantly affects the throughput because the cycle duration depends on it; i.e., the largest N , the largest the cycle duration, and, as a result, the smallest maximum network capacity (e.g., for N = 40, 1/Tc = 0.3546 packets/s). However, this is not the case for small values of N because the throughput is not limited by the network capacity but by the packet arrival rate. In this case, the analytical model and the simulation experiments yield practically the same results with deviations below 0.11%). Fig. 6 shows that the expected value of the power consumption (P tot ) is practically insensitive to p rel . This is because the time nodes spend awake (either receiving or transmitting) does not depend on p rel . On the other hand, the number of nodes that awake at the beginning of the transmission slot directly depends on N , hence, the largest N , the largest P tot , as we also observe in Fig. 6. Similar to the case of the throughput, our analytical model for P tot is consistent with the simulation results. In this case, the deviations are below 0.19%, except for N = 40 and p rel = 0.9 where the difference is approximately 2%.
In Fig. 7 we show the expected delay (D i ) as a function of the source grade (i) and the probability p rel . To highlight the impact of p rel over the network performance, for these experiments, we consider high node densities and high packet arrival rates. The figure shows that for small values of p rel (e.g., p rel = 0.7), the nodes that are close to the sink experience a superior performance than the remote nodes. The performance becomes more homogeneous by selecting a larger value of p rel (e.g., 0.75); however, excessively large values of p rel may significantly degrade the delay experienced 36706 VOLUME 10, 2022  by nodes close to the sink without improving the delay for remote nodes (e.g., 0.85). In this case, the differences between the analytical and simulated results are below 3%. These deviations result from small time variations (due to the variation of number of minislots required to access the channel in the link between grade 1 and the sink node) omitted from the analytical model for simplicity. These results indicate that the analytical model achieves a reasonable tradeoff between accuracy and simplicity. Fig. 8 shows the behavior of the packet loss probability (p lp ) as a function of p rel under high node density. For this set of parameters, we observe that the loss probability across the gades is insensitive to p rel . Similar to the previous metrics, the figure shows that analytical and simulated results are very similar. In general, the deviation is smaller than 2.7% with the exception of the results for grade 2, where the differences are 6.4% and 13.2%, for p rel = 0.75 and p rel = 0.8, respectively. These deviations occur at the closest grade to the curve's inflection point and, in any case, they do not significantly affect the evaluation of the network.
By comprehensively analyzing the results from Figs. 5-8, we observe that the end-to-end delay is the most sensitive metric to the probability of serving the relay buffer. Therefore, p rel should be selected to attain small end-to-end delays for the data packets generated from all the grades.  Figs. 9-13 present the results where we compare the performance attained by the proposed protocol against that of PRI-MAC [16] and SA-MAC [21]. We observe that HP-MAC outperforms the other protocols in terms of throughput, average power consumption, end-to-end delay, and packet loss probability. Fig. 9 shows that HP-MAC achieves better throughput as the node density increases, which is a consequence of avoiding contention hot-spots due to collisions and reducing the cycle duration by limiting the number of minislots to the number of nodes in the grade. The latter feature contrasts with previous proposals where the number of required minislots exceeds the number of nodes in a grade.
As we observe in Fig. 10, HP-MAC significantly reduces power consumption in comparison with PRI-MAC and SA-MAC. This reduction is achieved because HP-MAC nodes with a packet to send can go to sleep as soon as they receive a CTS from a higher priority ticket holder. However, these savings are reduced as the number of nodes per grade increases because more nodes wake up at the beginning of the transmission slots to determine if they can access the channel (because nodes with higher priority tickets did not wake up). Fig. 11 shows the average end-to-end delay attained by the different protocols under high packet arrival rate conditions. We observe that HP-MAC exhibits the best performance as it consistently achieves similar or lower delays than PRI-MAC and SA-MAC. This is particularly true for   the packets generated at the last grade, where HP-MAC achieves a reduction of more than half of the delay attained by SA-MAC. On the other hand, from Fig. 12 we can observe that HP-MAC also outperforms the other protocols under low packet arrival rate conditions. In this case, however, we must select a small value for p rel because there is no need to prioritize relay packets.
Lastly, in Fig. 13 we show the packet loss probability p lp experienced by packets generated at the different grades. These results show the performance gains attained by eliminating collisions, and hence, contention hot-spots near the sink. From the figure, we can observe that HP-MAC outperforms SA-MAC and PRI-MAC by reducing the probability of losing packets generated at the first grade by an order of magnitude and the probability of losing packets generated at the last grades by up to half. It is important to point out that these performance gains come at no cost in terms of extra signaling overhead because HP-MAC uses distributed elections based on hash functions to determine which node can access the channel in an interference-free fashion.

VIII. CONCLUSION
Despite the seeming simplicity of LSNs, these networks pose particular challenges to their designers. As discussed in the related work section, previous proposals do not scale well as the node density and network length (in number of grades) increases. The proposed analytical model and the simulationbased analysis show that without careful design, sensory data collected a few hops away from the sink experience unacceptably high end-to-end delays and rarely reach its destination. In practice, the differentiated performance experienced by nodes located at different grades is not acceptable since all sensory information is equally important.
In this paper, we presented HP-MAC, a MAC protocol specifically designed for the moderately long and dense LSNs found in IoT applications for smart cities. HP-MAC implements distributed elections based on hash functions to provide collision-free access to the channel without the need for additional control signaling or synchronization requirements. HP-MAC also implements a simple two-queue scheme that effectively assigns extra network resources to data flows generated hops away from the sink. Our simulation-based and analytical results show that, unlike previous proposals, HP-MAC provides adequate end-to-end delay and packet loss probability to nodes located at the last grades, even under high-traffic conditions. All these while reducing energy consumption. Our results show that HP-MAC outperforms representatives of the state-of-the-art in MAC protocols for LNS.
The Discrete-Time Markov Chain solution developed in our analytical model allowed us to derive closed-form expressions for the LSN performance parameters. In this regard, we would also like to highlight the novelty of the method that we developed to obtain the end-to-end delay, which is simpler and more accurate than previous proposals such as the ones presented at [16] and [21]. Moreover, our analytical model was validated by the very small deviations observed between its results and those obtained during the simulationbased experiments.
Future work includes extending our analyses to consider packet prioritization schemes where priorities depend on the packet lifetime and the buffer state. These schemes may further improve the end-to-end packet delay and energy consumption. In addition, we consider formulating the network design problem as a multi-objective optimization problem. In particular, we are interested in determining the right amount of resources assigned to each grade to simultaneously optimize energy consumption, loss probability, and end-to-end delay.