Esempio n. 1
0
void
Forwarder::onIncomingInterest(Face& inFace, const Interest& interest)
{
  // receive Interest
  NFD_LOG_DEBUG("onIncomingInterest face=" << inFace.getId() <<
                " interest=" << interest.getName());
  const_cast<Interest&>(interest).setIncomingFaceId(inFace.getId());
  ++m_counters.getNInInterests();

  // /localhost scope control
  bool isViolatingLocalhost = !inFace.isLocal() &&
                              LOCALHOST_NAME.isPrefixOf(interest.getName());
  if (isViolatingLocalhost) {
    NFD_LOG_DEBUG("onIncomingInterest face=" << inFace.getId() <<
                  " interest=" << interest.getName() << " violates /localhost");
    // (drop)
    return;
  }

  // PIT insert
  shared_ptr<pit::Entry> pitEntry = m_pit.insert(interest).first;

  // detect duplicate Nonce
  int dnw = pitEntry->findNonce(interest.getNonce(), inFace);
  bool hasDuplicateNonce = (dnw != pit::DUPLICATE_NONCE_NONE) ||
                           m_deadNonceList.has(interest.getName(), interest.getNonce());
  if (hasDuplicateNonce) {
    // goto Interest loop pipeline
    this->onInterestLoop(inFace, interest, pitEntry);
    return;
  }

  // cancel unsatisfy & straggler timer
  this->cancelUnsatisfyAndStragglerTimer(pitEntry);

  // is pending?
  const pit::InRecordCollection& inRecords = pitEntry->getInRecords();
  bool isPending = inRecords.begin() != inRecords.end();
  if (!isPending) {
    if (m_csFromNdnSim == nullptr) {
      m_cs.find(interest,
                bind(&Forwarder::onContentStoreHit, this, ref(inFace), pitEntry, _1, _2),
                bind(&Forwarder::onContentStoreMiss, this, ref(inFace), pitEntry, _1));
    }
    else {
      shared_ptr<Data> match = m_csFromNdnSim->Lookup(interest.shared_from_this());
      if (match != nullptr) {
        this->onContentStoreHit(inFace, pitEntry, interest, *match);
      }
      else {
        this->onContentStoreMiss(inFace, pitEntry, interest);
      }
    }
  }
  else {
    this->onContentStoreMiss(inFace, pitEntry, interest);
  }
}
Esempio n. 2
0
static vector<string>
dumpInterest(const Interest& interest)
{
  vector<string> result;

  result.push_back(dump("name:", interest.getName().toUri()));
  result.push_back(dump("minSuffixComponents:",
    interest.getMinSuffixComponents() >= 0 ?
      toString(interest.getMinSuffixComponents()) : "<none>"));
  result.push_back(dump("maxSuffixComponents:",
    interest.getMaxSuffixComponents() >= 0 ?
      toString(interest.getMaxSuffixComponents()) : "<none>"));
  if ((int)interest.getKeyLocator().getType() >= 0) {
    if (interest.getKeyLocator().getType() == ndn_KeyLocatorType_KEY_LOCATOR_DIGEST)
      result.push_back(dump("keyLocator: KeyLocatorDigest:",
        interest.getKeyLocator().getKeyData().toHex()));
    else if (interest.getKeyLocator().getType() == ndn_KeyLocatorType_KEYNAME)
      result.push_back(dump("keyLocator: KeyName:",
        interest.getKeyLocator().getKeyName().toUri()));
    else
      result.push_back(dump("keyLocator: <unrecognized KeyLocatorType"));
  }
  else
    result.push_back(dump("keyLocator: <none>"));
  result.push_back(dump("exclude:",
    interest.getExclude().size() > 0 ? interest.getExclude().toUri() :
      "<none>"));
  result.push_back(dump("childSelector:",
    interest.getChildSelector() >= 0 ? toString(interest.getChildSelector()) :
      "<none>"));
  result.push_back(dump("mustBeFresh:",
    interest.getMustBeFresh() ? "True" : "False"));
  result.push_back(dump("nonce:",
    interest.getNonce().size() == 0 ? "<none>" :
      interest.getNonce().toHex()));
  result.push_back(dump("lifetimeMilliseconds:",
    interest.getInterestLifetimeMilliseconds() < 0 ? "<none>" :
      toString(interest.getInterestLifetimeMilliseconds())));

  return result;
};
static void dumpInterest(const Interest& interest)
{
  cout << "name: " << interest.getName().toUri() << endl;
  cout << "minSuffixComponents: ";
  if (interest.getMinSuffixComponents() >= 0)
    cout << interest.getMinSuffixComponents() << endl;
  else
    cout << "<none>" << endl;
  cout << "maxSuffixComponents: ";
  if (interest.getMaxSuffixComponents() >= 0)
    cout << interest.getMaxSuffixComponents() << endl;
  else
    cout << "<none>" << endl;
  cout << "keyLocator: ";
  if ((int)interest.getKeyLocator().getType() >= 0) {
    if (interest.getKeyLocator().getType() == ndn_KeyLocatorType_KEY_LOCATOR_DIGEST)
      cout << "KeyLocatorDigest: " << interest.getKeyLocator().getKeyData().toHex() << endl;
    else if (interest.getKeyLocator().getType() == ndn_KeyLocatorType_KEYNAME)
      cout << "KeyName: " << interest.getKeyLocator().getKeyName().toUri() << endl;
    else
      cout << "<unrecognized ndn_KeyLocatorType " << interest.getKeyLocator().getType() << ">" << endl;
  }
  else
    cout << "<none>" << endl;

  cout << "exclude: "
       << (interest.getExclude().size() > 0 ? interest.getExclude().toUri() : "<none>") << endl;
  cout << "lifetimeMilliseconds: ";
  if (interest.getInterestLifetimeMilliseconds() >= 0)
    cout << interest.getInterestLifetimeMilliseconds() << endl;
  else
    cout << "<none>" << endl;
  cout << "childSelector: ";
  if (interest.getChildSelector() >= 0)
    cout << interest.getChildSelector() << endl;
  else
    cout << "<none>" << endl;
  cout << "mustBeFresh: " << (interest.getMustBeFresh() ? "true" : "false") << endl;
  cout << "nonce: "
       << (interest.getNonce().size() > 0 ? interest.getNonce().toHex() : "<none>") << endl;
}
Esempio n. 4
0
void
Forwarder::onIncomingInterest(Face& inFace, const Interest& interest)
{
  // receive Interest
  NFD_LOG_DEBUG("onIncomingInterest face=" << inFace.getId() <<
                " interest=" << interest.getName());
  const_cast<Interest&>(interest).setIncomingFaceId(inFace.getId());
  ++m_counters.getNInInterests();

  // /localhost scope control
  bool isViolatingLocalhost = !inFace.isLocal() &&
                              LOCALHOST_NAME.isPrefixOf(interest.getName());
  if (isViolatingLocalhost) {
    NFD_LOG_DEBUG("onIncomingInterest face=" << inFace.getId() <<
                  " interest=" << interest.getName() << " violates /localhost");
    // (drop)
    return;
  }

  // PIT insert
  shared_ptr<pit::Entry> pitEntry = m_pit.insert(interest).first;

  // detect duplicate Nonce
  int dnw = pitEntry->findNonce(interest.getNonce(), inFace);
  bool hasDuplicateNonce = (dnw != pit::DUPLICATE_NONCE_NONE) ||
                           m_deadNonceList.has(interest.getName(), interest.getNonce());
  if (hasDuplicateNonce) {
    // goto Interest loop pipeline
    this->onInterestLoop(inFace, interest, pitEntry);
    return;
  }

  // cancel unsatisfy & straggler timer
  this->cancelUnsatisfyAndStragglerTimer(pitEntry);

  // is pending?
  const pit::InRecordCollection& inRecords = pitEntry->getInRecords();
  bool isPending = inRecords.begin() != inRecords.end();
  if (!isPending) {
    // CS lookup
    const Data* csMatch;
    shared_ptr<Data> match;
    if (m_csFromNdnSim == nullptr)
      csMatch = m_cs.find(interest);
    else {
      match = m_csFromNdnSim->Lookup(interest.shared_from_this());
      csMatch = match.get();
    }
    if (csMatch != 0) {
      const_cast<Data*>(csMatch)->setIncomingFaceId(FACEID_CONTENT_STORE);
      // XXX should we lookup PIT for other Interests that also match csMatch?

      // invoke PIT satisfy callback
      beforeSatisfyInterest(*pitEntry, *m_csFace, *csMatch);
      this->dispatchToStrategy(pitEntry, bind(&Strategy::beforeSatisfyInterest, _1,
                                              pitEntry, cref(*m_csFace), cref(*csMatch)));
      // set PIT straggler timer
      this->setStragglerTimer(pitEntry, true, csMatch->getFreshnessPeriod());

      // goto outgoing Data pipeline
      this->onOutgoingData(*csMatch, inFace);
      return;
    }
  }

  // insert InRecord
  pitEntry->insertOrUpdateInRecord(inFace.shared_from_this(), interest);

  // set PIT unsatisfy timer
  this->setUnsatisfyTimer(pitEntry);

  // FIB lookup
  shared_ptr<fib::Entry> fibEntry = m_fib.findLongestPrefixMatch(*pitEntry);

  // dispatch to strategy
  this->dispatchToStrategy(pitEntry, bind(&Strategy::afterReceiveInterest, _1,
                                          cref(inFace), cref(interest), fibEntry, pitEntry));
}
Esempio n. 5
0
TEST_F(TestInterestMethods, EmptyNonce)
{
  // make sure a freshly created interest has no nonce
  Interest freshInterest = createFreshInterest();
  ASSERT_TRUE(freshInterest.getNonce().isNull()) << "Freshly created interest should not have a nonce";
}