blob: 7f0cad3fb4a124efc8fd4d2d49b8dde4b4216851 [file] [log] [blame]
Ashlesh Gawande793e8702017-08-01 15:59:26 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi008c9b12019-01-13 23:15:56 +00003 * Copyright (c) 2014-2019, The University of Memphis,
Ashlesh Gawande793e8702017-08-01 15:59:26 -05004 * Regents of the University of California,
5 * Arizona Board of Regents.
6 *
7 * This file is part of NLSR (Named-data Link State Routing).
8 * See AUTHORS.md for complete list of NLSR authors and contributors.
9 *
10 * NLSR is free software: you can redistribute it and/or modify it under the terms
11 * of the GNU General Public License as published by the Free Software Foundation,
12 * either version 3 of the License, or (at your option) any later version.
13 *
14 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 * PURPOSE. See the GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
20 **/
21
Ashlesh Gawande793e8702017-08-01 15:59:26 -050022#include "nlsr.hpp"
23
Junxiao Shi008c9b12019-01-13 23:15:56 +000024#include "../test-common.hpp"
25
Ashlesh Gawande793e8702017-08-01 15:59:26 -050026namespace nlsr {
Ashlesh Gawande793e8702017-08-01 15:59:26 -050027namespace test {
28
29class AdvertiseCrashFixture : public nlsr::test::UnitTestTimeFixture
30{
31public:
32 AdvertiseCrashFixture()
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050033 : face(m_ioService, m_keyChain, {true, true})
Ashlesh Gawande85998a12017-12-07 22:22:13 -060034 , conf(face)
35 , confProcessor(conf)
36 , nlsr(face, m_keyChain, conf)
37 , namePrefixList(conf.getNamePrefixList())
Ashlesh Gawande793e8702017-08-01 15:59:26 -050038 {
39 // Add an adjacency to nlsr
40 Adjacent adj("/ndn/edu/test-site-2/%C1.Router/test",
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050041 ndn::FaceUri("udp://1.0.0.2"), 10, Adjacent::STATUS_INACTIVE, 0, 0);
Ashlesh Gawande85998a12017-12-07 22:22:13 -060042 conf.getAdjacencyList().insert(adj);
Ashlesh Gawande793e8702017-08-01 15:59:26 -050043
44 // Create a face dataset response with the face having the same uri as
45 // the adjacent
46 ndn::nfd::FaceStatus payload1;
47 payload1.setFaceId(25401);
48 payload1.setRemoteUri("udp://1.0.0.2");
49
50 std::vector<ndn::nfd::FaceStatus> faces{payload1};
51
Ashlesh Gawande85998a12017-12-07 22:22:13 -060052 addIdentity(conf.getRouterPrefix());
Ashlesh Gawande793e8702017-08-01 15:59:26 -050053
54 // So that NLSR starts listening on prefixes
55 nlsr.initialize();
56
57 // Simulate a callback with fake response
58 // This will trigger the undefined behavior found
59 // in fib.cpp if an operation is done on non-existent faceUri
60 nlsr.processFaceDataset(faces);
61
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050062 this->advanceClocks(ndn::time::milliseconds(1), 10);
Ashlesh Gawande793e8702017-08-01 15:59:26 -050063
64 face.sentInterests.clear();
65 }
66
67public:
68 ndn::util::DummyClientFace face;
Ashlesh Gawande85998a12017-12-07 22:22:13 -060069 ConfParameter conf;
70 DummyConfFileProcessor confProcessor;
Ashlesh Gawande793e8702017-08-01 15:59:26 -050071
72 Nlsr nlsr;
73 NamePrefixList& namePrefixList;
Ashlesh Gawande793e8702017-08-01 15:59:26 -050074};
75
76BOOST_FIXTURE_TEST_CASE(TestAdvertiseCrash, AdvertiseCrashFixture)
77{
78 // Note that this test does not setup any security
79 // and the interest will be rejected by NLSR.
80 // This is because the bug triggers upon merely receiving
81 // an advertise interest so security was not needed.
82
83 // Advertise
84 ndn::nfd::ControlParameters parameters;
Junxiao Shi008c9b12019-01-13 23:15:56 +000085 parameters.setName("/prefix/to/advertise");
Ashlesh Gawande793e8702017-08-01 15:59:26 -050086 ndn::Name advertiseCommand("/localhost/nlsr/prefix-update/advertise");
87 advertiseCommand.append(parameters.wireEncode());
88
Junxiao Shi008c9b12019-01-13 23:15:56 +000089 auto advertiseInterest = std::make_shared<ndn::Interest>(advertiseCommand);
90 advertiseInterest->setCanBePrefix(false);
Ashlesh Gawande793e8702017-08-01 15:59:26 -050091 face.receive(*advertiseInterest);
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050092 this->advanceClocks(ndn::time::milliseconds(10), 10);
Ashlesh Gawande793e8702017-08-01 15:59:26 -050093}
94
95} // namespace test
Ashlesh Gawande793e8702017-08-01 15:59:26 -050096} // namespace nlsr