blob: 92a3755ea5848df82e45040ee74d1cd581026325 [file] [log] [blame]
Junxiao Shida93f1f2015-11-11 06:13:16 -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.hpp"
27
28#include "tests/test-common.hpp"
29#include "dummy-lp-face.hpp"
30
31namespace nfd {
32namespace face {
33namespace tests {
34
35using namespace nfd::tests;
36
37BOOST_AUTO_TEST_SUITE(Face)
38BOOST_FIXTURE_TEST_SUITE(TestLpFace, BaseFixture)
39
40BOOST_AUTO_TEST_CASE(LinkServiceSendReceive)
41{
42 auto face1 = make_shared<DummyLpFace>();
43
44 const size_t nInInterests = 192;
45 const size_t nInData = 91;
46 const size_t nInNacks = 29;
47 const size_t nOutInterests = 202;
48 const size_t nOutData = 128;
49 const size_t nOutNacks = 84;
50
51 size_t nReceivedInterests = 0;
52 size_t nReceivedData = 0;
53 size_t nReceivedNacks = 0;
54 face1->afterReceiveInterest.connect(bind([&nReceivedInterests] { ++nReceivedInterests; }));
55 face1->afterReceiveData.connect(bind([&nReceivedData] { ++nReceivedData; }));
56 face1->afterReceiveNack.connect(bind([&nReceivedNacks] { ++nReceivedNacks; }));
57
58 for (size_t i = 0; i < nInInterests; ++i) {
59 shared_ptr<Interest> interest = makeInterest("/JSQdqward4");
60 face1->receiveInterest(*interest);
61 }
62
63 for (size_t i = 0; i < nInData; ++i) {
64 shared_ptr<Data> data = makeData("/hT8FDigWn1");
65 face1->receiveData(*data);
66 }
67
68 for (size_t i = 0; i < nInNacks; ++i) {
69 lp::Nack nack = makeNack("/StnEVTj4Ex", 561, lp::NackReason::CONGESTION);
70 face1->receiveNack(nack);
71 }
72
73 for (size_t i = 0; i < nOutInterests; ++i) {
74 shared_ptr<Interest> interest = makeInterest("/XyUAFYQDmd");
75 face1->sendInterest(*interest);
76 }
77
78 for (size_t i = 0; i < nOutData; ++i) {
79 shared_ptr<Data> data = makeData("/GigPEtPH6");
80 face1->sendData(*data);
81 }
82
83 for (size_t i = 0; i < nOutNacks; ++i) {
84 lp::Nack nack = makeNack("/9xK6FbwIBM", 365, lp::NackReason::CONGESTION);
85 face1->sendNack(nack);
86 }
87
88 BOOST_CHECK_EQUAL(face1->getCounters().nInInterests, nInInterests);
89 BOOST_CHECK_EQUAL(face1->getCounters().nInData, nInData);
90 BOOST_CHECK_EQUAL(face1->getCounters().nInNacks, nInNacks);
91 BOOST_CHECK_EQUAL(face1->getCounters().nOutInterests, nOutInterests);
92 BOOST_CHECK_EQUAL(face1->getCounters().nOutData, nOutData);
93 BOOST_CHECK_EQUAL(face1->getCounters().nOutNacks, nOutNacks);
94
95 BOOST_CHECK_EQUAL(nReceivedInterests, nInInterests);
96 BOOST_CHECK_EQUAL(nReceivedData, nInData);
97 BOOST_CHECK_EQUAL(nReceivedNacks, nInNacks);
98 BOOST_CHECK_EQUAL(face1->sentInterests.size(), nOutInterests);
99 BOOST_CHECK_EQUAL(face1->sentData.size(), nOutData);
100 BOOST_CHECK_EQUAL(face1->sentNacks.size(), nOutNacks);
101}
102
103BOOST_AUTO_TEST_SUITE_END()
104BOOST_AUTO_TEST_SUITE_END()
105
106} // namespace tests
107} // namespace face
108} // namespace nfd