Search code examples
groovyunetstack

Deleting a route from routing table in Unetstack


I'm creating my routes in UnetStack from agents only without any shellcode. I want to delete a route from the routing table?

The following is my code:

What I'm trying to do is toggle between two routes every 10 seconds. So from my source node (node 5) to my destination node (node 1), the route changes from 5 to 3 to 4 to 1 or from 5 to 2 to 4 to 1

Simulation

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

Agent

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) {

    }
}

Solution

  • UnetStack currently does not standardize a message to delete routes as part of the ROUTING service. However, you can use the same mechanism as the shell uses to delete routes, bearing in mind that future versions of UnetStack might change the mechanism. For details on how to do this, see: How to delete route entries from routing table using an agent in UnetStack.