Vince Lehman | c439d66 | 2015-04-27 10:56:00 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 3 | * Copyright (c) 2014-2020, The University of Memphis, |
Vince Lehman | c439d66 | 2015-04-27 10:56:00 -0500 | [diff] [blame] | 4 | * Regents of the University of California, |
| 5 | * Arizona Board of Regents. |
| 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 | **/ |
| 21 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 22 | #include "lsa/adj-lsa.hpp" |
| 23 | #include "lsa/coordinate-lsa.hpp" |
| 24 | #include "lsa/name-lsa.hpp" |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 25 | #include "tlv/routing-table-status.hpp" |
| 26 | |
Vince Lehman | c439d66 | 2015-04-27 10:56:00 -0500 | [diff] [blame] | 27 | #include <boost/noncopyable.hpp> |
| 28 | #include <ndn-cxx/face.hpp> |
| 29 | #include <ndn-cxx/security/key-chain.hpp> |
Muktadir R Chowdhury | 4c7caad | 2015-09-03 15:49:22 -0500 | [diff] [blame] | 30 | #include <ndn-cxx/security/validator-null.hpp> |
Vince Lehman | c439d66 | 2015-04-27 10:56:00 -0500 | [diff] [blame] | 31 | |
| 32 | #include <deque> |
| 33 | #include <map> |
| 34 | #include <stdexcept> |
| 35 | |
| 36 | #ifndef NLSR_TOOLS_NLSRC_HPP |
| 37 | #define NLSR_TOOLS_NLSRC_HPP |
| 38 | |
| 39 | namespace nlsrc { |
| 40 | |
| 41 | class Nlsrc : boost::noncopyable |
| 42 | { |
| 43 | public: |
| 44 | explicit |
| 45 | Nlsrc(ndn::Face& face); |
| 46 | |
| 47 | void |
| 48 | printUsage(); |
| 49 | |
| 50 | void |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 51 | getStatus(const std::string& command); |
Vince Lehman | c439d66 | 2015-04-27 10:56:00 -0500 | [diff] [blame] | 52 | |
| 53 | bool |
| 54 | dispatch(const std::string& cmd); |
| 55 | |
| 56 | private: |
| 57 | void |
| 58 | runNextStep(); |
| 59 | |
| 60 | /** |
| 61 | * \brief Adds a name prefix to be advertised in NLSR's Name LSA |
| 62 | * |
| 63 | * cmd format: |
| 64 | * name |
| 65 | * |
| 66 | */ |
| 67 | void |
| 68 | advertiseName(); |
| 69 | |
| 70 | /** |
| 71 | * \brief Removes a name prefix from NLSR's Name LSA |
| 72 | * |
| 73 | * cmd format: |
| 74 | * name |
| 75 | * |
| 76 | */ |
| 77 | void |
| 78 | withdrawName(); |
| 79 | |
| 80 | void |
| 81 | sendNamePrefixUpdate(const ndn::Name& name, |
| 82 | const ndn::Name::Component& verb, |
Saurab Dulal | 7526cee | 2018-01-31 18:14:10 +0000 | [diff] [blame] | 83 | const std::string& info, |
| 84 | bool saveFlag); |
Vince Lehman | c439d66 | 2015-04-27 10:56:00 -0500 | [diff] [blame] | 85 | |
| 86 | void |
| 87 | onControlResponse(const std::string& info, const ndn::Data& data); |
| 88 | |
| 89 | private: |
| 90 | void |
| 91 | fetchAdjacencyLsas(); |
| 92 | |
| 93 | void |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 94 | fetchRtables(); |
| 95 | |
| 96 | void |
| 97 | fetchHRRtables(); |
| 98 | |
| 99 | void |
Vince Lehman | c439d66 | 2015-04-27 10:56:00 -0500 | [diff] [blame] | 100 | fetchCoordinateLsas(); |
| 101 | |
| 102 | void |
| 103 | fetchNameLsas(); |
| 104 | |
| 105 | template <class T> |
| 106 | void |
| 107 | fetchFromLsdb(const ndn::Name::Component& datasetType, |
| 108 | const std::function<void(const T&)>& recordLsa); |
| 109 | |
| 110 | template <class T> |
| 111 | void |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 112 | fetchFromRt(const std::function<void(const T&)>& recordLsa); |
| 113 | |
| 114 | template <class T> |
| 115 | void |
Vince Lehman | c439d66 | 2015-04-27 10:56:00 -0500 | [diff] [blame] | 116 | onFetchSuccess(const ndn::ConstBufferPtr& data, |
| 117 | const std::function<void(const T&)>& recordLsa); |
| 118 | |
| 119 | void |
| 120 | onTimeout(uint32_t errorCode, const std::string& error); |
| 121 | |
Vince Lehman | c439d66 | 2015-04-27 10:56:00 -0500 | [diff] [blame] | 122 | void |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 123 | recordLsa(const nlsr::Lsa& lsa); |
Vince Lehman | c439d66 | 2015-04-27 10:56:00 -0500 | [diff] [blame] | 124 | |
| 125 | void |
laqinfan | a073e2e | 2018-01-15 21:17:24 +0000 | [diff] [blame] | 126 | recordRtable(const nlsr::tlv::RoutingTableStatus& rts); |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 127 | |
| 128 | void |
Vince Lehman | c439d66 | 2015-04-27 10:56:00 -0500 | [diff] [blame] | 129 | printLsdb(); |
| 130 | |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 131 | void |
| 132 | printRT(); |
| 133 | |
| 134 | void |
| 135 | printAll(); |
| 136 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 137 | std::string |
| 138 | getLsaInfo(const nlsr::Lsa& lsa); |
| 139 | |
Vince Lehman | c439d66 | 2015-04-27 10:56:00 -0500 | [diff] [blame] | 140 | public: |
| 141 | const char* programName; |
| 142 | |
| 143 | // command parameters without leading 'cmd' component |
| 144 | const char* const* commandLineArguments; |
| 145 | int nOptions; |
| 146 | |
| 147 | private: |
| 148 | struct Router |
| 149 | { |
| 150 | std::string adjacencyLsaString; |
| 151 | std::string coordinateLsaString; |
| 152 | std::string nameLsaString; |
| 153 | }; |
| 154 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 155 | std::map<ndn::Name, Router> m_routers; |
Vince Lehman | c439d66 | 2015-04-27 10:56:00 -0500 | [diff] [blame] | 156 | |
| 157 | private: |
| 158 | ndn::KeyChain m_keyChain; |
| 159 | ndn::Face& m_face; |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 160 | ndn::security::ValidatorNull m_validator; |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 161 | std::string commandString; |
laqinfan | a073e2e | 2018-01-15 21:17:24 +0000 | [diff] [blame] | 162 | std::string m_rtString; |
Vince Lehman | c439d66 | 2015-04-27 10:56:00 -0500 | [diff] [blame] | 163 | |
| 164 | std::deque<std::function<void()>> m_fetchSteps; |
| 165 | |
| 166 | static const ndn::Name LOCALHOST_PREFIX; |
| 167 | static const ndn::Name LSDB_PREFIX; |
| 168 | static const ndn::Name NAME_UPDATE_PREFIX; |
| 169 | |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 170 | static const ndn::Name RT_PREFIX; |
| 171 | |
Vince Lehman | c439d66 | 2015-04-27 10:56:00 -0500 | [diff] [blame] | 172 | static const uint32_t ERROR_CODE_TIMEOUT; |
| 173 | static const uint32_t RESPONSE_CODE_SUCCESS; |
Saurab Dulal | 7526cee | 2018-01-31 18:14:10 +0000 | [diff] [blame] | 174 | static const uint32_t RESPONSE_CODE_SAVE_OR_DELETE; |
Vince Lehman | c439d66 | 2015-04-27 10:56:00 -0500 | [diff] [blame] | 175 | }; |
| 176 | |
| 177 | } // namespace nlsrc |
| 178 | |
| 179 | #endif // NLSR_TOOLS_NLSRC_HPP |