blob: db9dfe6e9647cd007b905bc5525b3ebfc931e6b1 [file] [log] [blame]
Ashlesh Gawande793e8702017-08-01 15:59:26 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2017, The University of Memphis,
4 * 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
22#include "../test-common.hpp"
23#include "nlsr.hpp"
24
25namespace nlsr {
26namespace update {
27namespace 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})
34 , nlsr(m_ioService, m_scheduler, face, m_keyChain)
Ashlesh Gawande793e8702017-08-01 15:59:26 -050035 , namePrefixList(nlsr.getNamePrefixList())
36 , updatePrefixUpdateProcessor(nlsr.getPrefixUpdateProcessor())
37 {
38 // Add an adjacency to nlsr
39 Adjacent adj("/ndn/edu/test-site-2/%C1.Router/test",
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050040 ndn::FaceUri("udp://1.0.0.2"), 10, Adjacent::STATUS_INACTIVE, 0, 0);
Ashlesh Gawande793e8702017-08-01 15:59:26 -050041 nlsr.getAdjacencyList().insert(adj);
42
43 // Create a face dataset response with the face having the same uri as
44 // the adjacent
45 ndn::nfd::FaceStatus payload1;
46 payload1.setFaceId(25401);
47 payload1.setRemoteUri("udp://1.0.0.2");
48
49 std::vector<ndn::nfd::FaceStatus> faces{payload1};
50
51 // Set the network so the LSA prefix is constructed
52 nlsr.getConfParameter().setNetwork("/ndn");
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050053 nlsr.getConfParameter().setRouterName(ndn::Name("/This/router"));
54
55 addIdentity(ndn::Name("/ndn/This/router"));
Ashlesh Gawande793e8702017-08-01 15:59:26 -050056
57 // So that NLSR starts listening on prefixes
58 nlsr.initialize();
59
60 // Simulate a callback with fake response
61 // This will trigger the undefined behavior found
62 // in fib.cpp if an operation is done on non-existent faceUri
63 nlsr.processFaceDataset(faces);
64
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050065 this->advanceClocks(ndn::time::milliseconds(1), 10);
Ashlesh Gawande793e8702017-08-01 15:59:26 -050066
67 face.sentInterests.clear();
68 }
69
70public:
71 ndn::util::DummyClientFace face;
Ashlesh Gawande793e8702017-08-01 15:59:26 -050072
73 Nlsr nlsr;
74 NamePrefixList& namePrefixList;
75 PrefixUpdateProcessor& updatePrefixUpdateProcessor;
76};
77
78BOOST_FIXTURE_TEST_CASE(TestAdvertiseCrash, AdvertiseCrashFixture)
79{
80 // Note that this test does not setup any security
81 // and the interest will be rejected by NLSR.
82 // This is because the bug triggers upon merely receiving
83 // an advertise interest so security was not needed.
84
85 // Advertise
86 ndn::nfd::ControlParameters parameters;
87 parameters.setName("/prefix/to/advertise/");
88 ndn::Name advertiseCommand("/localhost/nlsr/prefix-update/advertise");
89 advertiseCommand.append(parameters.wireEncode());
90
91 std::shared_ptr<ndn::Interest> advertiseInterest = std::make_shared<ndn::Interest>(advertiseCommand);
92
93 face.receive(*advertiseInterest);
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050094 this->advanceClocks(ndn::time::milliseconds(10), 10);
Ashlesh Gawande793e8702017-08-01 15:59:26 -050095}
96
97} // namespace test
98} // namespace update
99} // namespace nlsr