Vince Lehman | c439d66 | 2015-04-27 10:56:00 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014-2015, The University of Memphis, |
| 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 | |
| 22 | #include "tlv/adjacency-lsa.hpp" |
| 23 | #include "tlv/coordinate-lsa.hpp" |
| 24 | #include "tlv/name-lsa.hpp" |
| 25 | |
| 26 | #include <boost/noncopyable.hpp> |
| 27 | #include <ndn-cxx/face.hpp> |
| 28 | #include <ndn-cxx/security/key-chain.hpp> |
Muktadir R Chowdhury | 4c7caad | 2015-09-03 15:49:22 -0500 | [diff] [blame^] | 29 | #include <ndn-cxx/security/validator-null.hpp> |
Vince Lehman | c439d66 | 2015-04-27 10:56:00 -0500 | [diff] [blame] | 30 | |
| 31 | #include <deque> |
| 32 | #include <map> |
| 33 | #include <stdexcept> |
| 34 | |
| 35 | #ifndef NLSR_TOOLS_NLSRC_HPP |
| 36 | #define NLSR_TOOLS_NLSRC_HPP |
| 37 | |
| 38 | namespace nlsrc { |
| 39 | |
| 40 | class Nlsrc : boost::noncopyable |
| 41 | { |
| 42 | public: |
| 43 | explicit |
| 44 | Nlsrc(ndn::Face& face); |
| 45 | |
| 46 | void |
| 47 | printUsage(); |
| 48 | |
| 49 | void |
| 50 | getStatus(); |
| 51 | |
| 52 | bool |
| 53 | dispatch(const std::string& cmd); |
| 54 | |
| 55 | private: |
| 56 | void |
| 57 | runNextStep(); |
| 58 | |
| 59 | /** |
| 60 | * \brief Adds a name prefix to be advertised in NLSR's Name LSA |
| 61 | * |
| 62 | * cmd format: |
| 63 | * name |
| 64 | * |
| 65 | */ |
| 66 | void |
| 67 | advertiseName(); |
| 68 | |
| 69 | /** |
| 70 | * \brief Removes a name prefix from NLSR's Name LSA |
| 71 | * |
| 72 | * cmd format: |
| 73 | * name |
| 74 | * |
| 75 | */ |
| 76 | void |
| 77 | withdrawName(); |
| 78 | |
| 79 | void |
| 80 | sendNamePrefixUpdate(const ndn::Name& name, |
| 81 | const ndn::Name::Component& verb, |
| 82 | const std::string& info); |
| 83 | |
| 84 | void |
| 85 | onControlResponse(const std::string& info, const ndn::Data& data); |
| 86 | |
| 87 | private: |
| 88 | void |
| 89 | fetchAdjacencyLsas(); |
| 90 | |
| 91 | void |
| 92 | fetchCoordinateLsas(); |
| 93 | |
| 94 | void |
| 95 | fetchNameLsas(); |
| 96 | |
| 97 | template <class T> |
| 98 | void |
| 99 | fetchFromLsdb(const ndn::Name::Component& datasetType, |
| 100 | const std::function<void(const T&)>& recordLsa); |
| 101 | |
| 102 | template <class T> |
| 103 | void |
| 104 | onFetchSuccess(const ndn::ConstBufferPtr& data, |
| 105 | const std::function<void(const T&)>& recordLsa); |
| 106 | |
| 107 | void |
| 108 | onTimeout(uint32_t errorCode, const std::string& error); |
| 109 | |
| 110 | private: |
| 111 | std::string |
| 112 | getLsaInfoString(const nlsr::tlv::LsaInfo& info); |
| 113 | |
| 114 | void |
| 115 | recordAdjacencyLsa(const nlsr::tlv::AdjacencyLsa& lsa); |
| 116 | |
| 117 | void |
| 118 | recordCoordinateLsa(const nlsr::tlv::CoordinateLsa& lsa); |
| 119 | |
| 120 | void |
| 121 | recordNameLsa(const nlsr::tlv::NameLsa& lsa); |
| 122 | |
| 123 | void |
| 124 | printLsdb(); |
| 125 | |
| 126 | public: |
| 127 | const char* programName; |
| 128 | |
| 129 | // command parameters without leading 'cmd' component |
| 130 | const char* const* commandLineArguments; |
| 131 | int nOptions; |
| 132 | |
| 133 | private: |
| 134 | struct Router |
| 135 | { |
| 136 | std::string adjacencyLsaString; |
| 137 | std::string coordinateLsaString; |
| 138 | std::string nameLsaString; |
| 139 | }; |
| 140 | |
| 141 | Router& |
| 142 | getRouter(const nlsr::tlv::LsaInfo& info); |
| 143 | |
| 144 | typedef std::map<const ndn::Name, Router> RouterMap; |
| 145 | RouterMap m_routers; |
| 146 | |
| 147 | private: |
| 148 | ndn::KeyChain m_keyChain; |
| 149 | ndn::Face& m_face; |
Muktadir R Chowdhury | 4c7caad | 2015-09-03 15:49:22 -0500 | [diff] [blame^] | 150 | ndn::ValidatorNull m_validator; |
Vince Lehman | c439d66 | 2015-04-27 10:56:00 -0500 | [diff] [blame] | 151 | |
| 152 | std::deque<std::function<void()>> m_fetchSteps; |
| 153 | |
| 154 | static const ndn::Name LOCALHOST_PREFIX; |
| 155 | static const ndn::Name LSDB_PREFIX; |
| 156 | static const ndn::Name NAME_UPDATE_PREFIX; |
| 157 | |
| 158 | static const uint32_t ERROR_CODE_TIMEOUT; |
| 159 | static const uint32_t RESPONSE_CODE_SUCCESS; |
| 160 | }; |
| 161 | |
| 162 | } // namespace nlsrc |
| 163 | |
| 164 | #endif // NLSR_TOOLS_NLSRC_HPP |