blob: 23f6e61814b83e30a26b221655a0f6401f2c6cad [file] [log] [blame]
Ashlesh Gawande793e8702017-08-01 15:59:26 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -07002/*
Junxiao Shi43f37a02023-08-09 00:09:00 +00003 * Copyright (c) 2014-2023, 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/>.
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -070020 */
Ashlesh Gawande793e8702017-08-01 15:59:26 -050021
Ashlesh Gawande793e8702017-08-01 15:59:26 -050022#include "nlsr.hpp"
23
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040024#include "tests/io-key-chain-fixture.hpp"
25#include "tests/test-common.hpp"
Junxiao Shi008c9b12019-01-13 23:15:56 +000026
Ashlesh Gawande793e8702017-08-01 15:59:26 -050027namespace nlsr {
Ashlesh Gawande793e8702017-08-01 15:59:26 -050028namespace test {
29
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040030class AdvertiseCrashFixture : public IoKeyChainFixture
Ashlesh Gawande793e8702017-08-01 15:59:26 -050031{
32public:
33 AdvertiseCrashFixture()
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040034 : face(m_io, m_keyChain, {true, true})
Saurab Dulal427e0122019-11-28 11:58:02 -060035 , conf(face, m_keyChain)
Ashlesh Gawande85998a12017-12-07 22:22:13 -060036 , confProcessor(conf)
37 , nlsr(face, m_keyChain, conf)
38 , namePrefixList(conf.getNamePrefixList())
Ashlesh Gawande793e8702017-08-01 15:59:26 -050039 {
40 // Add an adjacency to nlsr
41 Adjacent adj("/ndn/edu/test-site-2/%C1.Router/test",
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050042 ndn::FaceUri("udp://1.0.0.2"), 10, Adjacent::STATUS_INACTIVE, 0, 0);
Ashlesh Gawande85998a12017-12-07 22:22:13 -060043 conf.getAdjacencyList().insert(adj);
Ashlesh Gawande793e8702017-08-01 15:59:26 -050044
45 // Create a face dataset response with the face having the same uri as
46 // the adjacent
47 ndn::nfd::FaceStatus payload1;
48 payload1.setFaceId(25401);
49 payload1.setRemoteUri("udp://1.0.0.2");
50
51 std::vector<ndn::nfd::FaceStatus> faces{payload1};
52
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040053 m_keyChain.createIdentity(conf.getRouterPrefix());
Ashlesh Gawande793e8702017-08-01 15:59:26 -050054
Ashlesh Gawande793e8702017-08-01 15:59:26 -050055 // Simulate a callback with fake response
56 // This will trigger the undefined behavior found
57 // in fib.cpp if an operation is done on non-existent faceUri
58 nlsr.processFaceDataset(faces);
59
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050060 this->advanceClocks(ndn::time::milliseconds(1), 10);
Ashlesh Gawande793e8702017-08-01 15:59:26 -050061
62 face.sentInterests.clear();
63 }
64
65public:
Junxiao Shi43f37a02023-08-09 00:09:00 +000066 ndn::DummyClientFace face;
Ashlesh Gawande85998a12017-12-07 22:22:13 -060067 ConfParameter conf;
68 DummyConfFileProcessor confProcessor;
Ashlesh Gawande793e8702017-08-01 15:59:26 -050069
70 Nlsr nlsr;
71 NamePrefixList& namePrefixList;
Ashlesh Gawande793e8702017-08-01 15:59:26 -050072};
73
Davide Pesaventod1f1df82022-03-12 16:40:37 -050074BOOST_FIXTURE_TEST_SUITE(TestAdvertiseCrash, AdvertiseCrashFixture)
75
76BOOST_AUTO_TEST_CASE(ReceiveAdvertiseInterest)
Ashlesh Gawande793e8702017-08-01 15:59:26 -050077{
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");
Davide Pesaventoe28d8752022-03-19 03:55:25 -040087 advertiseCommand.append(ndn::tlv::GenericNameComponent, parameters.wireEncode());
Ashlesh Gawande793e8702017-08-01 15:59:26 -050088
Junxiao Shi008c9b12019-01-13 23:15:56 +000089 auto advertiseInterest = std::make_shared<ndn::Interest>(advertiseCommand);
Ashlesh Gawande793e8702017-08-01 15:59:26 -050090 face.receive(*advertiseInterest);
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050091 this->advanceClocks(ndn::time::milliseconds(10), 10);
Davide Pesaventod1f1df82022-03-12 16:40:37 -050092
93 // avoid "test case [...] did not check any assertions" message from Boost.Test
94 BOOST_CHECK(true);
Ashlesh Gawande793e8702017-08-01 15:59:26 -050095}
96
Davide Pesaventod1f1df82022-03-12 16:40:37 -050097BOOST_AUTO_TEST_SUITE_END()
98
Ashlesh Gawande793e8702017-08-01 15:59:26 -050099} // namespace test
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500100} // namespace nlsr