blob: 4aded013c2f20b27676e0629cd6034d21c300f23 [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Nick Gordonc6a85222017-01-03 16:54:34 -06003 * Copyright (c) 2014-2017, 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 **/
akmhoque53353462014-04-22 08:43:45 -050020#include <string>
akmhoque102aea42014-08-04 10:22:12 -050021#include <cmath>
akmhoquefdbddb12014-05-02 18:35:19 -050022#include <boost/cstdint.hpp>
Nick Gordone9733ed2017-04-26 10:48:39 -050023
akmhoque31d1d4b2014-05-05 22:08:14 -050024#include <ndn-cxx/face.hpp>
Nick Gordone9733ed2017-04-26 10:48:39 -050025#include <ndn-cxx/util/face-uri.hpp>
akmhoque53353462014-04-22 08:43:45 -050026
akmhoquefdbddb12014-05-02 18:35:19 -050027#ifndef NLSR_ADJACENT_HPP
28#define NLSR_ADJACENT_HPP
akmhoque53353462014-04-22 08:43:45 -050029
30namespace nlsr {
akmhoque157b0a42014-05-13 00:26:37 -050031
akmhoque53353462014-04-22 08:43:45 -050032class Adjacent
33{
34
35public:
Vince Lehmancb76ade2014-08-28 21:24:41 -050036 enum Status
37 {
38 STATUS_UNKNOWN = -1,
39 STATUS_INACTIVE = 0,
40 STATUS_ACTIVE = 1
41 };
42
akmhoque157b0a42014-05-13 00:26:37 -050043 Adjacent();
akmhoque53353462014-04-22 08:43:45 -050044
akmhoque157b0a42014-05-13 00:26:37 -050045 Adjacent(const ndn::Name& an);
akmhoque53353462014-04-22 08:43:45 -050046
Nick Gordone9733ed2017-04-26 10:48:39 -050047 Adjacent(const ndn::Name& an, const ndn::util::FaceUri& faceUri, double lc,
Vince Lehmancb76ade2014-08-28 21:24:41 -050048 Status s, uint32_t iton, uint64_t faceId);
akmhoque53353462014-04-22 08:43:45 -050049
akmhoque31d1d4b2014-05-05 22:08:14 -050050 const ndn::Name&
akmhoquefdbddb12014-05-02 18:35:19 -050051 getName() const
akmhoque53353462014-04-22 08:43:45 -050052 {
53 return m_name;
54 }
55
56 void
akmhoque31d1d4b2014-05-05 22:08:14 -050057 setName(const ndn::Name& an)
akmhoque53353462014-04-22 08:43:45 -050058 {
59 m_name = an;
60 }
61
Nick Gordone9733ed2017-04-26 10:48:39 -050062 const ndn::util::FaceUri&
63 getFaceUri() const
akmhoque53353462014-04-22 08:43:45 -050064 {
Nick Gordone9733ed2017-04-26 10:48:39 -050065 return m_faceUri;
akmhoque53353462014-04-22 08:43:45 -050066 }
67
68 void
Nick Gordone9733ed2017-04-26 10:48:39 -050069 setFaceUri(const ndn::util::FaceUri& faceUri)
akmhoque53353462014-04-22 08:43:45 -050070 {
Nick Gordone9733ed2017-04-26 10:48:39 -050071 m_faceUri = faceUri;
akmhoque53353462014-04-22 08:43:45 -050072 }
73
akmhoque102aea42014-08-04 10:22:12 -050074 uint64_t
akmhoquefdbddb12014-05-02 18:35:19 -050075 getLinkCost() const
akmhoque53353462014-04-22 08:43:45 -050076 {
akmhoque102aea42014-08-04 10:22:12 -050077 uint64_t linkCost = static_cast<uint64_t>(ceil(m_linkCost));
78 return linkCost;
akmhoque53353462014-04-22 08:43:45 -050079 }
80
81 void
82 setLinkCost(double lc)
83 {
84 m_linkCost = lc;
85 }
86
Vince Lehmancb76ade2014-08-28 21:24:41 -050087 Status
akmhoquefdbddb12014-05-02 18:35:19 -050088 getStatus() const
akmhoque53353462014-04-22 08:43:45 -050089 {
90 return m_status;
91 }
92
93 void
Vince Lehmancb76ade2014-08-28 21:24:41 -050094 setStatus(Status s)
akmhoque53353462014-04-22 08:43:45 -050095 {
96 m_status = s;
97 }
98
akmhoquefdbddb12014-05-02 18:35:19 -050099 uint32_t
100 getInterestTimedOutNo() const
akmhoque53353462014-04-22 08:43:45 -0500101 {
102 return m_interestTimedOutNo;
103 }
104
105 void
akmhoquefdbddb12014-05-02 18:35:19 -0500106 setInterestTimedOutNo(uint32_t iton)
akmhoque53353462014-04-22 08:43:45 -0500107 {
108 m_interestTimedOutNo = iton;
109 }
110
akmhoquec04e7272014-07-02 11:00:14 -0500111 void
112 setFaceId(uint64_t faceId)
113 {
114 m_faceId = faceId;
115 }
116
117 uint64_t
118 getFaceId()
119 {
120 return m_faceId;
121 }
122
akmhoque53353462014-04-22 08:43:45 -0500123 bool
akmhoquefdbddb12014-05-02 18:35:19 -0500124 operator==(const Adjacent& adjacent) const;
akmhoque53353462014-04-22 08:43:45 -0500125
akmhoquec04e7272014-07-02 11:00:14 -0500126 inline bool
127 compare(const ndn::Name& adjacencyName)
128 {
129 return m_name == adjacencyName;
130 }
131
132 inline bool
Nick Gordone9733ed2017-04-26 10:48:39 -0500133 compareFaceId(const uint64_t faceId)
akmhoquec04e7272014-07-02 11:00:14 -0500134 {
135 return m_faceId == faceId;
136 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500137
akmhoque102aea42014-08-04 10:22:12 -0500138 inline bool
Nick Gordone9733ed2017-04-26 10:48:39 -0500139 compareFaceUri(const ndn::util::FaceUri& faceUri)
akmhoque102aea42014-08-04 10:22:12 -0500140 {
Nick Gordone9733ed2017-04-26 10:48:39 -0500141 return m_faceUri == faceUri;
akmhoque102aea42014-08-04 10:22:12 -0500142 }
143
akmhoque674b0b12014-05-20 14:33:28 -0500144 void
145 writeLog();
146
akmhoque157b0a42014-05-13 00:26:37 -0500147public:
148 static const float DEFAULT_LINK_COST;
149
akmhoque53353462014-04-22 08:43:45 -0500150private:
akmhoque31d1d4b2014-05-05 22:08:14 -0500151 ndn::Name m_name;
Nick Gordone9733ed2017-04-26 10:48:39 -0500152 ndn::util::FaceUri m_faceUri;
akmhoque53353462014-04-22 08:43:45 -0500153 double m_linkCost;
Vince Lehmancb76ade2014-08-28 21:24:41 -0500154 Status m_status;
akmhoquefdbddb12014-05-02 18:35:19 -0500155 uint32_t m_interestTimedOutNo;
akmhoquec04e7272014-07-02 11:00:14 -0500156 uint64_t m_faceId;
akmhoque53353462014-04-22 08:43:45 -0500157};
158
akmhoque53353462014-04-22 08:43:45 -0500159} // namespace nlsr
160
Nick Gordone9733ed2017-04-26 10:48:39 -0500161#endif // NLSR_ADJACENT_HPP