示例#1
0
文件: main.cpp 项目: CCJY/coliru
    Exclude exclusions(Elements const& elements) {
        Exclude result;

        for(auto& el : elements)
            result.add(el, true);

        return result;
    }
示例#2
0
bool
Exclude::operator==(const Exclude& other) const
{
  if (empty() && other.empty())
    return true;
  if (empty() || other.empty())
    return false;

  return wireEncode() == other.wireEncode();
}
BOOST_AUTO_TEST_CASE_TEMPLATE(ExcludeSelector, T, InMemoryStorages)
{
  T ims;

  shared_ptr<Data> data = makeData("/a");
  ims.insert(*data);

  shared_ptr<Data> data2 = makeData("/b");
  ims.insert(*data2);

  shared_ptr<Data> data3 = makeData("/c/a");
  ims.insert(*data3);

  shared_ptr<Data> data4 = makeData("/d");
  ims.insert(*data4);

  shared_ptr<Data> data5 = makeData("/c/c");
  ims.insert(*data5);

  shared_ptr<Data> data6 = makeData("/c/f");
  ims.insert(*data6);

  shared_ptr<Data> data7 = makeData("/c/n");
  ims.insert(*data7);

  shared_ptr<Interest> interest = makeInterest("/c");
  interest->setChildSelector(1);
  Exclude e;
  e.excludeOne (Name::Component("n"));
  interest->setExclude(e);

  shared_ptr<const Data> found = ims.find(*interest);
  BOOST_CHECK_EQUAL(found->getName(), "/c/f");

  shared_ptr<Interest> interest2 = makeInterest("/c");
  interest2->setChildSelector(0);

  Exclude e2;
  e2.excludeOne (Name::Component("a"));
  interest2->setExclude(e2);

  shared_ptr<const Data> found2 = ims.find(*interest2);
  BOOST_CHECK_EQUAL(found2->getName(), "/c/c");

  shared_ptr<Interest> interest3 = makeInterest("/c");
  interest3->setChildSelector(0);

  Exclude e3;
  e3.excludeOne (Name::Component("c"));
  interest3->setExclude(e3);

  shared_ptr<const Data> found3 = ims.find(*interest3);
  BOOST_CHECK_EQUAL(found3->getName(), "/c/a");
}
void
SelectorHelper::applySelectors(Interest& interest, Context* context)
{
  int minSuffix = -1;
  context->getContextOption(MIN_SUFFIX_COMP_S, minSuffix);
  
  if (minSuffix >= 0)
  {
    interest.setMinSuffixComponents(minSuffix);
  }
  
  int maxSuffix = -1;
  context->getContextOption(MAX_SUFFIX_COMP_S, maxSuffix);
  
  if (maxSuffix >= 0)
  {
    interest.setMaxSuffixComponents(maxSuffix);
  }
  
  Exclude exclusion;
  context->getContextOption(EXCLUDE_S, exclusion);
  
  if (!exclusion.empty())
  {
    interest.setExclude(exclusion);
  }
  
  bool mustBeFresh = false;
  context->getContextOption(MUST_BE_FRESH_S, mustBeFresh);
  
  if (mustBeFresh)
  {
    interest.setMustBeFresh(mustBeFresh);
  }
  
  int child = -10;
  context->getContextOption(RIGHTMOST_CHILD_S, child);
  
  if (child != -10)
  {
    interest.setChildSelector(child);
  }
  
  KeyLocator keyLocator;
  context->getContextOption(KEYLOCATOR_S, keyLocator);
  
  if (!keyLocator.empty())
  {
    interest.setPublisherPublicKeyLocator(keyLocator);
  }
}
示例#5
0
TEST_F(TestInterestMethods, ExcludeMatches)
{
  Exclude exclude;
  exclude.appendComponent(Name("%00%02").get(0));
  exclude.appendAny();
  exclude.appendComponent(Name("%00%20").get(0));

  Name::Component component;
  component = Name("%00%01").get(0);
  ASSERT_FALSE(exclude.matches(component)) <<
    component.toEscapedString() << " should not match " << exclude.toUri();
  component = Name("%00%0F").get(0);
  ASSERT_TRUE(exclude.matches(component)) <<
    component.toEscapedString() << " should match " << exclude.toUri();
  component = Name("%00%21").get(0);
  ASSERT_FALSE(exclude.matches(component)) <<
    component.toEscapedString() << " should not match " << exclude.toUri();
}
  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));
          }
      }
  }