/* * Construct instance of service installation command, parsing all arguments */ InstallCommand::InstallCommand(const char* _serviceName, int servArgc, char* servArgv[]) : ServiceCommand(_serviceName) , serviceParameters(NULL) , parametersValid(false) { parametersValid = validateParameters(servArgc, servArgv); }
bool FaceManager::extractLocalControlParameters(const Interest& request, ControlParameters& parameters, ControlCommand& command, shared_ptr<LocalFace>& outFace, LocalControlFeature& outFeature) { if (!validateParameters(command, parameters)) { sendResponse(request.getName(), 400, "Malformed command"); return false; } shared_ptr<Face> face = m_faceTable.get(request.getIncomingFaceId()); if (!static_cast<bool>(face)) { NFD_LOG_DEBUG("command result: faceid " << request.getIncomingFaceId() << " not found"); sendResponse(request.getName(), 410, "Face not found"); return false; } else if (!face->isLocal()) { NFD_LOG_DEBUG("command result: cannot enable local control on non-local faceid " << face->getId()); sendResponse(request.getName(), 412, "Face is non-local"); return false; } outFace = dynamic_pointer_cast<LocalFace>(face); outFeature = static_cast<LocalControlFeature>(parameters.getLocalControlFeature()); return true; }
void StrategyChoiceManager::unsetStrategy(ControlParameters& parameters, ControlResponse& response) { ndn::nfd::StrategyChoiceUnsetCommand command; if (!validateParameters(command, parameters)) { static const Name ROOT_PREFIX; if (parameters.hasName() && parameters.getName() == ROOT_PREFIX) { NFD_LOG_DEBUG("strategy-choice result: FAIL reason: unset-root"); setResponse(response, 403, "Cannot unset root prefix strategy"); } else { NFD_LOG_DEBUG("strategy-choice result: FAIL reason: malformed"); setResponse(response, 400, "Malformed command"); } return; } m_strategyChoice.erase(parameters.getName()); NFD_LOG_DEBUG("strategy-choice result: SUCCESS"); setResponse(response, 200, "Success", parameters.wireEncode()); }
void StrategyChoiceManager::setStrategy(ControlParameters& parameters, ControlResponse& response) { ndn::nfd::StrategyChoiceSetCommand command; if (!validateParameters(command, parameters)) { NFD_LOG_DEBUG("strategy-choice result: FAIL reason: malformed"); setResponse(response, 400, "Malformed command"); return; } const Name& prefix = parameters.getName(); const Name& selectedStrategy = parameters.getStrategy(); if (!m_strategyChoice.hasStrategy(selectedStrategy)) { NFD_LOG_DEBUG("strategy-choice result: FAIL reason: unknown-strategy: " << parameters.getStrategy()); setResponse(response, 504, "Unsupported strategy"); return; } if (m_strategyChoice.insert(prefix, selectedStrategy)) { NFD_LOG_DEBUG("strategy-choice result: SUCCESS"); setResponse(response, 200, "Success", parameters.wireEncode()); } else { NFD_LOG_DEBUG("strategy-choice result: FAIL reason: not-installed"); setResponse(response, 405, "Strategy not installed"); } }
void RibManager::unregisterEntry(const shared_ptr<const Interest>& request, ControlParameters& params) { ndn::nfd::RibUnregisterCommand command; // Passing all parameters gives error in validation, // so passing only the required arguments. ControlParameters parameters; parameters.setName(params.getName()); if (params.hasFaceId()) { parameters.setFaceId(params.getFaceId()); } if (params.hasOrigin()) { parameters.setOrigin(params.getOrigin()); } if (!validateParameters(command, parameters)) { NFD_LOG_DEBUG("unregister result: FAIL reason: malformed"); if (static_cast<bool>(request)) { sendResponse(request->getName(), 400, "Malformed command"); } return; } bool isSelfRegistration = (!parameters.hasFaceId() || parameters.getFaceId() == 0); if (isSelfRegistration) { shared_ptr<lp::IncomingFaceIdTag> incomingFaceIdTag = request->getTag<lp::IncomingFaceIdTag>(); if (incomingFaceIdTag == nullptr) { sendResponse(request->getName(), 503, "requested self-registration, but IncomingFaceId is unavailable"); return; } parameters.setFaceId(*incomingFaceIdTag); } // Respond since command is valid and authorized sendSuccessResponse(request, parameters); Route route; route.faceId = parameters.getFaceId(); route.origin = parameters.getOrigin(); NFD_LOG_INFO("Removing route " << parameters.getName() << " nexthop=" << route.faceId << " origin=" << route.origin); RibUpdate update; update.setAction(RibUpdate::UNREGISTER) .setName(parameters.getName()) .setRoute(route); m_managedRib.beginApplyUpdate(update, bind(&RibManager::onRibUpdateSuccess, this, update), bind(&RibManager::onRibUpdateFailure, this, update, _1, _2)); }
void DynamicRandomDots::load(shared_ptr<StimulusDisplay> display) { if (loaded) return; validateParameters(); computeDotSizeInPixels(display); initializeDots(); loaded = true; }
void FibManager::removeNextHop(ControlParameters& parameters, ControlResponse& response) { ndn::nfd::FibRemoveNextHopCommand command; if (!validateParameters(command, parameters)) { NFD_LOG_DEBUG("remove-nexthop result: FAIL reason: malformed"); setResponse(response, 400, "Malformed command"); return; } NFD_LOG_TRACE("remove-nexthop prefix: " << parameters.getName() << " faceid: " << parameters.getFaceId()); shared_ptr<Face> faceToRemove = m_getFace(parameters.getFaceId()); if (static_cast<bool>(faceToRemove)) { shared_ptr<fib::Entry> entry = m_managedFib.findExactMatch(parameters.getName()); if (static_cast<bool>(entry)) { entry->removeNextHop(faceToRemove); NFD_LOG_DEBUG("remove-nexthop result: OK prefix: " << parameters.getName() << " faceid: " << parameters.getFaceId()); if (!entry->hasNextHops()) { m_managedFib.erase(*entry); } } else { NFD_LOG_DEBUG("remove-nexthop result: OK, but entry for face id " << parameters.getFaceId() << " not found"); } } else { NFD_LOG_DEBUG("remove-nexthop result: OK, but face id " << parameters.getFaceId() << " not found"); } setResponse(response, 200, "Success", parameters.wireEncode()); }
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(); } }
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 FibManager::addNextHop(ControlParameters& parameters, ControlResponse& response) { ndn::nfd::FibAddNextHopCommand command; if (!validateParameters(command, parameters)) { NFD_LOG_DEBUG("add-nexthop result: FAIL reason: malformed"); setResponse(response, 400, "Malformed command"); return; } const Name& prefix = parameters.getName(); FaceId faceId = parameters.getFaceId(); uint64_t cost = parameters.getCost(); NFD_LOG_TRACE("add-nexthop prefix: " << prefix << " faceid: " << faceId << " cost: " << cost); shared_ptr<Face> nextHopFace = m_getFace(faceId); if (static_cast<bool>(nextHopFace)) { shared_ptr<fib::Entry> entry = m_managedFib.insert(prefix).first; entry->addNextHop(nextHopFace, cost); NFD_LOG_DEBUG("add-nexthop result: OK" << " prefix:" << prefix << " faceid: " << faceId << " cost: " << cost); setResponse(response, 200, "Success", parameters.wireEncode()); } else { NFD_LOG_DEBUG("add-nexthop result: FAIL reason: unknown-faceid: " << faceId); setResponse(response, 410, "Face not found"); } }
void FaceManager::destroyFace(const Interest& request, ControlParameters& parameters) { const Name& requestName = request.getName(); ndn::nfd::FaceDestroyCommand command; if (!validateParameters(command, parameters)) { sendResponse(requestName, 400, "Malformed command"); return; } shared_ptr<Face> target = m_faceTable.get(parameters.getFaceId()); if (static_cast<bool>(target)) { target->close(); } sendResponse(requestName, 200, "Success", parameters.wireEncode()); }
int HarnessTestExecutor :: execute (InfoForExecutor &ir) { time_t rawtime; time ( &rawtime ); std::string nowStr(ctime (&rawtime)); nowStr = nowStr.substr(0,nowStr.size()-1); // remove newline if (strcasecmp (ir.logDestination.c_str (), LOGDESTINATION_CONSOLE) != 0) { cout << "[" << ir.test_sequence_number << "][" << nowStr << "]: " << "[start] " << ir.testID << std::endl; } copyToLocal (ir); if (validateParameters () == FAILURE) return FAILURE; createLogger (); //print_executor_environment (); if (prepareShellscript () == FAILURE) { LOG4CXX_INFO (_logger, "EXECUTOR returning FAILURE to the caller."); return FAILURE; } if (executeTestCase () == FAILURE) { LOG4CXX_INFO (_logger, "EXECUTOR returning FAILURE to the caller."); return FAILURE; } LOG4CXX_INFO (_logger, "EXECUTOR returning SUCCESS to the caller."); return SUCCESS; }
void FaceManager::createFace(const Interest& request, ControlParameters& parameters) { const Name& requestName = request.getName(); ndn::nfd::FaceCreateCommand command; if (!validateParameters(command, parameters)) { sendResponse(requestName, 400, "Malformed command"); NFD_LOG_TRACE("invalid control parameters URI"); return; } FaceUri uri; if (!uri.parse(parameters.getUri())) { sendResponse(requestName, 400, "Malformed command"); NFD_LOG_TRACE("failed to parse URI"); return; } if (!uri.isCanonical()) { sendResponse(requestName, 400, "Non-canonical URI"); NFD_LOG_TRACE("received non-canonical URI"); return; } FactoryMap::iterator factory = m_factories.find(uri.getScheme()); if (factory == m_factories.end()) { sendResponse(requestName, 501, "Unsupported protocol"); return; } try { factory->second->createFace(uri, bind(&FaceManager::onCreated, this, requestName, parameters, _1), bind(&FaceManager::onConnectFailed, this, requestName, _1)); } catch (const std::runtime_error& error) { std::string errorMessage = "NFD error: "; errorMessage += error.what(); NFD_LOG_ERROR(errorMessage); sendResponse(requestName, 500, errorMessage); } catch (const std::logic_error& error) { std::string errorMessage = "NFD error: "; errorMessage += error.what(); NFD_LOG_ERROR(errorMessage); sendResponse(requestName, 500, errorMessage); } }
void RibManager::registerEntry(const shared_ptr<const Interest>& request, ControlParameters& parameters) { ndn::nfd::RibRegisterCommand command; if (!validateParameters(command, parameters)) { NFD_LOG_DEBUG("register result: FAIL reason: malformed"); if (static_cast<bool>(request)) { sendResponse(request->getName(), 400, "Malformed command"); } return; } bool isSelfRegistration = (!parameters.hasFaceId() || parameters.getFaceId() == 0); if (isSelfRegistration) { shared_ptr<lp::IncomingFaceIdTag> incomingFaceIdTag = request->getTag<lp::IncomingFaceIdTag>(); if (incomingFaceIdTag == nullptr) { sendResponse(request->getName(), 503, "requested self-registration, but IncomingFaceId is unavailable"); return; } parameters.setFaceId(*incomingFaceIdTag); } // Respond since command is valid and authorized sendSuccessResponse(request, parameters); Route route; route.faceId = parameters.getFaceId(); route.origin = parameters.getOrigin(); route.cost = parameters.getCost(); route.flags = parameters.getFlags(); if (parameters.hasExpirationPeriod() && parameters.getExpirationPeriod() != time::milliseconds::max()) { route.expires = time::steady_clock::now() + parameters.getExpirationPeriod(); // Schedule a new event, the old one will be cancelled during rib insertion. scheduler::EventId eventId = scheduler::schedule(parameters.getExpirationPeriod(), bind(&Rib::onRouteExpiration, &m_managedRib, parameters.getName(), route)); NFD_LOG_TRACE("Scheduled unregistration at: " << route.expires << " with EventId: " << eventId); // Set the NewEventId of this entry route.setExpirationEvent(eventId); } else { route.expires = time::steady_clock::TimePoint::max(); } NFD_LOG_INFO("Adding route " << parameters.getName() << " nexthop=" << route.faceId << " origin=" << route.origin << " cost=" << route.cost); RibUpdate update; update.setAction(RibUpdate::REGISTER) .setName(parameters.getName()) .setRoute(route); m_managedRib.beginApplyUpdate(update, bind(&RibManager::onRibUpdateSuccess, this, update), bind(&RibManager::onRibUpdateFailure, this, update, _1, _2)); m_registeredFaces.insert(route.faceId); }