# An On-Demand Scheduling-Based MAC Protocol for UW-WiFi Networks
## 4 Design of SDDA MAC Protocol
### The Periodic Regular Reservation Phase  
The reservation phase is the beginning of each round. The abovementioned initial reservation phase is only a special case at the network initialization. The only difference between the periodic regular reservation phase and the initial reservation phase is the scheduling scheme of \(RE\) packets. In the initial reservation phase, as the result of the propagation delay of each terminal node being unknown, the maximum propagation delay is adopted when calculating the transmission moment per \(RE\) packet by way of forestalling conflicts as much as possible. Nevertheless, in the periodic regular reservation phase, the propagation delay is known for static terminal nodes at present. Therefore, in order to minimize the spare waiting time of each static node, the calculation method of static nodes' \(RE\) packets transmission moment is the same as that of data packets transmission moment. We assume that the first \(k\) nodes are static nodes and the rest are dynamic nodes in the UW-WiFi network, and that the ascending order of static nodes' propagation delays is \(pd_{i}<pd_{i+1},i\in[1,k-1]\). Then the \(RE\) packet transmission moment of the first static node is (i.e., the waiting time before sending the \(RE\) packet):  
\[wd_{tx\_RE\_1}=pd_{max}-pd_{1}, \tag{5}\]  
where the meaning of \(wd_{tx\_RE\_1}\) is in common with \(wd_{tx\_RE\_i}\) in the initial reservation phase. Additionally, then \(RE\) packets transmission moment of the rest static nodes is:  
\[wd_{tx\_RE\_i}=wd_{tx\_RE\_i-1}+td_{RE}+t_{g}+2(pd_{i-1}-pd_{i}),\;1<i<k+1. \tag{6}\]  
However, the propagation delay of dynamic nodes is constantly changing. Therefore, for preventing \(RE\) packets of dynamic nodes from conflicting, we still use the maximum propagation delay, and the transmission moment of each dynamic node's \(RE\) packet is as follows. From the above, the \(RE\) transmission moment of the first dynamic node (i.e., _node \((k+1)\)_) is:  
\[wd_{tx\_RE\_(k+1)}=wd_{tx\_RE\_k}+pd_{k}+td_{RE}. \tag{7}\]  
Additionally, then \(RE\) packets transmission moment of the rest dynamic nodes is:  
\[wd_{tx\_RE\_i}=wd_{tx\_RE\_(i-1)}+pd_{max}+td_{RE},\;k+1<i\leq n. \tag{8}\]  
The pseudo code of this phase is detailed in Algorithm 4.  
```
1. define an array of structures \(pd\_array\_re[k]\), \(k\) is the number of static nodes, storing the node ID and its propagation delay.
2. sort \(pd\_array\_re[k]\) in ascending order according to \(pd\_array\_re[i].pd\)
3. calculate the \(RE\) transmitting moment of the first static node \((pd\_array\_re[0].ID)\), \(wd_{tx\_RE\_(pd\_array\_re[0].ID)}=pd_{max}-pd\_array\_re[0].pd\)
4. **for each** index \(i\), \(0<i<k\), do
5. calculate the \(RE\) transmitting moment of the rest static nodes, \(wd_{tx\_RE\_(pd\_array\_re[i].ID)}=2 pd\_array\_re[i-1].pd+wd_{tx\_RE\_(pd\_array\_re[i-1].ID)}+td_{RE}+t_{g}-2 pd\_array\_re[i].pd\)
6. **end for**
7. calculate the \(RE\) transmission moment of the first dynamic node \((k+1)\), \(wd_{tx\_RE\_(pd\_array\_re[k-1].ID)}+pd\_array\_re[k-1].pd+td_{RE}\)
8. **for each** dynamic node \(j\), \((k+1)<j<(n+1)\), do
9. calculate the \(RE\) transmitting moment of the rest dynamic nodes, \(wd_{tx\_RE\_}=wd_{tx\_RE\_(j-1)}+pd_{max}+td_{RE}\)
10. **end for**
11. write each \(RE\)'s transmitting moment information into \(TR\)
12. record \(t_{send\_TR}\) and broadcast \(TR\)
13. switch from the sending \(TR\) state to the waiting \(RE\) state
14. start the waiting \(RE\) time, the duration of this timer is \(D_{w\_RE}=td_{TR}+2 pd_{max}+wd_{tx\_RE\_n}+td_{RE}\)
15. if \(D_{w\_RE}\) doesn't expire, then
16. receive \(RE\), record \(t_{rec\_RE\_,i}\), and \(td_{data\_,i}\) \(T_{DATA}+=td_{data\_,i}\), \(T_{DATA}\) is the transmission delay of all data packets from all terminal nodes.
17. **else if** the number of \(RE\) packets received > 0, then
18. switch from the waiting \(RE\) state to the sending \(TS\) state
19. **else**
20. go to the step of Line 12
21. **end if**
```  
**Algorithm 4** The Periodic Regular Reservation Phase.