Finding distance between two nodes using using unetstack with groovy script

Refresh

April 2019

Views

18 time

1

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.

  1. 3-node-network_test.groovy : It is a simulation script in which I deployed 3 nodes. Node 1 is the sink node, in which ranging agent and sink script will be executed. Node 2 and 3 are running "ranging agent" and "node_agent".
  2. sink.groovy: Will initialize the beaconing process by broadcasting a beacon.
  3. node_agent: Which receives a beacon from the sink and identify the distance to sink. Here I have written script to find the distance to sink using:

complete script. how to find distance in unetstack?

3-node-network_test.groovy:

//! 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();    
  }
}

Sink.groovy:

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]);

        }

}

node_agent.groovy:

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
}

0 answers