# A Secure Protocol against Selfish and Pollution Attacker Misbehavior in Clustered WSNs
## 3 Model Establishment
### About the Network Coding Technique  
We begin by introducing the basic principles of the standard \(NC\) and then we present the modified version of \(NC\) that uses data redundancy to protect against \(DoS\) and pollution attacks.  
In \(NC\)-enabled networks, intermediate nodes are able to re-code and combine the received packets in order to generate new ones. More specifically, a fixed set of original data messages received at a relay node \(r\) from different source nodes is linearly combined in a hierarchical network to generate new coded messages. As a result that the combination is linear, the technique is called linear network coding (\(LNC\)) [31; 32]. Let us note \(x=(x_{1},x_{2},\ldots,x_{L})\) the set of original data messages of size \(L\). Once received at a relay node \(r\), a resulting coded packet \(y\) is generated using an encoding vector \(v=(v_{1},v_{2},\ldots,v_{L})\). Eventually, it processes the coding operation as follows:  
\[y=v_{1}\times x_{1}+v_{2}\times x_{2}+\ldots+v_{L}\times x_{L} \tag{1}\]  
If two data packets meet in the network at a relay node, the node can derive a new linear combination using random encoding vectors. The standard \(NC\) technique thus allows data re-coding multiple times. The final destination, which is supposed to be the \(BS\), needs to receive at least \(L\) coded packets \((y_{1},y_{2},\ldots,y_{L})\) from different relay nodes to be able to retrieve the original data messages \((x_{1},x_{2},\ldots,x_{L})\) using the same encoding vectors \(v=(v_{1},v_{2},\ldots,v_{L})\). Figure 2 shows an example of \(NC\), where nodes \(S\) and \(D\) correspond to the source node and the destination node, respectively. It illustrates the way the \(NC\) technique operates with a set of original data messages of size 2.  
There are many existing \(NC\) techniques in the literature. Ref. [23] depicts the evolution of \(NC\) theory and its families.  
In order to ensure availability and integrity and counteract the misbehavior of the adversary, we incorporate new features into the \(NC\) technique. In fact, the \(NC\) technique used in this paper creates an \((L,M)\) data redundancy. It produces \(M\) coded data messages from the set of \(L\) original ones, so that \(L\) of them suffice for reconstructing the original messages, where \(L<M\).  
Let \(v_{i}=(v_{1,i},v_{2,i},\ldots,v_{L,i})\), where \(i\in\{1,2,\ldots,M\}\), denote the encoding vectors associated with the coded packets \(y_{i}\) and \(M\) is the number of relay nodes. The set of the coded data messages is generated through the following system of equations:\[\begin{pmatrix}y_{1}\\ y_{2}\\ \vdots\\ y_{M}\end{pmatrix}=\begin{pmatrix}v_{1,1}&v_{1,2}&\dots&v_{1,L}\\ v_{2,1}&v_{2,2}&\dots&v_{2,L}\\ \vdots&\vdots&\ddots&\vdots\\ v_{M,1}&v_{2,M}&\dots&v_{M,L}\end{pmatrix}\times\begin{pmatrix}x_{1}\\ x_{2}\\ \vdots\\ x_{L}\end{pmatrix} \tag{2}\]  
The \(BS\) will need \(L\) data coded messages out of \(M\) to retrieve the original ones. It will proceed to solve the linear equation system that should be contained in the set of coded received packets \((y_{q_{1}},y_{q_{2}},\dots,y_{q_{L}})\), extracted from the initial constructed coded packets \((y_{1},y_{2},\dots,y_{M})\), using the \(L\) corresponding encoding vectors, as follows:  
\[\begin{pmatrix}x_{1}\\ x_{2}\\ \vdots\\ x_{L}\end{pmatrix}=\begin{pmatrix}v_{1,q_{1}}&\dots&v_{1,q_{L}}\\ v_{2,q_{1}}&\dots&v_{2,q_{L}}\\ \vdots&\ddots&\vdots\\ v_{L,q_{1}}&\dots&v_{L,q_{L}}\end{pmatrix}\times\begin{pmatrix}y_{q_{1}}\\ y_{q_{2}}\\ \vdots\\ y_{q_{L}}\end{pmatrix} \tag{3}\]  
This \(BS\) can achieve this process with a simple elimination of Gauss or by inverting the matrix made up of the different rows \((q_{1},\dots,q_{L})\) of the matrix of encoding vectors used by the \(L\) out of \(M\) existing relay nodes.