diff --git a/src/nix-vector-routing/model/nix-vector-routing.cc b/src/nix-vector-routing/model/nix-vector-routing.cc index 0d259ac24..2b4e2fefd 100644 --- a/src/nix-vector-routing/model/nix-vector-routing.cc +++ b/src/nix-vector-routing/model/nix-vector-routing.cc @@ -239,7 +239,7 @@ NixVectorRouting::GetNixVector (Ptr source, IpAddress dest, Ptr Ptr -NixVectorRouting::GetNixVectorInCache (IpAddress address) const +NixVectorRouting::GetNixVectorInCache (const IpAddress &address, bool &foundInCache) const { NS_LOG_FUNCTION (this << address); @@ -249,10 +249,12 @@ NixVectorRouting::GetNixVectorInCache (IpAddress address) const if (iter != m_nixCache.end ()) { NS_LOG_LOGIC ("Found Nix-vector in cache."); + foundInCache = true; return iter->second; } // not in cache + foundInCache = false; return 0; } @@ -705,11 +707,12 @@ NixVectorRouting::RouteOutput (Ptr p, const IpHeader &header, Ptr::RouteOutput (Ptr p, const IpHeade // into a separate function and kept here for better code // readability. - // check if cache - nixVectorInCache = GetNixVectorInCache (destAddress); + // Check the Nix cache + bool foundInCache = false; + nixVectorInCache = GetNixVectorInCache (destAddress, foundInCache); // not in cache - if (!nixVectorInCache) + if (!foundInCache) { NS_LOG_LOGIC ("Nix-vector not in cache, build: "); // Build the nix-vector, given this node and the @@ -1173,7 +1177,10 @@ NixVectorRouting::PrintRoutingTable (Ptr stream, Time::U std::ostringstream dest; dest << it->first; *os << std::setw (30) << dest.str (); - *os << *(it->second) << std::endl; + if (it->second) + { + *os << *(it->second) << std::endl; + } } } *os << "IpRouteCache:" << std::endl; @@ -1456,15 +1463,19 @@ NixVectorRouting::PrintRoutingPath (Ptr source, IpAddress dest, *os << "(Node " << source->GetId () << " to Node " << destNode->GetId () << ", "; *os << "Nix Vector: "; - nixVectorInCache = GetNixVectorInCache (dest); + // Check the Nix cache + bool foundInCache = true; + nixVectorInCache = GetNixVectorInCache (dest, foundInCache); // not in cache - if (!nixVectorInCache) + if (!foundInCache) { NS_LOG_LOGIC ("Nix-vector not in cache, build: "); // Build the nix-vector, given the source node and the // dest IP address nixVectorInCache = GetNixVector (source, dest, nullptr); + // cache it + m_nixCache.insert (typename NixMap_t::value_type (dest, nixVectorInCache)); } if (nixVectorInCache || (!nixVectorInCache && source == destNode)) @@ -1474,8 +1485,6 @@ NixVectorRouting::PrintRoutingPath (Ptr source, IpAddress dest, if (nixVectorInCache) { - // cache it - m_nixCache.insert (typename NixMap_t::value_type (dest, nixVectorInCache)); // Make a NixVector copy to work with. This is because // we don't want to extract the bits from nixVectorInCache // which is stored in the m_nixCache. diff --git a/src/nix-vector-routing/model/nix-vector-routing.h b/src/nix-vector-routing/model/nix-vector-routing.h index 21904eefe..21bafd3dd 100644 --- a/src/nix-vector-routing/model/nix-vector-routing.h +++ b/src/nix-vector-routing/model/nix-vector-routing.h @@ -161,9 +161,10 @@ private: /** * Checks the cache based on dest IP for the nix-vector * \param address Address to check + * \param foundInCache Address found in cache * \returns The NixVector to be used in routing. */ - Ptr GetNixVectorInCache (IpAddress address) const; + Ptr GetNixVectorInCache (const IpAddress &address, bool &foundInCache) const; /** * Checks the cache based on dest IP for the IpRoute