blob: 2f2b1642b17ec033272e2cac39ad2362b436525d [file] [log] [blame]
Ashlesh Gawande793e8702017-08-01 15:59:26 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesaventod90338d2021-01-07 17:50:05 -05002/*
3 * Copyright (c) 2014-2021, The University of Memphis,
alvydce3f182015-04-09 11:23:30 -05004 * Regents of the University of California,
5 * Arizona Board of Regents.
akmhoque3d06e792014-05-27 16:23:20 -05006 *
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/>.
akmhoque3d06e792014-05-27 16:23:20 -050020 **/
alvydce3f182015-04-09 11:23:30 -050021
akmhoquefdbddb12014-05-02 18:35:19 -050022#ifndef NLSR_ADJACENCY_LIST_HPP
23#define NLSR_ADJACENCY_LIST_HPP
akmhoque53353462014-04-22 08:43:45 -050024
Ashlesh Gawande793e8702017-08-01 15:59:26 -050025#include "adjacent.hpp"
Nick Gordone98480b2017-05-24 11:23:03 -050026#include "common.hpp"
Ashlesh Gawande793e8702017-08-01 15:59:26 -050027
akmhoque53353462014-04-22 08:43:45 -050028#include <list>
29
30namespace nlsr {
akmhoque53353462014-04-22 08:43:45 -050031
akmhoquec8a10f72014-04-25 18:42:55 -050032class AdjacencyList
akmhoque53353462014-04-22 08:43:45 -050033{
akmhoque53353462014-04-22 08:43:45 -050034public:
alvydce3f182015-04-09 11:23:30 -050035 typedef std::list<Adjacent>::const_iterator const_iterator;
36 typedef std::list<Adjacent>::iterator iterator;
37
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080038 bool
Davide Pesaventod90338d2021-01-07 17:50:05 -050039 insert(const Adjacent& adjacent);
akmhoque53353462014-04-22 08:43:45 -050040
akmhoque53353462014-04-22 08:43:45 -050041 std::list<Adjacent>&
42 getAdjList();
43
Nick Gordon22b5c952017-08-10 17:48:15 -050044 const std::list<Adjacent>&
45 getAdjList() const;
46
akmhoque53353462014-04-22 08:43:45 -050047 bool
Nick Gordon49648702018-01-22 11:57:33 -060048 isNeighbor(const ndn::Name& adjName) const;
akmhoque53353462014-04-22 08:43:45 -050049
50 void
akmhoque31d1d4b2014-05-05 22:08:14 -050051 incrementTimedOutInterestCount(const ndn::Name& neighbor);
akmhoque53353462014-04-22 08:43:45 -050052
akmhoquefdbddb12014-05-02 18:35:19 -050053 int32_t
Nick Gordon49648702018-01-22 11:57:33 -060054 getTimedOutInterestCount(const ndn::Name& neighbor) const;
akmhoque53353462014-04-22 08:43:45 -050055
Vince Lehmancb76ade2014-08-28 21:24:41 -050056 Adjacent::Status
Nick Gordon49648702018-01-22 11:57:33 -060057 getStatusOfNeighbor(const ndn::Name& neighbor) const;
akmhoque53353462014-04-22 08:43:45 -050058
59 void
Vince Lehmancb76ade2014-08-28 21:24:41 -050060 setStatusOfNeighbor(const ndn::Name& neighbor, Adjacent::Status status);
akmhoque53353462014-04-22 08:43:45 -050061
62 void
akmhoque31d1d4b2014-05-05 22:08:14 -050063 setTimedOutInterestCount(const ndn::Name& neighbor, uint32_t count);
akmhoque53353462014-04-22 08:43:45 -050064
Nick G97e34942016-07-11 14:46:27 -050065 /*! \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 */
akmhoque53353462014-04-22 08:43:45 -050080 bool
Vince Lehmanf7eec4f2015-05-08 19:02:31 -050081 isAdjLsaBuildable(const uint32_t interestRetryNo) const;
akmhoque53353462014-04-22 08:43:45 -050082
akmhoquefdbddb12014-05-02 18:35:19 -050083 int32_t
Nick Gordon49648702018-01-22 11:57:33 -060084 getNumOfActiveNeighbor() const;
akmhoque53353462014-04-22 08:43:45 -050085
86 Adjacent
akmhoque31d1d4b2014-05-05 22:08:14 -050087 getAdjacent(const ndn::Name& adjName);
akmhoque53353462014-04-22 08:43:45 -050088
89 bool
Nick Gordon49648702018-01-22 11:57:33 -060090 operator==(const AdjacencyList& adl) const;
akmhoque53353462014-04-22 08:43:45 -050091
akmhoquefdbddb12014-05-02 18:35:19 -050092 size_t
Nick Gordonff9a6272017-10-12 13:38:29 -050093 size() const
akmhoque53353462014-04-22 08:43:45 -050094 {
95 return m_adjList.size();
96 }
97
98 void
99 reset()
100 {
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800101 m_adjList.clear();
akmhoque53353462014-04-22 08:43:45 -0500102 }
103
Nick Gordonc780a692017-04-27 18:03:02 -0500104 AdjacencyList::iterator
akmhoquec04e7272014-07-02 11:00:14 -0500105 findAdjacent(const ndn::Name& adjName);
106
Nick Gordonc780a692017-04-27 18:03:02 -0500107 AdjacencyList::iterator
akmhoquec04e7272014-07-02 11:00:14 -0500108 findAdjacent(uint64_t faceId);
109
Nick Gordone9733ed2017-04-26 10:48:39 -0500110 AdjacencyList::iterator
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500111 findAdjacent(const ndn::FaceUri& faceUri);
Nick Gordone9733ed2017-04-26 10:48:39 -0500112
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500113 /*! \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
akmhoque102aea42014-08-04 10:22:12 -0500126 uint64_t
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500127 getFaceId(const ndn::FaceUri& faceUri);
akmhoque102aea42014-08-04 10:22:12 -0500128
akmhoque53353462014-04-22 08:43:45 -0500129 void
akmhoque674b0b12014-05-20 14:33:28 -0500130 writeLog();
131
alvydce3f182015-04-09 11:23:30 -0500132public:
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
akmhoque53353462014-04-22 08:43:45 -0500145private:
alvydce3f182015-04-09 11:23:30 -0500146 iterator
akmhoque31d1d4b2014-05-05 22:08:14 -0500147 find(const ndn::Name& adjName);
akmhoque53353462014-04-22 08:43:45 -0500148
Nick Gordon49648702018-01-22 11:57:33 -0600149 const_iterator
150 find(const ndn::Name& adjName) const;
151
akmhoque53353462014-04-22 08:43:45 -0500152private:
153 std::list<Adjacent> m_adjList;
154};
155
Nick Gordonfad8e252016-08-11 14:21:38 -0500156} // namespace nlsr
Nick Gordonc780a692017-04-27 18:03:02 -0500157#endif // NLSR_ADJACENCY_LIST_HPP