Loading...
Searching...
No Matches
name-map.hpp
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2014-2024, 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#ifndef NLSR_NAME_MAP_HPP
22#define NLSR_NAME_MAP_HPP
23
24#include "common.hpp"
25#include "lsa/adj-lsa.hpp"
26
27#include <boost/bimap.hpp>
28#include <boost/bimap/unordered_set_of.hpp>
29#include <boost/concept_check.hpp>
30
31#include <optional>
32
33namespace nlsr {
34
46{
47public:
56 template<typename IteratorType>
57 static NameMap
58 createFromAdjLsdb(IteratorType first, IteratorType last)
59 {
60 BOOST_CONCEPT_ASSERT((boost::InputIterator<IteratorType>));
62 for (auto it = first; it != last; ++it) {
63 // *it has type std::shared_ptr<Lsa> ; it->get() has type Lsa*
64 auto lsa = static_cast<const AdjLsa*>(it->get());
65 map.addEntry(lsa->getOriginRouter());
66 for (const auto& adjacent : lsa->getAdl().getAdjList()) {
67 map.addEntry(adjacent.getName());
68 }
69 }
70 return map;
71 }
72
80 template<typename IteratorType>
81 static NameMap
82 createFromCoordinateLsdb(IteratorType first, IteratorType last)
83 {
84 BOOST_CONCEPT_ASSERT((boost::InputIterator<IteratorType>));
86 for (auto it = first; it != last; ++it) {
87 map.addEntry((*it)->getOriginRouter());
88 }
89 return map;
90 }
91
96 void
97 addEntry(const ndn::Name& rtrName);
98
104 std::optional<ndn::Name>
105 getRouterNameByMappingNo(int32_t mn) const;
106
112 std::optional<int32_t>
113 getMappingNoByRouterName(const ndn::Name& rtrName) const;
114
119 size_t
120 size() const
121 {
122 return m_bimap.size();
123 }
124
125private:
126 struct MappingNo;
127 boost::bimap<
128 boost::bimaps::unordered_set_of<
129 boost::bimaps::tagged<ndn::Name, ndn::Name>,
130 std::hash<ndn::Name>
131 >,
132 boost::bimaps::unordered_set_of<
133 boost::bimaps::tagged<int32_t, MappingNo>
134 >
135 > m_bimap;
136
137 friend std::ostream&
138 operator<<(std::ostream& os, const NameMap& map);
139};
140
141std::ostream&
142operator<<(std::ostream& os, const NameMap& map);
143
144} // namespace nlsr
145
146#endif // NLSR_NAME_MAP_HPP
Represents an LSA of adjacencies of the origin router in link-state mode.
Definition adj-lsa.hpp:44
Assigning numbers to router names.
Definition name-map.hpp:46
std::optional< ndn::Name > getRouterNameByMappingNo(int32_t mn) const
Find router name by its mapping number.
Definition name-map.cpp:37
std::optional< int32_t > getMappingNoByRouterName(const ndn::Name &rtrName) const
Find mapping number of a router name.
Definition name-map.cpp:47
void addEntry(const ndn::Name &rtrName)
Insert a router name.
Definition name-map.cpp:30
friend std::ostream & operator<<(std::ostream &os, const NameMap &map)
Definition name-map.cpp:57
size_t size() const
Return number of entries in this container.
Definition name-map.hpp:120
static NameMap createFromCoordinateLsdb(IteratorType first, IteratorType last)
Create a NameMap populated with router names in Coordinate LSAs.
Definition name-map.hpp:82
static NameMap createFromAdjLsdb(IteratorType first, IteratorType last)
Create a NameMap populated with router names in Adjacency LSAs.
Definition name-map.hpp:58
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