1

I am trying to implement a routing algorithm in which node A first sends RouteDiscoveryReq to a non-existent node to find its neighbours. Its neighbours, a1 and a2, on receiving a RouteDiscoveryNtf should reply with a random number to node A. I have made an agent startnode.groovy which is added on nodes a1 and a2 but it is giving me an error. These are the scripts that I have wrote:

  1. multiHop.groovy: A simulation script in which I have deployed 6 nodes. Nodes a1 and a2 are the neighbouring nodes of node A and should run the startnode agent on them. I have only attached code snippets of node A, a1 and a2.
  2. startnode.groovy: The agent which should reply with a random number to A, after waiting for a random amount of time(to avoid collision).

multiHop.groovy:

def n2 = node 'A', address: 2, location: [ 0.km, 2.km, 0.m], web: 8087, stack: "$home/etc/setup"
    n2.startup={
        def rdp = agentForService Services.ROUTE_MAINTENANCE
        subscribe topic(rdp);
        def datagram = agentForService(org.arl.unet.Services.DATAGRAM)
        subscribe topic(datagram);
        n = []                        
        rdp << new RouteDiscoveryReq(to: 100, count: 1)
        while (ntf = receive(RouteDiscoveryNtf, 10000)) {
          n << ntf.nextHop            // add neighbor to list
        }
        n = n.unique() // remove duplicates
        println("Neighbors are ${n}")
        
        }
        
        def a1 = node 'a1', address: 3, location: [ 0.km, 3.km, -1850.m], web: 8088, stack: "$home/etc/setup"
        a1.startup={
        container.add 'sn', new startnode();
      }
        
     def a2 = node 'a2', address: 4, location: [ 1.5.km, 3.km, -1850.m], web: 8089, stack: "$home/etc/setup"
     a2.startup={
        container.add 'sn', new startnode();
     }

startnode.groovy:

import org.arl.fjage.*
import org.arl.fjage.param.Parameter
// import static org.arl.unet.utils.MathUtils.*
import org.arl.unet.*

class startnode extends UnetAgent {
    
  int delay = Math.abs(new Random().nextInt()) % 1000 + 1                          
  int rand_num = Math.abs(new Random().nextInt()) % 10 + 1
  
  void startup() {
    subscribeForServices(Services.DATAGRAM)
    subscribeForServices(Services.ROUTE_MAINTENANCE)
  }
  
  void processMessage(Message msg) {
     
    if (msg instanceof RouteDiscoveryNtf) {
      add new WakerBehavior(delay, {
        send new DatagramReq(
          recipient: msg.sender,
          to: msg.from,
          data: rand_num
        )
      })
    }
  }
}
  • What version of groovy? These are often actual bugs which should be reported https://groovy-lang.org/reporting-issues.html but you should provide more information about your environment, plus an example which can be executed to show the issue – tim_yates Mar 10 '23 at 14:18
  • Also see https://stackoverflow.com/questions/64973662/how-to-write-modem-drivers-for-non-subnero-modems – Mandar Chitre Mar 10 '23 at 19:23
  • Thank you for the reply sir! On compiling the code I am getting an the following error-` unable to resolve class org.arl.unet.net.RouteDiscoveryReq @ line 5, column 1. import org.arl.unet.localization.RouteDiscoveryReq`. – Radhika Suradkar Mar 13 '23 at 15:18
  • The correct package is `org.arl.unet.net.RouteDiscoveryReq` – Mandar Chitre Aug 14 '23 at 07:14

0 Answers0