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