void FibHelper::AddRoute(Ptr<Node> node, const Name& prefix, shared_ptr<Face> face, int32_t metric) { NS_LOG_LOGIC("[" << node->GetId() << "]$ route add " << prefix << " via " << face->getLocalUri() << " metric " << metric); ControlParameters parameters; parameters.setName(prefix); parameters.setFaceId(face->getId()); parameters.setCost(metric); AddNextHop(parameters, node); }
void Nfdc::strategyChoiceUnset() { const std::string& name = m_commandLineArguments[0]; ControlParameters parameters; parameters.setName(name); m_controller.start<StrategyChoiceUnsetCommand>(parameters, bind(&Nfdc::onSuccess, this, _1, "Successfully unset strategy choice"), bind(&Nfdc::onError, this, _1, _2, "Failed to unset strategy choice")); }
void FibHelper::RemoveRoute(Ptr<Node> node, const Name& prefix, shared_ptr<Face> face) { // Get L3Protocol object Ptr<L3Protocol> L3protocol = node->GetObject<L3Protocol>(); // Get the forwarder instance shared_ptr<nfd::Forwarder> m_forwarder = L3protocol->getForwarder(); ControlParameters parameters; parameters.setName(prefix); parameters.setFaceId(face->getId()); RemoveNextHop(parameters, node); }
void RemoteRegistrator::redoRegistration() { NFD_LOG_INFO("redo " << m_regEntries.size() << " registration when new Hub connection is built."); for (auto&& entry : m_regEntries) { // make copies to avoid unreasonable overwrite. ControlParameters parameters = m_controlParameters; CommandOptions options = m_commandOptions; startRegistration(parameters.setName(entry.first), options.setSigningIdentity(entry.first), m_nRetries); } }
void FibHelper::AddRoute(Ptr<Node> node, const Name& prefix, shared_ptr<Face> face, int32_t metric) { NS_LOG_LOGIC("[" << node->GetId() << "]$ route add " << prefix << " via " << face->getLocalUri() << " metric " << metric); // Get L3Protocol object Ptr<L3Protocol> L3protocol = node->GetObject<L3Protocol>(); // Get the forwarder instance shared_ptr<nfd::Forwarder> m_forwarder = L3protocol->getForwarder(); ControlParameters parameters; parameters.setName(prefix); parameters.setFaceId(face->getId()); parameters.setCost(metric); AddNextHop(parameters, node); }
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()); }
const RegisteredPrefixId* registerPrefix(const Name& prefix, const shared_ptr<InterestFilterRecord>& filter, const RegisterPrefixSuccessCallback& onSuccess, const RegisterPrefixFailureCallback& onFailure, uint64_t flags, const nfd::CommandOptions& options) { using namespace nfd; ControlParameters params; params.setName(prefix); params.setFlags(flags); auto prefixToRegister = make_shared<RegisteredPrefix>(prefix, filter, options); m_face.m_nfdController->start<RibRegisterCommand>(params, bind(&Impl::afterPrefixRegistered, this, prefixToRegister, onSuccess), bind(onFailure, prefixToRegister->getPrefix(), _2), options); return reinterpret_cast<const RegisteredPrefixId*>(prefixToRegister.get()); }
void RemoteRegistrator::unregisterPrefix(const Name& prefix) { if (prefix == REMOTE_HUB_PREFIX) { NFD_LOG_INFO("disconnected to hub with prefix: " << prefix); // for phase 1: suppose there is at most one hub connected. // if the hub prefix has been unregistered locally, there may // be no connected hub. m_hasConnectedHub = false; clearRefreshEvents(); return; } if (!m_hasConnectedHub) { NFD_LOG_INFO("no hub connected when unregistering " << prefix); return; } std::pair<Name, size_t> identity = findIdentityForRegistration(prefix); if (0 == identity.second) { NFD_LOG_INFO("no proper identity found for unregistering " << prefix); return; } Name prefixForRegistration; if (identity.first.size() == identity.second) { prefixForRegistration = identity.first; } else { prefixForRegistration = identity.first.getPrefix(-1); } RegisteredEntryIt iRegEntry = m_regEntries.find(prefixForRegistration); if (m_regEntries.end() == iRegEntry) { NFD_LOG_INFO("no existing entry found when unregistering " << prefix); return; } for (auto&& entry : m_rib) { if (prefixForRegistration.isPrefixOf(entry.first) && findIdentityForRegistration(entry.first) == identity) { NFD_LOG_INFO("this identity should be kept for other rib entry: " << entry.first); return; } } scheduler::cancel(iRegEntry->second); m_regEntries.erase(iRegEntry); // make copies of m_controlParameters and m_commandOptions to // avoid unreasonable overwriting during concurrent registration // and unregistration. ControlParameters parameters = m_controlParameters; CommandOptions options = m_commandOptions; startUnregistration(parameters.setName(prefixForRegistration).unsetCost(), options.setSigningIdentity(identity.first), m_nRetries); }
void RemoteRegistrator::registerPrefix(const Name& prefix) { if (LOCAL_REGISTRATION_PREFIX.isPrefixOf(prefix)) { NFD_LOG_INFO("local registration only for " << prefix); return; } bool isHubPrefix = prefix == REMOTE_HUB_PREFIX; if (isHubPrefix) { NFD_LOG_INFO("this is a prefix registered by some hub: " << prefix); m_hasConnectedHub = true; redoRegistration(); return; } if (!m_hasConnectedHub) { NFD_LOG_INFO("no hub connected when registering " << prefix); return; } std::pair<Name, size_t> identity = findIdentityForRegistration(prefix); if (0 == identity.second) { NFD_LOG_INFO("no proper identity found for registering " << prefix); return; } Name prefixForRegistration; if (identity.first.size() == identity.second) { prefixForRegistration = identity.first; } else { prefixForRegistration = identity.first.getPrefix(-1); } if (m_regEntries.find(prefixForRegistration) != m_regEntries.end()) { NFD_LOG_INFO("registration already in process for " << prefix); return; } // make copies of m_controlParameters and m_commandOptions to // avoid unreasonable overwriting during concurrent registration // and unregistration. ControlParameters parameters = m_controlParameters; CommandOptions options = m_commandOptions; startRegistration(parameters.setName(prefixForRegistration), options.setSigningIdentity(identity.first), m_nRetries); }
void Node::nfdRegisterPrefix (uint64_t registeredPrefixId, const ptr_lib::shared_ptr<const Name>& prefix, const OnInterestCallback& onInterest, const OnRegisterFailed& onRegisterFailed, const ForwardingFlags& flags, KeyChain& commandKeyChain, const Name& commandCertificateName, WireFormat& wireFormat, Face* face) { if (!&commandKeyChain) throw runtime_error ("registerPrefix: The command KeyChain has not been set. You must call setCommandSigningInfo."); if (commandCertificateName.size() == 0) throw runtime_error ("registerPrefix: The command certificate name has not been set. You must call setCommandSigningInfo."); ControlParameters controlParameters; controlParameters.setName(*prefix); controlParameters.setForwardingFlags(flags); ptr_lib::shared_ptr<Interest> commandInterest(new Interest()); if (isLocal()) { commandInterest->setName(Name("/localhost/nfd/rib/register")); // The interest is answered by the local host, so set a short timeout. commandInterest->setInterestLifetimeMilliseconds(2000.0); } else { commandInterest->setName(Name("/localhop/nfd/rib/register")); // The host is remote, so set a longer timeout. commandInterest->setInterestLifetimeMilliseconds(4000.0); } // NFD only accepts TlvWireFormat packets. commandInterest->getName().append (controlParameters.wireEncode(*TlvWireFormat::get())); makeCommandInterest (*commandInterest, commandKeyChain, commandCertificateName, *TlvWireFormat::get()); if (registeredPrefixId != 0) { uint64_t interestFilterId = 0; if (onInterest) { // registerPrefix was called with the "combined" form that includes the // callback, so add an InterestFilterEntry. interestFilterId = getNextEntryId(); setInterestFilter (interestFilterId, ptr_lib::make_shared<const InterestFilter>(*prefix), onInterest, face); } registeredPrefixTable_.push_back (ptr_lib::shared_ptr<RegisteredPrefix>(new RegisteredPrefix (registeredPrefixId, prefix, interestFilterId))); } // Send the registration interest. RegisterResponse response (ptr_lib::shared_ptr<RegisterResponse::Info>(new RegisterResponse::Info (this, prefix, onInterest, onRegisterFailed, flags, wireFormat, face))); // It is OK for func_lib::function make a copy of the function object because // the Info is in a ptr_lib::shared_ptr. expressInterest (getNextEntryId(), commandInterest, response, response, wireFormat, face); }