Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 1 | /* -*- 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 | |
| 32 | namespace nfd { |
| 33 | namespace face { |
| 34 | namespace tests { |
| 35 | |
| 36 | using namespace nfd::tests; |
| 37 | |
| 38 | BOOST_AUTO_TEST_SUITE(Face) |
| 39 | BOOST_FIXTURE_TEST_SUITE(TestLpFaceWrapper, BaseFixture) |
| 40 | |
| 41 | BOOST_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 | |
| 57 | BOOST_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 | |
| 74 | BOOST_AUTO_TEST_CASE(FailSignal) |
| 75 | { |
| 76 | auto face1w = make_shared<face::LpFaceWrapper>(make_unique<DummyLpFace>()); |
| 77 | auto face1 = static_cast<DummyLpFace*>(face1w->getLpFace()); |
| 78 | |
| 79 | bool isFailed = false; |
| 80 | face1w->onFail.connect(bind([&isFailed] { isFailed = true; })); |
| 81 | |
| 82 | face1->setState(FaceState::DOWN); |
| 83 | BOOST_CHECK(!isFailed); |
| 84 | |
| 85 | face1->setState(FaceState::FAILED); |
| 86 | BOOST_CHECK(!isFailed); |
| 87 | |
| 88 | face1->setState(FaceState::CLOSED); |
| 89 | BOOST_CHECK(isFailed); |
| 90 | } |
| 91 | |
| 92 | BOOST_AUTO_TEST_CASE(SendReceive) |
| 93 | { |
| 94 | auto face1w = make_shared<face::LpFaceWrapper>(make_unique<DummyLpFace>()); |
| 95 | auto face1 = static_cast<DummyLpFace*>(face1w->getLpFace()); |
| 96 | |
| 97 | const size_t nInInterests = 192; |
| 98 | const size_t nInData = 91; |
| 99 | const size_t nInNacks = 29; |
| 100 | const size_t nOutInterests = 202; |
| 101 | const size_t nOutData = 128; |
| 102 | const size_t nOutNacks = 84; |
| 103 | |
| 104 | size_t nReceivedInterests = 0; |
| 105 | size_t nReceivedData = 0; |
| 106 | size_t nReceivedNacks = 0; |
| 107 | face1w->onReceiveInterest.connect(bind([&nReceivedInterests] { ++nReceivedInterests; })); |
| 108 | face1w->onReceiveData.connect(bind([&nReceivedData] { ++nReceivedData; })); |
| 109 | face1w->onReceiveNack.connect(bind([&nReceivedNacks] { ++nReceivedNacks; })); |
| 110 | |
| 111 | BOOST_CHECK_EQUAL(face1->getCounters().getNInInterests(), 0); |
| 112 | BOOST_CHECK_EQUAL(face1->getCounters().getNInDatas(), 0); |
| 113 | BOOST_CHECK_EQUAL(face1->getCounters().getNOutInterests(), 0); |
| 114 | BOOST_CHECK_EQUAL(face1->getCounters().getNOutDatas(), 0); |
| 115 | BOOST_CHECK_EQUAL(face1w->getCounters().getNInInterests(), 0); |
| 116 | BOOST_CHECK_EQUAL(face1w->getCounters().getNInDatas(), 0); |
| 117 | BOOST_CHECK_EQUAL(face1w->getCounters().getNOutInterests(), 0); |
| 118 | BOOST_CHECK_EQUAL(face1w->getCounters().getNOutDatas(), 0); |
| 119 | // There's no counters for NACK for now. |
| 120 | |
| 121 | for (size_t i = 0; i < nInInterests; ++i) { |
| 122 | shared_ptr<Interest> interest = makeInterest("/JSQdqward4"); |
| 123 | face1->receiveInterest(*interest); |
| 124 | } |
| 125 | |
| 126 | for (size_t i = 0; i < nInData; ++i) { |
| 127 | shared_ptr<Data> data = makeData("/hT8FDigWn1"); |
| 128 | face1->receiveData(*data); |
| 129 | } |
| 130 | |
| 131 | for (size_t i = 0; i < nInNacks; ++i) { |
| 132 | lp::Nack nack = makeNack("/StnEVTj4Ex", 561, lp::NackReason::CONGESTION); |
| 133 | face1->receiveNack(nack); |
| 134 | } |
| 135 | |
| 136 | for (size_t i = 0; i < nOutInterests; ++i) { |
| 137 | shared_ptr<Interest> interest = makeInterest("/XyUAFYQDmd"); |
| 138 | face1w->sendInterest(*interest); |
| 139 | } |
| 140 | |
| 141 | for (size_t i = 0; i < nOutData; ++i) { |
| 142 | shared_ptr<Data> data = makeData("/GigPEtPH6"); |
| 143 | face1w->sendData(*data); |
| 144 | } |
| 145 | |
| 146 | for (size_t i = 0; i < nOutNacks; ++i) { |
| 147 | lp::Nack nack = makeNack("/9xK6FbwIBM", 365, lp::NackReason::CONGESTION); |
| 148 | face1w->sendNack(nack); |
| 149 | } |
| 150 | |
| 151 | BOOST_CHECK_EQUAL(face1->getCounters().getNInInterests(), nInInterests); |
| 152 | BOOST_CHECK_EQUAL(face1->getCounters().getNInDatas(), nInData); |
| 153 | BOOST_CHECK_EQUAL(face1->getCounters().getNOutInterests(), nOutInterests); |
| 154 | BOOST_CHECK_EQUAL(face1->getCounters().getNOutDatas(), nOutData); |
| 155 | BOOST_CHECK_EQUAL(face1w->getCounters().getNInInterests(), nInInterests); |
| 156 | BOOST_CHECK_EQUAL(face1w->getCounters().getNInDatas(), nInData); |
| 157 | BOOST_CHECK_EQUAL(face1w->getCounters().getNOutInterests(), nOutInterests); |
| 158 | BOOST_CHECK_EQUAL(face1w->getCounters().getNOutDatas(), nOutData); |
| 159 | |
| 160 | BOOST_CHECK_EQUAL(nReceivedInterests, nInInterests); |
| 161 | BOOST_CHECK_EQUAL(nReceivedData, nInData); |
| 162 | BOOST_CHECK_EQUAL(nReceivedNacks, nInNacks); |
| 163 | BOOST_CHECK_EQUAL(face1->sentInterests.size(), nOutInterests); |
| 164 | BOOST_CHECK_EQUAL(face1->sentData.size(), nOutData); |
| 165 | BOOST_CHECK_EQUAL(face1->sentNacks.size(), nOutNacks); |
| 166 | } |
| 167 | |
| 168 | BOOST_AUTO_TEST_SUITE_END() |
| 169 | BOOST_AUTO_TEST_SUITE_END() |
| 170 | |
| 171 | } // namespace tests |
| 172 | } // namespace face |
| 173 | } // namespace nfd |