Junxiao Shi | 606d5dd | 2019-09-23 12:47:44 -0600 | [diff] [blame^] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2014-2019, 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 "tests/daemon/global-io-fixture.hpp" |
| 27 | #include "topology-tester.hpp" |
| 28 | |
| 29 | #include <ndn-cxx/lp/packet.hpp> |
| 30 | #include <ndn-cxx/lp/pit-token.hpp> |
| 31 | |
| 32 | namespace nfd { |
| 33 | namespace fw { |
| 34 | namespace tests { |
| 35 | |
| 36 | using namespace nfd::tests; |
| 37 | |
| 38 | BOOST_AUTO_TEST_SUITE(Fw) |
| 39 | BOOST_AUTO_TEST_SUITE(TestPitToken) |
| 40 | |
| 41 | // Downstream requires PIT token. |
| 42 | BOOST_FIXTURE_TEST_CASE(Downstream, GlobalIoTimeFixture) |
| 43 | { |
| 44 | TopologyTester topo; |
| 45 | TopologyNode nodeR = topo.addForwarder("R"); |
| 46 | auto linkC = topo.addBareLink("C", nodeR, ndn::nfd::FACE_SCOPE_NON_LOCAL); |
| 47 | auto linkS = topo.addBareLink("S", nodeR, ndn::nfd::FACE_SCOPE_NON_LOCAL); |
| 48 | topo.registerPrefix(nodeR, linkS->getForwarderFace(), "/U", 5); |
| 49 | // Client --- Router --- Server |
| 50 | // Client requires PIT token; Router supports PIT token; Server disallows PIT token. |
| 51 | |
| 52 | // C sends Interest /U/0 with PIT token |
| 53 | lp::Packet lppI("6414 pit-token=6206A0A1A2A3A4A5 payload=500A interest=0508 0706080155080130"_block); |
| 54 | lp::PitToken tokenI(lppI.get<lp::PitTokenField>()); |
| 55 | linkC->receivePacket(lppI.wireEncode()); |
| 56 | advanceClocks(5_ms, 30_ms); |
| 57 | |
| 58 | // S should receive Interest without PIT token |
| 59 | BOOST_REQUIRE_EQUAL(linkS->sentPackets.size(), 1); |
| 60 | lp::Packet lppS(linkS->sentPackets.front()); |
| 61 | BOOST_CHECK_EQUAL(lppS.count<lp::PitTokenField>(), 0); |
| 62 | |
| 63 | // S responds Data |
| 64 | linkS->receivePacket(makeData("/U/0")->wireEncode()); |
| 65 | advanceClocks(5_ms, 30_ms); |
| 66 | |
| 67 | // C should receive Data with same PIT token |
| 68 | BOOST_REQUIRE_EQUAL(linkC->sentPackets.size(), 1); |
| 69 | lp::Packet lppD(linkC->sentPackets.front()); |
| 70 | lp::PitToken tokenD(lppD.get<lp::PitTokenField>()); |
| 71 | BOOST_CHECK(tokenD == tokenI); |
| 72 | } |
| 73 | |
| 74 | BOOST_AUTO_TEST_SUITE_END() // TestPitToken |
| 75 | BOOST_AUTO_TEST_SUITE_END() // Fw |
| 76 | |
| 77 | } // namespace tests |
| 78 | } // namespace fw |
| 79 | } // namespace nfd |