forked from named-data/ndnSIM
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added strategy parameters and the BroadcastNewNonceStrategy as simple…
… example how to use them.
- Loading branch information
Klaus (Laptop)
committed
May 25, 2015
1 parent
a5587ca
commit f26d1ae
Showing
10 changed files
with
330 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,6 @@ | |
*~ | ||
.DS_Store | ||
docs/doxygen.warnings.log | ||
|
||
test.cc | ||
.*project | ||
helper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | ||
/** | ||
* Copyright (c) 2014, Regents of the University of California, | ||
* Arizona Board of Regents, | ||
* Colorado State University, | ||
* University Pierre & Marie Curie, Sorbonne University, | ||
* Washington University in St. Louis, | ||
* Beijing Institute of Technology, | ||
* The University of Memphis | ||
* | ||
* This file is part of NFD (Named Data Networking Forwarding Daemon). | ||
* See AUTHORS.md for complete list of NFD authors and contributors. | ||
* | ||
* NFD 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. | ||
* | ||
* NFD 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 | ||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "broadcast-newnonce-strategy.hpp" | ||
#include "strategy-helper.hpp" | ||
#include <map> | ||
#include "core/logger.hpp" | ||
|
||
namespace nfd { | ||
namespace fw { | ||
|
||
NFD_LOG_INIT("BroadcastNewNonceStrategy"); | ||
|
||
const Name BroadcastNewNonceStrategy::STRATEGY_NAME( | ||
"ndn:/localhost/nfd/strategy/broadcast-newnonce/%FD%01"); | ||
|
||
BroadcastNewNonceStrategy::BroadcastNewNonceStrategy(Forwarder& forwarder, const Name& name) : | ||
Strategy(forwarder, name), ownStrategyChoice(forwarder.getStrategyChoice()) | ||
{ | ||
NFD_LOG_INFO("BroadcastNewNonceStrategy initialized!"); | ||
} | ||
|
||
BroadcastNewNonceStrategy::~BroadcastNewNonceStrategy() | ||
{ | ||
} | ||
|
||
void BroadcastNewNonceStrategy::afterReceiveInterest(const Face& inFace, const Interest& interest, | ||
shared_ptr<fib::Entry> fibEntry, shared_ptr<pit::Entry> pitEntry) | ||
{ | ||
|
||
bool useNonce = true; | ||
// Getting nonce value from parameters; | ||
std::string parameterString = ownStrategyChoice.findEffectiveParameters( | ||
interest.getName().toUri()); | ||
std::map < std::string, std::string > parameterMap = StrategyHelper::getParameterMap( | ||
parameterString); | ||
|
||
std::map<std::string, std::string>::const_iterator it = parameterMap.find("nonce"); | ||
if (it != parameterMap.end()) { | ||
if (it->second == "false") { | ||
useNonce = false; | ||
} | ||
} | ||
|
||
const fib::NextHopList& nexthops = fibEntry->getNextHops(); | ||
|
||
for (fib::NextHopList::const_iterator it = nexthops.begin(); it != nexthops.end(); ++it) { | ||
shared_ptr < Face > outFace = it->getFace(); | ||
if (pitEntry->canForwardTo(*outFace)) { | ||
NFD_LOG_TRACE("New Nonce? " << useNonce); | ||
// If nonce == true, change interest nonce for each new packet | ||
this->sendInterest(pitEntry, outFace, useNonce); | ||
} | ||
} | ||
|
||
if (!pitEntry->hasUnexpiredOutRecords()) { | ||
this->rejectPendingInterest(pitEntry); | ||
} | ||
} | ||
|
||
} // namespace fw | ||
} // namespace nfd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#ifndef NFD_DAEMON_FW_OWNSTRATEGY_HPP | ||
#define NFD_DAEMON_FW_OWNSTRATEGY_HPP | ||
|
||
#include "strategy.hpp" | ||
|
||
namespace nfd { | ||
namespace fw { | ||
|
||
/** \class BroadcastNewNonceStrategy | ||
* \brief Forwards interests to all nexthops using a new nonce. | ||
* | ||
* The parameter "nonce" denotes if a new nonce should be used (nonce=true) or not (nonce=false). | ||
* The default is to use a new nonce. | ||
*/ | ||
class BroadcastNewNonceStrategy : public Strategy | ||
{ | ||
public: | ||
BroadcastNewNonceStrategy(Forwarder& forwarder, const Name& name = STRATEGY_NAME); | ||
|
||
virtual | ||
~BroadcastNewNonceStrategy(); | ||
|
||
virtual void | ||
afterReceiveInterest(const Face& inFace, const Interest& interest, | ||
shared_ptr<fib::Entry> fibEntry, shared_ptr<pit::Entry> pitEntry) | ||
DECL_OVERRIDE; | ||
|
||
public: | ||
static const Name STRATEGY_NAME; | ||
|
||
private: | ||
StrategyChoice& ownStrategyChoice; | ||
}; | ||
|
||
} // namespace fw | ||
} // namespace nfd | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include "strategy-helper.hpp" | ||
#include "core/logger.hpp" | ||
#include <boost/algorithm/string/classification.hpp> | ||
#include <boost/algorithm/string/detail/classification.hpp> | ||
#include <boost/algorithm/string/replace.hpp> | ||
#include <boost/algorithm/string/split.hpp> | ||
|
||
namespace nfd { | ||
namespace fw { | ||
|
||
NFD_LOG_INIT("StrategyHelper"); | ||
|
||
std::map<std::string, std::string> StrategyHelper::getParameterMap(std::string parameters) | ||
{ | ||
NFD_LOG_INFO("Parsing parameters!"); | ||
|
||
std::map < std::string, std::string > outputMap; | ||
|
||
// Replace ASCII elements | ||
boost::replace_all(parameters, "%2C", ","); | ||
boost::replace_all(parameters, "%3D", "="); | ||
|
||
std::vector < std::string > paramVector; | ||
boost::split(paramVector, parameters, boost::is_any_of(",")); | ||
|
||
for (auto substring : paramVector) { | ||
std::vector < std::string > substringVector; | ||
boost::split(substringVector, substring, boost::is_any_of("=")); | ||
|
||
std::string key = substringVector.front(); | ||
std::string value = substringVector.back(); | ||
outputMap[substringVector.front()] = substringVector.back(); | ||
} | ||
|
||
return outputMap; | ||
} | ||
|
||
} // namespace nfd | ||
} // namespace fw |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#ifndef NFD_DAEMON_FW_STRATEGY_HELPER_HPP | ||
#define NFD_DAEMON_FW_STRATEGY_HELPER_HPP | ||
|
||
#include <map> | ||
#include <string> | ||
|
||
namespace nfd { | ||
namespace fw { | ||
|
||
class StrategyHelper | ||
{ | ||
|
||
public: | ||
static std::map<std::string, std::string> getParameterMap(std::string parameters); | ||
}; | ||
|
||
} // namespace fw | ||
} // namespace nfd | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.