# Context-Aware Trust and Reputation Routing Protocol for Opportunistic IoT Networks
## 3 Proposed CATR Routing Protocol for OppIoT Networks
### Direct Trust Computation
```
0: n, D, Current time (as \(t_{c}\))
0:Recent contact degree (\(RC_{mn}\))
1:procedurecalcRC(\(m,n,D\))
2:for each NId-\(k\) in \(\mathit{EncounterList}\) of node \(m\)do
3:// Determine the latest elapsed contact time of \(m\) with \(n\). 4:if\(NId=n\)then
5:\(rc_{mm}=min(t_{c}-t_{lc})\)
6:endif
7:// Determine the total time elapsed since last contact of \(m\) with other nodes. 8:\(rc_{mk}=rc_{mk}+min(t_{c}-t_{lc})\)
9:endfor
10:\(\sum\limits_{k=1}^{n}rc_{ik}=s\)
11:for each NId-\(k\) in \(\mathit{EncounterList}\) of node \(n\)do
12:// Determine the latest elapsed contact time of \(n\) with destination \(D\). 13:if\(k=D\)then
14:\(rc_{nD}=min(t_{c}-t_{lc})\)
15:endif
16:// Determine the total time elapsed since last contact of \(n\) with other nodes. 17:\(rc_{nk}=rc_{mk}+min(t_{c}-t_{lc})\)
18:endfor
19:\(RC_{mn}=\{rc_{mn}+rc_{nD}\}/\{\sum\limits_{k=1}^{K}rc_{mk}+\sum\limits_{k=1}^{K}rc_{ mk}\}\)
21:return \(RC_{mn}\)
22:endprocedure
```

**Algorithm 5** Packet forwarding degree (\(PF_{mn}\)). ```
0: n, D, Current time (as \(t_{c}\))
0:Recent contact degree (\(RC_{mn}\))
1:procedurecalcRC(\(m,n,D\))
2:for each NId-\(k\) in \(\mathit{EncounterList}\) of node \(m\)do
23:// Determine the latest elapsed contact time of \(m\) with \(n\). 3:if\(NId=n\)then
4:\(rc_{mm}=min(t_{c}-t_{lc})\)
5:endif
6:\(rc_{mk}=rc_{mk}+min(t_{c}-t_{lc})\)
7:endfor
24:\(k=1\)
8:\(rc_{mk}=rc_{mk}+min(t_{c}-t_{lc})\)
9:endfor
25:\(k=1\)
10:\(rc_{mk}=rc_{mk}+min(t_{c}-t_{lc})\)
11:endprocedure
```

**Algorithm 6** Packet forwarding degree (\(PF_{mn}\)). ```
0: n, D, Current time (as \(t_{c}\))
0:Recent contact degree (\(RC_{mn}\))
1:procedurecalcRC(\(m,n,D\))
2:for each NId-\(k\) in \(\mathit{EncounterList}\) of node \(m\)do
3:// Determine the latest elapsed contact time of \(m\) with \(n\). 4:if\(NId=n\)then
5:\(rc_{mm}=min(t_{c}-t_{lc})\)
6:endif
7:// Determine the total time elapsed since last contact of \(m\) with other nodes. 8:\(rc_{mk}=rc_{mk}+min(t_{c}-t_{lc})\)
9:endfor
10:\(\sum\limits_{k=1}^{n}rc_{ik}=s\)
11:for each NId-\(k\) in \(\mathit{EncounterList}\) of node \(n\)do
12:// Determine the latest elapsed contact time of \(n\) with destination \(D\). 13:if\(k=D\)then
14:\(rc_{mk}=min(t_{c}-t_{lc})\)
15:endif
16:// Determine the total time elapsed since last contact of \(n\) with other nodes. 17:\(rc_{mk}=rc_{mk}+min(t_{c}-t_{lc})\)
18:endfor
19:\(RC_{mn}=\{rc_{mm}+rc_{nD}\}/\{\sum\limits_{k=1}^{K}rc_{mk}+\sum\limits_{k=1}^{K}rc_{ mk}\}\)
20:return \(RC_{mn}\)
21:endprocedure
```

**Algorithm 7** Packet forwarding degree (\(PF_{mn}\)). ```
0:\(rc_{mk}=rc_{mk}+min(t_{c}-t_{lc})\)
12:for each NId-\(k\) in \(\mathit{EncounterList}\) of node \(m\)do
22:// Determine the latest elapsed contact time of \(m\) with \(n\). 33:if\(NId=n\)then
4:\(rc_{mk}=min(t_{c}-t_{lc})\)
5:endif
6:\(rc_{mk}=rc_{mk}+min(t_{c}-t_{lc})\)
7:endfor
26:\(k=1\)
27:\(rc_{mk}=rc_{mk}+min(t_
```
0: m, n, D
0: Contact durability degree (\(CD_{mn}\))
1:procedurecalcRC(\(m,n,D\))
2:for each NId-\(k\) in \(EncounterList\) of \(m\)do
3:// Determine the contact duration time of \(m\) with \(n\). 4:if\(k=n\)then
5:\(cd_{mn}=cd_{mn}+(t_{e}-t_{b})\)
6:endif
7:// Determine the contact duration time of \(m\) with all other nodes. 8:\(cd_{mk}=cd_{mk}+(t_{e}-t_{b})\)
9:endfor
10:for each NId-\(k\) in \(EncounterList\) of \(n\)do
11:// Determine the contact duration time of \(m\) with destination \(D\). 12:if\(k=D\)then
13:\(cd_{mb}=cd_{md}+(t_{e}-t_{b})\)
14:endif// Determine the total contact duration time of \(n\) with all other nodes
15:\(cd_{nk}=cd_{nk}+(t_{e}-t_{b})\)
16:endfor
17:\(CD_{mn}=\{cd_{mn}+cd_{nD}\}/\{\sum\limits_{k=1}^{K}cd_{mk}+\sum\limits_{k=1}^{ K}cd_{mk}\}\)
18:return \(CD_{mn}\)
19:endprocedure
```
**Algorithm 5** Contact durability degree (\(CD_{mn}\)). By substituting the values returned by each of the above-described algorithms in Equation (8), we get the DT value \((DT_{mn})\) of node \(m\) on node \(n\).