Nick Gordon | 9471925 | 2016-10-20 20:48:01 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Nick Gordon | 04262d9 | 2017-01-31 12:27:06 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, Regents of the University of California, |
Nick Gordon | 9471925 | 2016-10-20 20:48:01 +0000 | [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. |
| 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/>. |
| 24 | */ |
| 25 | |
| 26 | #include "nfd-rib-readvertise-destination.hpp" |
Junxiao Shi | 63b67e2 | 2017-03-06 19:46:02 +0000 | [diff] [blame] | 27 | #include "core/logger.hpp" |
| 28 | |
| 29 | #include <ndn-cxx/mgmt/nfd/command-options.hpp> |
| 30 | #include <ndn-cxx/mgmt/nfd/control-command.hpp> |
| 31 | #include <ndn-cxx/mgmt/nfd/control-parameters.hpp> |
| 32 | #include <ndn-cxx/mgmt/nfd/control-response.hpp> |
Nick Gordon | 9471925 | 2016-10-20 20:48:01 +0000 | [diff] [blame] | 33 | |
| 34 | namespace nfd { |
| 35 | namespace rib { |
| 36 | |
Junxiao Shi | 63b67e2 | 2017-03-06 19:46:02 +0000 | [diff] [blame] | 37 | NFD_LOG_INIT("NfdRibReadvertiseDestination"); |
| 38 | |
| 39 | using ndn::nfd::CommandOptions; |
Nick Gordon | 9471925 | 2016-10-20 20:48:01 +0000 | [diff] [blame] | 40 | using ndn::nfd::ControlParameters; |
| 41 | using ndn::nfd::ControlResponse; |
| 42 | |
| 43 | NfdRibReadvertiseDestination::NfdRibReadvertiseDestination(ndn::nfd::Controller& controller, |
Junxiao Shi | 63b67e2 | 2017-03-06 19:46:02 +0000 | [diff] [blame] | 44 | const Name& commandPrefix, |
Nick Gordon | 04262d9 | 2017-01-31 12:27:06 -0600 | [diff] [blame] | 45 | Rib& rib) |
Nick Gordon | 9471925 | 2016-10-20 20:48:01 +0000 | [diff] [blame] | 46 | : m_controller(controller) |
| 47 | , m_commandPrefix(commandPrefix) |
| 48 | { |
Junxiao Shi | 63b67e2 | 2017-03-06 19:46:02 +0000 | [diff] [blame] | 49 | m_ribInsertConn = rib.afterInsertEntry.connect( |
| 50 | std::bind(&NfdRibReadvertiseDestination::handleRibInsert, this, _1)); |
| 51 | m_ribEraseConn = rib.afterEraseEntry.connect( |
| 52 | std::bind(&NfdRibReadvertiseDestination::handleRibErase, this, _1)); |
Nick Gordon | 9471925 | 2016-10-20 20:48:01 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | void |
Junxiao Shi | 63b67e2 | 2017-03-06 19:46:02 +0000 | [diff] [blame] | 56 | NfdRibReadvertiseDestination::advertise(const nfd::rib::ReadvertisedRoute& rr, |
Nick Gordon | 9471925 | 2016-10-20 20:48:01 +0000 | [diff] [blame] | 57 | std::function<void()> successCb, |
| 58 | std::function<void(const std::string&)> failureCb) |
| 59 | { |
Junxiao Shi | 63b67e2 | 2017-03-06 19:46:02 +0000 | [diff] [blame] | 60 | NFD_LOG_DEBUG("advertise " << rr.prefix << " on " << m_commandPrefix); |
| 61 | |
| 62 | m_controller.start<ndn::nfd::RibRegisterCommand>( |
| 63 | ControlParameters().setName(rr.prefix).setOrigin(ndn::nfd::ROUTE_ORIGIN_CLIENT), |
Nick Gordon | 9471925 | 2016-10-20 20:48:01 +0000 | [diff] [blame] | 64 | [=] (const ControlParameters& cp) { successCb(); }, |
Junxiao Shi | 63b67e2 | 2017-03-06 19:46:02 +0000 | [diff] [blame] | 65 | [=] (const ControlResponse& cr) { failureCb(cr.getText()); }, |
| 66 | CommandOptions().setPrefix(m_commandPrefix).setSigningInfo(rr.signer)); |
Nick Gordon | 9471925 | 2016-10-20 20:48:01 +0000 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | void |
Junxiao Shi | 63b67e2 | 2017-03-06 19:46:02 +0000 | [diff] [blame] | 70 | NfdRibReadvertiseDestination::withdraw(const nfd::rib::ReadvertisedRoute& rr, |
Nick Gordon | 9471925 | 2016-10-20 20:48:01 +0000 | [diff] [blame] | 71 | std::function<void()> successCb, |
| 72 | std::function<void(const std::string&)> failureCb) |
| 73 | { |
Junxiao Shi | 63b67e2 | 2017-03-06 19:46:02 +0000 | [diff] [blame] | 74 | NFD_LOG_DEBUG("withdraw " << rr.prefix << " on " << m_commandPrefix); |
| 75 | |
| 76 | m_controller.start<ndn::nfd::RibUnregisterCommand>( |
| 77 | ControlParameters().setName(rr.prefix).setOrigin(ndn::nfd::ROUTE_ORIGIN_CLIENT), |
Nick Gordon | 9471925 | 2016-10-20 20:48:01 +0000 | [diff] [blame] | 78 | [=] (const ControlParameters& cp) { successCb(); }, |
Junxiao Shi | 63b67e2 | 2017-03-06 19:46:02 +0000 | [diff] [blame] | 79 | [=] (const ControlResponse& cr) { failureCb(cr.getText()); }, |
| 80 | CommandOptions().setPrefix(m_commandPrefix).setSigningInfo(rr.signer)); |
Nick Gordon | 9471925 | 2016-10-20 20:48:01 +0000 | [diff] [blame] | 81 | } |
| 82 | |
Nick Gordon | 04262d9 | 2017-01-31 12:27:06 -0600 | [diff] [blame] | 83 | void |
Junxiao Shi | 63b67e2 | 2017-03-06 19:46:02 +0000 | [diff] [blame] | 84 | NfdRibReadvertiseDestination::handleRibInsert(const ndn::Name& name) |
Nick Gordon | 04262d9 | 2017-01-31 12:27:06 -0600 | [diff] [blame] | 85 | { |
Junxiao Shi | 63b67e2 | 2017-03-06 19:46:02 +0000 | [diff] [blame] | 86 | if (name.isPrefixOf(m_commandPrefix)) { |
Nick Gordon | 04262d9 | 2017-01-31 12:27:06 -0600 | [diff] [blame] | 87 | setAvailability(true); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | void |
Junxiao Shi | 63b67e2 | 2017-03-06 19:46:02 +0000 | [diff] [blame] | 92 | NfdRibReadvertiseDestination::handleRibErase(const ndn::Name& name) |
Nick Gordon | 04262d9 | 2017-01-31 12:27:06 -0600 | [diff] [blame] | 93 | { |
Junxiao Shi | 63b67e2 | 2017-03-06 19:46:02 +0000 | [diff] [blame] | 94 | if (name.isPrefixOf(m_commandPrefix)) { |
Nick Gordon | 04262d9 | 2017-01-31 12:27:06 -0600 | [diff] [blame] | 95 | setAvailability(false); |
| 96 | } |
| 97 | } |
| 98 | |
Nick Gordon | 9471925 | 2016-10-20 20:48:01 +0000 | [diff] [blame] | 99 | } // namespace rib |
| 100 | } // namespace nfd |