akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Nick Gordon | c6a8522 | 2017-01-03 16:54:34 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, The University of Memphis, |
Junxiao Shi | 3e5120c | 2016-09-10 16:58:34 +0000 | [diff] [blame] | 4 | * Regents of the University of California, |
| 5 | * Arizona Board of Regents. |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 6 | * |
| 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 | * |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 21 | **/ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 22 | |
Muktadir Chowdhury | 3be6466 | 2015-05-01 14:50:53 -0500 | [diff] [blame^] | 23 | #ifndef NLSR_ROUTE_FIB_HPP |
| 24 | #define NLSR_ROUTE_FIB_HPP |
Nick Gordon | b716847 | 2016-09-21 13:57:17 -0500 | [diff] [blame] | 25 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 26 | #include "face-map.hpp" |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 27 | #include "fib-entry.hpp" |
Vince Lehman | 942eb7b | 2014-10-02 10:09:27 -0500 | [diff] [blame] | 28 | #include "test-access-control.hpp" |
Vince Lehman | 27f1add | 2014-10-16 17:14:46 -0500 | [diff] [blame] | 29 | #include "utility/face-controller.hpp" |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 30 | |
Muktadir Chowdhury | 3be6466 | 2015-05-01 14:50:53 -0500 | [diff] [blame^] | 31 | #include <ndn-cxx/management/nfd-controller.hpp> |
| 32 | #include <ndn-cxx/util/time.hpp> |
| 33 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 34 | namespace nlsr { |
| 35 | |
Junxiao Shi | 63bd034 | 2016-08-17 16:57:14 +0000 | [diff] [blame] | 36 | typedef ndn::nfd::Controller::CommandSucceedCallback CommandSucceedCallback; |
| 37 | typedef ndn::nfd::Controller::CommandFailCallback CommandFailCallback; |
Muktadir Chowdhury | 3be6466 | 2015-05-01 14:50:53 -0500 | [diff] [blame^] | 38 | typedef std::function<void(FibEntry&)> afterRefreshCallback; |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 39 | |
Vince Lehman | 942eb7b | 2014-10-02 10:09:27 -0500 | [diff] [blame] | 40 | class AdjacencyList; |
| 41 | class ConfParameter; |
Muktadir Chowdhury | 3be6466 | 2015-05-01 14:50:53 -0500 | [diff] [blame^] | 42 | class FibEntry; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 43 | |
| 44 | class Fib |
| 45 | { |
| 46 | public: |
Vince Lehman | b7079a1 | 2014-11-04 12:45:50 -0600 | [diff] [blame] | 47 | Fib(ndn::Face& face, ndn::Scheduler& scheduler, AdjacencyList& adjacencyList, ConfParameter& conf, |
| 48 | ndn::KeyChain& keyChain) |
Vince Lehman | 942eb7b | 2014-10-02 10:09:27 -0500 | [diff] [blame] | 49 | : m_scheduler(scheduler) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 50 | , m_refreshTime(0) |
Vince Lehman | b7079a1 | 2014-11-04 12:45:50 -0600 | [diff] [blame] | 51 | , m_controller(face, keyChain) |
Vince Lehman | 27f1add | 2014-10-16 17:14:46 -0500 | [diff] [blame] | 52 | , m_faceController(face.getIoService(), m_controller) |
Vince Lehman | 942eb7b | 2014-10-02 10:09:27 -0500 | [diff] [blame] | 53 | , m_adjacencyList(adjacencyList) |
| 54 | , m_confParameter(conf) |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 55 | { |
| 56 | } |
Vince Lehman | 942eb7b | 2014-10-02 10:09:27 -0500 | [diff] [blame] | 57 | |
Muktadir Chowdhury | 3be6466 | 2015-05-01 14:50:53 -0500 | [diff] [blame^] | 58 | void |
| 59 | update(const ndn::Name& name, NexthopList& allHops); |
| 60 | |
| 61 | FibEntry* |
| 62 | processUpdate(const ndn::Name& name, NexthopList& allHops); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 63 | |
| 64 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 65 | remove(const ndn::Name& name); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 66 | |
| 67 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 68 | clean(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 69 | |
| 70 | void |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 71 | setEntryRefreshTime(int32_t fert) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 72 | { |
| 73 | m_refreshTime = fert; |
| 74 | } |
| 75 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 76 | void |
Muktadir Chowdhury | 3be6466 | 2015-05-01 14:50:53 -0500 | [diff] [blame^] | 77 | registerPrefix(const ndn::Name& namePrefix, |
| 78 | const std::string& faceUri, |
akmhoque | bf11c5f | 2014-07-21 14:49:47 -0500 | [diff] [blame] | 79 | uint64_t faceCost, |
akmhoque | 060d302 | 2014-08-12 13:35:06 -0500 | [diff] [blame] | 80 | const ndn::time::milliseconds& timeout, |
Muktadir Chowdhury | 3be6466 | 2015-05-01 14:50:53 -0500 | [diff] [blame^] | 81 | uint64_t flags, |
| 82 | uint8_t times); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 83 | |
| 84 | void |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 85 | registerPrefix(const ndn::Name& namePrefix, |
| 86 | const std::string& faceUri, |
akmhoque | bf11c5f | 2014-07-21 14:49:47 -0500 | [diff] [blame] | 87 | uint64_t faceCost, |
| 88 | const ndn::time::milliseconds& timeout, |
akmhoque | 060d302 | 2014-08-12 13:35:06 -0500 | [diff] [blame] | 89 | uint64_t flags, |
akmhoque | 102aea4 | 2014-08-04 10:22:12 -0500 | [diff] [blame] | 90 | uint8_t times, |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 91 | const CommandSucceedCallback& onSuccess, |
| 92 | const CommandFailCallback& onFailure); |
akmhoque | 060d302 | 2014-08-12 13:35:06 -0500 | [diff] [blame] | 93 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 94 | void |
akmhoque | 393d4ff | 2014-07-16 14:27:03 -0500 | [diff] [blame] | 95 | setStrategy(const ndn::Name& name, const std::string& strategy, uint32_t count); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 96 | |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 97 | void |
| 98 | writeLog(); |
| 99 | |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 100 | void |
| 101 | destroyFace(const std::string& faceUri, |
| 102 | const CommandSucceedCallback& onSuccess, |
| 103 | const CommandFailCallback& onFailure); |
| 104 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 105 | private: |
Muktadir Chowdhury | 3be6466 | 2015-05-01 14:50:53 -0500 | [diff] [blame^] | 106 | 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 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 118 | void |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 119 | createFace(const std::string& faceUri, |
| 120 | const CommandSucceedCallback& onSuccess, |
| 121 | const CommandFailCallback& onFailure); |
| 122 | |
| 123 | void |
akmhoque | 060d302 | 2014-08-12 13:35:06 -0500 | [diff] [blame] | 124 | registerPrefixInNfd(ndn::nfd::ControlParameters& parameters, |
akmhoque | 102aea4 | 2014-08-04 10:22:12 -0500 | [diff] [blame] | 125 | const std::string& faceUri, |
| 126 | uint8_t times); |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 127 | |
| 128 | void |
| 129 | registerPrefixInNfd(const ndn::nfd::ControlParameters& faceCreateResult, |
akmhoque | 060d302 | 2014-08-12 13:35:06 -0500 | [diff] [blame] | 130 | const ndn::nfd::ControlParameters& parameters, |
akmhoque | 102aea4 | 2014-08-04 10:22:12 -0500 | [diff] [blame] | 131 | uint8_t times, |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 132 | 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 |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 141 | unregisterPrefix(const ndn::Name& namePrefix, const std::string& faceUri); |
| 142 | |
| 143 | void |
Muktadir Chowdhury | 3be6466 | 2015-05-01 14:50:53 -0500 | [diff] [blame^] | 144 | onRegistrationSuccess(const ndn::nfd::ControlParameters& commandSuccessResult, |
| 145 | const std::string& message, const std::string& faceUri); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 146 | |
| 147 | void |
Junxiao Shi | 63bd034 | 2016-08-17 16:57:14 +0000 | [diff] [blame] | 148 | onRegistrationFailure(const ndn::nfd::ControlResponse& response, |
akmhoque | 102aea4 | 2014-08-04 10:22:12 -0500 | [diff] [blame] | 149 | const std::string& message, |
akmhoque | 060d302 | 2014-08-12 13:35:06 -0500 | [diff] [blame] | 150 | const ndn::nfd::ControlParameters& parameters, |
| 151 | const std::string& faceUri, |
akmhoque | 102aea4 | 2014-08-04 10:22:12 -0500 | [diff] [blame] | 152 | uint8_t times); |
| 153 | |
| 154 | void |
Muktadir Chowdhury | 3be6466 | 2015-05-01 14:50:53 -0500 | [diff] [blame^] | 155 | onUnregistrationSuccess(const ndn::nfd::ControlParameters& commandSuccessResult, |
Junxiao Shi | 63bd034 | 2016-08-17 16:57:14 +0000 | [diff] [blame] | 156 | const std::string& message); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 157 | |
akmhoque | 393d4ff | 2014-07-16 14:27:03 -0500 | [diff] [blame] | 158 | void |
Muktadir Chowdhury | 3be6466 | 2015-05-01 14:50:53 -0500 | [diff] [blame^] | 159 | onUnregistrationFailure(const ndn::nfd::ControlResponse& response, |
| 160 | const std::string& message); |
| 161 | |
| 162 | void |
akmhoque | 393d4ff | 2014-07-16 14:27:03 -0500 | [diff] [blame] | 163 | onSetStrategySuccess(const ndn::nfd::ControlParameters& commandSuccessResult, |
| 164 | const std::string& message); |
| 165 | |
| 166 | void |
Junxiao Shi | 63bd034 | 2016-08-17 16:57:14 +0000 | [diff] [blame] | 167 | onSetStrategyFailure(const ndn::nfd::ControlResponse& response, |
akmhoque | 393d4ff | 2014-07-16 14:27:03 -0500 | [diff] [blame] | 168 | const ndn::nfd::ControlParameters& parameters, |
| 169 | uint32_t count, |
| 170 | const std::string& message); |
| 171 | |
Muktadir Chowdhury | 3be6466 | 2015-05-01 14:50:53 -0500 | [diff] [blame^] | 172 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
| 173 | void |
| 174 | scheduleEntryRefresh(FibEntry& entry, const afterRefreshCallback& refreshCb); |
| 175 | |
| 176 | private: |
| 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 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 186 | private: |
Vince Lehman | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame] | 187 | ndn::Scheduler& m_scheduler; |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 188 | int32_t m_refreshTime; |
| 189 | ndn::nfd::Controller m_controller; |
Vince Lehman | 27f1add | 2014-10-16 17:14:46 -0500 | [diff] [blame] | 190 | util::FaceController m_faceController; |
Vince Lehman | 942eb7b | 2014-10-02 10:09:27 -0500 | [diff] [blame] | 191 | |
| 192 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 193 | FaceMap m_faceMap; |
Muktadir Chowdhury | 3be6466 | 2015-05-01 14:50:53 -0500 | [diff] [blame^] | 194 | std::map<ndn::Name, FibEntry> m_table; |
akmhoque | 393d4ff | 2014-07-16 14:27:03 -0500 | [diff] [blame] | 195 | |
Vince Lehman | 942eb7b | 2014-10-02 10:09:27 -0500 | [diff] [blame] | 196 | private: |
| 197 | AdjacencyList& m_adjacencyList; |
| 198 | ConfParameter& m_confParameter; |
| 199 | |
akmhoque | 393d4ff | 2014-07-16 14:27:03 -0500 | [diff] [blame] | 200 | static const uint64_t GRACE_PERIOD; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 201 | }; |
| 202 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame] | 203 | } // namespace nlsr |
Muktadir Chowdhury | 3be6466 | 2015-05-01 14:50:53 -0500 | [diff] [blame^] | 204 | |
| 205 | #endif // NLSR_ROUTE_FIB_HPP |