Steve DiBenedetto | 5b43398 | 2014-01-29 17:14:27 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Vince Lehman | 5144f82 | 2014-07-23 15:12:56 -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 | * 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/>. |
Vince Lehman | 5144f82 | 2014-07-23 15:12:56 -0700 | [diff] [blame^] | 24 | */ |
Steve DiBenedetto | 5b43398 | 2014-01-29 17:14:27 -0700 | [diff] [blame] | 25 | |
| 26 | #include "mgmt/internal-face.hpp" |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 27 | #include "tests/daemon/face/dummy-face.hpp" |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 28 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 29 | #include "tests/test-common.hpp" |
Steve DiBenedetto | 5b43398 | 2014-01-29 17:14:27 -0700 | [diff] [blame] | 30 | |
| 31 | namespace nfd { |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 32 | namespace tests { |
Steve DiBenedetto | 5b43398 | 2014-01-29 17:14:27 -0700 | [diff] [blame] | 33 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 34 | NFD_LOG_INIT("InternalFaceTest"); |
| 35 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 36 | class InternalFaceFixture : protected BaseFixture |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 37 | { |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 38 | public: |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 39 | |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 40 | InternalFaceFixture() |
| 41 | : m_onInterestFired(false), |
| 42 | m_noOnInterestFired(false) |
| 43 | { |
| 44 | |
| 45 | } |
| 46 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 47 | void |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 48 | validateOnInterestCallback(const Name& name, const Interest& interest) |
| 49 | { |
| 50 | m_onInterestFired = true; |
| 51 | } |
| 52 | |
| 53 | void |
| 54 | validateNoOnInterestCallback(const Name& name, const Interest& interest) |
| 55 | { |
| 56 | m_noOnInterestFired = true; |
| 57 | } |
| 58 | |
| 59 | void |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 60 | addFace(shared_ptr<Face> face) |
| 61 | { |
| 62 | m_faces.push_back(face); |
| 63 | } |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 64 | |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 65 | bool |
| 66 | didOnInterestFire() |
| 67 | { |
| 68 | return m_onInterestFired; |
| 69 | } |
| 70 | |
| 71 | bool |
| 72 | didNoOnInterestFire() |
| 73 | { |
| 74 | return m_noOnInterestFired; |
| 75 | } |
| 76 | |
| 77 | void |
| 78 | resetOnInterestFired() |
| 79 | { |
| 80 | m_onInterestFired = false; |
| 81 | } |
| 82 | |
| 83 | void |
| 84 | resetNoOnInterestFired() |
| 85 | { |
| 86 | m_noOnInterestFired = false; |
| 87 | } |
| 88 | |
Vince Lehman | 5144f82 | 2014-07-23 15:12:56 -0700 | [diff] [blame^] | 89 | protected: |
| 90 | ndn::KeyChain m_keyChain; |
| 91 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 92 | private: |
| 93 | std::vector<shared_ptr<Face> > m_faces; |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 94 | bool m_onInterestFired; |
| 95 | bool m_noOnInterestFired; |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 96 | }; |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 97 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 98 | BOOST_FIXTURE_TEST_SUITE(MgmtInternalFace, InternalFaceFixture) |
Steve DiBenedetto | 5b43398 | 2014-01-29 17:14:27 -0700 | [diff] [blame] | 99 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 100 | void |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 101 | validatePutData(bool& called, const Name& expectedName, const Data& data) |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 102 | { |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 103 | called = true; |
| 104 | BOOST_CHECK_EQUAL(expectedName, data.getName()); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 105 | } |
| 106 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 107 | BOOST_AUTO_TEST_CASE(PutData) |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 108 | { |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 109 | addFace(make_shared<DummyFace>()); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 110 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 111 | shared_ptr<InternalFace> face(new InternalFace); |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 112 | |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 113 | bool didPutData = false; |
| 114 | Name dataName("/hello"); |
Alexander Afanasyev | f698028 | 2014-05-13 18:28:40 -0700 | [diff] [blame] | 115 | face->onReceiveData += bind(&validatePutData, ref(didPutData), dataName, _1); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 116 | |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 117 | Data testData(dataName); |
Vince Lehman | 5144f82 | 2014-07-23 15:12:56 -0700 | [diff] [blame^] | 118 | m_keyChain.sign(testData); |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 119 | face->put(testData); |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 120 | |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 121 | BOOST_REQUIRE(didPutData); |
Alexander Afanasyev | a0a10fb | 2014-02-13 19:56:15 -0800 | [diff] [blame] | 122 | |
| 123 | BOOST_CHECK_THROW(face->close(), InternalFace::Error); |
Steve DiBenedetto | 5b43398 | 2014-01-29 17:14:27 -0700 | [diff] [blame] | 124 | } |
| 125 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 126 | BOOST_AUTO_TEST_CASE(SendInterestHitEnd) |
Steve DiBenedetto | 5b43398 | 2014-01-29 17:14:27 -0700 | [diff] [blame] | 127 | { |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 128 | addFace(make_shared<DummyFace>()); |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 129 | |
| 130 | shared_ptr<InternalFace> face(new InternalFace); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 131 | |
| 132 | face->setInterestFilter("/localhost/nfd/fib", |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 133 | bind(&InternalFaceFixture::validateOnInterestCallback, |
| 134 | this, _1, _2)); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 135 | |
| 136 | // generate command whose name is canonically |
| 137 | // ordered after /localhost/nfd/fib so that |
| 138 | // we hit the end of the std::map |
| 139 | |
| 140 | Name commandName("/localhost/nfd/fib/end"); |
Junxiao Shi | 72c3e04 | 2014-04-08 15:02:37 -0700 | [diff] [blame] | 141 | shared_ptr<Interest> command = makeInterest(commandName); |
| 142 | face->sendInterest(*command); |
Junxiao Shi | 16d1b7d | 2014-03-27 21:29:09 -0700 | [diff] [blame] | 143 | g_io.run_one(); |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 144 | |
| 145 | BOOST_REQUIRE(didOnInterestFire()); |
| 146 | BOOST_REQUIRE(didNoOnInterestFire() == false); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 149 | BOOST_AUTO_TEST_CASE(SendInterestHitBegin) |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 150 | { |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 151 | addFace(make_shared<DummyFace>()); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 152 | |
| 153 | shared_ptr<InternalFace> face(new InternalFace); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 154 | |
| 155 | face->setInterestFilter("/localhost/nfd/fib", |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 156 | bind(&InternalFaceFixture::validateNoOnInterestCallback, |
| 157 | this, _1, _2)); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 158 | |
| 159 | // generate command whose name is canonically |
| 160 | // ordered before /localhost/nfd/fib so that |
| 161 | // we hit the beginning of the std::map |
| 162 | |
| 163 | Name commandName("/localhost/nfd"); |
Junxiao Shi | 72c3e04 | 2014-04-08 15:02:37 -0700 | [diff] [blame] | 164 | shared_ptr<Interest> command = makeInterest(commandName); |
| 165 | face->sendInterest(*command); |
Junxiao Shi | 16d1b7d | 2014-03-27 21:29:09 -0700 | [diff] [blame] | 166 | g_io.run_one(); |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 167 | |
| 168 | BOOST_REQUIRE(didNoOnInterestFire() == false); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 171 | BOOST_AUTO_TEST_CASE(SendInterestHitExact) |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 172 | { |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 173 | addFace(make_shared<DummyFace>()); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 174 | |
| 175 | shared_ptr<InternalFace> face(new InternalFace); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 176 | |
| 177 | face->setInterestFilter("/localhost/nfd/eib", |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 178 | bind(&InternalFaceFixture::validateNoOnInterestCallback, |
| 179 | this, _1, _2)); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 180 | |
| 181 | face->setInterestFilter("/localhost/nfd/fib", |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 182 | bind(&InternalFaceFixture::validateOnInterestCallback, |
| 183 | this, _1, _2)); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 184 | |
| 185 | face->setInterestFilter("/localhost/nfd/gib", |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 186 | bind(&InternalFaceFixture::validateNoOnInterestCallback, |
| 187 | this, _1, _2)); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 188 | |
| 189 | // generate command whose name exactly matches |
| 190 | // /localhost/nfd/fib |
| 191 | |
| 192 | Name commandName("/localhost/nfd/fib"); |
Junxiao Shi | 72c3e04 | 2014-04-08 15:02:37 -0700 | [diff] [blame] | 193 | shared_ptr<Interest> command = makeInterest(commandName); |
| 194 | face->sendInterest(*command); |
Junxiao Shi | 16d1b7d | 2014-03-27 21:29:09 -0700 | [diff] [blame] | 195 | g_io.run_one(); |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 196 | |
| 197 | BOOST_REQUIRE(didOnInterestFire()); |
| 198 | BOOST_REQUIRE(didNoOnInterestFire() == false); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 201 | BOOST_AUTO_TEST_CASE(SendInterestHitPrevious) |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 202 | { |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 203 | addFace(make_shared<DummyFace>()); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 204 | |
| 205 | shared_ptr<InternalFace> face(new InternalFace); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 206 | |
| 207 | face->setInterestFilter("/localhost/nfd/fib", |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 208 | bind(&InternalFaceFixture::validateOnInterestCallback, |
| 209 | this, _1, _2)); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 210 | |
| 211 | face->setInterestFilter("/localhost/nfd/fib/zzzzzzzzzzzzz/", |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 212 | bind(&InternalFaceFixture::validateNoOnInterestCallback, |
| 213 | this, _1, _2)); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 214 | |
| 215 | // generate command whose name exactly matches |
| 216 | // an Interest filter |
| 217 | |
| 218 | Name commandName("/localhost/nfd/fib/previous"); |
Junxiao Shi | 72c3e04 | 2014-04-08 15:02:37 -0700 | [diff] [blame] | 219 | shared_ptr<Interest> command = makeInterest(commandName); |
| 220 | face->sendInterest(*command); |
Junxiao Shi | 16d1b7d | 2014-03-27 21:29:09 -0700 | [diff] [blame] | 221 | g_io.run_one(); |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 222 | |
| 223 | BOOST_REQUIRE(didOnInterestFire()); |
| 224 | BOOST_REQUIRE(didNoOnInterestFire() == false); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 225 | } |
| 226 | |
Junxiao Shi | 72c3e04 | 2014-04-08 15:02:37 -0700 | [diff] [blame] | 227 | BOOST_AUTO_TEST_CASE(InterestGone) |
| 228 | { |
| 229 | shared_ptr<InternalFace> face = make_shared<InternalFace>(); |
| 230 | shared_ptr<Interest> interest = makeInterest("ndn:/localhost/nfd/gone"); |
| 231 | face->sendInterest(*interest); |
| 232 | |
| 233 | interest.reset(); |
| 234 | BOOST_CHECK_NO_THROW(g_io.poll()); |
| 235 | } |
| 236 | |
Steve DiBenedetto | 5b43398 | 2014-01-29 17:14:27 -0700 | [diff] [blame] | 237 | BOOST_AUTO_TEST_SUITE_END() |
| 238 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 239 | } // namespace tests |
Steve DiBenedetto | 5b43398 | 2014-01-29 17:14:27 -0700 | [diff] [blame] | 240 | } // namespace nfd |