# Design of a Technique for Accelerating the WSN Convergence Process
## 5 Proposal--Design and Implementation of a Quick Recovery Mechanism (Step 3)
### BFD Packet  
First, it was necessary to create a control packet. A BFD packet is a message exchanged between neighboring nodes to signal their availability and detect outages. The BFD packet contains the following fields:  
1. Version: This field identifies the version of the BFD protocol. The version currently in use is BFD version 1.
2. Diagnostic: The diagnostic field is used to provide diagnostic information about the state of the connection. It can contain values such as \"No Diagnostic\", \"Control Detection Time Expired\", and others.
3. State: This field represents the current state of the connection between neighboring nodes. It can contain values such as \"Admin Down\", \"Down\", \"Init\", \"Up\", and \"Unknown\".
4. Poll: This field is used to poll a neighboring node for a response. When set to 1, it means that the node requests a response from the neighboring node.
5. Final: This field is used to end the BFD session. When set to 1, it indicates that the node is trying to terminate the connection.
6. Control Plane Independent: This field indicates whether the BFD communication is independent of the control plane (for example, independent of OSPF or BGP). When this field is set to 1, BFD communication is independent of the control plane.
7. Detection Time: This field represents the time interval between sending BFD packets. Specifies how often BFD packets should be broadcast between neighboring nodes.
8. Desired Min TX Interval: This field specifies the minimum interval between sending BFD packets from the node that is the source of BFD messages.
9. Required Min RX Interval: This field specifies the minimum interval between receiving BFD packets on the node that is the destination of BFD messages.  
BFD control packets have a mandatory section and an optional authentication section. Only the mandatory part was implemented in the presented work; the authentication part will be the subject of further research.  
When writing the C++ code, the option of defining the packet in the MSG file was used. The task of the OMNeT++ message compiler, opp_msg or opp_msgtool, is to translate the definitions into C++ classes that are created from the C++ code model. The message compiler is invoked for.msg files automatically as part of the build process. A BfdControlPacket.msg file was created in which the BfdControlPacket class was defined with its necessary fields. In order for the fields of this class to be subsequently used when creating and sending a packet, it was necessary to define that it would extend FieldsChunk. Thanks to this extension, the packet data structure will be built on another set of data structures called chunk-y. Chunks provide several alternatives for representing parts of data. In the created file, the namespace for the packet, i.e., inet and BFD, were additionally defined. To represent the state of the BFD session, the BfdState enum was created, which defines the necessary numerical values as constants. For the other parameters of the BFD control packet, the most suitable data types according to their sizes were used. Figure 8 shows the BfdControlPacket.msg file.