inet icon indicating copy to clipboard operation
inet copied to clipboard

Allow IPv4 configurator to not add DIRECT MANUAL routes

Open ManiAm opened this issue 6 years ago • 3 comments

When the static route assignment is active in the Ipv4NetworkConfigurator module, MANUAL routes of type DIRECT might be redundant since they are already added by the interface (IFACENETMASK). As an example, consider the following network:

import inet.networklayer.configurator.ipv4.Ipv4NetworkConfigurator;
import inet.node.ethernet.Eth100M;
import inet.node.ethernet.Eth10M;
import inet.node.ethernet.EtherSwitch;
import inet.node.inet.Router;
import inet.node.inet.StandardHost;
import inet.visualizer.integrated.IntegratedCanvasVisualizer;


network Network
{
    @display("bgb=2101.0125,829.44995");
    submodules:
        configurator: Ipv4NetworkConfigurator {
            @display("p=100,100");
        }
        host0: StandardHost {
            @display("p=97.81249,375.59998");
        }
        host1: StandardHost {
            @display("p=97.81249,532.1");
        }
        host2: StandardHost {
            @display("p=97.81249,694.46875");
        }
        host3: StandardHost {
            @display("p=1271.5625,334.51874");
        }
        router0: Router {
            @display("p=543.83746,532.1");
        }
        router2: Router {
            @display("p=1508.2687,532.1");
        }
        router1: Router {
            @display("p=925.3062,532.1");
        }
        host4: StandardHost {
            @display("p=1271.5625,692.51245");
        }
        host5: StandardHost {
            @display("p=1473.0562,389.29373");
        }
        host6: StandardHost {
            @display("p=1977.7687,373.64374");
        }
        host7: StandardHost {
            @display("p=1977.7687,532.1");
        }
        host8: StandardHost {
            @display("p=1977.7687,692.51245");
        }
        switch0: EtherSwitch {
            @display("p=318.86874,530.14374");
        }
        switch2: EtherSwitch {
            @display("p=1727.3687,530.14374");
        }
        switch1: EtherSwitch {
            @display("p=1271.5625,530.14374");
        }
        visualizer: IntegratedCanvasVisualizer {
            @display("p=98.8575,209.81999");
        }
        router3: Router {
            @display("p=1054.4187,334.51874");
        }
        router4: Router {
            @display("p=712.07495,334.51874");
        }
    connections:
        host2.ethg++ <--> Eth100M <--> switch0.ethg++;
        host1.ethg++ <--> Eth100M <--> switch0.ethg++;
        host0.ethg++ <--> Eth100M <--> switch0.ethg++;
        switch0.ethg++ <--> Eth100M <--> router0.ethg++;

        switch1.ethg++ <--> Eth100M <--> host3.ethg++;
        switch1.ethg++ <--> Eth100M <--> host4.ethg++;
        switch1.ethg++ <--> Eth100M <--> host5.ethg++;
        switch1.ethg++ <--> Eth100M <--> router2.ethg++;

        switch2.ethg++ <--> Eth100M <--> host6.ethg++;
        switch2.ethg++ <--> Eth100M <--> host7.ethg++;
        switch2.ethg++ <--> Eth100M <--> host8.ethg++;

        router2.ethg++ <--> Eth100M <--> switch2.ethg++;
        router0.ethg++ <--> Eth10M <--> router1.ethg++;
        router1.ethg++ <--> Eth10M <--> switch1.ethg++;
        router0.ethg++ <--> Eth100M <--> router4.ethg++;
        router4.ethg++ <--> Eth100M <--> router3.ethg++;
        router3.ethg++ <--> Eth100M <--> switch1.ethg++;
}

With this configuration:

[Config Step1]
network = Network
description = "static routing"

*.*.ipv4.arpType = "GlobalArp"

# Application parameters
*.host0.numApps = 1
*.host0.app[0].typename = "PingApp"
*.host0.app[0].destAddr = "host6"

# Visualizer settings
*.visualizer.interfaceTableVisualizer.displayInterfaceTables = true

The routing table of router 0 looks like the following (I re-ordered the rows and made it look fancy!):

2018-05-04_16-39-16

As you can see, the first four DIRECT routes were already added in the beginning. The configurator adds three DIRECT routes + three REMOTE routes. What is the point of adding the three DIRECT MANUAL routes when DIRECT IFACENETMASK routes are already there? (or I am missing a point here).

I could not find any NED parameters in the Ipv4NetworkConfigurator module to instruct it to not add DIRECT MANUAL routes. I guess a parameter like addStaticDirectRoutes can be defined with default value of true and then the following lines here could be changed:

https://github.com/inet-framework/inet/blob/6551c8079a70621986d51f7e2c43fa57979d8b19/src/inet/networklayer/configurator/ipv4/IPv4NetworkConfigurator.cc#L1379

From

if (containsRoute(sourceNode->staticRoutes, route))
    delete route;
else {
    sourceNode->staticRoutes.push_back(route);
    EV_DEBUG << "Adding route " << sourceInterfaceEntry->getFullPath() << " -> " << destinationInterfaceEntry->getFullPath() << " as " << route->info() << endl;
}

To

if (containsRoute(sourceNode->staticRoutes, route))
    delete route;
else if(!addStaticDirectRoutes  && route->getGateway().isUnspecified())
    delete route;
else {
    sourceNode->staticRoutes.push_back(route);
    EV_DEBUG << "Adding route " << sourceInterfaceEntry->getInterfaceFullPath() << " -> " << destinationInterfaceEntry->getInterfaceFullPath() << " as " << route->str() << endl;
}

With this assumption that an unspecified gateway address (*) is a DIRECT route.

ManiAm avatar May 04 '18 23:05 ManiAm

Thank you for the clean description! The reason why the configurator adds those routes is that it doesn't know anything about the interface routes added somewhere else. So I think the right approach would be to add a parameter as you suggested. How about calling it addDirectRoutes? The configurator is only able to add static routes, so I think there's no reason to put that in the parameter name (see the other parameters).

Will you send a pull request?

levy avatar May 07 '18 09:05 levy

I sent the pull request #327 .

Two more points that I noticed:

  1. In many of the showcases and tutorials, I noticed that DIRECT routes added by the interface class is dismissed by the following line:

..ipv4.routingTable.netmaskRoutes = ""

As you said, the ipv4configurator does not know anything about the interface routes and adds the DIRECT routes any ways. Thus, I think the above line was added to the ini configuration so that DIRECT interface routes are dismissed. One issue with this approach is that the loopback routes won't get added into the routing table. After accepting my pull request, probably someone should go and updates the configuration.

  1. Now that the new parameter addDirectRoutes is added, I argue that this parameter can be set to 'false' by default, because in almost all cases the interface routes are added and we don't want the ipv4configurator to double-add them. It is up to you to change the default value from true to false. Probably after updating the examples.

ManiAm avatar May 07 '18 17:05 ManiAm

I merged your pull request.

I understand what you are saying, but I would also the following. The network configurator should be able to provide a routing configuration that is complete on its own. So if the loopback routes are missing, then we should add another parameter to add them if requested.

As for what the default values should be, that is an entirely different question. I'm too lazy to change the default values right now, because we would have to update the showcase documentation and retest it.

I leave this issue open for now so that we can come back to it later.

levy avatar May 09 '18 09:05 levy