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 |
Alexander Afanasyev | f056c11 | 2014-08-14 16:39:25 -0700 | [diff] [blame^] | 140 | registerPrefixesIfNeeded(uint64_t faceId, const FaceUri& uri, bool isOnDemand) |
| 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 |
| 151 | if (isOnDemand && !isBlacklisted(address) && isWhitelisted(address)) { |
| 152 | registerPrefixesForFace(faceId, m_autoregPrefixes); |
| 153 | } |
| 154 | } |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | void |
Junxiao Shi | 15b12e7 | 2014-08-09 19:56:24 -0700 | [diff] [blame] | 159 | onNotification(const FaceEventNotification& notification) |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 160 | { |
Junxiao Shi | 6e69432 | 2014-04-03 10:27:13 -0700 | [diff] [blame] | 161 | if (notification.getKind() == FACE_EVENT_CREATED && |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 162 | !notification.isLocal()) |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 163 | { |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 164 | std::cerr << "PROCESSING: " << notification << std::endl; |
| 165 | |
Alexander Afanasyev | f056c11 | 2014-08-14 16:39:25 -0700 | [diff] [blame^] | 166 | registerPrefixesIfNeeded(notification.getFaceId(), FaceUri(notification.getRemoteUri()), |
| 167 | notification.isOnDemand()); |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 168 | } |
| 169 | else |
| 170 | { |
Junxiao Shi | dda0b46 | 2014-06-30 19:42:29 -0700 | [diff] [blame] | 171 | std::cerr << "IGNORED: " << notification << std::endl; |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 172 | } |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 173 | } |
| 174 | |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 175 | |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 176 | void |
| 177 | signalHandler() |
| 178 | { |
| 179 | m_face.shutdown(); |
| 180 | } |
| 181 | |
| 182 | |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 183 | void |
Alexander Afanasyev | 60a7ba5 | 2014-03-23 11:23:06 -0700 | [diff] [blame] | 184 | usage(std::ostream& os, |
| 185 | const po::options_description& optionDesciption, |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 186 | const char* programName) |
| 187 | { |
Alexander Afanasyev | 60a7ba5 | 2014-03-23 11:23:06 -0700 | [diff] [blame] | 188 | os << "Usage:\n" |
| 189 | << " " << programName << " --prefix=</autoreg/prefix> [--prefix=/another/prefix] ...\n" |
| 190 | << "\n"; |
| 191 | os << optionDesciption; |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | void |
| 195 | startProcessing() |
| 196 | { |
Junxiao Shi | dda0b46 | 2014-06-30 19:42:29 -0700 | [diff] [blame] | 197 | std::cerr << "AUTOREG prefixes: " << std::endl; |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 198 | for (std::vector<ndn::Name>::const_iterator prefix = m_autoregPrefixes.begin(); |
| 199 | prefix != m_autoregPrefixes.end(); |
| 200 | ++prefix) |
| 201 | { |
| 202 | std::cout << " " << *prefix << std::endl; |
| 203 | } |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 204 | std::cerr << "ALL-FACES-AUTOREG prefixes: " << std::endl; |
| 205 | for (std::vector<ndn::Name>::const_iterator prefix = m_allFacesPrefixes.begin(); |
| 206 | prefix != m_allFacesPrefixes.end(); |
| 207 | ++prefix) |
| 208 | { |
| 209 | std::cout << " " << *prefix << std::endl; |
| 210 | } |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 211 | |
| 212 | if (!m_blackList.empty()) |
| 213 | { |
Junxiao Shi | dda0b46 | 2014-06-30 19:42:29 -0700 | [diff] [blame] | 214 | std::cerr << "Blacklisted networks: " << std::endl; |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 215 | for (std::vector<Network>::const_iterator network = m_blackList.begin(); |
| 216 | network != m_blackList.end(); |
| 217 | ++network) |
| 218 | { |
| 219 | std::cout << " " << *network << std::endl; |
| 220 | } |
| 221 | } |
| 222 | |
Junxiao Shi | dda0b46 | 2014-06-30 19:42:29 -0700 | [diff] [blame] | 223 | std::cerr << "Whitelisted networks: " << std::endl; |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 224 | for (std::vector<Network>::const_iterator network = m_whiteList.begin(); |
| 225 | network != m_whiteList.end(); |
| 226 | ++network) |
| 227 | { |
| 228 | std::cout << " " << *network << std::endl; |
| 229 | } |
| 230 | |
Junxiao Shi | 15b12e7 | 2014-08-09 19:56:24 -0700 | [diff] [blame] | 231 | m_faceMonitor.onNotification += bind(&AutoregServer::onNotification, this, _1); |
| 232 | m_faceMonitor.start(); |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 233 | |
Alexander Afanasyev | b3893c9 | 2014-05-15 01:49:54 -0700 | [diff] [blame] | 234 | boost::asio::signal_set signalSet(m_face.getIoService(), SIGINT, SIGTERM); |
Alexander Afanasyev | f698028 | 2014-05-13 18:28:40 -0700 | [diff] [blame] | 235 | signalSet.async_wait(bind(&AutoregServer::signalHandler, this)); |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 236 | |
| 237 | m_face.processEvents(); |
| 238 | } |
| 239 | |
Alexander Afanasyev | f056c11 | 2014-08-14 16:39:25 -0700 | [diff] [blame^] | 240 | |
| 241 | void |
| 242 | fetchFaceStatusSegments(const Data& data, const shared_ptr<ndn::OBufferStream>& buffer) |
| 243 | { |
| 244 | buffer->write(reinterpret_cast<const char*>(data.getContent().value()), |
| 245 | data.getContent().value_size()); |
| 246 | |
| 247 | uint64_t currentSegment = data.getName().get(-1).toSegment(); |
| 248 | |
| 249 | const name::Component& finalBlockId = data.getMetaInfo().getFinalBlockId(); |
| 250 | if (finalBlockId.empty() || |
| 251 | finalBlockId.toSegment() > currentSegment) |
| 252 | { |
| 253 | m_face.expressInterest(data.getName().getPrefix(-1).appendSegment(currentSegment+1), |
| 254 | bind(&AutoregServer::fetchFaceStatusSegments, this, _2, buffer), |
| 255 | ndn::OnTimeout()); |
| 256 | } |
| 257 | else |
| 258 | { |
| 259 | return processFaceStatusDataset(buffer); |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | void |
| 264 | startFetchingFaceStatusDataset() |
| 265 | { |
| 266 | shared_ptr<ndn::OBufferStream> buffer = make_shared<ndn::OBufferStream>(); |
| 267 | |
| 268 | Interest interest("/localhost/nfd/faces/list"); |
| 269 | interest.setChildSelector(1); |
| 270 | interest.setMustBeFresh(true); |
| 271 | |
| 272 | m_face.expressInterest(interest, |
| 273 | bind(&AutoregServer::fetchFaceStatusSegments, this, _2, buffer), |
| 274 | ndn::OnTimeout()); |
| 275 | } |
| 276 | |
| 277 | void |
| 278 | processFaceStatusDataset(const shared_ptr<ndn::OBufferStream>& buffer) |
| 279 | { |
| 280 | ndn::ConstBufferPtr buf = buffer->buf(); |
| 281 | std::vector<uint64_t> multicastFaces; |
| 282 | |
| 283 | size_t offset = 0; |
| 284 | while (offset < buf->size()) |
| 285 | { |
| 286 | Block block; |
| 287 | bool ok = Block::fromBuffer(buf, offset, block); |
| 288 | if (!ok) |
| 289 | { |
| 290 | std::cerr << "ERROR: cannot decode FaceStatus TLV" << std::endl; |
| 291 | break; |
| 292 | } |
| 293 | |
| 294 | offset += block.size(); |
| 295 | |
| 296 | nfd::FaceStatus faceStatus(block); |
| 297 | registerPrefixesIfNeeded(faceStatus.getFaceId(), FaceUri(faceStatus.getRemoteUri()), |
| 298 | faceStatus.isOnDemand()); |
| 299 | } |
| 300 | } |
| 301 | |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 302 | int |
| 303 | main(int argc, char* argv[]) |
| 304 | { |
| 305 | po::options_description optionDesciption; |
| 306 | optionDesciption.add_options() |
| 307 | ("help,h", "produce help message") |
| 308 | ("prefix,i", po::value<std::vector<ndn::Name> >(&m_autoregPrefixes)->composing(), |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 309 | "prefix that should be automatically registered when new a remote non-local face is " |
| 310 | "established") |
| 311 | ("all-faces-prefix,a", po::value<std::vector<ndn::Name> >(&m_allFacesPrefixes)->composing(), |
| 312 | "prefix that should be automatically registered for all TCP and UDP non-local faces " |
| 313 | "(blacklists and whitelists do not apply to this prefix)") |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 314 | ("cost,c", po::value<uint64_t>(&m_cost)->default_value(255), |
| 315 | "FIB cost which should be assigned to autoreg nexthops") |
| 316 | ("whitelist,w", po::value<std::vector<Network> >(&m_whiteList)->composing(), |
| 317 | "Whitelisted network, e.g., 192.168.2.0/24 or ::1/128") |
| 318 | ("blacklist,b", po::value<std::vector<Network> >(&m_blackList)->composing(), |
| 319 | "Blacklisted network, e.g., 192.168.2.32/30 or ::1/128") |
Alexander Afanasyev | b47d538 | 2014-05-05 14:35:03 -0700 | [diff] [blame] | 320 | ("version,V", "show version and exit") |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 321 | ; |
| 322 | |
| 323 | po::variables_map options; |
| 324 | try |
| 325 | { |
| 326 | po::store(po::command_line_parser(argc, argv).options(optionDesciption).run(), options); |
| 327 | po::notify(options); |
| 328 | } |
| 329 | catch (std::exception& e) |
| 330 | { |
| 331 | std::cerr << "ERROR: " << e.what() << std::endl << std::endl; |
Alexander Afanasyev | 60a7ba5 | 2014-03-23 11:23:06 -0700 | [diff] [blame] | 332 | usage(std::cerr, optionDesciption, argv[0]); |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 333 | return 1; |
| 334 | } |
| 335 | |
| 336 | if (options.count("help")) |
| 337 | { |
Alexander Afanasyev | 60a7ba5 | 2014-03-23 11:23:06 -0700 | [diff] [blame] | 338 | usage(std::cout, optionDesciption, argv[0]); |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 339 | return 0; |
| 340 | } |
| 341 | |
Alexander Afanasyev | b47d538 | 2014-05-05 14:35:03 -0700 | [diff] [blame] | 342 | if (options.count("version")) |
| 343 | { |
| 344 | std::cout << NFD_VERSION_BUILD_STRING << std::endl; |
| 345 | return 0; |
| 346 | } |
| 347 | |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 348 | if (m_autoregPrefixes.empty() && m_allFacesPrefixes.empty()) |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 349 | { |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 350 | std::cerr << "ERROR: at least one --prefix or --all-faces-prefix must be specified" |
| 351 | << std::endl << std::endl; |
Alexander Afanasyev | 60a7ba5 | 2014-03-23 11:23:06 -0700 | [diff] [blame] | 352 | usage(std::cerr, optionDesciption, argv[0]); |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 353 | return 2; |
| 354 | } |
| 355 | |
| 356 | if (m_whiteList.empty()) |
| 357 | { |
| 358 | // Allow everything |
| 359 | m_whiteList.push_back(Network::getMaxRangeV4()); |
| 360 | m_whiteList.push_back(Network::getMaxRangeV6()); |
| 361 | } |
| 362 | |
| 363 | try |
| 364 | { |
Alexander Afanasyev | f056c11 | 2014-08-14 16:39:25 -0700 | [diff] [blame^] | 365 | startFetchingFaceStatusDataset(); |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 366 | startProcessing(); |
| 367 | } |
| 368 | catch (std::exception& e) |
| 369 | { |
| 370 | std::cerr << "ERROR: " << e.what() << std::endl; |
| 371 | return 2; |
| 372 | } |
| 373 | |
| 374 | return 0; |
| 375 | } |
| 376 | |
| 377 | private: |
| 378 | Face m_face; |
| 379 | Controller m_controller; |
Junxiao Shi | 15b12e7 | 2014-08-09 19:56:24 -0700 | [diff] [blame] | 380 | FaceMonitor m_faceMonitor; |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 381 | std::vector<ndn::Name> m_autoregPrefixes; |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 382 | std::vector<ndn::Name> m_allFacesPrefixes; |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 383 | uint64_t m_cost; |
| 384 | std::vector<Network> m_whiteList; |
| 385 | std::vector<Network> m_blackList; |
| 386 | }; |
| 387 | |
| 388 | } // namespace nfd |
| 389 | |
| 390 | int |
| 391 | main(int argc, char* argv[]) |
| 392 | { |
| 393 | nfd::AutoregServer server; |
| 394 | return server.main(argc, argv); |
| 395 | } |