blob: b592a240a3fbb8461815c2eb6ae82237f41c8549 [file] [log] [blame]
Junxiao Shi2c29f3a2014-01-24 19:59:00 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesaventocf7db2f2019-03-24 23:17:28 -04002/*
Teng Liangf3bc3ae2020-06-08 10:19:25 -07003 * Copyright (c) 2014-2020, Regents of the University of California,
Alexander Afanasyev319f2c82015-01-07 14:56:53 -08004 * 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 Afanasyev9bcbc7c2014-04-06 19:37:37 -070010 *
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 Afanasyev319f2c82015-01-07 14:56:53 -080024 */
Junxiao Shi2c29f3a2014-01-24 19:59:00 -070025
26#include "face/face.hpp"
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040027#include "face/generic-link-service.hpp"
Junxiao Shi2c29f3a2014-01-24 19:59:00 -070028
Junxiao Shid9ee45c2014-02-27 15:38:11 -070029#include "tests/test-common.hpp"
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040030#include "tests/daemon/global-io-fixture.hpp"
Junxiao Shicde37ad2015-12-24 01:02:05 -070031#include "dummy-face.hpp"
Weiwei Liu073da602016-02-17 16:05:00 -070032#include "dummy-transport.hpp"
Junxiao Shi2c29f3a2014-01-24 19:59:00 -070033
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080034namespace nfd {
Junxiao Shicde37ad2015-12-24 01:02:05 -070035namespace face {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070036namespace tests {
Junxiao Shi2c29f3a2014-01-24 19:59:00 -070037
Junxiao Shicde37ad2015-12-24 01:02:05 -070038using namespace nfd::tests;
Junxiao Shi2c29f3a2014-01-24 19:59:00 -070039
Junxiao Shicde37ad2015-12-24 01:02:05 -070040BOOST_AUTO_TEST_SUITE(Face)
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040041BOOST_FIXTURE_TEST_SUITE(TestFace, GlobalIoFixture)
Junxiao Shicde37ad2015-12-24 01:02:05 -070042
Weiwei Liu073da602016-02-17 16:05:00 -070043using nfd::Face;
44
45BOOST_AUTO_TEST_CASE(GetLinkService)
46{
47 auto linkService = make_unique<GenericLinkService>();
48 auto linkServicePtr = linkService.get();
49 auto face = make_unique<Face>(std::move(linkService), make_unique<DummyTransport>());
50
51 BOOST_CHECK_EQUAL(face->getLinkService(), linkServicePtr);
52}
53
54BOOST_AUTO_TEST_CASE(GetTransport)
55{
56 auto dummyTransport = make_unique<DummyTransport>();
57 auto transportPtr = dummyTransport.get();
58 auto face = make_unique<Face>(make_unique<GenericLinkService>(), std::move(dummyTransport));
59
60 BOOST_CHECK_EQUAL(face->getTransport(), transportPtr);
61}
62
63BOOST_AUTO_TEST_CASE(StaticProperties)
64{
65 auto face = make_unique<DummyFace>();
66
67 BOOST_CHECK_EQUAL(face->getId(), INVALID_FACEID);
68 BOOST_CHECK_EQUAL(face->getLocalUri().getScheme(), "dummy");
69 BOOST_CHECK_EQUAL(face->getRemoteUri().getScheme(), "dummy");
70 BOOST_CHECK_EQUAL(face->getScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL);
71 BOOST_CHECK_EQUAL(face->getPersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
72 BOOST_CHECK_EQUAL(face->getLinkType(), ndn::nfd::LINK_TYPE_POINT_TO_POINT);
73
74 face->setId(222);
75 BOOST_CHECK_EQUAL(face->getId(), 222);
76
77 face->setPersistency(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
78 BOOST_CHECK_EQUAL(face->getPersistency(), ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
79}
80
81BOOST_AUTO_TEST_CASE(State)
82{
83 auto face = make_shared<DummyFace>();
84 BOOST_CHECK_EQUAL(face->getState(), FaceState::UP);
85
86 face->setState(FaceState::DOWN);
87 BOOST_CHECK_EQUAL(face->getState(), FaceState::DOWN);
88}
Junxiao Shicde37ad2015-12-24 01:02:05 -070089
90BOOST_AUTO_TEST_CASE(LinkServiceSendReceive)
Junxiao Shi32bfeb32014-01-25 18:22:02 -070091{
Junxiao Shicde37ad2015-12-24 01:02:05 -070092 auto face1 = make_shared<DummyFace>();
93
94 const size_t nInInterests = 192;
95 const size_t nInData = 91;
96 const size_t nInNacks = 29;
97 const size_t nOutInterests = 202;
98 const size_t nOutData = 128;
99 const size_t nOutNacks = 84;
100
101 size_t nReceivedInterests = 0;
102 size_t nReceivedData = 0;
103 size_t nReceivedNacks = 0;
104 face1->afterReceiveInterest.connect(bind([&nReceivedInterests] { ++nReceivedInterests; }));
105 face1->afterReceiveData.connect(bind([&nReceivedData] { ++nReceivedData; }));
106 face1->afterReceiveNack.connect(bind([&nReceivedNacks] { ++nReceivedNacks; }));
107
108 for (size_t i = 0; i < nInInterests; ++i) {
Junxiao Shi9d727852019-05-14 13:44:22 -0600109 face1->receiveInterest(*makeInterest("/JSQdqward4"), 0);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700110 }
111
112 for (size_t i = 0; i < nInData; ++i) {
Junxiao Shi9d727852019-05-14 13:44:22 -0600113 face1->receiveData(*makeData("/hT8FDigWn1"), 0);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700114 }
115
116 for (size_t i = 0; i < nInNacks; ++i) {
Junxiao Shi9d727852019-05-14 13:44:22 -0600117 face1->receiveNack(makeNack(*makeInterest("/StnEVTj4Ex", false, nullopt, 561),
118 lp::NackReason::CONGESTION), 0);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700119 }
120
121 for (size_t i = 0; i < nOutInterests; ++i) {
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700122 face1->sendInterest(*makeInterest("/XyUAFYQDmd"));
Junxiao Shicde37ad2015-12-24 01:02:05 -0700123 }
124
125 for (size_t i = 0; i < nOutData; ++i) {
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700126 face1->sendData(*makeData("/GigPEtPH6"));
Junxiao Shicde37ad2015-12-24 01:02:05 -0700127 }
128
129 for (size_t i = 0; i < nOutNacks; ++i) {
Junxiao Shi9d727852019-05-14 13:44:22 -0600130 face1->sendNack(makeNack(*makeInterest("/9xK6FbwIBM", false, nullopt, 365),
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700131 lp::NackReason::CONGESTION));
Junxiao Shicde37ad2015-12-24 01:02:05 -0700132 }
133
134 BOOST_CHECK_EQUAL(face1->getCounters().nInInterests, nInInterests);
135 BOOST_CHECK_EQUAL(face1->getCounters().nInData, nInData);
136 BOOST_CHECK_EQUAL(face1->getCounters().nInNacks, nInNacks);
137 BOOST_CHECK_EQUAL(face1->getCounters().nOutInterests, nOutInterests);
138 BOOST_CHECK_EQUAL(face1->getCounters().nOutData, nOutData);
139 BOOST_CHECK_EQUAL(face1->getCounters().nOutNacks, nOutNacks);
140
141 BOOST_CHECK_EQUAL(nReceivedInterests, nInInterests);
142 BOOST_CHECK_EQUAL(nReceivedData, nInData);
143 BOOST_CHECK_EQUAL(nReceivedNacks, nInNacks);
144 BOOST_CHECK_EQUAL(face1->sentInterests.size(), nOutInterests);
145 BOOST_CHECK_EQUAL(face1->sentData.size(), nOutData);
146 BOOST_CHECK_EQUAL(face1->sentNacks.size(), nOutNacks);
Junxiao Shi32bfeb32014-01-25 18:22:02 -0700147}
Junxiao Shi2c29f3a2014-01-24 19:59:00 -0700148
Junxiao Shicde37ad2015-12-24 01:02:05 -0700149BOOST_AUTO_TEST_SUITE_END() // TestFace
150BOOST_AUTO_TEST_SUITE_END() // Face
Junxiao Shi2c29f3a2014-01-24 19:59:00 -0700151
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700152} // namespace tests
Junxiao Shicde37ad2015-12-24 01:02:05 -0700153} // namespace face
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800154} // namespace nfd