Steve DiBenedetto | 5b43398 | 2014-01-29 17:14:27 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2014 Named Data Networking Project |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #include "mgmt/internal-face.hpp" |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 8 | #include "mgmt/fib-manager.hpp" |
| 9 | #include "table/fib.hpp" |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 10 | #include "../face/dummy-face.hpp" |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 11 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 12 | #include <ndn-cpp-dev/management/fib-management-options.hpp> |
| 13 | #include <ndn-cpp-dev/management/control-response.hpp> |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 14 | #include <ndn-cpp-dev/encoding/block.hpp> |
Steve DiBenedetto | 5b43398 | 2014-01-29 17:14:27 -0700 | [diff] [blame] | 15 | |
| 16 | #include <boost/test/unit_test.hpp> |
| 17 | |
| 18 | namespace nfd { |
| 19 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 20 | NFD_LOG_INIT("InternalFaceTest"); |
| 21 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 22 | class InternalFaceFixture |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 23 | { |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 24 | public: |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 25 | |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 26 | InternalFaceFixture() |
| 27 | : m_onInterestFired(false), |
| 28 | m_noOnInterestFired(false) |
| 29 | { |
| 30 | |
| 31 | } |
| 32 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 33 | shared_ptr<Face> |
| 34 | getFace(FaceId id) |
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 | if (m_faces.size() < id) |
| 37 | { |
| 38 | BOOST_FAIL("Attempted to access invalid FaceId: " << id); |
| 39 | } |
| 40 | return m_faces[id-1]; |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 41 | } |
| 42 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 43 | void |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 44 | validateOnInterestCallback(const Name& name, const Interest& interest) |
| 45 | { |
| 46 | m_onInterestFired = true; |
| 47 | } |
| 48 | |
| 49 | void |
| 50 | validateNoOnInterestCallback(const Name& name, const Interest& interest) |
| 51 | { |
| 52 | m_noOnInterestFired = true; |
| 53 | } |
| 54 | |
| 55 | void |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 56 | addFace(shared_ptr<Face> face) |
| 57 | { |
| 58 | m_faces.push_back(face); |
| 59 | } |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 60 | |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 61 | bool |
| 62 | didOnInterestFire() |
| 63 | { |
| 64 | return m_onInterestFired; |
| 65 | } |
| 66 | |
| 67 | bool |
| 68 | didNoOnInterestFire() |
| 69 | { |
| 70 | return m_noOnInterestFired; |
| 71 | } |
| 72 | |
| 73 | void |
| 74 | resetOnInterestFired() |
| 75 | { |
| 76 | m_onInterestFired = false; |
| 77 | } |
| 78 | |
| 79 | void |
| 80 | resetNoOnInterestFired() |
| 81 | { |
| 82 | m_noOnInterestFired = false; |
| 83 | } |
| 84 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 85 | private: |
| 86 | std::vector<shared_ptr<Face> > m_faces; |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 87 | bool m_onInterestFired; |
| 88 | bool m_noOnInterestFired; |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 89 | }; |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 90 | |
Steve DiBenedetto | 5b43398 | 2014-01-29 17:14:27 -0700 | [diff] [blame] | 91 | BOOST_AUTO_TEST_SUITE(MgmtInternalFace) |
| 92 | |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 93 | void |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 94 | validatePutData(bool& called, const Name& expectedName, const Data& data) |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 95 | { |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 96 | called = true; |
| 97 | BOOST_CHECK_EQUAL(expectedName, data.getName()); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 98 | } |
| 99 | |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 100 | BOOST_FIXTURE_TEST_CASE(PutData, InternalFaceFixture) |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 101 | { |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 102 | addFace(make_shared<DummyFace>()); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 103 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 104 | shared_ptr<InternalFace> face(new InternalFace); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 105 | Fib fib; |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 106 | FibManager manager(fib, |
| 107 | bind(&InternalFaceFixture::getFace, |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 108 | this, _1), |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 109 | face); |
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"); |
| 113 | face->onReceiveData += bind(&validatePutData, boost::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); |
| 116 | face->sign(testData); |
| 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); |
Steve DiBenedetto | 5b43398 | 2014-01-29 17:14:27 -0700 | [diff] [blame] | 120 | } |
| 121 | |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 122 | BOOST_FIXTURE_TEST_CASE(SendInterestHitEnd, InternalFaceFixture) |
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 | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 127 | Fib fib; |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 128 | FibManager manager(fib, |
| 129 | bind(&InternalFaceFixture::getFace, |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 130 | this, _1), |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 131 | face); |
| 132 | |
| 133 | face->setInterestFilter("/localhost/nfd/fib", |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 134 | bind(&InternalFaceFixture::validateOnInterestCallback, |
| 135 | this, _1, _2)); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 136 | |
| 137 | // generate command whose name is canonically |
| 138 | // ordered after /localhost/nfd/fib so that |
| 139 | // we hit the end of the std::map |
| 140 | |
| 141 | Name commandName("/localhost/nfd/fib/end"); |
| 142 | Interest command(commandName); |
| 143 | face->sendInterest(command); |
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 | |
| 149 | |
| 150 | |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 151 | BOOST_FIXTURE_TEST_CASE(SendInterestHitBegin, InternalFaceFixture) |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 152 | { |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 153 | addFace(make_shared<DummyFace>()); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 154 | |
| 155 | shared_ptr<InternalFace> face(new InternalFace); |
| 156 | Fib fib; |
| 157 | FibManager manager(fib, |
| 158 | bind(&InternalFaceFixture::getFace, |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 159 | this, _1), |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 160 | face); |
| 161 | |
| 162 | face->setInterestFilter("/localhost/nfd/fib", |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 163 | bind(&InternalFaceFixture::validateNoOnInterestCallback, |
| 164 | this, _1, _2)); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 165 | |
| 166 | // generate command whose name is canonically |
| 167 | // ordered before /localhost/nfd/fib so that |
| 168 | // we hit the beginning of the std::map |
| 169 | |
| 170 | Name commandName("/localhost/nfd"); |
| 171 | Interest command(commandName); |
| 172 | face->sendInterest(command); |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 173 | |
| 174 | BOOST_REQUIRE(didNoOnInterestFire() == false); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | |
| 178 | |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 179 | BOOST_FIXTURE_TEST_CASE(SendInterestHitExact, InternalFaceFixture) |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 180 | { |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 181 | addFace(make_shared<DummyFace>()); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 182 | |
| 183 | shared_ptr<InternalFace> face(new InternalFace); |
| 184 | Fib fib; |
| 185 | FibManager manager(fib, |
| 186 | bind(&InternalFaceFixture::getFace, |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 187 | this, _1), |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 188 | face); |
| 189 | |
| 190 | face->setInterestFilter("/localhost/nfd/eib", |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 191 | bind(&InternalFaceFixture::validateNoOnInterestCallback, |
| 192 | this, _1, _2)); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 193 | |
| 194 | face->setInterestFilter("/localhost/nfd/fib", |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 195 | bind(&InternalFaceFixture::validateOnInterestCallback, |
| 196 | this, _1, _2)); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 197 | |
| 198 | face->setInterestFilter("/localhost/nfd/gib", |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 199 | bind(&InternalFaceFixture::validateNoOnInterestCallback, |
| 200 | this, _1, _2)); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 201 | |
| 202 | // generate command whose name exactly matches |
| 203 | // /localhost/nfd/fib |
| 204 | |
| 205 | Name commandName("/localhost/nfd/fib"); |
| 206 | Interest command(commandName); |
| 207 | face->sendInterest(command); |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 208 | |
| 209 | BOOST_REQUIRE(didOnInterestFire()); |
| 210 | BOOST_REQUIRE(didNoOnInterestFire() == false); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | |
| 214 | |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 215 | BOOST_FIXTURE_TEST_CASE(SendInterestHitPrevious, InternalFaceFixture) |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 216 | { |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 217 | addFace(make_shared<DummyFace>()); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 218 | |
| 219 | shared_ptr<InternalFace> face(new InternalFace); |
| 220 | Fib fib; |
| 221 | FibManager manager(fib, |
| 222 | bind(&InternalFaceFixture::getFace, |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 223 | this, _1), |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 224 | face); |
| 225 | |
| 226 | face->setInterestFilter("/localhost/nfd/fib", |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 227 | bind(&InternalFaceFixture::validateOnInterestCallback, |
| 228 | this, _1, _2)); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 229 | |
| 230 | face->setInterestFilter("/localhost/nfd/fib/zzzzzzzzzzzzz/", |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 231 | bind(&InternalFaceFixture::validateNoOnInterestCallback, |
| 232 | this, _1, _2)); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 233 | |
| 234 | // generate command whose name exactly matches |
| 235 | // an Interest filter |
| 236 | |
| 237 | Name commandName("/localhost/nfd/fib/previous"); |
| 238 | Interest command(commandName); |
| 239 | face->sendInterest(command); |
Steve DiBenedetto | bdedce9 | 2014-02-02 22:49:39 -0700 | [diff] [blame] | 240 | |
| 241 | BOOST_REQUIRE(didOnInterestFire()); |
| 242 | BOOST_REQUIRE(didNoOnInterestFire() == false); |
Steve DiBenedetto | 43cd037 | 2014-02-01 17:05:07 -0700 | [diff] [blame] | 243 | } |
| 244 | |
Steve DiBenedetto | 5b43398 | 2014-01-29 17:14:27 -0700 | [diff] [blame] | 245 | BOOST_AUTO_TEST_SUITE_END() |
| 246 | |
| 247 | } // namespace nfd |