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 | /* |
Junxiao Shi | 29b91ff | 2024-02-22 04:11:47 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2024, 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: |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 35 | using const_iterator = std::list<Adjacent>::const_iterator; |
| 36 | using iterator = std::list<Adjacent>::iterator; |
alvy | dce3f18 | 2015-04-09 11:23:30 -0500 | [diff] [blame] | 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 |
Junxiao Shi | 29b91ff | 2024-02-22 04:11:47 +0000 | [diff] [blame] | 87 | getAdjacent(const ndn::Name& adjName) const; |
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 | |
akmhoque | 102aea4 | 2014-08-04 10:22:12 -0500 | [diff] [blame] | 113 | uint64_t |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 114 | getFaceId(const ndn::FaceUri& faceUri); |
akmhoque | 102aea4 | 2014-08-04 10:22:12 -0500 | [diff] [blame] | 115 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 116 | void |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 117 | writeLog(); |
| 118 | |
alvy | dce3f18 | 2015-04-09 11:23:30 -0500 | [diff] [blame] | 119 | public: |
| 120 | const_iterator |
| 121 | begin() const |
| 122 | { |
| 123 | return m_adjList.begin(); |
| 124 | } |
| 125 | |
| 126 | const_iterator |
| 127 | end() const |
| 128 | { |
| 129 | return m_adjList.end(); |
| 130 | } |
| 131 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 132 | private: |
alvy | dce3f18 | 2015-04-09 11:23:30 -0500 | [diff] [blame] | 133 | iterator |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 134 | find(const ndn::Name& adjName); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 135 | |
Nick Gordon | 4964870 | 2018-01-22 11:57:33 -0600 | [diff] [blame] | 136 | const_iterator |
| 137 | find(const ndn::Name& adjName) const; |
| 138 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 139 | private: |
| 140 | std::list<Adjacent> m_adjList; |
| 141 | }; |
| 142 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame] | 143 | } // namespace nlsr |
Nick Gordon | c780a69 | 2017-04-27 18:03:02 -0500 | [diff] [blame] | 144 | #endif // NLSR_ADJACENCY_LIST_HPP |