Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014-2015, Regents of the University of California, |
| 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" |
| 27 | #include "face/lp-face.hpp" |
| 28 | #include "dummy-transport.hpp" |
| 29 | |
| 30 | #include "tests/test-common.hpp" |
| 31 | |
| 32 | namespace nfd { |
| 33 | namespace face { |
| 34 | namespace tests { |
| 35 | |
| 36 | using namespace nfd::tests; |
| 37 | |
| 38 | BOOST_AUTO_TEST_SUITE(Face) |
| 39 | |
| 40 | class GenericLinkServiceFixture : public BaseFixture |
| 41 | { |
| 42 | protected: |
| 43 | GenericLinkServiceFixture() |
| 44 | : service(nullptr) |
| 45 | , transport(nullptr) |
| 46 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 47 | this->initialize(GenericLinkService::Options()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 48 | // By default, GenericLinkService is created with default options. |
| 49 | // Test cases may invoke .initialize with alternate options. |
| 50 | } |
| 51 | |
| 52 | void |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 53 | initialize(const GenericLinkService::Options& options) |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 54 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 55 | face.reset(new LpFace(make_unique<GenericLinkService>(options), |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 56 | make_unique<DummyTransport>())); |
| 57 | service = static_cast<GenericLinkService*>(face->getLinkService()); |
| 58 | transport = static_cast<DummyTransport*>(face->getTransport()); |
| 59 | |
| 60 | face->afterReceiveInterest.connect( |
| 61 | [this] (const Interest& interest) { receivedInterests.push_back(interest); }); |
| 62 | face->afterReceiveData.connect( |
| 63 | [this] (const Data& data) { receivedData.push_back(data); }); |
| 64 | face->afterReceiveNack.connect( |
| 65 | [this] (const lp::Nack& nack) { receivedNacks.push_back(nack); }); |
| 66 | } |
| 67 | |
| 68 | protected: |
| 69 | unique_ptr<LpFace> face; |
| 70 | GenericLinkService* service; |
| 71 | DummyTransport* transport; |
| 72 | std::vector<Interest> receivedInterests; |
| 73 | std::vector<Data> receivedData; |
| 74 | std::vector<lp::Nack> receivedNacks; |
| 75 | }; |
| 76 | |
| 77 | BOOST_FIXTURE_TEST_SUITE(TestGenericLinkService, GenericLinkServiceFixture) |
| 78 | |
| 79 | |
| 80 | BOOST_AUTO_TEST_SUITE(SimpleSendReceive) // send and receive without other fields |
| 81 | |
| 82 | BOOST_AUTO_TEST_CASE(SendInterest) |
| 83 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 84 | // Initialize with Options that disables all services |
| 85 | GenericLinkService::Options options; |
| 86 | options.allowLocalFields = false; |
| 87 | initialize(options); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 88 | |
| 89 | shared_ptr<Interest> interest1 = makeInterest("/localhost/test"); |
| 90 | |
| 91 | face->sendInterest(*interest1); |
| 92 | |
| 93 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
| 94 | BOOST_CHECK(transport->sentPackets.back().packet == interest1->wireEncode()); |
| 95 | } |
| 96 | |
| 97 | BOOST_AUTO_TEST_CASE(SendData) |
| 98 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 99 | // Initialize with Options that disables all services |
| 100 | GenericLinkService::Options options; |
| 101 | options.allowLocalFields = false; |
| 102 | initialize(options); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 103 | |
| 104 | shared_ptr<Data> data1 = makeData("/localhost/test"); |
| 105 | |
| 106 | face->sendData(*data1); |
| 107 | |
| 108 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
| 109 | BOOST_CHECK(transport->sentPackets.back().packet == data1->wireEncode()); |
| 110 | } |
| 111 | |
| 112 | BOOST_AUTO_TEST_CASE(SendNack) |
| 113 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 114 | // Initialize with Options that disables all services |
| 115 | GenericLinkService::Options options; |
| 116 | options.allowLocalFields = false; |
| 117 | initialize(options); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 118 | |
| 119 | lp::Nack nack1 = makeNack("/localhost/test", 323, lp::NackReason::NO_ROUTE); |
| 120 | |
| 121 | face->sendNack(nack1); |
| 122 | |
| 123 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
| 124 | lp::Packet nack1pkt; |
| 125 | BOOST_REQUIRE_NO_THROW(nack1pkt.wireDecode(transport->sentPackets.back().packet)); |
| 126 | BOOST_CHECK_EQUAL(nack1pkt.has<lp::NackField>(), true); |
| 127 | BOOST_CHECK_EQUAL(nack1pkt.has<lp::FragmentField>(), true); |
| 128 | } |
| 129 | |
| 130 | BOOST_AUTO_TEST_CASE(ReceiveBareInterest) |
| 131 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 132 | // Initialize with Options that disables all services |
| 133 | GenericLinkService::Options options; |
| 134 | options.allowLocalFields = false; |
| 135 | initialize(options); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 136 | |
| 137 | shared_ptr<Interest> interest1 = makeInterest("/23Rd9hEiR"); |
| 138 | |
| 139 | transport->receivePacket(interest1->wireEncode()); |
| 140 | |
| 141 | BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1); |
| 142 | BOOST_CHECK_EQUAL(receivedInterests.back(), *interest1); |
| 143 | } |
| 144 | |
| 145 | BOOST_AUTO_TEST_CASE(ReceiveInterest) |
| 146 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 147 | // Initialize with Options that disables all services |
| 148 | GenericLinkService::Options options; |
| 149 | options.allowLocalFields = false; |
| 150 | initialize(options); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 151 | |
| 152 | shared_ptr<Interest> interest1 = makeInterest("/23Rd9hEiR"); |
| 153 | lp::Packet lpPacket; |
| 154 | lpPacket.set<lp::FragmentField>(std::make_pair( |
| 155 | interest1->wireEncode().begin(), interest1->wireEncode().end())); |
| 156 | lpPacket.set<lp::SequenceField>(0); // force LpPacket encoding |
| 157 | |
| 158 | transport->receivePacket(lpPacket.wireEncode()); |
| 159 | |
| 160 | BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1); |
| 161 | BOOST_CHECK_EQUAL(receivedInterests.back(), *interest1); |
| 162 | } |
| 163 | |
| 164 | BOOST_AUTO_TEST_CASE(ReceiveBareData) |
| 165 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 166 | // Initialize with Options that disables all services |
| 167 | GenericLinkService::Options options; |
| 168 | options.allowLocalFields = false; |
| 169 | initialize(options); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 170 | |
| 171 | shared_ptr<Data> data1 = makeData("/12345678"); |
| 172 | |
| 173 | transport->receivePacket(data1->wireEncode()); |
| 174 | |
| 175 | BOOST_REQUIRE_EQUAL(receivedData.size(), 1); |
| 176 | BOOST_CHECK_EQUAL(receivedData.back(), *data1); |
| 177 | } |
| 178 | |
| 179 | BOOST_AUTO_TEST_CASE(ReceiveData) |
| 180 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 181 | // Initialize with Options that disables all services |
| 182 | GenericLinkService::Options options; |
| 183 | options.allowLocalFields = false; |
| 184 | initialize(options); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 185 | |
| 186 | shared_ptr<Data> data1 = makeData("/12345689"); |
| 187 | lp::Packet lpPacket; |
| 188 | lpPacket.set<lp::FragmentField>(std::make_pair( |
| 189 | data1->wireEncode().begin(), data1->wireEncode().end())); |
| 190 | lpPacket.set<lp::SequenceField>(0); // force LpPacket encoding |
| 191 | |
| 192 | transport->receivePacket(lpPacket.wireEncode()); |
| 193 | |
| 194 | BOOST_REQUIRE_EQUAL(receivedData.size(), 1); |
| 195 | BOOST_CHECK_EQUAL(receivedData.back(), *data1); |
| 196 | } |
| 197 | |
| 198 | BOOST_AUTO_TEST_CASE(ReceiveNack) |
| 199 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 200 | // Initialize with Options that disables all services |
| 201 | GenericLinkService::Options options; |
| 202 | options.allowLocalFields = false; |
| 203 | initialize(options); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 204 | |
| 205 | lp::Nack nack1 = makeNack("/localhost/test", 323, lp::NackReason::NO_ROUTE); |
| 206 | lp::Packet lpPacket; |
| 207 | lpPacket.set<lp::FragmentField>(std::make_pair( |
| 208 | nack1.getInterest().wireEncode().begin(), nack1.getInterest().wireEncode().end())); |
| 209 | lpPacket.set<lp::NackField>(nack1.getHeader()); |
| 210 | |
| 211 | transport->receivePacket(lpPacket.wireEncode()); |
| 212 | |
| 213 | BOOST_REQUIRE_EQUAL(receivedNacks.size(), 1); |
| 214 | } |
| 215 | |
Eric Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 216 | BOOST_AUTO_TEST_CASE(ReceiveIdlePacket) |
| 217 | { |
| 218 | // Initialize with Options that disables all services |
| 219 | GenericLinkService::Options options; |
| 220 | options.allowLocalFields = false; |
| 221 | initialize(options); |
| 222 | |
| 223 | lp::Packet lpPacket; |
| 224 | lpPacket.set<lp::SequenceField>(0); |
| 225 | |
| 226 | BOOST_CHECK_NO_THROW(transport->receivePacket(lpPacket.wireEncode())); |
| 227 | |
| 228 | // IDLE packet should be ignored |
| 229 | BOOST_CHECK_EQUAL(receivedInterests.size(), 0); |
| 230 | BOOST_CHECK_EQUAL(receivedData.size(), 0); |
| 231 | BOOST_CHECK_EQUAL(receivedNacks.size(), 0); |
| 232 | } |
| 233 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 234 | BOOST_AUTO_TEST_SUITE_END() // SimpleSendReceive |
| 235 | |
| 236 | |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 237 | BOOST_AUTO_TEST_SUITE(Fragmentation) |
| 238 | |
| 239 | BOOST_AUTO_TEST_CASE(ReassemblyDisabledDropFragIndex) |
| 240 | { |
| 241 | // TODO#3171 Initialize with Options that disables reassembly |
| 242 | |
| 243 | shared_ptr<Interest> interest = makeInterest("/IgFe6NvH"); |
| 244 | lp::Packet packet(interest->wireEncode()); |
| 245 | packet.set<lp::FragIndexField>(140); |
| 246 | |
| 247 | transport->receivePacket(packet.wireEncode()); |
| 248 | |
| 249 | BOOST_CHECK(receivedInterests.empty()); |
| 250 | } |
| 251 | |
| 252 | BOOST_AUTO_TEST_CASE(ReassemblyDisabledDropFragCount) |
| 253 | { |
| 254 | // TODO#3171 Initialize with Options that disables reassembly |
| 255 | |
| 256 | shared_ptr<Interest> interest = makeInterest("/SeGmEjvIVX"); |
| 257 | lp::Packet packet(interest->wireEncode()); |
| 258 | packet.set<lp::FragCountField>(276); |
| 259 | |
| 260 | transport->receivePacket(packet.wireEncode()); |
| 261 | |
| 262 | BOOST_CHECK(receivedInterests.empty()); |
| 263 | } |
| 264 | |
| 265 | BOOST_AUTO_TEST_SUITE_END() // Fragmentation |
| 266 | |
| 267 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 268 | BOOST_AUTO_TEST_SUITE(LocalFields) |
| 269 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 270 | BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceId) |
| 271 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 272 | // Initialize with Options that enables local fields |
| 273 | GenericLinkService::Options options; |
| 274 | options.allowLocalFields = true; |
| 275 | initialize(options); |
| 276 | |
| 277 | shared_ptr<Interest> interest = makeInterest("/12345678"); |
| 278 | lp::Packet packet(interest->wireEncode()); |
| 279 | packet.set<lp::NextHopFaceIdField>(1000); |
| 280 | |
| 281 | transport->receivePacket(packet.wireEncode()); |
| 282 | |
| 283 | BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1); |
| 284 | BOOST_REQUIRE(receivedInterests.back().getLocalControlHeader().hasNextHopFaceId()); |
| 285 | BOOST_CHECK_EQUAL(receivedInterests.back().getNextHopFaceId(), 1000); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDisabled) |
| 289 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 290 | // Initialize with Options that disables local fields |
| 291 | GenericLinkService::Options options; |
| 292 | options.allowLocalFields = false; |
| 293 | initialize(options); |
| 294 | |
| 295 | shared_ptr<Interest> interest = makeInterest("/12345678"); |
| 296 | lp::Packet packet(interest->wireEncode()); |
| 297 | packet.set<lp::NextHopFaceIdField>(1000); |
| 298 | |
| 299 | transport->receivePacket(packet.wireEncode()); |
| 300 | |
| 301 | BOOST_CHECK(receivedInterests.empty()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDropData) |
| 305 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 306 | // Initialize with Options that enables local fields |
| 307 | GenericLinkService::Options options; |
| 308 | options.allowLocalFields = true; |
| 309 | initialize(options); |
| 310 | |
| 311 | shared_ptr<Data> data = makeData("/12345678"); |
| 312 | lp::Packet packet(data->wireEncode()); |
| 313 | packet.set<lp::NextHopFaceIdField>(1000); |
| 314 | |
| 315 | transport->receivePacket(packet.wireEncode()); |
| 316 | |
| 317 | BOOST_CHECK(receivedData.empty()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDropNack) |
| 321 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 322 | // Initialize with Options that enables local fields |
| 323 | GenericLinkService::Options options; |
| 324 | options.allowLocalFields = true; |
| 325 | initialize(options); |
| 326 | |
| 327 | lp::Nack nack = makeNack("/localhost/test", 123, lp::NackReason::NO_ROUTE); |
| 328 | lp::Packet packet; |
| 329 | packet.set<lp::FragmentField>(std::make_pair( |
| 330 | nack.getInterest().wireEncode().begin(), nack.getInterest().wireEncode().end())); |
| 331 | packet.set<lp::NackField>(nack.getHeader()); |
| 332 | packet.set<lp::NextHopFaceIdField>(1000); |
| 333 | |
| 334 | transport->receivePacket(packet.wireEncode()); |
| 335 | |
| 336 | BOOST_CHECK(receivedNacks.empty()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | BOOST_AUTO_TEST_CASE(ReceiveCacheControl) |
| 340 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 341 | // Initialize with Options that enables local fields |
| 342 | GenericLinkService::Options options; |
| 343 | options.allowLocalFields = true; |
| 344 | initialize(options); |
| 345 | |
| 346 | shared_ptr<Data> data = makeData("/12345678"); |
| 347 | lp::Packet packet(data->wireEncode()); |
| 348 | lp::CachePolicy policy; |
| 349 | policy.setPolicy(lp::CachePolicyType::NO_CACHE); |
| 350 | packet.set<lp::CachePolicyField>(policy); |
| 351 | |
| 352 | transport->receivePacket(packet.wireEncode()); |
| 353 | |
| 354 | BOOST_REQUIRE_EQUAL(receivedData.size(), 1); |
| 355 | BOOST_REQUIRE(receivedData.back().getLocalControlHeader().hasCachingPolicy()); |
| 356 | BOOST_CHECK_EQUAL(receivedData.back().getCachingPolicy(), |
| 357 | ndn::nfd::LocalControlHeader::CachingPolicy::NO_CACHE); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | BOOST_AUTO_TEST_CASE(ReceiveCacheControlDisabled) |
| 361 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 362 | // Initialize with Options that disables local fields |
| 363 | GenericLinkService::Options options; |
| 364 | options.allowLocalFields = false; |
| 365 | initialize(options); |
| 366 | |
| 367 | shared_ptr<Data> data = makeData("/12345678"); |
| 368 | lp::Packet packet(data->wireEncode()); |
| 369 | lp::CachePolicy policy; |
| 370 | policy.setPolicy(lp::CachePolicyType::NO_CACHE); |
| 371 | packet.set<lp::CachePolicyField>(policy); |
| 372 | |
| 373 | transport->receivePacket(packet.wireEncode()); |
| 374 | |
| 375 | BOOST_REQUIRE_EQUAL(receivedData.size(), 1); |
| 376 | BOOST_CHECK(!receivedData.back().getLocalControlHeader().hasCachingPolicy()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | BOOST_AUTO_TEST_CASE(ReceiveCacheControlDropInterest) |
| 380 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 381 | // Initialize with Options that enables local fields |
| 382 | GenericLinkService::Options options; |
| 383 | options.allowLocalFields = true; |
| 384 | initialize(options); |
| 385 | |
| 386 | shared_ptr<Interest> interest = makeInterest("/12345678"); |
| 387 | lp::Packet packet(interest->wireEncode()); |
| 388 | lp::CachePolicy policy; |
| 389 | policy.setPolicy(lp::CachePolicyType::NO_CACHE); |
| 390 | packet.set<lp::CachePolicyField>(policy); |
| 391 | |
| 392 | transport->receivePacket(packet.wireEncode()); |
| 393 | |
| 394 | BOOST_CHECK(receivedInterests.empty()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | BOOST_AUTO_TEST_CASE(ReceiveCacheControlDropNack) |
| 398 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 399 | // Initialize with Options that enables local fields |
| 400 | GenericLinkService::Options options; |
| 401 | options.allowLocalFields = true; |
| 402 | initialize(options); |
| 403 | |
| 404 | lp::Nack nack = makeNack("/localhost/test", 123, lp::NackReason::NO_ROUTE); |
| 405 | lp::Packet packet(nack.getInterest().wireEncode()); |
| 406 | packet.set<lp::NackField>(nack.getHeader()); |
| 407 | lp::CachePolicy policy; |
| 408 | policy.setPolicy(lp::CachePolicyType::NO_CACHE); |
| 409 | packet.set<lp::CachePolicyField>(policy); |
| 410 | |
| 411 | transport->receivePacket(packet.wireEncode()); |
| 412 | |
| 413 | BOOST_CHECK(receivedNacks.empty()); |
| 414 | } |
| 415 | |
| 416 | BOOST_AUTO_TEST_CASE(SendIncomingFaceId) |
| 417 | { |
| 418 | // Initialize with Options that enables local fields |
| 419 | GenericLinkService::Options options; |
| 420 | options.allowLocalFields = true; |
| 421 | initialize(options); |
| 422 | |
| 423 | shared_ptr<Interest> interest = makeInterest("/12345678"); |
| 424 | interest->setIncomingFaceId(1000); |
| 425 | |
| 426 | face->sendInterest(*interest); |
| 427 | |
| 428 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
| 429 | lp::Packet sent(transport->sentPackets.back().packet); |
| 430 | BOOST_REQUIRE(sent.has<lp::IncomingFaceIdField>()); |
| 431 | BOOST_CHECK_EQUAL(sent.get<lp::IncomingFaceIdField>(), 1000); |
| 432 | } |
| 433 | |
| 434 | BOOST_AUTO_TEST_CASE(SendIncomingFaceIdDisabled) |
| 435 | { |
| 436 | // Initialize with Options that disables local fields |
| 437 | GenericLinkService::Options options; |
| 438 | options.allowLocalFields = false; |
| 439 | initialize(options); |
| 440 | |
| 441 | shared_ptr<Interest> interest = makeInterest("/12345678"); |
| 442 | interest->setIncomingFaceId(1000); |
| 443 | |
| 444 | face->sendInterest(*interest); |
| 445 | |
| 446 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
| 447 | lp::Packet sent(transport->sentPackets.back().packet); |
| 448 | BOOST_CHECK(!sent.has<lp::IncomingFaceIdField>()); |
| 449 | } |
| 450 | |
| 451 | BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreInterest) |
| 452 | { |
| 453 | // Initialize with Options that enables local fields |
| 454 | GenericLinkService::Options options; |
| 455 | options.allowLocalFields = true; |
| 456 | initialize(options); |
| 457 | |
| 458 | shared_ptr<Interest> interest = makeInterest("/12345678"); |
| 459 | lp::Packet packet(interest->wireEncode()); |
| 460 | packet.set<lp::IncomingFaceIdField>(1000); |
| 461 | |
| 462 | transport->receivePacket(packet.wireEncode()); |
| 463 | |
| 464 | BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1); |
| 465 | BOOST_CHECK(!receivedInterests.back().getLocalControlHeader().hasIncomingFaceId()); |
| 466 | } |
| 467 | |
| 468 | BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreData) |
| 469 | { |
| 470 | // Initialize with Options that enables local fields |
| 471 | GenericLinkService::Options options; |
| 472 | options.allowLocalFields = true; |
| 473 | initialize(options); |
| 474 | |
| 475 | shared_ptr<Data> data = makeData("/z1megUh9Bj"); |
| 476 | lp::Packet packet(data->wireEncode()); |
| 477 | packet.set<lp::IncomingFaceIdField>(1000); |
| 478 | |
| 479 | transport->receivePacket(packet.wireEncode()); |
| 480 | |
| 481 | BOOST_REQUIRE_EQUAL(receivedData.size(), 1); |
| 482 | BOOST_CHECK(!receivedData.back().getLocalControlHeader().hasIncomingFaceId()); |
| 483 | } |
| 484 | |
| 485 | BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreNack) |
| 486 | { |
| 487 | // Initialize with Options that enables local fields |
| 488 | GenericLinkService::Options options; |
| 489 | options.allowLocalFields = true; |
| 490 | initialize(options); |
| 491 | |
| 492 | lp::Nack nack = makeNack("/TPAhdiHz", 278, lp::NackReason::CONGESTION); |
| 493 | lp::Packet packet(nack.getInterest().wireEncode()); |
| 494 | packet.set<lp::NackField>(nack.getHeader()); |
| 495 | packet.set<lp::IncomingFaceIdField>(1000); |
| 496 | |
| 497 | transport->receivePacket(packet.wireEncode()); |
| 498 | |
| 499 | BOOST_REQUIRE_EQUAL(receivedNacks.size(), 1); |
| 500 | BOOST_CHECK(!receivedNacks.back().getLocalControlHeader().hasIncomingFaceId()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | BOOST_AUTO_TEST_SUITE_END() // LocalFields |
| 504 | |
| 505 | |
Eric Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 506 | BOOST_AUTO_TEST_SUITE(Malformed) // receive malformed packets |
| 507 | |
| 508 | BOOST_AUTO_TEST_CASE(WrongTlvType) |
| 509 | { |
| 510 | // Initialize with Options that disables all services |
| 511 | GenericLinkService::Options options; |
| 512 | options.allowLocalFields = false; |
| 513 | initialize(options); |
| 514 | |
| 515 | Block packet = ndn::encoding::makeEmptyBlock(tlv::Name); |
| 516 | |
| 517 | BOOST_CHECK_NO_THROW(transport->receivePacket(packet)); |
| 518 | |
| 519 | BOOST_CHECK_EQUAL(receivedInterests.size(), 0); |
| 520 | BOOST_CHECK_EQUAL(receivedData.size(), 0); |
| 521 | BOOST_CHECK_EQUAL(receivedNacks.size(), 0); |
| 522 | } |
| 523 | |
| 524 | BOOST_AUTO_TEST_CASE(Unparsable) |
| 525 | { |
| 526 | // Initialize with Options that disables all services |
| 527 | GenericLinkService::Options options; |
| 528 | options.allowLocalFields = false; |
| 529 | initialize(options); |
| 530 | |
| 531 | Block packet = ndn::encoding::makeStringBlock(lp::tlv::LpPacket, "x"); |
| 532 | BOOST_CHECK_THROW(packet.parse(), tlv::Error); |
| 533 | |
| 534 | BOOST_CHECK_NO_THROW(transport->receivePacket(packet)); |
| 535 | |
| 536 | BOOST_CHECK_EQUAL(receivedInterests.size(), 0); |
| 537 | BOOST_CHECK_EQUAL(receivedData.size(), 0); |
| 538 | BOOST_CHECK_EQUAL(receivedNacks.size(), 0); |
| 539 | } |
| 540 | |
| 541 | BOOST_AUTO_TEST_SUITE_END() // Malformed |
| 542 | |
| 543 | |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 544 | BOOST_AUTO_TEST_SUITE_END() // TestGenericLinkService |
| 545 | BOOST_AUTO_TEST_SUITE_END() // Face |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 546 | |
| 547 | } // namespace tests |
| 548 | } // namespace face |
| 549 | } // namespace nfd |