# An On-Demand Scheduling-Based MAC Protocol for UW-WiFi Networks
## 4 Design of SDDA MAC Protocol
### The Time Sequence Scheduling Phase  
This phase mainly settles the efficient scheduling problem of data transmission for each node on the basis of \(td_{data\_i}\) and the propagation delay (from BS to terminal nodes, denoted as \(pd_{i}\)). The equation of computing \(pd_{i}\) is:  
\[pd_{i}=(t_{rec\_RE\_i}-t_{send\_TR}-wd_{tx\_RE\_i}-td_{TR}-td_{RE})/2. \tag{2}\]  
For the purpose of precluding data packets from colliding and enhancing the channel utilization as far as possible, we sort propagation delays of all terminal nodes in ascending order at first. Suppose the ascending sequence of these propagation delays is \(pd_{i}<pd_{i+1},i\in[1,n-1]\), where \(n\) is the number of all terminal nodes. Then the data sending order of all terminal nodes is _node \(1\), node \(2\), \(\cdots\), node \(n-1\), node \(n\)_. From the above, the waiting time of the first node before starting data transmission is:  
\[wd_{tx\_DATA\_1}=pd_{n}-pd_{1}. \tag{3}\]  
Figure 3: Frame formats for various packets.  
That is, \(wd_{tx\_DATA\_1}\) is waiting duration for _node_ 1 from receiving \(TS\) to beginning delivering data. In that way, the waiting duration for _node_ \(i\) can be expressed as below:  
\[wd_{tx\_DATA\_i}=wd_{tx\_data\_i-1}+td_{data\_i-1}+t_{g}+2(pd_{i-1}-pd_{i}), \tag{4}\]  
where \(t_{g}\) is the guard interval for BS between the end of receiving data from _node_ \(n-1\) and the start of receiving data from _node_ \(n\). Afterwards, \(wd_{tx\_DATA\_i}\) is added into the \(TS\) packet, whose specification is exhibited in Figure 3, where _node_num_send_ is the number of those terminal nodes having data to send, and \(data\_tx\_waitTime\) means \(wd_{tx\_DATA\_i}\). After that, BS broadcasts the \(TS\) packet. This on-demand scheduling design reasonably allocates channel according to the data amount of each terminal node, without wasting channel resources, thus maximizing channel utilization. The pseudo code of this phase is revealed as Algorithm 2.  
```
1.for each node ID \(i\), \(1\leq i\leq n\), \(n\) is the number of terminal nodes, do
2. calculate the propagation delay of each terminal node according to \(t_{rec\_RE\_i}andt_{send\_TR}\), \(pd_{i}=(t_{rec\_RE\_i}-t_{send\_TR}-wd_{tx\_RE\_i}-td_{TR}-td_{RE})/2\)
3.endfor
4. define an array of structures \(pd\_array[n\_s]\), \(n\_s\) is the number of terminal nodes to send data, storing the node ID and its propagation delay.
5. sort \(pd\_array[n\_s]\) in ascending order according to \(pd\_array[i].pd\)
6. calculate the data transmitting time of the first terminal node (\(pd\_array[0].ID\)), \(wd_{tx\_DATA\_(pd\_array[0].ID)}=pd\_array[n\_s-1].pd-pd\_array[0].pd\)
7.for each index \(i\), \(0<i<n\_s\),do
8. calculate the data transmitting time of the rest terminal nodes, \(wd_{tx\_DATA\_(pd\_array[i].ID)}=2 pd\_array[i-1].pd+wd_{tx\_DATA\_(pd\_array[i-1].ID)}+td_{data\_ (pd\_array[i-1].ID)}+t_{g}-2 pd\_array[i].pd\)
9.endfor
10. add each node's data transmitting time information into \(TS\)
11. broadcast \(TS\)
12. switch from the sending \(TS\) state to the waiting data state
13. start the waiting data timer, the duration of this timer is \(D_{w\_DATA}=pd\_array[n\_s-1].pd+pd\_array[0].pd+T_{DATA}+(n\_s-1)t_{g}+td_{TS}\)
```  
**Algorithm 2** The Time Sequence Scheduling Phase.