使用代理将路由添加到路由表中

时间:2019-05-06 22:59:54

标签: unetstack

我们计划在以下地区进行去年的项目 使用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

1 个答案:

答案 0 :(得分:2)

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

此简单的示例代码显示了如何实现自己的addroute()

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

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