akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
dulalsaurab | d0816a3 | 2019-07-26 13:11:24 +0000 | [diff] [blame^] | 3 | * Copyright (c) 2014-2019, The University of Memphis, |
Nick Gordon | f8b5bcd | 2016-08-11 15:06:50 -0500 | [diff] [blame] | 4 | * Regents of the University of California |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 5 | * |
| 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/>. |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 19 | **/ |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 20 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 21 | #include <string> |
akmhoque | 102aea4 | 2014-08-04 10:22:12 -0500 | [diff] [blame] | 22 | #include <cmath> |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 23 | #include <boost/cstdint.hpp> |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 24 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 25 | #include <ndn-cxx/face.hpp> |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 26 | #include <ndn-cxx/net/face-uri.hpp> |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 27 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 28 | #ifndef NLSR_ADJACENT_HPP |
| 29 | #define NLSR_ADJACENT_HPP |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 30 | |
| 31 | namespace nlsr { |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 32 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 33 | /*! \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 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 38 | class Adjacent |
| 39 | { |
| 40 | |
| 41 | public: |
Vince Lehman | cb76ade | 2014-08-28 21:24:41 -0500 | [diff] [blame] | 42 | enum Status |
| 43 | { |
| 44 | STATUS_UNKNOWN = -1, |
| 45 | STATUS_INACTIVE = 0, |
| 46 | STATUS_ACTIVE = 1 |
| 47 | }; |
| 48 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 49 | Adjacent(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 50 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 51 | Adjacent(const ndn::Name& an); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 52 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 53 | Adjacent(const ndn::Name& an, const ndn::FaceUri& faceUri, double lc, |
Vince Lehman | cb76ade | 2014-08-28 21:24:41 -0500 | [diff] [blame] | 54 | Status s, uint32_t iton, uint64_t faceId); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 55 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 56 | const ndn::Name& |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 57 | getName() const |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 58 | { |
| 59 | return m_name; |
| 60 | } |
| 61 | |
| 62 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 63 | setName(const ndn::Name& an) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 64 | { |
| 65 | m_name = an; |
| 66 | } |
| 67 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 68 | const ndn::FaceUri& |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 69 | getFaceUri() const |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 70 | { |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 71 | return m_faceUri; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | void |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 75 | setFaceUri(const ndn::FaceUri& faceUri) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 76 | { |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 77 | m_faceUri = faceUri; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 78 | } |
| 79 | |
dulalsaurab | d0816a3 | 2019-07-26 13:11:24 +0000 | [diff] [blame^] | 80 | double |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 81 | getLinkCost() const |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 82 | { |
dulalsaurab | d0816a3 | 2019-07-26 13:11:24 +0000 | [diff] [blame^] | 83 | return ceil(m_linkCost); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | void |
dulalsaurab | d0816a3 | 2019-07-26 13:11:24 +0000 | [diff] [blame^] | 87 | setLinkCost(double lc); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 88 | |
Vince Lehman | cb76ade | 2014-08-28 21:24:41 -0500 | [diff] [blame] | 89 | Status |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 90 | getStatus() const |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 91 | { |
| 92 | return m_status; |
| 93 | } |
| 94 | |
| 95 | void |
Vince Lehman | cb76ade | 2014-08-28 21:24:41 -0500 | [diff] [blame] | 96 | setStatus(Status s) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 97 | { |
| 98 | m_status = s; |
| 99 | } |
| 100 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 101 | uint32_t |
| 102 | getInterestTimedOutNo() const |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 103 | { |
| 104 | return m_interestTimedOutNo; |
| 105 | } |
| 106 | |
| 107 | void |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 108 | setInterestTimedOutNo(uint32_t iton) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 109 | { |
| 110 | m_interestTimedOutNo = iton; |
| 111 | } |
| 112 | |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 113 | void |
| 114 | setFaceId(uint64_t faceId) |
| 115 | { |
| 116 | m_faceId = faceId; |
| 117 | } |
| 118 | |
| 119 | uint64_t |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 120 | getFaceId() const |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 121 | { |
| 122 | return m_faceId; |
| 123 | } |
| 124 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 125 | /*! \brief Equality is when name, Face URI, and link cost are all equal. */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 126 | bool |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 127 | operator==(const Adjacent& adjacent) const; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 128 | |
Nick Gordon | 2a1ac61 | 2017-10-06 15:36:49 -0500 | [diff] [blame] | 129 | bool |
| 130 | operator!=(const Adjacent& adjacent) const |
| 131 | { |
| 132 | return !(*this == adjacent); |
| 133 | } |
| 134 | |
| 135 | bool |
| 136 | operator<(const Adjacent& adjacent) const; |
| 137 | |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 138 | inline bool |
Nick Gordon | 4964870 | 2018-01-22 11:57:33 -0600 | [diff] [blame] | 139 | compare(const ndn::Name& adjacencyName) const |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 140 | { |
| 141 | return m_name == adjacencyName; |
| 142 | } |
| 143 | |
| 144 | inline bool |
Nick Gordon | 4964870 | 2018-01-22 11:57:33 -0600 | [diff] [blame] | 145 | compareFaceId(const uint64_t faceId) const |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 146 | { |
| 147 | return m_faceId == faceId; |
| 148 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 149 | |
akmhoque | 102aea4 | 2014-08-04 10:22:12 -0500 | [diff] [blame] | 150 | inline bool |
Nick Gordon | 4964870 | 2018-01-22 11:57:33 -0600 | [diff] [blame] | 151 | compareFaceUri(const ndn::FaceUri& faceUri) const |
akmhoque | 102aea4 | 2014-08-04 10:22:12 -0500 | [diff] [blame] | 152 | { |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 153 | return m_faceUri == faceUri; |
akmhoque | 102aea4 | 2014-08-04 10:22:12 -0500 | [diff] [blame] | 154 | } |
| 155 | |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 156 | void |
| 157 | writeLog(); |
| 158 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 159 | public: |
dulalsaurab | d0816a3 | 2019-07-26 13:11:24 +0000 | [diff] [blame^] | 160 | static const double DEFAULT_LINK_COST; |
| 161 | static const double NON_ADJACENT_COST; |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 162 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 163 | private: |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 164 | /*! m_name The NLSR-configured router name of the neighbor */ |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 165 | ndn::Name m_name; |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 166 | /*! m_faceUri The NFD-level specification of the Face*/ |
| 167 | ndn::FaceUri m_faceUri; |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 168 | /*! m_linkCost The semi-arbitrary cost to traverse the link. */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 169 | double m_linkCost; |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 170 | /*! m_status Whether the neighbor is active or not */ |
Vince Lehman | cb76ade | 2014-08-28 21:24:41 -0500 | [diff] [blame] | 171 | Status m_status; |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 172 | /*! m_interestTimedOutNo How many failed Hello interests we have sent since the last reply */ |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 173 | uint32_t m_interestTimedOutNo; |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 174 | /*! m_faceId The NFD-assigned ID for the neighbor, used to |
| 175 | * determine whether a Face is available */ |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 176 | uint64_t m_faceId; |
Nick Gordon | 2a1ac61 | 2017-10-06 15:36:49 -0500 | [diff] [blame] | 177 | |
| 178 | friend std::ostream& |
| 179 | operator<<(std::ostream& os, const Adjacent& adjacent); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 180 | }; |
| 181 | |
Nick Gordon | 2a1ac61 | 2017-10-06 15:36:49 -0500 | [diff] [blame] | 182 | std::ostream& |
| 183 | operator<<(std::ostream& os, const Adjacent& adjacent); |
| 184 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 185 | } // namespace nlsr |
| 186 | |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 187 | #endif // NLSR_ADJACENT_HPP |