blob: 2876a37e5b12e8fd4f50f445156cac6a43188215 [file] [log] [blame]
Junxiao Shi2c29f3a2014-01-24 19:59:00 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Weiwei Liu073da602016-02-17 16:05:00 -07003 * Copyright (c) 2014-2016, 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"
27
Junxiao Shid9ee45c2014-02-27 15:38:11 -070028#include "tests/test-common.hpp"
Junxiao Shicde37ad2015-12-24 01:02:05 -070029#include "dummy-face.hpp"
Weiwei Liu073da602016-02-17 16:05:00 -070030#include "dummy-transport.hpp"
31#include "face/generic-link-service.hpp"
Junxiao Shi2c29f3a2014-01-24 19:59:00 -070032
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080033namespace nfd {
Junxiao Shicde37ad2015-12-24 01:02:05 -070034namespace face {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070035namespace tests {
Junxiao Shi2c29f3a2014-01-24 19:59:00 -070036
Junxiao Shicde37ad2015-12-24 01:02:05 -070037using namespace nfd::tests;
Junxiao Shi2c29f3a2014-01-24 19:59:00 -070038
Junxiao Shicde37ad2015-12-24 01:02:05 -070039BOOST_AUTO_TEST_SUITE(Face)
40BOOST_FIXTURE_TEST_SUITE(TestFace, BaseFixture)
41
Weiwei Liu073da602016-02-17 16:05:00 -070042using nfd::Face;
43
44BOOST_AUTO_TEST_CASE(GetLinkService)
45{
46 auto linkService = make_unique<GenericLinkService>();
47 auto linkServicePtr = linkService.get();
48 auto face = make_unique<Face>(std::move(linkService), make_unique<DummyTransport>());
49
50 BOOST_CHECK_EQUAL(face->getLinkService(), linkServicePtr);
51}
52
53BOOST_AUTO_TEST_CASE(GetTransport)
54{
55 auto dummyTransport = make_unique<DummyTransport>();
56 auto transportPtr = dummyTransport.get();
57 auto face = make_unique<Face>(make_unique<GenericLinkService>(), std::move(dummyTransport));
58
59 BOOST_CHECK_EQUAL(face->getTransport(), transportPtr);
60}
61
62BOOST_AUTO_TEST_CASE(StaticProperties)
63{
64 auto face = make_unique<DummyFace>();
65
66 BOOST_CHECK_EQUAL(face->getId(), INVALID_FACEID);
67 BOOST_CHECK_EQUAL(face->getLocalUri().getScheme(), "dummy");
68 BOOST_CHECK_EQUAL(face->getRemoteUri().getScheme(), "dummy");
69 BOOST_CHECK_EQUAL(face->getScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL);
70 BOOST_CHECK_EQUAL(face->getPersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
71 BOOST_CHECK_EQUAL(face->getLinkType(), ndn::nfd::LINK_TYPE_POINT_TO_POINT);
72
73 face->setId(222);
74 BOOST_CHECK_EQUAL(face->getId(), 222);
75
76 face->setPersistency(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
77 BOOST_CHECK_EQUAL(face->getPersistency(), ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
78}
79
80BOOST_AUTO_TEST_CASE(State)
81{
82 auto face = make_shared<DummyFace>();
83 BOOST_CHECK_EQUAL(face->getState(), FaceState::UP);
84
85 face->setState(FaceState::DOWN);
86 BOOST_CHECK_EQUAL(face->getState(), FaceState::DOWN);
87}
Junxiao Shicde37ad2015-12-24 01:02:05 -070088
89BOOST_AUTO_TEST_CASE(LinkServiceSendReceive)
Junxiao Shi32bfeb32014-01-25 18:22:02 -070090{
Junxiao Shicde37ad2015-12-24 01:02:05 -070091 auto face1 = make_shared<DummyFace>();
92
93 const size_t nInInterests = 192;
94 const size_t nInData = 91;
95 const size_t nInNacks = 29;
96 const size_t nOutInterests = 202;
97 const size_t nOutData = 128;
98 const size_t nOutNacks = 84;
99
100 size_t nReceivedInterests = 0;
101 size_t nReceivedData = 0;
102 size_t nReceivedNacks = 0;
103 face1->afterReceiveInterest.connect(bind([&nReceivedInterests] { ++nReceivedInterests; }));
104 face1->afterReceiveData.connect(bind([&nReceivedData] { ++nReceivedData; }));
105 face1->afterReceiveNack.connect(bind([&nReceivedNacks] { ++nReceivedNacks; }));
106
107 for (size_t i = 0; i < nInInterests; ++i) {
108 shared_ptr<Interest> interest = makeInterest("/JSQdqward4");
109 face1->receiveInterest(*interest);
110 }
111
112 for (size_t i = 0; i < nInData; ++i) {
113 shared_ptr<Data> data = makeData("/hT8FDigWn1");
114 face1->receiveData(*data);
115 }
116
117 for (size_t i = 0; i < nInNacks; ++i) {
118 lp::Nack nack = makeNack("/StnEVTj4Ex", 561, lp::NackReason::CONGESTION);
119 face1->receiveNack(nack);
120 }
121
122 for (size_t i = 0; i < nOutInterests; ++i) {
123 shared_ptr<Interest> interest = makeInterest("/XyUAFYQDmd");
124 face1->sendInterest(*interest);
125 }
126
127 for (size_t i = 0; i < nOutData; ++i) {
128 shared_ptr<Data> data = makeData("/GigPEtPH6");
129 face1->sendData(*data);
130 }
131
132 for (size_t i = 0; i < nOutNacks; ++i) {
133 lp::Nack nack = makeNack("/9xK6FbwIBM", 365, lp::NackReason::CONGESTION);
134 face1->sendNack(nack);
135 }
136
137 BOOST_CHECK_EQUAL(face1->getCounters().nInInterests, nInInterests);
138 BOOST_CHECK_EQUAL(face1->getCounters().nInData, nInData);
139 BOOST_CHECK_EQUAL(face1->getCounters().nInNacks, nInNacks);
140 BOOST_CHECK_EQUAL(face1->getCounters().nOutInterests, nOutInterests);
141 BOOST_CHECK_EQUAL(face1->getCounters().nOutData, nOutData);
142 BOOST_CHECK_EQUAL(face1->getCounters().nOutNacks, nOutNacks);
143
144 BOOST_CHECK_EQUAL(nReceivedInterests, nInInterests);
145 BOOST_CHECK_EQUAL(nReceivedData, nInData);
146 BOOST_CHECK_EQUAL(nReceivedNacks, nInNacks);
147 BOOST_CHECK_EQUAL(face1->sentInterests.size(), nOutInterests);
148 BOOST_CHECK_EQUAL(face1->sentData.size(), nOutData);
149 BOOST_CHECK_EQUAL(face1->sentNacks.size(), nOutNacks);
Junxiao Shi32bfeb32014-01-25 18:22:02 -0700150}
Junxiao Shi2c29f3a2014-01-24 19:59:00 -0700151
Junxiao Shicde37ad2015-12-24 01:02:05 -0700152BOOST_AUTO_TEST_SUITE_END() // TestFace
153BOOST_AUTO_TEST_SUITE_END() // Face
Junxiao Shi2c29f3a2014-01-24 19:59:00 -0700154
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700155} // namespace tests
Junxiao Shicde37ad2015-12-24 01:02:05 -0700156} // namespace face
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800157} // namespace nfd