blob: 8217d77baad7a7835d774d13729c07dd1b43238d [file] [log] [blame]
Eric Newberrya98bf932015-09-21 00:58:47 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2015, Regents of the University of California,
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.
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/>.
24 */
25
26#include "face/lp-face-wrapper.hpp"
27#include "fw/forwarder.hpp"
28
29#include "tests/test-common.hpp"
30#include "dummy-lp-face.hpp"
31
32namespace nfd {
33namespace face {
34namespace tests {
35
36using namespace nfd::tests;
37
38BOOST_AUTO_TEST_SUITE(Face)
39BOOST_FIXTURE_TEST_SUITE(TestLpFaceWrapper, BaseFixture)
40
41BOOST_AUTO_TEST_CASE(SetId)
42{
43 Forwarder forwarder;
44 auto face1w = make_shared<face::LpFaceWrapper>(make_unique<DummyLpFace>());
45 auto face1 = static_cast<DummyLpFace*>(face1w->getLpFace());
46
47 BOOST_CHECK_EQUAL(face1->getId(), nfd::face::INVALID_FACEID);
48 BOOST_CHECK_EQUAL(face1w->getId(), nfd::INVALID_FACEID);
49
50 forwarder.addFace(face1w);
51
52 BOOST_CHECK_NE(face1->getId(), nfd::face::INVALID_FACEID);
53 BOOST_CHECK_NE(face1w->getId(), nfd::INVALID_FACEID);
54 BOOST_CHECK_EQUAL(face1->getId(), static_cast<face::FaceId>(face1w->getId()));
55}
56
57BOOST_AUTO_TEST_CASE(SetPersistency)
58{
59 unique_ptr<LpFace> face1u = make_unique<DummyLpFace>();
60 face1u->setPersistency(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
61
62 auto face1w = make_shared<face::LpFaceWrapper>(std::move(face1u));
63 auto face1 = static_cast<DummyLpFace*>(face1w->getLpFace());
64
65 BOOST_CHECK_EQUAL(face1->getPersistency(), ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
66 BOOST_CHECK_EQUAL(face1w->getPersistency(), ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
67
68 face1w->setPersistency(ndn::nfd::FACE_PERSISTENCY_PERMANENT);
69
70 BOOST_CHECK_EQUAL(face1->getPersistency(), ndn::nfd::FACE_PERSISTENCY_PERMANENT);
71 BOOST_CHECK_EQUAL(face1w->getPersistency(), ndn::nfd::FACE_PERSISTENCY_PERMANENT);
72}
73
Junxiao Shida93f1f2015-11-11 06:13:16 -070074BOOST_AUTO_TEST_CASE(Counters)
75{
76 auto face1w = make_shared<face::LpFaceWrapper>(make_unique<DummyLpFace>());
77 auto face1 = static_cast<DummyLpFace*>(face1w->getLpFace());
78
79 BOOST_CHECK(&face1->getCounters() == &face1w->getCounters());
80}
81
Eric Newberrya98bf932015-09-21 00:58:47 -070082BOOST_AUTO_TEST_CASE(FailSignal)
83{
84 auto face1w = make_shared<face::LpFaceWrapper>(make_unique<DummyLpFace>());
85 auto face1 = static_cast<DummyLpFace*>(face1w->getLpFace());
86
87 bool isFailed = false;
88 face1w->onFail.connect(bind([&isFailed] { isFailed = true; }));
89
90 face1->setState(FaceState::DOWN);
91 BOOST_CHECK(!isFailed);
92
93 face1->setState(FaceState::FAILED);
94 BOOST_CHECK(!isFailed);
95
96 face1->setState(FaceState::CLOSED);
97 BOOST_CHECK(isFailed);
98}
99
100BOOST_AUTO_TEST_CASE(SendReceive)
101{
102 auto face1w = make_shared<face::LpFaceWrapper>(make_unique<DummyLpFace>());
103 auto face1 = static_cast<DummyLpFace*>(face1w->getLpFace());
104
105 const size_t nInInterests = 192;
106 const size_t nInData = 91;
107 const size_t nInNacks = 29;
108 const size_t nOutInterests = 202;
109 const size_t nOutData = 128;
110 const size_t nOutNacks = 84;
111
112 size_t nReceivedInterests = 0;
113 size_t nReceivedData = 0;
114 size_t nReceivedNacks = 0;
115 face1w->onReceiveInterest.connect(bind([&nReceivedInterests] { ++nReceivedInterests; }));
116 face1w->onReceiveData.connect(bind([&nReceivedData] { ++nReceivedData; }));
117 face1w->onReceiveNack.connect(bind([&nReceivedNacks] { ++nReceivedNacks; }));
118
Eric Newberrya98bf932015-09-21 00:58:47 -0700119 for (size_t i = 0; i < nInInterests; ++i) {
120 shared_ptr<Interest> interest = makeInterest("/JSQdqward4");
121 face1->receiveInterest(*interest);
122 }
123
124 for (size_t i = 0; i < nInData; ++i) {
125 shared_ptr<Data> data = makeData("/hT8FDigWn1");
126 face1->receiveData(*data);
127 }
128
129 for (size_t i = 0; i < nInNacks; ++i) {
130 lp::Nack nack = makeNack("/StnEVTj4Ex", 561, lp::NackReason::CONGESTION);
131 face1->receiveNack(nack);
132 }
133
134 for (size_t i = 0; i < nOutInterests; ++i) {
135 shared_ptr<Interest> interest = makeInterest("/XyUAFYQDmd");
136 face1w->sendInterest(*interest);
137 }
138
139 for (size_t i = 0; i < nOutData; ++i) {
140 shared_ptr<Data> data = makeData("/GigPEtPH6");
141 face1w->sendData(*data);
142 }
143
144 for (size_t i = 0; i < nOutNacks; ++i) {
145 lp::Nack nack = makeNack("/9xK6FbwIBM", 365, lp::NackReason::CONGESTION);
146 face1w->sendNack(nack);
147 }
148
Eric Newberrya98bf932015-09-21 00:58:47 -0700149 BOOST_CHECK_EQUAL(nReceivedInterests, nInInterests);
150 BOOST_CHECK_EQUAL(nReceivedData, nInData);
151 BOOST_CHECK_EQUAL(nReceivedNacks, nInNacks);
152 BOOST_CHECK_EQUAL(face1->sentInterests.size(), nOutInterests);
153 BOOST_CHECK_EQUAL(face1->sentData.size(), nOutData);
154 BOOST_CHECK_EQUAL(face1->sentNacks.size(), nOutNacks);
155}
156
157BOOST_AUTO_TEST_SUITE_END()
158BOOST_AUTO_TEST_SUITE_END()
159
160} // namespace tests
161} // namespace face
162} // namespace nfd