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