Steve DiBenedetto | 5b43398 | 2014-01-29 17:14:27 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014 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 | * |
| 10 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 11 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 12 | * |
| 13 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 14 | * of the GNU General Public License as published by the Free Software Foundation, |
| 15 | * either version 3 of the License, or (at your option) any later version. |
| 16 | * |
| 17 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 18 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 19 | * PURPOSE. See the GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License along with |
| 22 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 23 | **/ |
Steve DiBenedetto | 5b43398 | 2014-01-29 17:14:27 -0700 | [diff] [blame] | 24 | |
| 25 | #include "mgmt/internal-face.hpp" |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 26 | #include "tests/face/dummy-face.hpp" |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 27 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 28 | #include "tests/test-common.hpp" |
Steve DiBenedetto | 5b43398 | 2014-01-29 17:14:27 -0700 | [diff] [blame] | 29 | |
| 30 | namespace nfd { |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 31 | namespace tests { |
Steve DiBenedetto | 5b43398 | 2014-01-29 17:14:27 -0700 | [diff] [blame] | 32 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 33 | NFD_LOG_INIT("InternalFaceTest"); |
| 34 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 35 | class InternalFaceFixture : protected BaseFixture |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 36 | { |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 37 | public: |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 38 | |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 39 | InternalFaceFixture() |
| 40 | : m_onInterestFired(false), |
| 41 | m_noOnInterestFired(false) |
| 42 | { |
| 43 | |
| 44 | } |
| 45 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 46 | void |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 47 | validateOnInterestCallback(const Name& name, const Interest& interest) |
| 48 | { |
| 49 | m_onInterestFired = true; |
| 50 | } |
| 51 | |
| 52 | void |
| 53 | validateNoOnInterestCallback(const Name& name, const Interest& interest) |
| 54 | { |
| 55 | m_noOnInterestFired = true; |
| 56 | } |
| 57 | |
| 58 | void |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 59 | addFace(shared_ptr<Face> face) |
| 60 | { |
| 61 | m_faces.push_back(face); |
| 62 | } |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 63 | |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 64 | bool |
| 65 | didOnInterestFire() |
| 66 | { |
| 67 | return m_onInterestFired; |
| 68 | } |
| 69 | |
| 70 | bool |
| 71 | didNoOnInterestFire() |
| 72 | { |
| 73 | return m_noOnInterestFired; |
| 74 | } |
| 75 | |
| 76 | void |
| 77 | resetOnInterestFired() |
| 78 | { |
| 79 | m_onInterestFired = false; |
| 80 | } |
| 81 | |
| 82 | void |
| 83 | resetNoOnInterestFired() |
| 84 | { |
| 85 | m_noOnInterestFired = false; |
| 86 | } |
| 87 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 88 | private: |
| 89 | std::vector<shared_ptr<Face> > m_faces; |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 90 | bool m_onInterestFired; |
| 91 | bool m_noOnInterestFired; |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 92 | }; |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 93 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 94 | BOOST_FIXTURE_TEST_SUITE(MgmtInternalFace, InternalFaceFixture) |
Steve DiBenedetto | 5b43398 | 2014-01-29 17:14:27 -0700 | [diff] [blame] | 95 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 96 | void |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 97 | validatePutData(bool& called, const Name& expectedName, const Data& data) |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 98 | { |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 99 | called = true; |
| 100 | BOOST_CHECK_EQUAL(expectedName, data.getName()); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 103 | BOOST_AUTO_TEST_CASE(PutData) |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 104 | { |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 105 | addFace(make_shared<DummyFace>()); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 106 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 107 | shared_ptr<InternalFace> face(new InternalFace); |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 108 | |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 109 | bool didPutData = false; |
| 110 | Name dataName("/hello"); |
| 111 | face->onReceiveData += bind(&validatePutData, boost::ref(didPutData), dataName, _1); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 112 | |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 113 | Data testData(dataName); |
| 114 | face->sign(testData); |
| 115 | face->put(testData); |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 116 | |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 117 | BOOST_REQUIRE(didPutData); |
Alexander Afanasyev | a0a10fb | 2014-02-13 19:56:15 -0800 | [diff] [blame] | 118 | |
| 119 | BOOST_CHECK_THROW(face->close(), InternalFace::Error); |
Steve DiBenedetto | 5b43398 | 2014-01-29 17:14:27 -0700 | [diff] [blame] | 120 | } |
| 121 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 122 | BOOST_AUTO_TEST_CASE(SendInterestHitEnd) |
Steve DiBenedetto | 5b43398 | 2014-01-29 17:14:27 -0700 | [diff] [blame] | 123 | { |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 124 | addFace(make_shared<DummyFace>()); |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 125 | |
| 126 | shared_ptr<InternalFace> face(new InternalFace); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 127 | |
| 128 | face->setInterestFilter("/localhost/nfd/fib", |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 129 | bind(&InternalFaceFixture::validateOnInterestCallback, |
| 130 | this, _1, _2)); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 131 | |
| 132 | // generate command whose name is canonically |
| 133 | // ordered after /localhost/nfd/fib so that |
| 134 | // we hit the end of the std::map |
| 135 | |
| 136 | Name commandName("/localhost/nfd/fib/end"); |
Junxiao Shi | 72c3e04 | 2014-04-08 15:02:37 -0700 | [diff] [blame] | 137 | shared_ptr<Interest> command = makeInterest(commandName); |
| 138 | face->sendInterest(*command); |
Junxiao Shi | 16d1b7d | 2014-03-27 21:29:09 -0700 | [diff] [blame] | 139 | g_io.run_one(); |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 140 | |
| 141 | BOOST_REQUIRE(didOnInterestFire()); |
| 142 | BOOST_REQUIRE(didNoOnInterestFire() == false); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 143 | } |
| 144 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 145 | BOOST_AUTO_TEST_CASE(SendInterestHitBegin) |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 146 | { |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 147 | addFace(make_shared<DummyFace>()); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 148 | |
| 149 | shared_ptr<InternalFace> face(new InternalFace); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 150 | |
| 151 | face->setInterestFilter("/localhost/nfd/fib", |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 152 | bind(&InternalFaceFixture::validateNoOnInterestCallback, |
| 153 | this, _1, _2)); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 154 | |
| 155 | // generate command whose name is canonically |
| 156 | // ordered before /localhost/nfd/fib so that |
| 157 | // we hit the beginning of the std::map |
| 158 | |
| 159 | Name commandName("/localhost/nfd"); |
Junxiao Shi | 72c3e04 | 2014-04-08 15:02:37 -0700 | [diff] [blame] | 160 | shared_ptr<Interest> command = makeInterest(commandName); |
| 161 | face->sendInterest(*command); |
Junxiao Shi | 16d1b7d | 2014-03-27 21:29:09 -0700 | [diff] [blame] | 162 | g_io.run_one(); |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 163 | |
| 164 | BOOST_REQUIRE(didNoOnInterestFire() == false); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 167 | BOOST_AUTO_TEST_CASE(SendInterestHitExact) |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 168 | { |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 169 | addFace(make_shared<DummyFace>()); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 170 | |
| 171 | shared_ptr<InternalFace> face(new InternalFace); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 172 | |
| 173 | face->setInterestFilter("/localhost/nfd/eib", |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 174 | bind(&InternalFaceFixture::validateNoOnInterestCallback, |
| 175 | this, _1, _2)); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 176 | |
| 177 | face->setInterestFilter("/localhost/nfd/fib", |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 178 | bind(&InternalFaceFixture::validateOnInterestCallback, |
| 179 | this, _1, _2)); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 180 | |
| 181 | face->setInterestFilter("/localhost/nfd/gib", |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 182 | bind(&InternalFaceFixture::validateNoOnInterestCallback, |
| 183 | this, _1, _2)); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 184 | |
| 185 | // generate command whose name exactly matches |
| 186 | // /localhost/nfd/fib |
| 187 | |
| 188 | Name commandName("/localhost/nfd/fib"); |
Junxiao Shi | 72c3e04 | 2014-04-08 15:02:37 -0700 | [diff] [blame] | 189 | shared_ptr<Interest> command = makeInterest(commandName); |
| 190 | face->sendInterest(*command); |
Junxiao Shi | 16d1b7d | 2014-03-27 21:29:09 -0700 | [diff] [blame] | 191 | g_io.run_one(); |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 192 | |
| 193 | BOOST_REQUIRE(didOnInterestFire()); |
| 194 | BOOST_REQUIRE(didNoOnInterestFire() == false); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 195 | } |
| 196 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 197 | BOOST_AUTO_TEST_CASE(SendInterestHitPrevious) |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 198 | { |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 199 | addFace(make_shared<DummyFace>()); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 200 | |
| 201 | shared_ptr<InternalFace> face(new InternalFace); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 202 | |
| 203 | face->setInterestFilter("/localhost/nfd/fib", |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 204 | bind(&InternalFaceFixture::validateOnInterestCallback, |
| 205 | this, _1, _2)); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 206 | |
| 207 | face->setInterestFilter("/localhost/nfd/fib/zzzzzzzzzzzzz/", |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 208 | bind(&InternalFaceFixture::validateNoOnInterestCallback, |
| 209 | this, _1, _2)); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 210 | |
| 211 | // generate command whose name exactly matches |
| 212 | // an Interest filter |
| 213 | |
| 214 | Name commandName("/localhost/nfd/fib/previous"); |
Junxiao Shi | 72c3e04 | 2014-04-08 15:02:37 -0700 | [diff] [blame] | 215 | shared_ptr<Interest> command = makeInterest(commandName); |
| 216 | face->sendInterest(*command); |
Junxiao Shi | 16d1b7d | 2014-03-27 21:29:09 -0700 | [diff] [blame] | 217 | g_io.run_one(); |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 218 | |
| 219 | BOOST_REQUIRE(didOnInterestFire()); |
| 220 | BOOST_REQUIRE(didNoOnInterestFire() == false); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 221 | } |
| 222 | |
Junxiao Shi | 72c3e04 | 2014-04-08 15:02:37 -0700 | [diff] [blame] | 223 | BOOST_AUTO_TEST_CASE(InterestGone) |
| 224 | { |
| 225 | shared_ptr<InternalFace> face = make_shared<InternalFace>(); |
| 226 | shared_ptr<Interest> interest = makeInterest("ndn:/localhost/nfd/gone"); |
| 227 | face->sendInterest(*interest); |
| 228 | |
| 229 | interest.reset(); |
| 230 | BOOST_CHECK_NO_THROW(g_io.poll()); |
| 231 | } |
| 232 | |
Steve DiBenedetto | 5b43398 | 2014-01-29 17:14:27 -0700 | [diff] [blame] | 233 | BOOST_AUTO_TEST_SUITE_END() |
| 234 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 235 | } // namespace tests |
Steve DiBenedetto | 5b43398 | 2014-01-29 17:14:27 -0700 | [diff] [blame] | 236 | } // namespace nfd |