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