map.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2022, The University of Memphis,
4  * Regents of the University of California
5  *
6  * This file is part of NLSR (Named-data Link State Routing).
7  * See AUTHORS.md for complete list of NLSR authors and contributors.
8  *
9  * NLSR is free software: you can redistribute it and/or modify it under the terms
10  * of the GNU General Public License as published by the Free Software Foundation,
11  * either version 3 of the License, or (at your option) any later version.
12  *
13  * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
14  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #include "map.hpp"
22 #include "nlsr.hpp"
23 #include "adjacent.hpp"
24 #include "lsa/lsa.hpp"
25 #include "lsdb.hpp"
26 #include "logger.hpp"
27 
28 namespace nlsr {
29 
30 INIT_LOGGER(route.Map);
31 
32 void
33 Map::addEntry(const ndn::Name& rtrName)
34 {
35  MapEntry me {rtrName, m_mappingIndex};
36  if (addEntry(me)) {
37  m_mappingIndex++;
38  }
39 }
40 
41 bool
43 {
44  return m_entries.insert(mpe).second;
45 }
46 
47 std::optional<ndn::Name>
49 {
50  auto&& mappingNumberView = m_entries.get<detail::byMappingNumber>();
51  auto it = mappingNumberView.find(mn);
52  return it == mappingNumberView.end() ? std::nullopt : std::optional(it->router);
53 }
54 
55 std::optional<int32_t>
56 Map::getMappingNoByRouterName(const ndn::Name& rName)
57 {
58  auto&& routerNameView = m_entries.get<detail::byRouterName>();
59  auto it = routerNameView.find(rName);
60  return it == routerNameView.end() ? std::nullopt : std::optional(it->mappingNumber);
61 }
62 
63 void
65 {
66  NLSR_LOG_DEBUG("---------------Map----------------------");
67  for (const auto& entry : m_entries.get<detail::byRouterName>()) {
68  NLSR_LOG_DEBUG("MapEntry: ( Router: " << entry.router << " Mapping No: " <<
69  entry.mappingNumber << " )");
70  }
71 }
72 
73 } // namespace nlsr
void writeLog()
Definition: map.cpp:64
void addEntry(const ndn::Name &rtrName)
Add a map entry to this map.
Definition: map.cpp:33
std::optional< int32_t > getMappingNoByRouterName(const ndn::Name &rName)
Definition: map.cpp:56
std::optional< ndn::Name > getRouterNameByMappingNo(int32_t mn) const
Definition: map.cpp:48
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California.
#define NLSR_LOG_DEBUG(x)
Definition: logger.hpp:38
#define INIT_LOGGER(name)
Definition: logger.hpp:35
Copyright (c) 2014-2020, The University of Memphis, Regents of the University of California.
Definition: map.hpp:37