Junxiao Shi | 2c29f3a | 2014-01-24 19:59:00 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 2 | /* |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2022, Regents of the University of California, |
Alexander Afanasyev | 319f2c8 | 2015-01-07 14:56:53 -0800 | [diff] [blame] | 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
Alexander Afanasyev | 319f2c8 | 2015-01-07 14:56:53 -0800 | [diff] [blame] | 24 | */ |
Junxiao Shi | 2c29f3a | 2014-01-24 19:59:00 -0700 | [diff] [blame] | 25 | |
| 26 | #include "face/face.hpp" |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 27 | #include "face/generic-link-service.hpp" |
Junxiao Shi | 2c29f3a | 2014-01-24 19:59:00 -0700 | [diff] [blame] | 28 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 29 | #include "tests/test-common.hpp" |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 30 | #include "tests/daemon/global-io-fixture.hpp" |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 31 | #include "dummy-face.hpp" |
Weiwei Liu | 073da60 | 2016-02-17 16:05:00 -0700 | [diff] [blame] | 32 | #include "dummy-transport.hpp" |
Junxiao Shi | 2c29f3a | 2014-01-24 19:59:00 -0700 | [diff] [blame] | 33 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 34 | namespace nfd::tests { |
Junxiao Shi | 2c29f3a | 2014-01-24 19:59:00 -0700 | [diff] [blame] | 35 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 36 | using namespace nfd::face; |
Junxiao Shi | 2c29f3a | 2014-01-24 19:59:00 -0700 | [diff] [blame] | 37 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 38 | BOOST_AUTO_TEST_SUITE(Face) |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 39 | BOOST_FIXTURE_TEST_SUITE(TestFace, GlobalIoFixture) |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 40 | |
Weiwei Liu | 073da60 | 2016-02-17 16:05:00 -0700 | [diff] [blame] | 41 | using nfd::Face; |
| 42 | |
| 43 | BOOST_AUTO_TEST_CASE(GetLinkService) |
| 44 | { |
| 45 | auto linkService = make_unique<GenericLinkService>(); |
| 46 | auto linkServicePtr = linkService.get(); |
| 47 | auto face = make_unique<Face>(std::move(linkService), make_unique<DummyTransport>()); |
| 48 | |
| 49 | BOOST_CHECK_EQUAL(face->getLinkService(), linkServicePtr); |
| 50 | } |
| 51 | |
| 52 | BOOST_AUTO_TEST_CASE(GetTransport) |
| 53 | { |
| 54 | auto dummyTransport = make_unique<DummyTransport>(); |
| 55 | auto transportPtr = dummyTransport.get(); |
| 56 | auto face = make_unique<Face>(make_unique<GenericLinkService>(), std::move(dummyTransport)); |
| 57 | |
| 58 | BOOST_CHECK_EQUAL(face->getTransport(), transportPtr); |
| 59 | } |
| 60 | |
| 61 | BOOST_AUTO_TEST_CASE(StaticProperties) |
| 62 | { |
| 63 | auto face = make_unique<DummyFace>(); |
| 64 | |
| 65 | BOOST_CHECK_EQUAL(face->getId(), INVALID_FACEID); |
| 66 | BOOST_CHECK_EQUAL(face->getLocalUri().getScheme(), "dummy"); |
| 67 | BOOST_CHECK_EQUAL(face->getRemoteUri().getScheme(), "dummy"); |
| 68 | BOOST_CHECK_EQUAL(face->getScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL); |
| 69 | BOOST_CHECK_EQUAL(face->getPersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT); |
| 70 | BOOST_CHECK_EQUAL(face->getLinkType(), ndn::nfd::LINK_TYPE_POINT_TO_POINT); |
| 71 | |
| 72 | face->setId(222); |
| 73 | BOOST_CHECK_EQUAL(face->getId(), 222); |
| 74 | |
| 75 | face->setPersistency(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND); |
| 76 | BOOST_CHECK_EQUAL(face->getPersistency(), ndn::nfd::FACE_PERSISTENCY_ON_DEMAND); |
| 77 | } |
| 78 | |
| 79 | BOOST_AUTO_TEST_CASE(State) |
| 80 | { |
| 81 | auto face = make_shared<DummyFace>(); |
| 82 | BOOST_CHECK_EQUAL(face->getState(), FaceState::UP); |
| 83 | |
| 84 | face->setState(FaceState::DOWN); |
| 85 | BOOST_CHECK_EQUAL(face->getState(), FaceState::DOWN); |
| 86 | } |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 87 | |
| 88 | BOOST_AUTO_TEST_CASE(LinkServiceSendReceive) |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 89 | { |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 90 | auto face1 = make_shared<DummyFace>(); |
| 91 | |
| 92 | const size_t nInInterests = 192; |
| 93 | const size_t nInData = 91; |
| 94 | const size_t nInNacks = 29; |
| 95 | const size_t nOutInterests = 202; |
| 96 | const size_t nOutData = 128; |
| 97 | const size_t nOutNacks = 84; |
| 98 | |
| 99 | size_t nReceivedInterests = 0; |
| 100 | size_t nReceivedData = 0; |
| 101 | size_t nReceivedNacks = 0; |
Davide Pesavento | 412c982 | 2021-07-02 00:21:05 -0400 | [diff] [blame] | 102 | face1->afterReceiveInterest.connect([&] (auto&&...) { ++nReceivedInterests; }); |
| 103 | face1->afterReceiveData.connect([&] (auto&&...) { ++nReceivedData; }); |
| 104 | face1->afterReceiveNack.connect([&] (auto&&...) { ++nReceivedNacks; }); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 105 | |
| 106 | for (size_t i = 0; i < nInInterests; ++i) { |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 107 | face1->receiveInterest(*makeInterest("/JSQdqward4")); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | for (size_t i = 0; i < nInData; ++i) { |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 111 | face1->receiveData(*makeData("/hT8FDigWn1")); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | for (size_t i = 0; i < nInNacks; ++i) { |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 115 | face1->receiveNack(makeNack(*makeInterest("/StnEVTj4Ex", false, std::nullopt, 561), |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 116 | lp::NackReason::CONGESTION)); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | for (size_t i = 0; i < nOutInterests; ++i) { |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 120 | face1->sendInterest(*makeInterest("/XyUAFYQDmd")); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | for (size_t i = 0; i < nOutData; ++i) { |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 124 | face1->sendData(*makeData("/GigPEtPH6")); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | for (size_t i = 0; i < nOutNacks; ++i) { |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 128 | face1->sendNack(makeNack(*makeInterest("/9xK6FbwIBM", false, std::nullopt, 365), |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 129 | lp::NackReason::CONGESTION)); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | BOOST_CHECK_EQUAL(face1->getCounters().nInInterests, nInInterests); |
| 133 | BOOST_CHECK_EQUAL(face1->getCounters().nInData, nInData); |
| 134 | BOOST_CHECK_EQUAL(face1->getCounters().nInNacks, nInNacks); |
| 135 | BOOST_CHECK_EQUAL(face1->getCounters().nOutInterests, nOutInterests); |
| 136 | BOOST_CHECK_EQUAL(face1->getCounters().nOutData, nOutData); |
| 137 | BOOST_CHECK_EQUAL(face1->getCounters().nOutNacks, nOutNacks); |
| 138 | |
| 139 | BOOST_CHECK_EQUAL(nReceivedInterests, nInInterests); |
| 140 | BOOST_CHECK_EQUAL(nReceivedData, nInData); |
| 141 | BOOST_CHECK_EQUAL(nReceivedNacks, nInNacks); |
| 142 | BOOST_CHECK_EQUAL(face1->sentInterests.size(), nOutInterests); |
| 143 | BOOST_CHECK_EQUAL(face1->sentData.size(), nOutData); |
| 144 | BOOST_CHECK_EQUAL(face1->sentNacks.size(), nOutNacks); |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 145 | } |
Junxiao Shi | 2c29f3a | 2014-01-24 19:59:00 -0700 | [diff] [blame] | 146 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 147 | BOOST_AUTO_TEST_SUITE_END() // TestFace |
| 148 | BOOST_AUTO_TEST_SUITE_END() // Face |
Junxiao Shi | 2c29f3a | 2014-01-24 19:59:00 -0700 | [diff] [blame] | 149 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 150 | } // namespace nfd::tests |