# Cross-Layer-Aided Opportunistic Routing for Sparse Underwater Wireless Sensor Networks
## 4 CLOR Protocol
### Process of CLOR
#### 4.2.4 Adaptive Transmission Process  
After choosing an optimal forwarder from the candidate set, the sender executes burst transmission, as explained in Figure 2. First, the sender uses encode mask \(M_{cc}\) to filter out the invalid data packets in the data queue. Second, the sender estimates transmission redundancy by using forward link quality, and then, it calculates the number of coded packets. Third, the sender generates a random coding matrix and then executes random linear packet coding for these input packets. Lastly, the sender puts the output packets to the transmit queue. Generally, encode mask \(M_{cc}\) is the same with the data transmission mask \(M_{tx}\) in the negotiation process and can be represented as below. \[M_{cc}=\sum_{i=1}^{N_{IoT}}b_{cc}(i)x^{i} \tag{20}\]  
where \(b_{cc}(i)\) = 1 represents the \(i_{th}\) packet in the queue that is valid to participate in coding. Then, the number of input packets \(\mathbf{P_{I}}\) for coding \(N_{in}\) can be calculated by  
\[N_{in}=\sum_{i=1}^{N_{IoT}}b_{cc}(i) \tag{21}\]  
Then, we calculate the number of coded packets \(N_{out}\) as below. \[N_{out}=\left\lceil\lambda_{cc}\cdot N_{in}/PRR_{i\to j}\right\rceil \tag{22}\]  
where \(\lambda_{cc}\) is the redundancy factor for coding, and \(PRR_{i\to j}\) is the packet reception ratio of the forward link coming from the sender \(i\) to the receiver \(j\). The sender executes systematic network coding by using coding matrix \(\mathbf{G}_{s}=\left[\mathbf{I}|\mathbf{G}_{0}\right]^{T}\)[53] where \(\mathbf{I}\) is an identity matrix with a size of \(N_{in}\times N_{in}\). matrix \(\mathbf{G}_{0}\) is generated randomly in Galois field, the size of which is \((N_{out}-N_{in})\times N_{in}\). Then, we can obtain the output of coding \(\mathbf{P_{O}}\) as below. \[\mathbf{P_{O}}=\mathbf{G}_{s}\cdot\mathbf{P_{I}} \tag{23}\]  
The receiver only knows the original information of these data packets; however, we have no knowledge about the input information and output information of this coding. There are two ways to transmit the coding information: one way is to add the coding vector in the output packet and the other way is to store the coding matrix locally. In CLOR, we add all the coding information in the coding vector \(V_{cc}\). Then, other nodes in the candidate set that overhear sufficient coded packets can attempt to recover the original packets. \(V_{cc}\) includes the index and the coefficients of the input packets. In addition, the information of burst transmission \(M_{cc}\), \(N_{out}\), and the index of the output packet \(Eoldx\) are introduced to each output packet. Thus, the receiver sets a valid time interval according to this information for waiting for the rest of the data packets in this transmission. As shown in Figure 2, we use an example to illustrate the coding process: after filtering the invalid data packets in the queue, the node obtains three input packets  
Figure 2: An example of burst transmission based on network coding. \(P_{1}=[P_{11},P_{12},P_{13}]^{\rm T}\), and then, the node can calculate \(N_{out}\)= 5 by Formula (22). On this basis, the coding matrix is generated to encode the input packets \(\mathbf{P_{1}}\). Finally, the coded packets \(\mathbf{P_{O}}=[P_{11},P_{12},P_{13},P_{11}+P_{12},2P_{11}+3P_{12}+P_{13}]^{\rm T}\) are obtained after executing the coding algorithm according to Formula (23). After finishing coding, the node adds these output packets into the transmit queue. Meanwhile, the sender sets a timer to wait for the acknowledgement (\(ACK\)) packet from the receiver. The time interval of the timer \(\tau_{\tau\mu ACK}\) is calculated as:  
\[\tau_{\tau\mu ACK}=2\cdot\tau_{maxProp}+N_{out}\cdot\tau_{ED} \tag{24}\]  
where \(\tau_{maxProp}\) is the maximum propagation delay of one hop and \(\tau_{ED}\) is the transmission delay of a coded data packet. Upon receiving a new coded packet, the receiver executes On the Fly Gaussian Elimination (OFG) to decode the information [54; 55]. The decoding process goes on until the timer for decoding is expired.