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/generic-link-service.hpp" |
| 27 | #include "face/lp-face.hpp" |
| 28 | #include "dummy-transport.hpp" |
| 29 | |
| 30 | #include "tests/test-common.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 | |
| 40 | class GenericLinkServiceFixture : public BaseFixture |
| 41 | { |
| 42 | protected: |
| 43 | GenericLinkServiceFixture() |
| 44 | : service(nullptr) |
| 45 | , transport(nullptr) |
| 46 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 47 | this->initialize(GenericLinkService::Options()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 48 | // By default, GenericLinkService is created with default options. |
| 49 | // Test cases may invoke .initialize with alternate options. |
| 50 | } |
| 51 | |
| 52 | void |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 53 | initialize(const GenericLinkService::Options& options) |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 54 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 55 | face.reset(new LpFace(make_unique<GenericLinkService>(options), |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 56 | make_unique<DummyTransport>())); |
| 57 | service = static_cast<GenericLinkService*>(face->getLinkService()); |
| 58 | transport = static_cast<DummyTransport*>(face->getTransport()); |
| 59 | |
| 60 | face->afterReceiveInterest.connect( |
| 61 | [this] (const Interest& interest) { receivedInterests.push_back(interest); }); |
| 62 | face->afterReceiveData.connect( |
| 63 | [this] (const Data& data) { receivedData.push_back(data); }); |
| 64 | face->afterReceiveNack.connect( |
| 65 | [this] (const lp::Nack& nack) { receivedNacks.push_back(nack); }); |
| 66 | } |
| 67 | |
| 68 | protected: |
| 69 | unique_ptr<LpFace> face; |
| 70 | GenericLinkService* service; |
| 71 | DummyTransport* transport; |
| 72 | std::vector<Interest> receivedInterests; |
| 73 | std::vector<Data> receivedData; |
| 74 | std::vector<lp::Nack> receivedNacks; |
| 75 | }; |
| 76 | |
| 77 | BOOST_FIXTURE_TEST_SUITE(TestGenericLinkService, GenericLinkServiceFixture) |
| 78 | |
| 79 | |
| 80 | BOOST_AUTO_TEST_SUITE(SimpleSendReceive) // send and receive without other fields |
| 81 | |
| 82 | BOOST_AUTO_TEST_CASE(SendInterest) |
| 83 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 84 | // Initialize with Options that disables all services |
| 85 | GenericLinkService::Options options; |
| 86 | options.allowLocalFields = false; |
| 87 | initialize(options); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 88 | |
| 89 | shared_ptr<Interest> interest1 = makeInterest("/localhost/test"); |
| 90 | |
| 91 | face->sendInterest(*interest1); |
| 92 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 93 | BOOST_CHECK_EQUAL(service->getCounters().nOutInterests, 1); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 94 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 95 | lp::Packet interest1pkt; |
| 96 | BOOST_REQUIRE_NO_THROW(interest1pkt.wireDecode(transport->sentPackets.back().packet)); |
| 97 | BOOST_CHECK(interest1pkt.has<lp::FragmentField>()); |
| 98 | BOOST_CHECK(!interest1pkt.has<lp::SequenceField>()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | BOOST_AUTO_TEST_CASE(SendData) |
| 102 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 103 | // Initialize with Options that disables all services |
| 104 | GenericLinkService::Options options; |
| 105 | options.allowLocalFields = false; |
| 106 | initialize(options); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 107 | |
| 108 | shared_ptr<Data> data1 = makeData("/localhost/test"); |
| 109 | |
| 110 | face->sendData(*data1); |
| 111 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 112 | BOOST_CHECK_EQUAL(service->getCounters().nOutData, 1); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 113 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 114 | lp::Packet data1pkt; |
| 115 | BOOST_REQUIRE_NO_THROW(data1pkt.wireDecode(transport->sentPackets.back().packet)); |
| 116 | BOOST_CHECK(data1pkt.has<lp::FragmentField>()); |
| 117 | BOOST_CHECK(!data1pkt.has<lp::SequenceField>()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | BOOST_AUTO_TEST_CASE(SendNack) |
| 121 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 122 | // Initialize with Options that disables all services |
| 123 | GenericLinkService::Options options; |
| 124 | options.allowLocalFields = false; |
| 125 | initialize(options); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 126 | |
| 127 | lp::Nack nack1 = makeNack("/localhost/test", 323, lp::NackReason::NO_ROUTE); |
| 128 | |
| 129 | face->sendNack(nack1); |
| 130 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 131 | BOOST_CHECK_EQUAL(service->getCounters().nOutNacks, 1); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 132 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
| 133 | lp::Packet nack1pkt; |
| 134 | BOOST_REQUIRE_NO_THROW(nack1pkt.wireDecode(transport->sentPackets.back().packet)); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 135 | BOOST_CHECK(nack1pkt.has<lp::NackField>()); |
| 136 | BOOST_CHECK(nack1pkt.has<lp::FragmentField>()); |
| 137 | BOOST_CHECK(!nack1pkt.has<lp::SequenceField>()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | BOOST_AUTO_TEST_CASE(ReceiveBareInterest) |
| 141 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 142 | // Initialize with Options that disables all services |
| 143 | GenericLinkService::Options options; |
| 144 | options.allowLocalFields = false; |
| 145 | initialize(options); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 146 | |
| 147 | shared_ptr<Interest> interest1 = makeInterest("/23Rd9hEiR"); |
| 148 | |
| 149 | transport->receivePacket(interest1->wireEncode()); |
| 150 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 151 | BOOST_CHECK_EQUAL(service->getCounters().nInInterests, 1); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 152 | BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1); |
| 153 | BOOST_CHECK_EQUAL(receivedInterests.back(), *interest1); |
| 154 | } |
| 155 | |
| 156 | BOOST_AUTO_TEST_CASE(ReceiveInterest) |
| 157 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 158 | // Initialize with Options that disables all services |
| 159 | GenericLinkService::Options options; |
| 160 | options.allowLocalFields = false; |
| 161 | initialize(options); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 162 | |
| 163 | shared_ptr<Interest> interest1 = makeInterest("/23Rd9hEiR"); |
| 164 | lp::Packet lpPacket; |
| 165 | lpPacket.set<lp::FragmentField>(std::make_pair( |
| 166 | interest1->wireEncode().begin(), interest1->wireEncode().end())); |
| 167 | lpPacket.set<lp::SequenceField>(0); // force LpPacket encoding |
| 168 | |
| 169 | transport->receivePacket(lpPacket.wireEncode()); |
| 170 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 171 | BOOST_CHECK_EQUAL(service->getCounters().nInInterests, 1); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 172 | BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1); |
| 173 | BOOST_CHECK_EQUAL(receivedInterests.back(), *interest1); |
| 174 | } |
| 175 | |
| 176 | BOOST_AUTO_TEST_CASE(ReceiveBareData) |
| 177 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 178 | // Initialize with Options that disables all services |
| 179 | GenericLinkService::Options options; |
| 180 | options.allowLocalFields = false; |
| 181 | initialize(options); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 182 | |
| 183 | shared_ptr<Data> data1 = makeData("/12345678"); |
| 184 | |
| 185 | transport->receivePacket(data1->wireEncode()); |
| 186 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 187 | BOOST_CHECK_EQUAL(service->getCounters().nInData, 1); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 188 | BOOST_REQUIRE_EQUAL(receivedData.size(), 1); |
| 189 | BOOST_CHECK_EQUAL(receivedData.back(), *data1); |
| 190 | } |
| 191 | |
| 192 | BOOST_AUTO_TEST_CASE(ReceiveData) |
| 193 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 194 | // Initialize with Options that disables all services |
| 195 | GenericLinkService::Options options; |
| 196 | options.allowLocalFields = false; |
| 197 | initialize(options); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 198 | |
| 199 | shared_ptr<Data> data1 = makeData("/12345689"); |
| 200 | lp::Packet lpPacket; |
| 201 | lpPacket.set<lp::FragmentField>(std::make_pair( |
| 202 | data1->wireEncode().begin(), data1->wireEncode().end())); |
| 203 | lpPacket.set<lp::SequenceField>(0); // force LpPacket encoding |
| 204 | |
| 205 | transport->receivePacket(lpPacket.wireEncode()); |
| 206 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 207 | BOOST_CHECK_EQUAL(service->getCounters().nInData, 1); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 208 | BOOST_REQUIRE_EQUAL(receivedData.size(), 1); |
| 209 | BOOST_CHECK_EQUAL(receivedData.back(), *data1); |
| 210 | } |
| 211 | |
| 212 | BOOST_AUTO_TEST_CASE(ReceiveNack) |
| 213 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 214 | // Initialize with Options that disables all services |
| 215 | GenericLinkService::Options options; |
| 216 | options.allowLocalFields = false; |
| 217 | initialize(options); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 218 | |
| 219 | lp::Nack nack1 = makeNack("/localhost/test", 323, lp::NackReason::NO_ROUTE); |
| 220 | lp::Packet lpPacket; |
| 221 | lpPacket.set<lp::FragmentField>(std::make_pair( |
| 222 | nack1.getInterest().wireEncode().begin(), nack1.getInterest().wireEncode().end())); |
| 223 | lpPacket.set<lp::NackField>(nack1.getHeader()); |
| 224 | |
| 225 | transport->receivePacket(lpPacket.wireEncode()); |
| 226 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 227 | BOOST_CHECK_EQUAL(service->getCounters().nInNacks, 1); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 228 | BOOST_REQUIRE_EQUAL(receivedNacks.size(), 1); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 229 | BOOST_CHECK(receivedNacks.back().getReason() == nack1.getReason()); |
| 230 | BOOST_CHECK(receivedNacks.back().getInterest() == nack1.getInterest()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 231 | } |
| 232 | |
Eric Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 233 | BOOST_AUTO_TEST_CASE(ReceiveIdlePacket) |
| 234 | { |
| 235 | // Initialize with Options that disables all services |
| 236 | GenericLinkService::Options options; |
| 237 | options.allowLocalFields = false; |
| 238 | initialize(options); |
| 239 | |
| 240 | lp::Packet lpPacket; |
| 241 | lpPacket.set<lp::SequenceField>(0); |
| 242 | |
| 243 | BOOST_CHECK_NO_THROW(transport->receivePacket(lpPacket.wireEncode())); |
| 244 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 245 | // IDLE packet should be ignored, but is not an error |
| 246 | BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 0); |
Eric Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 247 | BOOST_CHECK_EQUAL(receivedInterests.size(), 0); |
| 248 | BOOST_CHECK_EQUAL(receivedData.size(), 0); |
| 249 | BOOST_CHECK_EQUAL(receivedNacks.size(), 0); |
| 250 | } |
| 251 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 252 | BOOST_AUTO_TEST_SUITE_END() // SimpleSendReceive |
| 253 | |
| 254 | |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 255 | BOOST_AUTO_TEST_SUITE(Fragmentation) |
| 256 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 257 | BOOST_AUTO_TEST_CASE(FragmentationDisabledExceedMtuDrop) |
| 258 | { |
| 259 | // Initialize with Options that disable fragmentation |
| 260 | GenericLinkService::Options options; |
| 261 | options.allowFragmentation = false; |
| 262 | initialize(options); |
| 263 | |
| 264 | transport->setMtu(55); |
| 265 | |
| 266 | shared_ptr<Data> data = makeData("/test/data/123456789/987654321/123456789"); |
| 267 | face->sendData(*data); |
| 268 | |
| 269 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 0); |
| 270 | BOOST_CHECK_EQUAL(service->getCounters().nOutOverMtu, 1); |
| 271 | } |
| 272 | |
| 273 | BOOST_AUTO_TEST_CASE(FragmentationUnlimitedMtu) |
| 274 | { |
| 275 | // Initialize with Options that enable fragmentation |
| 276 | GenericLinkService::Options options; |
| 277 | options.allowFragmentation = true; |
| 278 | initialize(options); |
| 279 | |
| 280 | transport->setMtu(MTU_UNLIMITED); |
| 281 | |
| 282 | shared_ptr<Data> data = makeData("/test/data/123456789/987654321/123456789"); |
| 283 | face->sendData(*data); |
| 284 | |
| 285 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 1); |
| 286 | } |
| 287 | |
| 288 | BOOST_AUTO_TEST_CASE(FragmentationUnderMtu) |
| 289 | { |
| 290 | // Initialize with Options that enable fragmentation |
| 291 | GenericLinkService::Options options; |
| 292 | options.allowFragmentation = true; |
| 293 | initialize(options); |
| 294 | |
| 295 | transport->setMtu(105); |
| 296 | |
| 297 | shared_ptr<Data> data = makeData("/test/data/123456789/987654321/123456789"); |
| 298 | face->sendData(*data); |
| 299 | |
| 300 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 1); |
| 301 | } |
| 302 | |
| 303 | BOOST_AUTO_TEST_CASE(FragmentationOverMtu) |
| 304 | { |
| 305 | // Initialize with Options that enable fragmentation |
| 306 | GenericLinkService::Options options; |
| 307 | options.allowFragmentation = true; |
| 308 | initialize(options); |
| 309 | |
| 310 | transport->setMtu(60); |
| 311 | |
| 312 | shared_ptr<Data> data = makeData("/test/data/123456789/987654321/123456789"); |
| 313 | face->sendData(*data); |
| 314 | |
| 315 | BOOST_CHECK_GT(transport->sentPackets.size(), 1); |
| 316 | } |
| 317 | |
| 318 | BOOST_AUTO_TEST_CASE(ReassembleFragments) |
| 319 | { |
| 320 | // Initialize with Options that enables reassembly |
| 321 | GenericLinkService::Options options; |
| 322 | options.allowReassembly = true; |
| 323 | initialize(options); |
| 324 | |
| 325 | shared_ptr<Interest> interest = makeInterest( |
| 326 | "/mt7P130BHXmtLm5dwaY5dpUM6SWYNN2B05g7y3UhsQuLvDdnTWdNnTeEiLuW3FAbJRSG3tzQ0UfaSEgG9rvYHmsKtgPMag1Hj4Tr"); |
| 327 | lp::Packet packet(interest->wireEncode()); |
| 328 | |
| 329 | // fragment the packet |
| 330 | LpFragmenter fragmenter; |
| 331 | size_t mtu = 100; |
| 332 | bool isOk = false; |
| 333 | std::vector<lp::Packet> frags; |
| 334 | std::tie(isOk, frags) = fragmenter.fragmentPacket(packet, mtu); |
| 335 | BOOST_REQUIRE(isOk); |
| 336 | BOOST_CHECK_GT(frags.size(), 1); |
| 337 | |
| 338 | // receive the fragments |
| 339 | for (ssize_t fragIndex = frags.size() - 1; fragIndex >= 0; --fragIndex) { |
| 340 | size_t sequence = 1000 + fragIndex; |
| 341 | frags[fragIndex].add<lp::SequenceField>(sequence); |
| 342 | |
| 343 | transport->receivePacket(frags[fragIndex].wireEncode()); |
| 344 | |
| 345 | if (fragIndex > 0) { |
| 346 | BOOST_CHECK(receivedInterests.empty()); |
| 347 | BOOST_CHECK_EQUAL(service->getCounters().nReassembling, 1); |
| 348 | } |
| 349 | else { |
| 350 | BOOST_CHECK_EQUAL(receivedInterests.size(), 1); |
| 351 | BOOST_CHECK_EQUAL(receivedInterests.back(), *interest); |
| 352 | BOOST_CHECK_EQUAL(service->getCounters().nReassembling, 0); |
| 353 | } |
| 354 | } |
| 355 | } |
| 356 | |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 357 | BOOST_AUTO_TEST_CASE(ReassemblyDisabledDropFragIndex) |
| 358 | { |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 359 | // Initialize with Options that disables reassembly |
| 360 | GenericLinkService::Options options; |
| 361 | options.allowReassembly = false; |
| 362 | initialize(options); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 363 | |
| 364 | shared_ptr<Interest> interest = makeInterest("/IgFe6NvH"); |
| 365 | lp::Packet packet(interest->wireEncode()); |
| 366 | packet.set<lp::FragIndexField>(140); |
| 367 | |
| 368 | transport->receivePacket(packet.wireEncode()); |
| 369 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 370 | BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 0); // not an error |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 371 | BOOST_CHECK(receivedInterests.empty()); |
| 372 | } |
| 373 | |
| 374 | BOOST_AUTO_TEST_CASE(ReassemblyDisabledDropFragCount) |
| 375 | { |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 376 | // Initialize with Options that disables reassembly |
| 377 | GenericLinkService::Options options; |
| 378 | options.allowReassembly = false; |
| 379 | initialize(options); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 380 | |
| 381 | shared_ptr<Interest> interest = makeInterest("/SeGmEjvIVX"); |
| 382 | lp::Packet packet(interest->wireEncode()); |
| 383 | packet.set<lp::FragCountField>(276); |
| 384 | |
| 385 | transport->receivePacket(packet.wireEncode()); |
| 386 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 387 | BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 0); // not an error |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 388 | BOOST_CHECK(receivedInterests.empty()); |
| 389 | } |
| 390 | |
| 391 | BOOST_AUTO_TEST_SUITE_END() // Fragmentation |
| 392 | |
| 393 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 394 | BOOST_AUTO_TEST_SUITE(LocalFields) |
| 395 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 396 | BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceId) |
| 397 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 398 | // Initialize with Options that enables local fields |
| 399 | GenericLinkService::Options options; |
| 400 | options.allowLocalFields = true; |
| 401 | initialize(options); |
| 402 | |
| 403 | shared_ptr<Interest> interest = makeInterest("/12345678"); |
| 404 | lp::Packet packet(interest->wireEncode()); |
| 405 | packet.set<lp::NextHopFaceIdField>(1000); |
| 406 | |
| 407 | transport->receivePacket(packet.wireEncode()); |
| 408 | |
| 409 | BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 410 | shared_ptr<lp::NextHopFaceIdTag> tag = receivedInterests.back().getTag<lp::NextHopFaceIdTag>(); |
| 411 | BOOST_REQUIRE(tag != nullptr); |
| 412 | BOOST_CHECK_EQUAL(*tag, 1000); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDisabled) |
| 416 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 417 | // Initialize with Options that disables local fields |
| 418 | GenericLinkService::Options options; |
| 419 | options.allowLocalFields = false; |
| 420 | initialize(options); |
| 421 | |
| 422 | shared_ptr<Interest> interest = makeInterest("/12345678"); |
| 423 | lp::Packet packet(interest->wireEncode()); |
| 424 | packet.set<lp::NextHopFaceIdField>(1000); |
| 425 | |
| 426 | transport->receivePacket(packet.wireEncode()); |
| 427 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 428 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 429 | BOOST_CHECK(receivedInterests.empty()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDropData) |
| 433 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 434 | // Initialize with Options that enables local fields |
| 435 | GenericLinkService::Options options; |
| 436 | options.allowLocalFields = true; |
| 437 | initialize(options); |
| 438 | |
| 439 | shared_ptr<Data> data = makeData("/12345678"); |
| 440 | lp::Packet packet(data->wireEncode()); |
| 441 | packet.set<lp::NextHopFaceIdField>(1000); |
| 442 | |
| 443 | transport->receivePacket(packet.wireEncode()); |
| 444 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 445 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 446 | BOOST_CHECK(receivedData.empty()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDropNack) |
| 450 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 451 | // Initialize with Options that enables local fields |
| 452 | GenericLinkService::Options options; |
| 453 | options.allowLocalFields = true; |
| 454 | initialize(options); |
| 455 | |
| 456 | lp::Nack nack = makeNack("/localhost/test", 123, lp::NackReason::NO_ROUTE); |
| 457 | lp::Packet packet; |
| 458 | packet.set<lp::FragmentField>(std::make_pair( |
| 459 | nack.getInterest().wireEncode().begin(), nack.getInterest().wireEncode().end())); |
| 460 | packet.set<lp::NackField>(nack.getHeader()); |
| 461 | packet.set<lp::NextHopFaceIdField>(1000); |
| 462 | |
| 463 | transport->receivePacket(packet.wireEncode()); |
| 464 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 465 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 466 | BOOST_CHECK(receivedNacks.empty()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | BOOST_AUTO_TEST_CASE(ReceiveCacheControl) |
| 470 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 471 | // Initialize with Options that enables local fields |
| 472 | GenericLinkService::Options options; |
| 473 | options.allowLocalFields = true; |
| 474 | initialize(options); |
| 475 | |
| 476 | shared_ptr<Data> data = makeData("/12345678"); |
| 477 | lp::Packet packet(data->wireEncode()); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 478 | packet.set<lp::CachePolicyField>(lp::CachePolicy().setPolicy(lp::CachePolicyType::NO_CACHE)); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 479 | |
| 480 | transport->receivePacket(packet.wireEncode()); |
| 481 | |
| 482 | BOOST_REQUIRE_EQUAL(receivedData.size(), 1); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 483 | shared_ptr<lp::CachePolicyTag> tag = receivedData.back().getTag<lp::CachePolicyTag>(); |
| 484 | BOOST_REQUIRE(tag != nullptr); |
| 485 | BOOST_CHECK_EQUAL(tag->get().getPolicy(), lp::CachePolicyType::NO_CACHE); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | BOOST_AUTO_TEST_CASE(ReceiveCacheControlDisabled) |
| 489 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 490 | // Initialize with Options that disables local fields |
| 491 | GenericLinkService::Options options; |
| 492 | options.allowLocalFields = false; |
| 493 | initialize(options); |
| 494 | |
| 495 | shared_ptr<Data> data = makeData("/12345678"); |
| 496 | lp::Packet packet(data->wireEncode()); |
| 497 | lp::CachePolicy policy; |
| 498 | policy.setPolicy(lp::CachePolicyType::NO_CACHE); |
| 499 | packet.set<lp::CachePolicyField>(policy); |
| 500 | |
| 501 | transport->receivePacket(packet.wireEncode()); |
| 502 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 503 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 504 | BOOST_REQUIRE_EQUAL(receivedData.size(), 1); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 505 | BOOST_CHECK(receivedData.back().getTag<lp::CachePolicyTag>() == nullptr); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | BOOST_AUTO_TEST_CASE(ReceiveCacheControlDropInterest) |
| 509 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 510 | // Initialize with Options that enables local fields |
| 511 | GenericLinkService::Options options; |
| 512 | options.allowLocalFields = true; |
| 513 | initialize(options); |
| 514 | |
| 515 | shared_ptr<Interest> interest = makeInterest("/12345678"); |
| 516 | lp::Packet packet(interest->wireEncode()); |
| 517 | lp::CachePolicy policy; |
| 518 | policy.setPolicy(lp::CachePolicyType::NO_CACHE); |
| 519 | packet.set<lp::CachePolicyField>(policy); |
| 520 | |
| 521 | transport->receivePacket(packet.wireEncode()); |
| 522 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 523 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 524 | BOOST_CHECK(receivedInterests.empty()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | BOOST_AUTO_TEST_CASE(ReceiveCacheControlDropNack) |
| 528 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 529 | // Initialize with Options that enables local fields |
| 530 | GenericLinkService::Options options; |
| 531 | options.allowLocalFields = true; |
| 532 | initialize(options); |
| 533 | |
| 534 | lp::Nack nack = makeNack("/localhost/test", 123, lp::NackReason::NO_ROUTE); |
| 535 | lp::Packet packet(nack.getInterest().wireEncode()); |
| 536 | packet.set<lp::NackField>(nack.getHeader()); |
| 537 | lp::CachePolicy policy; |
| 538 | policy.setPolicy(lp::CachePolicyType::NO_CACHE); |
| 539 | packet.set<lp::CachePolicyField>(policy); |
| 540 | |
| 541 | transport->receivePacket(packet.wireEncode()); |
| 542 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 543 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 544 | BOOST_CHECK(receivedNacks.empty()); |
| 545 | } |
| 546 | |
| 547 | BOOST_AUTO_TEST_CASE(SendIncomingFaceId) |
| 548 | { |
| 549 | // Initialize with Options that enables local fields |
| 550 | GenericLinkService::Options options; |
| 551 | options.allowLocalFields = true; |
| 552 | initialize(options); |
| 553 | |
| 554 | shared_ptr<Interest> interest = makeInterest("/12345678"); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 555 | interest->setTag(make_shared<lp::IncomingFaceIdTag>(1000)); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 556 | |
| 557 | face->sendInterest(*interest); |
| 558 | |
| 559 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
| 560 | lp::Packet sent(transport->sentPackets.back().packet); |
| 561 | BOOST_REQUIRE(sent.has<lp::IncomingFaceIdField>()); |
| 562 | BOOST_CHECK_EQUAL(sent.get<lp::IncomingFaceIdField>(), 1000); |
| 563 | } |
| 564 | |
| 565 | BOOST_AUTO_TEST_CASE(SendIncomingFaceIdDisabled) |
| 566 | { |
| 567 | // Initialize with Options that disables local fields |
| 568 | GenericLinkService::Options options; |
| 569 | options.allowLocalFields = false; |
| 570 | initialize(options); |
| 571 | |
| 572 | shared_ptr<Interest> interest = makeInterest("/12345678"); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 573 | interest->setTag(make_shared<lp::IncomingFaceIdTag>(1000)); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 574 | |
| 575 | face->sendInterest(*interest); |
| 576 | |
| 577 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
| 578 | lp::Packet sent(transport->sentPackets.back().packet); |
| 579 | BOOST_CHECK(!sent.has<lp::IncomingFaceIdField>()); |
| 580 | } |
| 581 | |
| 582 | BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreInterest) |
| 583 | { |
| 584 | // Initialize with Options that enables local fields |
| 585 | GenericLinkService::Options options; |
| 586 | options.allowLocalFields = true; |
| 587 | initialize(options); |
| 588 | |
| 589 | shared_ptr<Interest> interest = makeInterest("/12345678"); |
| 590 | lp::Packet packet(interest->wireEncode()); |
| 591 | packet.set<lp::IncomingFaceIdField>(1000); |
| 592 | |
| 593 | transport->receivePacket(packet.wireEncode()); |
| 594 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 595 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 596 | BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 597 | BOOST_CHECK(receivedInterests.back().getTag<lp::IncomingFaceIdTag>() == nullptr); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreData) |
| 601 | { |
| 602 | // Initialize with Options that enables local fields |
| 603 | GenericLinkService::Options options; |
| 604 | options.allowLocalFields = true; |
| 605 | initialize(options); |
| 606 | |
| 607 | shared_ptr<Data> data = makeData("/z1megUh9Bj"); |
| 608 | lp::Packet packet(data->wireEncode()); |
| 609 | packet.set<lp::IncomingFaceIdField>(1000); |
| 610 | |
| 611 | transport->receivePacket(packet.wireEncode()); |
| 612 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 613 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 614 | BOOST_REQUIRE_EQUAL(receivedData.size(), 1); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 615 | BOOST_CHECK(receivedData.back().getTag<lp::IncomingFaceIdTag>() == nullptr); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreNack) |
| 619 | { |
| 620 | // Initialize with Options that enables local fields |
| 621 | GenericLinkService::Options options; |
| 622 | options.allowLocalFields = true; |
| 623 | initialize(options); |
| 624 | |
| 625 | lp::Nack nack = makeNack("/TPAhdiHz", 278, lp::NackReason::CONGESTION); |
| 626 | lp::Packet packet(nack.getInterest().wireEncode()); |
| 627 | packet.set<lp::NackField>(nack.getHeader()); |
| 628 | packet.set<lp::IncomingFaceIdField>(1000); |
| 629 | |
| 630 | transport->receivePacket(packet.wireEncode()); |
| 631 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 632 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 633 | BOOST_REQUIRE_EQUAL(receivedNacks.size(), 1); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 634 | BOOST_CHECK(receivedNacks.back().getTag<lp::IncomingFaceIdTag>() == nullptr); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | BOOST_AUTO_TEST_SUITE_END() // LocalFields |
| 638 | |
| 639 | |
Eric Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 640 | BOOST_AUTO_TEST_SUITE(Malformed) // receive malformed packets |
| 641 | |
| 642 | BOOST_AUTO_TEST_CASE(WrongTlvType) |
| 643 | { |
| 644 | // Initialize with Options that disables all services |
| 645 | GenericLinkService::Options options; |
| 646 | options.allowLocalFields = false; |
| 647 | initialize(options); |
| 648 | |
| 649 | Block packet = ndn::encoding::makeEmptyBlock(tlv::Name); |
| 650 | |
| 651 | BOOST_CHECK_NO_THROW(transport->receivePacket(packet)); |
| 652 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 653 | BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 1); |
Eric Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 654 | BOOST_CHECK_EQUAL(receivedInterests.size(), 0); |
| 655 | BOOST_CHECK_EQUAL(receivedData.size(), 0); |
| 656 | BOOST_CHECK_EQUAL(receivedNacks.size(), 0); |
| 657 | } |
| 658 | |
| 659 | BOOST_AUTO_TEST_CASE(Unparsable) |
| 660 | { |
| 661 | // Initialize with Options that disables all services |
| 662 | GenericLinkService::Options options; |
| 663 | options.allowLocalFields = false; |
| 664 | initialize(options); |
| 665 | |
| 666 | Block packet = ndn::encoding::makeStringBlock(lp::tlv::LpPacket, "x"); |
| 667 | BOOST_CHECK_THROW(packet.parse(), tlv::Error); |
| 668 | |
| 669 | BOOST_CHECK_NO_THROW(transport->receivePacket(packet)); |
| 670 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 671 | BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 1); |
Eric Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 672 | BOOST_CHECK_EQUAL(receivedInterests.size(), 0); |
| 673 | BOOST_CHECK_EQUAL(receivedData.size(), 0); |
| 674 | BOOST_CHECK_EQUAL(receivedNacks.size(), 0); |
| 675 | } |
| 676 | |
| 677 | BOOST_AUTO_TEST_SUITE_END() // Malformed |
| 678 | |
| 679 | |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 680 | BOOST_AUTO_TEST_SUITE_END() // TestGenericLinkService |
| 681 | BOOST_AUTO_TEST_SUITE_END() // Face |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 682 | |
| 683 | } // namespace tests |
| 684 | } // namespace face |
| 685 | } // namespace nfd |