From 6fbea4f7f7fcbbd99e3c3c83542b162e1ca21d09 Mon Sep 17 00:00:00 2001 From: Claudio-Daniel Freire Date: Thu, 12 May 2011 14:27:25 +0200 Subject: [PATCH] NS3 fix: properly handle default (0.0.0.0/0) and host (x.y.z.w/32) routes. --- .../ns3/factories_metadata_v3_9_RC3.py | 35 ++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/src/nepi/testbeds/ns3/factories_metadata_v3_9_RC3.py b/src/nepi/testbeds/ns3/factories_metadata_v3_9_RC3.py index 65216782..c570e9a1 100644 --- a/src/nepi/testbeds/ns3/factories_metadata_v3_9_RC3.py +++ b/src/nepi/testbeds/ns3/factories_metadata_v3_9_RC3.py @@ -241,6 +241,32 @@ def configure_device(testbed_instance, guid): ipv4.SetMetric(ifindex, 1) ipv4.SetUp(ifindex) +def _add_static_route(static_routing, + address, netprefix, nexthop_address, ifindex): + if netprefix == 0: + # Default route: 0.0.0.0/0 + static_routing.SetDefaultRoute(nexthop_address, ifindex) + elif netprefix == 32: + # Host route: x.y.z.w/32 + static_routing.AddHostRouteTo(address, nexthop_address, ifindex) + else: + # Network route: x.y.z.w/n + mask = ns3.Ipv4Mask("/%d" % netprefix) + static_routing.AddNetworkRouteTo(address, mask, nexthop_address, + ifindex) + +def _add_static_route_if(static_routing, address, netprefix, ifindex): + if netprefix == 0: + # Default route: 0.0.0.0/0 + static_routing.SetDefaultRoute(ifindex) + elif netprefix == 32: + # Host route: x.y.z.w/32 + static_routing.AddHostRouteTo(address, ifindex) + else: + # Network route: x.y.z.w/n + mask = ns3.Ipv4Mask("/%d" % netprefix) + static_routing.AddNetworkRouteTo(address, mask, ifindex) + def configure_node(testbed_instance, guid): configure_traces(testbed_instance, guid) @@ -257,7 +283,6 @@ def configure_node(testbed_instance, guid): for route in routes: (destination, netprefix, nexthop) = route address = ns3.Ipv4Address(destination) - mask = ns3.Ipv4Mask("/%d" % netprefix) if nexthop: nexthop_address = ns3.Ipv4Address(nexthop) ifindex = -1 @@ -272,11 +297,13 @@ def configure_node(testbed_instance, guid): ifindex = ipv4.GetInterfaceForPrefix(nexthop_address, ifmask) if ifindex == ifidx: break - static_routing.AddNetworkRouteTo(address, mask, nexthop_address, - ifindex) + _add_static_route(static_routing, + address, netprefix, nexthop_address, ifindex) else: + mask = ns3.Ipv4Mask("/%d" % netprefix) ifindex = ipv4.GetInterfaceForPrefix(address, mask) - static_routing.AddNetworkRouteTo(address, mask, ifindex) + _add_static_route_if(static_routing, + address, netprefix, nexthop_address, ifindex) factories_info = dict({ "ns3::Ping6": dict({ -- 2.47.0