internet: avoid route duplication in Ipv[4,6]StaticRouting
This commit is contained in:
@@ -72,7 +72,10 @@ Ipv4StaticRouting::AddNetworkRouteTo (Ipv4Address network,
|
|||||||
networkMask,
|
networkMask,
|
||||||
nextHop,
|
nextHop,
|
||||||
interface);
|
interface);
|
||||||
m_networkRoutes.push_back (make_pair (route,metric));
|
if (!LookupRoute (route, metric))
|
||||||
|
{
|
||||||
|
m_networkRoutes.push_back (make_pair (route,metric));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -86,7 +89,10 @@ Ipv4StaticRouting::AddNetworkRouteTo (Ipv4Address network,
|
|||||||
*route = Ipv4RoutingTableEntry::CreateNetworkRouteTo (network,
|
*route = Ipv4RoutingTableEntry::CreateNetworkRouteTo (network,
|
||||||
networkMask,
|
networkMask,
|
||||||
interface);
|
interface);
|
||||||
m_networkRoutes.push_back (make_pair (route,metric));
|
if (!LookupRoute (route, metric))
|
||||||
|
{
|
||||||
|
m_networkRoutes.push_back (make_pair (route,metric));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
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>
|
Ptr<Ipv4Route>
|
||||||
Ipv4StaticRouting::LookupStatic (Ipv4Address dest, Ptr<NetDevice> oif)
|
Ipv4StaticRouting::LookupStatic (Ipv4Address dest, Ptr<NetDevice> oif)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -376,6 +376,14 @@ private:
|
|||||||
/// Iterator for container for the multicast routes
|
/// Iterator for container for the multicast routes
|
||||||
typedef std::list<Ipv4MulticastRoutingTableEntry *>::iterator MulticastRoutesI;
|
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.
|
* \brief Lookup in the forwarding table for destination.
|
||||||
* \param dest destination address
|
* \param dest destination address
|
||||||
|
|||||||
@@ -151,7 +151,10 @@ void Ipv6StaticRouting::AddNetworkRouteTo (Ipv6Address network, Ipv6Prefix netwo
|
|||||||
NS_LOG_FUNCTION (this << network << networkPrefix << nextHop << interface << metric);
|
NS_LOG_FUNCTION (this << network << networkPrefix << nextHop << interface << metric);
|
||||||
Ipv6RoutingTableEntry* route = new Ipv6RoutingTableEntry ();
|
Ipv6RoutingTableEntry* route = new Ipv6RoutingTableEntry ();
|
||||||
*route = Ipv6RoutingTableEntry::CreateNetworkRouteTo (network, networkPrefix, nextHop, interface);
|
*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)
|
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 ();
|
Ipv6RoutingTableEntry* route = new Ipv6RoutingTableEntry ();
|
||||||
*route = Ipv6RoutingTableEntry::CreateNetworkRouteTo (network, networkPrefix, nextHop, interface, prefixToUse);
|
*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)
|
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);
|
NS_LOG_FUNCTION (this << network << networkPrefix << interface);
|
||||||
Ipv6RoutingTableEntry* route = new Ipv6RoutingTableEntry ();
|
Ipv6RoutingTableEntry* route = new Ipv6RoutingTableEntry ();
|
||||||
*route = Ipv6RoutingTableEntry::CreateNetworkRouteTo (network, networkPrefix, interface);
|
*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)
|
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;
|
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)
|
Ptr<Ipv6Route> Ipv6StaticRouting::LookupStatic (Ipv6Address dst, Ptr<NetDevice> interface)
|
||||||
{
|
{
|
||||||
NS_LOG_FUNCTION (this << dst << interface);
|
NS_LOG_FUNCTION (this << dst << interface);
|
||||||
|
|||||||
@@ -264,6 +264,14 @@ private:
|
|||||||
/// Iterator for container for the multicast routes
|
/// Iterator for container for the multicast routes
|
||||||
typedef std::list<Ipv6MulticastRoutingTableEntry *>::iterator MulticastRoutesI;
|
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.
|
* \brief Lookup in the forwarding table for destination.
|
||||||
* \param dest destination address
|
* \param dest destination address
|
||||||
|
|||||||
Reference in New Issue
Block a user