blob: c85f0ff3e3c0f22d697bdc8d83f1fe5fb70b5804 [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
dulalsaurabd0816a32019-07-26 13:11:24 +00003 * Copyright (c) 2014-2019, The University of Memphis,
Nick Gordonf8b5bcd2016-08-11 15:06:50 -05004 * Regents of the University of California
akmhoque3d06e792014-05-27 16:23:20 -05005 *
6 * This file is part of NLSR (Named-data Link State Routing).
7 * See AUTHORS.md for complete list of NLSR authors and contributors.
8 *
9 * NLSR is free software: you can redistribute it and/or modify it under the terms
10 * of the GNU General Public License as published by the Free Software Foundation,
11 * either version 3 of the License, or (at your option) any later version.
12 *
13 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
14 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
akmhoque3d06e792014-05-27 16:23:20 -050019 **/
Nick Gordond0a7df32017-05-30 16:44:34 -050020
akmhoque53353462014-04-22 08:43:45 -050021#include <string>
akmhoque102aea42014-08-04 10:22:12 -050022#include <cmath>
akmhoquefdbddb12014-05-02 18:35:19 -050023#include <boost/cstdint.hpp>
Nick Gordone9733ed2017-04-26 10:48:39 -050024
akmhoque31d1d4b2014-05-05 22:08:14 -050025#include <ndn-cxx/face.hpp>
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050026#include <ndn-cxx/net/face-uri.hpp>
akmhoque53353462014-04-22 08:43:45 -050027
akmhoquefdbddb12014-05-02 18:35:19 -050028#ifndef NLSR_ADJACENT_HPP
29#define NLSR_ADJACENT_HPP
akmhoque53353462014-04-22 08:43:45 -050030
31namespace nlsr {
akmhoque157b0a42014-05-13 00:26:37 -050032
Nick Gordond0a7df32017-05-30 16:44:34 -050033/*! \brief A neighbor reachable over a Face.
34 *
35 * Represents another node that we expect to be running NLSR that we
36 * should be able to reach over a direct Face connection.
37 */
akmhoque53353462014-04-22 08:43:45 -050038class Adjacent
39{
40
41public:
Vince Lehmancb76ade2014-08-28 21:24:41 -050042 enum Status
43 {
44 STATUS_UNKNOWN = -1,
45 STATUS_INACTIVE = 0,
46 STATUS_ACTIVE = 1
47 };
48
akmhoque157b0a42014-05-13 00:26:37 -050049 Adjacent();
akmhoque53353462014-04-22 08:43:45 -050050
akmhoque157b0a42014-05-13 00:26:37 -050051 Adjacent(const ndn::Name& an);
akmhoque53353462014-04-22 08:43:45 -050052
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050053 Adjacent(const ndn::Name& an, const ndn::FaceUri& faceUri, double lc,
Vince Lehmancb76ade2014-08-28 21:24:41 -050054 Status s, uint32_t iton, uint64_t faceId);
akmhoque53353462014-04-22 08:43:45 -050055
akmhoque31d1d4b2014-05-05 22:08:14 -050056 const ndn::Name&
akmhoquefdbddb12014-05-02 18:35:19 -050057 getName() const
akmhoque53353462014-04-22 08:43:45 -050058 {
59 return m_name;
60 }
61
62 void
akmhoque31d1d4b2014-05-05 22:08:14 -050063 setName(const ndn::Name& an)
akmhoque53353462014-04-22 08:43:45 -050064 {
65 m_name = an;
66 }
67
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050068 const ndn::FaceUri&
Nick Gordone9733ed2017-04-26 10:48:39 -050069 getFaceUri() const
akmhoque53353462014-04-22 08:43:45 -050070 {
Nick Gordone9733ed2017-04-26 10:48:39 -050071 return m_faceUri;
akmhoque53353462014-04-22 08:43:45 -050072 }
73
74 void
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050075 setFaceUri(const ndn::FaceUri& faceUri)
akmhoque53353462014-04-22 08:43:45 -050076 {
Nick Gordone9733ed2017-04-26 10:48:39 -050077 m_faceUri = faceUri;
akmhoque53353462014-04-22 08:43:45 -050078 }
79
dulalsaurabd0816a32019-07-26 13:11:24 +000080 double
akmhoquefdbddb12014-05-02 18:35:19 -050081 getLinkCost() const
akmhoque53353462014-04-22 08:43:45 -050082 {
dulalsaurabd0816a32019-07-26 13:11:24 +000083 return ceil(m_linkCost);
akmhoque53353462014-04-22 08:43:45 -050084 }
85
86 void
dulalsaurabd0816a32019-07-26 13:11:24 +000087 setLinkCost(double lc);
akmhoque53353462014-04-22 08:43:45 -050088
Vince Lehmancb76ade2014-08-28 21:24:41 -050089 Status
akmhoquefdbddb12014-05-02 18:35:19 -050090 getStatus() const
akmhoque53353462014-04-22 08:43:45 -050091 {
92 return m_status;
93 }
94
95 void
Vince Lehmancb76ade2014-08-28 21:24:41 -050096 setStatus(Status s)
akmhoque53353462014-04-22 08:43:45 -050097 {
98 m_status = s;
99 }
100
akmhoquefdbddb12014-05-02 18:35:19 -0500101 uint32_t
102 getInterestTimedOutNo() const
akmhoque53353462014-04-22 08:43:45 -0500103 {
104 return m_interestTimedOutNo;
105 }
106
107 void
akmhoquefdbddb12014-05-02 18:35:19 -0500108 setInterestTimedOutNo(uint32_t iton)
akmhoque53353462014-04-22 08:43:45 -0500109 {
110 m_interestTimedOutNo = iton;
111 }
112
akmhoquec04e7272014-07-02 11:00:14 -0500113 void
114 setFaceId(uint64_t faceId)
115 {
116 m_faceId = faceId;
117 }
118
119 uint64_t
Nick Gordond5c1a372016-10-31 13:56:23 -0500120 getFaceId() const
akmhoquec04e7272014-07-02 11:00:14 -0500121 {
122 return m_faceId;
123 }
124
Nick Gordond0a7df32017-05-30 16:44:34 -0500125 /*! \brief Equality is when name, Face URI, and link cost are all equal. */
akmhoque53353462014-04-22 08:43:45 -0500126 bool
akmhoquefdbddb12014-05-02 18:35:19 -0500127 operator==(const Adjacent& adjacent) const;
akmhoque53353462014-04-22 08:43:45 -0500128
Nick Gordon2a1ac612017-10-06 15:36:49 -0500129 bool
130 operator!=(const Adjacent& adjacent) const
131 {
132 return !(*this == adjacent);
133 }
134
135 bool
136 operator<(const Adjacent& adjacent) const;
137
akmhoquec04e7272014-07-02 11:00:14 -0500138 inline bool
Nick Gordon49648702018-01-22 11:57:33 -0600139 compare(const ndn::Name& adjacencyName) const
akmhoquec04e7272014-07-02 11:00:14 -0500140 {
141 return m_name == adjacencyName;
142 }
143
144 inline bool
Nick Gordon49648702018-01-22 11:57:33 -0600145 compareFaceId(const uint64_t faceId) const
akmhoquec04e7272014-07-02 11:00:14 -0500146 {
147 return m_faceId == faceId;
148 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500149
akmhoque102aea42014-08-04 10:22:12 -0500150 inline bool
Nick Gordon49648702018-01-22 11:57:33 -0600151 compareFaceUri(const ndn::FaceUri& faceUri) const
akmhoque102aea42014-08-04 10:22:12 -0500152 {
Nick Gordone9733ed2017-04-26 10:48:39 -0500153 return m_faceUri == faceUri;
akmhoque102aea42014-08-04 10:22:12 -0500154 }
155
akmhoque674b0b12014-05-20 14:33:28 -0500156 void
157 writeLog();
158
akmhoque157b0a42014-05-13 00:26:37 -0500159public:
dulalsaurabd0816a32019-07-26 13:11:24 +0000160 static const double DEFAULT_LINK_COST;
161 static const double NON_ADJACENT_COST;
akmhoque157b0a42014-05-13 00:26:37 -0500162
akmhoque53353462014-04-22 08:43:45 -0500163private:
Nick Gordond0a7df32017-05-30 16:44:34 -0500164 /*! m_name The NLSR-configured router name of the neighbor */
akmhoque31d1d4b2014-05-05 22:08:14 -0500165 ndn::Name m_name;
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500166 /*! m_faceUri The NFD-level specification of the Face*/
167 ndn::FaceUri m_faceUri;
Nick Gordond0a7df32017-05-30 16:44:34 -0500168 /*! m_linkCost The semi-arbitrary cost to traverse the link. */
akmhoque53353462014-04-22 08:43:45 -0500169 double m_linkCost;
Nick Gordond0a7df32017-05-30 16:44:34 -0500170 /*! m_status Whether the neighbor is active or not */
Vince Lehmancb76ade2014-08-28 21:24:41 -0500171 Status m_status;
Nick Gordond0a7df32017-05-30 16:44:34 -0500172 /*! m_interestTimedOutNo How many failed Hello interests we have sent since the last reply */
akmhoquefdbddb12014-05-02 18:35:19 -0500173 uint32_t m_interestTimedOutNo;
Nick Gordond0a7df32017-05-30 16:44:34 -0500174 /*! m_faceId The NFD-assigned ID for the neighbor, used to
175 * determine whether a Face is available */
akmhoquec04e7272014-07-02 11:00:14 -0500176 uint64_t m_faceId;
Nick Gordon2a1ac612017-10-06 15:36:49 -0500177
178 friend std::ostream&
179 operator<<(std::ostream& os, const Adjacent& adjacent);
akmhoque53353462014-04-22 08:43:45 -0500180};
181
Nick Gordon2a1ac612017-10-06 15:36:49 -0500182std::ostream&
183operator<<(std::ostream& os, const Adjacent& adjacent);
184
akmhoque53353462014-04-22 08:43:45 -0500185} // namespace nlsr
186
Nick Gordone9733ed2017-04-26 10:48:39 -0500187#endif // NLSR_ADJACENT_HPP