blob: 967265f4a1dbd4ada61a141993753fe9ebe220e4 [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014 University of Memphis,
4 * Regents of the University of California
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/>.
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
33enum {
34 ADJACENT_STATUS_INACTIVE = 0,
35 ADJACENT_STATUS_ACTIVE = 1
36};
37
akmhoque53353462014-04-22 08:43:45 -050038class Adjacent
39{
40
41public:
akmhoque157b0a42014-05-13 00:26:37 -050042 Adjacent();
akmhoque53353462014-04-22 08:43:45 -050043
akmhoque157b0a42014-05-13 00:26:37 -050044 Adjacent(const ndn::Name& an);
akmhoque53353462014-04-22 08:43:45 -050045
akmhoque157b0a42014-05-13 00:26:37 -050046 Adjacent(const ndn::Name& an, const std::string& cfu, double lc,
akmhoquec04e7272014-07-02 11:00:14 -050047 uint32_t s, uint32_t iton, uint64_t faceId);
akmhoque53353462014-04-22 08:43:45 -050048
akmhoque31d1d4b2014-05-05 22:08:14 -050049 const ndn::Name&
akmhoquefdbddb12014-05-02 18:35:19 -050050 getName() const
akmhoque53353462014-04-22 08:43:45 -050051 {
52 return m_name;
53 }
54
55 void
akmhoque31d1d4b2014-05-05 22:08:14 -050056 setName(const ndn::Name& an)
akmhoque53353462014-04-22 08:43:45 -050057 {
58 m_name = an;
59 }
60
akmhoque157b0a42014-05-13 00:26:37 -050061 const std::string&
62 getConnectingFaceUri() const
akmhoque53353462014-04-22 08:43:45 -050063 {
akmhoque157b0a42014-05-13 00:26:37 -050064 return m_connectingFaceUri;
akmhoque53353462014-04-22 08:43:45 -050065 }
66
67 void
akmhoque157b0a42014-05-13 00:26:37 -050068 setConnectingFaceUri(const std::string& cfu)
akmhoque53353462014-04-22 08:43:45 -050069 {
akmhoque157b0a42014-05-13 00:26:37 -050070 m_connectingFaceUri = cfu;
akmhoque53353462014-04-22 08:43:45 -050071 }
72
akmhoque102aea42014-08-04 10:22:12 -050073 uint64_t
akmhoquefdbddb12014-05-02 18:35:19 -050074 getLinkCost() const
akmhoque53353462014-04-22 08:43:45 -050075 {
akmhoque102aea42014-08-04 10:22:12 -050076 uint64_t linkCost = static_cast<uint64_t>(ceil(m_linkCost));
77 return linkCost;
akmhoque53353462014-04-22 08:43:45 -050078 }
79
80 void
81 setLinkCost(double lc)
82 {
83 m_linkCost = lc;
84 }
85
akmhoquefdbddb12014-05-02 18:35:19 -050086 uint32_t
87 getStatus() const
akmhoque53353462014-04-22 08:43:45 -050088 {
89 return m_status;
90 }
91
92 void
akmhoquefdbddb12014-05-02 18:35:19 -050093 setStatus(uint32_t s)
akmhoque53353462014-04-22 08:43:45 -050094 {
95 m_status = s;
96 }
97
akmhoquefdbddb12014-05-02 18:35:19 -050098 uint32_t
99 getInterestTimedOutNo() const
akmhoque53353462014-04-22 08:43:45 -0500100 {
101 return m_interestTimedOutNo;
102 }
103
104 void
akmhoquefdbddb12014-05-02 18:35:19 -0500105 setInterestTimedOutNo(uint32_t iton)
akmhoque53353462014-04-22 08:43:45 -0500106 {
107 m_interestTimedOutNo = iton;
108 }
109
akmhoquec04e7272014-07-02 11:00:14 -0500110 void
111 setFaceId(uint64_t faceId)
112 {
113 m_faceId = faceId;
114 }
115
116 uint64_t
117 getFaceId()
118 {
119 return m_faceId;
120 }
121
akmhoque53353462014-04-22 08:43:45 -0500122 bool
akmhoquefdbddb12014-05-02 18:35:19 -0500123 operator==(const Adjacent& adjacent) const;
akmhoque53353462014-04-22 08:43:45 -0500124
akmhoquec04e7272014-07-02 11:00:14 -0500125 inline bool
126 compare(const ndn::Name& adjacencyName)
127 {
128 return m_name == adjacencyName;
129 }
130
131 inline bool
132 compareFaceId(uint64_t faceId)
133 {
134 return m_faceId == faceId;
135 }
akmhoque31d1d4b2014-05-05 22:08:14 -0500136
akmhoque102aea42014-08-04 10:22:12 -0500137 inline bool
138 compareFaceUri(std::string& faceUri)
139 {
140 return m_connectingFaceUri == faceUri;
141 }
142
akmhoque674b0b12014-05-20 14:33:28 -0500143 void
144 writeLog();
145
akmhoque157b0a42014-05-13 00:26:37 -0500146public:
147 static const float DEFAULT_LINK_COST;
148
akmhoque53353462014-04-22 08:43:45 -0500149private:
akmhoque31d1d4b2014-05-05 22:08:14 -0500150 ndn::Name m_name;
akmhoque157b0a42014-05-13 00:26:37 -0500151 std::string m_connectingFaceUri;
akmhoque53353462014-04-22 08:43:45 -0500152 double m_linkCost;
akmhoquefdbddb12014-05-02 18:35:19 -0500153 uint32_t m_status;
154 uint32_t m_interestTimedOutNo;
akmhoquec04e7272014-07-02 11:00:14 -0500155 uint64_t m_faceId;
akmhoque53353462014-04-22 08:43:45 -0500156};
157
akmhoque53353462014-04-22 08:43:45 -0500158} // namespace nlsr
159
akmhoquefdbddb12014-05-02 18:35:19 -0500160#endif //NLSR_ADJACENT_HPP