blob: 5e15fea7df42ad96ee4e671d564261b6047b4c16 [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,
Junxiao Shi3e5120c2016-09-10 16:58:34 +00004 * Regents of the University of California,
5 * Arizona Board of Regents.
akmhoque3d06e792014-05-27 16:23:20 -05006 *
7 * This file is part of NLSR (Named-data Link State Routing).
8 * See AUTHORS.md for complete list of NLSR authors and contributors.
9 *
10 * NLSR is free software: you can redistribute it and/or modify it under the terms
11 * of the GNU General Public License as published by the Free Software Foundation,
12 * either version 3 of the License, or (at your option) any later version.
13 *
14 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 * PURPOSE. See the GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
20 *
akmhoque3d06e792014-05-27 16:23:20 -050021 **/
akmhoque53353462014-04-22 08:43:45 -050022
Muktadir Chowdhury3be64662015-05-01 14:50:53 -050023#ifndef NLSR_ROUTE_FIB_HPP
24#define NLSR_ROUTE_FIB_HPP
Nick Gordonb7168472016-09-21 13:57:17 -050025
akmhoque157b0a42014-05-13 00:26:37 -050026#include "face-map.hpp"
akmhoque53353462014-04-22 08:43:45 -050027#include "fib-entry.hpp"
Vince Lehman942eb7b2014-10-02 10:09:27 -050028#include "test-access-control.hpp"
Vince Lehman27f1add2014-10-16 17:14:46 -050029#include "utility/face-controller.hpp"
akmhoque53353462014-04-22 08:43:45 -050030
Nick Gordon21088082017-05-24 10:57:06 -050031#include <ndn-cxx/mgmt/nfd/controller.hpp>
Muktadir Chowdhury3be64662015-05-01 14:50:53 -050032#include <ndn-cxx/util/time.hpp>
33
akmhoque53353462014-04-22 08:43:45 -050034namespace nlsr {
35
Junxiao Shi63bd0342016-08-17 16:57:14 +000036typedef ndn::nfd::Controller::CommandSucceedCallback CommandSucceedCallback;
37typedef ndn::nfd::Controller::CommandFailCallback CommandFailCallback;
Muktadir Chowdhury3be64662015-05-01 14:50:53 -050038typedef std::function<void(FibEntry&)> afterRefreshCallback;
akmhoquec04e7272014-07-02 11:00:14 -050039
Vince Lehman942eb7b2014-10-02 10:09:27 -050040class AdjacencyList;
41class ConfParameter;
Muktadir Chowdhury3be64662015-05-01 14:50:53 -050042class FibEntry;
akmhoque53353462014-04-22 08:43:45 -050043
44class Fib
45{
46public:
Vince Lehmanb7079a12014-11-04 12:45:50 -060047 Fib(ndn::Face& face, ndn::Scheduler& scheduler, AdjacencyList& adjacencyList, ConfParameter& conf,
48 ndn::KeyChain& keyChain)
Vince Lehman942eb7b2014-10-02 10:09:27 -050049 : m_scheduler(scheduler)
akmhoque53353462014-04-22 08:43:45 -050050 , m_refreshTime(0)
Vince Lehmanb7079a12014-11-04 12:45:50 -060051 , m_controller(face, keyChain)
Vince Lehman27f1add2014-10-16 17:14:46 -050052 , m_faceController(face.getIoService(), m_controller)
Vince Lehman942eb7b2014-10-02 10:09:27 -050053 , m_adjacencyList(adjacencyList)
54 , m_confParameter(conf)
akmhoquefdbddb12014-05-02 18:35:19 -050055 {
56 }
Vince Lehman942eb7b2014-10-02 10:09:27 -050057
Muktadir Chowdhury3be64662015-05-01 14:50:53 -050058 FibEntry*
59 processUpdate(const ndn::Name& name, NexthopList& allHops);
akmhoque53353462014-04-22 08:43:45 -050060
Nick Gordon4d2c6c02017-01-20 13:18:46 -060061 VIRTUAL_WITH_TESTS void
akmhoque31d1d4b2014-05-05 22:08:14 -050062 remove(const ndn::Name& name);
akmhoque53353462014-04-22 08:43:45 -050063
Nick Gordon4d2c6c02017-01-20 13:18:46 -060064 VIRTUAL_WITH_TESTS void
65 update(const ndn::Name& name, NexthopList& allHops);
66
akmhoque53353462014-04-22 08:43:45 -050067 void
akmhoque31d1d4b2014-05-05 22:08:14 -050068 clean();
akmhoque53353462014-04-22 08:43:45 -050069
70 void
akmhoquefdbddb12014-05-02 18:35:19 -050071 setEntryRefreshTime(int32_t fert)
akmhoque53353462014-04-22 08:43:45 -050072 {
73 m_refreshTime = fert;
74 }
75
akmhoque53353462014-04-22 08:43:45 -050076 void
Muktadir Chowdhury3be64662015-05-01 14:50:53 -050077 registerPrefix(const ndn::Name& namePrefix,
78 const std::string& faceUri,
akmhoquebf11c5f2014-07-21 14:49:47 -050079 uint64_t faceCost,
akmhoque060d3022014-08-12 13:35:06 -050080 const ndn::time::milliseconds& timeout,
Muktadir Chowdhury3be64662015-05-01 14:50:53 -050081 uint64_t flags,
82 uint8_t times);
akmhoquefdbddb12014-05-02 18:35:19 -050083
84 void
akmhoquec04e7272014-07-02 11:00:14 -050085 registerPrefix(const ndn::Name& namePrefix,
86 const std::string& faceUri,
akmhoquebf11c5f2014-07-21 14:49:47 -050087 uint64_t faceCost,
88 const ndn::time::milliseconds& timeout,
akmhoque060d3022014-08-12 13:35:06 -050089 uint64_t flags,
akmhoque102aea42014-08-04 10:22:12 -050090 uint8_t times,
akmhoquec04e7272014-07-02 11:00:14 -050091 const CommandSucceedCallback& onSuccess,
92 const CommandFailCallback& onFailure);
akmhoque060d3022014-08-12 13:35:06 -050093
akmhoque157b0a42014-05-13 00:26:37 -050094 void
akmhoque393d4ff2014-07-16 14:27:03 -050095 setStrategy(const ndn::Name& name, const std::string& strategy, uint32_t count);
akmhoque157b0a42014-05-13 00:26:37 -050096
akmhoque674b0b12014-05-20 14:33:28 -050097 void
98 writeLog();
99
akmhoquec04e7272014-07-02 11:00:14 -0500100 void
101 destroyFace(const std::string& faceUri,
102 const CommandSucceedCallback& onSuccess,
103 const CommandFailCallback& onFailure);
104
akmhoque157b0a42014-05-13 00:26:37 -0500105private:
Muktadir Chowdhury3be64662015-05-01 14:50:53 -0500106 bool
107 isPrefixUpdatable(const ndn::Name& name);
108
109 void
110 addNextHopsToFibEntryAndNfd(FibEntry& entry, NexthopList& hopsToAdd);
111
112 void
113 removeOldNextHopsFromFibEntryAndNfd(FibEntry& entry, const NexthopList& installedHops);
114
115 unsigned int
116 getNumberOfFacesForName(NexthopList& nextHopList);
117
akmhoque157b0a42014-05-13 00:26:37 -0500118 void
akmhoquec04e7272014-07-02 11:00:14 -0500119 createFace(const std::string& faceUri,
120 const CommandSucceedCallback& onSuccess,
121 const CommandFailCallback& onFailure);
122
123 void
akmhoque060d3022014-08-12 13:35:06 -0500124 registerPrefixInNfd(ndn::nfd::ControlParameters& parameters,
akmhoque102aea42014-08-04 10:22:12 -0500125 const std::string& faceUri,
126 uint8_t times);
akmhoquec04e7272014-07-02 11:00:14 -0500127
128 void
129 registerPrefixInNfd(const ndn::nfd::ControlParameters& faceCreateResult,
akmhoque060d3022014-08-12 13:35:06 -0500130 const ndn::nfd::ControlParameters& parameters,
akmhoque102aea42014-08-04 10:22:12 -0500131 uint8_t times,
akmhoquec04e7272014-07-02 11:00:14 -0500132 const CommandSucceedCallback& onSuccess,
133 const CommandFailCallback& onFailure);
134
135 void
136 destroyFaceInNfd(const ndn::nfd::ControlParameters& faceDestroyResult,
137 const CommandSucceedCallback& onSuccess,
138 const CommandFailCallback& onFailure);
139
140 void
akmhoque157b0a42014-05-13 00:26:37 -0500141 unregisterPrefix(const ndn::Name& namePrefix, const std::string& faceUri);
142
143 void
Muktadir Chowdhury3be64662015-05-01 14:50:53 -0500144 onRegistrationSuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
145 const std::string& message, const std::string& faceUri);
akmhoquefdbddb12014-05-02 18:35:19 -0500146
147 void
Junxiao Shi63bd0342016-08-17 16:57:14 +0000148 onRegistrationFailure(const ndn::nfd::ControlResponse& response,
akmhoque102aea42014-08-04 10:22:12 -0500149 const std::string& message,
akmhoque060d3022014-08-12 13:35:06 -0500150 const ndn::nfd::ControlParameters& parameters,
151 const std::string& faceUri,
akmhoque102aea42014-08-04 10:22:12 -0500152 uint8_t times);
153
154 void
Muktadir Chowdhury3be64662015-05-01 14:50:53 -0500155 onUnregistrationSuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
Junxiao Shi63bd0342016-08-17 16:57:14 +0000156 const std::string& message);
akmhoque53353462014-04-22 08:43:45 -0500157
akmhoque393d4ff2014-07-16 14:27:03 -0500158 void
Muktadir Chowdhury3be64662015-05-01 14:50:53 -0500159 onUnregistrationFailure(const ndn::nfd::ControlResponse& response,
160 const std::string& message);
161
162 void
akmhoque393d4ff2014-07-16 14:27:03 -0500163 onSetStrategySuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
164 const std::string& message);
165
166 void
Junxiao Shi63bd0342016-08-17 16:57:14 +0000167 onSetStrategyFailure(const ndn::nfd::ControlResponse& response,
akmhoque393d4ff2014-07-16 14:27:03 -0500168 const ndn::nfd::ControlParameters& parameters,
169 uint32_t count,
170 const std::string& message);
171
Muktadir Chowdhury3be64662015-05-01 14:50:53 -0500172PUBLIC_WITH_TESTS_ELSE_PRIVATE:
173 void
174 scheduleEntryRefresh(FibEntry& entry, const afterRefreshCallback& refreshCb);
175
176private:
177 void
178 scheduleLoop(FibEntry& entry);
179
180 void
181 cancelEntryRefresh(const FibEntry& entry);
182
183 void
184 refreshEntry(const ndn::Name& name, afterRefreshCallback refreshCb);
185
akmhoque53353462014-04-22 08:43:45 -0500186private:
Vince Lehman7c603292014-09-11 17:48:16 -0500187 ndn::Scheduler& m_scheduler;
akmhoquefdbddb12014-05-02 18:35:19 -0500188 int32_t m_refreshTime;
189 ndn::nfd::Controller m_controller;
Vince Lehman27f1add2014-10-16 17:14:46 -0500190 util::FaceController m_faceController;
Vince Lehman942eb7b2014-10-02 10:09:27 -0500191
192PUBLIC_WITH_TESTS_ELSE_PRIVATE:
akmhoque157b0a42014-05-13 00:26:37 -0500193 FaceMap m_faceMap;
Muktadir Chowdhury3be64662015-05-01 14:50:53 -0500194 std::map<ndn::Name, FibEntry> m_table;
akmhoque393d4ff2014-07-16 14:27:03 -0500195
Vince Lehman942eb7b2014-10-02 10:09:27 -0500196private:
197 AdjacencyList& m_adjacencyList;
198 ConfParameter& m_confParameter;
199
akmhoque393d4ff2014-07-16 14:27:03 -0500200 static const uint64_t GRACE_PERIOD;
akmhoque53353462014-04-22 08:43:45 -0500201};
202
Nick Gordonfad8e252016-08-11 14:21:38 -0500203} // namespace nlsr
Muktadir Chowdhury3be64662015-05-01 14:50:53 -0500204
205#endif // NLSR_ROUTE_FIB_HPP