blob: 66a2710b3ebc7c7c91b162e128d91c946fe40c95 [file] [log] [blame]
Ashlesh Gawande793e8702017-08-01 15:59:26 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
akmhoque3d06e792014-05-27 16:23:20 -05002/**
Nick Gordonc6a85222017-01-03 16:54:34 -06003 * Copyright (c) 2014-2017, 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>
akmhoquefdbddb12014-05-02 18:35:19 -050029#include <boost/cstdint.hpp>
akmhoque53353462014-04-22 08:43:45 -050030
31namespace nlsr {
akmhoque53353462014-04-22 08:43:45 -050032
akmhoquec8a10f72014-04-25 18:42:55 -050033class AdjacencyList
akmhoque53353462014-04-22 08:43:45 -050034{
akmhoque53353462014-04-22 08:43:45 -050035public:
alvydce3f182015-04-09 11:23:30 -050036 typedef std::list<Adjacent>::const_iterator const_iterator;
37 typedef std::list<Adjacent>::iterator iterator;
38
akmhoquec8a10f72014-04-25 18:42:55 -050039 AdjacencyList();
40 ~AdjacencyList();
akmhoque53353462014-04-22 08:43:45 -050041
Nick G97e34942016-07-11 14:46:27 -050042 /*! \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 */
akmhoquefdbddb12014-05-02 18:35:19 -050052 int32_t
53 insert(Adjacent& adjacent);
akmhoque53353462014-04-22 08:43:45 -050054
Nick G97e34942016-07-11 14:46:27 -050055 /*! \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 Lehmancb76ade2014-08-28 21:24:41 -050064 bool
65 updateAdjacentStatus(const ndn::Name& adjName, Adjacent::Status s);
akmhoque53353462014-04-22 08:43:45 -050066
akmhoquefdbddb12014-05-02 18:35:19 -050067 int32_t
akmhoque31d1d4b2014-05-05 22:08:14 -050068 updateAdjacentLinkCost(const ndn::Name& adjName, double lc);
akmhoque53353462014-04-22 08:43:45 -050069
70 std::list<Adjacent>&
71 getAdjList();
72
Nick Gordon22b5c952017-08-10 17:48:15 -050073 const std::list<Adjacent>&
74 getAdjList() const;
75
akmhoque53353462014-04-22 08:43:45 -050076 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050077 isNeighbor(const ndn::Name& adjName);
akmhoque53353462014-04-22 08:43:45 -050078
79 void
akmhoque31d1d4b2014-05-05 22:08:14 -050080 incrementTimedOutInterestCount(const ndn::Name& neighbor);
akmhoque53353462014-04-22 08:43:45 -050081
akmhoquefdbddb12014-05-02 18:35:19 -050082 int32_t
akmhoque31d1d4b2014-05-05 22:08:14 -050083 getTimedOutInterestCount(const ndn::Name& neighbor);
akmhoque53353462014-04-22 08:43:45 -050084
Vince Lehmancb76ade2014-08-28 21:24:41 -050085 Adjacent::Status
akmhoque31d1d4b2014-05-05 22:08:14 -050086 getStatusOfNeighbor(const ndn::Name& neighbor);
akmhoque53353462014-04-22 08:43:45 -050087
88 void
Vince Lehmancb76ade2014-08-28 21:24:41 -050089 setStatusOfNeighbor(const ndn::Name& neighbor, Adjacent::Status status);
akmhoque53353462014-04-22 08:43:45 -050090
91 void
akmhoque31d1d4b2014-05-05 22:08:14 -050092 setTimedOutInterestCount(const ndn::Name& neighbor, uint32_t count);
akmhoque53353462014-04-22 08:43:45 -050093
Nick G97e34942016-07-11 14:46:27 -050094 /*! \brief Copies the adjacencies in a list to this one.
95
96 \param adl The adjacency list, the entries of which we want to
97 copy into this object.
98
99 Copies the entries contained in one list into this object.
100 */
akmhoque53353462014-04-22 08:43:45 -0500101 void
akmhoquefdbddb12014-05-02 18:35:19 -0500102 addAdjacents(AdjacencyList& adl);
akmhoque53353462014-04-22 08:43:45 -0500103
Nick G97e34942016-07-11 14:46:27 -0500104 /*! \brief Determines whether this list can be used to build an adj. LSA.
105 \param interestRetryNo The maximum number of hello-interest
106 retries to contact a neighbor.
107
108 \return Returns a boolean indicating whether this list can be used
109 to build an adj. LSA.
110
111 Determines whether this adjacency list object could be used to
112 build an adjacency LSA. An LSA is buildable when the status of all
113 neighbors is known. A neighbor's status is known when their status
114 is ACTIVE, or INACTIVE and some number of hello interests
115 (specified by nlsr::ConfParameter::getInterestRetryNumber()) have
116 failed. To be explicit, a neighbor's status is unknown if we are
117 still sending hello interests.
118 */
akmhoque53353462014-04-22 08:43:45 -0500119 bool
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500120 isAdjLsaBuildable(const uint32_t interestRetryNo) const;
akmhoque53353462014-04-22 08:43:45 -0500121
akmhoquefdbddb12014-05-02 18:35:19 -0500122 int32_t
akmhoque53353462014-04-22 08:43:45 -0500123 getNumOfActiveNeighbor();
124
125 Adjacent
akmhoque31d1d4b2014-05-05 22:08:14 -0500126 getAdjacent(const ndn::Name& adjName);
akmhoque53353462014-04-22 08:43:45 -0500127
128 bool
akmhoquefdbddb12014-05-02 18:35:19 -0500129 operator==(AdjacencyList& adl);
akmhoque53353462014-04-22 08:43:45 -0500130
akmhoquefdbddb12014-05-02 18:35:19 -0500131 size_t
akmhoque53353462014-04-22 08:43:45 -0500132 getSize()
133 {
134 return m_adjList.size();
135 }
136
137 void
138 reset()
139 {
akmhoque157b0a42014-05-13 00:26:37 -0500140 if (m_adjList.size() > 0) {
akmhoque53353462014-04-22 08:43:45 -0500141 m_adjList.clear();
142 }
143 }
144
Nick Gordonc780a692017-04-27 18:03:02 -0500145 AdjacencyList::iterator
akmhoquec04e7272014-07-02 11:00:14 -0500146 findAdjacent(const ndn::Name& adjName);
147
Nick Gordonc780a692017-04-27 18:03:02 -0500148 AdjacencyList::iterator
akmhoquec04e7272014-07-02 11:00:14 -0500149 findAdjacent(uint64_t faceId);
150
Nick Gordone9733ed2017-04-26 10:48:39 -0500151 AdjacencyList::iterator
152 findAdjacent(const ndn::util::FaceUri& faceUri);
153
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500154 /*! \brief Hack to stop developers from using this function
155
156 It is here so that faceUri cannot be passed in as string,
157 converted to Name and findAdjacent(Name) be used.
158 So when faceUri is passed as string this will cause a compile error
159 */
160 template <typename T = float> void
161 findAdjacent(const std::string& faceUri)
162 {
163 BOOST_STATIC_ASSERT_MSG(std::is_integral<T>::value,
164 "Don't use std::string with findAdjacent!");
165 }
166
akmhoque102aea42014-08-04 10:22:12 -0500167 uint64_t
Nick Gordone9733ed2017-04-26 10:48:39 -0500168 getFaceId(const ndn::util::FaceUri& faceUri);
akmhoque102aea42014-08-04 10:22:12 -0500169
akmhoque53353462014-04-22 08:43:45 -0500170 void
akmhoque674b0b12014-05-20 14:33:28 -0500171 writeLog();
172
alvydce3f182015-04-09 11:23:30 -0500173public:
174 const_iterator
175 begin() const
176 {
177 return m_adjList.begin();
178 }
179
180 const_iterator
181 end() const
182 {
183 return m_adjList.end();
184 }
185
akmhoque53353462014-04-22 08:43:45 -0500186private:
alvydce3f182015-04-09 11:23:30 -0500187 iterator
akmhoque31d1d4b2014-05-05 22:08:14 -0500188 find(const ndn::Name& adjName);
akmhoque53353462014-04-22 08:43:45 -0500189
190private:
191 std::list<Adjacent> m_adjList;
192};
193
Nick Gordonfad8e252016-08-11 14:21:38 -0500194} // namespace nlsr
Nick Gordonc780a692017-04-27 18:03:02 -0500195#endif // NLSR_ADJACENCY_LIST_HPP