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 | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014-2018, 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 | |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 29 | #include "test-common.hpp" |
| 30 | #include "dummy-transport.hpp" |
| 31 | |
| 32 | #include <ndn-cxx/lp/tags.hpp> |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 33 | |
| 34 | namespace nfd { |
| 35 | namespace face { |
| 36 | namespace tests { |
| 37 | |
| 38 | using namespace nfd::tests; |
| 39 | |
| 40 | BOOST_AUTO_TEST_SUITE(Face) |
| 41 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 42 | using nfd::Face; |
| 43 | |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 44 | class GenericLinkServiceFixture : public UnitTestTimeFixture |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 45 | { |
| 46 | protected: |
| 47 | GenericLinkServiceFixture() |
| 48 | : service(nullptr) |
| 49 | , transport(nullptr) |
| 50 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 51 | this->initialize(GenericLinkService::Options()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 52 | // By default, GenericLinkService is created with default options. |
| 53 | // Test cases may invoke .initialize with alternate options. |
| 54 | } |
| 55 | |
| 56 | void |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 57 | initialize(const GenericLinkService::Options& options, |
| 58 | ssize_t mtu = MTU_UNLIMITED, |
| 59 | ssize_t sendQueueCapacity = QUEUE_UNSUPPORTED) |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 60 | { |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 61 | face.reset(new Face(make_unique<GenericLinkService>(options), |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 62 | make_unique<DummyTransport>("dummy://", |
| 63 | "dummy://", |
| 64 | ndn::nfd::FACE_SCOPE_NON_LOCAL, |
| 65 | ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
| 66 | ndn::nfd::LINK_TYPE_POINT_TO_POINT, |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 67 | mtu, |
| 68 | sendQueueCapacity))); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 69 | service = static_cast<GenericLinkService*>(face->getLinkService()); |
| 70 | transport = static_cast<DummyTransport*>(face->getTransport()); |
| 71 | |
| 72 | face->afterReceiveInterest.connect( |
| 73 | [this] (const Interest& interest) { receivedInterests.push_back(interest); }); |
| 74 | face->afterReceiveData.connect( |
| 75 | [this] (const Data& data) { receivedData.push_back(data); }); |
| 76 | face->afterReceiveNack.connect( |
| 77 | [this] (const lp::Nack& nack) { receivedNacks.push_back(nack); }); |
| 78 | } |
| 79 | |
| 80 | protected: |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 81 | unique_ptr<Face> face; |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 82 | GenericLinkService* service; |
| 83 | DummyTransport* transport; |
| 84 | std::vector<Interest> receivedInterests; |
| 85 | std::vector<Data> receivedData; |
| 86 | std::vector<lp::Nack> receivedNacks; |
| 87 | }; |
| 88 | |
| 89 | BOOST_FIXTURE_TEST_SUITE(TestGenericLinkService, GenericLinkServiceFixture) |
| 90 | |
| 91 | |
| 92 | BOOST_AUTO_TEST_SUITE(SimpleSendReceive) // send and receive without other fields |
| 93 | |
| 94 | BOOST_AUTO_TEST_CASE(SendInterest) |
| 95 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 96 | // Initialize with Options that disables all services |
| 97 | GenericLinkService::Options options; |
| 98 | options.allowLocalFields = false; |
| 99 | initialize(options); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 100 | |
| 101 | shared_ptr<Interest> interest1 = makeInterest("/localhost/test"); |
| 102 | |
| 103 | face->sendInterest(*interest1); |
| 104 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 105 | BOOST_CHECK_EQUAL(service->getCounters().nOutInterests, 1); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 106 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 107 | lp::Packet interest1pkt; |
| 108 | BOOST_REQUIRE_NO_THROW(interest1pkt.wireDecode(transport->sentPackets.back().packet)); |
| 109 | BOOST_CHECK(interest1pkt.has<lp::FragmentField>()); |
| 110 | BOOST_CHECK(!interest1pkt.has<lp::SequenceField>()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | BOOST_AUTO_TEST_CASE(SendData) |
| 114 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 115 | // Initialize with Options that disables all services |
| 116 | GenericLinkService::Options options; |
| 117 | options.allowLocalFields = false; |
| 118 | initialize(options); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 119 | |
| 120 | shared_ptr<Data> data1 = makeData("/localhost/test"); |
| 121 | |
| 122 | face->sendData(*data1); |
| 123 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 124 | BOOST_CHECK_EQUAL(service->getCounters().nOutData, 1); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 125 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 126 | lp::Packet data1pkt; |
| 127 | BOOST_REQUIRE_NO_THROW(data1pkt.wireDecode(transport->sentPackets.back().packet)); |
| 128 | BOOST_CHECK(data1pkt.has<lp::FragmentField>()); |
| 129 | BOOST_CHECK(!data1pkt.has<lp::SequenceField>()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | BOOST_AUTO_TEST_CASE(SendNack) |
| 133 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 134 | // Initialize with Options that disables all services |
| 135 | GenericLinkService::Options options; |
| 136 | options.allowLocalFields = false; |
| 137 | initialize(options); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 138 | |
| 139 | lp::Nack nack1 = makeNack("/localhost/test", 323, lp::NackReason::NO_ROUTE); |
| 140 | |
| 141 | face->sendNack(nack1); |
| 142 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 143 | BOOST_CHECK_EQUAL(service->getCounters().nOutNacks, 1); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 144 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
| 145 | lp::Packet nack1pkt; |
| 146 | BOOST_REQUIRE_NO_THROW(nack1pkt.wireDecode(transport->sentPackets.back().packet)); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 147 | BOOST_CHECK(nack1pkt.has<lp::NackField>()); |
| 148 | BOOST_CHECK(nack1pkt.has<lp::FragmentField>()); |
| 149 | BOOST_CHECK(!nack1pkt.has<lp::SequenceField>()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | BOOST_AUTO_TEST_CASE(ReceiveBareInterest) |
| 153 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 154 | // Initialize with Options that disables all services |
| 155 | GenericLinkService::Options options; |
| 156 | options.allowLocalFields = false; |
| 157 | initialize(options); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 158 | |
| 159 | shared_ptr<Interest> interest1 = makeInterest("/23Rd9hEiR"); |
| 160 | |
| 161 | transport->receivePacket(interest1->wireEncode()); |
| 162 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 163 | BOOST_CHECK_EQUAL(service->getCounters().nInInterests, 1); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 164 | BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1); |
| 165 | BOOST_CHECK_EQUAL(receivedInterests.back(), *interest1); |
| 166 | } |
| 167 | |
| 168 | BOOST_AUTO_TEST_CASE(ReceiveInterest) |
| 169 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 170 | // Initialize with Options that disables all services |
| 171 | GenericLinkService::Options options; |
| 172 | options.allowLocalFields = false; |
| 173 | initialize(options); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 174 | |
| 175 | shared_ptr<Interest> interest1 = makeInterest("/23Rd9hEiR"); |
| 176 | lp::Packet lpPacket; |
| 177 | lpPacket.set<lp::FragmentField>(std::make_pair( |
| 178 | interest1->wireEncode().begin(), interest1->wireEncode().end())); |
| 179 | lpPacket.set<lp::SequenceField>(0); // force LpPacket encoding |
| 180 | |
| 181 | transport->receivePacket(lpPacket.wireEncode()); |
| 182 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 183 | BOOST_CHECK_EQUAL(service->getCounters().nInInterests, 1); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 184 | BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1); |
| 185 | BOOST_CHECK_EQUAL(receivedInterests.back(), *interest1); |
| 186 | } |
| 187 | |
| 188 | BOOST_AUTO_TEST_CASE(ReceiveBareData) |
| 189 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 190 | // Initialize with Options that disables all services |
| 191 | GenericLinkService::Options options; |
| 192 | options.allowLocalFields = false; |
| 193 | initialize(options); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 194 | |
| 195 | shared_ptr<Data> data1 = makeData("/12345678"); |
| 196 | |
| 197 | transport->receivePacket(data1->wireEncode()); |
| 198 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 199 | BOOST_CHECK_EQUAL(service->getCounters().nInData, 1); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 200 | BOOST_REQUIRE_EQUAL(receivedData.size(), 1); |
| 201 | BOOST_CHECK_EQUAL(receivedData.back(), *data1); |
| 202 | } |
| 203 | |
| 204 | BOOST_AUTO_TEST_CASE(ReceiveData) |
| 205 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 206 | // Initialize with Options that disables all services |
| 207 | GenericLinkService::Options options; |
| 208 | options.allowLocalFields = false; |
| 209 | initialize(options); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 210 | |
| 211 | shared_ptr<Data> data1 = makeData("/12345689"); |
| 212 | lp::Packet lpPacket; |
| 213 | lpPacket.set<lp::FragmentField>(std::make_pair( |
| 214 | data1->wireEncode().begin(), data1->wireEncode().end())); |
| 215 | lpPacket.set<lp::SequenceField>(0); // force LpPacket encoding |
| 216 | |
| 217 | transport->receivePacket(lpPacket.wireEncode()); |
| 218 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 219 | BOOST_CHECK_EQUAL(service->getCounters().nInData, 1); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 220 | BOOST_REQUIRE_EQUAL(receivedData.size(), 1); |
| 221 | BOOST_CHECK_EQUAL(receivedData.back(), *data1); |
| 222 | } |
| 223 | |
| 224 | BOOST_AUTO_TEST_CASE(ReceiveNack) |
| 225 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 226 | // Initialize with Options that disables all services |
| 227 | GenericLinkService::Options options; |
| 228 | options.allowLocalFields = false; |
| 229 | initialize(options); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 230 | |
| 231 | lp::Nack nack1 = makeNack("/localhost/test", 323, lp::NackReason::NO_ROUTE); |
| 232 | lp::Packet lpPacket; |
| 233 | lpPacket.set<lp::FragmentField>(std::make_pair( |
| 234 | nack1.getInterest().wireEncode().begin(), nack1.getInterest().wireEncode().end())); |
| 235 | lpPacket.set<lp::NackField>(nack1.getHeader()); |
| 236 | |
| 237 | transport->receivePacket(lpPacket.wireEncode()); |
| 238 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 239 | BOOST_CHECK_EQUAL(service->getCounters().nInNacks, 1); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 240 | BOOST_REQUIRE_EQUAL(receivedNacks.size(), 1); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 241 | BOOST_CHECK(receivedNacks.back().getReason() == nack1.getReason()); |
| 242 | BOOST_CHECK(receivedNacks.back().getInterest() == nack1.getInterest()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 243 | } |
| 244 | |
Eric Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 245 | BOOST_AUTO_TEST_CASE(ReceiveIdlePacket) |
| 246 | { |
| 247 | // Initialize with Options that disables all services |
| 248 | GenericLinkService::Options options; |
| 249 | options.allowLocalFields = false; |
| 250 | initialize(options); |
| 251 | |
| 252 | lp::Packet lpPacket; |
| 253 | lpPacket.set<lp::SequenceField>(0); |
| 254 | |
| 255 | BOOST_CHECK_NO_THROW(transport->receivePacket(lpPacket.wireEncode())); |
| 256 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 257 | // IDLE packet should be ignored, but is not an error |
| 258 | BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 0); |
Eric Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 259 | BOOST_CHECK_EQUAL(receivedInterests.size(), 0); |
| 260 | BOOST_CHECK_EQUAL(receivedData.size(), 0); |
| 261 | BOOST_CHECK_EQUAL(receivedNacks.size(), 0); |
| 262 | } |
| 263 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 264 | BOOST_AUTO_TEST_SUITE_END() // SimpleSendReceive |
| 265 | |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 266 | BOOST_AUTO_TEST_SUITE(Fragmentation) |
| 267 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 268 | BOOST_AUTO_TEST_CASE(FragmentationDisabledExceedMtuDrop) |
| 269 | { |
| 270 | // Initialize with Options that disable fragmentation |
| 271 | GenericLinkService::Options options; |
| 272 | options.allowFragmentation = false; |
| 273 | initialize(options); |
| 274 | |
| 275 | transport->setMtu(55); |
| 276 | |
| 277 | shared_ptr<Data> data = makeData("/test/data/123456789/987654321/123456789"); |
| 278 | face->sendData(*data); |
| 279 | |
| 280 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 0); |
| 281 | BOOST_CHECK_EQUAL(service->getCounters().nOutOverMtu, 1); |
| 282 | } |
| 283 | |
| 284 | BOOST_AUTO_TEST_CASE(FragmentationUnlimitedMtu) |
| 285 | { |
| 286 | // Initialize with Options that enable fragmentation |
| 287 | GenericLinkService::Options options; |
| 288 | options.allowFragmentation = true; |
| 289 | initialize(options); |
| 290 | |
| 291 | transport->setMtu(MTU_UNLIMITED); |
| 292 | |
| 293 | shared_ptr<Data> data = makeData("/test/data/123456789/987654321/123456789"); |
| 294 | face->sendData(*data); |
| 295 | |
| 296 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 1); |
| 297 | } |
| 298 | |
| 299 | BOOST_AUTO_TEST_CASE(FragmentationUnderMtu) |
| 300 | { |
| 301 | // Initialize with Options that enable fragmentation |
| 302 | GenericLinkService::Options options; |
| 303 | options.allowFragmentation = true; |
| 304 | initialize(options); |
| 305 | |
| 306 | transport->setMtu(105); |
| 307 | |
| 308 | shared_ptr<Data> data = makeData("/test/data/123456789/987654321/123456789"); |
| 309 | face->sendData(*data); |
| 310 | |
| 311 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 1); |
| 312 | } |
| 313 | |
| 314 | BOOST_AUTO_TEST_CASE(FragmentationOverMtu) |
| 315 | { |
| 316 | // Initialize with Options that enable fragmentation |
| 317 | GenericLinkService::Options options; |
| 318 | options.allowFragmentation = true; |
| 319 | initialize(options); |
| 320 | |
| 321 | transport->setMtu(60); |
| 322 | |
| 323 | shared_ptr<Data> data = makeData("/test/data/123456789/987654321/123456789"); |
| 324 | face->sendData(*data); |
| 325 | |
| 326 | BOOST_CHECK_GT(transport->sentPackets.size(), 1); |
| 327 | } |
| 328 | |
| 329 | BOOST_AUTO_TEST_CASE(ReassembleFragments) |
| 330 | { |
| 331 | // Initialize with Options that enables reassembly |
| 332 | GenericLinkService::Options options; |
| 333 | options.allowReassembly = true; |
| 334 | initialize(options); |
| 335 | |
| 336 | shared_ptr<Interest> interest = makeInterest( |
| 337 | "/mt7P130BHXmtLm5dwaY5dpUM6SWYNN2B05g7y3UhsQuLvDdnTWdNnTeEiLuW3FAbJRSG3tzQ0UfaSEgG9rvYHmsKtgPMag1Hj4Tr"); |
| 338 | lp::Packet packet(interest->wireEncode()); |
| 339 | |
| 340 | // fragment the packet |
| 341 | LpFragmenter fragmenter; |
| 342 | size_t mtu = 100; |
| 343 | bool isOk = false; |
| 344 | std::vector<lp::Packet> frags; |
| 345 | std::tie(isOk, frags) = fragmenter.fragmentPacket(packet, mtu); |
| 346 | BOOST_REQUIRE(isOk); |
| 347 | BOOST_CHECK_GT(frags.size(), 1); |
| 348 | |
| 349 | // receive the fragments |
| 350 | for (ssize_t fragIndex = frags.size() - 1; fragIndex >= 0; --fragIndex) { |
| 351 | size_t sequence = 1000 + fragIndex; |
| 352 | frags[fragIndex].add<lp::SequenceField>(sequence); |
| 353 | |
| 354 | transport->receivePacket(frags[fragIndex].wireEncode()); |
| 355 | |
| 356 | if (fragIndex > 0) { |
| 357 | BOOST_CHECK(receivedInterests.empty()); |
| 358 | BOOST_CHECK_EQUAL(service->getCounters().nReassembling, 1); |
| 359 | } |
| 360 | else { |
| 361 | BOOST_CHECK_EQUAL(receivedInterests.size(), 1); |
| 362 | BOOST_CHECK_EQUAL(receivedInterests.back(), *interest); |
| 363 | BOOST_CHECK_EQUAL(service->getCounters().nReassembling, 0); |
| 364 | } |
| 365 | } |
| 366 | } |
| 367 | |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 368 | BOOST_AUTO_TEST_CASE(ReassemblyDisabledDropFragIndex) |
| 369 | { |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 370 | // Initialize with Options that disables reassembly |
| 371 | GenericLinkService::Options options; |
| 372 | options.allowReassembly = false; |
| 373 | initialize(options); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 374 | |
| 375 | shared_ptr<Interest> interest = makeInterest("/IgFe6NvH"); |
| 376 | lp::Packet packet(interest->wireEncode()); |
| 377 | packet.set<lp::FragIndexField>(140); |
| 378 | |
| 379 | transport->receivePacket(packet.wireEncode()); |
| 380 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 381 | BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 0); // not an error |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 382 | BOOST_CHECK(receivedInterests.empty()); |
| 383 | } |
| 384 | |
| 385 | BOOST_AUTO_TEST_CASE(ReassemblyDisabledDropFragCount) |
| 386 | { |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 387 | // Initialize with Options that disables reassembly |
| 388 | GenericLinkService::Options options; |
| 389 | options.allowReassembly = false; |
| 390 | initialize(options); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 391 | |
| 392 | shared_ptr<Interest> interest = makeInterest("/SeGmEjvIVX"); |
| 393 | lp::Packet packet(interest->wireEncode()); |
| 394 | packet.set<lp::FragCountField>(276); |
| 395 | |
| 396 | transport->receivePacket(packet.wireEncode()); |
| 397 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 398 | BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 0); // not an error |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 399 | BOOST_CHECK(receivedInterests.empty()); |
| 400 | } |
| 401 | |
| 402 | BOOST_AUTO_TEST_SUITE_END() // Fragmentation |
| 403 | |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 404 | BOOST_AUTO_TEST_SUITE(Reliability) |
| 405 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 406 | BOOST_AUTO_TEST_CASE(SendInterest) |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 407 | { |
| 408 | // Initialize with Options that enables reliability |
| 409 | GenericLinkService::Options options; |
| 410 | options.allowLocalFields = false; |
| 411 | options.reliabilityOptions.isEnabled = true; |
| 412 | initialize(options); |
| 413 | |
| 414 | shared_ptr<Interest> interest1 = makeInterest("/localhost/test"); |
| 415 | |
| 416 | face->sendInterest(*interest1); |
| 417 | |
| 418 | BOOST_CHECK_EQUAL(service->getCounters().nOutInterests, 1); |
| 419 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
| 420 | lp::Packet interest1pkt; |
| 421 | BOOST_REQUIRE_NO_THROW(interest1pkt.wireDecode(transport->sentPackets.back().packet)); |
| 422 | BOOST_CHECK(interest1pkt.has<lp::FragmentField>()); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 423 | BOOST_CHECK(interest1pkt.has<lp::TxSequenceField>()); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 424 | } |
| 425 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 426 | BOOST_AUTO_TEST_CASE(SendData) |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 427 | { |
| 428 | // Initialize with Options that enables reliability |
| 429 | GenericLinkService::Options options; |
| 430 | options.allowLocalFields = false; |
| 431 | options.reliabilityOptions.isEnabled = true; |
| 432 | initialize(options); |
| 433 | |
| 434 | shared_ptr<Data> data1 = makeData("/localhost/test"); |
| 435 | |
| 436 | face->sendData(*data1); |
| 437 | |
| 438 | BOOST_CHECK_EQUAL(service->getCounters().nOutData, 1); |
| 439 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
| 440 | lp::Packet data1pkt; |
| 441 | BOOST_REQUIRE_NO_THROW(data1pkt.wireDecode(transport->sentPackets.back().packet)); |
| 442 | BOOST_CHECK(data1pkt.has<lp::FragmentField>()); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 443 | BOOST_CHECK(data1pkt.has<lp::TxSequenceField>()); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 444 | } |
| 445 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 446 | BOOST_AUTO_TEST_CASE(SendNack) |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 447 | { |
| 448 | // Initialize with Options that enables reliability |
| 449 | GenericLinkService::Options options; |
| 450 | options.allowLocalFields = false; |
| 451 | options.reliabilityOptions.isEnabled = true; |
| 452 | initialize(options); |
| 453 | |
| 454 | lp::Nack nack1 = makeNack("/localhost/test", 323, lp::NackReason::NO_ROUTE); |
| 455 | |
| 456 | face->sendNack(nack1); |
| 457 | |
| 458 | BOOST_CHECK_EQUAL(service->getCounters().nOutNacks, 1); |
| 459 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
| 460 | lp::Packet nack1pkt; |
| 461 | BOOST_REQUIRE_NO_THROW(nack1pkt.wireDecode(transport->sentPackets.back().packet)); |
| 462 | BOOST_CHECK(nack1pkt.has<lp::NackField>()); |
| 463 | BOOST_CHECK(nack1pkt.has<lp::FragmentField>()); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 464 | BOOST_CHECK(nack1pkt.has<lp::TxSequenceField>()); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | BOOST_AUTO_TEST_SUITE_END() // Reliability |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 468 | |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 469 | // congestion detection and marking |
| 470 | BOOST_AUTO_TEST_SUITE(CongestionMark) |
| 471 | |
| 472 | BOOST_AUTO_TEST_CASE(NoCongestion) |
| 473 | { |
| 474 | GenericLinkService::Options options; |
| 475 | options.allowCongestionMarking = true; |
| 476 | options.baseCongestionMarkingInterval = time::milliseconds(100); |
| 477 | initialize(options, MTU_UNLIMITED, 65536); |
| 478 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max()); |
| 479 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 480 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0); |
| 481 | |
| 482 | shared_ptr<Interest> interest = makeInterest("/12345678"); |
| 483 | |
| 484 | // congestion threshold will be 32768 bytes, since min(65536, 65536 / 2) = 32768 bytes |
| 485 | |
| 486 | // no congestion |
| 487 | transport->setSendQueueLength(0); |
| 488 | face->sendInterest(*interest); |
| 489 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
| 490 | lp::Packet pkt1; |
| 491 | BOOST_REQUIRE_NO_THROW(pkt1.wireDecode(transport->sentPackets.back().packet)); |
| 492 | BOOST_CHECK_EQUAL(pkt1.count<lp::CongestionMarkField>(), 0); |
| 493 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max()); |
| 494 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 495 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0); |
| 496 | |
| 497 | // no congestion |
| 498 | transport->setSendQueueLength(32768); |
| 499 | face->sendInterest(*interest); |
| 500 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 2); |
| 501 | lp::Packet pkt2; |
| 502 | BOOST_REQUIRE_NO_THROW(pkt2.wireDecode(transport->sentPackets.back().packet)); |
| 503 | BOOST_CHECK_EQUAL(pkt2.count<lp::CongestionMarkField>(), 0); |
| 504 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max()); |
| 505 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 506 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0); |
| 507 | } |
| 508 | |
| 509 | BOOST_AUTO_TEST_CASE(CongestionCoDel) |
| 510 | { |
| 511 | GenericLinkService::Options options; |
| 512 | options.allowCongestionMarking = true; |
| 513 | options.baseCongestionMarkingInterval = time::milliseconds(100); |
| 514 | initialize(options, MTU_UNLIMITED, 65536); |
| 515 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max()); |
| 516 | BOOST_CHECK_EQUAL(service->m_lastMarkTime, time::steady_clock::TimePoint::min()); |
| 517 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 518 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0); |
| 519 | |
| 520 | shared_ptr<Interest> interest = makeInterest("/12345678"); |
| 521 | |
| 522 | // congestion threshold will be 32768 bytes, since min(65536, 65536 / 2) = 32768 bytes |
| 523 | |
| 524 | // first congested packet, will be marked |
| 525 | transport->setSendQueueLength(32769); |
| 526 | face->sendInterest(*interest); |
| 527 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
| 528 | lp::Packet pkt1; |
| 529 | BOOST_REQUIRE_NO_THROW(pkt1.wireDecode(transport->sentPackets.back().packet)); |
| 530 | BOOST_REQUIRE_EQUAL(pkt1.count<lp::CongestionMarkField>(), 1); |
| 531 | BOOST_CHECK_EQUAL(pkt1.get<lp::CongestionMarkField>(), 1); |
| 532 | time::steady_clock::TimePoint nextMarkTime = time::steady_clock::now() + time::milliseconds(100); |
| 533 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
| 534 | time::steady_clock::TimePoint lastMarkTime = time::steady_clock::now(); |
| 535 | BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime); |
| 536 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1); |
| 537 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 1); |
| 538 | |
| 539 | // advance clock to half of marking interval cycle |
| 540 | advanceClocks(time::milliseconds(50)); |
| 541 | |
| 542 | // second congested packet, but within marking interval, will not be marked |
| 543 | transport->setSendQueueLength(33000); |
| 544 | face->sendInterest(*interest); |
| 545 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 2); |
| 546 | lp::Packet pkt2; |
| 547 | BOOST_REQUIRE_NO_THROW(pkt2.wireDecode(transport->sentPackets.back().packet)); |
| 548 | BOOST_CHECK_EQUAL(pkt2.count<lp::CongestionMarkField>(), 0); |
| 549 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
| 550 | BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime); |
| 551 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1); |
| 552 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 1); |
| 553 | |
| 554 | // advance clocks past end of initial interval cycle |
| 555 | this->advanceClocks(time::milliseconds(51)); |
| 556 | |
| 557 | // first congested packet after waiting marking interval, will be marked |
| 558 | transport->setSendQueueLength(40000); |
| 559 | face->sendInterest(*interest); |
| 560 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 3); |
| 561 | lp::Packet pkt3; |
| 562 | BOOST_REQUIRE_NO_THROW(pkt3.wireDecode(transport->sentPackets.back().packet)); |
| 563 | BOOST_REQUIRE_EQUAL(pkt3.count<lp::CongestionMarkField>(), 1); |
| 564 | BOOST_CHECK_EQUAL(pkt3.get<lp::CongestionMarkField>(), 1); |
| 565 | time::nanoseconds markingInterval( |
| 566 | static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() / |
| 567 | std::sqrt(service->m_nMarkedSinceInMarkingState))); |
| 568 | nextMarkTime += markingInterval; |
| 569 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
| 570 | lastMarkTime = time::steady_clock::now(); |
| 571 | BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime); |
| 572 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 2); |
| 573 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 2); |
| 574 | |
| 575 | // advance clock partway through current marking interval |
| 576 | this->advanceClocks(markingInterval - time::milliseconds(10)); |
| 577 | |
| 578 | // still congested, but within marking interval cycle |
| 579 | transport->setSendQueueLength(38000); |
| 580 | face->sendInterest(*interest); |
| 581 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 4); |
| 582 | lp::Packet pkt4; |
| 583 | BOOST_REQUIRE_NO_THROW(pkt4.wireDecode(transport->sentPackets.back().packet)); |
| 584 | BOOST_CHECK_EQUAL(pkt4.count<lp::CongestionMarkField>(), 0); |
| 585 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
| 586 | BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime); |
| 587 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 2); |
| 588 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 2); |
| 589 | |
| 590 | // advance clocks past end of current marking interval cycle |
| 591 | this->advanceClocks(time::milliseconds(11)); |
| 592 | |
| 593 | // still congested, after marking interval cycle |
| 594 | transport->setSendQueueLength(39000); |
| 595 | face->sendInterest(*interest); |
| 596 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 5); |
| 597 | lp::Packet pkt5; |
| 598 | BOOST_REQUIRE_NO_THROW(pkt5.wireDecode(transport->sentPackets.back().packet)); |
| 599 | BOOST_REQUIRE_EQUAL(pkt5.count<lp::CongestionMarkField>(), 1); |
| 600 | BOOST_CHECK_EQUAL(pkt5.get<lp::CongestionMarkField>(), 1); |
| 601 | markingInterval = time::nanoseconds( |
| 602 | static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() / |
| 603 | std::sqrt(service->m_nMarkedSinceInMarkingState))); |
| 604 | nextMarkTime += markingInterval; |
| 605 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
| 606 | lastMarkTime = time::steady_clock::now(); |
| 607 | BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime); |
| 608 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 3); |
| 609 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 3); |
| 610 | |
| 611 | this->advanceClocks(time::milliseconds(1)); |
| 612 | |
| 613 | // still congested, but within marking interval cycle |
| 614 | transport->setSendQueueLength(38000); |
| 615 | face->sendInterest(*interest); |
| 616 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 6); |
| 617 | lp::Packet pkt6; |
| 618 | BOOST_REQUIRE_NO_THROW(pkt6.wireDecode(transport->sentPackets.back().packet)); |
| 619 | BOOST_CHECK_EQUAL(pkt6.count<lp::CongestionMarkField>(), 0); |
| 620 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
| 621 | BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime); |
| 622 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 3); |
| 623 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 3); |
| 624 | |
| 625 | this->advanceClocks(markingInterval); |
| 626 | |
| 627 | // still congested, after marking interval cycle |
| 628 | transport->setSendQueueLength(34000); |
| 629 | face->sendInterest(*interest); |
| 630 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 7); |
| 631 | lp::Packet pkt7; |
| 632 | BOOST_REQUIRE_NO_THROW(pkt7.wireDecode(transport->sentPackets.back().packet)); |
| 633 | BOOST_REQUIRE_EQUAL(pkt7.count<lp::CongestionMarkField>(), 1); |
| 634 | BOOST_CHECK_EQUAL(pkt7.get<lp::CongestionMarkField>(), 1); |
| 635 | markingInterval = time::nanoseconds( |
| 636 | static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() / |
| 637 | std::sqrt(service->m_nMarkedSinceInMarkingState))); |
| 638 | nextMarkTime += markingInterval; |
| 639 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
| 640 | lastMarkTime = time::steady_clock::now(); |
| 641 | BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime); |
| 642 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 4); |
| 643 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 4); |
| 644 | |
| 645 | // no more congestion |
| 646 | transport->setSendQueueLength(30000); |
| 647 | face->sendInterest(*interest); |
| 648 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 8); |
| 649 | lp::Packet pkt8; |
| 650 | BOOST_REQUIRE_NO_THROW(pkt8.wireDecode(transport->sentPackets.back().packet)); |
| 651 | BOOST_CHECK_EQUAL(pkt8.count<lp::CongestionMarkField>(), 0); |
| 652 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max()); |
| 653 | BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime); |
| 654 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 655 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 4); |
| 656 | |
| 657 | this->advanceClocks(time::milliseconds(50)); |
| 658 | |
| 659 | // send queue congested again, but can't mark packet because within one full interval of last mark |
| 660 | transport->setSendQueueLength(50000); |
| 661 | face->sendInterest(*interest); |
| 662 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 9); |
| 663 | lp::Packet pkt9; |
| 664 | BOOST_REQUIRE_NO_THROW(pkt9.wireDecode(transport->sentPackets.back().packet)); |
| 665 | BOOST_CHECK_EQUAL(pkt9.count<lp::CongestionMarkField>(), 0); |
| 666 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max()); |
| 667 | BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime); |
| 668 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 669 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 4); |
| 670 | |
| 671 | // advance clock past full 100ms interval since last mark |
| 672 | this->advanceClocks(time::milliseconds(51)); |
| 673 | |
| 674 | transport->setSendQueueLength(40000); |
| 675 | face->sendInterest(*interest); |
| 676 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 10); |
| 677 | lp::Packet pkt10; |
| 678 | BOOST_REQUIRE_NO_THROW(pkt10.wireDecode(transport->sentPackets.back().packet)); |
| 679 | BOOST_REQUIRE_EQUAL(pkt10.count<lp::CongestionMarkField>(), 1); |
| 680 | BOOST_CHECK_EQUAL(pkt10.get<lp::CongestionMarkField>(), 1); |
| 681 | nextMarkTime = time::steady_clock::now() + time::milliseconds(100); |
| 682 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
| 683 | lastMarkTime = time::steady_clock::now(); |
| 684 | BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime); |
| 685 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1); |
| 686 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 5); |
| 687 | |
| 688 | // advance clock partway through 100ms marking interval |
| 689 | this->advanceClocks(time::milliseconds(50)); |
| 690 | |
| 691 | // not marked since within 100ms window before can mark again |
| 692 | transport->setSendQueueLength(50000); |
| 693 | face->sendInterest(*interest); |
| 694 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 11); |
| 695 | lp::Packet pkt11; |
| 696 | BOOST_REQUIRE_NO_THROW(pkt11.wireDecode(transport->sentPackets.back().packet)); |
| 697 | BOOST_CHECK_EQUAL(pkt11.count<lp::CongestionMarkField>(), 0); |
| 698 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
| 699 | BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime); |
| 700 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1); |
| 701 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 5); |
| 702 | |
| 703 | // advance clocks past m_nextMarkTime |
| 704 | this->advanceClocks(time::milliseconds(51)); |
| 705 | |
| 706 | // markable packet, queue length still above threshold |
| 707 | transport->setSendQueueLength(33000); |
| 708 | face->sendInterest(*interest); |
| 709 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 12); |
| 710 | lp::Packet pkt12; |
| 711 | BOOST_REQUIRE_NO_THROW(pkt12.wireDecode(transport->sentPackets.back().packet)); |
| 712 | BOOST_REQUIRE_EQUAL(pkt12.count<lp::CongestionMarkField>(), 1); |
| 713 | BOOST_CHECK_EQUAL(pkt12.get<lp::CongestionMarkField>(), 1); |
| 714 | markingInterval = time::nanoseconds( |
| 715 | static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() / |
| 716 | std::sqrt(service->m_nMarkedSinceInMarkingState))); |
| 717 | nextMarkTime += markingInterval; |
| 718 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
| 719 | lastMarkTime = time::steady_clock::now(); |
| 720 | BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime); |
| 721 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 2); |
| 722 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 6); |
| 723 | |
| 724 | // no more congestion |
| 725 | transport->setSendQueueLength(10000); |
| 726 | face->sendInterest(*interest); |
| 727 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 13); |
| 728 | lp::Packet pkt13; |
| 729 | BOOST_REQUIRE_NO_THROW(pkt13.wireDecode(transport->sentPackets.back().packet)); |
| 730 | BOOST_CHECK_EQUAL(pkt13.count<lp::CongestionMarkField>(), 0); |
| 731 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max()); |
| 732 | BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime); |
| 733 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 734 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 6); |
| 735 | |
| 736 | // advance clocks past one full interval since last mark |
| 737 | this->advanceClocks(time::milliseconds(101)); |
| 738 | |
| 739 | // start congestion again |
| 740 | transport->setSendQueueLength(50000); |
| 741 | face->sendInterest(*interest); |
| 742 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 14); |
| 743 | lp::Packet pkt14; |
| 744 | BOOST_REQUIRE_NO_THROW(pkt14.wireDecode(transport->sentPackets.back().packet)); |
| 745 | BOOST_REQUIRE_EQUAL(pkt14.count<lp::CongestionMarkField>(), 1); |
| 746 | BOOST_CHECK_EQUAL(pkt14.get<lp::CongestionMarkField>(), 1); |
| 747 | nextMarkTime = time::steady_clock::now() + time::milliseconds(100); |
| 748 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
| 749 | lastMarkTime = time::steady_clock::now(); |
| 750 | BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime); |
| 751 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1); |
| 752 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 7); |
| 753 | |
| 754 | // no more congestion, cancel marking interval |
| 755 | transport->setSendQueueLength(5000); |
| 756 | face->sendInterest(*interest); |
| 757 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 15); |
| 758 | lp::Packet pkt15; |
| 759 | BOOST_REQUIRE_NO_THROW(pkt15.wireDecode(transport->sentPackets.back().packet)); |
| 760 | BOOST_CHECK_EQUAL(pkt15.count<lp::CongestionMarkField>(), 0); |
| 761 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max()); |
| 762 | BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime); |
| 763 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 764 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 7); |
| 765 | } |
| 766 | |
| 767 | BOOST_AUTO_TEST_CASE(DefaultThreshold) |
| 768 | { |
| 769 | GenericLinkService::Options options; |
| 770 | options.allowCongestionMarking = true; |
| 771 | options.baseCongestionMarkingInterval = time::milliseconds(100); |
| 772 | initialize(options, MTU_UNLIMITED, QUEUE_UNSUPPORTED); |
| 773 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max()); |
| 774 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 775 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0); |
| 776 | |
| 777 | shared_ptr<Interest> interest = makeInterest("/12345678"); |
| 778 | |
| 779 | // congestion threshold will be 65536 bytes, since the transport reports that it cannot measure |
| 780 | // the queue capacity |
| 781 | |
| 782 | // no congestion |
| 783 | transport->setSendQueueLength(0); |
| 784 | face->sendInterest(*interest); |
| 785 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
| 786 | lp::Packet pkt1; |
| 787 | BOOST_REQUIRE_NO_THROW(pkt1.wireDecode(transport->sentPackets.back().packet)); |
| 788 | BOOST_CHECK_EQUAL(pkt1.count<lp::CongestionMarkField>(), 0); |
| 789 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max()); |
| 790 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 791 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0); |
| 792 | |
| 793 | // no congestion |
| 794 | transport->setSendQueueLength(65536); |
| 795 | face->sendInterest(*interest); |
| 796 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 2); |
| 797 | lp::Packet pkt2; |
| 798 | BOOST_REQUIRE_NO_THROW(pkt2.wireDecode(transport->sentPackets.back().packet)); |
| 799 | BOOST_CHECK_EQUAL(pkt2.count<lp::CongestionMarkField>(), 0); |
| 800 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max()); |
| 801 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 802 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0); |
| 803 | |
| 804 | // first congested (and marked) packet |
| 805 | transport->setSendQueueLength(65537); |
| 806 | face->sendInterest(*interest); |
| 807 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 3); |
| 808 | lp::Packet pkt3; |
| 809 | BOOST_REQUIRE_NO_THROW(pkt3.wireDecode(transport->sentPackets.back().packet)); |
| 810 | BOOST_REQUIRE_EQUAL(pkt3.count<lp::CongestionMarkField>(), 1); |
| 811 | BOOST_CHECK_EQUAL(pkt3.get<lp::CongestionMarkField>(), 1); |
| 812 | time::steady_clock::TimePoint nextMarkTime = time::steady_clock::now() + time::milliseconds(100); |
| 813 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
| 814 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1); |
| 815 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 1); |
| 816 | } |
| 817 | |
| 818 | BOOST_AUTO_TEST_SUITE_END() // CongestionMark |
| 819 | |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 820 | BOOST_AUTO_TEST_SUITE(LpFields) |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 821 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 822 | BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceId) |
| 823 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 824 | // Initialize with Options that enables local fields |
| 825 | GenericLinkService::Options options; |
| 826 | options.allowLocalFields = true; |
| 827 | initialize(options); |
| 828 | |
| 829 | shared_ptr<Interest> interest = makeInterest("/12345678"); |
| 830 | lp::Packet packet(interest->wireEncode()); |
| 831 | packet.set<lp::NextHopFaceIdField>(1000); |
| 832 | |
| 833 | transport->receivePacket(packet.wireEncode()); |
| 834 | |
| 835 | BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 836 | shared_ptr<lp::NextHopFaceIdTag> tag = receivedInterests.back().getTag<lp::NextHopFaceIdTag>(); |
| 837 | BOOST_REQUIRE(tag != nullptr); |
| 838 | BOOST_CHECK_EQUAL(*tag, 1000); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 839 | } |
| 840 | |
| 841 | BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDisabled) |
| 842 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 843 | // Initialize with Options that disables local fields |
| 844 | GenericLinkService::Options options; |
| 845 | options.allowLocalFields = false; |
| 846 | initialize(options); |
| 847 | |
| 848 | shared_ptr<Interest> interest = makeInterest("/12345678"); |
| 849 | lp::Packet packet(interest->wireEncode()); |
| 850 | packet.set<lp::NextHopFaceIdField>(1000); |
| 851 | |
| 852 | transport->receivePacket(packet.wireEncode()); |
| 853 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 854 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 855 | BOOST_CHECK(receivedInterests.empty()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDropData) |
| 859 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 860 | // Initialize with Options that enables local fields |
| 861 | GenericLinkService::Options options; |
| 862 | options.allowLocalFields = true; |
| 863 | initialize(options); |
| 864 | |
| 865 | shared_ptr<Data> data = makeData("/12345678"); |
| 866 | lp::Packet packet(data->wireEncode()); |
| 867 | packet.set<lp::NextHopFaceIdField>(1000); |
| 868 | |
| 869 | transport->receivePacket(packet.wireEncode()); |
| 870 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 871 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 872 | BOOST_CHECK(receivedData.empty()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDropNack) |
| 876 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 877 | // Initialize with Options that enables local fields |
| 878 | GenericLinkService::Options options; |
| 879 | options.allowLocalFields = true; |
| 880 | initialize(options); |
| 881 | |
| 882 | lp::Nack nack = makeNack("/localhost/test", 123, lp::NackReason::NO_ROUTE); |
| 883 | lp::Packet packet; |
| 884 | packet.set<lp::FragmentField>(std::make_pair( |
| 885 | nack.getInterest().wireEncode().begin(), nack.getInterest().wireEncode().end())); |
| 886 | packet.set<lp::NackField>(nack.getHeader()); |
| 887 | packet.set<lp::NextHopFaceIdField>(1000); |
| 888 | |
| 889 | transport->receivePacket(packet.wireEncode()); |
| 890 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 891 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 892 | BOOST_CHECK(receivedNacks.empty()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 893 | } |
| 894 | |
Junxiao Shi | 6eb0271 | 2017-05-27 22:48:02 +0000 | [diff] [blame] | 895 | BOOST_AUTO_TEST_CASE(ReceiveCachePolicy) |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 896 | { |
Junxiao Shi | 6eb0271 | 2017-05-27 22:48:02 +0000 | [diff] [blame] | 897 | // Initialize with Options that disables local fields |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 898 | GenericLinkService::Options options; |
Junxiao Shi | 6eb0271 | 2017-05-27 22:48:02 +0000 | [diff] [blame] | 899 | options.allowLocalFields = false; |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 900 | initialize(options); |
Junxiao Shi | 6eb0271 | 2017-05-27 22:48:02 +0000 | [diff] [blame] | 901 | // CachePolicy is unprivileged and does not require allowLocalFields option. |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 902 | |
| 903 | shared_ptr<Data> data = makeData("/12345678"); |
| 904 | lp::Packet packet(data->wireEncode()); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 905 | packet.set<lp::CachePolicyField>(lp::CachePolicy().setPolicy(lp::CachePolicyType::NO_CACHE)); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 906 | |
| 907 | transport->receivePacket(packet.wireEncode()); |
| 908 | |
| 909 | BOOST_REQUIRE_EQUAL(receivedData.size(), 1); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 910 | shared_ptr<lp::CachePolicyTag> tag = receivedData.back().getTag<lp::CachePolicyTag>(); |
| 911 | BOOST_REQUIRE(tag != nullptr); |
| 912 | BOOST_CHECK_EQUAL(tag->get().getPolicy(), lp::CachePolicyType::NO_CACHE); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 913 | } |
| 914 | |
Junxiao Shi | 6eb0271 | 2017-05-27 22:48:02 +0000 | [diff] [blame] | 915 | BOOST_AUTO_TEST_CASE(ReceiveCachePolicyDropInterest) |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 916 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 917 | // Initialize with Options that enables local fields |
| 918 | GenericLinkService::Options options; |
| 919 | options.allowLocalFields = true; |
| 920 | initialize(options); |
| 921 | |
| 922 | shared_ptr<Interest> interest = makeInterest("/12345678"); |
| 923 | lp::Packet packet(interest->wireEncode()); |
| 924 | lp::CachePolicy policy; |
| 925 | policy.setPolicy(lp::CachePolicyType::NO_CACHE); |
| 926 | packet.set<lp::CachePolicyField>(policy); |
| 927 | |
| 928 | transport->receivePacket(packet.wireEncode()); |
| 929 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 930 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 931 | BOOST_CHECK(receivedInterests.empty()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 932 | } |
| 933 | |
Junxiao Shi | 6eb0271 | 2017-05-27 22:48:02 +0000 | [diff] [blame] | 934 | BOOST_AUTO_TEST_CASE(ReceiveCachePolicyDropNack) |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 935 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 936 | // Initialize with Options that enables local fields |
| 937 | GenericLinkService::Options options; |
| 938 | options.allowLocalFields = true; |
| 939 | initialize(options); |
| 940 | |
| 941 | lp::Nack nack = makeNack("/localhost/test", 123, lp::NackReason::NO_ROUTE); |
| 942 | lp::Packet packet(nack.getInterest().wireEncode()); |
| 943 | packet.set<lp::NackField>(nack.getHeader()); |
| 944 | lp::CachePolicy policy; |
| 945 | policy.setPolicy(lp::CachePolicyType::NO_CACHE); |
| 946 | packet.set<lp::CachePolicyField>(policy); |
| 947 | |
| 948 | transport->receivePacket(packet.wireEncode()); |
| 949 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 950 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 951 | BOOST_CHECK(receivedNacks.empty()); |
| 952 | } |
| 953 | |
| 954 | BOOST_AUTO_TEST_CASE(SendIncomingFaceId) |
| 955 | { |
| 956 | // Initialize with Options that enables local fields |
| 957 | GenericLinkService::Options options; |
| 958 | options.allowLocalFields = true; |
| 959 | initialize(options); |
| 960 | |
| 961 | shared_ptr<Interest> interest = makeInterest("/12345678"); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 962 | interest->setTag(make_shared<lp::IncomingFaceIdTag>(1000)); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 963 | |
| 964 | face->sendInterest(*interest); |
| 965 | |
| 966 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
| 967 | lp::Packet sent(transport->sentPackets.back().packet); |
| 968 | BOOST_REQUIRE(sent.has<lp::IncomingFaceIdField>()); |
| 969 | BOOST_CHECK_EQUAL(sent.get<lp::IncomingFaceIdField>(), 1000); |
| 970 | } |
| 971 | |
| 972 | BOOST_AUTO_TEST_CASE(SendIncomingFaceIdDisabled) |
| 973 | { |
| 974 | // Initialize with Options that disables local fields |
| 975 | GenericLinkService::Options options; |
| 976 | options.allowLocalFields = false; |
| 977 | initialize(options); |
| 978 | |
| 979 | shared_ptr<Interest> interest = makeInterest("/12345678"); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 980 | interest->setTag(make_shared<lp::IncomingFaceIdTag>(1000)); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 981 | |
| 982 | face->sendInterest(*interest); |
| 983 | |
| 984 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
| 985 | lp::Packet sent(transport->sentPackets.back().packet); |
| 986 | BOOST_CHECK(!sent.has<lp::IncomingFaceIdField>()); |
| 987 | } |
| 988 | |
| 989 | BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreInterest) |
| 990 | { |
| 991 | // Initialize with Options that enables local fields |
| 992 | GenericLinkService::Options options; |
| 993 | options.allowLocalFields = true; |
| 994 | initialize(options); |
| 995 | |
| 996 | shared_ptr<Interest> interest = makeInterest("/12345678"); |
| 997 | lp::Packet packet(interest->wireEncode()); |
| 998 | packet.set<lp::IncomingFaceIdField>(1000); |
| 999 | |
| 1000 | transport->receivePacket(packet.wireEncode()); |
| 1001 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 1002 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1003 | BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 1004 | BOOST_CHECK(receivedInterests.back().getTag<lp::IncomingFaceIdTag>() == nullptr); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreData) |
| 1008 | { |
| 1009 | // Initialize with Options that enables local fields |
| 1010 | GenericLinkService::Options options; |
| 1011 | options.allowLocalFields = true; |
| 1012 | initialize(options); |
| 1013 | |
| 1014 | shared_ptr<Data> data = makeData("/z1megUh9Bj"); |
| 1015 | lp::Packet packet(data->wireEncode()); |
| 1016 | packet.set<lp::IncomingFaceIdField>(1000); |
| 1017 | |
| 1018 | transport->receivePacket(packet.wireEncode()); |
| 1019 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 1020 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1021 | BOOST_REQUIRE_EQUAL(receivedData.size(), 1); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 1022 | BOOST_CHECK(receivedData.back().getTag<lp::IncomingFaceIdTag>() == nullptr); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1023 | } |
| 1024 | |
| 1025 | BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreNack) |
| 1026 | { |
| 1027 | // Initialize with Options that enables local fields |
| 1028 | GenericLinkService::Options options; |
| 1029 | options.allowLocalFields = true; |
| 1030 | initialize(options); |
| 1031 | |
| 1032 | lp::Nack nack = makeNack("/TPAhdiHz", 278, lp::NackReason::CONGESTION); |
| 1033 | lp::Packet packet(nack.getInterest().wireEncode()); |
| 1034 | packet.set<lp::NackField>(nack.getHeader()); |
| 1035 | packet.set<lp::IncomingFaceIdField>(1000); |
| 1036 | |
| 1037 | transport->receivePacket(packet.wireEncode()); |
| 1038 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 1039 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1040 | BOOST_REQUIRE_EQUAL(receivedNacks.size(), 1); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 1041 | BOOST_CHECK(receivedNacks.back().getTag<lp::IncomingFaceIdTag>() == nullptr); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 1042 | } |
| 1043 | |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1044 | BOOST_AUTO_TEST_CASE(SendCongestionMarkInterest) |
| 1045 | { |
| 1046 | shared_ptr<Interest> interest = makeInterest("/12345678"); |
| 1047 | interest->setTag(make_shared<lp::CongestionMarkTag>(1)); |
| 1048 | |
| 1049 | face->sendInterest(*interest); |
| 1050 | |
| 1051 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
| 1052 | lp::Packet sent(transport->sentPackets.back().packet); |
| 1053 | BOOST_REQUIRE(sent.has<lp::CongestionMarkField>()); |
| 1054 | BOOST_CHECK_EQUAL(sent.get<lp::CongestionMarkField>(), 1); |
| 1055 | } |
| 1056 | |
| 1057 | BOOST_AUTO_TEST_CASE(SendCongestionMarkData) |
| 1058 | { |
| 1059 | shared_ptr<Data> data = makeData("/12345678"); |
| 1060 | data->setTag(make_shared<lp::CongestionMarkTag>(0)); |
| 1061 | |
| 1062 | face->sendData(*data); |
| 1063 | |
| 1064 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
| 1065 | lp::Packet sent(transport->sentPackets.back().packet); |
| 1066 | BOOST_REQUIRE(sent.has<lp::CongestionMarkField>()); |
| 1067 | BOOST_CHECK_EQUAL(sent.get<lp::CongestionMarkField>(), 0); |
| 1068 | } |
| 1069 | |
| 1070 | BOOST_AUTO_TEST_CASE(SendCongestionMarkNack) |
| 1071 | { |
| 1072 | lp::Nack nack = makeNack("/localhost/test", 123, lp::NackReason::NO_ROUTE); |
| 1073 | nack.setTag(make_shared<lp::CongestionMarkTag>(std::numeric_limits<uint64_t>::max())); |
| 1074 | |
| 1075 | face->sendNack(nack); |
| 1076 | |
| 1077 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
| 1078 | lp::Packet sent(transport->sentPackets.back().packet); |
| 1079 | BOOST_REQUIRE(sent.has<lp::CongestionMarkField>()); |
| 1080 | BOOST_CHECK_EQUAL(sent.get<lp::CongestionMarkField>(), std::numeric_limits<uint64_t>::max()); |
| 1081 | } |
| 1082 | |
| 1083 | BOOST_AUTO_TEST_CASE(ReceiveCongestionMarkInterest) |
| 1084 | { |
| 1085 | shared_ptr<Interest> interest = makeInterest("/12345678"); |
| 1086 | lp::Packet packet(interest->wireEncode()); |
| 1087 | packet.set<lp::CongestionMarkField>(1); |
| 1088 | |
| 1089 | transport->receivePacket(packet.wireEncode()); |
| 1090 | |
| 1091 | BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1); |
| 1092 | shared_ptr<lp::CongestionMarkTag> tag = receivedInterests.back().getTag<lp::CongestionMarkTag>(); |
| 1093 | BOOST_REQUIRE(tag != nullptr); |
| 1094 | BOOST_CHECK_EQUAL(*tag, 1); |
| 1095 | } |
| 1096 | |
| 1097 | BOOST_AUTO_TEST_CASE(ReceiveCongestionMarkData) |
| 1098 | { |
| 1099 | shared_ptr<Data> data = makeData("/12345678"); |
| 1100 | lp::Packet packet(data->wireEncode()); |
| 1101 | packet.set<lp::CongestionMarkField>(1); |
| 1102 | |
| 1103 | transport->receivePacket(packet.wireEncode()); |
| 1104 | |
| 1105 | BOOST_REQUIRE_EQUAL(receivedData.size(), 1); |
| 1106 | shared_ptr<lp::CongestionMarkTag> tag = receivedData.back().getTag<lp::CongestionMarkTag>(); |
| 1107 | BOOST_REQUIRE(tag != nullptr); |
| 1108 | BOOST_CHECK_EQUAL(*tag, 1); |
| 1109 | } |
| 1110 | |
| 1111 | BOOST_AUTO_TEST_CASE(ReceiveCongestionMarkNack) |
| 1112 | { |
| 1113 | lp::Nack nack = makeNack("/localhost/test", 123, lp::NackReason::NO_ROUTE); |
| 1114 | lp::Packet packet; |
| 1115 | packet.set<lp::FragmentField>(std::make_pair( |
| 1116 | nack.getInterest().wireEncode().begin(), nack.getInterest().wireEncode().end())); |
| 1117 | packet.set<lp::NackField>(nack.getHeader()); |
| 1118 | packet.set<lp::CongestionMarkField>(1); |
| 1119 | |
| 1120 | transport->receivePacket(packet.wireEncode()); |
| 1121 | |
| 1122 | BOOST_REQUIRE_EQUAL(receivedNacks.size(), 1); |
| 1123 | shared_ptr<lp::CongestionMarkTag> tag = receivedNacks.back().getTag<lp::CongestionMarkTag>(); |
| 1124 | BOOST_REQUIRE(tag != nullptr); |
| 1125 | BOOST_CHECK_EQUAL(*tag, 1); |
| 1126 | } |
| 1127 | |
| 1128 | BOOST_AUTO_TEST_SUITE_END() // LpFields |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 1129 | |
Eric Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 1130 | BOOST_AUTO_TEST_SUITE(Malformed) // receive malformed packets |
| 1131 | |
| 1132 | BOOST_AUTO_TEST_CASE(WrongTlvType) |
| 1133 | { |
| 1134 | // Initialize with Options that disables all services |
| 1135 | GenericLinkService::Options options; |
| 1136 | options.allowLocalFields = false; |
| 1137 | initialize(options); |
| 1138 | |
| 1139 | Block packet = ndn::encoding::makeEmptyBlock(tlv::Name); |
| 1140 | |
| 1141 | BOOST_CHECK_NO_THROW(transport->receivePacket(packet)); |
| 1142 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 1143 | BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 1); |
Eric Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 1144 | BOOST_CHECK_EQUAL(receivedInterests.size(), 0); |
| 1145 | BOOST_CHECK_EQUAL(receivedData.size(), 0); |
| 1146 | BOOST_CHECK_EQUAL(receivedNacks.size(), 0); |
| 1147 | } |
| 1148 | |
| 1149 | BOOST_AUTO_TEST_CASE(Unparsable) |
| 1150 | { |
| 1151 | // Initialize with Options that disables all services |
| 1152 | GenericLinkService::Options options; |
| 1153 | options.allowLocalFields = false; |
| 1154 | initialize(options); |
| 1155 | |
| 1156 | Block packet = ndn::encoding::makeStringBlock(lp::tlv::LpPacket, "x"); |
| 1157 | BOOST_CHECK_THROW(packet.parse(), tlv::Error); |
| 1158 | |
| 1159 | BOOST_CHECK_NO_THROW(transport->receivePacket(packet)); |
| 1160 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 1161 | BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 1); |
Eric Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 1162 | BOOST_CHECK_EQUAL(receivedInterests.size(), 0); |
| 1163 | BOOST_CHECK_EQUAL(receivedData.size(), 0); |
| 1164 | BOOST_CHECK_EQUAL(receivedNacks.size(), 0); |
| 1165 | } |
| 1166 | |
| 1167 | BOOST_AUTO_TEST_SUITE_END() // Malformed |
| 1168 | |
| 1169 | |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1170 | BOOST_AUTO_TEST_SUITE_END() // TestGenericLinkService |
| 1171 | BOOST_AUTO_TEST_SUITE_END() // Face |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 1172 | |
| 1173 | } // namespace tests |
| 1174 | } // namespace face |
| 1175 | } // namespace nfd |