blob: d1995cf89b667094f2dc6ec597a6c92ec9c9c1f3 [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/>.
19 *
20 * \author A K M Mahmudul Hoque <ahoque1@memphis.edu>
21 *
22 **/
akmhoque53353462014-04-22 08:43:45 -050023#include <string>
akmhoque102aea42014-08-04 10:22:12 -050024#include <cmath>
akmhoquefdbddb12014-05-02 18:35:19 -050025#include <boost/cstdint.hpp>
akmhoque31d1d4b2014-05-05 22:08:14 -050026#include <ndn-cxx/face.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
akmhoque53353462014-04-22 08:43:45 -050033class Adjacent
34{
35
36public:
Vince Lehmancb76ade2014-08-28 21:24:41 -050037 enum Status
38 {
39 STATUS_UNKNOWN = -1,
40 STATUS_INACTIVE = 0,
41 STATUS_ACTIVE = 1
42 };
43
akmhoque157b0a42014-05-13 00:26:37 -050044 Adjacent();
akmhoque53353462014-04-22 08:43:45 -050045
akmhoque157b0a42014-05-13 00:26:37 -050046 Adjacent(const ndn::Name& an);
akmhoque53353462014-04-22 08:43:45 -050047
akmhoque157b0a42014-05-13 00:26:37 -050048 Adjacent(const ndn::Name& an, const std::string& cfu, double lc,
Vince Lehmancb76ade2014-08-28 21:24:41 -050049 Status s, uint32_t iton, uint64_t faceId);
akmhoque53353462014-04-22 08:43:45 -050050
akmhoque31d1d4b2014-05-05 22:08:14 -050051 const ndn::Name&
akmhoquefdbddb12014-05-02 18:35:19 -050052 getName() const
akmhoque53353462014-04-22 08:43:45 -050053 {
54 return m_name;
55 }
56
57 void
akmhoque31d1d4b2014-05-05 22:08:14 -050058 setName(const ndn::Name& an)
akmhoque53353462014-04-22 08:43:45 -050059 {
60 m_name = an;
61 }
62
akmhoque157b0a42014-05-13 00:26:37 -050063 const std::string&
64 getConnectingFaceUri() const
akmhoque53353462014-04-22 08:43:45 -050065 {
akmhoque157b0a42014-05-13 00:26:37 -050066 return m_connectingFaceUri;
akmhoque53353462014-04-22 08:43:45 -050067 }
68
69 void
akmhoque157b0a42014-05-13 00:26:37 -050070 setConnectingFaceUri(const std::string& cfu)
akmhoque53353462014-04-22 08:43:45 -050071 {
akmhoque157b0a42014-05-13 00:26:37 -050072 m_connectingFaceUri = cfu;
akmhoque53353462014-04-22 08:43:45 -050073 }
74
akmhoque102aea42014-08-04 10:22:12 -050075 uint64_t
akmhoquefdbddb12014-05-02 18:35:19 -050076 getLinkCost() const
akmhoque53353462014-04-22 08:43:45 -050077 {
akmhoque102aea42014-08-04 10:22:12 -050078 uint64_t linkCost = static_cast<uint64_t>(ceil(m_linkCost));
79 return linkCost;
akmhoque53353462014-04-22 08:43:45 -050080 }
81
82 void
83 setLinkCost(double lc)
84 {
85 m_linkCost = lc;
86 }
87
Vince Lehmancb76ade2014-08-28 21:24:41 -050088 Status
akmhoquefdbddb12014-05-02 18:35:19 -050089 getStatus() const
akmhoque53353462014-04-22 08:43:45 -050090 {
91 return m_status;
92 }
93
94 void
Vince Lehmancb76ade2014-08-28 21:24:41 -050095 setStatus(Status s)
akmhoque53353462014-04-22 08:43:45 -050096 {
97 m_status = s;
98 }
99
akmhoquefdbddb12014-05-02 18:35:19 -0500100 uint32_t
101 getInterestTimedOutNo() const
akmhoque53353462014-04-22 08:43:45 -0500102 {
103 return m_interestTimedOutNo;
104 }
105
106 void
akmhoquefdbddb12014-05-02 18:35:19 -0500107 setInterestTimedOutNo(uint32_t iton)
akmhoque53353462014-04-22 08:43:45 -0500108 {
109 m_interestTimedOutNo = iton;
110 }
111
akmhoquec04e7272014-07-02 11:00:14 -0500112 void
113 setFaceId(uint64_t faceId)
114 {
115 m_faceId = faceId;
116 }
117
118 uint64_t
119 getFaceId()
120 {
121 return m_faceId;
122 }
123
akmhoque53353462014-04-22 08:43:45 -0500124 bool
akmhoquefdbddb12014-05-02 18:35:19 -0500125 operator==(const Adjacent& adjacent) const;
akmhoque53353462014-04-22 08:43:45 -0500126
akmhoquec04e7272014-07-02 11:00:14 -0500127 inline bool
128 compare(const ndn::Name& adjacencyName)
129 {
130 return m_name == adjacencyName;
131 }
132
133 inline bool
134 compareFaceId(uint64_t faceId)
135 {
136 return m_faceId == faceId;
137 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500138
akmhoque102aea42014-08-04 10:22:12 -0500139 inline bool
140 compareFaceUri(std::string& faceUri)
141 {
142 return m_connectingFaceUri == faceUri;
143 }
144
akmhoque674b0b12014-05-20 14:33:28 -0500145 void
146 writeLog();
147
akmhoque157b0a42014-05-13 00:26:37 -0500148public:
149 static const float DEFAULT_LINK_COST;
150
akmhoque53353462014-04-22 08:43:45 -0500151private:
akmhoque31d1d4b2014-05-05 22:08:14 -0500152 ndn::Name m_name;
akmhoque157b0a42014-05-13 00:26:37 -0500153 std::string m_connectingFaceUri;
akmhoque53353462014-04-22 08:43:45 -0500154 double m_linkCost;
Vince Lehmancb76ade2014-08-28 21:24:41 -0500155 Status m_status;
akmhoquefdbddb12014-05-02 18:35:19 -0500156 uint32_t m_interestTimedOutNo;
akmhoquec04e7272014-07-02 11:00:14 -0500157 uint64_t m_faceId;
akmhoque53353462014-04-22 08:43:45 -0500158};
159
akmhoque53353462014-04-22 08:43:45 -0500160} // namespace nlsr
161
akmhoquefdbddb12014-05-02 18:35:19 -0500162#endif //NLSR_ADJACENT_HPP