Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 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 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 402 | BOOST_AUTO_TEST_CASE(SendInterest) |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 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>()); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 419 | BOOST_CHECK(interest1pkt.has<lp::TxSequenceField>()); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 420 | } |
| 421 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 422 | BOOST_AUTO_TEST_CASE(SendData) |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 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>()); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 439 | BOOST_CHECK(data1pkt.has<lp::TxSequenceField>()); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 440 | } |
| 441 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 442 | BOOST_AUTO_TEST_CASE(SendNack) |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 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>()); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 460 | BOOST_CHECK(nack1pkt.has<lp::TxSequenceField>()); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 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 | |
Junxiao Shi | 6eb0271 | 2017-05-27 22:48:02 +0000 | [diff] [blame] | 540 | BOOST_AUTO_TEST_CASE(ReceiveCachePolicy) |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 541 | { |
Junxiao Shi | 6eb0271 | 2017-05-27 22:48:02 +0000 | [diff] [blame] | 542 | // Initialize with Options that disables local fields |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 543 | GenericLinkService::Options options; |
Junxiao Shi | 6eb0271 | 2017-05-27 22:48:02 +0000 | [diff] [blame] | 544 | options.allowLocalFields = false; |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 545 | initialize(options); |
Junxiao Shi | 6eb0271 | 2017-05-27 22:48:02 +0000 | [diff] [blame] | 546 | // CachePolicy is unprivileged and does not require allowLocalFields option. |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 547 | |
| 548 | shared_ptr<Data> data = makeData("/12345678"); |
| 549 | lp::Packet packet(data->wireEncode()); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 550 | packet.set<lp::CachePolicyField>(lp::CachePolicy().setPolicy(lp::CachePolicyType::NO_CACHE)); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 551 | |
| 552 | transport->receivePacket(packet.wireEncode()); |
| 553 | |
| 554 | BOOST_REQUIRE_EQUAL(receivedData.size(), 1); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 555 | shared_ptr<lp::CachePolicyTag> tag = receivedData.back().getTag<lp::CachePolicyTag>(); |
| 556 | BOOST_REQUIRE(tag != nullptr); |
| 557 | BOOST_CHECK_EQUAL(tag->get().getPolicy(), lp::CachePolicyType::NO_CACHE); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 558 | } |
| 559 | |
Junxiao Shi | 6eb0271 | 2017-05-27 22:48:02 +0000 | [diff] [blame] | 560 | BOOST_AUTO_TEST_CASE(ReceiveCachePolicyDropInterest) |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 561 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 562 | // Initialize with Options that enables local fields |
| 563 | GenericLinkService::Options options; |
| 564 | options.allowLocalFields = true; |
| 565 | initialize(options); |
| 566 | |
| 567 | shared_ptr<Interest> interest = makeInterest("/12345678"); |
| 568 | lp::Packet packet(interest->wireEncode()); |
| 569 | lp::CachePolicy policy; |
| 570 | policy.setPolicy(lp::CachePolicyType::NO_CACHE); |
| 571 | packet.set<lp::CachePolicyField>(policy); |
| 572 | |
| 573 | transport->receivePacket(packet.wireEncode()); |
| 574 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 575 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 576 | BOOST_CHECK(receivedInterests.empty()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 577 | } |
| 578 | |
Junxiao Shi | 6eb0271 | 2017-05-27 22:48:02 +0000 | [diff] [blame] | 579 | BOOST_AUTO_TEST_CASE(ReceiveCachePolicyDropNack) |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 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 | lp::Nack nack = makeNack("/localhost/test", 123, lp::NackReason::NO_ROUTE); |
| 587 | lp::Packet packet(nack.getInterest().wireEncode()); |
| 588 | packet.set<lp::NackField>(nack.getHeader()); |
| 589 | lp::CachePolicy policy; |
| 590 | policy.setPolicy(lp::CachePolicyType::NO_CACHE); |
| 591 | packet.set<lp::CachePolicyField>(policy); |
| 592 | |
| 593 | transport->receivePacket(packet.wireEncode()); |
| 594 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 595 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 596 | BOOST_CHECK(receivedNacks.empty()); |
| 597 | } |
| 598 | |
| 599 | BOOST_AUTO_TEST_CASE(SendIncomingFaceId) |
| 600 | { |
| 601 | // Initialize with Options that enables local fields |
| 602 | GenericLinkService::Options options; |
| 603 | options.allowLocalFields = true; |
| 604 | initialize(options); |
| 605 | |
| 606 | shared_ptr<Interest> interest = makeInterest("/12345678"); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 607 | interest->setTag(make_shared<lp::IncomingFaceIdTag>(1000)); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 608 | |
| 609 | face->sendInterest(*interest); |
| 610 | |
| 611 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
| 612 | lp::Packet sent(transport->sentPackets.back().packet); |
| 613 | BOOST_REQUIRE(sent.has<lp::IncomingFaceIdField>()); |
| 614 | BOOST_CHECK_EQUAL(sent.get<lp::IncomingFaceIdField>(), 1000); |
| 615 | } |
| 616 | |
| 617 | BOOST_AUTO_TEST_CASE(SendIncomingFaceIdDisabled) |
| 618 | { |
| 619 | // Initialize with Options that disables local fields |
| 620 | GenericLinkService::Options options; |
| 621 | options.allowLocalFields = false; |
| 622 | initialize(options); |
| 623 | |
| 624 | shared_ptr<Interest> interest = makeInterest("/12345678"); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 625 | interest->setTag(make_shared<lp::IncomingFaceIdTag>(1000)); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 626 | |
| 627 | face->sendInterest(*interest); |
| 628 | |
| 629 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
| 630 | lp::Packet sent(transport->sentPackets.back().packet); |
| 631 | BOOST_CHECK(!sent.has<lp::IncomingFaceIdField>()); |
| 632 | } |
| 633 | |
| 634 | BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreInterest) |
| 635 | { |
| 636 | // Initialize with Options that enables local fields |
| 637 | GenericLinkService::Options options; |
| 638 | options.allowLocalFields = true; |
| 639 | initialize(options); |
| 640 | |
| 641 | shared_ptr<Interest> interest = makeInterest("/12345678"); |
| 642 | lp::Packet packet(interest->wireEncode()); |
| 643 | packet.set<lp::IncomingFaceIdField>(1000); |
| 644 | |
| 645 | transport->receivePacket(packet.wireEncode()); |
| 646 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 647 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 648 | BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 649 | BOOST_CHECK(receivedInterests.back().getTag<lp::IncomingFaceIdTag>() == nullptr); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreData) |
| 653 | { |
| 654 | // Initialize with Options that enables local fields |
| 655 | GenericLinkService::Options options; |
| 656 | options.allowLocalFields = true; |
| 657 | initialize(options); |
| 658 | |
| 659 | shared_ptr<Data> data = makeData("/z1megUh9Bj"); |
| 660 | lp::Packet packet(data->wireEncode()); |
| 661 | packet.set<lp::IncomingFaceIdField>(1000); |
| 662 | |
| 663 | transport->receivePacket(packet.wireEncode()); |
| 664 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 665 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 666 | BOOST_REQUIRE_EQUAL(receivedData.size(), 1); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 667 | BOOST_CHECK(receivedData.back().getTag<lp::IncomingFaceIdTag>() == nullptr); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreNack) |
| 671 | { |
| 672 | // Initialize with Options that enables local fields |
| 673 | GenericLinkService::Options options; |
| 674 | options.allowLocalFields = true; |
| 675 | initialize(options); |
| 676 | |
| 677 | lp::Nack nack = makeNack("/TPAhdiHz", 278, lp::NackReason::CONGESTION); |
| 678 | lp::Packet packet(nack.getInterest().wireEncode()); |
| 679 | packet.set<lp::NackField>(nack.getHeader()); |
| 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(receivedNacks.size(), 1); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 686 | BOOST_CHECK(receivedNacks.back().getTag<lp::IncomingFaceIdTag>() == nullptr); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 687 | } |
| 688 | |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 689 | BOOST_AUTO_TEST_CASE(SendCongestionMarkInterest) |
| 690 | { |
| 691 | shared_ptr<Interest> interest = makeInterest("/12345678"); |
| 692 | interest->setTag(make_shared<lp::CongestionMarkTag>(1)); |
| 693 | |
| 694 | face->sendInterest(*interest); |
| 695 | |
| 696 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
| 697 | lp::Packet sent(transport->sentPackets.back().packet); |
| 698 | BOOST_REQUIRE(sent.has<lp::CongestionMarkField>()); |
| 699 | BOOST_CHECK_EQUAL(sent.get<lp::CongestionMarkField>(), 1); |
| 700 | } |
| 701 | |
| 702 | BOOST_AUTO_TEST_CASE(SendCongestionMarkData) |
| 703 | { |
| 704 | shared_ptr<Data> data = makeData("/12345678"); |
| 705 | data->setTag(make_shared<lp::CongestionMarkTag>(0)); |
| 706 | |
| 707 | face->sendData(*data); |
| 708 | |
| 709 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
| 710 | lp::Packet sent(transport->sentPackets.back().packet); |
| 711 | BOOST_REQUIRE(sent.has<lp::CongestionMarkField>()); |
| 712 | BOOST_CHECK_EQUAL(sent.get<lp::CongestionMarkField>(), 0); |
| 713 | } |
| 714 | |
| 715 | BOOST_AUTO_TEST_CASE(SendCongestionMarkNack) |
| 716 | { |
| 717 | lp::Nack nack = makeNack("/localhost/test", 123, lp::NackReason::NO_ROUTE); |
| 718 | nack.setTag(make_shared<lp::CongestionMarkTag>(std::numeric_limits<uint64_t>::max())); |
| 719 | |
| 720 | face->sendNack(nack); |
| 721 | |
| 722 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
| 723 | lp::Packet sent(transport->sentPackets.back().packet); |
| 724 | BOOST_REQUIRE(sent.has<lp::CongestionMarkField>()); |
| 725 | BOOST_CHECK_EQUAL(sent.get<lp::CongestionMarkField>(), std::numeric_limits<uint64_t>::max()); |
| 726 | } |
| 727 | |
| 728 | BOOST_AUTO_TEST_CASE(ReceiveCongestionMarkInterest) |
| 729 | { |
| 730 | shared_ptr<Interest> interest = makeInterest("/12345678"); |
| 731 | lp::Packet packet(interest->wireEncode()); |
| 732 | packet.set<lp::CongestionMarkField>(1); |
| 733 | |
| 734 | transport->receivePacket(packet.wireEncode()); |
| 735 | |
| 736 | BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1); |
| 737 | shared_ptr<lp::CongestionMarkTag> tag = receivedInterests.back().getTag<lp::CongestionMarkTag>(); |
| 738 | BOOST_REQUIRE(tag != nullptr); |
| 739 | BOOST_CHECK_EQUAL(*tag, 1); |
| 740 | } |
| 741 | |
| 742 | BOOST_AUTO_TEST_CASE(ReceiveCongestionMarkData) |
| 743 | { |
| 744 | shared_ptr<Data> data = makeData("/12345678"); |
| 745 | lp::Packet packet(data->wireEncode()); |
| 746 | packet.set<lp::CongestionMarkField>(1); |
| 747 | |
| 748 | transport->receivePacket(packet.wireEncode()); |
| 749 | |
| 750 | BOOST_REQUIRE_EQUAL(receivedData.size(), 1); |
| 751 | shared_ptr<lp::CongestionMarkTag> tag = receivedData.back().getTag<lp::CongestionMarkTag>(); |
| 752 | BOOST_REQUIRE(tag != nullptr); |
| 753 | BOOST_CHECK_EQUAL(*tag, 1); |
| 754 | } |
| 755 | |
| 756 | BOOST_AUTO_TEST_CASE(ReceiveCongestionMarkNack) |
| 757 | { |
| 758 | lp::Nack nack = makeNack("/localhost/test", 123, lp::NackReason::NO_ROUTE); |
| 759 | lp::Packet packet; |
| 760 | packet.set<lp::FragmentField>(std::make_pair( |
| 761 | nack.getInterest().wireEncode().begin(), nack.getInterest().wireEncode().end())); |
| 762 | packet.set<lp::NackField>(nack.getHeader()); |
| 763 | packet.set<lp::CongestionMarkField>(1); |
| 764 | |
| 765 | transport->receivePacket(packet.wireEncode()); |
| 766 | |
| 767 | BOOST_REQUIRE_EQUAL(receivedNacks.size(), 1); |
| 768 | shared_ptr<lp::CongestionMarkTag> tag = receivedNacks.back().getTag<lp::CongestionMarkTag>(); |
| 769 | BOOST_REQUIRE(tag != nullptr); |
| 770 | BOOST_CHECK_EQUAL(*tag, 1); |
| 771 | } |
| 772 | |
| 773 | BOOST_AUTO_TEST_SUITE_END() // LpFields |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 774 | |
| 775 | |
Eric Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 776 | BOOST_AUTO_TEST_SUITE(Malformed) // receive malformed packets |
| 777 | |
| 778 | BOOST_AUTO_TEST_CASE(WrongTlvType) |
| 779 | { |
| 780 | // Initialize with Options that disables all services |
| 781 | GenericLinkService::Options options; |
| 782 | options.allowLocalFields = false; |
| 783 | initialize(options); |
| 784 | |
| 785 | Block packet = ndn::encoding::makeEmptyBlock(tlv::Name); |
| 786 | |
| 787 | BOOST_CHECK_NO_THROW(transport->receivePacket(packet)); |
| 788 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 789 | BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 1); |
Eric Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 790 | BOOST_CHECK_EQUAL(receivedInterests.size(), 0); |
| 791 | BOOST_CHECK_EQUAL(receivedData.size(), 0); |
| 792 | BOOST_CHECK_EQUAL(receivedNacks.size(), 0); |
| 793 | } |
| 794 | |
| 795 | BOOST_AUTO_TEST_CASE(Unparsable) |
| 796 | { |
| 797 | // Initialize with Options that disables all services |
| 798 | GenericLinkService::Options options; |
| 799 | options.allowLocalFields = false; |
| 800 | initialize(options); |
| 801 | |
| 802 | Block packet = ndn::encoding::makeStringBlock(lp::tlv::LpPacket, "x"); |
| 803 | BOOST_CHECK_THROW(packet.parse(), tlv::Error); |
| 804 | |
| 805 | BOOST_CHECK_NO_THROW(transport->receivePacket(packet)); |
| 806 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 807 | BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 1); |
Eric Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 808 | BOOST_CHECK_EQUAL(receivedInterests.size(), 0); |
| 809 | BOOST_CHECK_EQUAL(receivedData.size(), 0); |
| 810 | BOOST_CHECK_EQUAL(receivedNacks.size(), 0); |
| 811 | } |
| 812 | |
| 813 | BOOST_AUTO_TEST_SUITE_END() // Malformed |
| 814 | |
| 815 | |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 816 | BOOST_AUTO_TEST_SUITE_END() // TestGenericLinkService |
| 817 | BOOST_AUTO_TEST_SUITE_END() // Face |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 818 | |
| 819 | } // namespace tests |
| 820 | } // namespace face |
| 821 | } // namespace nfd |