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