Skip to content

Commit

Permalink
mgmt: refactor management modules to conform to NFD Management Protocol
Browse files Browse the repository at this point in the history
Refactor management protocol specific option types to ControlParameters
Add control parameter field enforcement
Add missing control response "success" message bodies
Update fib management protocol response codes and behavior
Merge local control header manager into face manager
Refactor references of nfd::LocalControlHeaderFeature enum to ndn::nfd::LocalControlFeature
Remove "control-header" privilege from default configuration

refs: #1397, #1399, #1400

Change-Id: Id042daf00b3cee1f1c7fa38d2e4a4ff6d95c15c6
  • Loading branch information
Steve DiBenedetto committed Mar 25, 2014
1 parent efea8fe commit 7564d97
Show file tree
Hide file tree
Showing 23 changed files with 1,134 additions and 1,105 deletions.
73 changes: 40 additions & 33 deletions daemon/face/local-face.hpp
Expand Up @@ -8,48 +8,50 @@
#define NFD_FACE_LOCAL_FACE_HPP

#include "face.hpp"
#include <ndn-cpp-dev/management/nfd-control-parameters.hpp>

namespace nfd {

/* \brief indicates a feature in LocalControlHeader
*/
enum LocalControlHeaderFeature
{
/// any feature
LOCAL_CONTROL_HEADER_FEATURE_ANY,
/// in-faceid
LOCAL_CONTROL_HEADER_FEATURE_IN_FACEID,
/// out-faceid
LOCAL_CONTROL_HEADER_FEATURE_NEXTHOP_FACEID,
/// upper bound of enum
LOCAL_CONTROL_HEADER_FEATURE_MAX
};

using ndn::nfd::LocalControlFeature;
using ndn::nfd::LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID;
using ndn::nfd::LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID;

/** \brief represents a face
*/
class LocalFace : public Face
{
public:

explicit
LocalFace(const FaceUri& uri);

/** \brief get whether a LocalControlHeader feature is enabled
/** \brief get whether any LocalControlHeader feature is enabled
*
* \returns true if any feature is enabled.
*/
bool
isLocalControlHeaderEnabled() const;

/** \brief get whether a specific LocalControlHeader feature is enabled
*
* \param feature The feature. Cannot be LOCAL_CONTROL_HEADER_FEATURE_MAX
* LOCAL_CONTROL_HEADER_FEATURE_ANY returns true if any feature is enabled.
* \param feature The feature.
* \returns true if the specified feature is enabled.
*/
bool
isLocalControlHeaderEnabled(LocalControlHeaderFeature feature =
LOCAL_CONTROL_HEADER_FEATURE_ANY) const;
isLocalControlHeaderEnabled(LocalControlFeature feature) const;

/** \brief enable or disable a LocalControlHeader feature
*
* \param feature The feature. Cannot be LOCAL_CONTROL_HEADER_FEATURE_ANY
* or LOCAL_CONTROL_HEADER_FEATURE_MAX
* \param feature The feature. Cannot be LOCAL_CONTROL_FEATURE_ANY
* or LOCAL_CONTROL_FEATURE_MAX
*/
void
setLocalControlHeaderFeature(LocalControlHeaderFeature feature, bool enabled = true);
setLocalControlHeaderFeature(LocalControlFeature feature, bool enabled = true);

public:

static const size_t LOCAL_CONTROL_FEATURE_MAX = 3; /// upper bound of LocalControlFeature enum
static const size_t LOCAL_CONTROL_FEATURE_ANY = 0; /// any feature

protected:
// statically overridden from Face
Expand Down Expand Up @@ -84,26 +86,31 @@ class LocalFace : public Face
inline
LocalFace::LocalFace(const FaceUri& uri)
: Face(uri, true)
, m_localControlHeaderFeatures(LOCAL_CONTROL_HEADER_FEATURE_MAX)
, m_localControlHeaderFeatures(LocalFace::LOCAL_CONTROL_FEATURE_MAX)
{
}

inline bool
LocalFace::isLocalControlHeaderEnabled() const
{
return m_localControlHeaderFeatures[LOCAL_CONTROL_FEATURE_ANY];
}

inline bool
LocalFace::isLocalControlHeaderEnabled(LocalControlHeaderFeature feature) const
LocalFace::isLocalControlHeaderEnabled(LocalControlFeature feature) const
{
BOOST_ASSERT(feature < m_localControlHeaderFeatures.size());
BOOST_ASSERT(0 < feature && feature < m_localControlHeaderFeatures.size());
return m_localControlHeaderFeatures[feature];
}

inline void
LocalFace::setLocalControlHeaderFeature(LocalControlHeaderFeature feature, bool enabled/* = true*/)
LocalFace::setLocalControlHeaderFeature(LocalControlFeature feature, bool enabled/* = true*/)
{
BOOST_ASSERT(feature > LOCAL_CONTROL_HEADER_FEATURE_ANY &&
feature < m_localControlHeaderFeatures.size());
BOOST_ASSERT(0 < feature && feature < m_localControlHeaderFeatures.size());

m_localControlHeaderFeatures[feature] = enabled;

BOOST_STATIC_ASSERT(LOCAL_CONTROL_HEADER_FEATURE_ANY == 0);
m_localControlHeaderFeatures[LOCAL_CONTROL_HEADER_FEATURE_ANY] =
m_localControlHeaderFeatures[LOCAL_CONTROL_FEATURE_ANY] =
std::find(m_localControlHeaderFeatures.begin() + 1,
m_localControlHeaderFeatures.end(), true) <
m_localControlHeaderFeatures.end();
Expand All @@ -127,7 +134,7 @@ LocalFace::decodeAndDispatchInput(const Block& element)
{
i->getLocalControlHeader().wireDecode(element,
false,
this->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_NEXTHOP_FACEID));
this->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
}

this->onReceiveInterest(*i);
Expand Down Expand Up @@ -162,7 +169,7 @@ LocalFace::isEmptyFilteredLocalControlHeader(const ndn::nfd::LocalControlHeader&
if (!this->isLocalControlHeaderEnabled())
return true;

return header.empty(this->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_IN_FACEID),
return header.empty(this->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID),
false);
}

Expand All @@ -171,7 +178,7 @@ inline Block
LocalFace::filterAndEncodeLocalControlHeader(const Packet& packet)
{
return packet.getLocalControlHeader().wireEncode(packet,
this->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_IN_FACEID),
this->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID),
false);
}

