Loading...
Searching...
No Matches
name-prefix-table-entry.cpp
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2014-2020, The University of Memphis,
4 * Regents of the University of California,
5 * Arizona Board of Regents.
6 *
7 * This file is part of NLSR (Named-data Link State Routing).
8 * See AUTHORS.md for complete list of NLSR authors and contributors.
9 *
10 * NLSR is free software: you can redistribute it and/or modify it under the terms
11 * of the GNU General Public License as published by the Free Software Foundation,
12 * either version 3 of the License, or (at your option) any later version.
13 *
14 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 * PURPOSE. See the GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
20 */
21
23
24#include "common.hpp"
25#include "nexthop.hpp"
26#include "logger.hpp"
27
28namespace nlsr {
29
30INIT_LOGGER(route.NamePrefixTableEntry);
31
32void
34{
35 m_nexthopList.clear();
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
45uint64_t
46NamePrefixTableEntry::removeRoutingTableEntry(std::shared_ptr<RoutingTablePoolEntry> entryPtr)
47{
48 auto iterator = std::find(m_rteList.begin(), m_rteList.end(), entryPtr);
49
50 if (iterator != m_rteList.end()) {
51 (*iterator)->decrementUseCount();
52 // Remove this NamePrefixEntry from the RoutingTablePoolEntry
53 (*iterator)->namePrefixTableEntries.erase(getNamePrefix());
54 m_rteList.erase(iterator);
55 }
56 else {
57 NLSR_LOG_ERROR("Routing entry for: " << entryPtr->getDestination()
58 << " not found in NPT entry: " << getNamePrefix());
59 }
60 return entryPtr->getUseCount();
61}
62
63void
64NamePrefixTableEntry::addRoutingTableEntry(std::shared_ptr<RoutingTablePoolEntry> entryPtr)
65{
66 auto iterator = std::find(m_rteList.begin(), m_rteList.end(), entryPtr);
67
68 // Ensure that this is a new entry
69 if (iterator == m_rteList.end()) {
70 // Adding a new routing entry to the NPT entry
71 entryPtr->incrementUseCount();
72 m_rteList.push_back(entryPtr);
73 }
74 // Note: we don't need to update in the else case because these are
75 // pointers, and they are centrally-located in the NPT and will all
76 // be updated there.
77}
78
79bool
81{
82 return lhs.getNamePrefix() == rhs.getNamePrefix();
83}
84
85bool
86operator==(const NamePrefixTableEntry& lhs, const ndn::Name& rhs)
87{
88 return lhs.getNamePrefix() == rhs;
89}
90
91std::ostream&
92operator<<(std::ostream& os, const NamePrefixTableEntry& entry)
93{
94 os << "Name: " << entry.getNamePrefix() << "\n";
95
96 for (const auto& entryPtr : entry.getRteList()) {
97 os << " Destination: " << entryPtr->getDestination() << "\n";
98 os << entryPtr->getNexthopList();
99 }
100 return os;
101}
102
103} // namespace nlsr
uint64_t removeRoutingTableEntry(std::shared_ptr< RoutingTablePoolEntry > rtpePtr)
Removes a routing entry from this NPT entry.
const ndn::Name & getNamePrefix() const
void generateNhlfromRteList()
Collect all next-hops that are advertised by this entry's routing entries.
void addRoutingTableEntry(std::shared_ptr< RoutingTablePoolEntry > rtpePtr)
Adds a routing entry to this NPT entry.
const std::list< std::shared_ptr< RoutingTablePoolEntry > > & getRteList() const
void addNextHop(const NextHop &nh)
Adds a next hop to the list.
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California.
#define INIT_LOGGER(name)
Definition logger.hpp:35
#define NLSR_LOG_ERROR(x)
Definition logger.hpp:41
Copyright (c) 2014-2020, The University of Memphis, Regents of the University of California.
std::ostream & operator<<(std::ostream &os, const Adjacent &adjacent)
Definition adjacent.cpp:176
bool operator==(const NamePrefixTableEntry &lhs, const NamePrefixTableEntry &rhs)