Esempio n. 1
0
  // After we create a new Face, we need to set it up for use. This
  // function sets the controlling strategy, registers prefixes in
  // sync, broadcast, and LSA.
void
HelloProtocol::onRegistrationSuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
                                     const ndn::Name& neighbor,const ndn::time::milliseconds& timeout)
{
  Adjacent *adjacent = m_nlsr.getAdjacencyList().findAdjacent(neighbor);
  if (adjacent != 0) {
    adjacent->setFaceId(commandSuccessResult.getFaceId());
    ndn::Name broadcastKeyPrefix = DEFAULT_BROADCAST_PREFIX;
    broadcastKeyPrefix.append("KEYS");
    std::string faceUri = adjacent->getConnectingFaceUri();
    double linkCost = adjacent->getLinkCost();
    m_nlsr.getFib().registerPrefix(m_nlsr.getConfParameter().getChronosyncPrefix(),
                                 faceUri, linkCost, timeout,
                                 ndn::nfd::ROUTE_FLAG_CAPTURE, 0);
    m_nlsr.getFib().registerPrefix(m_nlsr.getConfParameter().getLsaPrefix(),
                                 faceUri, linkCost, timeout,
                                 ndn::nfd::ROUTE_FLAG_CAPTURE, 0);
    m_nlsr.getFib().registerPrefix(broadcastKeyPrefix,
                                 faceUri, linkCost, timeout,
                                 ndn::nfd::ROUTE_FLAG_CAPTURE, 0);

    // Sends a Hello Interest to determine status before the next scheduled.
    /* interest name: /<neighbor>/NLSR/INFO/<router> */
    ndn::Name interestName(neighbor);
    interestName.append(NLSR_COMPONENT);
    interestName.append(INFO_COMPONENT);
    interestName.append(m_nlsr.getConfParameter().getRouterPrefix().wireEncode());
    expressInterest(interestName,
                    m_nlsr.getConfParameter().getInterestResendTime());
  }
}
Esempio n. 2
0
 void
 fetchFibEnumerationInformation()
 {
   Name interestName("/localhost/nfd/fib/list");
   Interest interest(interestName);
   interest.setChildSelector(1);
   interest.setMustBeFresh(true);
   m_face.expressInterest(
     interest,
     func_lib::bind(&NfdStatus::onData, this, _1, _2, "FIBDataRequest"),
     func_lib::bind(&NfdStatus::onTimeout, this, _1, "FIBDataRequest"));
 }
Esempio n. 3
0
void
HelloProtocol::onRegistrationSuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
                                     const ndn::Name& neighbor)
{
  Adjacent *adjacent = m_nlsr.getAdjacencyList().findAdjacent(neighbor);
  if (adjacent != 0) {
    adjacent->setFaceId(commandSuccessResult.getFaceId());
    /* interest name: /<neighbor>/NLSR/INFO/<router> */
    ndn::Name interestName(neighbor);
    interestName.append(NLSR_COMPONENT);
    interestName.append(INFO_COMPONENT);
    interestName.append(m_nlsr.getConfParameter().getRouterPrefix().wireEncode());
    expressInterest(interestName,
                    m_nlsr.getConfParameter().getInterestResendTime());
  }
}
Esempio n. 4
0
 ndn::Interest
 createInterestPacket()
 {
   ndn::Name interestName(m_prefixName);
   ndn::Interest interestPacket(interestName);
   if (m_mustBeFresh)
     interestPacket.setMustBeFresh(true);
   if (m_isChildSelectorRightmost)
     interestPacket.setChildSelector(1);
   if (m_minSuffixComponents >= 0)
     interestPacket.setMinSuffixComponents(m_minSuffixComponents);
   if (m_maxSuffixComponents >= 0)
     interestPacket.setMaxSuffixComponents(m_maxSuffixComponents);
   if (m_interestLifetime < ndn::time::milliseconds::zero())
     interestPacket.setInterestLifetime(getDefaultInterestLifetime());
   else
     interestPacket.setInterestLifetime(m_interestLifetime);
   return interestPacket;
 }
