face+mgmt: accept LocalUri in ProtocolFactory and FaceManager

refs #4016

Change-Id: I3e192e6d3982ae8e6ced1dbfbaa62f1c993f799e
This commit is contained in:
Eric Newberry
2017-04-01 14:34:44 +00:00
committed by Junxiao Shi
parent 6bd6d0b50a
commit 78e32b0ee2
20 changed files with 117 additions and 39 deletions
+2 -1
View File
@@ -133,7 +133,8 @@ EthernetFactory::processConfig(OptionalConfigSection configSection,
}
void
EthernetFactory::createFace(const FaceUri& uri,
EthernetFactory::createFace(const FaceUri& remoteUri,
const ndn::optional<FaceUri>& localUri,
ndn::nfd::FacePersistency persistency,
bool wantLocalFieldsEnabled,
const FaceCreatedCallback& onCreated,
+2 -1
View File
@@ -50,7 +50,8 @@ public:
/** \brief unicast face creation is not supported and will always fail
*/
void
createFace(const FaceUri& uri,
createFace(const FaceUri& remoteUri,
const ndn::optional<FaceUri>& localUri,
ndn::nfd::FacePersistency persistency,
bool wantLocalFieldsEnabled,
const FaceCreatedCallback& onCreated,
+6 -8
View File
@@ -116,19 +116,17 @@ public:
/** \brief Try to create Face using the supplied FaceUri
*
* This method should automatically choose channel, based on supplied FaceUri
* and create face.
*
* \param uri remote URI of the new face
* \param remoteUri remote URI of the new face
* \param localUri local URI of the new face
* \param persistency persistency of the new face
* \param wantLocalFieldsEnabled whether local fields should be enabled on the face
* \param onCreated callback if face creation succeeds
* If a face with the same remote URI already exists, its persistency and
* LocalFieldsEnabled setting will not be modified.
* \param onCreated callback if face creation succeeds or face already exists;
* persistency and local fields settings are not updated on an existing face
* \param onFailure callback if face creation fails
*/
virtual void
createFace(const FaceUri& uri,
createFace(const FaceUri& remoteUri,
const ndn::optional<FaceUri>& localUri,
ndn::nfd::FacePersistency persistency,
bool wantLocalFieldsEnabled,
const FaceCreatedCallback& onCreated,
+11 -4
View File
@@ -121,13 +121,20 @@ TcpFactory::processConfig(OptionalConfigSection configSection,
}
void
TcpFactory::createFace(const FaceUri& uri,
TcpFactory::createFace(const FaceUri& remoteUri,
const ndn::optional<FaceUri>& localUri,
ndn::nfd::FacePersistency persistency,
bool wantLocalFieldsEnabled,
const FaceCreatedCallback& onCreated,
const FaceCreationFailedCallback& onFailure)
{
BOOST_ASSERT(uri.isCanonical());
BOOST_ASSERT(remoteUri.isCanonical());
if (localUri) {
NFD_LOG_TRACE("Cannot create unicast TCP face with LocalUri");
onFailure(406, "Unicast TCP faces cannot be created with a LocalUri");
return;
}
if (persistency != ndn::nfd::FACE_PERSISTENCY_PERSISTENT) {
NFD_LOG_TRACE("createFace only supports FACE_PERSISTENCY_PERSISTENT");
@@ -135,8 +142,8 @@ TcpFactory::createFace(const FaceUri& uri,
return;
}
tcp::Endpoint endpoint(ip::address::from_string(uri.getHost()),
boost::lexical_cast<uint16_t>(uri.getPort()));
tcp::Endpoint endpoint(ip::address::from_string(remoteUri.getHost()),
boost::lexical_cast<uint16_t>(remoteUri.getPort()));
if (endpoint.address().is_multicast()) {
NFD_LOG_TRACE("createFace cannot create multicast faces");
+2 -1
View File
@@ -47,7 +47,8 @@ public:
FaceSystem::ConfigContext& context) override;
void
createFace(const FaceUri& uri,
createFace(const FaceUri& remoteUri,
const ndn::optional<FaceUri>& localUri,
ndn::nfd::FacePersistency persistency,
bool wantLocalFieldsEnabled,
const FaceCreatedCallback& onCreated,
+11 -4
View File
@@ -202,13 +202,20 @@ UdpFactory::processConfig(OptionalConfigSection configSection,
}
void
UdpFactory::createFace(const FaceUri& uri,
UdpFactory::createFace(const FaceUri& remoteUri,
const ndn::optional<FaceUri>& localUri,
ndn::nfd::FacePersistency persistency,
bool wantLocalFieldsEnabled,
const FaceCreatedCallback& onCreated,
const FaceCreationFailedCallback& onFailure)
{
BOOST_ASSERT(uri.isCanonical());
BOOST_ASSERT(remoteUri.isCanonical());
if (localUri) {
NFD_LOG_TRACE("Cannot create unicast UDP face with LocalUri");
onFailure(406, "Unicast UDP faces cannot be created with a LocalUri");
return;
}
if (persistency == ndn::nfd::FACE_PERSISTENCY_ON_DEMAND) {
NFD_LOG_TRACE("createFace does not support FACE_PERSISTENCY_ON_DEMAND");
@@ -216,8 +223,8 @@ UdpFactory::createFace(const FaceUri& uri,
return;
}
udp::Endpoint endpoint(ip::address::from_string(uri.getHost()),
boost::lexical_cast<uint16_t>(uri.getPort()));
udp::Endpoint endpoint(ip::address::from_string(remoteUri.getHost()),
boost::lexical_cast<uint16_t>(remoteUri.getPort()));
if (endpoint.address().is_multicast()) {
NFD_LOG_TRACE("createFace does not support multicast faces");
+2 -1
View File
@@ -63,7 +63,8 @@ public:
FaceSystem::ConfigContext& context) override;
void
createFace(const FaceUri& uri,
createFace(const FaceUri& remoteUri,
const ndn::optional<FaceUri>& localUri,
ndn::nfd::FacePersistency persistency,
bool wantLocalFieldsEnabled,
const FaceCreatedCallback& onCreated,
+2 -1
View File
@@ -81,7 +81,8 @@ UnixStreamFactory::processConfig(OptionalConfigSection configSection,
}
void
UnixStreamFactory::createFace(const FaceUri& uri,
UnixStreamFactory::createFace(const FaceUri& remoteUri,
const ndn::optional<FaceUri>& localUri,
ndn::nfd::FacePersistency persistency,
bool wantLocalFieldsEnabled,
const FaceCreatedCallback& onCreated,
+2 -1
View File
@@ -47,7 +47,8 @@ public:
FaceSystem::ConfigContext& context) override;
void
createFace(const FaceUri& uri,
createFace(const FaceUri& remoteUri,
const ndn::optional<FaceUri>& localUri,
ndn::nfd::FacePersistency persistency,
bool wantLocalFieldsEnabled,
const FaceCreatedCallback& onCreated,
+2 -1
View File
@@ -115,7 +115,8 @@ WebSocketFactory::processConfig(OptionalConfigSection configSection,
}
void
WebSocketFactory::createFace(const FaceUri& uri,
WebSocketFactory::createFace(const FaceUri& remoteUri,
const ndn::optional<FaceUri>& localUri,
ndn::nfd::FacePersistency persistency,
bool wantLocalFieldsEnabled,
const FaceCreatedCallback& onCreated,
+2 -1
View File
@@ -49,7 +49,8 @@ public:
/** \brief unicast face creation is not supported and will always fail
*/
void
createFace(const FaceUri& uri,
createFace(const FaceUri& remoteUri,
const ndn::optional<FaceUri>& localUri,
ndn::nfd::FacePersistency persistency,
bool wantLocalFieldsEnabled,
const FaceCreatedCallback& onCreated,
+27 -9
View File
@@ -78,28 +78,46 @@ FaceManager::createFace(const Name& topPrefix, const Interest& interest,
const ControlParameters& parameters,
const ndn::mgmt::CommandContinuation& done)
{
FaceUri uri;
if (!uri.parse(parameters.getUri())) {
NFD_LOG_TRACE("failed to parse URI");
FaceUri remoteUri;
if (!remoteUri.parse(parameters.getUri())) {
NFD_LOG_TRACE("failed to parse remote URI: " << parameters.getUri());
done(ControlResponse(400, "Malformed command"));
return;
}
if (!uri.isCanonical()) {
NFD_LOG_TRACE("received non-canonical URI");
done(ControlResponse(400, "Non-canonical URI"));
if (!remoteUri.isCanonical()) {
NFD_LOG_TRACE("received non-canonical remote URI: " << remoteUri.toString());
done(ControlResponse(400, "Non-canonical remote URI"));
return;
}
ProtocolFactory* factory = m_faceSystem.getFactoryByScheme(uri.getScheme());
ndn::optional<FaceUri> localUri;
if (parameters.hasLocalUri()) {
localUri = FaceUri{};
if (!localUri->parse(parameters.getLocalUri())) {
NFD_LOG_TRACE("failed to parse local URI: " << parameters.getLocalUri());
done(ControlResponse(400, "Malformed command"));
return;
}
if (!localUri->isCanonical()) {
NFD_LOG_TRACE("received non-canonical local URI: " << localUri->toString());
done(ControlResponse(400, "Non-canonical local URI"));
return;
}
}
ProtocolFactory* factory = m_faceSystem.getFactoryByScheme(remoteUri.getScheme());
if (factory == nullptr) {
NFD_LOG_TRACE("received create request for unsupported protocol");
NFD_LOG_TRACE("received create request for unsupported protocol: " << remoteUri.getScheme());
done(ControlResponse(406, "Unsupported protocol"));
return;
}
try {
factory->createFace(uri,
factory->createFace(remoteUri,
localUri,
parameters.getFacePersistency(),
parameters.hasFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED) &&
parameters.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED),
+3
View File
@@ -327,18 +327,21 @@ BOOST_AUTO_TEST_CASE(UnsupportedFaceCreate)
createFace(factory,
FaceUri("ether://[08:00:27:01:01:01]"),
{},
ndn::nfd::FACE_PERSISTENCY_PERMANENT,
false,
{CreateFaceExpectedResult::FAILURE, 406, "Unsupported protocol"});
createFace(factory,
FaceUri("ether://[08:00:27:01:01:01]"),
{},
ndn::nfd::FACE_PERSISTENCY_ON_DEMAND,
false,
{CreateFaceExpectedResult::FAILURE, 406, "Unsupported protocol"});
createFace(factory,
FaceUri("ether://[08:00:27:01:01:01]"),
{},
ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
false,
{CreateFaceExpectedResult::FAILURE, 406, "Unsupported protocol"});
+2 -1
View File
@@ -53,7 +53,8 @@ public:
}
void
createFace(const FaceUri& uri,
createFace(const FaceUri& remoteUri,
const ndn::optional<FaceUri>& localUri,
ndn::nfd::FacePersistency persistency,
bool wantLocalFieldsEnabled,
const FaceCreatedCallback& onCreated,
+3 -2
View File
@@ -43,12 +43,13 @@ struct CreateFaceExpectedResult
inline void
createFace(ProtocolFactory& factory,
const FaceUri& uri,
const FaceUri& remoteUri,
const ndn::optional<FaceUri>& localUri,
ndn::nfd::FacePersistency persistency,
bool wantLocalFieldsEnabled,
const CreateFaceExpectedResult& expected)
{
factory.createFace(uri, persistency, wantLocalFieldsEnabled,
factory.createFace(remoteUri, localUri, persistency, wantLocalFieldsEnabled,
[expected] (const shared_ptr<Face>&) {
BOOST_CHECK_EQUAL(CreateFaceExpectedResult::SUCCESS, expected.result);
},
+15 -1
View File
@@ -172,6 +172,7 @@ BOOST_AUTO_TEST_CASE(FaceCreate)
createFace(factory,
FaceUri("tcp4://127.0.0.1:6363"),
{},
ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
false,
{CreateFaceExpectedResult::FAILURE, 504, "No channels available to connect"});
@@ -179,7 +180,8 @@ BOOST_AUTO_TEST_CASE(FaceCreate)
factory.createChannel("127.0.0.1", "20071");
createFace(factory,
FaceUri("tcp4://127.0.0.1:20070"),
FaceUri("tcp4://127.0.0.1:6363"),
{},
ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
false,
{CreateFaceExpectedResult::SUCCESS, 0, ""});
@@ -191,9 +193,11 @@ BOOST_AUTO_TEST_CASE(UnsupportedFaceCreate)
factory.createChannel("127.0.0.1", "20070");
factory.createChannel("127.0.0.1", "20071");
factory.createChannel("127.0.0.1", "20072");
createFace(factory,
FaceUri("tcp4://127.0.0.1:20070"),
{},
ndn::nfd::FACE_PERSISTENCY_PERMANENT,
false,
{CreateFaceExpectedResult::FAILURE, 406,
@@ -201,10 +205,19 @@ BOOST_AUTO_TEST_CASE(UnsupportedFaceCreate)
createFace(factory,
FaceUri("tcp4://127.0.0.1:20071"),
{},
ndn::nfd::FACE_PERSISTENCY_ON_DEMAND,
false,
{CreateFaceExpectedResult::FAILURE, 406,
"Outgoing TCP faces only support persistent persistency"});
createFace(factory,
FaceUri("tcp4://127.0.0.1:20072"),
FaceUri("udp4://127.0.0.1:20073"),
ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
false,
{CreateFaceExpectedResult::FAILURE, 406,
"Unicast TCP faces cannot be created with a LocalUri"});
}
class FaceCreateTimeoutFixture : public BaseFixture
@@ -240,6 +253,7 @@ BOOST_FIXTURE_TEST_CASE(FaceCreateTimeout, FaceCreateTimeoutFixture)
shared_ptr<TcpChannel> channel = factory.createChannel("0.0.0.0", "20070");
factory.createFace(FaceUri("tcp4://192.0.2.1:20070"),
{},
ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
false,
bind(&FaceCreateTimeoutFixture::onFaceCreated, this, _1),
+15 -1
View File
@@ -603,6 +603,7 @@ BOOST_AUTO_TEST_CASE(FaceCreate)
createFace(factory,
FaceUri("udp4://127.0.0.1:6363"),
{},
ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
false,
{CreateFaceExpectedResult::FAILURE, 504, "No channels available to connect"});
@@ -611,18 +612,21 @@ BOOST_AUTO_TEST_CASE(FaceCreate)
createFace(factory,
FaceUri("udp4://127.0.0.1:20070"),
{},
ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
false,
{CreateFaceExpectedResult::SUCCESS, 0, ""});
//test the upgrade
createFace(factory,
FaceUri("udp4://127.0.0.1:20070"),
{},
ndn::nfd::FACE_PERSISTENCY_PERMANENT,
false,
{CreateFaceExpectedResult::SUCCESS, 0, ""});
createFace(factory,
FaceUri("udp4://127.0.0.1:20072"),
{},
ndn::nfd::FACE_PERSISTENCY_PERMANENT,
false,
{CreateFaceExpectedResult::SUCCESS, 0, ""});
@@ -633,13 +637,23 @@ BOOST_AUTO_TEST_CASE(UnsupportedFaceCreate)
UdpFactory factory;
factory.createChannel("127.0.0.1", "20070");
factory.createChannel("127.0.0.1", "20071");
createFace(factory,
FaceUri("udp4://127.0.0.1:20070"),
{},
ndn::nfd::FACE_PERSISTENCY_ON_DEMAND,
false,
{CreateFaceExpectedResult::FAILURE, 406,
"Outgoing unicast UDP faces do not support on-demand persistency"});
createFace(factory,
FaceUri("udp4://127.0.0.1:20071"),
FaceUri("udp4://127.0.0.1:20073"),
ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
false,
{CreateFaceExpectedResult::FAILURE, 406,
"Unicast UDP faces cannot be created with a LocalUri"});
}
class FakeNetworkInterfaceFixture : public BaseFixture
@@ -137,18 +137,21 @@ BOOST_AUTO_TEST_CASE(UnsupportedFaceCreate)
createFace(factory,
FaceUri("unix:///var/run/nfd.sock"),
{},
ndn::nfd::FACE_PERSISTENCY_PERMANENT,
false,
{CreateFaceExpectedResult::FAILURE, 406, "Unsupported protocol"});
createFace(factory,
FaceUri("unix:///var/run/nfd.sock"),
{},
ndn::nfd::FACE_PERSISTENCY_ON_DEMAND,
false,
{CreateFaceExpectedResult::FAILURE, 406, "Unsupported protocol"});
createFace(factory,
FaceUri("unix:///var/run/nfd.sock"),
{},
ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
false,
{CreateFaceExpectedResult::FAILURE, 406, "Unsupported protocol"});
@@ -199,18 +199,21 @@ BOOST_AUTO_TEST_CASE(UnsupportedFaceCreate)
createFace(factory,
FaceUri("ws://127.0.0.1:20070"),
{},
ndn::nfd::FACE_PERSISTENCY_PERMANENT,
false,
{CreateFaceExpectedResult::FAILURE, 406, "Unsupported protocol"});
createFace(factory,
FaceUri("ws://127.0.0.1:20070"),
{},
ndn::nfd::FACE_PERSISTENCY_ON_DEMAND,
false,
{CreateFaceExpectedResult::FAILURE, 406, "Unsupported protocol"});
createFace(factory,
FaceUri("ws://127.0.0.1:20070"),
{},
ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
false,
{CreateFaceExpectedResult::FAILURE, 406, "Unsupported protocol"});
+2 -1
View File
@@ -259,7 +259,8 @@ public:
}
void
createFace(const FaceUri& uri,
createFace(const FaceUri& remoteUri,
const ndn::optional<FaceUri>& localUri,
ndn::nfd::FacePersistency persistency,
bool wantLocalFieldsEnabled,
const FaceCreatedCallback& onCreated,