blob: 7d0d37de39229cd1022a36378eb23a1d4781a28e [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 Shifab9e0d2017-02-02 06:04:59 +00003 * Copyright (c) 2014-2017, 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 "fw/best-route-strategy2.hpp"
27
28#include "topology-tester.hpp"
29
30namespace nfd {
31namespace fw {
32namespace tests {
33
34using namespace nfd::tests;
35
36BOOST_AUTO_TEST_SUITE(Fw)
Junxiao Shifc2e13d2017-07-25 02:08:48 +000037BOOST_AUTO_TEST_SUITE(TestForwardingHint)
Junxiao Shifab9e0d2017-02-02 06:04:59 +000038
39/**
40 * /arizona/cs/avenir
41 * |
42 * v
43 * /arizona/cs/hobo
44 * | |
45 * v v
46 * /telia/terabits /ucsd/caida/click
47 * | |
48 * v v
49 * /net/ndnsim /ucla/cs/spurs
50 * (serverP) |
51 * v
52 * /net/ndnsim
53 * (serverQ)
54 */
55class NdnsimTeliaUclaTopologyFixture : public UnitTestTimeFixture
56{
57public:
58 NdnsimTeliaUclaTopologyFixture()
59 {
60 topo.enablePcap();
61
62 nodeA = topo.addForwarder("avenir");
63 nodeH = topo.addForwarder("hobo");
64 nodeT = topo.addForwarder("terabits");
65 nodeP = topo.addForwarder("serverP");
66 nodeC = topo.addForwarder("click");
67 nodeS = topo.addForwarder("spurs");
68 nodeQ = topo.addForwarder("serverQ");
69 for (TopologyNode node : {nodeA, nodeH, nodeT, nodeP, nodeC, nodeS, nodeQ}) {
70 topo.setStrategy<BestRouteStrategy2>(node);
71 }
72
Junxiao Shifab9e0d2017-02-02 06:04:59 +000073 topo.getForwarder(nodeH).getNetworkRegionTable().insert("/arizona/cs/hobo");
74 topo.getForwarder(nodeT).getNetworkRegionTable().insert("/telia/terabits/router");
Junxiao Shifab9e0d2017-02-02 06:04:59 +000075 topo.getForwarder(nodeC).getNetworkRegionTable().insert("/ucsd/caida/click");
76 topo.getForwarder(nodeS).getNetworkRegionTable().insert("/ucla/cs/spurs");
Junxiao Shif9858fd2017-02-01 16:22:44 +000077 // NetworkRegionTable configuration is unnecessary on end hosts
Junxiao Shifab9e0d2017-02-02 06:04:59 +000078
79 linkAH = topo.addLink("AH", time::milliseconds(10), {nodeA, nodeH});
80 linkHT = topo.addLink("HT", time::milliseconds(10), {nodeH, nodeT});
81 linkTP = topo.addLink("TP", time::milliseconds(10), {nodeT, nodeP});
82 linkHC = topo.addLink("HC", time::milliseconds(10), {nodeH, nodeC});
83 linkCS = topo.addLink("CS", time::milliseconds(10), {nodeC, nodeS});
84 linkSQ = topo.addLink("SQ", time::milliseconds(10), {nodeS, nodeQ});
85 consumerA = topo.addAppFace("avenir", nodeA);
86 producerP = topo.addAppFace("ndnsimP", nodeP, "/net/ndnsim");
87 producerQ = topo.addAppFace("ndnsimQ", nodeQ, "/net/ndnsim");
88
89 topo.addEchoProducer(producerP->getClientFace());
90 topo.addEchoProducer(producerQ->getClientFace());
91
92 topo.registerPrefix(nodeA, linkAH->getFace(nodeA), "/", 10);
93 topo.registerPrefix(nodeH, linkHT->getFace(nodeH), "/telia", 10);
94 topo.registerPrefix(nodeT, linkTP->getFace(nodeT), "/net/ndnsim", 10);
95 topo.registerPrefix(nodeH, linkHC->getFace(nodeH), "/ucla", 20);
96 topo.registerPrefix(nodeC, linkCS->getFace(nodeC), "/ucla", 10);
97 topo.registerPrefix(nodeS, linkSQ->getFace(nodeS), "/net/ndnsim", 10);
Junxiao Shifab9e0d2017-02-02 06:04:59 +000098 }
99
100 /** \brief express an Interest with Link object from consumerA
101 */
102 void
103 consumerExpressInterest(int seq)
104 {
105 auto interest = makeInterest(Name("/net/ndnsim").appendNumber(seq));
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000106 interest->setForwardingHint({delTelia, delUcla});
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000107 consumerA->getClientFace().expressInterest(*interest, nullptr, nullptr, nullptr);
108 }
109
110public:
111 TopologyTester topo;
112 TopologyNode nodeA, nodeH, nodeT, nodeP, nodeC, nodeS, nodeQ;
113 shared_ptr<TopologyLink> linkAH, linkHT, linkTP, linkHC, linkCS, linkSQ;
114 shared_ptr<TopologyAppLink> consumerA, producerP, producerQ;
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000115
116 Delegation delTelia = {10, "/telia/terabits"};
117 Delegation delUcla = {20, "/ucla/cs"};
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000118};
119
120BOOST_FIXTURE_TEST_SUITE(NdnsimTeliaUclaTopology, NdnsimTeliaUclaTopologyFixture)
121
122BOOST_AUTO_TEST_CASE(FetchTelia)
123{
124 this->consumerExpressInterest(1);
125 this->advanceClocks(time::milliseconds(11), 20);
126
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000127 // A forwards Interest according to default route, no change to forwarding hint
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000128 BOOST_CHECK_EQUAL(linkAH->getFace(nodeA).getCounters().nOutInterests, 1);
129 const Interest& interestAH = topo.getPcap(linkAH->getFace(nodeA)).sentInterests.at(0);
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000130 BOOST_CHECK_EQUAL(interestAH.getForwardingHint(), DelegationList({delTelia, delUcla}));
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000131
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000132 // H prefers T, no change to forwarding hint
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000133 BOOST_CHECK_EQUAL(linkHT->getFace(nodeH).getCounters().nOutInterests, 1);
134 const Interest& interestHT = topo.getPcap(linkHT->getFace(nodeH)).sentInterests.at(0);
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000135 BOOST_CHECK_EQUAL(interestHT.getForwardingHint(), DelegationList({delTelia, delUcla}));
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000136
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000137 // T forwards to P, forwarding hint stripped when Interest reaches producer region
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000138 BOOST_CHECK_EQUAL(linkTP->getFace(nodeT).getCounters().nOutInterests, 1);
139 const Interest& interestTP = topo.getPcap(linkTP->getFace(nodeT)).sentInterests.at(0);
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000140 BOOST_CHECK(interestTP.getForwardingHint().empty());
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000141
142 // Data is served by P and reaches A
143 BOOST_CHECK_EQUAL(producerP->getForwarderFace().getCounters().nInData, 1);
144 BOOST_CHECK_EQUAL(consumerA->getForwarderFace().getCounters().nOutData, 1);
145}
146
147BOOST_AUTO_TEST_CASE(FetchUcla)
148{
149 // disconnect H-T and delete FIB entry
150 linkHT->fail();
151 topo.getForwarder(nodeH).getFib().erase("/telia");
152
153 this->consumerExpressInterest(1);
154 this->advanceClocks(time::milliseconds(11), 20);
155
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000156 // A forwards Interest according to default route, no change to forwarding hint
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000157 BOOST_CHECK_EQUAL(linkAH->getFace(nodeA).getCounters().nOutInterests, 1);
158 const Interest& interestAH = topo.getPcap(linkAH->getFace(nodeA)).sentInterests.at(0);
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000159 BOOST_CHECK_EQUAL(interestAH.getForwardingHint(), DelegationList({delTelia, delUcla}));
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000160
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000161 // H forwards to C, no change to forwarding hint
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000162 BOOST_CHECK_EQUAL(linkHC->getFace(nodeH).getCounters().nOutInterests, 1);
163 const Interest& interestHC = topo.getPcap(linkHC->getFace(nodeH)).sentInterests.at(0);
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000164 BOOST_CHECK_EQUAL(interestHC.getForwardingHint(), DelegationList({delTelia, delUcla}));
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000165
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000166 // C forwards to S, no change to forwarding hint
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000167 BOOST_CHECK_EQUAL(linkCS->getFace(nodeC).getCounters().nOutInterests, 1);
168 const Interest& interestCS = topo.getPcap(linkCS->getFace(nodeC)).sentInterests.at(0);
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000169 BOOST_CHECK_EQUAL(interestCS.getForwardingHint(), DelegationList({delTelia, delUcla}));
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000170
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000171 // S forwards to Q, forwarding hint stripped when Interest reaches producer region
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000172 BOOST_CHECK_EQUAL(linkSQ->getFace(nodeS).getCounters().nOutInterests, 1);
173 const Interest& interestSQ = topo.getPcap(linkSQ->getFace(nodeS)).sentInterests.at(0);
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000174 BOOST_CHECK(interestSQ.getForwardingHint().empty());
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000175
176 // Data is served by Q and reaches A
177 BOOST_CHECK_EQUAL(producerQ->getForwarderFace().getCounters().nInData, 1);
178 BOOST_CHECK_EQUAL(consumerA->getForwarderFace().getCounters().nOutData, 1);
179}
180
181BOOST_AUTO_TEST_SUITE_END() // NdnsimTeliaUclaTopology
182
Junxiao Shifc2e13d2017-07-25 02:08:48 +0000183BOOST_AUTO_TEST_SUITE_END() // TestForwardingHint
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000184BOOST_AUTO_TEST_SUITE_END() // Fw
185
186} // namespace tests
187} // namespace fw
188} // namespace nfd