blob: 239823c9dfd09aaeb477825947998b34903d0118 [file] [log] [blame]
Junxiao Shifef73e42016-03-29 14:15:05 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2016, 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/pit-algorithm.hpp"
27
28#include "tests/test-common.hpp"
29#include "tests/daemon/face/dummy-face.hpp"
30
31namespace nfd {
32namespace fw {
33namespace tests {
34
35using namespace nfd::tests;
36
37BOOST_AUTO_TEST_SUITE(Fw)
38BOOST_FIXTURE_TEST_SUITE(TestPitAlgorithm, BaseFixture)
39
40class ScopeControlFixture : public BaseFixture
41{
42protected:
43 ScopeControlFixture()
44 : nonLocalFace1(make_shared<DummyFace>("dummy://1", "dummy://1", ndn::nfd::FACE_SCOPE_NON_LOCAL))
45 , nonLocalFace2(make_shared<DummyFace>("dummy://2", "dummy://2", ndn::nfd::FACE_SCOPE_NON_LOCAL))
46 , localFace3(make_shared<DummyFace>("dummy://3", "dummy://3", ndn::nfd::FACE_SCOPE_LOCAL))
47 , localFace4(make_shared<DummyFace>("dummy://4", "dummy://4", ndn::nfd::FACE_SCOPE_LOCAL))
48 {
49 }
50
51protected:
52 shared_ptr<Face> nonLocalFace1;
53 shared_ptr<Face> nonLocalFace2;
54 shared_ptr<Face> localFace3;
55 shared_ptr<Face> localFace4;
56};
57
58BOOST_FIXTURE_TEST_SUITE(ViolatesScope, ScopeControlFixture)
59
60BOOST_AUTO_TEST_CASE(Unrestricted)
61{
62 shared_ptr<Interest> interest = makeInterest("ndn:/ieWRzDsCu");
63 pit::Entry entry(*interest);
64
65 entry.insertOrUpdateInRecord(nonLocalFace1, *interest);
66 BOOST_CHECK_EQUAL(violatesScope(entry, *nonLocalFace2), false);
67 BOOST_CHECK_EQUAL(violatesScope(entry, *localFace4), false);
68}
69
70BOOST_AUTO_TEST_CASE(Localhost)
71{
72 shared_ptr<Interest> interest = makeInterest("ndn:/localhost/5n1LzIt3");
73 pit::Entry entry(*interest);
74
75 entry.insertOrUpdateInRecord(localFace3, *interest);
76 BOOST_CHECK_EQUAL(violatesScope(entry, *nonLocalFace2), true);
77 BOOST_CHECK_EQUAL(violatesScope(entry, *localFace4), false);
78}
79
80BOOST_AUTO_TEST_CASE(LocalhopFromLocal)
81{
82 shared_ptr<Interest> interest = makeInterest("ndn:/localhop/YcIKWCRYJ");
83 pit::Entry entry(*interest);
84
85 entry.insertOrUpdateInRecord(localFace3, *interest);
86 BOOST_CHECK_EQUAL(violatesScope(entry, *nonLocalFace2), false);
87 BOOST_CHECK_EQUAL(violatesScope(entry, *localFace4), false);
88}
89
90BOOST_AUTO_TEST_CASE(LocalhopFromNonLocal)
91{
92 shared_ptr<Interest> interest = makeInterest("ndn:/localhop/x5uFr5IpqY");
93 pit::Entry entry(*interest);
94
95 entry.insertOrUpdateInRecord(nonLocalFace1, *interest);
96 BOOST_CHECK_EQUAL(violatesScope(entry, *nonLocalFace2), true);
97 BOOST_CHECK_EQUAL(violatesScope(entry, *localFace4), false);
98}
99
100BOOST_AUTO_TEST_CASE(LocalhopFromLocalAndNonLocal)
101{
102 shared_ptr<Interest> interest = makeInterest("ndn:/localhop/gNn2MJAXt");
103 pit::Entry entry(*interest);
104
105 entry.insertOrUpdateInRecord(nonLocalFace1, *interest);
106 entry.insertOrUpdateInRecord(localFace3, *interest);
107 BOOST_CHECK_EQUAL(violatesScope(entry, *nonLocalFace2), false);
108 BOOST_CHECK_EQUAL(violatesScope(entry, *localFace4), false);
109}
110
111BOOST_AUTO_TEST_SUITE_END() // ViolatesScope
112
113BOOST_AUTO_TEST_CASE(CanForwardToLegacy)
114{
115 shared_ptr<Interest> interest = makeInterest("ndn:/WDsuBLIMG");
116 pit::Entry entry(*interest);
117
118 auto face1 = make_shared<DummyFace>();
119 auto face2 = make_shared<DummyFace>();
120
121 entry.insertOrUpdateInRecord(face1, *interest);
122 BOOST_CHECK_EQUAL(canForwardToLegacy(entry, *face1), false);
123 BOOST_CHECK_EQUAL(canForwardToLegacy(entry, *face2), true);
124
125 entry.insertOrUpdateInRecord(face2, *interest);
126 BOOST_CHECK_EQUAL(canForwardToLegacy(entry, *face1), true);
127 BOOST_CHECK_EQUAL(canForwardToLegacy(entry, *face2), true);
128
129 entry.insertOrUpdateOutRecord(face1, *interest);
130 BOOST_CHECK_EQUAL(canForwardToLegacy(entry, *face1), false);
131 BOOST_CHECK_EQUAL(canForwardToLegacy(entry, *face2), true);
132}
133
134BOOST_AUTO_TEST_CASE(Nonce)
135{
136 auto face1 = make_shared<DummyFace>();
137 auto face2 = make_shared<DummyFace>();
138
139 shared_ptr<Interest> interest = makeInterest("ndn:/qtCQ7I1c");
140 interest->setNonce(25559);
141
142 pit::Entry entry0(*interest);
143 BOOST_CHECK_EQUAL(findDuplicateNonce(entry0, 25559, *face1), DUPLICATE_NONCE_NONE);
144 BOOST_CHECK_EQUAL(findDuplicateNonce(entry0, 25559, *face2), DUPLICATE_NONCE_NONE);
145 BOOST_CHECK_EQUAL(findDuplicateNonce(entry0, 19004, *face1), DUPLICATE_NONCE_NONE);
146 BOOST_CHECK_EQUAL(findDuplicateNonce(entry0, 19004, *face2), DUPLICATE_NONCE_NONE);
147
148 pit::Entry entry1(*interest);
149 entry1.insertOrUpdateInRecord(face1, *interest);
150 BOOST_CHECK_EQUAL(findDuplicateNonce(entry1, 25559, *face1), DUPLICATE_NONCE_IN_SAME);
151 BOOST_CHECK_EQUAL(findDuplicateNonce(entry1, 25559, *face2), DUPLICATE_NONCE_IN_OTHER);
152 BOOST_CHECK_EQUAL(findDuplicateNonce(entry1, 19004, *face1), DUPLICATE_NONCE_NONE);
153 BOOST_CHECK_EQUAL(findDuplicateNonce(entry1, 19004, *face2), DUPLICATE_NONCE_NONE);
154
155 pit::Entry entry2(*interest);
156 entry2.insertOrUpdateOutRecord(face1, *interest);
157 BOOST_CHECK_EQUAL(findDuplicateNonce(entry2, 25559, *face1), DUPLICATE_NONCE_OUT_SAME);
158 BOOST_CHECK_EQUAL(findDuplicateNonce(entry2, 25559, *face2), DUPLICATE_NONCE_OUT_OTHER);
159 BOOST_CHECK_EQUAL(findDuplicateNonce(entry2, 19004, *face1), DUPLICATE_NONCE_NONE);
160 BOOST_CHECK_EQUAL(findDuplicateNonce(entry2, 19004, *face2), DUPLICATE_NONCE_NONE);
161
162 pit::Entry entry3(*interest);
163 entry3.insertOrUpdateInRecord(face1, *interest);
164 entry3.insertOrUpdateOutRecord(face1, *interest);
165 BOOST_CHECK_EQUAL(findDuplicateNonce(entry3, 25559, *face1),
166 DUPLICATE_NONCE_IN_SAME | DUPLICATE_NONCE_OUT_SAME);
167 BOOST_CHECK_EQUAL(findDuplicateNonce(entry3, 25559, *face2),
168 DUPLICATE_NONCE_IN_OTHER | DUPLICATE_NONCE_OUT_OTHER);
169 BOOST_CHECK_EQUAL(findDuplicateNonce(entry3, 19004, *face1), DUPLICATE_NONCE_NONE);
170 BOOST_CHECK_EQUAL(findDuplicateNonce(entry3, 19004, *face2), DUPLICATE_NONCE_NONE);
171
172 pit::Entry entry4(*interest);
173 entry4.insertOrUpdateInRecord(face1, *interest);
174 entry4.insertOrUpdateInRecord(face2, *interest);
175 BOOST_CHECK_EQUAL(findDuplicateNonce(entry4, 25559, *face1),
176 DUPLICATE_NONCE_IN_SAME | DUPLICATE_NONCE_IN_OTHER);
177 BOOST_CHECK_EQUAL(findDuplicateNonce(entry4, 25559, *face2),
178 DUPLICATE_NONCE_IN_SAME | DUPLICATE_NONCE_IN_OTHER);
179 BOOST_CHECK_EQUAL(findDuplicateNonce(entry4, 19004, *face1), DUPLICATE_NONCE_NONE);
180 BOOST_CHECK_EQUAL(findDuplicateNonce(entry4, 19004, *face2), DUPLICATE_NONCE_NONE);
181
182 pit::Entry entry5(*interest);
183 entry5.insertOrUpdateOutRecord(face1, *interest);
184 entry5.insertOrUpdateOutRecord(face2, *interest);
185 BOOST_CHECK_EQUAL(findDuplicateNonce(entry5, 25559, *face1),
186 DUPLICATE_NONCE_OUT_SAME | DUPLICATE_NONCE_OUT_OTHER);
187 BOOST_CHECK_EQUAL(findDuplicateNonce(entry5, 25559, *face2),
188 DUPLICATE_NONCE_OUT_SAME | DUPLICATE_NONCE_OUT_OTHER);
189 BOOST_CHECK_EQUAL(findDuplicateNonce(entry5, 19004, *face1), DUPLICATE_NONCE_NONE);
190 BOOST_CHECK_EQUAL(findDuplicateNonce(entry5, 19004, *face2), DUPLICATE_NONCE_NONE);
191}
192
193BOOST_AUTO_TEST_CASE(HasPendingOutRecords)
194{
195 /// \todo #3545
196}
197
198BOOST_AUTO_TEST_SUITE_END() // TestPitAlgorithm
199BOOST_AUTO_TEST_SUITE_END() // Fw
200
201} // namespace tests
202} // namespace fw
203} // namespace nfd