Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | a997d29 | 2017-08-24 20:16:59 -0400 | [diff] [blame] | 2 | /* |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2022, Regents of the University of California, |
Junxiao Shi | fbf7834 | 2015-01-23 14:46:41 -0700 | [diff] [blame] | 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
Junxiao Shi | dda0b46 | 2014-06-30 19:42:29 -0700 | [diff] [blame] | 24 | */ |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 25 | |
Davide Pesavento | a997d29 | 2017-08-24 20:16:59 -0400 | [diff] [blame] | 26 | #include "core/network.hpp" |
| 27 | #include "core/version.hpp" |
| 28 | |
Alexander Afanasyev | 4a77136 | 2014-04-24 21:29:33 -0700 | [diff] [blame] | 29 | #include <ndn-cxx/face.hpp> |
Junxiao Shi | 25c6ce4 | 2016-09-09 13:49:59 +0000 | [diff] [blame] | 30 | #include <ndn-cxx/mgmt/nfd/controller.hpp> |
| 31 | #include <ndn-cxx/mgmt/nfd/face-monitor.hpp> |
| 32 | #include <ndn-cxx/mgmt/nfd/face-status.hpp> |
Junxiao Shi | 83be1da | 2017-06-30 13:37:37 +0000 | [diff] [blame] | 33 | #include <ndn-cxx/net/face-uri.hpp> |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 34 | #include <ndn-cxx/security/key-chain.hpp> |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 35 | |
Davide Pesavento | 97e3302 | 2019-02-14 16:00:50 -0500 | [diff] [blame] | 36 | #include <boost/exception/diagnostic_information.hpp> |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 37 | #include <boost/program_options/options_description.hpp> |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 38 | #include <boost/program_options/parsers.hpp> |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 39 | #include <boost/program_options/variables_map.hpp> |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 40 | |
Davide Pesavento | a997d29 | 2017-08-24 20:16:59 -0400 | [diff] [blame] | 41 | #include <iostream> |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 42 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 43 | namespace nfd::tools::autoreg { |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 44 | |
Junxiao Shi | dda0b46 | 2014-06-30 19:42:29 -0700 | [diff] [blame] | 45 | class AutoregServer : boost::noncopyable |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 46 | { |
| 47 | public: |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 48 | static void |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 49 | onRegisterCommandSuccess(uint64_t faceId, const Name& prefix) |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 50 | { |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 51 | std::cerr << "SUCCESS: register " << prefix << " on face " << faceId << std::endl; |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 52 | } |
| 53 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 54 | static void |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 55 | onRegisterCommandFailure(uint64_t faceId, const Name& prefix, |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 56 | const ndn::nfd::ControlResponse& response) |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 57 | { |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 58 | std::cerr << "FAILED: register " << prefix << " on face " << faceId |
Junxiao Shi | 29b4128 | 2016-08-22 03:47:02 +0000 | [diff] [blame] | 59 | << " (code: " << response.getCode() << ", reason: " << response.getText() << ")" |
| 60 | << std::endl; |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Junxiao Shi | dda0b46 | 2014-06-30 19:42:29 -0700 | [diff] [blame] | 63 | /** |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 64 | * \return true if uri has schema allowed to do auto-registrations |
Junxiao Shi | dda0b46 | 2014-06-30 19:42:29 -0700 | [diff] [blame] | 65 | */ |
Davide Pesavento | 59769b1 | 2017-11-12 23:52:06 -0500 | [diff] [blame] | 66 | static bool |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 67 | hasAllowedSchema(const FaceUri& uri) |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 68 | { |
| 69 | const std::string& scheme = uri.getScheme(); |
Davide Pesavento | 59769b1 | 2017-11-12 23:52:06 -0500 | [diff] [blame] | 70 | return scheme == "udp4" || scheme == "tcp4" || |
| 71 | scheme == "udp6" || scheme == "tcp6"; |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 72 | } |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 73 | |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 74 | /** |
Alexander Afanasyev | f056c11 | 2014-08-14 16:39:25 -0700 | [diff] [blame] | 75 | * \return true if address is blacklisted |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 76 | */ |
| 77 | bool |
Davide Pesavento | 59769b1 | 2017-11-12 23:52:06 -0500 | [diff] [blame] | 78 | isBlacklisted(const boost::asio::ip::address& address) const |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 79 | { |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 80 | return std::any_of(m_blackList.begin(), m_blackList.end(), |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 81 | [&] (const auto& net) { return net.doesContain(address); }); |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | /** |
Alexander Afanasyev | f056c11 | 2014-08-14 16:39:25 -0700 | [diff] [blame] | 85 | * \return true if address is whitelisted |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 86 | */ |
| 87 | bool |
Davide Pesavento | 59769b1 | 2017-11-12 23:52:06 -0500 | [diff] [blame] | 88 | isWhitelisted(const boost::asio::ip::address& address) const |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 89 | { |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 90 | return std::any_of(m_whiteList.begin(), m_whiteList.end(), |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 91 | [&] (const auto& net) { return net.doesContain(address); }); |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | void |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 95 | registerPrefixesForFace(uint64_t faceId, const std::vector<Name>& prefixes) |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 96 | { |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 97 | for (const Name& prefix : prefixes) { |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 98 | m_controller.start<ndn::nfd::RibRegisterCommand>( |
| 99 | ndn::nfd::ControlParameters() |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 100 | .setName(prefix) |
| 101 | .setFaceId(faceId) |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 102 | .setOrigin(ndn::nfd::ROUTE_ORIGIN_AUTOREG) |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 103 | .setCost(m_cost) |
| 104 | .setExpirationPeriod(time::milliseconds::max()), |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 105 | [=] (auto&&...) { onRegisterCommandSuccess(faceId, prefix); }, |
| 106 | [=] (const auto& response) { onRegisterCommandFailure(faceId, prefix, response); }); |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 107 | } |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | void |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 111 | registerPrefixesIfNeeded(uint64_t faceId, const FaceUri& uri, ndn::nfd::FacePersistency facePersistency) |
Alexander Afanasyev | f056c11 | 2014-08-14 16:39:25 -0700 | [diff] [blame] | 112 | { |
| 113 | if (hasAllowedSchema(uri)) { |
| 114 | boost::system::error_code ec; |
Davide Pesavento | 9c33b90 | 2018-05-20 01:30:29 -0400 | [diff] [blame] | 115 | auto address = boost::asio::ip::address::from_string(uri.getHost(), ec); |
Alexander Afanasyev | f056c11 | 2014-08-14 16:39:25 -0700 | [diff] [blame] | 116 | |
| 117 | if (!address.is_multicast()) { |
| 118 | // register all-face prefixes |
| 119 | registerPrefixesForFace(faceId, m_allFacesPrefixes); |
| 120 | |
| 121 | // register autoreg prefixes if new face is on-demand and not blacklisted and whitelisted |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 122 | if (facePersistency == ndn::nfd::FACE_PERSISTENCY_ON_DEMAND && |
Chengyu Fan | 9942cea | 2014-10-13 14:47:13 -0600 | [diff] [blame] | 123 | !isBlacklisted(address) && isWhitelisted(address)) { |
Alexander Afanasyev | f056c11 | 2014-08-14 16:39:25 -0700 | [diff] [blame] | 124 | registerPrefixesForFace(faceId, m_autoregPrefixes); |
| 125 | } |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | void |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 131 | onNotification(const ndn::nfd::FaceEventNotification& notification) |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 132 | { |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 133 | if (notification.getKind() == ndn::nfd::FACE_EVENT_CREATED && |
| 134 | notification.getFaceScope() != ndn::nfd::FACE_SCOPE_LOCAL) { |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 135 | std::cerr << "PROCESSING: " << notification << std::endl; |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 136 | |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 137 | registerPrefixesIfNeeded(notification.getFaceId(), FaceUri(notification.getRemoteUri()), |
| 138 | notification.getFacePersistency()); |
| 139 | } |
| 140 | else { |
| 141 | std::cerr << "IGNORED: " << notification << std::endl; |
| 142 | } |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 143 | } |
| 144 | |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 145 | void |
| 146 | startProcessing() |
| 147 | { |
Junxiao Shi | dda0b46 | 2014-06-30 19:42:29 -0700 | [diff] [blame] | 148 | std::cerr << "AUTOREG prefixes: " << std::endl; |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 149 | for (const Name& prefix : m_autoregPrefixes) { |
| 150 | std::cout << " " << prefix << std::endl; |
| 151 | } |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 152 | std::cerr << "ALL-FACES-AUTOREG prefixes: " << std::endl; |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 153 | for (const Name& prefix : m_allFacesPrefixes) { |
| 154 | std::cout << " " << prefix << std::endl; |
| 155 | } |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 156 | |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 157 | if (!m_blackList.empty()) { |
| 158 | std::cerr << "Blacklisted networks: " << std::endl; |
| 159 | for (const Network& network : m_blackList) { |
| 160 | std::cout << " " << network << std::endl; |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 161 | } |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 162 | } |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 163 | |
Junxiao Shi | dda0b46 | 2014-06-30 19:42:29 -0700 | [diff] [blame] | 164 | std::cerr << "Whitelisted networks: " << std::endl; |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 165 | for (const Network& network : m_whiteList) { |
| 166 | std::cout << " " << network << std::endl; |
| 167 | } |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 168 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 169 | m_faceMonitor.onNotification.connect([this] (const auto& notif) { onNotification(notif); }); |
Junxiao Shi | 15b12e7 | 2014-08-09 19:56:24 -0700 | [diff] [blame] | 170 | m_faceMonitor.start(); |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 171 | |
Alexander Afanasyev | b3893c9 | 2014-05-15 01:49:54 -0700 | [diff] [blame] | 172 | boost::asio::signal_set signalSet(m_face.getIoService(), SIGINT, SIGTERM); |
Davide Pesavento | 412c982 | 2021-07-02 00:21:05 -0400 | [diff] [blame] | 173 | signalSet.async_wait([this] (auto&&...) { m_face.shutdown(); }); |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 174 | |
| 175 | m_face.processEvents(); |
| 176 | } |
| 177 | |
Alexander Afanasyev | f056c11 | 2014-08-14 16:39:25 -0700 | [diff] [blame] | 178 | void |
| 179 | startFetchingFaceStatusDataset() |
| 180 | { |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 181 | m_controller.fetch<ndn::nfd::FaceDataset>( |
Davide Pesavento | 412c982 | 2021-07-02 00:21:05 -0400 | [diff] [blame] | 182 | [this] (const auto& faces) { |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 183 | for (const auto& faceStatus : faces) { |
Weiwei Liu | 7c79513 | 2016-10-07 14:22:54 -0700 | [diff] [blame] | 184 | registerPrefixesIfNeeded(faceStatus.getFaceId(), FaceUri(faceStatus.getRemoteUri()), |
| 185 | faceStatus.getFacePersistency()); |
| 186 | } |
| 187 | }, |
Davide Pesavento | 412c982 | 2021-07-02 00:21:05 -0400 | [diff] [blame] | 188 | [] (auto&&...) {}); |
Alexander Afanasyev | f056c11 | 2014-08-14 16:39:25 -0700 | [diff] [blame] | 189 | } |
| 190 | |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 191 | int |
| 192 | main(int argc, char* argv[]) |
| 193 | { |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 194 | namespace po = boost::program_options; |
| 195 | |
Davide Pesavento | 59769b1 | 2017-11-12 23:52:06 -0500 | [diff] [blame] | 196 | po::options_description optionsDesc("Options"); |
| 197 | optionsDesc.add_options() |
| 198 | ("help,h", "print this message and exit") |
| 199 | ("version,V", "show version information and exit") |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 200 | ("prefix,i", po::value<std::vector<Name>>(&m_autoregPrefixes)->composing(), |
Davide Pesavento | 59769b1 | 2017-11-12 23:52:06 -0500 | [diff] [blame] | 201 | "prefix that should be automatically registered when a new non-local face is created") |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 202 | ("all-faces-prefix,a", po::value<std::vector<Name>>(&m_allFacesPrefixes)->composing(), |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 203 | "prefix that should be automatically registered for all TCP and UDP non-local faces " |
| 204 | "(blacklists and whitelists do not apply to this prefix)") |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 205 | ("cost,c", po::value<uint64_t>(&m_cost)->default_value(m_cost), |
Davide Pesavento | 59769b1 | 2017-11-12 23:52:06 -0500 | [diff] [blame] | 206 | "FIB cost that should be assigned to autoreg nexthops") |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 207 | ("whitelist,w", po::value<std::vector<Network>>(&m_whiteList)->composing(), |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 208 | "Whitelisted network, e.g., 192.168.2.0/24 or ::1/128") |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 209 | ("blacklist,b", po::value<std::vector<Network>>(&m_blackList)->composing(), |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 210 | "Blacklisted network, e.g., 192.168.2.32/30 or ::1/128") |
| 211 | ; |
| 212 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 213 | auto usage = [&] (std::ostream& os) { |
| 214 | os << "Usage: " << argv[0] << " [--prefix=</autoreg/prefix>]... [options]\n" |
| 215 | << "\n" |
| 216 | << optionsDesc; |
| 217 | }; |
| 218 | |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 219 | po::variables_map options; |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 220 | try { |
Davide Pesavento | 59769b1 | 2017-11-12 23:52:06 -0500 | [diff] [blame] | 221 | po::store(po::parse_command_line(argc, argv, optionsDesc), options); |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 222 | po::notify(options); |
| 223 | } |
| 224 | catch (const std::exception& e) { |
| 225 | std::cerr << "ERROR: " << e.what() << std::endl << std::endl; |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 226 | usage(std::cerr); |
Davide Pesavento | 59769b1 | 2017-11-12 23:52:06 -0500 | [diff] [blame] | 227 | return 2; |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 228 | } |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 229 | |
Davide Pesavento | 59769b1 | 2017-11-12 23:52:06 -0500 | [diff] [blame] | 230 | if (options.count("help") > 0) { |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 231 | usage(std::cout); |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 232 | return 0; |
| 233 | } |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 234 | |
Davide Pesavento | 59769b1 | 2017-11-12 23:52:06 -0500 | [diff] [blame] | 235 | if (options.count("version") > 0) { |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 236 | std::cout << NFD_VERSION_BUILD_STRING << std::endl; |
| 237 | return 0; |
| 238 | } |
Alexander Afanasyev | b47d538 | 2014-05-05 14:35:03 -0700 | [diff] [blame] | 239 | |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 240 | if (m_autoregPrefixes.empty() && m_allFacesPrefixes.empty()) { |
| 241 | std::cerr << "ERROR: at least one --prefix or --all-faces-prefix must be specified" |
| 242 | << std::endl << std::endl; |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 243 | usage(std::cerr); |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 244 | return 2; |
| 245 | } |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 246 | |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 247 | if (m_whiteList.empty()) { |
| 248 | // Allow everything |
| 249 | m_whiteList.push_back(Network::getMaxRangeV4()); |
| 250 | m_whiteList.push_back(Network::getMaxRangeV6()); |
| 251 | } |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 252 | |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 253 | try { |
| 254 | startFetchingFaceStatusDataset(); |
| 255 | startProcessing(); |
| 256 | } |
| 257 | catch (const std::exception& e) { |
Davide Pesavento | 97e3302 | 2019-02-14 16:00:50 -0500 | [diff] [blame] | 258 | std::cerr << "ERROR: " << boost::diagnostic_information(e); |
Davide Pesavento | 59769b1 | 2017-11-12 23:52:06 -0500 | [diff] [blame] | 259 | return 1; |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 260 | } |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 261 | |
| 262 | return 0; |
| 263 | } |
| 264 | |
| 265 | private: |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 266 | ndn::Face m_face; |
| 267 | ndn::KeyChain m_keyChain; |
| 268 | ndn::nfd::Controller m_controller{m_face, m_keyChain}; |
| 269 | ndn::nfd::FaceMonitor m_faceMonitor{m_face}; |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 270 | std::vector<Name> m_autoregPrefixes; |
| 271 | std::vector<Name> m_allFacesPrefixes; |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 272 | uint64_t m_cost = 255; |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 273 | std::vector<Network> m_whiteList; |
| 274 | std::vector<Network> m_blackList; |
| 275 | }; |
| 276 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 277 | } // namespace nfd::tools::autoreg |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 278 | |
| 279 | int |
| 280 | main(int argc, char* argv[]) |
| 281 | { |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 282 | nfd::tools::autoreg::AutoregServer server; |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 283 | return server.main(argc, argv); |
| 284 | } |