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