akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Nick Gordon | c6a8522 | 2017-01-03 16:54:34 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, 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/>. |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [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" |
| 25 | #include "map-entry.hpp" |
| 26 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 27 | #include <iostream> |
| 28 | #include <list> |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 29 | #include <boost/cstdint.hpp> |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 30 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 31 | namespace nlsr { |
| 32 | |
| 33 | class Nlsr; |
| 34 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 35 | class Map |
| 36 | { |
| 37 | public: |
| 38 | Map() |
| 39 | : m_mappingIndex(0) |
| 40 | { |
| 41 | } |
| 42 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 43 | /*! \brief Add a map entry to this map. |
| 44 | \param rtrName The name of the router. |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 45 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 46 | Adds a router to this map. Each entry is also given an arbitrary, |
| 47 | ascending mappingNo (mapping number). |
| 48 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 49 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 50 | addEntry(const ndn::Name& rtrName); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 51 | |
Nick Gordon | 22b5c95 | 2017-08-10 17:48:15 -0500 | [diff] [blame^] | 52 | /*! Populates the Map with AdjacencyLsas. |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 53 | |
Nick Gordon | 22b5c95 | 2017-08-10 17:48:15 -0500 | [diff] [blame^] | 54 | \note IteratorType must an iterator type, and begin to end must represent a valid range. |
| 55 | */ |
| 56 | template<typename IteratorType> |
Nick Gordon | e8e03ac | 2016-07-07 14:24:38 -0500 | [diff] [blame] | 57 | void |
Nick Gordon | 22b5c95 | 2017-08-10 17:48:15 -0500 | [diff] [blame^] | 58 | createFromAdjLsdb(IteratorType begin, IteratorType end) |
| 59 | { |
| 60 | BOOST_STATIC_ASSERT_MSG(is_iterator<IteratorType>::value, "IteratorType must be an iterator!"); |
| 61 | for (auto lsa = begin; lsa != end; lsa++) { |
| 62 | addEntry(lsa->getOrigRouter()); |
| 63 | for (const auto& adjacent : lsa->getAdl().getAdjList()) { |
| 64 | addEntry(adjacent.getName()); |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | /*! Populates the Map with CoordinateLsas. |
| 70 | |
| 71 | \note IteratorType must an iterator type, and begin to end must represent a valid range. |
| 72 | */ |
| 73 | template<typename IteratorType> |
| 74 | void |
| 75 | createFromCoordinateLsdb(IteratorType begin, IteratorType end) |
| 76 | { |
| 77 | BOOST_STATIC_ASSERT_MSG(is_iterator<IteratorType>::value, "IteratorType must be an iterator!"); |
| 78 | for (auto lsa = begin; lsa != end; lsa++) { |
| 79 | addEntry(lsa->getOrigRouter()); |
| 80 | } |
| 81 | } |
Nick Gordon | e8e03ac | 2016-07-07 14:24:38 -0500 | [diff] [blame] | 82 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 83 | const ndn::Name |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 84 | getRouterNameByMappingNo(int32_t mn); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 85 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 86 | int32_t |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 87 | getMappingNoByRouterName(const ndn::Name& rName); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 88 | |
| 89 | void |
| 90 | reset(); |
| 91 | |
| 92 | std::list<MapEntry>& |
| 93 | getMapList() |
| 94 | { |
| 95 | return m_table; |
| 96 | } |
| 97 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 98 | size_t |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 99 | getMapSize() const |
| 100 | { |
| 101 | return m_table.size(); |
| 102 | } |
| 103 | |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 104 | void |
| 105 | writeLog(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 106 | |
| 107 | private: |
| 108 | bool |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 109 | addEntry(MapEntry& mpe); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 110 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 111 | int32_t m_mappingIndex; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 112 | std::list<MapEntry> m_table; |
| 113 | }; |
| 114 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 115 | } // namespace nlsr |
Nick Gordon | 22b5c95 | 2017-08-10 17:48:15 -0500 | [diff] [blame^] | 116 | |
| 117 | #endif // NLSR_MAP_HPP |