## 4 Mobility Model of the MS
### Optimization Method
Equation (10) becomes as follows:

\[d_{k}=\frac{\left|x_{CM_{k}}-m_{ij}^{-1}y_{CM_{k}}+m_{ij}^{-1}b_{ij}\right|}{ \sqrt{1^{2}+\left(-m_{ij}^{-1}\right)^{2}}} \tag{15}\]

\(d_{k}\) in Equation (15) represents the distance between a \(CM_{k}\) and the trajectory line of the MS.

(3) The closest CM to the MS's trajectory is HN

The CH searches the closest CM to the trajectory line and on the same direction of the MS path. CH selects this CM to be the HN by sending the SELECTING_PACKET, then routes the data to the selected HN in the case of MS leaves the communication area before sending all data stored in the buffer (Figure 6). #### 5.2.2 The Layered Architecture of CLR-MSPH

In this part, we show the layered architecture used in our proposed protocol CLR-MSPH. Figure 7 illustrates the different layers involved and cooperated in each kind of node in the Cluster-based wireless sensor network. We involve the network layer to provide efficient mobility support for our proposed CLR-MSPH because we believe that this layer handles the mobility better than other layers. The main reason to involve the network layer is that this layer uses the information coming from the mobility manager to estimate and predict the appropriate node for performing the handover and routing the data. Figure 6: Selecting the closest CM to the trajectory of the sink. Figure 7: Involved layers in CLR-MSPH. (**a**) The layered architecture of the MS; (**b**) The layered architecture of a CH; (**c**) Layered architecture of an HN. Mobility management allows the network layer to get information about localization, which is used for calculating distances. Figure 7a shows the interactions of layers in the MS, the network layer sends a direct control message to mobility management to request the current destination and the next destination with their coordinates. The network layer uses this information coming from mobility management to encapsulate it in the ALLOW_SENDING packet. MS sends this packet to current CH (current destination) in order to make this CH start sending data and predicts the HN. Figure 7b illustrates the layers involved in the CH. As we mentioned before, the network layer handles the mobility better than other layers. The communication between this layer and the mobility management is used to estimate and calculate the HN. For making the handover perform efficiently and for better knowledge about the network, we also make MAC layer, and network layer cooperate. The network layer informs the MAC layer that the type of this node is CH by sending a control message to the MAC layer in order to make this node interacts in the case of handover mechanism. When an ACK frame is received at the MAC layer of a CH with a RSSI value less or equal to the RSSI threshold, the MAC layer sends a control message to network layer to inform it that the RSSI reaches the threshold. Depending on this control message, the network layer changes the destination of packets from the sink address to the preselected HN address to handover the remaining data. Figure 7c shows the layered architecture of the HN. The network layer and MAC layer also cooperate for better handover. CH selects a node as HN by sending SELECTING_PACKET which is created at the network layer of CH, and it is received at the network layer of the receiving node (HN) to inform it that it is selected as HN. In the case where an ACK frame is received from MS with RSSI value less or equal to the threshold, the MAC layer sends a control message to the network layer to get permission to process the handover mechanism at the MAC layer of the HN (process the similar handover of BMAC-H). Once the MAC layer gets the information and the permission to process handover, HN creates at the MAC layer a HANDOVER_REQUEST frame and broadcasts it, and then it waits for HANDOVER_RESPONSE from other nodes. #### 5.2.3 Collision Problem

Collision problems are a common issue is wireless communications. This problem is caused by the simultaneous sending of packets from source nodes to the same destination node.