# Context-Aware Trust and Reputation Routing Protocol for Opportunistic IoT Networks
## 3 Proposed CATR Routing Protocol for OppIoT Networks
### Beta Distribution and Trust Modeling  
According to the beta distribution [12], the probability density function (PDF) is formulated by using two parameters \((\alpha\) and \(\beta)\) and the gamma function [7], as follows:  
\[P(x)=f(x|\alpha,\beta)=\frac{\Gamma(\alpha+\beta)}{\Gamma\alpha\cdot\Gamma\beta} x^{\alpha-1}(1-x)^{\beta-1} \tag{1}\]  
where \(0\leq x\leq 1\), \(\alpha\geq 0\), \(\beta\geq 0\), such that if \(\alpha<1\), then \(x\
eq 0\) and if \(\beta<1\), \(x\
eq 1\). The probability expectation value of this beta distribution is then computed as follows:  
\[E(x)=\frac{\alpha}{\alpha+\beta} \tag{2}\]  
In the context of data transmission in OppNet, \(\alpha\) and \(\beta\) can represent the successful (resp. unsuccessful) encounters among the nodes. Additionally, let \(\zeta\) be the number of times that successful encounters have occurred and \(\lambda\) be the number of times that unsuccessful encounters have occurred. Then, the probability density function (PDF) of \(\alpha\), the future can be expressed by setting  
\[\alpha=\zeta+1\,\ \beta=\lambda+1\ \textit{such that}\ \zeta,\zeta\geq 0 \tag{3}\]  
Substituting these values in Equation (1) yields  
\[P(x) = f(x|\alpha,\beta) \tag{4}\] \[= f(x|\zeta+1,\lambda+1)\] \[= \frac{\Gamma(\zeta+1+\zeta+1)}{\Gamma(\zeta+1)\cdot\Gamma( \lambda+1)}x^{\zeta+1-1}(1-x)^{\lambda+1-1}\] \[= \frac{\Gamma(\zeta+\lambda+2)}{\Gamma(\zeta+1)\cdot\Gamma( \lambda+1)}x^{\zeta}(1-x)^{\lambda}\]  
The corresponding probability expectation in Equation (2) can then be rewritten as  
\[E(x) = \frac{\zeta+1}{(\zeta+1)+(\lambda+1)} \tag{5}\] \[= \frac{\zeta+1}{(\zeta+\lambda+2)}\]  
This Equation (5) can be used to represent the beta trust of a node \(n\) as computed by another node \(m\) (denoted \(BT_{mn}\)). Additionally, the beta distribution [12] can also be used to determine the reputation index of a node by another node \(m\) (denoted \(RI_{mn}\)). Indeed, let \(i\) be any neighbor of node \(n\), \(\zeta_{n}^{i}\) be the number of successful encounters between nodes \(n\) and \(i\) as maintained by node \(i\), and \(\lambda_{n}^{i}\) be the number of unsuccessful encounters between nodes \(n\) and \(i\) as maintained by node \(i\). Then, for calculating the reputation of a node, the probability density function (PDF) that can be used (according to Equation (4) is  
\[P(x) = \frac{\Gamma(\zeta_{n}^{i}+\lambda_{n}^{i}+2)}{\Gamma(\zeta_{n}^ {i}+1)\cdot\Gamma(\lambda_{n}^{i}+1)}x^{\zeta_{n}^{i}}(1-x)^{\lambda_{n}^{i}} \tag{6}\]  
such that \(\zeta_{n}^{i},\lambda_{n}^{i}\geq 0\). In this case, the probability expectation using Equation (6) is obtained as  
\[E(x)=\frac{\alpha}{\alpha+\beta} \tag{2}\]0 \[E(x)=\frac{\alpha}{\alpha+\beta} \tag{2}\]1This Equation (7) can be utilized to represent the reputation index (\(RI_{mn}\)) of a node n as computed by node \(m\). Based on this, the reputations obtained from those nodes that node n had encountered can be used to calculate its Indirect Trust (\(IT\)) value of \(n\), precisely as the mean value of these reputation values. For trust modeling purposes, the social status of a node mainly depends upon the trustworthiness and cooperation that it provides to other nodes in the network. This further enhances a belief system among the nodes which can be referred to as trust. Thus, trust can be defined as a measure of belief that one node has in another node; it is influenced by the cooperative behavior among the nodes. For instance, whenever a pair of nodes \(N_{1}\) and \(N_{2}\) encounter each other, \(N_{2}\) can be considered as cooperative and trustworthy for \(N_{1}\) if \(N_{2}\) can successfully forward a data packet that it received coming from \(N_{1}\) without altering its content. However, if node \(N_{2}\) fails to forward the received data packet, it is considered as non-cooperative or as having malicious intent. Therefore, node \(N_{1}\) must first determine whether \(N_{2}\) can be trusted or not.