I am implementing a routing protocol for underwater communication networks based on the distance between neighboring nodes. I created an agent and written a script to find the distance between neighboring node using a ranging agent but I am getting an error
No such property: ranging for class:.
I will attach scripts I wrote.
complete script. how to find distance in unetstack?
//! Simulation: Simple 3-node network
import org.arl.fjage.*
// run the simulation forever
simulate {
node '1', remote: 1101, address: 1, location: [ 0.km, 0.km, -15.m], shell: true, stack: {container ->
container.add 'ranging', new org.arl.unet.phy.Ranging()
container.shell.addInitrc "${script.parent}/sink.groovy"
}
node '2', remote: 1102, address: 2, location: [ 1.km, 0.km, -15.m], shell: 5102, stack: {container ->
container.add 'ranging', new org.arl.unet.phy.Ranging();
//container.shell.addInitrc "${script.parent}/sink.groovy"
container.add 'node_agent', new node_agent();
}
node '3', remote: 1103, address: 3, location: [-1.km, 0.km, -15.m], shell: 5103, stack: { container ->
container.add 'ranging', new org.arl.unet.phy.Ranging()
container.add 'node_agent', new node_agent();
}
}
import org.arl.unet.*
import org.arl.unet.phy.*
import org.arl.unet.mac.*
//import org.arl.unet.nodeinfo.NodeInfo
import org.arl.unet.PDU
import org.arl.fjage.*
import static org.arl.unet.Services.*
import static org.arl.unet.phy.Physical.*
import org.arl.unet.phy.Ranging.*
int hc = 0, ad;
float neighbor_dist;
float rang
subscribe phy;
send = { count = 1 ->
println ''' BROADCASTING '''
count.times {
phy << new DatagramReq(to: Address.BROADCAST, protocol: Protocol.MAC, data: [node.address, hc, 0]);
}
}
import org.arl.fjage.Message
import org.arl.unet.*
import org.arl.unet.net.Router
import org.arl.unet.phy.*
import org.arl.unet.mac.*
import org.arl.fjage.RealTimePlatform
import org.arl.unet.nodeinfo.NodeInfo
import org.arl.fjage.*
import org.arl.unet.phy.Ranging.*
import org.arl.unet.phy.RangeNtf.*
import org.arl.unet.phy.RangeReq
class node_agent extends UnetAgent {
int neighbor, addr;
float neighbor_distance;
void startup()
{
def phy = agentForService Services.PHYSICAL;
subscribe topic(phy);
def rang = agentForService Services.RANGING;
subscribe topic(rang);
def nodeInfo = agentForService Services.NODE_INFO;
addr = nodeInfo.address;
}
void processMessage(Message msg) {
if (msg instanceof DatagramNtf && msg.protocol == Protocol.MAC)
{
neighbor = msg.from;
println " BEACON RECEIVED FROM:" +neighbor
ranging<< new RangeReq(to: neighbor);
}
else if (msg instanceof RangeNtf )
{
float neighbor_distance = msg.getRange();
println " Distance between node "+addr + " and neighbor" +neighbor+ "is" + neighbor_dis
} // End of if*/
else {
}
} //End of process message
}
The RangeReq
needs to be sent to the ranging agent. You can get the agent using agentForService Services.RANGING
. Since you're looking it up in the startup()
anyway, you can store it in an attribute and use it later to request range. Something like:
def ranging
void startup()
{
:
ranging = agentForService Services.RANGING;
:
}
void processMessage(Message msg)
{
if (msg instanceof DatagramNtf && msg.protocol == Protocol.MAC)
{
neighbor = msg.from;
println " BEACON RECEIVED FROM:" +neighbor
ranging << new RangeReq(to: neighbor);
}
else if (msg instanceof RangeNtf )
{
float neighbor_distance = msg.getRange();
:
}
}
}