3

我们计划使用 UnetStack 在水下路由协议(多跳通信)领域做最后一年的项目。在计划的路由协议中,每个节点都必须从许多可用的邻居中选择它的下一跳。在深入了解下一跳算法的选择之前,我想看看如何使用 UnetStack 在路由表中配置选定的下一跳。为此,我安装了 5 个节点。节点 1 和 5 分别是目标节点和源节点。节点 5 的邻居是节点 3 和 4。在邻居 3 和 4 中,我想选择节点 3 作为节点 5 的下一跳到达目的地。我无法将节点 3 添加为节点 5 的下一跳。如果您提供一些有关此的输入,这将很有帮助。

我编写了模拟脚本如下:

channel.soundSpeed = 1500.mps           // c
channel.communicationRange = 100.m     // Rc

// run the simulation infinately
simulate  {
 // Destination node
node '1', remote: 1101, address: 1, location: [ 0.m, 0.m, 0.m], shell: true, stack: { container ->
container.add 'routing', new org.arl.unet.net.Router();
container.add 'rdp', new org.arl.unet.net.RouteDiscoveryProtocol();  
} 

node '2', remote: 1102, address: 2, location: [ 0.m, 0.m, -75.m], shell: 5102, stack: { container ->
container.add 'new_routing_agent', new new_routing_agent();
container.add 'routing', new org.arl.unet.net.Router();  
container.add 'rdp', new org.arl.unet.net.RouteDiscoveryProtocol();
}    

 // neighbor node for node 5, and will be a next node for node 5 during routing
node '3', remote: 1103, address: 3, location: [0.m, 0.m, -90.m], shell: 5103, stack: { container ->
container.add 'new_routing_agent', new new_routing_agent();
container.add 'routing', new org.arl.unet.net.Router();  container.add 'rdp', new org.arl.unet.net.RouteDiscoveryProtocol();   
}

//Neighbor node for node 5 ,but not a next node for node 5
 node '4', remote: 1104, address: 4, location: [0.m, 0.m, -150.m], shell: 5104, stack: {container ->
container.add 'new_routing_agent', new new_routing_agent();
container.add 'routing', new org.arl.unet.net.Router();
container.add 'rdp', new org.arl.unet.net.RouteDiscoveryProtocol();    
}

// Source node
node '5', remote: 1105, address: 5, location: [0.m, 0.m, -160.m], shell: 5105, stack: {container ->
container.add 'new_routing_agent', new new_routing_agent();
container.add 'routing', new org.arl.unet.net.Router();
container.add 'rdp', new org.arl.unet.net.RouteDiscoveryProtocol();    
  }
}

代理:new_routing_agent 如下:

class new_routing_agent extends UnetAgent {
    def router;
    int addr;  
        // STARTUP  
   void startup() 
    {

        def phy = agentForService Services.PHYSICAL;
        subscribe topic(phy);

        router = agentForService Services.ROUTING;
        subscribe topic(router);

        def nodeInfo = agentForService Services.NODE_INFO;
        addr = nodeInfo.address; // obtain the address of the node

        def rdp = agentForService org.arl.unet.Services.ROUTE_MAINTENANCE
        def rsp = rdp << new RouteDiscoveryReq(1)      // discover routes to node 1

    }

    void processMessage(Message msg) {  
    if (msg instanceof RouteDiscoveryNtf )  
    { 
        if (addr == 5)
        addroute 1, 3 ;

        else if (addr == 4)
        addroute 1, 2;

        else 
          addroute 1,1;     
    }  //End of if   
} //End of processMessage
} // End of class
4

1 回答 1

2

Router如果您打算填充自己的路线,代理就是您所需要的。要添加路由,请向RouteDiscoveryNtf路由器代理发送一个。这就是addroute命令的作用,但这仅适用于 shell(而不是代理)。

这个简单的示例代码展示了如何实现自己的addroute()

void addroute(int to, int via) {
  def router = agentForService Services.ROUTING
  router.send new RouteDiscoveryNtf(to: to, nextHop: via)
}

RouteDiscoveryProtocol如果您正在开发自己的路由协议,代理会为您管理路由,这可能不是您想要的。

于 2019-05-08T05:44:15.333 回答