blob: 864d59809503c43e2bce3351c8c51c16d68e5e17 [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
73 topo.getForwarder(nodeA).getNetworkRegionTable().insert("/arizona/cs/avenir");
74 topo.getForwarder(nodeH).getNetworkRegionTable().insert("/arizona/cs/hobo");
75 topo.getForwarder(nodeT).getNetworkRegionTable().insert("/telia/terabits/router");
76 topo.getForwarder(nodeP).getNetworkRegionTable().insert("/telia/terabits/serverP");
77 topo.getForwarder(nodeC).getNetworkRegionTable().insert("/ucsd/caida/click");
78 topo.getForwarder(nodeS).getNetworkRegionTable().insert("/ucla/cs/spurs");
79 topo.getForwarder(nodeQ).getNetworkRegionTable().insert("/ucla/cs/serverQ");
80
81 linkAH = topo.addLink("AH", time::milliseconds(10), {nodeA, nodeH});
82 linkHT = topo.addLink("HT", time::milliseconds(10), {nodeH, nodeT});
83 linkTP = topo.addLink("TP", time::milliseconds(10), {nodeT, nodeP});
84 linkHC = topo.addLink("HC", time::milliseconds(10), {nodeH, nodeC});
85 linkCS = topo.addLink("CS", time::milliseconds(10), {nodeC, nodeS});
86 linkSQ = topo.addLink("SQ", time::milliseconds(10), {nodeS, nodeQ});
87 consumerA = topo.addAppFace("avenir", nodeA);
88 producerP = topo.addAppFace("ndnsimP", nodeP, "/net/ndnsim");
89 producerQ = topo.addAppFace("ndnsimQ", nodeQ, "/net/ndnsim");
90
91 topo.addEchoProducer(producerP->getClientFace());
92 topo.addEchoProducer(producerQ->getClientFace());
93
94 topo.registerPrefix(nodeA, linkAH->getFace(nodeA), "/", 10);
95 topo.registerPrefix(nodeH, linkHT->getFace(nodeH), "/telia", 10);
96 topo.registerPrefix(nodeT, linkTP->getFace(nodeT), "/net/ndnsim", 10);
97 topo.registerPrefix(nodeH, linkHC->getFace(nodeH), "/ucla", 20);
98 topo.registerPrefix(nodeC, linkCS->getFace(nodeC), "/ucla", 10);
99 topo.registerPrefix(nodeS, linkSQ->getFace(nodeS), "/net/ndnsim", 10);
100
101 linkObject = makeLink("/net/ndnsim", {{10, "/telia/terabits"}, {20, "/ucla/cs"}});
102 }
103
104 /** \brief express an Interest with Link object from consumerA
105 */
106 void
107 consumerExpressInterest(int seq)
108 {
109 auto interest = makeInterest(Name("/net/ndnsim").appendNumber(seq));
110 interest->setLink(linkObject->wireEncode());
111 consumerA->getClientFace().expressInterest(*interest, nullptr, nullptr, nullptr);
112 }
113
114public:
115 TopologyTester topo;
116 TopologyNode nodeA, nodeH, nodeT, nodeP, nodeC, nodeS, nodeQ;
117 shared_ptr<TopologyLink> linkAH, linkHT, linkTP, linkHC, linkCS, linkSQ;
118 shared_ptr<TopologyAppLink> consumerA, producerP, producerQ;
119 shared_ptr<Link> linkObject;
120};
121
122BOOST_FIXTURE_TEST_SUITE(NdnsimTeliaUclaTopology, NdnsimTeliaUclaTopologyFixture)
123
124BOOST_AUTO_TEST_CASE(FetchTelia)
125{
126 this->consumerExpressInterest(1);
127 this->advanceClocks(time::milliseconds(11), 20);
128
129 // A forwards Interest according to default route, no change to Link and SelectedDelegation
130 BOOST_CHECK_EQUAL(linkAH->getFace(nodeA).getCounters().nOutInterests, 1);
131 const Interest& interestAH = topo.getPcap(linkAH->getFace(nodeA)).sentInterests.at(0);
132 BOOST_CHECK_EQUAL(interestAH.hasLink(), true);
133 BOOST_CHECK_EQUAL(interestAH.hasSelectedDelegation(), false);
134
135 // H prefers T, and sets SelectedDelegation
136 BOOST_CHECK_EQUAL(linkHT->getFace(nodeH).getCounters().nOutInterests, 1);
137 const Interest& interestHT = topo.getPcap(linkHT->getFace(nodeH)).sentInterests.at(0);
138 BOOST_CHECK_EQUAL(interestHT.hasLink(), true);
139 BOOST_CHECK_EQUAL(interestHT.hasSelectedDelegation(), true);
140 BOOST_CHECK_EQUAL(interestHT.getSelectedDelegation(), "/telia/terabits");
141
142 // T forwards to P, no change to Link and SelectedDelegation
143 BOOST_CHECK_EQUAL(linkTP->getFace(nodeT).getCounters().nOutInterests, 1);
144 const Interest& interestTP = topo.getPcap(linkTP->getFace(nodeT)).sentInterests.at(0);
145 BOOST_CHECK_EQUAL(interestTP.hasLink(), true);
146 BOOST_CHECK_EQUAL(interestTP.hasSelectedDelegation(), true);
147 BOOST_CHECK_EQUAL(interestTP.getSelectedDelegation(), "/telia/terabits");
148
149 // Data is served by P and reaches A
150 BOOST_CHECK_EQUAL(producerP->getForwarderFace().getCounters().nInData, 1);
151 BOOST_CHECK_EQUAL(consumerA->getForwarderFace().getCounters().nOutData, 1);
152}
153
154BOOST_AUTO_TEST_CASE(FetchUcla)
155{
156 // disconnect H-T and delete FIB entry
157 linkHT->fail();
158 topo.getForwarder(nodeH).getFib().erase("/telia");
159
160 this->consumerExpressInterest(1);
161 this->advanceClocks(time::milliseconds(11), 20);
162
163 // A forwards Interest according to default route, no change to Link and SelectedDelegation
164 BOOST_CHECK_EQUAL(linkAH->getFace(nodeA).getCounters().nOutInterests, 1);
165 const Interest& interestAH = topo.getPcap(linkAH->getFace(nodeA)).sentInterests.at(0);
166 BOOST_CHECK_EQUAL(interestAH.hasLink(), true);
167 BOOST_CHECK_EQUAL(interestAH.hasSelectedDelegation(), false);
168
169 // H forwards to C, and sets SelectedDelegation
170 BOOST_CHECK_EQUAL(linkHC->getFace(nodeH).getCounters().nOutInterests, 1);
171 const Interest& interestHC = topo.getPcap(linkHC->getFace(nodeH)).sentInterests.at(0);
172 BOOST_CHECK_EQUAL(interestHC.hasLink(), true);
173 BOOST_CHECK_EQUAL(interestHC.hasSelectedDelegation(), true);
174 BOOST_CHECK_EQUAL(interestHC.getSelectedDelegation(), "/ucla/cs");
175
176 // C forwards to S, no change to Link and SelectedDelegation
177 BOOST_CHECK_EQUAL(linkCS->getFace(nodeC).getCounters().nOutInterests, 1);
178 const Interest& interestCS = topo.getPcap(linkCS->getFace(nodeC)).sentInterests.at(0);
179 BOOST_CHECK_EQUAL(interestCS.hasLink(), true);
180 BOOST_CHECK_EQUAL(interestCS.hasSelectedDelegation(), true);
181 BOOST_CHECK_EQUAL(interestCS.getSelectedDelegation(), "/ucla/cs");
182
183 // S forwards to Q, no change to Link and SelectedDelegation
184 BOOST_CHECK_EQUAL(linkSQ->getFace(nodeS).getCounters().nOutInterests, 1);
185 const Interest& interestSQ = topo.getPcap(linkSQ->getFace(nodeS)).sentInterests.at(0);
186 BOOST_CHECK_EQUAL(interestSQ.hasLink(), true);
187 BOOST_CHECK_EQUAL(interestSQ.hasSelectedDelegation(), true);
188 BOOST_CHECK_EQUAL(interestSQ.getSelectedDelegation(), "/ucla/cs");
189
190 // Data is served by Q and reaches A
191 BOOST_CHECK_EQUAL(producerQ->getForwarderFace().getCounters().nInData, 1);
192 BOOST_CHECK_EQUAL(consumerA->getForwarderFace().getCounters().nOutData, 1);
193}
194
195BOOST_AUTO_TEST_SUITE_END() // NdnsimTeliaUclaTopology
196
197BOOST_AUTO_TEST_SUITE_END() // TestLinkForwarding
198BOOST_AUTO_TEST_SUITE_END() // Fw
199
200} // namespace tests
201} // namespace fw
202} // namespace nfd