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