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" |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 29 | |
Nick Gordon | 2108808 | 2017-05-24 10:57:06 -0500 | [diff] [blame] | 30 | #include <ndn-cxx/mgmt/nfd/controller.hpp> |
Muktadir Chowdhury | 3be6466 | 2015-05-01 14:50:53 -0500 | [diff] [blame] | 31 | #include <ndn-cxx/util/time.hpp> |
| 32 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 33 | namespace nlsr { |
| 34 | |
Muktadir Chowdhury | 3be6466 | 2015-05-01 14:50:53 -0500 | [diff] [blame] | 35 | typedef std::function<void(FibEntry&)> afterRefreshCallback; |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 36 | |
Vince Lehman | 942eb7b | 2014-10-02 10:09:27 -0500 | [diff] [blame] | 37 | class AdjacencyList; |
| 38 | class ConfParameter; |
Muktadir Chowdhury | 3be6466 | 2015-05-01 14:50:53 -0500 | [diff] [blame] | 39 | class FibEntry; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 40 | |
| 41 | class Fib |
| 42 | { |
| 43 | public: |
Vince Lehman | b7079a1 | 2014-11-04 12:45:50 -0600 | [diff] [blame] | 44 | Fib(ndn::Face& face, ndn::Scheduler& scheduler, AdjacencyList& adjacencyList, ConfParameter& conf, |
| 45 | ndn::KeyChain& keyChain) |
Vince Lehman | 942eb7b | 2014-10-02 10:09:27 -0500 | [diff] [blame] | 46 | : m_scheduler(scheduler) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 47 | , m_refreshTime(0) |
Vince Lehman | b7079a1 | 2014-11-04 12:45:50 -0600 | [diff] [blame] | 48 | , m_controller(face, keyChain) |
Vince Lehman | 942eb7b | 2014-10-02 10:09:27 -0500 | [diff] [blame] | 49 | , m_adjacencyList(adjacencyList) |
| 50 | , m_confParameter(conf) |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 51 | { |
| 52 | } |
Vince Lehman | 942eb7b | 2014-10-02 10:09:27 -0500 | [diff] [blame] | 53 | |
Muktadir Chowdhury | 3be6466 | 2015-05-01 14:50:53 -0500 | [diff] [blame] | 54 | FibEntry* |
| 55 | processUpdate(const ndn::Name& name, NexthopList& allHops); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 56 | |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 57 | VIRTUAL_WITH_TESTS 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 | |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 60 | VIRTUAL_WITH_TESTS void |
| 61 | update(const ndn::Name& name, NexthopList& allHops); |
| 62 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 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 | void |
Muktadir Chowdhury | 3be6466 | 2015-05-01 14:50:53 -0500 | [diff] [blame] | 73 | registerPrefix(const ndn::Name& namePrefix, |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame^] | 74 | const ndn::util::FaceUri& faceUri, |
akmhoque | bf11c5f | 2014-07-21 14:49:47 -0500 | [diff] [blame] | 75 | uint64_t faceCost, |
akmhoque | 060d302 | 2014-08-12 13:35:06 -0500 | [diff] [blame] | 76 | const ndn::time::milliseconds& timeout, |
Muktadir Chowdhury | 3be6466 | 2015-05-01 14:50:53 -0500 | [diff] [blame] | 77 | uint64_t flags, |
| 78 | uint8_t times); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 79 | |
| 80 | void |
akmhoque | 393d4ff | 2014-07-16 14:27:03 -0500 | [diff] [blame] | 81 | setStrategy(const ndn::Name& name, const std::string& strategy, uint32_t count); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 82 | |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 83 | void |
| 84 | writeLog(); |
| 85 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 86 | private: |
Muktadir Chowdhury | 3be6466 | 2015-05-01 14:50:53 -0500 | [diff] [blame] | 87 | bool |
| 88 | isPrefixUpdatable(const ndn::Name& name); |
| 89 | |
| 90 | void |
| 91 | addNextHopsToFibEntryAndNfd(FibEntry& entry, NexthopList& hopsToAdd); |
| 92 | |
Muktadir Chowdhury | 3be6466 | 2015-05-01 14:50:53 -0500 | [diff] [blame] | 93 | unsigned int |
| 94 | getNumberOfFacesForName(NexthopList& nextHopList); |
| 95 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 96 | void |
| 97 | unregisterPrefix(const ndn::Name& namePrefix, const std::string& faceUri); |
| 98 | |
| 99 | void |
Muktadir Chowdhury | 3be6466 | 2015-05-01 14:50:53 -0500 | [diff] [blame] | 100 | onRegistrationSuccess(const ndn::nfd::ControlParameters& commandSuccessResult, |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame^] | 101 | const std::string& message, const ndn::util::FaceUri& faceUri); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 102 | |
| 103 | void |
Junxiao Shi | 63bd034 | 2016-08-17 16:57:14 +0000 | [diff] [blame] | 104 | onRegistrationFailure(const ndn::nfd::ControlResponse& response, |
akmhoque | 102aea4 | 2014-08-04 10:22:12 -0500 | [diff] [blame] | 105 | const std::string& message, |
akmhoque | 060d302 | 2014-08-12 13:35:06 -0500 | [diff] [blame] | 106 | const ndn::nfd::ControlParameters& parameters, |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame^] | 107 | const ndn::util::FaceUri& faceUri, |
akmhoque | 102aea4 | 2014-08-04 10:22:12 -0500 | [diff] [blame] | 108 | uint8_t times); |
| 109 | |
| 110 | void |
Muktadir Chowdhury | 3be6466 | 2015-05-01 14:50:53 -0500 | [diff] [blame] | 111 | onUnregistrationSuccess(const ndn::nfd::ControlParameters& commandSuccessResult, |
Junxiao Shi | 63bd034 | 2016-08-17 16:57:14 +0000 | [diff] [blame] | 112 | const std::string& message); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 113 | |
akmhoque | 393d4ff | 2014-07-16 14:27:03 -0500 | [diff] [blame] | 114 | void |
Muktadir Chowdhury | 3be6466 | 2015-05-01 14:50:53 -0500 | [diff] [blame] | 115 | onUnregistrationFailure(const ndn::nfd::ControlResponse& response, |
| 116 | const std::string& message); |
| 117 | |
| 118 | void |
akmhoque | 393d4ff | 2014-07-16 14:27:03 -0500 | [diff] [blame] | 119 | onSetStrategySuccess(const ndn::nfd::ControlParameters& commandSuccessResult, |
| 120 | const std::string& message); |
| 121 | |
| 122 | void |
Junxiao Shi | 63bd034 | 2016-08-17 16:57:14 +0000 | [diff] [blame] | 123 | onSetStrategyFailure(const ndn::nfd::ControlResponse& response, |
akmhoque | 393d4ff | 2014-07-16 14:27:03 -0500 | [diff] [blame] | 124 | const ndn::nfd::ControlParameters& parameters, |
| 125 | uint32_t count, |
| 126 | const std::string& message); |
| 127 | |
Muktadir Chowdhury | 3be6466 | 2015-05-01 14:50:53 -0500 | [diff] [blame] | 128 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
| 129 | void |
| 130 | scheduleEntryRefresh(FibEntry& entry, const afterRefreshCallback& refreshCb); |
| 131 | |
| 132 | private: |
| 133 | void |
| 134 | scheduleLoop(FibEntry& entry); |
| 135 | |
| 136 | void |
| 137 | cancelEntryRefresh(const FibEntry& entry); |
| 138 | |
| 139 | void |
| 140 | refreshEntry(const ndn::Name& name, afterRefreshCallback refreshCb); |
| 141 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 142 | private: |
Vince Lehman | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame] | 143 | ndn::Scheduler& m_scheduler; |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 144 | int32_t m_refreshTime; |
| 145 | ndn::nfd::Controller m_controller; |
Vince Lehman | 942eb7b | 2014-10-02 10:09:27 -0500 | [diff] [blame] | 146 | |
| 147 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 148 | FaceMap m_faceMap; |
Muktadir Chowdhury | 3be6466 | 2015-05-01 14:50:53 -0500 | [diff] [blame] | 149 | std::map<ndn::Name, FibEntry> m_table; |
akmhoque | 393d4ff | 2014-07-16 14:27:03 -0500 | [diff] [blame] | 150 | |
Vince Lehman | 942eb7b | 2014-10-02 10:09:27 -0500 | [diff] [blame] | 151 | private: |
| 152 | AdjacencyList& m_adjacencyList; |
| 153 | ConfParameter& m_confParameter; |
| 154 | |
akmhoque | 393d4ff | 2014-07-16 14:27:03 -0500 | [diff] [blame] | 155 | static const uint64_t GRACE_PERIOD; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 156 | }; |
| 157 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame] | 158 | } // namespace nlsr |
Muktadir Chowdhury | 3be6466 | 2015-05-01 14:50:53 -0500 | [diff] [blame] | 159 | |
| 160 | #endif // NLSR_ROUTE_FIB_HPP |