# Design of a Technique for Accelerating the WSN Convergence Process
## 5 Proposal--Design and Implementation of a Quick Recovery Mechanism (Step 3)
### Processing of the Packet  
Processing of the packet is performed in the processPacket() function. In it, the source address from which the received packet originates is determined, then the BFD control packet is extracted and both of these values are sent as parameters to the next function handleBfdMessage(). Finally, after completing the handling of the received packet, the packet itself is deleted (Figure 15).  
In the handleBfdMessage() function, the correct values of the received BFD control packet are verified at the beginning according to RFC 5880. If any condition is met, an error message is displayed, and the packet is immediately discarded. If no condition for dropping the packet is met, the packet is received and searched for in the BFD list of the session according to the source address. If the session with the received source address is not already in the letter, a new session is created and added. Subsequently, in this session, other correct settings of the received packet are verified again, while the packet is again discarded if it fulfills any condition. After verification, a correctly configured packet is processed in such a way that the following hold:  
* If regular sending of BFD control packets is not scheduled, it will be scheduled.
* The RemoteDiscr of the session is set according to the received value.
* The RemoteState of the session is set according to the received value.
* The RemoteDemandMode of the session is set according to the received value.
* The RemoteMinRxInterval of the session is set according to the received value.
* If the received packet has the Required Min Echo RX Interval set to 0, the sending of Echo packets must be enabled (not yet implemented).
* The poll sequence is used if it is set in the received packet (not yet implemented).
* The detection time is updated according to the received values and the outage detection timer is scheduled.
* If the session state is administratively down (AsminDown), the received packet is dropped.
* If the session status of the received packet is administratively disabled (AsminDown), the session status will be set to disabled (Down), if it is not already, and the local diagnostics will be set to 3.
* If the session status is other than administratively disabled (AsminDown), the session status is set according to the following status machine (Figure 16).  
Figure 14: SendBfdMessage() function.  
Figure 15: ProcessPacket() function.  
* If the session status after evaluating the machine is ON (UP) and the neighboring device also has a session in the UP status, the interval between sending regular BFD packets can be adjusted. Here, only one common rapidTransmissionInterval was implemented, which speeds up the sending of BFD packets. However, each session can have its own pace of sending and receiving packets. This is an option for further development of the mentioned implementation.
* If the BFD mechanism of the remote device is in demand mode and both devices have a session in the UP state, the local system must stop the regular sending of BFD packets. Demand mode was not implemented in this case because it requires separate detection of the outage. This work is focused on the possibility of detection using the BFD mechanism, and in this case, the demand mode would not help.  
In this section, the basic part of the BFD implementation into the AODV protocol is described. In the next section, the testing and evaluation of the proposed solution is rebuilt.