Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, 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 | |
Alexander Afanasyev | 4a77136 | 2014-04-24 21:29:33 -0700 | [diff] [blame] | 26 | #include <ndn-cxx/face.hpp> |
| 27 | #include <ndn-cxx/name.hpp> |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 28 | |
Junxiao Shi | 8e273ca | 2014-11-12 00:42:29 -0700 | [diff] [blame] | 29 | #include <ndn-cxx/security/key-chain.hpp> |
Junxiao Shi | a1937bf | 2014-11-06 11:43:40 -0700 | [diff] [blame] | 30 | #include <ndn-cxx/util/face-uri.hpp> |
Junxiao Shi | 25c6ce4 | 2016-09-09 13:49:59 +0000 | [diff] [blame] | 31 | #include <ndn-cxx/mgmt/nfd/controller.hpp> |
| 32 | #include <ndn-cxx/mgmt/nfd/face-monitor.hpp> |
| 33 | #include <ndn-cxx/mgmt/nfd/face-status.hpp> |
Alexander Afanasyev | f056c11 | 2014-08-14 16:39:25 -0700 | [diff] [blame] | 34 | #include <ndn-cxx/encoding/buffer-stream.hpp> |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 35 | |
| 36 | #include <boost/program_options/options_description.hpp> |
| 37 | #include <boost/program_options/variables_map.hpp> |
| 38 | #include <boost/program_options/parsers.hpp> |
| 39 | |
Junxiao Shi | 9f5b01d | 2016-08-05 03:54:28 +0000 | [diff] [blame] | 40 | #include "core/version.hpp" |
Alexander Afanasyev | 689f0e9 | 2014-11-09 12:09:00 -0800 | [diff] [blame] | 41 | #include "core/network.hpp" |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 42 | |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 43 | using namespace ndn::nfd; |
Junxiao Shi | a1937bf | 2014-11-06 11:43:40 -0700 | [diff] [blame] | 44 | using ndn::util::FaceUri; |
| 45 | using ::nfd::Network; |
| 46 | |
| 47 | namespace ndn { |
| 48 | namespace nfd_autoreg { |
| 49 | |
Junxiao Shi | dda0b46 | 2014-06-30 19:42:29 -0700 | [diff] [blame] | 50 | class AutoregServer : boost::noncopyable |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 51 | { |
| 52 | public: |
| 53 | AutoregServer() |
Junxiao Shi | 8e273ca | 2014-11-12 00:42:29 -0700 | [diff] [blame] | 54 | : m_controller(m_face, m_keyChain) |
Junxiao Shi | 15b12e7 | 2014-08-09 19:56:24 -0700 | [diff] [blame] | 55 | , m_faceMonitor(m_face) |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 56 | , m_cost(255) |
| 57 | { |
| 58 | } |
| 59 | |
| 60 | void |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 61 | onRegisterCommandSuccess(uint64_t faceId, const Name& prefix) |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 62 | { |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 63 | std::cerr << "SUCCEED: register " << prefix << " on face " << faceId << std::endl; |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | void |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 67 | onRegisterCommandFailure(uint64_t faceId, const Name& prefix, |
Junxiao Shi | 29b4128 | 2016-08-22 03:47:02 +0000 | [diff] [blame] | 68 | const nfd::ControlResponse& response) |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 69 | { |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 70 | std::cerr << "FAILED: register " << prefix << " on face " << faceId |
Junxiao Shi | 29b4128 | 2016-08-22 03:47:02 +0000 | [diff] [blame] | 71 | << " (code: " << response.getCode() << ", reason: " << response.getText() << ")" |
| 72 | << std::endl; |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 73 | } |
| 74 | |
Junxiao Shi | dda0b46 | 2014-06-30 19:42:29 -0700 | [diff] [blame] | 75 | /** |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 76 | * \return true if uri has schema allowed to do auto-registrations |
Junxiao Shi | dda0b46 | 2014-06-30 19:42:29 -0700 | [diff] [blame] | 77 | */ |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 78 | bool |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 79 | hasAllowedSchema(const FaceUri& uri) |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 80 | { |
| 81 | const std::string& scheme = uri.getScheme(); |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 82 | return (scheme == "udp4" || scheme == "tcp4" || |
| 83 | scheme == "udp6" || scheme == "tcp6"); |
| 84 | } |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 85 | |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 86 | /** |
Alexander Afanasyev | f056c11 | 2014-08-14 16:39:25 -0700 | [diff] [blame] | 87 | * \return true if address is blacklisted |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 88 | */ |
| 89 | bool |
Alexander Afanasyev | f056c11 | 2014-08-14 16:39:25 -0700 | [diff] [blame] | 90 | isBlacklisted(const boost::asio::ip::address& address) |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 91 | { |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 92 | for (std::vector<Network>::const_iterator network = m_blackList.begin(); |
| 93 | network != m_blackList.end(); |
| 94 | ++network) |
| 95 | { |
| 96 | if (network->doesContain(address)) |
| 97 | return true; |
| 98 | } |
| 99 | |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 100 | return false; |
| 101 | } |
| 102 | |
| 103 | /** |
Alexander Afanasyev | f056c11 | 2014-08-14 16:39:25 -0700 | [diff] [blame] | 104 | * \return true if address is whitelisted |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 105 | */ |
| 106 | bool |
Alexander Afanasyev | f056c11 | 2014-08-14 16:39:25 -0700 | [diff] [blame] | 107 | isWhitelisted(const boost::asio::ip::address& address) |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 108 | { |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 109 | for (std::vector<Network>::const_iterator network = m_whiteList.begin(); |
| 110 | network != m_whiteList.end(); |
| 111 | ++network) |
| 112 | { |
| 113 | if (network->doesContain(address)) |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 114 | return true; |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 117 | return false; |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | void |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 121 | registerPrefixesForFace(uint64_t faceId, const std::vector<Name>& prefixes) |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 122 | { |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 123 | for (std::vector<Name>::const_iterator prefix = prefixes.begin(); |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 124 | prefix != prefixes.end(); |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 125 | ++prefix) |
| 126 | { |
Junxiao Shi | dda0b46 | 2014-06-30 19:42:29 -0700 | [diff] [blame] | 127 | m_controller.start<RibRegisterCommand>( |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 128 | ControlParameters() |
| 129 | .setName(*prefix) |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 130 | .setFaceId(faceId) |
Junxiao Shi | dda0b46 | 2014-06-30 19:42:29 -0700 | [diff] [blame] | 131 | .setOrigin(ROUTE_ORIGIN_AUTOREG) |
| 132 | .setCost(m_cost) |
| 133 | .setExpirationPeriod(time::milliseconds::max()), |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 134 | bind(&AutoregServer::onRegisterCommandSuccess, this, faceId, *prefix), |
Junxiao Shi | 29b4128 | 2016-08-22 03:47:02 +0000 | [diff] [blame] | 135 | bind(&AutoregServer::onRegisterCommandFailure, this, faceId, *prefix, _1)); |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 136 | } |
| 137 | } |
| 138 | |
| 139 | void |
Chengyu Fan | 9942cea | 2014-10-13 14:47:13 -0600 | [diff] [blame] | 140 | registerPrefixesIfNeeded(uint64_t faceId, const FaceUri& uri, FacePersistency facePersistency) |
Alexander Afanasyev | f056c11 | 2014-08-14 16:39:25 -0700 | [diff] [blame] | 141 | { |
| 142 | if (hasAllowedSchema(uri)) { |
| 143 | boost::system::error_code ec; |
| 144 | boost::asio::ip::address address = boost::asio::ip::address::from_string(uri.getHost(), ec); |
| 145 | |
| 146 | if (!address.is_multicast()) { |
| 147 | // register all-face prefixes |
| 148 | registerPrefixesForFace(faceId, m_allFacesPrefixes); |
| 149 | |
| 150 | // register autoreg prefixes if new face is on-demand and not blacklisted and whitelisted |
Chengyu Fan | 9942cea | 2014-10-13 14:47:13 -0600 | [diff] [blame] | 151 | if (facePersistency == FACE_PERSISTENCY_ON_DEMAND && |
| 152 | !isBlacklisted(address) && isWhitelisted(address)) { |
Alexander Afanasyev | f056c11 | 2014-08-14 16:39:25 -0700 | [diff] [blame] | 153 | registerPrefixesForFace(faceId, m_autoregPrefixes); |
| 154 | } |
| 155 | } |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | void |
Junxiao Shi | 15b12e7 | 2014-08-09 19:56:24 -0700 | [diff] [blame] | 160 | onNotification(const FaceEventNotification& notification) |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 161 | { |
Junxiao Shi | 6e69432 | 2014-04-03 10:27:13 -0700 | [diff] [blame] | 162 | if (notification.getKind() == FACE_EVENT_CREATED && |
Chengyu Fan | 9942cea | 2014-10-13 14:47:13 -0600 | [diff] [blame] | 163 | notification.getFaceScope() != FACE_SCOPE_LOCAL) |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 164 | { |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 165 | std::cerr << "PROCESSING: " << notification << std::endl; |
| 166 | |
Alexander Afanasyev | f056c11 | 2014-08-14 16:39:25 -0700 | [diff] [blame] | 167 | registerPrefixesIfNeeded(notification.getFaceId(), FaceUri(notification.getRemoteUri()), |
Chengyu Fan | 9942cea | 2014-10-13 14:47:13 -0600 | [diff] [blame] | 168 | notification.getFacePersistency()); |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 169 | } |
| 170 | else |
| 171 | { |
Junxiao Shi | dda0b46 | 2014-06-30 19:42:29 -0700 | [diff] [blame] | 172 | std::cerr << "IGNORED: " << notification << std::endl; |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 173 | } |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | void |
| 177 | signalHandler() |
| 178 | { |
| 179 | m_face.shutdown(); |
| 180 | } |
| 181 | |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 182 | void |
Alexander Afanasyev | 60a7ba5 | 2014-03-23 11:23:06 -0700 | [diff] [blame] | 183 | usage(std::ostream& os, |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 184 | const boost::program_options::options_description& desc, |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 185 | const char* programName) |
| 186 | { |
Alexander Afanasyev | 60a7ba5 | 2014-03-23 11:23:06 -0700 | [diff] [blame] | 187 | os << "Usage:\n" |
| 188 | << " " << programName << " --prefix=</autoreg/prefix> [--prefix=/another/prefix] ...\n" |
| 189 | << "\n"; |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 190 | os << desc; |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | void |
| 194 | startProcessing() |
| 195 | { |
Junxiao Shi | dda0b46 | 2014-06-30 19:42:29 -0700 | [diff] [blame] | 196 | std::cerr << "AUTOREG prefixes: " << std::endl; |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 197 | for (std::vector<Name>::const_iterator prefix = m_autoregPrefixes.begin(); |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 198 | prefix != m_autoregPrefixes.end(); |
| 199 | ++prefix) |
| 200 | { |
| 201 | std::cout << " " << *prefix << std::endl; |
| 202 | } |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 203 | std::cerr << "ALL-FACES-AUTOREG prefixes: " << std::endl; |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 204 | for (std::vector<Name>::const_iterator prefix = m_allFacesPrefixes.begin(); |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 205 | prefix != m_allFacesPrefixes.end(); |
| 206 | ++prefix) |
| 207 | { |
| 208 | std::cout << " " << *prefix << std::endl; |
| 209 | } |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 210 | |
| 211 | if (!m_blackList.empty()) |
| 212 | { |
Junxiao Shi | dda0b46 | 2014-06-30 19:42:29 -0700 | [diff] [blame] | 213 | std::cerr << "Blacklisted networks: " << std::endl; |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 214 | for (std::vector<Network>::const_iterator network = m_blackList.begin(); |
| 215 | network != m_blackList.end(); |
| 216 | ++network) |
| 217 | { |
| 218 | std::cout << " " << *network << std::endl; |
| 219 | } |
| 220 | } |
| 221 | |
Junxiao Shi | dda0b46 | 2014-06-30 19:42:29 -0700 | [diff] [blame] | 222 | std::cerr << "Whitelisted networks: " << std::endl; |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 223 | for (std::vector<Network>::const_iterator network = m_whiteList.begin(); |
| 224 | network != m_whiteList.end(); |
| 225 | ++network) |
| 226 | { |
| 227 | std::cout << " " << *network << std::endl; |
| 228 | } |
| 229 | |
Junxiao Shi | fbf7834 | 2015-01-23 14:46:41 -0700 | [diff] [blame] | 230 | m_faceMonitor.onNotification.connect(bind(&AutoregServer::onNotification, this, _1)); |
Junxiao Shi | 15b12e7 | 2014-08-09 19:56:24 -0700 | [diff] [blame] | 231 | m_faceMonitor.start(); |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 232 | |
Alexander Afanasyev | b3893c9 | 2014-05-15 01:49:54 -0700 | [diff] [blame] | 233 | boost::asio::signal_set signalSet(m_face.getIoService(), SIGINT, SIGTERM); |
Alexander Afanasyev | f698028 | 2014-05-13 18:28:40 -0700 | [diff] [blame] | 234 | signalSet.async_wait(bind(&AutoregServer::signalHandler, this)); |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 235 | |
| 236 | m_face.processEvents(); |
| 237 | } |
| 238 | |
Alexander Afanasyev | f056c11 | 2014-08-14 16:39:25 -0700 | [diff] [blame] | 239 | void |
| 240 | startFetchingFaceStatusDataset() |
| 241 | { |
Weiwei Liu | 7c79513 | 2016-10-07 14:22:54 -0700 | [diff] [blame] | 242 | m_controller.fetch<FaceDataset>( |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 243 | [this] (const std::vector<FaceStatus>& faces) { |
| 244 | for (const auto& faceStatus : faces) { |
Weiwei Liu | 7c79513 | 2016-10-07 14:22:54 -0700 | [diff] [blame] | 245 | registerPrefixesIfNeeded(faceStatus.getFaceId(), FaceUri(faceStatus.getRemoteUri()), |
| 246 | faceStatus.getFacePersistency()); |
| 247 | } |
| 248 | }, |
| 249 | [this] (uint32_t code, const std::string& reason) {}); |
Alexander Afanasyev | f056c11 | 2014-08-14 16:39:25 -0700 | [diff] [blame] | 250 | } |
| 251 | |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 252 | int |
| 253 | main(int argc, char* argv[]) |
| 254 | { |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 255 | namespace po = boost::program_options; |
| 256 | |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 257 | po::options_description optionDesciption; |
| 258 | optionDesciption.add_options() |
| 259 | ("help,h", "produce help message") |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 260 | ("prefix,i", po::value<std::vector<Name>>(&m_autoregPrefixes)->composing(), |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 261 | "prefix that should be automatically registered when new a remote non-local face is " |
| 262 | "established") |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 263 | ("all-faces-prefix,a", po::value<std::vector<Name>>(&m_allFacesPrefixes)->composing(), |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 264 | "prefix that should be automatically registered for all TCP and UDP non-local faces " |
| 265 | "(blacklists and whitelists do not apply to this prefix)") |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 266 | ("cost,c", po::value<uint64_t>(&m_cost)->default_value(255), |
| 267 | "FIB cost which should be assigned to autoreg nexthops") |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 268 | ("whitelist,w", po::value<std::vector<Network>>(&m_whiteList)->composing(), |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 269 | "Whitelisted network, e.g., 192.168.2.0/24 or ::1/128") |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 270 | ("blacklist,b", po::value<std::vector<Network>>(&m_blackList)->composing(), |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 271 | "Blacklisted network, e.g., 192.168.2.32/30 or ::1/128") |
Alexander Afanasyev | b47d538 | 2014-05-05 14:35:03 -0700 | [diff] [blame] | 272 | ("version,V", "show version and exit") |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 273 | ; |
| 274 | |
| 275 | po::variables_map options; |
| 276 | try |
| 277 | { |
| 278 | po::store(po::command_line_parser(argc, argv).options(optionDesciption).run(), options); |
| 279 | po::notify(options); |
| 280 | } |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 281 | catch (const std::exception& e) |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 282 | { |
| 283 | std::cerr << "ERROR: " << e.what() << std::endl << std::endl; |
Alexander Afanasyev | 60a7ba5 | 2014-03-23 11:23:06 -0700 | [diff] [blame] | 284 | usage(std::cerr, optionDesciption, argv[0]); |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 285 | return 1; |
| 286 | } |
| 287 | |
| 288 | if (options.count("help")) |
| 289 | { |
Alexander Afanasyev | 60a7ba5 | 2014-03-23 11:23:06 -0700 | [diff] [blame] | 290 | usage(std::cout, optionDesciption, argv[0]); |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 291 | return 0; |
| 292 | } |
| 293 | |
Alexander Afanasyev | b47d538 | 2014-05-05 14:35:03 -0700 | [diff] [blame] | 294 | if (options.count("version")) |
| 295 | { |
| 296 | std::cout << NFD_VERSION_BUILD_STRING << std::endl; |
| 297 | return 0; |
| 298 | } |
| 299 | |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 300 | if (m_autoregPrefixes.empty() && m_allFacesPrefixes.empty()) |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 301 | { |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 302 | std::cerr << "ERROR: at least one --prefix or --all-faces-prefix must be specified" |
| 303 | << std::endl << std::endl; |
Alexander Afanasyev | 60a7ba5 | 2014-03-23 11:23:06 -0700 | [diff] [blame] | 304 | usage(std::cerr, optionDesciption, argv[0]); |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 305 | return 2; |
| 306 | } |
| 307 | |
| 308 | if (m_whiteList.empty()) |
| 309 | { |
| 310 | // Allow everything |
| 311 | m_whiteList.push_back(Network::getMaxRangeV4()); |
| 312 | m_whiteList.push_back(Network::getMaxRangeV6()); |
| 313 | } |
| 314 | |
| 315 | try |
| 316 | { |
Alexander Afanasyev | f056c11 | 2014-08-14 16:39:25 -0700 | [diff] [blame] | 317 | startFetchingFaceStatusDataset(); |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 318 | startProcessing(); |
| 319 | } |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 320 | catch (const std::exception& e) |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 321 | { |
| 322 | std::cerr << "ERROR: " << e.what() << std::endl; |
| 323 | return 2; |
| 324 | } |
| 325 | |
| 326 | return 0; |
| 327 | } |
| 328 | |
| 329 | private: |
| 330 | Face m_face; |
Junxiao Shi | 8e273ca | 2014-11-12 00:42:29 -0700 | [diff] [blame] | 331 | KeyChain m_keyChain; |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 332 | Controller m_controller; |
Junxiao Shi | 15b12e7 | 2014-08-09 19:56:24 -0700 | [diff] [blame] | 333 | FaceMonitor m_faceMonitor; |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 334 | std::vector<Name> m_autoregPrefixes; |
| 335 | std::vector<Name> m_allFacesPrefixes; |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 336 | uint64_t m_cost; |
| 337 | std::vector<Network> m_whiteList; |
| 338 | std::vector<Network> m_blackList; |
| 339 | }; |
| 340 | |
Junxiao Shi | a1937bf | 2014-11-06 11:43:40 -0700 | [diff] [blame] | 341 | } // namespace nfd_autoreg |
| 342 | } // namespace ndn |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 343 | |
| 344 | int |
| 345 | main(int argc, char* argv[]) |
| 346 | { |
Junxiao Shi | a1937bf | 2014-11-06 11:43:40 -0700 | [diff] [blame] | 347 | ndn::nfd_autoreg::AutoregServer server; |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 348 | return server.main(argc, argv); |
| 349 | } |