Junxiao Shi | 606d5dd | 2019-09-23 12:47:44 -0600 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
Davide Pesavento | 9a63bf2 | 2023-11-11 17:12:51 -0500 | [diff] [blame^] | 3 | * Copyright (c) 2014-2023, Regents of the University of California, |
Junxiao Shi | 606d5dd | 2019-09-23 12:47:44 -0600 | [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 "tests/daemon/global-io-fixture.hpp" |
| 27 | #include "topology-tester.hpp" |
| 28 | |
Davide Pesavento | 9a63bf2 | 2023-11-11 17:12:51 -0500 | [diff] [blame^] | 29 | #include <ndn-cxx/lp/fields.hpp> |
Junxiao Shi | 606d5dd | 2019-09-23 12:47:44 -0600 | [diff] [blame] | 30 | #include <ndn-cxx/lp/packet.hpp> |
| 31 | #include <ndn-cxx/lp/pit-token.hpp> |
| 32 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 33 | namespace nfd::tests { |
Junxiao Shi | 606d5dd | 2019-09-23 12:47:44 -0600 | [diff] [blame] | 34 | |
| 35 | BOOST_AUTO_TEST_SUITE(Fw) |
| 36 | BOOST_AUTO_TEST_SUITE(TestPitToken) |
| 37 | |
| 38 | // Downstream requires PIT token. |
| 39 | BOOST_FIXTURE_TEST_CASE(Downstream, GlobalIoTimeFixture) |
| 40 | { |
| 41 | TopologyTester topo; |
| 42 | TopologyNode nodeR = topo.addForwarder("R"); |
| 43 | auto linkC = topo.addBareLink("C", nodeR, ndn::nfd::FACE_SCOPE_NON_LOCAL); |
| 44 | auto linkS = topo.addBareLink("S", nodeR, ndn::nfd::FACE_SCOPE_NON_LOCAL); |
| 45 | topo.registerPrefix(nodeR, linkS->getForwarderFace(), "/U", 5); |
| 46 | // Client --- Router --- Server |
| 47 | // Client requires PIT token; Router supports PIT token; Server disallows PIT token. |
| 48 | |
Junxiao Shi | c29eb7f | 2020-04-14 18:20:32 +0000 | [diff] [blame] | 49 | // C sends Interest /U/0 with PIT token A |
| 50 | lp::Packet lppI0("641A pit-token=6206A0A1A2A3A4A5 payload=5010 interest=050E 0706080155080130 0A0400000001"_block); |
| 51 | lp::PitToken tokenI0(lppI0.get<lp::PitTokenField>()); |
| 52 | linkC->receivePacket(lppI0.wireEncode()); |
Junxiao Shi | 606d5dd | 2019-09-23 12:47:44 -0600 | [diff] [blame] | 53 | advanceClocks(5_ms, 30_ms); |
| 54 | |
| 55 | // S should receive Interest without PIT token |
| 56 | BOOST_REQUIRE_EQUAL(linkS->sentPackets.size(), 1); |
Junxiao Shi | c29eb7f | 2020-04-14 18:20:32 +0000 | [diff] [blame] | 57 | lp::Packet lppS(linkS->sentPackets.back()); |
Junxiao Shi | 606d5dd | 2019-09-23 12:47:44 -0600 | [diff] [blame] | 58 | BOOST_CHECK_EQUAL(lppS.count<lp::PitTokenField>(), 0); |
| 59 | |
| 60 | // S responds Data |
| 61 | linkS->receivePacket(makeData("/U/0")->wireEncode()); |
| 62 | advanceClocks(5_ms, 30_ms); |
| 63 | |
Junxiao Shi | c29eb7f | 2020-04-14 18:20:32 +0000 | [diff] [blame] | 64 | // C should receive Data with PIT token A |
Junxiao Shi | 606d5dd | 2019-09-23 12:47:44 -0600 | [diff] [blame] | 65 | BOOST_REQUIRE_EQUAL(linkC->sentPackets.size(), 1); |
Junxiao Shi | c29eb7f | 2020-04-14 18:20:32 +0000 | [diff] [blame] | 66 | lp::Packet lppD0(linkC->sentPackets.back()); |
| 67 | lp::PitToken tokenD0(lppD0.get<lp::PitTokenField>()); |
| 68 | BOOST_CHECK(tokenD0 == tokenI0); |
| 69 | |
| 70 | // C sends Interest /U/0 again with PIT token B |
| 71 | lp::Packet lppI1("641C pit-token=6208B0B1B2B3B4B5B6B7 payload=5010 interest=050E 0706080155080130 0A0400000002"_block); |
| 72 | lp::PitToken tokenI1(lppI1.get<lp::PitTokenField>()); |
| 73 | linkC->receivePacket(lppI1.wireEncode()); |
| 74 | advanceClocks(5_ms, 30_ms); |
| 75 | |
| 76 | // S should not receive Interest, because the Interest is satisfied by CS |
| 77 | BOOST_CHECK_EQUAL(linkS->sentPackets.size(), 1); |
| 78 | |
| 79 | // C should receive Data with PIT token B |
| 80 | BOOST_REQUIRE_EQUAL(linkC->sentPackets.size(), 2); |
| 81 | lp::Packet lppD1(linkC->sentPackets.back()); |
| 82 | lp::PitToken tokenD1(lppD1.get<lp::PitTokenField>()); |
| 83 | BOOST_CHECK(tokenD1 == tokenI1); |
Junxiao Shi | 606d5dd | 2019-09-23 12:47:44 -0600 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | BOOST_AUTO_TEST_SUITE_END() // TestPitToken |
| 87 | BOOST_AUTO_TEST_SUITE_END() // Fw |
| 88 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 89 | } // namespace nfd::tests |