blob: 06b590e9de60e20e6f6e72e72c448bf5d3f118b4 [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Nick Gordonf8b5bcd2016-08-11 15:06:50 -05003 * Copyright (c) 2014-2016, 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#ifndef NLSR_FIB_HPP
23#define NLSR_FIB_HPP
24
Nick Gordonb7168472016-09-21 13:57:17 -050025#include <map>
26
akmhoquefdbddb12014-05-02 18:35:19 -050027#include <boost/cstdint.hpp>
28
Junxiao Shi3e5120c2016-09-10 16:58:34 +000029#include <ndn-cxx/mgmt/nfd/controller.hpp>
akmhoquec7a79b22014-05-26 08:06:19 -050030#include <ndn-cxx/util/time.hpp>
akmhoque157b0a42014-05-13 00:26:37 -050031#include "face-map.hpp"
akmhoque53353462014-04-22 08:43:45 -050032#include "fib-entry.hpp"
Vince Lehman942eb7b2014-10-02 10:09:27 -050033#include "test-access-control.hpp"
Vince Lehman27f1add2014-10-16 17:14:46 -050034#include "utility/face-controller.hpp"
akmhoque53353462014-04-22 08:43:45 -050035
36namespace nlsr {
37
Junxiao Shi63bd0342016-08-17 16:57:14 +000038typedef ndn::nfd::Controller::CommandSucceedCallback CommandSucceedCallback;
39typedef ndn::nfd::Controller::CommandFailCallback CommandFailCallback;
akmhoquec04e7272014-07-02 11:00:14 -050040
Vince Lehman942eb7b2014-10-02 10:09:27 -050041class AdjacencyList;
42class ConfParameter;
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)
akmhoque31d1d4b2014-05-05 22:08:14 -050050 , m_table()
akmhoque53353462014-04-22 08:43:45 -050051 , m_refreshTime(0)
Vince Lehmanb7079a12014-11-04 12:45:50 -060052 , m_controller(face, keyChain)
Vince Lehman27f1add2014-10-16 17:14:46 -050053 , m_faceController(face.getIoService(), m_controller)
akmhoque157b0a42014-05-13 00:26:37 -050054 , m_faceMap()
Vince Lehman942eb7b2014-10-02 10:09:27 -050055 , m_adjacencyList(adjacencyList)
56 , m_confParameter(conf)
akmhoquefdbddb12014-05-02 18:35:19 -050057 {
58 }
Vince Lehman942eb7b2014-10-02 10:09:27 -050059
akmhoquefdbddb12014-05-02 18:35:19 -050060 ~Fib()
akmhoque53353462014-04-22 08:43:45 -050061 {
62 }
63
64 void
akmhoque31d1d4b2014-05-05 22:08:14 -050065 remove(const ndn::Name& name);
akmhoque53353462014-04-22 08:43:45 -050066
67 void
Vince Lehman942eb7b2014-10-02 10:09:27 -050068 update(const ndn::Name& name, NexthopList& allHops);
akmhoque53353462014-04-22 08:43:45 -050069
70 void
akmhoque31d1d4b2014-05-05 22:08:14 -050071 clean();
akmhoque53353462014-04-22 08:43:45 -050072
73 void
akmhoquefdbddb12014-05-02 18:35:19 -050074 setEntryRefreshTime(int32_t fert)
akmhoque53353462014-04-22 08:43:45 -050075 {
76 m_refreshTime = fert;
77 }
78
akmhoque53353462014-04-22 08:43:45 -050079private:
akmhoque393d4ff2014-07-16 14:27:03 -050080 bool
81 isPrefixUpdatable(const ndn::Name& name);
82
akmhoque53353462014-04-22 08:43:45 -050083 void
Vince Lehman942eb7b2014-10-02 10:09:27 -050084 addNextHopsToFibEntryAndNfd(FibEntry& entry, NexthopList& hopsToAdd);
Vince Lehman18841082014-08-19 17:15:24 -050085
86 void
Vince Lehman942eb7b2014-10-02 10:09:27 -050087 removeOldNextHopsFromFibEntryAndNfd(FibEntry& entry, const NexthopList& installedHops);
Vince Lehman18841082014-08-19 17:15:24 -050088
89 void
akmhoque157b0a42014-05-13 00:26:37 -050090 removeHop(NexthopList& nl, const std::string& doNotRemoveHopFaceUri,
akmhoque31d1d4b2014-05-05 22:08:14 -050091 const ndn::Name& name);
akmhoque53353462014-04-22 08:43:45 -050092
Vince Lehman942eb7b2014-10-02 10:09:27 -050093 unsigned int
94 getNumberOfFacesForName(NexthopList& nextHopList);
akmhoque53353462014-04-22 08:43:45 -050095
96 ndn::EventId
Vince Lehman18841082014-08-19 17:15:24 -050097 scheduleEntryExpiration(const ndn::Name& name, int32_t feSeqNum,
akmhoquec7a79b22014-05-26 08:06:19 -050098 const ndn::time::seconds& expTime);
akmhoque53353462014-04-22 08:43:45 -050099
100 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500101 cancelScheduledExpiringEvent(ndn::EventId eid);
akmhoquefdbddb12014-05-02 18:35:19 -0500102
akmhoque157b0a42014-05-13 00:26:37 -0500103public:
akmhoquefdbddb12014-05-02 18:35:19 -0500104 void
akmhoque157b0a42014-05-13 00:26:37 -0500105 registerPrefix(const ndn::Name& namePrefix, const std::string& faceUri,
akmhoquebf11c5f2014-07-21 14:49:47 -0500106 uint64_t faceCost,
akmhoque060d3022014-08-12 13:35:06 -0500107 const ndn::time::milliseconds& timeout,
108 uint64_t flags, uint8_t times);
akmhoquefdbddb12014-05-02 18:35:19 -0500109
110 void
akmhoquec04e7272014-07-02 11:00:14 -0500111 registerPrefix(const ndn::Name& namePrefix,
112 const std::string& faceUri,
akmhoquebf11c5f2014-07-21 14:49:47 -0500113 uint64_t faceCost,
114 const ndn::time::milliseconds& timeout,
akmhoque060d3022014-08-12 13:35:06 -0500115 uint64_t flags,
akmhoque102aea42014-08-04 10:22:12 -0500116 uint8_t times,
akmhoquec04e7272014-07-02 11:00:14 -0500117 const CommandSucceedCallback& onSuccess,
118 const CommandFailCallback& onFailure);
akmhoque060d3022014-08-12 13:35:06 -0500119
akmhoque157b0a42014-05-13 00:26:37 -0500120 void
akmhoque393d4ff2014-07-16 14:27:03 -0500121 setStrategy(const ndn::Name& name, const std::string& strategy, uint32_t count);
akmhoque157b0a42014-05-13 00:26:37 -0500122
akmhoque674b0b12014-05-20 14:33:28 -0500123 void
124 writeLog();
125
akmhoquec04e7272014-07-02 11:00:14 -0500126 void
127 destroyFace(const std::string& faceUri,
128 const CommandSucceedCallback& onSuccess,
129 const CommandFailCallback& onFailure);
130
akmhoque157b0a42014-05-13 00:26:37 -0500131private:
132 void
akmhoquec04e7272014-07-02 11:00:14 -0500133 createFace(const std::string& faceUri,
134 const CommandSucceedCallback& onSuccess,
135 const CommandFailCallback& onFailure);
136
137 void
akmhoque060d3022014-08-12 13:35:06 -0500138 registerPrefixInNfd(ndn::nfd::ControlParameters& parameters,
akmhoque102aea42014-08-04 10:22:12 -0500139 const std::string& faceUri,
140 uint8_t times);
akmhoquec04e7272014-07-02 11:00:14 -0500141
142 void
143 registerPrefixInNfd(const ndn::nfd::ControlParameters& faceCreateResult,
akmhoque060d3022014-08-12 13:35:06 -0500144 const ndn::nfd::ControlParameters& parameters,
akmhoque102aea42014-08-04 10:22:12 -0500145 uint8_t times,
akmhoquec04e7272014-07-02 11:00:14 -0500146 const CommandSucceedCallback& onSuccess,
147 const CommandFailCallback& onFailure);
148
149 void
150 destroyFaceInNfd(const ndn::nfd::ControlParameters& faceDestroyResult,
151 const CommandSucceedCallback& onSuccess,
152 const CommandFailCallback& onFailure);
153
154 void
akmhoque157b0a42014-05-13 00:26:37 -0500155 unregisterPrefix(const ndn::Name& namePrefix, const std::string& faceUri);
156
157 void
158 onRegistration(const ndn::nfd::ControlParameters& commandSuccessResult,
159 const std::string& message, const std::string& faceUri);
akmhoque31d1d4b2014-05-05 22:08:14 -0500160
akmhoquefdbddb12014-05-02 18:35:19 -0500161 void
akmhoqueb5b3b4f2014-07-23 16:36:51 -0500162 onUnregistration(const ndn::nfd::ControlParameters& commandSuccessResult,
163 const std::string& message);
akmhoquefdbddb12014-05-02 18:35:19 -0500164
165 void
Junxiao Shi63bd0342016-08-17 16:57:14 +0000166 onRegistrationFailure(const ndn::nfd::ControlResponse& response,
akmhoque102aea42014-08-04 10:22:12 -0500167 const std::string& message,
akmhoque060d3022014-08-12 13:35:06 -0500168 const ndn::nfd::ControlParameters& parameters,
169 const std::string& faceUri,
akmhoque102aea42014-08-04 10:22:12 -0500170 uint8_t times);
171
172 void
Junxiao Shi63bd0342016-08-17 16:57:14 +0000173 onUnregistrationFailure(const ndn::nfd::ControlResponse& response,
174 const std::string& message);
akmhoque53353462014-04-22 08:43:45 -0500175
akmhoque393d4ff2014-07-16 14:27:03 -0500176 void
177 onSetStrategySuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
178 const std::string& message);
179
180 void
Junxiao Shi63bd0342016-08-17 16:57:14 +0000181 onSetStrategyFailure(const ndn::nfd::ControlResponse& response,
akmhoque393d4ff2014-07-16 14:27:03 -0500182 const ndn::nfd::ControlParameters& parameters,
183 uint32_t count,
184 const std::string& message);
185
akmhoque53353462014-04-22 08:43:45 -0500186private:
Vince Lehman7c603292014-09-11 17:48:16 -0500187 ndn::Scheduler& m_scheduler;
Nick Gordonb7168472016-09-21 13:57:17 -0500188 std::map<ndn::Name, FibEntry> m_table;
akmhoquefdbddb12014-05-02 18:35:19 -0500189 int32_t m_refreshTime;
190 ndn::nfd::Controller m_controller;
Vince Lehman27f1add2014-10-16 17:14:46 -0500191 util::FaceController m_faceController;
Vince Lehman942eb7b2014-10-02 10:09:27 -0500192
193PUBLIC_WITH_TESTS_ELSE_PRIVATE:
akmhoque157b0a42014-05-13 00:26:37 -0500194 FaceMap m_faceMap;
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
akmhoque53353462014-04-22 08:43:45 -0500204#endif //NLSR_FIB_HPP