blob: 14e7c7dd76bc10a0d5be129020f0376abe11593c [file] [log] [blame]
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2017, The University of Memphis,
* Regents of the University of California
*
* This file is part of NLSR (Named-data Link State Routing).
* See AUTHORS.md for complete list of NLSR authors and contributors.
*
* NLSR is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*
**/
#ifndef NLSR_ROUTING_TABLE_POOL_ENTRY_HPP
#define NLSR_ROUTING_TABLE_POOL_ENTRY_HPP
#include "routing-table-entry.hpp"
#include "nexthop-list.hpp"
#include <iostream>
#include <ndn-cxx/name.hpp>
#include <unordered_map>
namespace nlsr {
/*! \brief A deduplication system for the NamePrefixTable
*
* The NamePrefixTable associates name prefixes to a router. To do
* this, it needs to know if certain routers are reachable. This in
* turn requires access to entries from the RoutingTable, which are
* associated with name prefixes. Doing this naively copies the entry
* from the RoutingTable each time, which is costly. This class
* provides a deduplication system where the NamePrefixTable can
* maintain a collection of RoutingTablePoolEntries. Then, this new
* class can be associated with the name prefixes instead of the
* original entries, which provides a minimal memory solution.
* \sa NamePrefixTable
*/
class NamePrefixTableEntry;
class RoutingTablePoolEntry : public RoutingTableEntry
{
public:
RoutingTablePoolEntry()
{
}
~RoutingTablePoolEntry()
{
}
RoutingTablePoolEntry(const ndn::Name& dest)
{
m_destination = dest;
m_useCount = 1;
}
RoutingTablePoolEntry(RoutingTableEntry& rte, uint64_t useCount)
{
m_destination = rte.getDestination();
m_nexthopList = rte.getNexthopList();
m_useCount = useCount;
}
RoutingTablePoolEntry(const ndn::Name& dest, uint64_t useCount)
{
m_destination = dest;
m_useCount = useCount;
}
uint64_t
getUseCount()
{
return m_useCount;
}
uint64_t
incrementUseCount()
{
return ++m_useCount;
}
uint64_t
decrementUseCount()
{
if (m_useCount != 0) {
return --m_useCount;
}
return 0;
}
void
setNexthopList(NexthopList nhl)
{
m_nexthopList = nhl;
}
public:
std::unordered_map<ndn::Name, std::weak_ptr<NamePrefixTableEntry>>
namePrefixTableEntries;
private:
uint64_t m_useCount;
};
bool
operator==(const RoutingTablePoolEntry& lhs, const RoutingTablePoolEntry& rhs);
std::ostream&
operator<<(std::ostream& os, RoutingTablePoolEntry& rtpe);
} // namespace nlsr
#endif // NLSR_ROUTING_TABLE_POOL_ENTRY_HPP