AKHILRAJ V GADAGKAR
AKHILRAJ V GADAGKAR

Reputation: 161

How to find available neighbors of a node in unetstack

I am developing an energy based routing protocol in which a node has to know its available neighbours, so that it can get the energy details of the neighbour nodes and decide its next hop.

a) How to find available neighbours for a node?

b) Among the use of PDU and RemoteGetParamReq, which method suits well to retrieve energy of neighbour nodes?

Upvotes: 3

Views: 247

Answers (1)

Mandar Chitre
Mandar Chitre

Reputation: 2280

a) If you are writing your own agent, you could send a broadcast frame to query neighbors, and have your agent on the neighbors respond to the frame with a random backoff (to avoid MAC collisions). An alternative hack could be to use the RouteDisoveryReq (see https://unetstack.net/svc-31-rdp.html) with the to address set to a non-existent node. This will cause all 1-hop neighbors to re-broadcast your route discovery request, and you will get RouteDiscoveryNtf for each of those neighbors.

Example script demonstrating the hack (rdpdemo.groovy):

// settings
attempts = 1      // try only a single attempt at discovery
phantom = 132     // non-existent node address
timeout = 10000   // 10 second timeout

println 'Starting discovery...'
n = []                        // collect list of neighbors
rdp << new RouteDiscoveryReq(to: phantom, count: attempts)
while (ntf = receive(RouteDiscoveryNtf, timeout)) {
  println("  Discovered neighbor: ${ntf.nextHop}")
  n << ntf.nextHop            // add neighbor to list
}
n = n.unique()                // remove duplicates
println("Neighbors: ${n}")

Example run (simulation samples/rt/3-node-network.groovy on node 3):

> rdpdemo
Starting discovery...
  Discovered neighbor: 1
  Discovered neighbor: 2
Neighbors: [1, 2]
>

b) The answer to this depends on how you expose your energy information. If you expose it as a parameter, you can use the RemoteGetParamReq to get it. But if you are already implementing some protocol in your agent, it is easy enough to have a specific PDU to convey the information.

Upvotes: 1

Related Questions