blob: d3303958b89c4c2373ea19a6bd424624abb26722 [file] [log] [blame]
Junxiao Shifab9e0d2017-02-02 06:04:59 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shifc2e13d2017-07-25 02:08:48 +00002/*
Junxiao Shi727b6102022-01-11 18:40:04 +00003 * Copyright (c) 2014-2022, Regents of the University of California,
Junxiao Shifab9e0d2017-02-02 06:04:59 +00004 * 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 Pesavento7922d122021-03-05 22:41:23 -050026#include "fw/best-route-strategy.hpp"
Junxiao Shifab9e0d2017-02-02 06:04:59 +000027
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040028#include "tests/daemon/global-io-fixture.hpp"
Junxiao Shifab9e0d2017-02-02 06:04:59 +000029#include "topology-tester.hpp"
30
31namespace nfd {
32namespace fw {
33namespace tests {
34
35using namespace nfd::tests;
36
Junxiao Shi727b6102022-01-11 18:40:04 +000037#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 Shifab9e0d2017-02-02 06:04:59 +000045BOOST_AUTO_TEST_SUITE(Fw)
Junxiao Shifc2e13d2017-07-25 02:08:48 +000046BOOST_AUTO_TEST_SUITE(TestForwardingHint)
Junxiao Shifab9e0d2017-02-02 06:04:59 +000047
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 Pesaventocf7db2f2019-03-24 23:17:28 -040064class NdnsimTeliaUclaTopologyFixture : public GlobalIoTimeFixture
Junxiao Shifab9e0d2017-02-02 06:04:59 +000065{
66public:
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 Pesavento7922d122021-03-05 22:41:23 -050078 for (auto node : {nodeA, nodeH, nodeT, nodeP, nodeC, nodeS, nodeQ}) {
79 topo.setStrategy<BestRouteStrategy>(node);
Junxiao Shifab9e0d2017-02-02 06:04:59 +000080 }
81
Junxiao Shifab9e0d2017-02-02 06:04:59 +000082 topo.getForwarder(nodeH).getNetworkRegionTable().insert("/arizona/cs/hobo");
83 topo.getForwarder(nodeT).getNetworkRegionTable().insert("/telia/terabits/router");
Junxiao Shifab9e0d2017-02-02 06:04:59 +000084 topo.getForwarder(nodeC).getNetworkRegionTable().insert("/ucsd/caida/click");
85 topo.getForwarder(nodeS).getNetworkRegionTable().insert("/ucla/cs/spurs");
Junxiao Shif9858fd2017-02-01 16:22:44 +000086 // NetworkRegionTable configuration is unnecessary on end hosts
Junxiao Shifab9e0d2017-02-02 06:04:59 +000087
Davide Pesavento14e71f02019-03-28 17:35:25 -040088 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 Shifab9e0d2017-02-02 06:04:59 +000094 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 Shifab9e0d2017-02-02 06:04:59 +0000107 }
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 Shi727b6102022-01-11 18:40:04 +0000115 interest->setForwardingHint({nameTelia, nameUcla});
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000116 consumerA->getClientFace().expressInterest(*interest, nullptr, nullptr, nullptr);
117 }
118
119public:
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 Shifc2e13d2017-07-25 02:08:48 +0000124
Junxiao Shi727b6102022-01-11 18:40:04 +0000125 Name nameTelia = "/telia/terabits";
126 Name nameUcla = "/ucla/cs";
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000127};
128
129BOOST_FIXTURE_TEST_SUITE(NdnsimTeliaUclaTopology, NdnsimTeliaUclaTopologyFixture)
130
131BOOST_AUTO_TEST_CASE(FetchTelia)
132{
133 this->consumerExpressInterest(1);
Davide Pesavento14e71f02019-03-28 17:35:25 -0400134 this->advanceClocks(11_ms, 20);
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000135
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000136 // A forwards Interest according to default route, no change to forwarding hint
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000137 BOOST_CHECK_EQUAL(linkAH->getFace(nodeA).getCounters().nOutInterests, 1);
138 const Interest& interestAH = topo.getPcap(linkAH->getFace(nodeA)).sentInterests.at(0);
Junxiao Shi727b6102022-01-11 18:40:04 +0000139 CHECK_FH_EQUAL(interestAH, nameTelia, nameUcla);
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000140
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000141 // H prefers T, no change to forwarding hint
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000142 BOOST_CHECK_EQUAL(linkHT->getFace(nodeH).getCounters().nOutInterests, 1);
143 const Interest& interestHT = topo.getPcap(linkHT->getFace(nodeH)).sentInterests.at(0);
Junxiao Shi727b6102022-01-11 18:40:04 +0000144 CHECK_FH_EQUAL(interestHT, nameTelia, nameUcla);
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000145
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000146 // T forwards to P, forwarding hint stripped when Interest reaches producer region
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000147 BOOST_CHECK_EQUAL(linkTP->getFace(nodeT).getCounters().nOutInterests, 1);
148 const Interest& interestTP = topo.getPcap(linkTP->getFace(nodeT)).sentInterests.at(0);
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000149 BOOST_CHECK(interestTP.getForwardingHint().empty());
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000150
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
156BOOST_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 Pesavento14e71f02019-03-28 17:35:25 -0400163 this->advanceClocks(11_ms, 20);
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000164
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000165 // A forwards Interest according to default route, no change to forwarding hint
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000166 BOOST_CHECK_EQUAL(linkAH->getFace(nodeA).getCounters().nOutInterests, 1);
167 const Interest& interestAH = topo.getPcap(linkAH->getFace(nodeA)).sentInterests.at(0);
Junxiao Shi727b6102022-01-11 18:40:04 +0000168 CHECK_FH_EQUAL(interestAH, nameTelia, nameUcla);
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000169
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000170 // H forwards to C, no change to forwarding hint
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000171 BOOST_CHECK_EQUAL(linkHC->getFace(nodeH).getCounters().nOutInterests, 1);
172 const Interest& interestHC = topo.getPcap(linkHC->getFace(nodeH)).sentInterests.at(0);
Junxiao Shi727b6102022-01-11 18:40:04 +0000173 CHECK_FH_EQUAL(interestHC, nameTelia, nameUcla);
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000174
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000175 // C forwards to S, no change to forwarding hint
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000176 BOOST_CHECK_EQUAL(linkCS->getFace(nodeC).getCounters().nOutInterests, 1);
177 const Interest& interestCS = topo.getPcap(linkCS->getFace(nodeC)).sentInterests.at(0);
Junxiao Shi727b6102022-01-11 18:40:04 +0000178 CHECK_FH_EQUAL(interestCS, nameTelia, nameUcla);
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000179
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000180 // S forwards to Q, forwarding hint stripped when Interest reaches producer region
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000181 BOOST_CHECK_EQUAL(linkSQ->getFace(nodeS).getCounters().nOutInterests, 1);
182 const Interest& interestSQ = topo.getPcap(linkSQ->getFace(nodeS)).sentInterests.at(0);
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000183 BOOST_CHECK(interestSQ.getForwardingHint().empty());
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000184
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
190BOOST_AUTO_TEST_SUITE_END() // NdnsimTeliaUclaTopology
191
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000192BOOST_AUTO_TEST_SUITE_END() // TestForwardingHint
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000193BOOST_AUTO_TEST_SUITE_END() // Fw
194
195} // namespace tests
196} // namespace fw
197} // namespace nfd