Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | fc2e13d | 2017-07-25 02:08:48 +0000 | [diff] [blame] | 2 | /* |
Junxiao Shi | 727b610 | 2022-01-11 18:40:04 +0000 | [diff] [blame^] | 3 | * Copyright (c) 2014-2022, Regents of the University of California, |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [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 | |
Davide Pesavento | 7922d12 | 2021-03-05 22:41:23 -0500 | [diff] [blame] | 26 | #include "fw/best-route-strategy.hpp" |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 27 | |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 28 | #include "tests/daemon/global-io-fixture.hpp" |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 29 | #include "topology-tester.hpp" |
| 30 | |
| 31 | namespace nfd { |
| 32 | namespace fw { |
| 33 | namespace tests { |
| 34 | |
| 35 | using namespace nfd::tests; |
| 36 | |
Junxiao Shi | 727b610 | 2022-01-11 18:40:04 +0000 | [diff] [blame^] | 37 | #define CHECK_FH_EQUAL(actual, ...) \ |
| 38 | do { \ |
| 39 | std::vector<Name> expected({__VA_ARGS__}); \ |
| 40 | BOOST_CHECK_EQUAL_COLLECTIONS( \ |
| 41 | (actual).getForwardingHint().begin(), (actual).getForwardingHint().end(), \ |
| 42 | expected.begin(), expected.end()); \ |
| 43 | } while (false) |
| 44 | |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 45 | BOOST_AUTO_TEST_SUITE(Fw) |
Junxiao Shi | fc2e13d | 2017-07-25 02:08:48 +0000 | [diff] [blame] | 46 | BOOST_AUTO_TEST_SUITE(TestForwardingHint) |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 47 | |
| 48 | /** |
| 49 | * /arizona/cs/avenir |
| 50 | * | |
| 51 | * v |
| 52 | * /arizona/cs/hobo |
| 53 | * | | |
| 54 | * v v |
| 55 | * /telia/terabits /ucsd/caida/click |
| 56 | * | | |
| 57 | * v v |
| 58 | * /net/ndnsim /ucla/cs/spurs |
| 59 | * (serverP) | |
| 60 | * v |
| 61 | * /net/ndnsim |
| 62 | * (serverQ) |
| 63 | */ |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 64 | class NdnsimTeliaUclaTopologyFixture : public GlobalIoTimeFixture |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 65 | { |
| 66 | public: |
| 67 | NdnsimTeliaUclaTopologyFixture() |
| 68 | { |
| 69 | topo.enablePcap(); |
| 70 | |
| 71 | nodeA = topo.addForwarder("avenir"); |
| 72 | nodeH = topo.addForwarder("hobo"); |
| 73 | nodeT = topo.addForwarder("terabits"); |
| 74 | nodeP = topo.addForwarder("serverP"); |
| 75 | nodeC = topo.addForwarder("click"); |
| 76 | nodeS = topo.addForwarder("spurs"); |
| 77 | nodeQ = topo.addForwarder("serverQ"); |
Davide Pesavento | 7922d12 | 2021-03-05 22:41:23 -0500 | [diff] [blame] | 78 | for (auto node : {nodeA, nodeH, nodeT, nodeP, nodeC, nodeS, nodeQ}) { |
| 79 | topo.setStrategy<BestRouteStrategy>(node); |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 80 | } |
| 81 | |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 82 | topo.getForwarder(nodeH).getNetworkRegionTable().insert("/arizona/cs/hobo"); |
| 83 | topo.getForwarder(nodeT).getNetworkRegionTable().insert("/telia/terabits/router"); |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 84 | topo.getForwarder(nodeC).getNetworkRegionTable().insert("/ucsd/caida/click"); |
| 85 | topo.getForwarder(nodeS).getNetworkRegionTable().insert("/ucla/cs/spurs"); |
Junxiao Shi | f9858fd | 2017-02-01 16:22:44 +0000 | [diff] [blame] | 86 | // NetworkRegionTable configuration is unnecessary on end hosts |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 87 | |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 88 | linkAH = topo.addLink("AH", 10_ms, {nodeA, nodeH}); |
| 89 | linkHT = topo.addLink("HT", 10_ms, {nodeH, nodeT}); |
| 90 | linkTP = topo.addLink("TP", 10_ms, {nodeT, nodeP}); |
| 91 | linkHC = topo.addLink("HC", 10_ms, {nodeH, nodeC}); |
| 92 | linkCS = topo.addLink("CS", 10_ms, {nodeC, nodeS}); |
| 93 | linkSQ = topo.addLink("SQ", 10_ms, {nodeS, nodeQ}); |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 94 | consumerA = topo.addAppFace("avenir", nodeA); |
| 95 | producerP = topo.addAppFace("ndnsimP", nodeP, "/net/ndnsim"); |
| 96 | producerQ = topo.addAppFace("ndnsimQ", nodeQ, "/net/ndnsim"); |
| 97 | |
| 98 | topo.addEchoProducer(producerP->getClientFace()); |
| 99 | topo.addEchoProducer(producerQ->getClientFace()); |
| 100 | |
| 101 | topo.registerPrefix(nodeA, linkAH->getFace(nodeA), "/", 10); |
| 102 | topo.registerPrefix(nodeH, linkHT->getFace(nodeH), "/telia", 10); |
| 103 | topo.registerPrefix(nodeT, linkTP->getFace(nodeT), "/net/ndnsim", 10); |
| 104 | topo.registerPrefix(nodeH, linkHC->getFace(nodeH), "/ucla", 20); |
| 105 | topo.registerPrefix(nodeC, linkCS->getFace(nodeC), "/ucla", 10); |
| 106 | topo.registerPrefix(nodeS, linkSQ->getFace(nodeS), "/net/ndnsim", 10); |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | /** \brief express an Interest with Link object from consumerA |
| 110 | */ |
| 111 | void |
| 112 | consumerExpressInterest(int seq) |
| 113 | { |
| 114 | auto interest = makeInterest(Name("/net/ndnsim").appendNumber(seq)); |
Junxiao Shi | 727b610 | 2022-01-11 18:40:04 +0000 | [diff] [blame^] | 115 | interest->setForwardingHint({nameTelia, nameUcla}); |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 116 | consumerA->getClientFace().expressInterest(*interest, nullptr, nullptr, nullptr); |
| 117 | } |
| 118 | |
| 119 | public: |
| 120 | TopologyTester topo; |
| 121 | TopologyNode nodeA, nodeH, nodeT, nodeP, nodeC, nodeS, nodeQ; |
| 122 | shared_ptr<TopologyLink> linkAH, linkHT, linkTP, linkHC, linkCS, linkSQ; |
| 123 | shared_ptr<TopologyAppLink> consumerA, producerP, producerQ; |
Junxiao Shi | fc2e13d | 2017-07-25 02:08:48 +0000 | [diff] [blame] | 124 | |
Junxiao Shi | 727b610 | 2022-01-11 18:40:04 +0000 | [diff] [blame^] | 125 | Name nameTelia = "/telia/terabits"; |
| 126 | Name nameUcla = "/ucla/cs"; |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 127 | }; |
| 128 | |
| 129 | BOOST_FIXTURE_TEST_SUITE(NdnsimTeliaUclaTopology, NdnsimTeliaUclaTopologyFixture) |
| 130 | |
| 131 | BOOST_AUTO_TEST_CASE(FetchTelia) |
| 132 | { |
| 133 | this->consumerExpressInterest(1); |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 134 | this->advanceClocks(11_ms, 20); |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 135 | |
Junxiao Shi | fc2e13d | 2017-07-25 02:08:48 +0000 | [diff] [blame] | 136 | // A forwards Interest according to default route, no change to forwarding hint |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 137 | BOOST_CHECK_EQUAL(linkAH->getFace(nodeA).getCounters().nOutInterests, 1); |
| 138 | const Interest& interestAH = topo.getPcap(linkAH->getFace(nodeA)).sentInterests.at(0); |
Junxiao Shi | 727b610 | 2022-01-11 18:40:04 +0000 | [diff] [blame^] | 139 | CHECK_FH_EQUAL(interestAH, nameTelia, nameUcla); |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 140 | |
Junxiao Shi | fc2e13d | 2017-07-25 02:08:48 +0000 | [diff] [blame] | 141 | // H prefers T, no change to forwarding hint |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 142 | BOOST_CHECK_EQUAL(linkHT->getFace(nodeH).getCounters().nOutInterests, 1); |
| 143 | const Interest& interestHT = topo.getPcap(linkHT->getFace(nodeH)).sentInterests.at(0); |
Junxiao Shi | 727b610 | 2022-01-11 18:40:04 +0000 | [diff] [blame^] | 144 | CHECK_FH_EQUAL(interestHT, nameTelia, nameUcla); |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 145 | |
Junxiao Shi | fc2e13d | 2017-07-25 02:08:48 +0000 | [diff] [blame] | 146 | // T forwards to P, forwarding hint stripped when Interest reaches producer region |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 147 | BOOST_CHECK_EQUAL(linkTP->getFace(nodeT).getCounters().nOutInterests, 1); |
| 148 | const Interest& interestTP = topo.getPcap(linkTP->getFace(nodeT)).sentInterests.at(0); |
Junxiao Shi | fc2e13d | 2017-07-25 02:08:48 +0000 | [diff] [blame] | 149 | BOOST_CHECK(interestTP.getForwardingHint().empty()); |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 150 | |
| 151 | // Data is served by P and reaches A |
| 152 | BOOST_CHECK_EQUAL(producerP->getForwarderFace().getCounters().nInData, 1); |
| 153 | BOOST_CHECK_EQUAL(consumerA->getForwarderFace().getCounters().nOutData, 1); |
| 154 | } |
| 155 | |
| 156 | BOOST_AUTO_TEST_CASE(FetchUcla) |
| 157 | { |
| 158 | // disconnect H-T and delete FIB entry |
| 159 | linkHT->fail(); |
| 160 | topo.getForwarder(nodeH).getFib().erase("/telia"); |
| 161 | |
| 162 | this->consumerExpressInterest(1); |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 163 | this->advanceClocks(11_ms, 20); |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 164 | |
Junxiao Shi | fc2e13d | 2017-07-25 02:08:48 +0000 | [diff] [blame] | 165 | // A forwards Interest according to default route, no change to forwarding hint |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 166 | BOOST_CHECK_EQUAL(linkAH->getFace(nodeA).getCounters().nOutInterests, 1); |
| 167 | const Interest& interestAH = topo.getPcap(linkAH->getFace(nodeA)).sentInterests.at(0); |
Junxiao Shi | 727b610 | 2022-01-11 18:40:04 +0000 | [diff] [blame^] | 168 | CHECK_FH_EQUAL(interestAH, nameTelia, nameUcla); |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 169 | |
Junxiao Shi | fc2e13d | 2017-07-25 02:08:48 +0000 | [diff] [blame] | 170 | // H forwards to C, no change to forwarding hint |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 171 | BOOST_CHECK_EQUAL(linkHC->getFace(nodeH).getCounters().nOutInterests, 1); |
| 172 | const Interest& interestHC = topo.getPcap(linkHC->getFace(nodeH)).sentInterests.at(0); |
Junxiao Shi | 727b610 | 2022-01-11 18:40:04 +0000 | [diff] [blame^] | 173 | CHECK_FH_EQUAL(interestHC, nameTelia, nameUcla); |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 174 | |
Junxiao Shi | fc2e13d | 2017-07-25 02:08:48 +0000 | [diff] [blame] | 175 | // C forwards to S, no change to forwarding hint |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 176 | BOOST_CHECK_EQUAL(linkCS->getFace(nodeC).getCounters().nOutInterests, 1); |
| 177 | const Interest& interestCS = topo.getPcap(linkCS->getFace(nodeC)).sentInterests.at(0); |
Junxiao Shi | 727b610 | 2022-01-11 18:40:04 +0000 | [diff] [blame^] | 178 | CHECK_FH_EQUAL(interestCS, nameTelia, nameUcla); |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 179 | |
Junxiao Shi | fc2e13d | 2017-07-25 02:08:48 +0000 | [diff] [blame] | 180 | // S forwards to Q, forwarding hint stripped when Interest reaches producer region |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 181 | BOOST_CHECK_EQUAL(linkSQ->getFace(nodeS).getCounters().nOutInterests, 1); |
| 182 | const Interest& interestSQ = topo.getPcap(linkSQ->getFace(nodeS)).sentInterests.at(0); |
Junxiao Shi | fc2e13d | 2017-07-25 02:08:48 +0000 | [diff] [blame] | 183 | BOOST_CHECK(interestSQ.getForwardingHint().empty()); |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 184 | |
| 185 | // Data is served by Q and reaches A |
| 186 | BOOST_CHECK_EQUAL(producerQ->getForwarderFace().getCounters().nInData, 1); |
| 187 | BOOST_CHECK_EQUAL(consumerA->getForwarderFace().getCounters().nOutData, 1); |
| 188 | } |
| 189 | |
| 190 | BOOST_AUTO_TEST_SUITE_END() // NdnsimTeliaUclaTopology |
| 191 | |
Junxiao Shi | fc2e13d | 2017-07-25 02:08:48 +0000 | [diff] [blame] | 192 | BOOST_AUTO_TEST_SUITE_END() // TestForwardingHint |
Junxiao Shi | fab9e0d | 2017-02-02 06:04:59 +0000 | [diff] [blame] | 193 | BOOST_AUTO_TEST_SUITE_END() // Fw |
| 194 | |
| 195 | } // namespace tests |
| 196 | } // namespace fw |
| 197 | } // namespace nfd |