Junxiao Shi | 2c29f3a | 2014-01-24 19:59:00 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 319f2c8 | 2015-01-07 14:56:53 -0800 | [diff] [blame] | 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. |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 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/>. |
Alexander Afanasyev | 319f2c8 | 2015-01-07 14:56:53 -0800 | [diff] [blame] | 24 | */ |
Junxiao Shi | 2c29f3a | 2014-01-24 19:59:00 -0700 | [diff] [blame] | 25 | |
| 26 | #include "face/face.hpp" |
| 27 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 28 | #include "tests/test-common.hpp" |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 29 | #include "dummy-face.hpp" |
Junxiao Shi | 2c29f3a | 2014-01-24 19:59:00 -0700 | [diff] [blame] | 30 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 31 | namespace nfd { |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 32 | namespace face { |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 33 | namespace tests { |
Junxiao Shi | 2c29f3a | 2014-01-24 19:59:00 -0700 | [diff] [blame] | 34 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 35 | using namespace nfd::tests; |
Junxiao Shi | 2c29f3a | 2014-01-24 19:59:00 -0700 | [diff] [blame] | 36 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 37 | BOOST_AUTO_TEST_SUITE(Face) |
| 38 | BOOST_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 | |
| 44 | BOOST_AUTO_TEST_CASE(LinkServiceSendReceive) |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 45 | { |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 46 | 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 Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 105 | } |
Junxiao Shi | 2c29f3a | 2014-01-24 19:59:00 -0700 | [diff] [blame] | 106 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 107 | BOOST_AUTO_TEST_SUITE_END() // TestFace |
| 108 | BOOST_AUTO_TEST_SUITE_END() // Face |
Junxiao Shi | 2c29f3a | 2014-01-24 19:59:00 -0700 | [diff] [blame] | 109 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 110 | } // namespace tests |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 111 | } // namespace face |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 112 | } // namespace nfd |