name-prefix-table-entry.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
23 
24 #include "common.hpp"
25 #include "nexthop.hpp"
26 #include "logger.hpp"
27 
28 namespace nlsr {
29 
30 INIT_LOGGER("NamePrefixTableEntry");
31 
32 void
34 {
35  m_nexthopList.reset();
36  for (auto iterator = m_rteList.begin(); iterator != m_rteList.end(); ++iterator) {
37  for (auto nhItr = (*iterator)->getNexthopList().getNextHops().begin();
38  nhItr != (*iterator)->getNexthopList().getNextHops().end();
39  ++nhItr) {
40  m_nexthopList.addNextHop((*nhItr));
41  }
42  }
43 }
44 
45 uint64_t
46 NamePrefixTableEntry::removeRoutingTableEntry(std::shared_ptr<RoutingTablePoolEntry>
47  entryPtr)
48 {
49  auto iterator = std::find(m_rteList.begin(), m_rteList.end(), entryPtr);
50 
51  if (iterator != m_rteList.end()) {
52  (*iterator)->decrementUseCount();
53  // Remove this NamePrefixEntry from the RoutingTablePoolEntry
54  (*iterator)->namePrefixTableEntries.erase(getNamePrefix());
55  m_rteList.erase(iterator);
56  }
57  else {
58  NLSR_LOG_ERROR("Routing entry for: " << entryPtr->getDestination()
59  << " not found in NPT entry: " << getNamePrefix());
60  }
61  return entryPtr->getUseCount();
62 }
63 
64 void
65 NamePrefixTableEntry::addRoutingTableEntry(std::shared_ptr<RoutingTablePoolEntry>
66  entryPtr)
67 {
68  auto iterator = std::find(m_rteList.begin(), m_rteList.end(), entryPtr);
69 
70  // Ensure that this is a new entry
71  if (iterator == m_rteList.end()) {
72  // Adding a new routing entry to the NPT entry
73  entryPtr->incrementUseCount();
74  m_rteList.push_back(entryPtr);
75  }
76  // Note: we don't need to update in the else case because these are
77  // pointers, and they are centrally-located in the NPT and will all
78  // be updated there.
79 }
80 
81 void
83 {
84  NLSR_LOG_DEBUG("Name: " << m_namePrefix);
85  for (auto it = m_rteList.begin(); it != m_rteList.end(); ++it) {
86  NLSR_LOG_DEBUG("Destination: " << (*it)->getDestination());
87  NLSR_LOG_DEBUG("Nexthops: ");
88  (*it)->getNexthopList().writeLog();
89  }
90  m_nexthopList.writeLog();
91 }
92 
93 bool
95 {
96  return (lhs.getNamePrefix() == rhs.getNamePrefix());
97 }
98 
99 bool
100 operator==(const NamePrefixTableEntry& lhs, const ndn::Name& rhs)
101 {
102  return (lhs.getNamePrefix() == rhs);
103 }
104 
105 std::ostream&
106 operator<<(std::ostream& os, const NamePrefixTableEntry& entry)
107 {
108  os << "Name: " << entry.getNamePrefix() << "\n";
109 
110  for (const std::shared_ptr<RoutingTablePoolEntry> entryPtr : entry.getRteList()) {
111  os << "Destination: " << entryPtr->getDestination() << "\n";
112  }
113 
114  return os;
115 }
116 
117 } // namespace nlsr
const ndn::Name & getNamePrefix() const
void addRoutingTableEntry(std::shared_ptr< RoutingTablePoolEntry > rtpePtr)
Adds a routing entry to this NPT entry.
std::ostream & operator<<(std::ostream &os, const Adjacent &adjacent)
Definition: adjacent.cpp:83
bool operator==(const NamePrefixTableEntry &lhs, const NamePrefixTableEntry &rhs)
const std::list< std::shared_ptr< RoutingTablePoolEntry > > & getRteList() const
#define NLSR_LOG_DEBUG(x)
Definition: logger.hpp:41
Copyright (c) 2014-2017, The University of Memphis, Regents of the University of California.
#define INIT_LOGGER(name)
Definition: logger.hpp:35
Copyright (c) 2014-2017, The University of Memphis, Regents of the University of California.
uint64_t removeRoutingTableEntry(std::shared_ptr< RoutingTablePoolEntry > rtpePtr)
Removes a routing entry from this NPT entry.
#define NLSR_LOG_ERROR(x)
Definition: logger.hpp:50
Copyright (c) 2014-2017, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
void addNextHop(const NextHop &nh)
Adds a next hop to the list.
void generateNhlfromRteList()
Collect all next-hops that are advertised by this entry&#39;s routing entries.