internet: avoid route duplication in Ipv[4,6]StaticRouting

This commit is contained in:
Tommaso Pecorella
2021-02-19 02:27:11 +00:00
parent 41e000cdca
commit b5c4f68f97
4 changed files with 74 additions and 5 deletions

View File

@@ -72,7 +72,10 @@ Ipv4StaticRouting::AddNetworkRouteTo (Ipv4Address network,
networkMask,
nextHop,
interface);
m_networkRoutes.push_back (make_pair (route,metric));
if (!LookupRoute (route, metric))
{
m_networkRoutes.push_back (make_pair (route,metric));
}
}
void
@@ -86,7 +89,10 @@ Ipv4StaticRouting::AddNetworkRouteTo (Ipv4Address network,
*route = Ipv4RoutingTableEntry::CreateNetworkRouteTo (network,
networkMask,
interface);
m_networkRoutes.push_back (make_pair (route,metric));
if (!LookupRoute (route, metric))
{
m_networkRoutes.push_back (make_pair (route,metric));
}
}
void
@@ -219,6 +225,25 @@ Ipv4StaticRouting::RemoveMulticastRoute (uint32_t index)
}
}
bool
Ipv4StaticRouting::LookupRoute (Ipv4RoutingTableEntry *route, uint32_t metric)
{
for (NetworkRoutesI j = m_networkRoutes.begin (); j != m_networkRoutes.end (); j++)
{
Ipv4RoutingTableEntry* rtentry = j->first;
if (rtentry->GetDest () == route->GetDest () &&
rtentry->GetDestNetworkMask () == route->GetDestNetworkMask () &&
rtentry->GetGateway () == route->GetGateway () &&
rtentry->GetInterface () == route->GetInterface () &&
j->second == metric)
{
return true;
}
}
return false;
}
Ptr<Ipv4Route>
Ipv4StaticRouting::LookupStatic (Ipv4Address dest, Ptr<NetDevice> oif)
{

View File

@@ -376,6 +376,14 @@ private:
/// Iterator for container for the multicast routes
typedef std::list<Ipv4MulticastRoutingTableEntry *>::iterator MulticastRoutesI;
/**
* \brief Checks if a route is already present in the forwarding table.
* \param route route
* \param metric metric of route
* \return true if the route/metric is already in the forwarding table
*/
bool LookupRoute (Ipv4RoutingTableEntry *route, uint32_t metric);
/**
* \brief Lookup in the forwarding table for destination.
* \param dest destination address

View File

@@ -151,7 +151,10 @@ void Ipv6StaticRouting::AddNetworkRouteTo (Ipv6Address network, Ipv6Prefix netwo
NS_LOG_FUNCTION (this << network << networkPrefix << nextHop << interface << metric);
Ipv6RoutingTableEntry* route = new Ipv6RoutingTableEntry ();
*route = Ipv6RoutingTableEntry::CreateNetworkRouteTo (network, networkPrefix, nextHop, interface);
m_networkRoutes.push_back (std::make_pair (route, metric));
if (!LookupRoute (route, metric))
{
m_networkRoutes.push_back (std::make_pair (route, metric));
}
}
void Ipv6StaticRouting::AddNetworkRouteTo (Ipv6Address network, Ipv6Prefix networkPrefix, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse, uint32_t metric)
@@ -164,7 +167,10 @@ void Ipv6StaticRouting::AddNetworkRouteTo (Ipv6Address network, Ipv6Prefix netwo
Ipv6RoutingTableEntry* route = new Ipv6RoutingTableEntry ();
*route = Ipv6RoutingTableEntry::CreateNetworkRouteTo (network, networkPrefix, nextHop, interface, prefixToUse);
m_networkRoutes.push_back (std::make_pair (route, metric));
if (!LookupRoute (route, metric))
{
m_networkRoutes.push_back (std::make_pair (route, metric));
}
}
void Ipv6StaticRouting::AddNetworkRouteTo (Ipv6Address network, Ipv6Prefix networkPrefix, uint32_t interface, uint32_t metric)
@@ -172,7 +178,10 @@ void Ipv6StaticRouting::AddNetworkRouteTo (Ipv6Address network, Ipv6Prefix netwo
NS_LOG_FUNCTION (this << network << networkPrefix << interface);
Ipv6RoutingTableEntry* route = new Ipv6RoutingTableEntry ();
*route = Ipv6RoutingTableEntry::CreateNetworkRouteTo (network, networkPrefix, interface);
m_networkRoutes.push_back (std::make_pair (route, metric));
if (!LookupRoute (route, metric))
{
m_networkRoutes.push_back (std::make_pair (route, metric));
}
}
void Ipv6StaticRouting::SetDefaultRoute (Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse, uint32_t metric)
@@ -281,6 +290,25 @@ bool Ipv6StaticRouting::HasNetworkDest (Ipv6Address network, uint32_t interfaceI
return false;
}
bool Ipv6StaticRouting::LookupRoute (Ipv6RoutingTableEntry *route, uint32_t metric)
{
for (NetworkRoutesI j = m_networkRoutes.begin (); j != m_networkRoutes.end (); j++)
{
Ipv6RoutingTableEntry* rtentry = j->first;
if (rtentry->GetDest () == route->GetDest () &&
rtentry->GetDestNetworkPrefix () == route->GetDestNetworkPrefix () &&
rtentry->GetGateway () == route->GetGateway () &&
rtentry->GetInterface () == route->GetInterface () &&
rtentry->GetPrefixToUse () == route->GetPrefixToUse () &&
j->second == metric)
{
return true;
}
}
return false;
}
Ptr<Ipv6Route> Ipv6StaticRouting::LookupStatic (Ipv6Address dst, Ptr<NetDevice> interface)
{
NS_LOG_FUNCTION (this << dst << interface);

View File

@@ -264,6 +264,14 @@ private:
/// Iterator for container for the multicast routes
typedef std::list<Ipv6MulticastRoutingTableEntry *>::iterator MulticastRoutesI;
/**
* \brief Checks if a route is already present in the forwarding table.
* \param route route
* \param metric metric of route
* \return true if the route/metric is already in the forwarding table
*/
bool LookupRoute (Ipv6RoutingTableEntry *route, uint32_t metric);
/**
* \brief Lookup in the forwarding table for destination.
* \param dest destination address