blob: 46e75f0786ac84eca6ce8821fb8c0df4615f850e [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
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040031namespace nfd::tests {
Junxiao Shifab9e0d2017-02-02 06:04:59 +000032
Junxiao Shi727b6102022-01-11 18:40:04 +000033#define CHECK_FH_EQUAL(actual, ...) \
34 do { \
35 std::vector<Name> expected({__VA_ARGS__}); \
36 BOOST_CHECK_EQUAL_COLLECTIONS( \
37 (actual).getForwardingHint().begin(), (actual).getForwardingHint().end(), \
38 expected.begin(), expected.end()); \
39 } while (false)
40
Junxiao Shifab9e0d2017-02-02 06:04:59 +000041BOOST_AUTO_TEST_SUITE(Fw)
Junxiao Shifc2e13d2017-07-25 02:08:48 +000042BOOST_AUTO_TEST_SUITE(TestForwardingHint)
Junxiao Shifab9e0d2017-02-02 06:04:59 +000043
44/**
45 * /arizona/cs/avenir
46 * |
47 * v
48 * /arizona/cs/hobo
49 * | |
50 * v v
51 * /telia/terabits /ucsd/caida/click
52 * | |
53 * v v
54 * /net/ndnsim /ucla/cs/spurs
55 * (serverP) |
56 * v
57 * /net/ndnsim
58 * (serverQ)
59 */
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040060class NdnsimTeliaUclaTopologyFixture : public GlobalIoTimeFixture
Junxiao Shifab9e0d2017-02-02 06:04:59 +000061{
62public:
63 NdnsimTeliaUclaTopologyFixture()
64 {
65 topo.enablePcap();
66
67 nodeA = topo.addForwarder("avenir");
68 nodeH = topo.addForwarder("hobo");
69 nodeT = topo.addForwarder("terabits");
70 nodeP = topo.addForwarder("serverP");
71 nodeC = topo.addForwarder("click");
72 nodeS = topo.addForwarder("spurs");
73 nodeQ = topo.addForwarder("serverQ");
Davide Pesavento7922d122021-03-05 22:41:23 -050074 for (auto node : {nodeA, nodeH, nodeT, nodeP, nodeC, nodeS, nodeQ}) {
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040075 topo.setStrategy<fw::BestRouteStrategy>(node);
Junxiao Shifab9e0d2017-02-02 06:04:59 +000076 }
77
Junxiao Shifab9e0d2017-02-02 06:04:59 +000078 topo.getForwarder(nodeH).getNetworkRegionTable().insert("/arizona/cs/hobo");
79 topo.getForwarder(nodeT).getNetworkRegionTable().insert("/telia/terabits/router");
Junxiao Shifab9e0d2017-02-02 06:04:59 +000080 topo.getForwarder(nodeC).getNetworkRegionTable().insert("/ucsd/caida/click");
81 topo.getForwarder(nodeS).getNetworkRegionTable().insert("/ucla/cs/spurs");
Junxiao Shif9858fd2017-02-01 16:22:44 +000082 // NetworkRegionTable configuration is unnecessary on end hosts
Junxiao Shifab9e0d2017-02-02 06:04:59 +000083
Davide Pesavento14e71f02019-03-28 17:35:25 -040084 linkAH = topo.addLink("AH", 10_ms, {nodeA, nodeH});
85 linkHT = topo.addLink("HT", 10_ms, {nodeH, nodeT});
86 linkTP = topo.addLink("TP", 10_ms, {nodeT, nodeP});
87 linkHC = topo.addLink("HC", 10_ms, {nodeH, nodeC});
88 linkCS = topo.addLink("CS", 10_ms, {nodeC, nodeS});
89 linkSQ = topo.addLink("SQ", 10_ms, {nodeS, nodeQ});
Junxiao Shifab9e0d2017-02-02 06:04:59 +000090 consumerA = topo.addAppFace("avenir", nodeA);
91 producerP = topo.addAppFace("ndnsimP", nodeP, "/net/ndnsim");
92 producerQ = topo.addAppFace("ndnsimQ", nodeQ, "/net/ndnsim");
93
94 topo.addEchoProducer(producerP->getClientFace());
95 topo.addEchoProducer(producerQ->getClientFace());
96
97 topo.registerPrefix(nodeA, linkAH->getFace(nodeA), "/", 10);
98 topo.registerPrefix(nodeH, linkHT->getFace(nodeH), "/telia", 10);
99 topo.registerPrefix(nodeT, linkTP->getFace(nodeT), "/net/ndnsim", 10);
100 topo.registerPrefix(nodeH, linkHC->getFace(nodeH), "/ucla", 20);
101 topo.registerPrefix(nodeC, linkCS->getFace(nodeC), "/ucla", 10);
102 topo.registerPrefix(nodeS, linkSQ->getFace(nodeS), "/net/ndnsim", 10);
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000103 }
104
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400105 /** \brief Express an Interest with Link object from consumerA.
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000106 */
107 void
108 consumerExpressInterest(int seq)
109 {
110 auto interest = makeInterest(Name("/net/ndnsim").appendNumber(seq));
Junxiao Shi727b6102022-01-11 18:40:04 +0000111 interest->setForwardingHint({nameTelia, nameUcla});
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000112 consumerA->getClientFace().expressInterest(*interest, nullptr, nullptr, nullptr);
113 }
114
115public:
116 TopologyTester topo;
117 TopologyNode nodeA, nodeH, nodeT, nodeP, nodeC, nodeS, nodeQ;
118 shared_ptr<TopologyLink> linkAH, linkHT, linkTP, linkHC, linkCS, linkSQ;
119 shared_ptr<TopologyAppLink> consumerA, producerP, producerQ;
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000120
Junxiao Shi727b6102022-01-11 18:40:04 +0000121 Name nameTelia = "/telia/terabits";
122 Name nameUcla = "/ucla/cs";
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000123};
124
125BOOST_FIXTURE_TEST_SUITE(NdnsimTeliaUclaTopology, NdnsimTeliaUclaTopologyFixture)
126
127BOOST_AUTO_TEST_CASE(FetchTelia)
128{
129 this->consumerExpressInterest(1);
Davide Pesavento14e71f02019-03-28 17:35:25 -0400130 this->advanceClocks(11_ms, 20);
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000131
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000132 // A forwards Interest according to default route, no change to forwarding hint
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000133 BOOST_CHECK_EQUAL(linkAH->getFace(nodeA).getCounters().nOutInterests, 1);
134 const Interest& interestAH = topo.getPcap(linkAH->getFace(nodeA)).sentInterests.at(0);
Junxiao Shi727b6102022-01-11 18:40:04 +0000135 CHECK_FH_EQUAL(interestAH, nameTelia, nameUcla);
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000136
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000137 // H prefers T, no change to forwarding hint
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000138 BOOST_CHECK_EQUAL(linkHT->getFace(nodeH).getCounters().nOutInterests, 1);
139 const Interest& interestHT = topo.getPcap(linkHT->getFace(nodeH)).sentInterests.at(0);
Junxiao Shi727b6102022-01-11 18:40:04 +0000140 CHECK_FH_EQUAL(interestHT, nameTelia, nameUcla);
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000141
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000142 // T forwards to P, forwarding hint stripped when Interest reaches producer region
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000143 BOOST_CHECK_EQUAL(linkTP->getFace(nodeT).getCounters().nOutInterests, 1);
144 const Interest& interestTP = topo.getPcap(linkTP->getFace(nodeT)).sentInterests.at(0);
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000145 BOOST_CHECK(interestTP.getForwardingHint().empty());
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000146
147 // Data is served by P and reaches A
148 BOOST_CHECK_EQUAL(producerP->getForwarderFace().getCounters().nInData, 1);
149 BOOST_CHECK_EQUAL(consumerA->getForwarderFace().getCounters().nOutData, 1);
150}
151
152BOOST_AUTO_TEST_CASE(FetchUcla)
153{
154 // disconnect H-T and delete FIB entry
155 linkHT->fail();
156 topo.getForwarder(nodeH).getFib().erase("/telia");
157
158 this->consumerExpressInterest(1);
Davide Pesavento14e71f02019-03-28 17:35:25 -0400159 this->advanceClocks(11_ms, 20);
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000160
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000161 // A forwards Interest according to default route, no change to forwarding hint
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000162 BOOST_CHECK_EQUAL(linkAH->getFace(nodeA).getCounters().nOutInterests, 1);
163 const Interest& interestAH = topo.getPcap(linkAH->getFace(nodeA)).sentInterests.at(0);
Junxiao Shi727b6102022-01-11 18:40:04 +0000164 CHECK_FH_EQUAL(interestAH, nameTelia, nameUcla);
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000165
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000166 // H forwards to C, no change to forwarding hint
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000167 BOOST_CHECK_EQUAL(linkHC->getFace(nodeH).getCounters().nOutInterests, 1);
168 const Interest& interestHC = topo.getPcap(linkHC->getFace(nodeH)).sentInterests.at(0);
Junxiao Shi727b6102022-01-11 18:40:04 +0000169 CHECK_FH_EQUAL(interestHC, nameTelia, nameUcla);
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000170
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000171 // C forwards to S, no change to forwarding hint
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000172 BOOST_CHECK_EQUAL(linkCS->getFace(nodeC).getCounters().nOutInterests, 1);
173 const Interest& interestCS = topo.getPcap(linkCS->getFace(nodeC)).sentInterests.at(0);
Junxiao Shi727b6102022-01-11 18:40:04 +0000174 CHECK_FH_EQUAL(interestCS, nameTelia, nameUcla);
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000175
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000176 // S forwards to Q, forwarding hint stripped when Interest reaches producer region
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000177 BOOST_CHECK_EQUAL(linkSQ->getFace(nodeS).getCounters().nOutInterests, 1);
178 const Interest& interestSQ = topo.getPcap(linkSQ->getFace(nodeS)).sentInterests.at(0);
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000179 BOOST_CHECK(interestSQ.getForwardingHint().empty());
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000180
181 // Data is served by Q and reaches A
182 BOOST_CHECK_EQUAL(producerQ->getForwarderFace().getCounters().nInData, 1);
183 BOOST_CHECK_EQUAL(consumerA->getForwarderFace().getCounters().nOutData, 1);
184}
185
186BOOST_AUTO_TEST_SUITE_END() // NdnsimTeliaUclaTopology
187
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000188BOOST_AUTO_TEST_SUITE_END() // TestForwardingHint
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000189BOOST_AUTO_TEST_SUITE_END() // Fw
190
Davide Pesaventoe422f9e2022-06-03 01:30:23 -0400191} // namespace nfd::tests