コード例 #1
0
ファイル: udp.t.cpp プロジェクト: zhtaoxiang/NFD
// automatically close an idle incoming face
BOOST_AUTO_TEST_CASE_TEMPLATE(IdleClose, A, EndToEndAddresses)
{
  LimitedIo limitedIo;
  UdpFactory factory;

  // channel1 is listening
  shared_ptr<UdpChannel> channel1 = factory.createChannel(A::getLocalIp(), A::getPort1(),
                                                          time::seconds(2));
  shared_ptr<Face> face1;
  unique_ptr<FaceHistory> history1;
  channel1->listen([&] (shared_ptr<Face> newFace) {
                     BOOST_CHECK(face1 == nullptr);
                     face1 = newFace;
                     history1.reset(new FaceHistory(*face1, limitedIo));
                     limitedIo.afterOp();
                   },
                   [] (const std::string& reason) { BOOST_ERROR(reason); });

  // face2 (on channel2) connects to channel1
  shared_ptr<UdpChannel> channel2 = factory.createChannel(A::getLocalIp(), A::getPort2(),
                                                          time::seconds(2));
  shared_ptr<Face> face2;
  unique_ptr<FaceHistory> history2;
  boost::asio::ip::address ipAddress = boost::asio::ip::address::from_string(A::getLocalIp());
  udp::Endpoint endpoint(ipAddress, boost::lexical_cast<uint16_t>(A::getPort1()));
  channel2->connect(endpoint,
                    [&] (shared_ptr<Face> newFace) {
                      face2 = newFace;
                      history2.reset(new FaceHistory(*face2, limitedIo));
                      limitedIo.afterOp();
                    },
                    [] (const std::string& reason) { BOOST_ERROR(reason); });

  limitedIo.run(1, time::milliseconds(100)); // 1 create (on channel2)
  BOOST_REQUIRE(face2 != nullptr);
  BOOST_CHECK_EQUAL(face2->getPersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
  BOOST_CHECK_EQUAL(face2->isMultiAccess(), false);

  // face2 sends to channel1, creates face1
  shared_ptr<Interest> interest2 = makeInterest("/I2");
  face2->sendInterest(*interest2);

  limitedIo.run(2, time::seconds(1)); // 1 accept (on channel1), 1 receive (on face1)
  BOOST_CHECK_EQUAL(channel1->size(), 1);
  BOOST_REQUIRE(face1 != nullptr);
  BOOST_CHECK_EQUAL(face1->getPersistency(), ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
  BOOST_CHECK_EQUAL(face1->isMultiAccess(), false);

  limitedIo.defer(time::seconds(1));
  BOOST_CHECK_EQUAL(history1->failures.size(), 0); // face1 is not idle
  BOOST_CHECK_EQUAL(history2->failures.size(), 0); // face2 is outgoing face and never closed

  limitedIo.defer(time::seconds(4));
  BOOST_CHECK_EQUAL(history1->failures.size(), 1); // face1 is idle and automatically closed
  BOOST_CHECK_EQUAL(channel1->size(), 0);
  BOOST_CHECK_EQUAL(history2->failures.size(), 0); // face2 is outgoing face and never closed
}
コード例 #2
0
BOOST_FIXTURE_TEST_CASE(CapacityUp, PeriodicalInsertionFixture)
{
  LimitedIo limitedIo;

  ssize_t cap0 = dnl.m_capacity;

  const int RATE = DeadNonceList::INITIAL_CAPACITY * 3;
  this->setRate(RATE);
  limitedIo.defer(LIFETIME * 10);

  ssize_t cap1 = dnl.m_capacity;
  BOOST_CHECK_LT(std::abs(cap1 - RATE), std::abs(cap0 - RATE));
}