Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 2 | /** |
Nick Gordon | c6a8522 | 2017-01-03 16:54:34 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, 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 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 25 | #include <list> |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 26 | #include <boost/cstdint.hpp> |
| 27 | #include <ndn-cxx/common.hpp> |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 28 | |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 29 | #include "adjacent.hpp" |
| 30 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 31 | namespace nlsr { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 32 | |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 33 | class AdjacencyList |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 34 | { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 35 | public: |
alvy | dce3f18 | 2015-04-09 11:23:30 -0500 | [diff] [blame] | 36 | typedef std::list<Adjacent>::const_iterator const_iterator; |
| 37 | typedef std::list<Adjacent>::iterator iterator; |
| 38 | |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 39 | AdjacencyList(); |
| 40 | ~AdjacencyList(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 41 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 42 | /*! \brief Inserts an adjacency into the list. |
| 43 | |
| 44 | \param adjacent The adjacency that we want to add to this list. |
| 45 | |
| 46 | \retval 0 Indicates success. |
| 47 | \retval 1 Indicates failure. |
| 48 | |
| 49 | This function attempts to insert the supplied adjacency into this |
| 50 | object, which is an adjacency list. |
| 51 | */ |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 52 | int32_t |
| 53 | insert(Adjacent& adjacent); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 54 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 55 | /*! \brief Sets the status of an adjacency. |
| 56 | |
| 57 | \param adjName The adjacency in this list you want to change the status of. |
| 58 | |
| 59 | \param s The status to change to. |
| 60 | |
| 61 | \return A boolean indicating whether an adjacency was |
| 62 | updated. This is false if s is not in the list. |
| 63 | */ |
Vince Lehman | cb76ade | 2014-08-28 21:24:41 -0500 | [diff] [blame] | 64 | bool |
| 65 | updateAdjacentStatus(const ndn::Name& adjName, Adjacent::Status s); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 66 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 67 | int32_t |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 68 | updateAdjacentLinkCost(const ndn::Name& adjName, double lc); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 69 | |
| 70 | std::list<Adjacent>& |
| 71 | getAdjList(); |
| 72 | |
| 73 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 74 | isNeighbor(const ndn::Name& adjName); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 75 | |
| 76 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 77 | incrementTimedOutInterestCount(const ndn::Name& neighbor); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 78 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 79 | int32_t |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 80 | getTimedOutInterestCount(const ndn::Name& neighbor); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 81 | |
Vince Lehman | cb76ade | 2014-08-28 21:24:41 -0500 | [diff] [blame] | 82 | Adjacent::Status |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 83 | getStatusOfNeighbor(const ndn::Name& neighbor); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 84 | |
| 85 | void |
Vince Lehman | cb76ade | 2014-08-28 21:24:41 -0500 | [diff] [blame] | 86 | setStatusOfNeighbor(const ndn::Name& neighbor, Adjacent::Status status); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 87 | |
| 88 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 89 | setTimedOutInterestCount(const ndn::Name& neighbor, uint32_t count); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 90 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 91 | /*! \brief Copies the adjacencies in a list to this one. |
| 92 | |
| 93 | \param adl The adjacency list, the entries of which we want to |
| 94 | copy into this object. |
| 95 | |
| 96 | Copies the entries contained in one list into this object. |
| 97 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 98 | void |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 99 | addAdjacents(AdjacencyList& adl); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 100 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 101 | /*! \brief Determines whether this list can be used to build an adj. LSA. |
| 102 | \param interestRetryNo The maximum number of hello-interest |
| 103 | retries to contact a neighbor. |
| 104 | |
| 105 | \return Returns a boolean indicating whether this list can be used |
| 106 | to build an adj. LSA. |
| 107 | |
| 108 | Determines whether this adjacency list object could be used to |
| 109 | build an adjacency LSA. An LSA is buildable when the status of all |
| 110 | neighbors is known. A neighbor's status is known when their status |
| 111 | is ACTIVE, or INACTIVE and some number of hello interests |
| 112 | (specified by nlsr::ConfParameter::getInterestRetryNumber()) have |
| 113 | failed. To be explicit, a neighbor's status is unknown if we are |
| 114 | still sending hello interests. |
| 115 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 116 | bool |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 117 | isAdjLsaBuildable(const uint32_t interestRetryNo) const; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 118 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 119 | int32_t |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 120 | getNumOfActiveNeighbor(); |
| 121 | |
| 122 | Adjacent |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 123 | getAdjacent(const ndn::Name& adjName); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 124 | |
| 125 | bool |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 126 | operator==(AdjacencyList& adl); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 127 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 128 | size_t |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 129 | getSize() |
| 130 | { |
| 131 | return m_adjList.size(); |
| 132 | } |
| 133 | |
| 134 | void |
| 135 | reset() |
| 136 | { |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 137 | if (m_adjList.size() > 0) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 138 | m_adjList.clear(); |
| 139 | } |
| 140 | } |
| 141 | |
Nick Gordon | c780a69 | 2017-04-27 18:03:02 -0500 | [diff] [blame] | 142 | AdjacencyList::iterator |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 143 | findAdjacent(const ndn::Name& adjName); |
| 144 | |
Nick Gordon | c780a69 | 2017-04-27 18:03:02 -0500 | [diff] [blame] | 145 | AdjacencyList::iterator |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 146 | findAdjacent(uint64_t faceId); |
| 147 | |
akmhoque | 102aea4 | 2014-08-04 10:22:12 -0500 | [diff] [blame] | 148 | uint64_t |
| 149 | getFaceId(const std::string& faceUri); |
| 150 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 151 | void |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 152 | writeLog(); |
| 153 | |
alvy | dce3f18 | 2015-04-09 11:23:30 -0500 | [diff] [blame] | 154 | public: |
| 155 | const_iterator |
| 156 | begin() const |
| 157 | { |
| 158 | return m_adjList.begin(); |
| 159 | } |
| 160 | |
| 161 | const_iterator |
| 162 | end() const |
| 163 | { |
| 164 | return m_adjList.end(); |
| 165 | } |
| 166 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 167 | private: |
alvy | dce3f18 | 2015-04-09 11:23:30 -0500 | [diff] [blame] | 168 | iterator |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 169 | find(const ndn::Name& adjName); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 170 | |
| 171 | private: |
| 172 | std::list<Adjacent> m_adjList; |
| 173 | }; |
| 174 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame] | 175 | } // namespace nlsr |
Nick Gordon | c780a69 | 2017-04-27 18:03:02 -0500 | [diff] [blame] | 176 | #endif // NLSR_ADJACENCY_LIST_HPP |