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.