Expand Down
6 changes: 0 additions & 6 deletions daemon/main.cpp
Expand Up @@ -10,7 +10,6 @@
#include "mgmt/internal-face.hpp"
#include "mgmt/fib-manager.hpp"
#include "mgmt/face-manager.hpp"
#include "mgmt/local-control-header-manager.hpp"
#include "mgmt/strategy-choice-manager.hpp"
#include "mgmt/status-server.hpp"
#include "mgmt/config-file.hpp"
Expand All @@ -31,7 +30,6 @@ static ProgramOptions g_options;
static Forwarder* g_forwarder;
static FibManager* g_fibManager;
static FaceManager* g_faceManager;
static LocalControlHeaderManager* g_localControlHeaderManager;
static StrategyChoiceManager* g_strategyChoiceManager;
static StatusServer* g_statusServer;
static shared_ptr<InternalFace> g_internalFace;
Expand Down Expand Up @@ -100,10 +98,6 @@ initializeMgmt()
g_faceManager = new FaceManager(g_forwarder->getFaceTable(), g_internalFace);
g_faceManager->setConfigFile(config);

g_localControlHeaderManager =
new LocalControlHeaderManager(bind(&Forwarder::getFace, g_forwarder, _1),
g_internalFace);

g_strategyChoiceManager = new StrategyChoiceManager(g_forwarder->getStrategyChoice(),
g_internalFace);

Expand Down

0 comments on commit 7564d97

Please sign in to comment.