update: Process Name prefix update commands
refs #1834 Change-Id: I18c86d0743b4a10ce3a8681f202b59a86602e43f
This commit is contained in:
1 parent
9d09780605
commit
297f4163c2
12 files changed
+808
-20
No files matched your search
@@ -212,7 +212,7 @@ security
|
||||
type name
|
||||
hyper-relation
|
||||
{
|
||||
k-regex ^([^<KEY><%C1.Operator>]*)<%C1.Operator>[^<KEY>]*<KEY><ksk-.*><ID-CERT>$
|
||||
k-regex ^([^<KEY><%C1.Operator>]*)<%C1.Operator>[^<KEY>]*<KEY><ksk-.*><ID-CERT>$
|
||||
k-expand \\1
|
||||
h-relation equal
|
||||
p-regex ^([^<KEY><%C1.Router>]*)<%C1.Router>[^<KEY>]*<KEY><ksk-.*><ID-CERT><>$
|
||||
@@ -244,6 +244,52 @@ security
|
||||
file-name "root.cert"
|
||||
}
|
||||
}
|
||||
|
||||
prefix-update-validator
|
||||
{
|
||||
rule
|
||||
{
|
||||
id "NLSR ControlCommand Rule"
|
||||
for interest
|
||||
filter
|
||||
{
|
||||
type name
|
||||
regex ^<localhost><nlsr><prefix-update>[<advertise><withdraw>]<>$
|
||||
}
|
||||
checker
|
||||
{
|
||||
type customized
|
||||
sig-type rsa-sha256
|
||||
key-locator
|
||||
{
|
||||
type name
|
||||
regex ^([^<KEY><%C1.Operator>]*)<%C1.Operator>[^<KEY>]*<KEY><ksk-.*><ID-CERT>$
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rule
|
||||
{
|
||||
id "NLSR Hierarchy Rule"
|
||||
for data
|
||||
filter
|
||||
{
|
||||
type name
|
||||
regex ^[^<KEY>]*<KEY><ksk-.*><ID-CERT><>$
|
||||
}
|
||||
checker
|
||||
{
|
||||
type hierarchical
|
||||
sig-type rsa-sha256
|
||||
}
|
||||
}
|
||||
|
||||
trust-anchor
|
||||
{
|
||||
type file
|
||||
file-name "site.cert"
|
||||
}
|
||||
}
|
||||
; cert-to-publish "root.cert" ; optional, a file containing the root certificate
|
||||
; Only the router that is designated to publish the root cert
|
||||
; needs to specify this
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#include "conf-file-processor.hpp"
|
||||
#include "adjacent.hpp"
|
||||
#include "utility/name-helper.hpp"
|
||||
#include "update/prefix-update-processor.hpp"
|
||||
|
||||
namespace nlsr {
|
||||
|
||||
@@ -620,6 +621,15 @@ ConfFileProcessor::processConfSectionSecurity(const ConfigSection& section)
|
||||
m_nlsr.loadValidator(it->second, m_confFileName);
|
||||
it++;
|
||||
|
||||
if (it == section.end() || it->first != "prefix-update-validator")
|
||||
{
|
||||
std::cerr << "Error: Expect prefix-update-validator section" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
m_nlsr.getPrefixUpdateProcessor().loadValidator(it->second, m_confFileName);
|
||||
it++;
|
||||
|
||||
for (; it != section.end(); it++)
|
||||
{
|
||||
using namespace boost::filesystem;
|
||||
|
||||
+11
-10
@@ -1,7 +1,8 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014 University of Memphis,
|
||||
* Regents of the University of California
|
||||
* Copyright (c) 2014-2015, The University of Memphis,
|
||||
* Regents of the University of California,
|
||||
* Arizona Board of Regents.
|
||||
*
|
||||
* This file is part of NLSR (Named-data Link State Routing).
|
||||
* See AUTHORS.md for complete list of NLSR authors and contributors.
|
||||
@@ -16,10 +17,8 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* \author A K M Mahmudul Hoque <ahoque1@memphis.edu>
|
||||
*
|
||||
**/
|
||||
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
|
||||
@@ -49,7 +48,7 @@ nameCompare(const ndn::Name& name1, const ndn::Name& name2)
|
||||
return name1 == name2;
|
||||
}
|
||||
|
||||
int32_t
|
||||
bool
|
||||
NamePrefixList::insert(const ndn::Name& name)
|
||||
{
|
||||
std::list<ndn::Name>::iterator it = std::find_if(m_nameList.begin(),
|
||||
@@ -57,13 +56,13 @@ NamePrefixList::insert(const ndn::Name& name)
|
||||
ndn::bind(&nameCompare, _1 ,
|
||||
ndn::cref(name)));
|
||||
if (it != m_nameList.end()) {
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
m_nameList.push_back(name);
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t
|
||||
bool
|
||||
NamePrefixList::remove(const ndn::Name& name)
|
||||
{
|
||||
std::list<ndn::Name>::iterator it = std::find_if(m_nameList.begin(),
|
||||
@@ -72,8 +71,10 @@ NamePrefixList::remove(const ndn::Name& name)
|
||||
ndn::cref(name)));
|
||||
if (it != m_nameList.end()) {
|
||||
m_nameList.erase(it);
|
||||
return true;
|
||||
}
|
||||
return -1;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014 University of Memphis,
|
||||
* Regents of the University of California
|
||||
* Copyright (c) 2014-2015, The University of Memphis,
|
||||
* Regents of the University of California,
|
||||
* Arizona Board of Regents.
|
||||
*
|
||||
* This file is part of NLSR (Named-data Link State Routing).
|
||||
* See AUTHORS.md for complete list of NLSR authors and contributors.
|
||||
@@ -16,10 +17,8 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* \author A K M Mahmudul Hoque <ahoque1@memphis.edu>
|
||||
*
|
||||
**/
|
||||
|
||||
#ifndef NLSR_NAME_PREFIX_LIST_HPP
|
||||
#define NLSR_NAME_PREFIX_LIST_HPP
|
||||
|
||||
@@ -38,10 +37,16 @@ public:
|
||||
|
||||
~NamePrefixList();
|
||||
|
||||
int32_t
|
||||
/** \brief inserts name into NamePrefixList
|
||||
* \return true if the name is inserted, otherwise false
|
||||
*/
|
||||
bool
|
||||
insert(const ndn::Name& name);
|
||||
|
||||
int32_t
|
||||
/** \brief removes name from NamePrefixList
|
||||
* \return true if the name is removed, otherwise false
|
||||
*/
|
||||
bool
|
||||
remove(const ndn::Name& name);
|
||||
|
||||
void
|
||||
|
||||
@@ -34,6 +34,8 @@ namespace nlsr {
|
||||
|
||||
INIT_LOGGER("nlsr");
|
||||
|
||||
const ndn::Name Nlsr::LOCALHOST_PREFIX = ndn::Name("/localhost/nlsr");
|
||||
|
||||
using namespace ndn;
|
||||
using namespace std;
|
||||
|
||||
@@ -56,6 +58,14 @@ Nlsr::onRegistrationSuccess(const ndn::Name& name)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Nlsr::onLocalhostRegistrationSuccess(const ndn::Name& name)
|
||||
{
|
||||
_LOG_DEBUG("Successfully registered prefix: " << name);
|
||||
|
||||
m_prefixUpdateProcessor.startListening();
|
||||
}
|
||||
|
||||
void
|
||||
Nlsr::setInfoInterestFilter()
|
||||
{
|
||||
@@ -156,6 +166,7 @@ Nlsr::initialize()
|
||||
m_nlsrLsdb.buildAndInstallOwnCoordinateLsa();
|
||||
|
||||
registerKeyPrefix();
|
||||
registerLocalhostPrefix();
|
||||
|
||||
m_helloProtocol.scheduleInterest(m_firstHelloInterval);
|
||||
|
||||
@@ -221,6 +232,16 @@ Nlsr::registerKeyPrefix()
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
Nlsr::registerLocalhostPrefix()
|
||||
{
|
||||
_LOG_TRACE("Registering prefix: " << LOCALHOST_PREFIX);
|
||||
|
||||
m_nlsrFace.registerPrefix(LOCALHOST_PREFIX,
|
||||
std::bind(&Nlsr::onLocalhostRegistrationSuccess, this, _1),
|
||||
std::bind(&Nlsr::registrationFailed, this, _1));
|
||||
}
|
||||
|
||||
void
|
||||
Nlsr::onKeyInterest(const ndn::Name& name, const ndn::Interest& interest)
|
||||
{
|
||||
|
||||
+34
-1
@@ -45,7 +45,8 @@
|
||||
#include "hello-protocol.hpp"
|
||||
#include "test-access-control.hpp"
|
||||
#include "publisher/lsdb-dataset-interest-handler.hpp"
|
||||
|
||||
#include "utility/name-helper.hpp"
|
||||
#include "update/prefix-update-processor.hpp"
|
||||
#include "validator.hpp"
|
||||
|
||||
|
||||
@@ -87,6 +88,13 @@ public:
|
||||
, m_helloProtocol(*this, scheduler)
|
||||
, m_certificateCache(new ndn::CertificateCacheTtl(ioService))
|
||||
, m_validator(m_nlsrFace, DEFAULT_BROADCAST_PREFIX, m_certificateCache)
|
||||
, m_prefixUpdateProcessor(m_nlsrFace,
|
||||
m_namePrefixList,
|
||||
m_nlsrLsdb,
|
||||
m_syncLogicHandler,
|
||||
DEFAULT_BROADCAST_PREFIX,
|
||||
m_keyChain,
|
||||
m_certificateCache)
|
||||
, m_faceMonitor(m_nlsrFace)
|
||||
, m_firstHelloInterval(FIRST_HELLO_INTERVAL_DEFAULT)
|
||||
{
|
||||
@@ -100,6 +108,9 @@ public:
|
||||
void
|
||||
onRegistrationSuccess(const ndn::Name& name);
|
||||
|
||||
void
|
||||
onLocalhostRegistrationSuccess(const ndn::Name& name);
|
||||
|
||||
void
|
||||
setInfoInterestFilter();
|
||||
|
||||
@@ -302,6 +313,12 @@ public:
|
||||
return m_defaultCertName;
|
||||
}
|
||||
|
||||
update::PrefixUpdateProcessor&
|
||||
getPrefixUpdateProcessor()
|
||||
{
|
||||
return m_prefixUpdateProcessor;
|
||||
}
|
||||
|
||||
void
|
||||
createFace(const std::string& faceUri,
|
||||
const CommandSucceedCallback& onSuccess,
|
||||
@@ -322,10 +339,22 @@ public:
|
||||
return m_firstHelloInterval;
|
||||
}
|
||||
|
||||
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
|
||||
void
|
||||
addCertificateToCache(ndn::shared_ptr<ndn::IdentityCertificate> certificate)
|
||||
{
|
||||
if (certificate != nullptr) {
|
||||
m_certificateCache->insertCertificate(certificate);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
void
|
||||
registerKeyPrefix();
|
||||
|
||||
void
|
||||
registerLocalhostPrefix();
|
||||
|
||||
void
|
||||
onKeyInterest(const ndn::Name& name, const ndn::Interest& interest);
|
||||
|
||||
@@ -347,6 +376,9 @@ private:
|
||||
m_firstHelloInterval = interval;
|
||||
}
|
||||
|
||||
public:
|
||||
static const ndn::Name LOCALHOST_PREFIX;
|
||||
|
||||
private:
|
||||
typedef std::map<ndn::Name, ndn::shared_ptr<ndn::IdentityCertificate> > CertMap;
|
||||
|
||||
@@ -377,6 +409,7 @@ private:
|
||||
ndn::KeyChain m_keyChain;
|
||||
ndn::Name m_defaultIdentity;
|
||||
ndn::Name m_defaultCertName;
|
||||
update::PrefixUpdateProcessor m_prefixUpdateProcessor;
|
||||
|
||||
ndn::nfd::FaceMonitor m_faceMonitor;
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2015, The University of Memphis,
|
||||
* Regents of the University of California,
|
||||
* Arizona Board of Regents.
|
||||
*
|
||||
* This file is part of NLSR (Named-data Link State Routing).
|
||||
* See AUTHORS.md for complete list of NLSR authors and contributors.
|
||||
*
|
||||
* NLSR is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
**/
|
||||
|
||||
#include "prefix-update-commands.hpp"
|
||||
|
||||
namespace nlsr {
|
||||
namespace update {
|
||||
|
||||
WithdrawPrefixCommand::WithdrawPrefixCommand()
|
||||
: ControlCommand("nlsr", "withdraw")
|
||||
{
|
||||
m_requestValidator.required(ndn::nfd::CONTROL_PARAMETER_NAME);
|
||||
m_responseValidator.required(ndn::nfd::CONTROL_PARAMETER_NAME);
|
||||
}
|
||||
|
||||
AdvertisePrefixCommand::AdvertisePrefixCommand()
|
||||
: ControlCommand("nlsr", "advertise")
|
||||
{
|
||||
m_requestValidator.required(ndn::nfd::CONTROL_PARAMETER_NAME);
|
||||
m_responseValidator.required(ndn::nfd::CONTROL_PARAMETER_NAME);
|
||||
}
|
||||
|
||||
} // namespace update
|
||||
} // namespace nlsr
|
||||
@@ -0,0 +1,45 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2015, The University of Memphis,
|
||||
* Regents of the University of California,
|
||||
* Arizona Board of Regents.
|
||||
*
|
||||
* This file is part of NLSR (Named-data Link State Routing).
|
||||
* See AUTHORS.md for complete list of NLSR authors and contributors.
|
||||
*
|
||||
* NLSR is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
**/
|
||||
|
||||
#ifndef UPDATE_PREFIX_UPDATE_COMMANDS_HPP
|
||||
#define UPDATE_PREFIX_UPDATE_COMMANDS_HPP
|
||||
|
||||
#include <ndn-cxx/management/nfd-control-command.hpp>
|
||||
|
||||
namespace nlsr {
|
||||
namespace update {
|
||||
|
||||
class WithdrawPrefixCommand : public ndn::nfd::ControlCommand
|
||||
{
|
||||
public:
|
||||
WithdrawPrefixCommand();
|
||||
};
|
||||
|
||||
class AdvertisePrefixCommand : public ndn::nfd::ControlCommand
|
||||
{
|
||||
public:
|
||||
AdvertisePrefixCommand();
|
||||
};
|
||||
|
||||
} // namespace update
|
||||
} // namespace nlsr
|
||||
|
||||
#endif // UPDATE_PREFIX_UPDATE_COMMANDS_HPP
|
||||
@@ -0,0 +1,207 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2015, The University of Memphis,
|
||||
* Regents of the University of California,
|
||||
* Arizona Board of Regents.
|
||||
*
|
||||
* This file is part of NLSR (Named-data Link State Routing).
|
||||
* See AUTHORS.md for complete list of NLSR authors and contributors.
|
||||
*
|
||||
* NLSR is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
**/
|
||||
|
||||
#include "prefix-update-processor.hpp"
|
||||
|
||||
#include "lsdb.hpp"
|
||||
#include "nlsr.hpp"
|
||||
#include "prefix-update-commands.hpp"
|
||||
#include "communication/sync-logic-handler.hpp"
|
||||
|
||||
#include <ndn-cxx/management/nfd-control-response.hpp>
|
||||
|
||||
namespace nlsr {
|
||||
namespace update {
|
||||
|
||||
INIT_LOGGER("PrefixUpdateProcessor");
|
||||
|
||||
const ndn::Name::Component PrefixUpdateProcessor::MODULE_COMPONENT = ndn::Name::Component("prefix-update");
|
||||
const ndn::Name::Component PrefixUpdateProcessor::ADVERTISE_VERB = ndn::Name::Component("advertise");
|
||||
const ndn::Name::Component PrefixUpdateProcessor::WITHDRAW_VERB = ndn::Name::Component("withdraw");
|
||||
|
||||
PrefixUpdateProcessor::PrefixUpdateProcessor(ndn::Face& face,
|
||||
NamePrefixList& namePrefixList,
|
||||
Lsdb& lsdb,
|
||||
SyncLogicHandler& sync,
|
||||
const ndn::Name broadcastPrefix,
|
||||
ndn::KeyChain& keyChain,
|
||||
ndn::shared_ptr<ndn::CertificateCacheTtl> certificateCache)
|
||||
: m_face(face)
|
||||
, m_namePrefixList(namePrefixList)
|
||||
, m_lsdb(lsdb)
|
||||
, m_sync(sync)
|
||||
, m_keyChain(keyChain)
|
||||
, m_validator(m_face, broadcastPrefix, certificateCache)
|
||||
, COMMAND_PREFIX(ndn::Name(Nlsr::LOCALHOST_PREFIX).append(MODULE_COMPONENT))
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
PrefixUpdateProcessor::startListening()
|
||||
{
|
||||
_LOG_DEBUG("Setting Interest filter for: " << COMMAND_PREFIX);
|
||||
|
||||
m_face.setInterestFilter(COMMAND_PREFIX, bind(&PrefixUpdateProcessor::onInterest, this, _2));
|
||||
}
|
||||
|
||||
void
|
||||
PrefixUpdateProcessor::onInterest(const ndn::Interest& request)
|
||||
{
|
||||
_LOG_TRACE("Received Interest: " << request);
|
||||
|
||||
m_validator.validate(request,
|
||||
bind(&PrefixUpdateProcessor::onCommandValidated, this, _1),
|
||||
bind(&PrefixUpdateProcessor::onCommandValidationFailed, this, _1, _2));
|
||||
}
|
||||
|
||||
void
|
||||
PrefixUpdateProcessor::loadValidator(boost::property_tree::ptree section,
|
||||
const std::string& filename)
|
||||
{
|
||||
m_validator.load(section, filename);
|
||||
}
|
||||
|
||||
void
|
||||
PrefixUpdateProcessor::onCommandValidated(const std::shared_ptr<const ndn::Interest>& request)
|
||||
{
|
||||
const ndn::Name& command = request->getName();
|
||||
const ndn::Name::Component& verb = command[COMMAND_PREFIX.size()];
|
||||
const ndn::Name::Component& parameterComponent = command[COMMAND_PREFIX.size() + 1];
|
||||
|
||||
if (verb == ADVERTISE_VERB || verb == WITHDRAW_VERB) {
|
||||
ndn::nfd::ControlParameters parameters;
|
||||
|
||||
if (!extractParameters(parameterComponent, parameters)) {
|
||||
sendResponse(request, 400, "Malformed command");
|
||||
return;
|
||||
}
|
||||
|
||||
if (verb == ADVERTISE_VERB) {
|
||||
advertise(request, parameters);
|
||||
}
|
||||
else if (verb == WITHDRAW_VERB) {
|
||||
withdraw(request, parameters);
|
||||
}
|
||||
|
||||
sendResponse(request, 200, "Success");
|
||||
}
|
||||
else {
|
||||
sendResponse(request, 501, "Unsupported command");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
PrefixUpdateProcessor::onCommandValidationFailed(const std::shared_ptr<const ndn::Interest>& request,
|
||||
const std::string& failureInfo)
|
||||
{
|
||||
sendResponse(request, 403, failureInfo);
|
||||
}
|
||||
|
||||
bool
|
||||
PrefixUpdateProcessor::extractParameters(const ndn::Name::Component& parameterComponent,
|
||||
ndn::nfd::ControlParameters& extractedParameters)
|
||||
{
|
||||
try {
|
||||
ndn::Block rawParameters = parameterComponent.blockFromValue();
|
||||
extractedParameters.wireDecode(rawParameters);
|
||||
}
|
||||
catch (const ndn::tlv::Error&) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
PrefixUpdateProcessor::advertise(const std::shared_ptr<const ndn::Interest>& request,
|
||||
const ndn::nfd::ControlParameters& parameters)
|
||||
{
|
||||
AdvertisePrefixCommand command;
|
||||
|
||||
if (!validateParameters(command, parameters)) {
|
||||
sendResponse(request, 400, "Malformed command");
|
||||
return;
|
||||
}
|
||||
|
||||
_LOG_INFO("Advertising name: " << parameters.getName());
|
||||
|
||||
if (m_namePrefixList.insert(parameters.getName())) {
|
||||
// Only build a Name LSA if the added name is new
|
||||
m_lsdb.buildAndInstallOwnNameLsa();
|
||||
m_sync.publishRoutingUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
PrefixUpdateProcessor::withdraw(const std::shared_ptr<const ndn::Interest>& request,
|
||||
const ndn::nfd::ControlParameters& parameters)
|
||||
{
|
||||
WithdrawPrefixCommand command;
|
||||
|
||||
if (!validateParameters(command, parameters)) {
|
||||
sendResponse(request, 400, "Malformed command");
|
||||
return;
|
||||
}
|
||||
|
||||
_LOG_INFO("Withdrawing name: " << parameters.getName());
|
||||
|
||||
if (m_namePrefixList.remove(parameters.getName())) {
|
||||
// Only build a Name LSA if a name was actually removed
|
||||
m_lsdb.buildAndInstallOwnNameLsa();
|
||||
m_sync.publishRoutingUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
PrefixUpdateProcessor::validateParameters(const ndn::nfd::ControlCommand& command,
|
||||
const ndn::nfd::ControlParameters& parameters)
|
||||
{
|
||||
try {
|
||||
command.validateRequest(parameters);
|
||||
}
|
||||
catch (const ndn::nfd::ControlCommand::ArgumentError&) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
PrefixUpdateProcessor::sendResponse(const std::shared_ptr<const ndn::Interest>& request,
|
||||
uint32_t code,
|
||||
const std::string& text)
|
||||
{
|
||||
if (request == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
ndn::nfd::ControlResponse response(code, text);
|
||||
const ndn::Block& encodedControl = response.wireEncode();
|
||||
|
||||
std::shared_ptr<ndn::Data> responseData = ndn::make_shared<ndn::Data>(request->getName());
|
||||
responseData->setContent(encodedControl);
|
||||
|
||||
m_keyChain.sign(*responseData);
|
||||
m_face.put(*responseData);
|
||||
}
|
||||
|
||||
} // namespace update
|
||||
} // namespace nlsr
|
||||
@@ -0,0 +1,137 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2015, The University of Memphis,
|
||||
* Regents of the University of California,
|
||||
* Arizona Board of Regents.
|
||||
*
|
||||
* This file is part of NLSR (Named-data Link State Routing).
|
||||
* See AUTHORS.md for complete list of NLSR authors and contributors.
|
||||
*
|
||||
* NLSR is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
**/
|
||||
|
||||
#ifndef UPDATE_PREFIX_UPDATE_PROCESSOR_HPP
|
||||
#define UPDATE_PREFIX_UPDATE_PROCESSOR_HPP
|
||||
|
||||
#include "name-prefix-list.hpp"
|
||||
#include "test-access-control.hpp"
|
||||
#include "validator.hpp"
|
||||
|
||||
#include <ndn-cxx/face.hpp>
|
||||
#include <ndn-cxx/interest.hpp>
|
||||
#include <ndn-cxx/management/nfd-control-command.hpp>
|
||||
#include <ndn-cxx/management/nfd-control-parameters.hpp>
|
||||
#include <ndn-cxx/security/certificate-cache-ttl.hpp>
|
||||
#include <ndn-cxx/security/key-chain.hpp>
|
||||
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
|
||||
namespace nlsr {
|
||||
|
||||
class Lsdb;
|
||||
class SyncLogicHandler;
|
||||
|
||||
namespace update {
|
||||
|
||||
typedef boost::property_tree::ptree ConfigSection;
|
||||
|
||||
class PrefixUpdateProcessor : boost::noncopyable
|
||||
{
|
||||
public:
|
||||
class Error : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
explicit
|
||||
Error(const std::string& what)
|
||||
: std::runtime_error(what)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
PrefixUpdateProcessor(ndn::Face& face,
|
||||
NamePrefixList& namePrefixList,
|
||||
Lsdb& lsdb,
|
||||
SyncLogicHandler& sync,
|
||||
const ndn::Name broadcastPrefix,
|
||||
ndn::KeyChain& keyChain,
|
||||
ndn::shared_ptr<ndn::CertificateCacheTtl> certificateCache);
|
||||
|
||||
void
|
||||
loadValidator(ConfigSection section, const std::string& filename);
|
||||
|
||||
void
|
||||
startListening();
|
||||
|
||||
private:
|
||||
void
|
||||
onInterest(const ndn::Interest& request);
|
||||
|
||||
void
|
||||
sendResponse(const std::shared_ptr<const ndn::Interest>& request,
|
||||
uint32_t code,
|
||||
const std::string& text);
|
||||
|
||||
/** \brief adds desired name prefix to the advertised name prefix list
|
||||
*/
|
||||
void
|
||||
advertise(const std::shared_ptr<const ndn::Interest>& request,
|
||||
const ndn::nfd::ControlParameters& parameters);
|
||||
|
||||
/** \brief removes desired name prefix from the advertised name prefix list
|
||||
*/
|
||||
void
|
||||
withdraw(const std::shared_ptr<const ndn::Interest>& request,
|
||||
const ndn::nfd::ControlParameters& parameters);
|
||||
|
||||
void
|
||||
onCommandValidated(const std::shared_ptr<const ndn::Interest>& request);
|
||||
|
||||
void
|
||||
onCommandValidationFailed(const std::shared_ptr<const ndn::Interest>& request,
|
||||
const std::string& failureInfo);
|
||||
|
||||
static bool
|
||||
extractParameters(const ndn::name::Component& parameterComponent,
|
||||
ndn::nfd::ControlParameters& extractedParameters);
|
||||
|
||||
bool
|
||||
validateParameters(const ndn::nfd::ControlCommand& command,
|
||||
const ndn::nfd::ControlParameters& parameters);
|
||||
|
||||
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
|
||||
Validator&
|
||||
getValidator()
|
||||
{
|
||||
return m_validator;
|
||||
}
|
||||
|
||||
private:
|
||||
ndn::Face& m_face;
|
||||
NamePrefixList& m_namePrefixList;
|
||||
Lsdb& m_lsdb;
|
||||
SyncLogicHandler& m_sync;
|
||||
ndn::KeyChain& m_keyChain;
|
||||
Validator m_validator;
|
||||
|
||||
const ndn::Name COMMAND_PREFIX; // /localhost/nlsr/prefix-update
|
||||
|
||||
static const ndn::Name::Component MODULE_COMPONENT;
|
||||
static const ndn::Name::Component ADVERTISE_VERB;
|
||||
static const ndn::Name::Component WITHDRAW_VERB;
|
||||
};
|
||||
|
||||
} // namespace update
|
||||
} // namespace nlsr
|
||||
|
||||
#endif // UPDATE_PREFIX_UPDATE_PROCESSOR_HPP
|
||||
@@ -0,0 +1,241 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2015, The University of Memphis,
|
||||
* Regents of the University of California,
|
||||
* Arizona Board of Regents.
|
||||
*
|
||||
* This file is part of NLSR (Named-data Link State Routing).
|
||||
* See AUTHORS.md for complete list of NLSR authors and contributors.
|
||||
*
|
||||
* NLSR is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
**/
|
||||
|
||||
#include "update/prefix-update-processor.hpp"
|
||||
|
||||
#include "../control-commands.hpp"
|
||||
#include "../test-common.hpp"
|
||||
#include "nlsr.hpp"
|
||||
|
||||
#include <ndn-cxx/interest.hpp>
|
||||
#include <ndn-cxx/management/nfd-control-parameters.hpp>
|
||||
#include <ndn-cxx/security/key-chain.hpp>
|
||||
#include <ndn-cxx/util/dummy-client-face.hpp>
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
using namespace ndn;
|
||||
|
||||
namespace nlsr {
|
||||
namespace update {
|
||||
namespace test {
|
||||
|
||||
class PrefixUpdateFixture : public nlsr::test::BaseFixture
|
||||
{
|
||||
public:
|
||||
PrefixUpdateFixture()
|
||||
: face(ndn::util::makeDummyClientFace(g_ioService))
|
||||
, siteIdentity(ndn::Name("/ndn/edu/test-site").appendVersion())
|
||||
, opIdentity(ndn::Name(siteIdentity).append(ndn::Name("%C1.Operator")).appendVersion())
|
||||
, nlsr(g_ioService, g_scheduler, *face)
|
||||
, keyPrefix(("/ndn/broadcast"))
|
||||
, updateProcessor(nlsr.getPrefixUpdateProcessor())
|
||||
, SITE_CERT_PATH(boost::filesystem::current_path() / std::string("site.cert"))
|
||||
{
|
||||
createSiteCert();
|
||||
BOOST_REQUIRE(siteCert != nullptr);
|
||||
|
||||
createOperatorCert();
|
||||
BOOST_REQUIRE(opCert != nullptr);
|
||||
|
||||
const std::string CONFIG =
|
||||
"rule\n"
|
||||
"{\n"
|
||||
" id \"NLSR ControlCommand Rule\"\n"
|
||||
" for interest\n"
|
||||
" filter\n"
|
||||
" {\n"
|
||||
" type name\n"
|
||||
" regex ^<localhost><nlsr><prefix-update>[<advertise><withdraw>]<>$\n"
|
||||
" }\n"
|
||||
" checker\n"
|
||||
" {\n"
|
||||
" type customized\n"
|
||||
" sig-type rsa-sha256\n"
|
||||
" key-locator\n"
|
||||
" {\n"
|
||||
" type name\n"
|
||||
" regex ^([^<KEY><%C1.Operator>]*)<%C1.Operator>[^<KEY>]*<KEY><ksk-.*><ID-CERT>$\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"rule\n"
|
||||
"{\n"
|
||||
" id \"NLSR Hierarchy Rule\"\n"
|
||||
" for data\n"
|
||||
" filter\n"
|
||||
" {\n"
|
||||
" type name\n"
|
||||
" regex ^[^<KEY>]*<KEY><ksk-.*><ID-CERT><>$\n"
|
||||
" }\n"
|
||||
" checker\n"
|
||||
" {\n"
|
||||
" type hierarchical\n"
|
||||
" sig-type rsa-sha256\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"trust-anchor\n"
|
||||
"{\n"
|
||||
" type file\n"
|
||||
" file-name \"site.cert\"\n"
|
||||
"}\n";
|
||||
|
||||
const boost::filesystem::path CONFIG_PATH =
|
||||
(boost::filesystem::current_path() / std::string("unit-test.conf"));
|
||||
|
||||
updateProcessor.getValidator().load(CONFIG, CONFIG_PATH.native());
|
||||
|
||||
// Insert certs after the validator is loaded since ValidatorConfig::load() clears
|
||||
// the certificate cache
|
||||
nlsr.addCertificateToCache(opCert);
|
||||
|
||||
// Set the network so the LSA prefix is constructed
|
||||
nlsr.getConfParameter().setNetwork("/ndn");
|
||||
|
||||
// Initialize NLSR so a sync socket is created
|
||||
nlsr.initialize();
|
||||
|
||||
// Listen on localhost prefix
|
||||
updateProcessor.startListening();
|
||||
|
||||
face->processEvents(ndn::time::milliseconds(1));
|
||||
face->sentInterests.clear();
|
||||
}
|
||||
|
||||
void
|
||||
createSiteCert()
|
||||
{
|
||||
// Site cert
|
||||
keyChain.createIdentity(siteIdentity);
|
||||
siteCertName = keyChain.getDefaultCertificateNameForIdentity(siteIdentity);
|
||||
siteCert = keyChain.getCertificate(siteCertName);
|
||||
|
||||
ndn::io::save(*siteCert, SITE_CERT_PATH.string());
|
||||
}
|
||||
|
||||
void
|
||||
createOperatorCert()
|
||||
{
|
||||
// Operator cert
|
||||
ndn::Name keyName = keyChain.generateRsaKeyPairAsDefault(opIdentity, true);
|
||||
|
||||
opCert = ndn::make_shared<ndn::IdentityCertificate>();
|
||||
ndn::shared_ptr<ndn::PublicKey> pubKey = keyChain.getPublicKey(keyName);
|
||||
opCertName = keyName.getPrefix(-1);
|
||||
opCertName.append("KEY").append(keyName.get(-1)).append("ID-CERT").appendVersion();
|
||||
opCert->setName(opCertName);
|
||||
opCert->setNotBefore(time::system_clock::now() - time::days(1));
|
||||
opCert->setNotAfter(time::system_clock::now() + time::days(1));
|
||||
opCert->setPublicKeyInfo(*pubKey);
|
||||
opCert->addSubjectDescription(CertificateSubjectDescription(ndn::oid::ATTRIBUTE_NAME,
|
||||
keyName.toUri()));
|
||||
opCert->encode();
|
||||
|
||||
keyChain.signByIdentity(*opCert, siteIdentity);
|
||||
|
||||
keyChain.addCertificateAsIdentityDefault(*opCert);
|
||||
}
|
||||
|
||||
bool
|
||||
wasRoutingUpdatePublished()
|
||||
{
|
||||
const ndn::Name& lsaPrefix = nlsr.getConfParameter().getLsaPrefix();
|
||||
|
||||
const auto& it = std::find_if(face->sentDatas.begin(), face->sentDatas.end(),
|
||||
[lsaPrefix] (const ndn::Data& data) {
|
||||
return lsaPrefix.isPrefixOf(data.getName());
|
||||
});
|
||||
|
||||
return (it != face->sentDatas.end());
|
||||
}
|
||||
|
||||
~PrefixUpdateFixture()
|
||||
{
|
||||
keyChain.deleteIdentity(siteIdentity);
|
||||
keyChain.deleteIdentity(opIdentity);
|
||||
|
||||
boost::filesystem::remove(SITE_CERT_PATH);
|
||||
}
|
||||
|
||||
public:
|
||||
shared_ptr<ndn::util::DummyClientFace> face;
|
||||
ndn::KeyChain keyChain;
|
||||
|
||||
ndn::Name siteIdentity;
|
||||
ndn::Name siteCertName;
|
||||
shared_ptr<IdentityCertificate> siteCert;
|
||||
|
||||
ndn::Name opIdentity;
|
||||
ndn::Name opCertName;
|
||||
shared_ptr<IdentityCertificate> opCert;
|
||||
|
||||
Nlsr nlsr;
|
||||
ndn::Name keyPrefix;
|
||||
PrefixUpdateProcessor& updateProcessor;
|
||||
|
||||
const boost::filesystem::path SITE_CERT_PATH;
|
||||
};
|
||||
|
||||
BOOST_FIXTURE_TEST_SUITE(TestPrefixUpdateProcessor, PrefixUpdateFixture)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Basic)
|
||||
{
|
||||
// Advertise
|
||||
ndn::nfd::ControlParameters parameters;
|
||||
parameters.setName("/prefix/to/advertise/");
|
||||
|
||||
ndn::Name advertiseCommand("/localhost/nlsr/prefix-update/advertise");
|
||||
advertiseCommand.append(parameters.wireEncode());
|
||||
|
||||
shared_ptr<Interest> advertiseInterest = make_shared<Interest>(advertiseCommand);
|
||||
keyChain.signByIdentity(*advertiseInterest, opIdentity);
|
||||
|
||||
face->receive(*advertiseInterest);
|
||||
face->processEvents(ndn::time::milliseconds(1));
|
||||
|
||||
NamePrefixList& namePrefixList = nlsr.getNamePrefixList();
|
||||
|
||||
BOOST_REQUIRE_EQUAL(namePrefixList.getSize(), 1);
|
||||
BOOST_CHECK_EQUAL(namePrefixList.getNameList().front(), parameters.getName());
|
||||
|
||||
BOOST_CHECK(wasRoutingUpdatePublished());
|
||||
face->sentDatas.clear();
|
||||
|
||||
// Withdraw
|
||||
ndn::Name withdrawCommand("/localhost/nlsr/prefix-update/withdraw");
|
||||
withdrawCommand.append(parameters.wireEncode());
|
||||
|
||||
shared_ptr<Interest> withdrawInterest = make_shared<Interest>(withdrawCommand);
|
||||
keyChain.signByIdentity(*withdrawInterest, opIdentity);
|
||||
|
||||
face->receive(*withdrawInterest);
|
||||
face->processEvents(ndn::time::milliseconds(1));
|
||||
|
||||
BOOST_CHECK_EQUAL(namePrefixList.getSize(), 0);
|
||||
|
||||
BOOST_CHECK(wasRoutingUpdatePublished());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
} // namespace test
|
||||
} // namespace update
|
||||
} // namespace nlsr
|
||||
+1
-1
@@ -28,7 +28,7 @@ def build(bld):
|
||||
target='unit-tests-main',
|
||||
name='unit-tests-main',
|
||||
features='cxx',
|
||||
source=bld.path.ant_glob(['*.cpp', 'utility/*.cpp', 'tlv/*.cpp', 'publisher/*.cpp']),
|
||||
source=bld.path.ant_glob(['**/*.cpp'], excl=['nsync/**/*']),
|
||||
use='nlsr-objects',
|
||||
)
|
||||
|
||||
|
||||
Reference in new issue
Block a user