akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 1 | /* -*- 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 | **/ |
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" |
| 33 | |
| 34 | namespace nlsr { |
| 35 | |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 36 | typedef ndn::function<void(const ndn::nfd::ControlParameters&)> CommandSucceedCallback; |
| 37 | typedef ndn::function<void(uint32_t/*code*/,const std::string&/*reason*/)> CommandFailCallback; |
| 38 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 39 | class Nlsr; |
| 40 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 41 | |
| 42 | class Fib |
| 43 | { |
| 44 | public: |
Vince Lehman | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame^] | 45 | Fib(Nlsr& nlsr, ndn::Face& face, ndn::Scheduler& scheduler) |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 46 | : m_nlsr(nlsr) |
Vince Lehman | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame^] | 47 | , m_scheduler(scheduler) |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 48 | , m_table() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 49 | , m_refreshTime(0) |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 50 | , m_controller(face) |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 51 | , m_faceMap() |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 52 | { |
| 53 | } |
| 54 | ~Fib() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 55 | { |
| 56 | } |
| 57 | |
| 58 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 59 | remove(const ndn::Name& name); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 60 | |
| 61 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 62 | update(const ndn::Name& name, NexthopList& nextHopList); |
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 | clean(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 66 | |
| 67 | void |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 68 | setEntryRefreshTime(int32_t fert) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 69 | { |
| 70 | m_refreshTime = fert; |
| 71 | } |
| 72 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 73 | private: |
akmhoque | 393d4ff | 2014-07-16 14:27:03 -0500 | [diff] [blame] | 74 | bool |
| 75 | isPrefixUpdatable(const ndn::Name& name); |
| 76 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 77 | void |
Vince Lehman | 1884108 | 2014-08-19 17:15:24 -0500 | [diff] [blame] | 78 | addNextHopsToFibEntryAndNfd(FibEntry& entry, NexthopList& nextHopList); |
| 79 | |
| 80 | void |
| 81 | removeOldNextHopsFromFibEntryAndNfd(FibEntry& entry, NexthopList& newHopList); |
| 82 | |
| 83 | void |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 84 | removeHop(NexthopList& nl, const std::string& doNotRemoveHopFaceUri, |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 85 | const ndn::Name& name); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 86 | |
| 87 | int |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 88 | getNumberOfFacesForName(NexthopList& nextHopList, uint32_t maxFacesPerPrefix); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 89 | |
| 90 | ndn::EventId |
Vince Lehman | 1884108 | 2014-08-19 17:15:24 -0500 | [diff] [blame] | 91 | scheduleEntryExpiration(const ndn::Name& name, int32_t feSeqNum, |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 92 | const ndn::time::seconds& expTime); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 93 | |
| 94 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 95 | cancelScheduledExpiringEvent(ndn::EventId eid); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 96 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 97 | public: |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 98 | void |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 99 | registerPrefix(const ndn::Name& namePrefix, const std::string& faceUri, |
akmhoque | bf11c5f | 2014-07-21 14:49:47 -0500 | [diff] [blame] | 100 | uint64_t faceCost, |
akmhoque | 060d302 | 2014-08-12 13:35:06 -0500 | [diff] [blame] | 101 | const ndn::time::milliseconds& timeout, |
| 102 | uint64_t flags, uint8_t times); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 103 | |
| 104 | void |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 105 | registerPrefix(const ndn::Name& namePrefix, |
| 106 | const std::string& faceUri, |
akmhoque | bf11c5f | 2014-07-21 14:49:47 -0500 | [diff] [blame] | 107 | uint64_t faceCost, |
| 108 | const ndn::time::milliseconds& timeout, |
akmhoque | 060d302 | 2014-08-12 13:35:06 -0500 | [diff] [blame] | 109 | uint64_t flags, |
akmhoque | 102aea4 | 2014-08-04 10:22:12 -0500 | [diff] [blame] | 110 | uint8_t times, |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 111 | const CommandSucceedCallback& onSuccess, |
| 112 | const CommandFailCallback& onFailure); |
akmhoque | 060d302 | 2014-08-12 13:35:06 -0500 | [diff] [blame] | 113 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 114 | void |
akmhoque | 393d4ff | 2014-07-16 14:27:03 -0500 | [diff] [blame] | 115 | setStrategy(const ndn::Name& name, const std::string& strategy, uint32_t count); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 116 | |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 117 | void |
| 118 | writeLog(); |
| 119 | |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 120 | void |
| 121 | destroyFace(const std::string& faceUri, |
| 122 | const CommandSucceedCallback& onSuccess, |
| 123 | const CommandFailCallback& onFailure); |
| 124 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 125 | private: |
| 126 | void |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 127 | createFace(const std::string& faceUri, |
| 128 | const CommandSucceedCallback& onSuccess, |
| 129 | const CommandFailCallback& onFailure); |
| 130 | |
| 131 | void |
akmhoque | 060d302 | 2014-08-12 13:35:06 -0500 | [diff] [blame] | 132 | registerPrefixInNfd(ndn::nfd::ControlParameters& parameters, |
akmhoque | 102aea4 | 2014-08-04 10:22:12 -0500 | [diff] [blame] | 133 | const std::string& faceUri, |
| 134 | uint8_t times); |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 135 | |
| 136 | void |
| 137 | registerPrefixInNfd(const ndn::nfd::ControlParameters& faceCreateResult, |
akmhoque | 060d302 | 2014-08-12 13:35:06 -0500 | [diff] [blame] | 138 | const ndn::nfd::ControlParameters& parameters, |
akmhoque | 102aea4 | 2014-08-04 10:22:12 -0500 | [diff] [blame] | 139 | uint8_t times, |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 140 | const CommandSucceedCallback& onSuccess, |
| 141 | const CommandFailCallback& onFailure); |
| 142 | |
| 143 | void |
| 144 | destroyFaceInNfd(const ndn::nfd::ControlParameters& faceDestroyResult, |
| 145 | const CommandSucceedCallback& onSuccess, |
| 146 | const CommandFailCallback& onFailure); |
| 147 | |
| 148 | void |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 149 | unregisterPrefix(const ndn::Name& namePrefix, const std::string& faceUri); |
| 150 | |
| 151 | void |
| 152 | onRegistration(const ndn::nfd::ControlParameters& commandSuccessResult, |
| 153 | const std::string& message, const std::string& faceUri); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 154 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 155 | void |
akmhoque | b5b3b4f | 2014-07-23 16:36:51 -0500 | [diff] [blame] | 156 | onUnregistration(const ndn::nfd::ControlParameters& commandSuccessResult, |
| 157 | const std::string& message); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 158 | |
| 159 | void |
akmhoque | 102aea4 | 2014-08-04 10:22:12 -0500 | [diff] [blame] | 160 | onRegistrationFailure(uint32_t code, const std::string& error, |
| 161 | const std::string& message, |
akmhoque | 060d302 | 2014-08-12 13:35:06 -0500 | [diff] [blame] | 162 | const ndn::nfd::ControlParameters& parameters, |
| 163 | const std::string& faceUri, |
akmhoque | 102aea4 | 2014-08-04 10:22:12 -0500 | [diff] [blame] | 164 | uint8_t times); |
| 165 | |
| 166 | void |
| 167 | onUnregistrationFailure(uint32_t code, const std::string& error, |
| 168 | const std::string& message); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 169 | |
akmhoque | 393d4ff | 2014-07-16 14:27:03 -0500 | [diff] [blame] | 170 | void |
| 171 | onSetStrategySuccess(const ndn::nfd::ControlParameters& commandSuccessResult, |
| 172 | const std::string& message); |
| 173 | |
| 174 | void |
| 175 | onSetStrategyFailure(uint32_t code, const std::string& error, |
| 176 | const ndn::nfd::ControlParameters& parameters, |
| 177 | uint32_t count, |
| 178 | const std::string& message); |
| 179 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 180 | private: |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 181 | Nlsr& m_nlsr; |
Vince Lehman | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame^] | 182 | ndn::Scheduler& m_scheduler; |
| 183 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 184 | std::list<FibEntry> m_table; |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 185 | int32_t m_refreshTime; |
| 186 | ndn::nfd::Controller m_controller; |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 187 | FaceMap m_faceMap; |
akmhoque | 393d4ff | 2014-07-16 14:27:03 -0500 | [diff] [blame] | 188 | |
| 189 | static const uint64_t GRACE_PERIOD; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 190 | }; |
| 191 | |
| 192 | }//namespace nlsr |
| 193 | #endif //NLSR_FIB_HPP |