Skip to main content
. 2022 Feb 28;22(5):1897. doi: 10.3390/s22051897
Algorithm 1: Black Hole Attack Detection and Prevention
Input: RREQ, RREP, G, B, Forged-RREQ
Output: BHA Detection and Prevention, Best and Secure Path Selection
1.   Initialization: i=0, 1, 2, 3,, n
2. S  RREQ to NN and sets t
3. if route to D in RT
4.     goto step 11
5. else
6.    do 
7.    NN RREQ to NHN
8.    whileNN=D
9.    end
10. end
11. D v NN RREP to S
12. S RAT  RREPi till t
13. QuicksortS RATDSNRREPi, start, end, pivot
14. Δ=DSN(RREPn)DSN RT
15. λ=µi=1nDSNRREPiΔ+nΔ
16.  each RREPin RAT 
17. if (DSNRREPk>λth)
18.    G  NID RREPk
19. else
20.    Selects RREPk+1(Max DSN<= λth and Min HC) 
21.    goto step 30
22. end
23. S  RREQforged to NN
24. S RREPf
25. if NIDRREPf= GNIDRREPk
26.    B  G NID
27.    S  Alarmmessage to NN
28.    goto step 20
29. else
30.    S Packets to D
31. end