Skip to content

Commit

Permalink
internet: Align RIPng and RIP implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
TommyPec committed Oct 9, 2021
1 parent db1fa07 commit b7ddd9d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
22 changes: 12 additions & 10 deletions src/internet/model/rip.cc
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ Ptr<Ipv4Route> Rip::RouteOutput (Ptr<Packet> p, const Ipv4Header &header, Ptr<Ne
NS_LOG_LOGIC ("RouteOutput (): Multicast destination");
}

rtentry = Lookup (destination, oif);
rtentry = Lookup (destination, true, oif);
if (rtentry)
{
sockerr = Socket::ERROR_NOTERROR;
Expand Down Expand Up @@ -276,7 +276,7 @@ bool Rip::RouteInput (Ptr<const Packet> p, const Ipv4Header &header, Ptr<const N
}
// Next, try to find a route
NS_LOG_LOGIC ("Unicast destination");
Ptr<Ipv4Route> rtentry = Lookup (header.GetDestination ());
Ptr<Ipv4Route> rtentry = Lookup (header.GetDestination (), false);

if (rtentry != 0)
{
Expand Down Expand Up @@ -582,8 +582,7 @@ void Rip::DoDispose ()
Ipv4RoutingProtocol::DoDispose ();
}


Ptr<Ipv4Route> Rip::Lookup (Ipv4Address dst, Ptr<NetDevice> interface)
Ptr<Ipv4Route> Rip::Lookup (Ipv4Address dst, bool setSource, Ptr<NetDevice> interface)
{
NS_LOG_FUNCTION (this << dst << interface);

Expand Down Expand Up @@ -633,13 +632,16 @@ Ptr<Ipv4Route> Rip::Lookup (Ipv4Address dst, Ptr<NetDevice> interface)
uint32_t interfaceIdx = route->GetInterface ();
rtentry = Create<Ipv4Route> ();

if (route->GetDest ().IsAny ()) /* default route */
if (setSource)
{
rtentry->SetSource (m_ipv4->SourceAddressSelection (interfaceIdx, route->GetGateway ()));
}
else
{
rtentry->SetSource (m_ipv4->SourceAddressSelection (interfaceIdx, route->GetDest ()));
if (route->GetDest ().IsAny ()) /* default route */
{
rtentry->SetSource (m_ipv4->SourceAddressSelection (interfaceIdx, route->GetGateway ()));
}
else
{
rtentry->SetSource (m_ipv4->SourceAddressSelection (interfaceIdx, route->GetDest ()));
}
}

rtentry->SetDestination (route->GetDest ());
Expand Down
3 changes: 2 additions & 1 deletion src/internet/model/rip.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,11 @@ class Rip : public Ipv4RoutingProtocol
/**
* \brief Lookup in the forwarding table for destination.
* \param dest destination address
* \param setSource set source address in the route
* \param interface output interface if any (put 0 otherwise)
* \return Ipv4Route to route the packet to reach dest address
*/
Ptr<Ipv4Route> Lookup (Ipv4Address dest, Ptr<NetDevice> = 0);
Ptr<Ipv4Route> Lookup (Ipv4Address dest, bool setSource, Ptr<NetDevice> = 0);

/**
* Receive and process unicast packet
Expand Down

0 comments on commit b7ddd9d

Please sign in to comment.