akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 2 | /* |
Junxiao Shi | d6922b5 | 2024-01-14 19:50:34 +0000 | [diff] [blame^] | 3 | * Copyright (c) 2014-2024, The University of Memphis, |
Nick Gordon | f8b5bcd | 2016-08-11 15:06:50 -0500 | [diff] [blame] | 4 | * Regents of the University of California |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 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/>. |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 19 | */ |
Nick Gordon | 22b5c95 | 2017-08-10 17:48:15 -0500 | [diff] [blame] | 20 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 21 | #ifndef NLSR_MAP_HPP |
| 22 | #define NLSR_MAP_HPP |
| 23 | |
Nick Gordon | 22b5c95 | 2017-08-10 17:48:15 -0500 | [diff] [blame] | 24 | #include "common.hpp" |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 25 | #include "lsa/adj-lsa.hpp" |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 26 | |
Junxiao Shi | d6922b5 | 2024-01-14 19:50:34 +0000 | [diff] [blame^] | 27 | #include <boost/bimap.hpp> |
| 28 | #include <boost/bimap/unordered_set_of.hpp> |
Nick Gordon | e40377d | 2017-08-11 15:10:02 -0500 | [diff] [blame] | 29 | |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 30 | #include <optional> |
| 31 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 32 | namespace nlsr { |
| 33 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 34 | class Map |
| 35 | { |
| 36 | public: |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 37 | /*! \brief Add a map entry to this map. |
| 38 | \param rtrName The name of the router. |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 39 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 40 | Adds a router to this map. Each entry is also given an arbitrary, |
| 41 | ascending mappingNo (mapping number). |
| 42 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 43 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 44 | addEntry(const ndn::Name& rtrName); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 45 | |
Nick Gordon | 22b5c95 | 2017-08-10 17:48:15 -0500 | [diff] [blame] | 46 | /*! Populates the Map with AdjacencyLsas. |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 47 | |
Nick Gordon | 22b5c95 | 2017-08-10 17:48:15 -0500 | [diff] [blame] | 48 | \note IteratorType must an iterator type, and begin to end must represent a valid range. |
| 49 | */ |
| 50 | template<typename IteratorType> |
Nick Gordon | e8e03ac | 2016-07-07 14:24:38 -0500 | [diff] [blame] | 51 | void |
Nick Gordon | 22b5c95 | 2017-08-10 17:48:15 -0500 | [diff] [blame] | 52 | createFromAdjLsdb(IteratorType begin, IteratorType end) |
| 53 | { |
| 54 | BOOST_STATIC_ASSERT_MSG(is_iterator<IteratorType>::value, "IteratorType must be an iterator!"); |
| 55 | for (auto lsa = begin; lsa != end; lsa++) { |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 56 | auto adjLsa = std::static_pointer_cast<AdjLsa>(*lsa); |
| 57 | addEntry(adjLsa->getOriginRouter()); |
| 58 | for (const auto& adjacent : adjLsa->getAdl().getAdjList()) { |
Nick Gordon | 22b5c95 | 2017-08-10 17:48:15 -0500 | [diff] [blame] | 59 | addEntry(adjacent.getName()); |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | /*! Populates the Map with CoordinateLsas. |
| 65 | |
| 66 | \note IteratorType must an iterator type, and begin to end must represent a valid range. |
| 67 | */ |
| 68 | template<typename IteratorType> |
| 69 | void |
| 70 | createFromCoordinateLsdb(IteratorType begin, IteratorType end) |
| 71 | { |
| 72 | BOOST_STATIC_ASSERT_MSG(is_iterator<IteratorType>::value, "IteratorType must be an iterator!"); |
| 73 | for (auto lsa = begin; lsa != end; lsa++) { |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 74 | addEntry((*lsa)->getOriginRouter()); |
Nick Gordon | 22b5c95 | 2017-08-10 17:48:15 -0500 | [diff] [blame] | 75 | } |
| 76 | } |
Nick Gordon | e8e03ac | 2016-07-07 14:24:38 -0500 | [diff] [blame] | 77 | |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 78 | std::optional<ndn::Name> |
Saurab Dulal | 9da6aa7 | 2018-01-12 17:25:51 +0000 | [diff] [blame] | 79 | getRouterNameByMappingNo(int32_t mn) const; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 80 | |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 81 | std::optional<int32_t> |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 82 | getMappingNoByRouterName(const ndn::Name& rName); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 83 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 84 | size_t |
Junxiao Shi | d6922b5 | 2024-01-14 19:50:34 +0000 | [diff] [blame^] | 85 | size() const |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 86 | { |
Junxiao Shi | d6922b5 | 2024-01-14 19:50:34 +0000 | [diff] [blame^] | 87 | return m_bimap.size(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 88 | } |
| 89 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 90 | private: |
Junxiao Shi | d6922b5 | 2024-01-14 19:50:34 +0000 | [diff] [blame^] | 91 | struct MappingNo; |
| 92 | boost::bimap< |
| 93 | boost::bimaps::unordered_set_of< |
| 94 | boost::bimaps::tagged<ndn::Name, ndn::Name>, |
| 95 | std::hash<ndn::Name> |
| 96 | >, |
| 97 | boost::bimaps::unordered_set_of< |
| 98 | boost::bimaps::tagged<int32_t, MappingNo> |
| 99 | > |
| 100 | > m_bimap; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 101 | |
Junxiao Shi | d6922b5 | 2024-01-14 19:50:34 +0000 | [diff] [blame^] | 102 | friend std::ostream& |
| 103 | operator<<(std::ostream& os, const Map& map); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 104 | }; |
| 105 | |
Junxiao Shi | d6922b5 | 2024-01-14 19:50:34 +0000 | [diff] [blame^] | 106 | std::ostream& |
| 107 | operator<<(std::ostream& os, const Map& map); |
| 108 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 109 | } // namespace nlsr |
Nick Gordon | 22b5c95 | 2017-08-10 17:48:15 -0500 | [diff] [blame] | 110 | |
| 111 | #endif // NLSR_MAP_HPP |