Some basic steps you have to do to implement a neighbor discovery mechanism are:
- You define your own class (like AODV) or simply a struct (like OLSR) to identify a Neighbor and its properties (e.g. IP address).
- Have a list/vector of that class/struct to store them, this will be your neighbor list.
- Send/Receive HELLO messages and update the list containing the properties you want to store. These messages are broadcast, so no routing is actually needed. Therefore, you can implement the neighbor discovery mechanism even as an application. Create a UDP socket and send HELLO messages, whilst listening to that socket you can receive HELLO messages from others and update your neighbor list.
Hello messages are used only to find direct neighbors (first hop neighbors).
AODV protocol establish a route between a source and a destination using AODV Request/Reply. When the reply message is sent, it creates a state in routing table in each node about the next hop toward the destination. Second hop neighbors are not included in the routing table, but you can add them by yourself by adding the second hop in the route reply message.