blob: 8bf1dfb9f60bbaac9201946f3596df52442b271e [file] [log] [blame]
Junxiao Shifab9e0d2017-02-02 06:04:59 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * 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)
37BOOST_AUTO_TEST_SUITE(TestLinkForwarding)
38
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);
98
99 linkObject = makeLink("/net/ndnsim", {{10, "/telia/terabits"}, {20, "/ucla/cs"}});
100 }
101
102 /** \brief express an Interest with Link object from consumerA
103 */
104 void
105 consumerExpressInterest(int seq)
106 {
107 auto interest = makeInterest(Name("/net/ndnsim").appendNumber(seq));
108 interest->setLink(linkObject->wireEncode());
109 consumerA->getClientFace().expressInterest(*interest, nullptr, nullptr, nullptr);
110 }
111
112public:
113 TopologyTester topo;
114 TopologyNode nodeA, nodeH, nodeT, nodeP, nodeC, nodeS, nodeQ;
115 shared_ptr<TopologyLink> linkAH, linkHT, linkTP, linkHC, linkCS, linkSQ;
116 shared_ptr<TopologyAppLink> consumerA, producerP, producerQ;
117 shared_ptr<Link> linkObject;
118};
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
127 // A forwards Interest according to default route, no change to Link and SelectedDelegation
128 BOOST_CHECK_EQUAL(linkAH->getFace(nodeA).getCounters().nOutInterests, 1);
129 const Interest& interestAH = topo.getPcap(linkAH->getFace(nodeA)).sentInterests.at(0);
130 BOOST_CHECK_EQUAL(interestAH.hasLink(), true);
131 BOOST_CHECK_EQUAL(interestAH.hasSelectedDelegation(), false);
132
133 // H prefers T, and sets SelectedDelegation
134 BOOST_CHECK_EQUAL(linkHT->getFace(nodeH).getCounters().nOutInterests, 1);
135 const Interest& interestHT = topo.getPcap(linkHT->getFace(nodeH)).sentInterests.at(0);
136 BOOST_CHECK_EQUAL(interestHT.hasLink(), true);
137 BOOST_CHECK_EQUAL(interestHT.hasSelectedDelegation(), true);
138 BOOST_CHECK_EQUAL(interestHT.getSelectedDelegation(), "/telia/terabits");
139
Junxiao Shif9858fd2017-02-01 16:22:44 +0000140 // T forwards to P, Link and SelectedDelegation are stripped when Interest reaches producer region
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000141 BOOST_CHECK_EQUAL(linkTP->getFace(nodeT).getCounters().nOutInterests, 1);
142 const Interest& interestTP = topo.getPcap(linkTP->getFace(nodeT)).sentInterests.at(0);
Junxiao Shif9858fd2017-02-01 16:22:44 +0000143 BOOST_CHECK_EQUAL(interestTP.hasLink(), false);
144 BOOST_CHECK_EQUAL(interestTP.hasSelectedDelegation(), false);
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000145
146 // Data is served by P and reaches A
147 BOOST_CHECK_EQUAL(producerP->getForwarderFace().getCounters().nInData, 1);
148 BOOST_CHECK_EQUAL(consumerA->getForwarderFace().getCounters().nOutData, 1);
149}
150
151BOOST_AUTO_TEST_CASE(FetchUcla)
152{
153 // disconnect H-T and delete FIB entry
154 linkHT->fail();
155 topo.getForwarder(nodeH).getFib().erase("/telia");
156
157 this->consumerExpressInterest(1);
158 this->advanceClocks(time::milliseconds(11), 20);
159
160 // A forwards Interest according to default route, no change to Link and SelectedDelegation
161 BOOST_CHECK_EQUAL(linkAH->getFace(nodeA).getCounters().nOutInterests, 1);
162 const Interest& interestAH = topo.getPcap(linkAH->getFace(nodeA)).sentInterests.at(0);
163 BOOST_CHECK_EQUAL(interestAH.hasLink(), true);
164 BOOST_CHECK_EQUAL(interestAH.hasSelectedDelegation(), false);
165
166 // H forwards to C, and sets SelectedDelegation
167 BOOST_CHECK_EQUAL(linkHC->getFace(nodeH).getCounters().nOutInterests, 1);
168 const Interest& interestHC = topo.getPcap(linkHC->getFace(nodeH)).sentInterests.at(0);
169 BOOST_CHECK_EQUAL(interestHC.hasLink(), true);
170 BOOST_CHECK_EQUAL(interestHC.hasSelectedDelegation(), true);
171 BOOST_CHECK_EQUAL(interestHC.getSelectedDelegation(), "/ucla/cs");
172
173 // C forwards to S, no change to Link and SelectedDelegation
174 BOOST_CHECK_EQUAL(linkCS->getFace(nodeC).getCounters().nOutInterests, 1);
175 const Interest& interestCS = topo.getPcap(linkCS->getFace(nodeC)).sentInterests.at(0);
176 BOOST_CHECK_EQUAL(interestCS.hasLink(), true);
177 BOOST_CHECK_EQUAL(interestCS.hasSelectedDelegation(), true);
178 BOOST_CHECK_EQUAL(interestCS.getSelectedDelegation(), "/ucla/cs");
179
Junxiao Shif9858fd2017-02-01 16:22:44 +0000180 // S forwards to Q, Link and SelectedDelegation are 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 Shif9858fd2017-02-01 16:22:44 +0000183 BOOST_CHECK_EQUAL(interestSQ.hasLink(), false);
184 BOOST_CHECK_EQUAL(interestSQ.hasSelectedDelegation(), false);
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000185
186 // Data is served by Q and reaches A
187 BOOST_CHECK_EQUAL(producerQ->getForwarderFace().getCounters().nInData, 1);
188 BOOST_CHECK_EQUAL(consumerA->getForwarderFace().getCounters().nOutData, 1);
189}
190
191BOOST_AUTO_TEST_SUITE_END() // NdnsimTeliaUclaTopology
192
193BOOST_AUTO_TEST_SUITE_END() // TestLinkForwarding
194BOOST_AUTO_TEST_SUITE_END() // Fw
195
196} // namespace tests
197} // namespace fw
198} // namespace nfd