From 771a0de40cbf858ad60051a84a5e53bb84f8ce3e Mon Sep 17 00:00:00 2001 From: Junxiao Shi Date: Wed, 9 Aug 2023 00:03:21 +0000 Subject: [PATCH] tests: change FaceId in test-nlsr and test-fib DummyClientFace is no longer overwriting FaceId of prefix registration reply, so that we can use FaceId other than 1. refs #5011 Change-Id: I50ff0a6ee023ebe5cc78e6d62a45ce375798ad41 --- tests/route/test-fib.cpp | 40 +++++++--------------------------------- tests/test-nlsr.cpp | 14 +++++--------- 2 files changed, 12 insertions(+), 42 deletions(-) diff --git a/tests/route/test-fib.cpp b/tests/route/test-fib.cpp index a902eb7..932b63a 100644 --- a/tests/route/test-fib.cpp +++ b/tests/route/test-fib.cpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2014-2022, The University of Memphis, + * Copyright (c) 2014-2023, The University of Memphis, * Regents of the University of California * * This file is part of NLSR (Named-data Link State Routing). @@ -39,7 +39,6 @@ public: , fib(face, m_scheduler, adjacencies, conf, m_keyChain) , interests(face.sentInterests) { - enableRegistrationReplyWithFaceId(); advanceClocks(1_s); Adjacent neighbor1(router1Name, ndn::FaceUri(router1FaceUri), 0, Adjacent::STATUS_ACTIVE, 0, router1FaceId); @@ -56,36 +55,6 @@ public: fib.setEntryRefreshTime(1); } - void - enableRegistrationReplyWithFaceId() - { - face.onSendInterest.connect([this] (const auto& interest) { - if (!RIB_COMMAND_PREFIX.isPrefixOf(interest.getName())) - return; - - ndn::name::Component verb; - ndn::nfd::ControlParameters params; - extractRibCommandParameters(interest, verb, params); - if (!params.hasFaceId()) { - params.setFaceId(1); - } - params.setOrigin(ndn::nfd::ROUTE_ORIGIN_APP); - if (verb == ndn::name::Component("register")) { - params.setCost(0); - } - - ndn::nfd::ControlResponse resp; - resp.setCode(200); - resp.setBody(params.wireEncode()); - - ndn::Data data(interest.getName()); - data.setContent(resp.wireEncode()); - m_keyChain.sign(data, ndn::security::SigningInfo(ndn::security::SigningInfo::SIGNER_TYPE_SHA256)); - - face.getIoService().post([this, data] { face.receive(data); }); - }); - } - static void extractRibCommandParameters(const ndn::Interest& interest, ndn::Name::Component& verb, @@ -102,7 +71,12 @@ private: ndn::Scheduler m_scheduler{m_io}; public: - ndn::util::DummyClientFace face{m_io, m_keyChain}; + ndn::util::DummyClientFace face{m_io, m_keyChain, [] { + ndn::util::DummyClientFace::Options opts; + opts.enableRegistrationReply = true; + opts.registrationReplyFaceId = 128; + return opts; + } ()}; ConfParameter conf{face, m_keyChain}; AdjacencyList& adjacencies; Fib fib; diff --git a/tests/test-nlsr.cpp b/tests/test-nlsr.cpp index e888acf..b4f979c 100644 --- a/tests/test-nlsr.cpp +++ b/tests/test-nlsr.cpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2014-2022, The University of Memphis, + * Copyright (c) 2014-2023, The University of Memphis, * Regents of the University of California, * Arizona Board of Regents. * @@ -207,7 +207,7 @@ BOOST_AUTO_TEST_CASE(SetEventIntervals) BOOST_AUTO_TEST_CASE(FaceCreateEvent) { // Setting constants for the unit test - const uint32_t faceId = 1; + const uint32_t faceId = 128; const std::string faceUri = "udp4://10.0.0.1:6363"; Adjacent neighbor("/ndn/neighborA", ndn::FaceUri(faceUri), 10, @@ -241,7 +241,7 @@ BOOST_AUTO_TEST_CASE(FaceCreateEvent) BOOST_AUTO_TEST_CASE(FaceCreateEventNoMatch) { // Setting constants for the unit test - const uint32_t faceId = 1; + const uint32_t faceId = 128; const std::string eventUri = "udp4://10.0.0.1:6363"; const std::string neighborUri = "udp4://10.0.0.2:6363"; @@ -272,10 +272,7 @@ BOOST_AUTO_TEST_CASE(FaceCreateEventNoMatch) BOOST_AUTO_TEST_CASE(FaceCreateEventAlreadyConfigured) { - // So if NLSR gets the notification and registers prefixes it - // will change the Id to 1 and our tests will fail - // Need to disable registrationReply in dummy face and have own registration reply in the future - const uint32_t neighborFaceId = 1; + const uint32_t neighborFaceId = 128; const std::string faceUri = "udp4://10.0.0.1:6363"; Adjacent neighbor("/ndn/neighborA", ndn::FaceUri(faceUri), 10, @@ -289,7 +286,7 @@ BOOST_AUTO_TEST_CASE(FaceCreateEventAlreadyConfigured) ndn::nfd::FaceEventNotification event; event.setKind(ndn::nfd::FACE_EVENT_CREATED) .setRemoteUri(faceUri) - .setFaceId(neighborFaceId); // Does not matter what we set here, dummy face always returns 1 + .setFaceId(neighborFaceId); auto data = std::make_shared(ndn::Name("/localhost/nfd/faces/events").appendSequenceNumber(0)); data->setFreshnessPeriod(1_s); data->setContent(event.wireEncode()); @@ -299,7 +296,6 @@ BOOST_AUTO_TEST_CASE(FaceCreateEventAlreadyConfigured) // Move the clocks forward so that the Face processes the event. this->advanceClocks(10_ms); - // Check that the neighbor is configured with the face id of 1 auto iterator = conf.getAdjacencyList().findAdjacent(ndn::FaceUri(faceUri)); BOOST_REQUIRE(iterator != conf.getAdjacencyList().end()); BOOST_CHECK_EQUAL(iterator->getFaceId(), neighborFaceId);