BOOST_FIXTURE_TEST_CASE(SegmentZero, Fixture)
{
  int nNacks = 2;

  ndn::Name interestName("ndn:/A");
  SegmentFetcher::fetch(face,
                        Interest(interestName),
                        make_shared<ValidatorNull>(),
                        bind(&Fixture::onComplete, this, _1),
                        bind(&Fixture::onError, this, _1));

  advanceClocks(time::milliseconds(1000));

  for (uint64_t segmentNo = 0; segmentNo <= 3; segmentNo++) {
    if (segmentNo == 1) {
      while (nNacks--) {
        nackLastInterest(lp::NackReason::CONGESTION);
        advanceClocks(time::milliseconds(10));
      }
    }

    auto data = makeDataSegment(interestName, segmentNo, segmentNo == 3);
    face.receive(*data);
    advanceClocks(time::milliseconds(10));
  }

  // Total number of sent interests should be 6: one interest for segment zero and segment one each,
  // two re-expressed interests for segment one after getting nack twice, and two interests for
  // segment two and three
  BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 6);

  BOOST_CHECK_EQUAL(face.sentInterests[0].getName(), ndn::Name("ndn:/A"));
  BOOST_CHECK_EQUAL(face.sentInterests[1].getName(), ndn::Name("ndn:/A/%00%01"));
  BOOST_CHECK_EQUAL(face.sentInterests[2].getName(), ndn::Name("ndn:/A/%00%01"));
  BOOST_CHECK_EQUAL(face.sentInterests[3].getName(), ndn::Name("ndn:/A/%00%01"));
  BOOST_CHECK_EQUAL(face.sentInterests[4].getName(), ndn::Name("ndn:/A/%00%02"));
  BOOST_CHECK_EQUAL(face.sentInterests[5].getName(), ndn::Name("ndn:/A/%00%03"));
}
    void
    onInterest(const ndn::Name& name, const ndn::Interest& interest)
    {
        ndn::Name interestName(interest.getName());

        if(DEBUG)
            std::cout << "received interest: " << interest.getName() << std::endl;

        //run scripts if requested by server
        ndn::Name cmpName(getFilter()+SCRIPT_SUFFIX);
        int num_components = cmpName.size();
        if(cmpName.isPrefixOf(interestName))
        {
            int numberOfComponents = interestName.size();
            for(int i = num_components; i < numberOfComponents; ++i)
            {
                m_scriptsList.push_front(interestName[i].toUri());
            }
            runScripts(interestName);
        }
        else
        {
            int numberOfComponents = interestName.size();
            if(!m_remoteLinks.empty())
            {
                std::cerr << "remote links list is not empty - check for a missing reports!!" << std::endl;
                m_remoteLinks.clear();
            }
            for(int i = name.size(); i < numberOfComponents; ++i)
            {
                m_remoteLinks.insert(interestName[i].toUri());
            }

            // ask for local status
            fetchFaceStatusInformation(interestName);
        }
    }
  void
  generateTraffic( const boost::system::error_code& errorCode,
                   boost::asio::deadline_timer* deadlineTimer )
  {
    if ((interestCount_ < 0) || (totalInterestSent_ < interestCount_))
      {
        int trafficKey, patternId, cumulativePercentage;
        std::srand(std::time(0));
        trafficKey = std::rand() % 100;
        cumulativePercentage = 0;
        for (patternId=0; patternId<trafficPattern_.size(); patternId++)
          {
            cumulativePercentage += trafficPattern_[patternId].trafficPercentage;
            if (trafficKey <= cumulativePercentage)
              {
                Name interestName(trafficPattern_[patternId].name);
                if (trafficPattern_[patternId].nameAppendBytes > 0)
                  interestName.append(getRandomByteString(trafficPattern_[patternId].nameAppendBytes));
                if (trafficPattern_[patternId].nameAppendSequenceNumber >= 0)
                  {
                    interestName.append(toString(trafficPattern_[patternId].nameAppendSequenceNumber));
                    trafficPattern_[patternId].nameAppendSequenceNumber++;
                  }
                Interest interest(interestName);
                if (trafficPattern_[patternId].minSuffixComponents >= 0)
                  interest.setMinSuffixComponents(trafficPattern_[patternId].minSuffixComponents);
                if (trafficPattern_[patternId].maxSuffixComponents >= 0)
                  interest.setMaxSuffixComponents(trafficPattern_[patternId].maxSuffixComponents);
                Exclude exclude;
                if (trafficPattern_[patternId].excludeBefore != "" &&  trafficPattern_[patternId].excludeAfter != "")
                  {
                    exclude.excludeRange(name::Component(trafficPattern_[patternId].excludeAfter),
                                         name::Component(trafficPattern_[patternId].excludeBefore));
                    interest.setExclude(exclude);
                  }
                else if (trafficPattern_[patternId].excludeBefore != "")
                  {
                    exclude.excludeBefore(name::Component(trafficPattern_[patternId].excludeBefore));
                    interest.setExclude(exclude);
                  }
                else if (trafficPattern_[patternId].excludeAfter != "")
                  {
                    exclude.excludeAfter(name::Component(trafficPattern_[patternId].excludeAfter));
                    interest.setExclude(exclude);
                  }
                if (trafficPattern_[patternId].excludeBeforeBytes > 0 &&  trafficPattern_[patternId].excludeAfterBytes > 0)
                  {
                    exclude.excludeRange(name::Component(getRandomByteString(trafficPattern_[patternId].excludeAfterBytes)),
                                         name::Component(getRandomByteString(trafficPattern_[patternId].excludeBeforeBytes)));
                    interest.setExclude(exclude);
                  }
                else if (trafficPattern_[patternId].excludeBeforeBytes > 0)
                  {
                    exclude.excludeBefore(name::Component(getRandomByteString(trafficPattern_[patternId].excludeBeforeBytes)));
                    interest.setExclude(exclude);
                  }
                else if (trafficPattern_[patternId].excludeAfterBytes > 0)
                  {
                    exclude.excludeAfter(name::Component(getRandomByteString(trafficPattern_[patternId].excludeAfterBytes)));
                    interest.setExclude(exclude);
                  }

                if (trafficPattern_[patternId].childSelector >= 0)
                  interest.setChildSelector(trafficPattern_[patternId].childSelector);

                if (trafficPattern_[patternId].mustBeFresh == 0)
                  interest.setMustBeFresh(false);
                else if (trafficPattern_[patternId].mustBeFresh > 0)
                  interest.setMustBeFresh(true);
                if (trafficPattern_[patternId].nonceDuplicationPercentage > 0)
                  {
                    int duplicationKey;
                    std::srand(std::time(0));
                    duplicationKey = std::rand() % 100;
                    if (trafficPattern_[patternId].nonceDuplicationPercentage <= duplicationKey)
                      interest.setNonce(getOldNonce());
                    else
                      interest.setNonce(getNewNonce());
                  }
                else
                  interest.setNonce(getNewNonce());
                if (trafficPattern_[patternId].scope >= 0)
                  interest.setScope(trafficPattern_[patternId].scope);
                if (trafficPattern_[patternId].interestLifetime >= 0)
                  interest.setInterestLifetime(trafficPattern_[patternId].interestLifetime);
                else
                  interest.setInterestLifetime(getDefaultInterestLifetime());
                try {
                  totalInterestSent_++;
                  trafficPattern_[patternId].totalInterestSent++;
                  boost::posix_time::ptime sentTime;
                  sentTime = boost::posix_time::microsec_clock::local_time();
                  face_.expressInterest(interest,
                                        func_lib::bind( &NdnTrafficClient::onData,
                                                        this, boost::ref(face_),
                                                        _1, _2, totalInterestSent_,
                                                        trafficPattern_[patternId].totalInterestSent,
                                                        patternId,
                                                        sentTime),
                                        func_lib::bind( &NdnTrafficClient::onTimeout,
                                                        this, boost::ref(face_),
                                                        _1, totalInterestSent_,
                                                        trafficPattern_[patternId].totalInterestSent,
                                                        patternId));
                  std::string logLine;
                  logLine = "";
                  logLine += "Sending Interest   - PatternType="+toString(patternId+1);
                  logLine += ", GlobalID="+toString(totalInterestSent_);
                  logLine += ", LocalID="+toString(trafficPattern_[patternId].totalInterestSent);
                  logLine += ", Name="+interest.getName().toUri();
                  m_logger.log(logLine, true, false);
                  deadlineTimer->expires_at(deadlineTimer->expires_at() +
                                            boost::posix_time::millisec(interestInterval_));
                  deadlineTimer->async_wait(boost::bind(&NdnTrafficClient::generateTraffic,
                                                        this,
                                                        boost::asio::placeholders::error,
                                                        deadlineTimer));
                }
                catch (std::exception &e) {
                  m_logger.log("ERROR: "+(std::string)e.what(), true, true);
                }
                break;
              }
          }
        if (patternId==trafficPattern_.size())
          {
            deadlineTimer->expires_at(deadlineTimer->expires_at() +
                                      boost::posix_time::millisec(interestInterval_));
            deadlineTimer->async_wait(boost::bind(&NdnTrafficClient::generateTraffic,
                                                  this,
                                                  boost::asio::placeholders::error,
                                                  deadlineTimer));
          }
      }
  }