blob: 7e9dbdcb0e52909db60043b3b91e8588dc3d5926 [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/*
Davide Pesaventocf7db2f2019-03-24 23:17:28 -04003 * Copyright (c) 2014-2019, 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
26#include "fw/best-route-strategy2.hpp"
27
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
37BOOST_AUTO_TEST_SUITE(Fw)
Junxiao Shifc2e13d2017-07-25 02:08:48 +000038BOOST_AUTO_TEST_SUITE(TestForwardingHint)
Junxiao Shifab9e0d2017-02-02 06:04:59 +000039
40/**
41 * /arizona/cs/avenir
42 * |
43 * v
44 * /arizona/cs/hobo
45 * | |
46 * v v
47 * /telia/terabits /ucsd/caida/click
48 * | |
49 * v v
50 * /net/ndnsim /ucla/cs/spurs
51 * (serverP) |
52 * v
53 * /net/ndnsim
54 * (serverQ)
55 */
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040056class NdnsimTeliaUclaTopologyFixture : public GlobalIoTimeFixture
Junxiao Shifab9e0d2017-02-02 06:04:59 +000057{
58public:
59 NdnsimTeliaUclaTopologyFixture()
60 {
61 topo.enablePcap();
62
63 nodeA = topo.addForwarder("avenir");
64 nodeH = topo.addForwarder("hobo");
65 nodeT = topo.addForwarder("terabits");
66 nodeP = topo.addForwarder("serverP");
67 nodeC = topo.addForwarder("click");
68 nodeS = topo.addForwarder("spurs");
69 nodeQ = topo.addForwarder("serverQ");
70 for (TopologyNode node : {nodeA, nodeH, nodeT, nodeP, nodeC, nodeS, nodeQ}) {
71 topo.setStrategy<BestRouteStrategy2>(node);
72 }
73
Junxiao Shifab9e0d2017-02-02 06:04:59 +000074 topo.getForwarder(nodeH).getNetworkRegionTable().insert("/arizona/cs/hobo");
75 topo.getForwarder(nodeT).getNetworkRegionTable().insert("/telia/terabits/router");
Junxiao Shifab9e0d2017-02-02 06:04:59 +000076 topo.getForwarder(nodeC).getNetworkRegionTable().insert("/ucsd/caida/click");
77 topo.getForwarder(nodeS).getNetworkRegionTable().insert("/ucla/cs/spurs");
Junxiao Shif9858fd2017-02-01 16:22:44 +000078 // NetworkRegionTable configuration is unnecessary on end hosts
Junxiao Shifab9e0d2017-02-02 06:04:59 +000079
Davide Pesavento14e71f02019-03-28 17:35:25 -040080 linkAH = topo.addLink("AH", 10_ms, {nodeA, nodeH});
81 linkHT = topo.addLink("HT", 10_ms, {nodeH, nodeT});
82 linkTP = topo.addLink("TP", 10_ms, {nodeT, nodeP});
83 linkHC = topo.addLink("HC", 10_ms, {nodeH, nodeC});
84 linkCS = topo.addLink("CS", 10_ms, {nodeC, nodeS});
85 linkSQ = topo.addLink("SQ", 10_ms, {nodeS, nodeQ});
Junxiao Shifab9e0d2017-02-02 06:04:59 +000086 consumerA = topo.addAppFace("avenir", nodeA);
87 producerP = topo.addAppFace("ndnsimP", nodeP, "/net/ndnsim");
88 producerQ = topo.addAppFace("ndnsimQ", nodeQ, "/net/ndnsim");
89
90 topo.addEchoProducer(producerP->getClientFace());
91 topo.addEchoProducer(producerQ->getClientFace());
92
93 topo.registerPrefix(nodeA, linkAH->getFace(nodeA), "/", 10);
94 topo.registerPrefix(nodeH, linkHT->getFace(nodeH), "/telia", 10);
95 topo.registerPrefix(nodeT, linkTP->getFace(nodeT), "/net/ndnsim", 10);
96 topo.registerPrefix(nodeH, linkHC->getFace(nodeH), "/ucla", 20);
97 topo.registerPrefix(nodeC, linkCS->getFace(nodeC), "/ucla", 10);
98 topo.registerPrefix(nodeS, linkSQ->getFace(nodeS), "/net/ndnsim", 10);
Junxiao Shifab9e0d2017-02-02 06:04:59 +000099 }
100
101 /** \brief express an Interest with Link object from consumerA
102 */
103 void
104 consumerExpressInterest(int seq)
105 {
106 auto interest = makeInterest(Name("/net/ndnsim").appendNumber(seq));
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000107 interest->setForwardingHint({delTelia, delUcla});
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000108 consumerA->getClientFace().expressInterest(*interest, nullptr, nullptr, nullptr);
109 }
110
111public:
112 TopologyTester topo;
113 TopologyNode nodeA, nodeH, nodeT, nodeP, nodeC, nodeS, nodeQ;
114 shared_ptr<TopologyLink> linkAH, linkHT, linkTP, linkHC, linkCS, linkSQ;
115 shared_ptr<TopologyAppLink> consumerA, producerP, producerQ;
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000116
117 Delegation delTelia = {10, "/telia/terabits"};
118 Delegation delUcla = {20, "/ucla/cs"};
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000119};
120
121BOOST_FIXTURE_TEST_SUITE(NdnsimTeliaUclaTopology, NdnsimTeliaUclaTopologyFixture)
122
123BOOST_AUTO_TEST_CASE(FetchTelia)
124{
125 this->consumerExpressInterest(1);
Davide Pesavento14e71f02019-03-28 17:35:25 -0400126 this->advanceClocks(11_ms, 20);
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000127
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000128 // A forwards Interest according to default route, no change to forwarding hint
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000129 BOOST_CHECK_EQUAL(linkAH->getFace(nodeA).getCounters().nOutInterests, 1);
130 const Interest& interestAH = topo.getPcap(linkAH->getFace(nodeA)).sentInterests.at(0);
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000131 BOOST_CHECK_EQUAL(interestAH.getForwardingHint(), DelegationList({delTelia, delUcla}));
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000132
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000133 // H prefers T, no change to forwarding hint
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000134 BOOST_CHECK_EQUAL(linkHT->getFace(nodeH).getCounters().nOutInterests, 1);
135 const Interest& interestHT = topo.getPcap(linkHT->getFace(nodeH)).sentInterests.at(0);
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000136 BOOST_CHECK_EQUAL(interestHT.getForwardingHint(), DelegationList({delTelia, delUcla}));
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000137
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000138 // T forwards to P, forwarding hint stripped when Interest reaches producer region
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000139 BOOST_CHECK_EQUAL(linkTP->getFace(nodeT).getCounters().nOutInterests, 1);
140 const Interest& interestTP = topo.getPcap(linkTP->getFace(nodeT)).sentInterests.at(0);
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000141 BOOST_CHECK(interestTP.getForwardingHint().empty());
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000142
143 // Data is served by P and reaches A
144 BOOST_CHECK_EQUAL(producerP->getForwarderFace().getCounters().nInData, 1);
145 BOOST_CHECK_EQUAL(consumerA->getForwarderFace().getCounters().nOutData, 1);
146}
147
148BOOST_AUTO_TEST_CASE(FetchUcla)
149{
150 // disconnect H-T and delete FIB entry
151 linkHT->fail();
152 topo.getForwarder(nodeH).getFib().erase("/telia");
153
154 this->consumerExpressInterest(1);
Davide Pesavento14e71f02019-03-28 17:35:25 -0400155 this->advanceClocks(11_ms, 20);
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000156
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000157 // A forwards Interest according to default route, no change to forwarding hint
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000158 BOOST_CHECK_EQUAL(linkAH->getFace(nodeA).getCounters().nOutInterests, 1);
159 const Interest& interestAH = topo.getPcap(linkAH->getFace(nodeA)).sentInterests.at(0);
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000160 BOOST_CHECK_EQUAL(interestAH.getForwardingHint(), DelegationList({delTelia, delUcla}));
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000161
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000162 // H forwards to C, no change to forwarding hint
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000163 BOOST_CHECK_EQUAL(linkHC->getFace(nodeH).getCounters().nOutInterests, 1);
164 const Interest& interestHC = topo.getPcap(linkHC->getFace(nodeH)).sentInterests.at(0);
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000165 BOOST_CHECK_EQUAL(interestHC.getForwardingHint(), DelegationList({delTelia, delUcla}));
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000166
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000167 // C forwards to S, no change to forwarding hint
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000168 BOOST_CHECK_EQUAL(linkCS->getFace(nodeC).getCounters().nOutInterests, 1);
169 const Interest& interestCS = topo.getPcap(linkCS->getFace(nodeC)).sentInterests.at(0);
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000170 BOOST_CHECK_EQUAL(interestCS.getForwardingHint(), DelegationList({delTelia, delUcla}));
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000171
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000172 // S forwards to Q, forwarding hint stripped when Interest reaches producer region
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000173 BOOST_CHECK_EQUAL(linkSQ->getFace(nodeS).getCounters().nOutInterests, 1);
174 const Interest& interestSQ = topo.getPcap(linkSQ->getFace(nodeS)).sentInterests.at(0);
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000175 BOOST_CHECK(interestSQ.getForwardingHint().empty());
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000176
177 // Data is served by Q and reaches A
178 BOOST_CHECK_EQUAL(producerQ->getForwarderFace().getCounters().nInData, 1);
179 BOOST_CHECK_EQUAL(consumerA->getForwarderFace().getCounters().nOutData, 1);
180}
181
182BOOST_AUTO_TEST_SUITE_END() // NdnsimTeliaUclaTopology
183
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000184BOOST_AUTO_TEST_SUITE_END() // TestForwardingHint
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000185BOOST_AUTO_TEST_SUITE_END() // Fw
186
187} // namespace tests
188} // namespace fw
189} // namespace nfd