BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceId, AuthorizedCommandFixture<LocalControlFixture>) { shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>(); BOOST_REQUIRE(dummy->isLocal()); FaceTableFixture::m_faceTable.add(dummy); ControlParameters parameters; parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID); Block encodedParameters(parameters.wireEncode()); Name enable("/localhost/nfd/faces/enable-local-control"); enable.append(encodedParameters); shared_ptr<Interest> enableCommand(make_shared<Interest>(enable)); enableCommand->setIncomingFaceId(dummy->getId()); generateCommand(*enableCommand); TestFaceManagerCommon::m_face->onReceiveData += [this, enableCommand, encodedParameters] (const Data& response) { this->validateControlResponse(response, enableCommand->getName(), 200, "Success", encodedParameters); }; onValidatedFaceRequest(enableCommand); BOOST_REQUIRE(didCallbackFire()); BOOST_REQUIRE(dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); TestFaceManagerCommon::m_face->onReceiveData.clear(); resetCallbackFired(); Name disable("/localhost/nfd/faces/disable-local-control"); disable.append(encodedParameters); shared_ptr<Interest> disableCommand(make_shared<Interest>(disable)); disableCommand->setIncomingFaceId(dummy->getId()); generateCommand(*disableCommand); TestFaceManagerCommon::m_face->onReceiveData += [this, disableCommand, encodedParameters] (const Data& response) { this->validateControlResponse(response, disableCommand->getName(), 200, "Success", encodedParameters); }; onValidatedFaceRequest(disableCommand); BOOST_REQUIRE(didCallbackFire()); BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); }
BOOST_FIXTURE_TEST_CASE(DestroyFace, AuthorizedCommandFixture<FaceFixture>) { shared_ptr<DummyFace> dummy(make_shared<DummyFace>()); FaceTableFixture::m_faceTable.add(dummy); ControlParameters parameters; parameters.setFaceId(dummy->getId()); Block encodedParameters(parameters.wireEncode()); Name commandName("/localhost/nfd/faces"); commandName.append("destroy"); commandName.append(encodedParameters); shared_ptr<Interest> command(make_shared<Interest>(commandName)); generateCommand(*command); ndn::nfd::FaceEventNotification expectedFaceEvent; expectedFaceEvent.setKind(ndn::nfd::FACE_EVENT_DESTROYED) .setFaceId(dummy->getId()) .setRemoteUri(dummy->getRemoteUri().toString()) .setLocalUri(dummy->getLocalUri().toString()) .setFlags(0); getFace()->onReceiveData += bind(&FaceFixture::callbackDispatch, this, _1, command->getName(), 200, "Success", ref(encodedParameters), expectedFaceEvent); destroyFace(*command, parameters); BOOST_REQUIRE(didCallbackFire()); BOOST_REQUIRE(didReceiveNotication()); }
BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceIdNonLocal, AuthorizedCommandFixture<LocalControlFixture>) { shared_ptr<DummyFace> dummy = make_shared<DummyFace>(); BOOST_REQUIRE(!dummy->isLocal()); FaceTableFixture::m_faceTable.add(dummy); ControlParameters parameters; parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID); Block encodedParameters(parameters.wireEncode()); Name enable("/localhost/nfd/faces/enable-local-control"); enable.append(encodedParameters); shared_ptr<Interest> enableCommand(make_shared<Interest>(enable)); enableCommand->setIncomingFaceId(dummy->getId()); generateCommand(*enableCommand); TestFaceManagerCommon::m_face->onReceiveData += bind(&LocalControlFixture::validateControlResponse, this, _1, enableCommand->getName(), 412, "Face is non-local"); onValidatedFaceRequest(enableCommand); BOOST_REQUIRE(didCallbackFire()); TestFaceManagerCommon::m_face->onReceiveData.clear(); resetCallbackFired(); Name disable("/localhost/nfd/faces/disable-local-control"); disable.append(encodedParameters); shared_ptr<Interest> disableCommand(make_shared<Interest>(disable)); disableCommand->setIncomingFaceId(dummy->getId()); generateCommand(*disableCommand); TestFaceManagerCommon::m_face->onReceiveData += bind(&LocalControlFixture::validateControlResponse, this, _1, disableCommand->getName(), 412, "Face is non-local"); onValidatedFaceRequest(disableCommand); BOOST_REQUIRE(didCallbackFire()); }
BOOST_FIXTURE_TEST_CASE(MalformedCommmand, AllStrategiesFixture) { shared_ptr<Interest> command(make_shared<Interest>("/localhost/nfd/strategy-choice")); getFace()->onReceiveData += bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1, command->getName(), 400, "Malformed command"); getManager().onStrategyChoiceRequest(*command); BOOST_REQUIRE(didCallbackFire()); }
BOOST_FIXTURE_TEST_CASE(ValidatedFaceRequestBadOptionParse, AuthorizedCommandFixture<ValidatedFaceRequestFixture>) { Name commandName("/localhost/nfd/faces"); commandName.append("create"); commandName.append("NotReallyParameters"); shared_ptr<Interest> command(make_shared<Interest>(commandName)); generateCommand(*command); getFace()->onReceiveData += bind(&ValidatedFaceRequestFixture::validateControlResponse, this, _1, command->getName(), 400, "Malformed command"); onValidatedFaceRequest(command); BOOST_REQUIRE(didCallbackFire()); }
BOOST_FIXTURE_TEST_CASE(OnCreated, AuthorizedCommandFixture<FaceFixture>) { ControlParameters parameters; parameters.setUri("tcp://127.0.0.1"); Block encodedParameters(parameters.wireEncode()); Name commandName("/localhost/nfd/faces"); commandName.append("create"); commandName.append(encodedParameters); shared_ptr<Interest> command(make_shared<Interest>(commandName)); generateCommand(*command); ControlParameters resultParameters; resultParameters.setUri("dummy://"); resultParameters.setFaceId(FACEID_RESERVED_MAX + 1); shared_ptr<DummyFace> dummy(make_shared<DummyFace>()); ndn::nfd::FaceEventNotification expectedFaceEvent; expectedFaceEvent.setKind(ndn::nfd::FACE_EVENT_CREATED) .setFaceId(FACEID_RESERVED_MAX + 1) .setRemoteUri(dummy->getRemoteUri().toString()) .setLocalUri(dummy->getLocalUri().toString()) .setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL) .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT); Block encodedResultParameters(resultParameters.wireEncode()); getFace()->onReceiveData += [this, command, encodedResultParameters, expectedFaceEvent] (const Data& response) { this->callbackDispatch(response,command->getName(), 200, "Success", encodedResultParameters, expectedFaceEvent); }; onCreated(command->getName(), parameters, dummy); BOOST_REQUIRE(didCallbackFire()); BOOST_REQUIRE(didReceiveNotication()); }
BOOST_FIXTURE_TEST_CASE(UnsupportedCommand, AuthorizedCommandFixture<FaceManagerFixture>) { ControlParameters parameters; Block encodedParameters(parameters.wireEncode()); Name commandName("/localhost/nfd/faces"); commandName.append("unsupported"); commandName.append(encodedParameters); shared_ptr<Interest> command(make_shared<Interest>(commandName)); generateCommand(*command); getFace()->onReceiveData += bind(&FaceManagerFixture::validateControlResponse, this, _1, command->getName(), 501, "Unsupported command"); getManager().onFaceRequest(*command); BOOST_REQUIRE(didCallbackFire()); }
BOOST_FIXTURE_TEST_CASE(CreateFaceMissingUri, AuthorizedCommandFixture<FaceFixture>) { ControlParameters parameters; Block encodedParameters(parameters.wireEncode()); Name commandName("/localhost/nfd/faces"); commandName.append("create"); commandName.append(encodedParameters); shared_ptr<Interest> command(make_shared<Interest>(commandName)); generateCommand(*command); getFace()->onReceiveData += bind(&FaceFixture::validateControlResponse, this, _1, command->getName(), 400, "Malformed command"); createFace(*command, parameters); BOOST_REQUIRE(didCallbackFire()); }
BOOST_FIXTURE_TEST_CASE(OnCreated, AuthorizedCommandFixture<FaceFixture>) { ControlParameters parameters; parameters.setUri("tcp://127.0.0.1"); Block encodedParameters(parameters.wireEncode()); Name commandName("/localhost/nfd/faces"); commandName.append("create"); commandName.append(encodedParameters); shared_ptr<Interest> command(make_shared<Interest>(commandName)); generateCommand(*command); ControlParameters resultParameters; resultParameters.setUri("tcp://127.0.0.1"); resultParameters.setFaceId(1); shared_ptr<DummyFace> dummy(make_shared<DummyFace>()); ndn::nfd::FaceEventNotification expectedFaceEvent; expectedFaceEvent.setKind(ndn::nfd::FACE_EVENT_CREATED) .setFaceId(1) .setRemoteUri(dummy->getRemoteUri().toString()) .setLocalUri(dummy->getLocalUri().toString()) .setFlags(0); Block encodedResultParameters(resultParameters.wireEncode()); getFace()->onReceiveData += bind(&FaceFixture::callbackDispatch, this, _1, command->getName(), 200, "Success", encodedResultParameters, expectedFaceEvent); onCreated(command->getName(), parameters, dummy); BOOST_REQUIRE(didCallbackFire()); BOOST_REQUIRE(didReceiveNotication()); }
BOOST_FIXTURE_TEST_CASE(CreateFaceBadUri, AuthorizedCommandFixture<FaceFixture>) { ControlParameters parameters; parameters.setUri("tcp:/127.0.0.1"); Block encodedParameters(parameters.wireEncode()); Name commandName("/localhost/nfd/faces"); commandName.append("create"); commandName.append(encodedParameters); shared_ptr<Interest> command(make_shared<Interest>(commandName)); generateCommand(*command); getFace()->onReceiveData += [this, command] (const Data& response) { this->validateControlResponse(response, command->getName(), 400, "Malformed command"); }; createFace(*command, parameters); BOOST_REQUIRE(didCallbackFire()); }
BOOST_FIXTURE_TEST_CASE(UnsignedCommand, AllStrategiesFixture) { ControlParameters parameters; parameters.setName("/test"); parameters.setStrategy("/localhost/nfd/strategy/best-route"); Block encodedParameters(parameters.wireEncode()); Name commandName("/localhost/nfd/strategy-choice"); commandName.append("set"); commandName.append(encodedParameters); shared_ptr<Interest> command(make_shared<Interest>(commandName)); getFace()->onReceiveData += bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1, command->getName(), 401, "Signature required"); getManager().onStrategyChoiceRequest(*command); BOOST_REQUIRE(didCallbackFire()); }
BOOST_FIXTURE_TEST_CASE(OnConnectFailed, AuthorizedCommandFixture<FaceFixture>) { ControlParameters parameters; parameters.setUri("tcp://127.0.0.1"); Block encodedParameters(parameters.wireEncode()); Name commandName("/localhost/nfd/faces"); commandName.append("create"); commandName.append(encodedParameters); shared_ptr<Interest> command(make_shared<Interest>(commandName)); generateCommand(*command); getFace()->onReceiveData += bind(&FaceFixture::validateControlResponse, this, _1, command->getName(), 408, "unit-test-reason"); onConnectFailed(command->getName(), "unit-test-reason"); BOOST_REQUIRE(didCallbackFire()); BOOST_CHECK_EQUAL(didReceiveNotication(), false); }
BOOST_FIXTURE_TEST_CASE(CreateFaceUnknownScheme, AuthorizedCommandFixture<FaceFixture>) { ControlParameters parameters; // this will be an unsupported protocol because no factories have been // added to the face manager parameters.setUri("tcp://127.0.0.1"); Block encodedParameters(parameters.wireEncode()); Name commandName("/localhost/nfd/faces"); commandName.append("create"); commandName.append(encodedParameters); shared_ptr<Interest> command(make_shared<Interest>(commandName)); generateCommand(*command); getFace()->onReceiveData += bind(&FaceFixture::validateControlResponse, this, _1, command->getName(), 501, "Unsupported protocol"); createFace(*command, parameters); BOOST_REQUIRE(didCallbackFire()); }
BOOST_FIXTURE_TEST_CASE(DestroyFace, AuthorizedCommandFixture<FaceFixture>) { shared_ptr<DummyFace> dummy(make_shared<DummyFace>()); FaceTableFixture::m_faceTable.add(dummy); ControlParameters parameters; parameters.setFaceId(dummy->getId()); Block encodedParameters(parameters.wireEncode()); Name commandName("/localhost/nfd/faces"); commandName.append("destroy"); commandName.append(encodedParameters); shared_ptr<Interest> command(make_shared<Interest>(commandName)); generateCommand(*command); ndn::nfd::FaceEventNotification expectedFaceEvent; expectedFaceEvent.setKind(ndn::nfd::FACE_EVENT_DESTROYED) .setFaceId(dummy->getId()) .setRemoteUri(dummy->getRemoteUri().toString()) .setLocalUri(dummy->getLocalUri().toString()) .setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL) .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT); getFace()->onReceiveData += [this, command, encodedParameters, expectedFaceEvent] (const Data& response) { this->callbackDispatch(response,command->getName(), 200, "Success", encodedParameters, expectedFaceEvent); }; destroyFace(*command, parameters); BOOST_REQUIRE(didCallbackFire()); BOOST_REQUIRE(didReceiveNotication()); }