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 | f8b5bcd | 2016-08-11 15:06:50 -0500 | [diff] [blame^] | 3 | * Copyright (c) 2014-2016, The University of Memphis, |
| 4 | * Regents of the University of California |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 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 | **/ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 23 | #ifndef NLSR_FIB_HPP |
| 24 | #define NLSR_FIB_HPP |
| 25 | |
| 26 | #include <list> |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 27 | #include <boost/cstdint.hpp> |
| 28 | |
| 29 | #include <ndn-cxx/management/nfd-controller.hpp> |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 30 | #include <ndn-cxx/util/time.hpp> |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 31 | #include "face-map.hpp" |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 32 | #include "fib-entry.hpp" |
Vince Lehman | 942eb7b | 2014-10-02 10:09:27 -0500 | [diff] [blame] | 33 | #include "test-access-control.hpp" |
Vince Lehman | 27f1add | 2014-10-16 17:14:46 -0500 | [diff] [blame] | 34 | #include "utility/face-controller.hpp" |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 35 | |
| 36 | namespace nlsr { |
| 37 | |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 38 | typedef ndn::function<void(const ndn::nfd::ControlParameters&)> CommandSucceedCallback; |
| 39 | typedef ndn::function<void(uint32_t/*code*/,const std::string&/*reason*/)> CommandFailCallback; |
| 40 | |
Vince Lehman | 942eb7b | 2014-10-02 10:09:27 -0500 | [diff] [blame] | 41 | class AdjacencyList; |
| 42 | class ConfParameter; |
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 | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 50 | , m_table() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 51 | , m_refreshTime(0) |
Vince Lehman | b7079a1 | 2014-11-04 12:45:50 -0600 | [diff] [blame] | 52 | , m_controller(face, keyChain) |
Vince Lehman | 27f1add | 2014-10-16 17:14:46 -0500 | [diff] [blame] | 53 | , m_faceController(face.getIoService(), m_controller) |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 54 | , m_faceMap() |
Vince Lehman | 942eb7b | 2014-10-02 10:09:27 -0500 | [diff] [blame] | 55 | , m_adjacencyList(adjacencyList) |
| 56 | , m_confParameter(conf) |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 57 | { |
| 58 | } |
Vince Lehman | 942eb7b | 2014-10-02 10:09:27 -0500 | [diff] [blame] | 59 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 60 | ~Fib() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 61 | { |
| 62 | } |
| 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 |
Vince Lehman | 942eb7b | 2014-10-02 10:09:27 -0500 | [diff] [blame] | 68 | update(const ndn::Name& name, NexthopList& allHops); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 69 | |
| 70 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 71 | clean(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 72 | |
| 73 | void |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 74 | setEntryRefreshTime(int32_t fert) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 75 | { |
| 76 | m_refreshTime = fert; |
| 77 | } |
| 78 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 79 | private: |
akmhoque | 393d4ff | 2014-07-16 14:27:03 -0500 | [diff] [blame] | 80 | bool |
| 81 | isPrefixUpdatable(const ndn::Name& name); |
| 82 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 83 | void |
Vince Lehman | 942eb7b | 2014-10-02 10:09:27 -0500 | [diff] [blame] | 84 | addNextHopsToFibEntryAndNfd(FibEntry& entry, NexthopList& hopsToAdd); |
Vince Lehman | 1884108 | 2014-08-19 17:15:24 -0500 | [diff] [blame] | 85 | |
| 86 | void |
Vince Lehman | 942eb7b | 2014-10-02 10:09:27 -0500 | [diff] [blame] | 87 | removeOldNextHopsFromFibEntryAndNfd(FibEntry& entry, const NexthopList& installedHops); |
Vince Lehman | 1884108 | 2014-08-19 17:15:24 -0500 | [diff] [blame] | 88 | |
| 89 | void |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 90 | removeHop(NexthopList& nl, const std::string& doNotRemoveHopFaceUri, |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 91 | const ndn::Name& name); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 92 | |
Vince Lehman | 942eb7b | 2014-10-02 10:09:27 -0500 | [diff] [blame] | 93 | unsigned int |
| 94 | getNumberOfFacesForName(NexthopList& nextHopList); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 95 | |
| 96 | ndn::EventId |
Vince Lehman | 1884108 | 2014-08-19 17:15:24 -0500 | [diff] [blame] | 97 | scheduleEntryExpiration(const ndn::Name& name, int32_t feSeqNum, |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 98 | const ndn::time::seconds& expTime); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 99 | |
| 100 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 101 | cancelScheduledExpiringEvent(ndn::EventId eid); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 102 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 103 | public: |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 104 | void |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 105 | registerPrefix(const ndn::Name& namePrefix, const std::string& faceUri, |
akmhoque | bf11c5f | 2014-07-21 14:49:47 -0500 | [diff] [blame] | 106 | uint64_t faceCost, |
akmhoque | 060d302 | 2014-08-12 13:35:06 -0500 | [diff] [blame] | 107 | const ndn::time::milliseconds& timeout, |
| 108 | uint64_t flags, uint8_t times); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 109 | |
| 110 | void |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 111 | registerPrefix(const ndn::Name& namePrefix, |
| 112 | const std::string& faceUri, |
akmhoque | bf11c5f | 2014-07-21 14:49:47 -0500 | [diff] [blame] | 113 | uint64_t faceCost, |
| 114 | const ndn::time::milliseconds& timeout, |
akmhoque | 060d302 | 2014-08-12 13:35:06 -0500 | [diff] [blame] | 115 | uint64_t flags, |
akmhoque | 102aea4 | 2014-08-04 10:22:12 -0500 | [diff] [blame] | 116 | uint8_t times, |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 117 | const CommandSucceedCallback& onSuccess, |
| 118 | const CommandFailCallback& onFailure); |
akmhoque | 060d302 | 2014-08-12 13:35:06 -0500 | [diff] [blame] | 119 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 120 | void |
akmhoque | 393d4ff | 2014-07-16 14:27:03 -0500 | [diff] [blame] | 121 | setStrategy(const ndn::Name& name, const std::string& strategy, uint32_t count); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 122 | |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 123 | void |
| 124 | writeLog(); |
| 125 | |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 126 | void |
| 127 | destroyFace(const std::string& faceUri, |
| 128 | const CommandSucceedCallback& onSuccess, |
| 129 | const CommandFailCallback& onFailure); |
| 130 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 131 | private: |
| 132 | void |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 133 | createFace(const std::string& faceUri, |
| 134 | const CommandSucceedCallback& onSuccess, |
| 135 | const CommandFailCallback& onFailure); |
| 136 | |
| 137 | void |
akmhoque | 060d302 | 2014-08-12 13:35:06 -0500 | [diff] [blame] | 138 | registerPrefixInNfd(ndn::nfd::ControlParameters& parameters, |
akmhoque | 102aea4 | 2014-08-04 10:22:12 -0500 | [diff] [blame] | 139 | const std::string& faceUri, |
| 140 | uint8_t times); |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 141 | |
| 142 | void |
| 143 | registerPrefixInNfd(const ndn::nfd::ControlParameters& faceCreateResult, |
akmhoque | 060d302 | 2014-08-12 13:35:06 -0500 | [diff] [blame] | 144 | const ndn::nfd::ControlParameters& parameters, |
akmhoque | 102aea4 | 2014-08-04 10:22:12 -0500 | [diff] [blame] | 145 | uint8_t times, |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 146 | 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 |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 155 | 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); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 160 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 161 | void |
akmhoque | b5b3b4f | 2014-07-23 16:36:51 -0500 | [diff] [blame] | 162 | onUnregistration(const ndn::nfd::ControlParameters& commandSuccessResult, |
| 163 | const std::string& message); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 164 | |
| 165 | void |
akmhoque | 102aea4 | 2014-08-04 10:22:12 -0500 | [diff] [blame] | 166 | onRegistrationFailure(uint32_t code, const std::string& error, |
| 167 | const std::string& message, |
akmhoque | 060d302 | 2014-08-12 13:35:06 -0500 | [diff] [blame] | 168 | const ndn::nfd::ControlParameters& parameters, |
| 169 | const std::string& faceUri, |
akmhoque | 102aea4 | 2014-08-04 10:22:12 -0500 | [diff] [blame] | 170 | uint8_t times); |
| 171 | |
| 172 | void |
| 173 | onUnregistrationFailure(uint32_t code, const std::string& error, |
| 174 | const std::string& message); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 175 | |
akmhoque | 393d4ff | 2014-07-16 14:27:03 -0500 | [diff] [blame] | 176 | void |
| 177 | onSetStrategySuccess(const ndn::nfd::ControlParameters& commandSuccessResult, |
| 178 | const std::string& message); |
| 179 | |
| 180 | void |
| 181 | onSetStrategyFailure(uint32_t code, const std::string& error, |
| 182 | const ndn::nfd::ControlParameters& parameters, |
| 183 | uint32_t count, |
| 184 | const std::string& message); |
| 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; |
| 188 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 189 | std::list<FibEntry> m_table; |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 190 | int32_t m_refreshTime; |
| 191 | ndn::nfd::Controller m_controller; |
Vince Lehman | 27f1add | 2014-10-16 17:14:46 -0500 | [diff] [blame] | 192 | util::FaceController m_faceController; |
Vince Lehman | 942eb7b | 2014-10-02 10:09:27 -0500 | [diff] [blame] | 193 | |
| 194 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 195 | FaceMap m_faceMap; |
akmhoque | 393d4ff | 2014-07-16 14:27:03 -0500 | [diff] [blame] | 196 | |
Vince Lehman | 942eb7b | 2014-10-02 10:09:27 -0500 | [diff] [blame] | 197 | private: |
| 198 | AdjacencyList& m_adjacencyList; |
| 199 | ConfParameter& m_confParameter; |
| 200 | |
akmhoque | 393d4ff | 2014-07-16 14:27:03 -0500 | [diff] [blame] | 201 | static const uint64_t GRACE_PERIOD; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 202 | }; |
| 203 | |
| 204 | }//namespace nlsr |
| 205 | #endif //NLSR_FIB_HPP |