首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从Unetstack的路由表中删除路由

从Unetstack的路由表中删除路由
EN

Stack Overflow用户
提问于 2019-08-26 23:29:40
回答 1查看 73关注 0票数 0

我在UnetStack中使用没有任何外壳代码的代理创建我的路由。我想从路由表中删除一条路由?

以下是我的代码:

我正在尝试做的是每10秒在两个路由之间切换。因此,从源节点(节点5)到目的节点(节点1),路由从5到3更改为4到1,或者从5到2更改为4到1

模拟

代码语言:javascript
复制
platform = RealTimePlatform
channel.model = ProtocolChannelModel

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: 5101, stack: { container ->
        container.add 'new_routing_agent', new new_routing_agent();
        container.add 'routing', new Router();
        container.add 'rdp', new 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 Router();
        container.add 'rdp', new 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 Router();
        container.add 'rdp', new 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 Router();
        container.add 'rdp', new RouteDiscoveryProtocol();
    }

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

代理

代码语言:javascript
复制
class new_routing_agent extends UnetAgent {
def router
int addr
def flag

void addroute(int to, int via) {
    router.send new RouteDiscoveryNtf(to: to, nextHop: via)
}

void deleteRoutes(){
//        router.send new RouteDiscoveryNtf().setRoute()

}

void routeDynamically(){
    while(1){
        deleteRoutes()
        if(flag){
            addroute 1, 2
        }
        else{
            addroute 1,3
        }
        flag = !flag
        sleep(10000)
    }
}

void startup() {
    flag = false
    def phy = agentForService Services.PHYSICAL
    subscribe topic(phy)

    router = agentForService Services.ROUTING
    subscribe topic(router)

    def nodeInfo = agentForService Services.NODE_INFO
    addr = nodeInfo.address

    switch (addr){
        case 1:
            addroute 1, 1
            break
        case 2:
            addroute 1, 4
            break
        case 3:
            addroute 1, 4
            break
        case 4:
            addroute 1, 1
            break
        case 5:
            routeDynamically()
            break
        default:
            addroute 1, 1
            break
    }
}

void processMessage(Message msg) {

    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-08-26 23:54:35

作为路由服务的一部分,UnetStack目前不对删除路由的消息进行标准化。但是,您可以使用与shell用于删除路由的机制相同的机制,但请记住,UnetStack的未来版本可能会更改该机制。有关如何执行此操作的详细信息,请参阅:How to delete route entries from routing table using an agent in UnetStack

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57660862

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档