Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | dda0b46 | 2014-06-30 19:42:29 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014, Regents of the University of California, |
| 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 | |
Alexander Afanasyev | 4a77136 | 2014-04-24 21:29:33 -0700 | [diff] [blame] | 29 | #include <ndn-cxx/management/nfd-controller.hpp> |
Alexander Afanasyev | 585e5a6 | 2014-08-12 11:49:31 -0700 | [diff] [blame] | 30 | #include <ndn-cxx/management/nfd-face-monitor.hpp> |
Alexander Afanasyev | f056c11 | 2014-08-14 16:39:25 -0700 | [diff] [blame] | 31 | #include <ndn-cxx/management/nfd-face-status.hpp> |
| 32 | #include <ndn-cxx/encoding/buffer-stream.hpp> |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 33 | |
| 34 | #include <boost/program_options/options_description.hpp> |
| 35 | #include <boost/program_options/variables_map.hpp> |
| 36 | #include <boost/program_options/parsers.hpp> |
| 37 | |
Alexander Afanasyev | b47d538 | 2014-05-05 14:35:03 -0700 | [diff] [blame] | 38 | #include "version.hpp" |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 39 | #include "core/face-uri.hpp" |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 40 | #include "network.hpp" |
| 41 | |
| 42 | namespace po = boost::program_options; |
| 43 | |
| 44 | namespace nfd { |
| 45 | |
| 46 | using namespace ndn::nfd; |
| 47 | using ndn::Face; |
Alexander Afanasyev | 585e5a6 | 2014-08-12 11:49:31 -0700 | [diff] [blame] | 48 | using ndn::nfd::FaceEventNotification; |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 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() |
| 54 | : m_controller(m_face) |
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 | dda0b46 | 2014-06-30 19:42:29 -0700 | [diff] [blame] | 68 | uint32_t code, const std::string& reason) |
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 |
Alexander Afanasyev | f4e89b4 | 2014-05-31 15:54:18 +0300 | [diff] [blame] | 71 | << " (code: " << code << ", reason: " << reason << ")" << std::endl; |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Junxiao Shi | dda0b46 | 2014-06-30 19:42:29 -0700 | [diff] [blame] | 74 | /** |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 75 | * \return true if uri has schema allowed to do auto-registrations |
Junxiao Shi | dda0b46 | 2014-06-30 19:42:29 -0700 | [diff] [blame] | 76 | */ |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 77 | bool |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 78 | hasAllowedSchema(const FaceUri& uri) |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 79 | { |
| 80 | const std::string& scheme = uri.getScheme(); |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 81 | return (scheme == "udp4" || scheme == "tcp4" || |
| 82 | scheme == "udp6" || scheme == "tcp6"); |
| 83 | } |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 84 | |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 85 | /** |
Alexander Afanasyev | f056c11 | 2014-08-14 16:39:25 -0700 | [diff] [blame] | 86 | * \return true if address is blacklisted |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 87 | */ |
| 88 | bool |
Alexander Afanasyev | f056c11 | 2014-08-14 16:39:25 -0700 | [diff] [blame] | 89 | isBlacklisted(const boost::asio::ip::address& address) |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 90 | { |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 91 | for (std::vector<Network>::const_iterator network = m_blackList.begin(); |
| 92 | network != m_blackList.end(); |
| 93 | ++network) |
| 94 | { |
| 95 | if (network->doesContain(address)) |
| 96 | return true; |
| 97 | } |
| 98 | |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 99 | return false; |
| 100 | } |
| 101 | |
| 102 | /** |
Alexander Afanasyev | f056c11 | 2014-08-14 16:39:25 -0700 | [diff] [blame] | 103 | * \return true if address is whitelisted |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 104 | */ |
| 105 | bool |
Alexander Afanasyev | f056c11 | 2014-08-14 16:39:25 -0700 | [diff] [blame] | 106 | isWhitelisted(const boost::asio::ip::address& address) |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 107 | { |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 108 | for (std::vector<Network>::const_iterator network = m_whiteList.begin(); |
| 109 | network != m_whiteList.end(); |
| 110 | ++network) |
| 111 | { |
| 112 | if (network->doesContain(address)) |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 113 | return true; |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 116 | return false; |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | void |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 120 | registerPrefixesForFace(uint64_t faceId, |
| 121 | const std::vector<ndn::Name>& prefixes) |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 122 | { |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 123 | for (std::vector<ndn::Name>::const_iterator prefix = prefixes.begin(); |
| 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), |
| 135 | bind(&AutoregServer::onRegisterCommandFailure, this, faceId, *prefix, _1, _2)); |
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 | |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 176 | |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 177 | void |
| 178 | signalHandler() |
| 179 | { |
| 180 | m_face.shutdown(); |
| 181 | } |
| 182 | |
| 183 | |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 184 | void |
Alexander Afanasyev | 60a7ba5 | 2014-03-23 11:23:06 -0700 | [diff] [blame] | 185 | usage(std::ostream& os, |
| 186 | const po::options_description& optionDesciption, |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 187 | const char* programName) |
| 188 | { |
Alexander Afanasyev | 60a7ba5 | 2014-03-23 11:23:06 -0700 | [diff] [blame] | 189 | os << "Usage:\n" |
| 190 | << " " << programName << " --prefix=</autoreg/prefix> [--prefix=/another/prefix] ...\n" |
| 191 | << "\n"; |
| 192 | os << optionDesciption; |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | void |
| 196 | startProcessing() |
| 197 | { |
Junxiao Shi | dda0b46 | 2014-06-30 19:42:29 -0700 | [diff] [blame] | 198 | std::cerr << "AUTOREG prefixes: " << std::endl; |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 199 | for (std::vector<ndn::Name>::const_iterator prefix = m_autoregPrefixes.begin(); |
| 200 | prefix != m_autoregPrefixes.end(); |
| 201 | ++prefix) |
| 202 | { |
| 203 | std::cout << " " << *prefix << std::endl; |
| 204 | } |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 205 | std::cerr << "ALL-FACES-AUTOREG prefixes: " << std::endl; |
| 206 | for (std::vector<ndn::Name>::const_iterator prefix = m_allFacesPrefixes.begin(); |
| 207 | prefix != m_allFacesPrefixes.end(); |
| 208 | ++prefix) |
| 209 | { |
| 210 | std::cout << " " << *prefix << std::endl; |
| 211 | } |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 212 | |
| 213 | if (!m_blackList.empty()) |
| 214 | { |
Junxiao Shi | dda0b46 | 2014-06-30 19:42:29 -0700 | [diff] [blame] | 215 | std::cerr << "Blacklisted networks: " << std::endl; |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 216 | for (std::vector<Network>::const_iterator network = m_blackList.begin(); |
| 217 | network != m_blackList.end(); |
| 218 | ++network) |
| 219 | { |
| 220 | std::cout << " " << *network << std::endl; |
| 221 | } |
| 222 | } |
| 223 | |
Junxiao Shi | dda0b46 | 2014-06-30 19:42:29 -0700 | [diff] [blame] | 224 | std::cerr << "Whitelisted networks: " << std::endl; |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 225 | for (std::vector<Network>::const_iterator network = m_whiteList.begin(); |
| 226 | network != m_whiteList.end(); |
| 227 | ++network) |
| 228 | { |
| 229 | std::cout << " " << *network << std::endl; |
| 230 | } |
| 231 | |
Junxiao Shi | 15b12e7 | 2014-08-09 19:56:24 -0700 | [diff] [blame] | 232 | m_faceMonitor.onNotification += bind(&AutoregServer::onNotification, this, _1); |
| 233 | m_faceMonitor.start(); |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 234 | |
Alexander Afanasyev | b3893c9 | 2014-05-15 01:49:54 -0700 | [diff] [blame] | 235 | boost::asio::signal_set signalSet(m_face.getIoService(), SIGINT, SIGTERM); |
Alexander Afanasyev | f698028 | 2014-05-13 18:28:40 -0700 | [diff] [blame] | 236 | signalSet.async_wait(bind(&AutoregServer::signalHandler, this)); |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 237 | |
| 238 | m_face.processEvents(); |
| 239 | } |
| 240 | |
Alexander Afanasyev | f056c11 | 2014-08-14 16:39:25 -0700 | [diff] [blame] | 241 | |
| 242 | void |
| 243 | fetchFaceStatusSegments(const Data& data, const shared_ptr<ndn::OBufferStream>& buffer) |
| 244 | { |
| 245 | buffer->write(reinterpret_cast<const char*>(data.getContent().value()), |
| 246 | data.getContent().value_size()); |
| 247 | |
| 248 | uint64_t currentSegment = data.getName().get(-1).toSegment(); |
| 249 | |
| 250 | const name::Component& finalBlockId = data.getMetaInfo().getFinalBlockId(); |
| 251 | if (finalBlockId.empty() || |
| 252 | finalBlockId.toSegment() > currentSegment) |
| 253 | { |
| 254 | m_face.expressInterest(data.getName().getPrefix(-1).appendSegment(currentSegment+1), |
| 255 | bind(&AutoregServer::fetchFaceStatusSegments, this, _2, buffer), |
| 256 | ndn::OnTimeout()); |
| 257 | } |
| 258 | else |
| 259 | { |
| 260 | return processFaceStatusDataset(buffer); |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | void |
| 265 | startFetchingFaceStatusDataset() |
| 266 | { |
| 267 | shared_ptr<ndn::OBufferStream> buffer = make_shared<ndn::OBufferStream>(); |
| 268 | |
| 269 | Interest interest("/localhost/nfd/faces/list"); |
| 270 | interest.setChildSelector(1); |
| 271 | interest.setMustBeFresh(true); |
| 272 | |
| 273 | m_face.expressInterest(interest, |
| 274 | bind(&AutoregServer::fetchFaceStatusSegments, this, _2, buffer), |
| 275 | ndn::OnTimeout()); |
| 276 | } |
| 277 | |
| 278 | void |
| 279 | processFaceStatusDataset(const shared_ptr<ndn::OBufferStream>& buffer) |
| 280 | { |
| 281 | ndn::ConstBufferPtr buf = buffer->buf(); |
| 282 | std::vector<uint64_t> multicastFaces; |
| 283 | |
| 284 | size_t offset = 0; |
| 285 | while (offset < buf->size()) |
| 286 | { |
| 287 | Block block; |
| 288 | bool ok = Block::fromBuffer(buf, offset, block); |
| 289 | if (!ok) |
| 290 | { |
| 291 | std::cerr << "ERROR: cannot decode FaceStatus TLV" << std::endl; |
| 292 | break; |
| 293 | } |
| 294 | |
| 295 | offset += block.size(); |
| 296 | |
| 297 | nfd::FaceStatus faceStatus(block); |
| 298 | registerPrefixesIfNeeded(faceStatus.getFaceId(), FaceUri(faceStatus.getRemoteUri()), |
Chengyu Fan | 9942cea | 2014-10-13 14:47:13 -0600 | [diff] [blame] | 299 | faceStatus.getFacePersistency()); |
Alexander Afanasyev | f056c11 | 2014-08-14 16:39:25 -0700 | [diff] [blame] | 300 | } |
| 301 | } |
| 302 | |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 303 | int |
| 304 | main(int argc, char* argv[]) |
| 305 | { |
| 306 | po::options_description optionDesciption; |
| 307 | optionDesciption.add_options() |
| 308 | ("help,h", "produce help message") |
| 309 | ("prefix,i", po::value<std::vector<ndn::Name> >(&m_autoregPrefixes)->composing(), |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 310 | "prefix that should be automatically registered when new a remote non-local face is " |
| 311 | "established") |
| 312 | ("all-faces-prefix,a", po::value<std::vector<ndn::Name> >(&m_allFacesPrefixes)->composing(), |
| 313 | "prefix that should be automatically registered for all TCP and UDP non-local faces " |
| 314 | "(blacklists and whitelists do not apply to this prefix)") |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 315 | ("cost,c", po::value<uint64_t>(&m_cost)->default_value(255), |
| 316 | "FIB cost which should be assigned to autoreg nexthops") |
| 317 | ("whitelist,w", po::value<std::vector<Network> >(&m_whiteList)->composing(), |
| 318 | "Whitelisted network, e.g., 192.168.2.0/24 or ::1/128") |
| 319 | ("blacklist,b", po::value<std::vector<Network> >(&m_blackList)->composing(), |
| 320 | "Blacklisted network, e.g., 192.168.2.32/30 or ::1/128") |
Alexander Afanasyev | b47d538 | 2014-05-05 14:35:03 -0700 | [diff] [blame] | 321 | ("version,V", "show version and exit") |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 322 | ; |
| 323 | |
| 324 | po::variables_map options; |
| 325 | try |
| 326 | { |
| 327 | po::store(po::command_line_parser(argc, argv).options(optionDesciption).run(), options); |
| 328 | po::notify(options); |
| 329 | } |
| 330 | catch (std::exception& e) |
| 331 | { |
| 332 | std::cerr << "ERROR: " << e.what() << std::endl << std::endl; |
Alexander Afanasyev | 60a7ba5 | 2014-03-23 11:23:06 -0700 | [diff] [blame] | 333 | usage(std::cerr, optionDesciption, argv[0]); |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 334 | return 1; |
| 335 | } |
| 336 | |
| 337 | if (options.count("help")) |
| 338 | { |
Alexander Afanasyev | 60a7ba5 | 2014-03-23 11:23:06 -0700 | [diff] [blame] | 339 | usage(std::cout, optionDesciption, argv[0]); |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 340 | return 0; |
| 341 | } |
| 342 | |
Alexander Afanasyev | b47d538 | 2014-05-05 14:35:03 -0700 | [diff] [blame] | 343 | if (options.count("version")) |
| 344 | { |
| 345 | std::cout << NFD_VERSION_BUILD_STRING << std::endl; |
| 346 | return 0; |
| 347 | } |
| 348 | |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 349 | if (m_autoregPrefixes.empty() && m_allFacesPrefixes.empty()) |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 350 | { |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 351 | std::cerr << "ERROR: at least one --prefix or --all-faces-prefix must be specified" |
| 352 | << std::endl << std::endl; |
Alexander Afanasyev | 60a7ba5 | 2014-03-23 11:23:06 -0700 | [diff] [blame] | 353 | usage(std::cerr, optionDesciption, argv[0]); |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 354 | return 2; |
| 355 | } |
| 356 | |
| 357 | if (m_whiteList.empty()) |
| 358 | { |
| 359 | // Allow everything |
| 360 | m_whiteList.push_back(Network::getMaxRangeV4()); |
| 361 | m_whiteList.push_back(Network::getMaxRangeV6()); |
| 362 | } |
| 363 | |
| 364 | try |
| 365 | { |
Alexander Afanasyev | f056c11 | 2014-08-14 16:39:25 -0700 | [diff] [blame] | 366 | startFetchingFaceStatusDataset(); |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 367 | startProcessing(); |
| 368 | } |
| 369 | catch (std::exception& e) |
| 370 | { |
| 371 | std::cerr << "ERROR: " << e.what() << std::endl; |
| 372 | return 2; |
| 373 | } |
| 374 | |
| 375 | return 0; |
| 376 | } |
| 377 | |
| 378 | private: |
| 379 | Face m_face; |
| 380 | Controller m_controller; |
Junxiao Shi | 15b12e7 | 2014-08-09 19:56:24 -0700 | [diff] [blame] | 381 | FaceMonitor m_faceMonitor; |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 382 | std::vector<ndn::Name> m_autoregPrefixes; |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 383 | std::vector<ndn::Name> m_allFacesPrefixes; |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 384 | uint64_t m_cost; |
| 385 | std::vector<Network> m_whiteList; |
| 386 | std::vector<Network> m_blackList; |
| 387 | }; |
| 388 | |
| 389 | } // namespace nfd |
| 390 | |
| 391 | int |
| 392 | main(int argc, char* argv[]) |
| 393 | { |
| 394 | nfd::AutoregServer server; |
| 395 | return server.main(argc, argv); |
| 396 | } |