Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | d90338d | 2021-01-07 17:50:05 -0500 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2014-2021, The University of Memphis, |
alvy | dce3f18 | 2015-04-09 11:23:30 -0500 | [diff] [blame] | 4 | * Regents of the University of California, |
| 5 | * Arizona Board of Regents. |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 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/>. |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 20 | **/ |
alvy | dce3f18 | 2015-04-09 11:23:30 -0500 | [diff] [blame] | 21 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 22 | #ifndef NLSR_ADJACENCY_LIST_HPP |
| 23 | #define NLSR_ADJACENCY_LIST_HPP |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 24 | |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 25 | #include "adjacent.hpp" |
Nick Gordon | e98480b | 2017-05-24 11:23:03 -0500 | [diff] [blame] | 26 | #include "common.hpp" |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 27 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 28 | #include <list> |
| 29 | |
| 30 | namespace nlsr { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 31 | |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 32 | class AdjacencyList |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 33 | { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 34 | public: |
alvy | dce3f18 | 2015-04-09 11:23:30 -0500 | [diff] [blame] | 35 | typedef std::list<Adjacent>::const_iterator const_iterator; |
| 36 | typedef std::list<Adjacent>::iterator iterator; |
| 37 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 38 | bool |
Davide Pesavento | d90338d | 2021-01-07 17:50:05 -0500 | [diff] [blame] | 39 | insert(const Adjacent& adjacent); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 40 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 41 | std::list<Adjacent>& |
| 42 | getAdjList(); |
| 43 | |
Nick Gordon | 22b5c95 | 2017-08-10 17:48:15 -0500 | [diff] [blame] | 44 | const std::list<Adjacent>& |
| 45 | getAdjList() const; |
| 46 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 47 | bool |
Nick Gordon | 4964870 | 2018-01-22 11:57:33 -0600 | [diff] [blame] | 48 | isNeighbor(const ndn::Name& adjName) const; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 49 | |
| 50 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 51 | incrementTimedOutInterestCount(const ndn::Name& neighbor); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 52 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 53 | int32_t |
Nick Gordon | 4964870 | 2018-01-22 11:57:33 -0600 | [diff] [blame] | 54 | getTimedOutInterestCount(const ndn::Name& neighbor) const; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 55 | |
Vince Lehman | cb76ade | 2014-08-28 21:24:41 -0500 | [diff] [blame] | 56 | Adjacent::Status |
Nick Gordon | 4964870 | 2018-01-22 11:57:33 -0600 | [diff] [blame] | 57 | getStatusOfNeighbor(const ndn::Name& neighbor) const; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 58 | |
| 59 | void |
Vince Lehman | cb76ade | 2014-08-28 21:24:41 -0500 | [diff] [blame] | 60 | setStatusOfNeighbor(const ndn::Name& neighbor, Adjacent::Status status); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 61 | |
| 62 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 63 | setTimedOutInterestCount(const ndn::Name& neighbor, uint32_t count); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 64 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 65 | /*! \brief Determines whether this list can be used to build an adj. LSA. |
| 66 | \param interestRetryNo The maximum number of hello-interest |
| 67 | retries to contact a neighbor. |
| 68 | |
| 69 | \return Returns a boolean indicating whether this list can be used |
| 70 | to build an adj. LSA. |
| 71 | |
| 72 | Determines whether this adjacency list object could be used to |
| 73 | build an adjacency LSA. An LSA is buildable when the status of all |
| 74 | neighbors is known. A neighbor's status is known when their status |
| 75 | is ACTIVE, or INACTIVE and some number of hello interests |
| 76 | (specified by nlsr::ConfParameter::getInterestRetryNumber()) have |
| 77 | failed. To be explicit, a neighbor's status is unknown if we are |
| 78 | still sending hello interests. |
| 79 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 80 | bool |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 81 | isAdjLsaBuildable(const uint32_t interestRetryNo) const; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 82 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 83 | int32_t |
Nick Gordon | 4964870 | 2018-01-22 11:57:33 -0600 | [diff] [blame] | 84 | getNumOfActiveNeighbor() const; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 85 | |
| 86 | Adjacent |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 87 | getAdjacent(const ndn::Name& adjName); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 88 | |
| 89 | bool |
Nick Gordon | 4964870 | 2018-01-22 11:57:33 -0600 | [diff] [blame] | 90 | operator==(const AdjacencyList& adl) const; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 91 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 92 | size_t |
Nick Gordon | ff9a627 | 2017-10-12 13:38:29 -0500 | [diff] [blame] | 93 | size() const |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 94 | { |
| 95 | return m_adjList.size(); |
| 96 | } |
| 97 | |
| 98 | void |
| 99 | reset() |
| 100 | { |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 101 | m_adjList.clear(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 102 | } |
| 103 | |
Nick Gordon | c780a69 | 2017-04-27 18:03:02 -0500 | [diff] [blame] | 104 | AdjacencyList::iterator |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 105 | findAdjacent(const ndn::Name& adjName); |
| 106 | |
Nick Gordon | c780a69 | 2017-04-27 18:03:02 -0500 | [diff] [blame] | 107 | AdjacencyList::iterator |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 108 | findAdjacent(uint64_t faceId); |
| 109 | |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 110 | AdjacencyList::iterator |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 111 | findAdjacent(const ndn::FaceUri& faceUri); |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 112 | |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 113 | /*! \brief Hack to stop developers from using this function |
| 114 | |
| 115 | It is here so that faceUri cannot be passed in as string, |
| 116 | converted to Name and findAdjacent(Name) be used. |
| 117 | So when faceUri is passed as string this will cause a compile error |
| 118 | */ |
| 119 | template <typename T = float> void |
| 120 | findAdjacent(const std::string& faceUri) |
| 121 | { |
| 122 | BOOST_STATIC_ASSERT_MSG(std::is_integral<T>::value, |
| 123 | "Don't use std::string with findAdjacent!"); |
| 124 | } |
| 125 | |
akmhoque | 102aea4 | 2014-08-04 10:22:12 -0500 | [diff] [blame] | 126 | uint64_t |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 127 | getFaceId(const ndn::FaceUri& faceUri); |
akmhoque | 102aea4 | 2014-08-04 10:22:12 -0500 | [diff] [blame] | 128 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 129 | void |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 130 | writeLog(); |
| 131 | |
alvy | dce3f18 | 2015-04-09 11:23:30 -0500 | [diff] [blame] | 132 | public: |
| 133 | const_iterator |
| 134 | begin() const |
| 135 | { |
| 136 | return m_adjList.begin(); |
| 137 | } |
| 138 | |
| 139 | const_iterator |
| 140 | end() const |
| 141 | { |
| 142 | return m_adjList.end(); |
| 143 | } |
| 144 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 145 | private: |
alvy | dce3f18 | 2015-04-09 11:23:30 -0500 | [diff] [blame] | 146 | iterator |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 147 | find(const ndn::Name& adjName); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 148 | |
Nick Gordon | 4964870 | 2018-01-22 11:57:33 -0600 | [diff] [blame] | 149 | const_iterator |
| 150 | find(const ndn::Name& adjName) const; |
| 151 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 152 | private: |
| 153 | std::list<Adjacent> m_adjList; |
| 154 | }; |
| 155 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame] | 156 | } // namespace nlsr |
Nick Gordon | c780a69 | 2017-04-27 18:03:02 -0500 | [diff] [blame] | 157 | #endif // NLSR_ADJACENCY_LIST_HPP |