blob: 7d0dba0f33d6943e454d7d7fe53b54817177db4d [file] [log] [blame]
Junxiao Shi2c29f3a2014-01-24 19:59:00 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev319f2c82015-01-07 14:56:53 -08003 * 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.
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"
Junxiao Shi2c29f3a2014-01-24 19:59:00 -070030
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080031namespace nfd {
Junxiao Shicde37ad2015-12-24 01:02:05 -070032namespace face {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070033namespace tests {
Junxiao Shi2c29f3a2014-01-24 19:59:00 -070034
Junxiao Shicde37ad2015-12-24 01:02:05 -070035using namespace nfd::tests;
Junxiao Shi2c29f3a2014-01-24 19:59:00 -070036
Junxiao Shicde37ad2015-12-24 01:02:05 -070037BOOST_AUTO_TEST_SUITE(Face)
38BOOST_FIXTURE_TEST_SUITE(TestFace, BaseFixture)
39
40// TODO add test cases for getLinkService, getTransport
41// TODO add a test case for static properties
42// TODO add a test case for getState
43
44BOOST_AUTO_TEST_CASE(LinkServiceSendReceive)
Junxiao Shi32bfeb32014-01-25 18:22:02 -070045{
Junxiao Shicde37ad2015-12-24 01:02:05 -070046 auto face1 = make_shared<DummyFace>();
47
48 const size_t nInInterests = 192;
49 const size_t nInData = 91;
50 const size_t nInNacks = 29;
51 const size_t nOutInterests = 202;
52 const size_t nOutData = 128;
53 const size_t nOutNacks = 84;
54
55 size_t nReceivedInterests = 0;
56 size_t nReceivedData = 0;
57 size_t nReceivedNacks = 0;
58 face1->afterReceiveInterest.connect(bind([&nReceivedInterests] { ++nReceivedInterests; }));
59 face1->afterReceiveData.connect(bind([&nReceivedData] { ++nReceivedData; }));
60 face1->afterReceiveNack.connect(bind([&nReceivedNacks] { ++nReceivedNacks; }));
61
62 for (size_t i = 0; i < nInInterests; ++i) {
63 shared_ptr<Interest> interest = makeInterest("/JSQdqward4");
64 face1->receiveInterest(*interest);
65 }
66
67 for (size_t i = 0; i < nInData; ++i) {
68 shared_ptr<Data> data = makeData("/hT8FDigWn1");
69 face1->receiveData(*data);
70 }
71
72 for (size_t i = 0; i < nInNacks; ++i) {
73 lp::Nack nack = makeNack("/StnEVTj4Ex", 561, lp::NackReason::CONGESTION);
74 face1->receiveNack(nack);
75 }
76
77 for (size_t i = 0; i < nOutInterests; ++i) {
78 shared_ptr<Interest> interest = makeInterest("/XyUAFYQDmd");
79 face1->sendInterest(*interest);
80 }
81
82 for (size_t i = 0; i < nOutData; ++i) {
83 shared_ptr<Data> data = makeData("/GigPEtPH6");
84 face1->sendData(*data);
85 }
86
87 for (size_t i = 0; i < nOutNacks; ++i) {
88 lp::Nack nack = makeNack("/9xK6FbwIBM", 365, lp::NackReason::CONGESTION);
89 face1->sendNack(nack);
90 }
91
92 BOOST_CHECK_EQUAL(face1->getCounters().nInInterests, nInInterests);
93 BOOST_CHECK_EQUAL(face1->getCounters().nInData, nInData);
94 BOOST_CHECK_EQUAL(face1->getCounters().nInNacks, nInNacks);
95 BOOST_CHECK_EQUAL(face1->getCounters().nOutInterests, nOutInterests);
96 BOOST_CHECK_EQUAL(face1->getCounters().nOutData, nOutData);
97 BOOST_CHECK_EQUAL(face1->getCounters().nOutNacks, nOutNacks);
98
99 BOOST_CHECK_EQUAL(nReceivedInterests, nInInterests);
100 BOOST_CHECK_EQUAL(nReceivedData, nInData);
101 BOOST_CHECK_EQUAL(nReceivedNacks, nInNacks);
102 BOOST_CHECK_EQUAL(face1->sentInterests.size(), nOutInterests);
103 BOOST_CHECK_EQUAL(face1->sentData.size(), nOutData);
104 BOOST_CHECK_EQUAL(face1->sentNacks.size(), nOutNacks);
Junxiao Shi32bfeb32014-01-25 18:22:02 -0700105}
Junxiao Shi2c29f3a2014-01-24 19:59:00 -0700106
Junxiao Shicde37ad2015-12-24 01:02:05 -0700107BOOST_AUTO_TEST_SUITE_END() // TestFace
108BOOST_AUTO_TEST_SUITE_END() // Face
Junxiao Shi2c29f3a2014-01-24 19:59:00 -0700109
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700110} // namespace tests
Junxiao Shicde37ad2015-12-24 01:02:05 -0700111} // namespace face
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800112} // namespace nfd