Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 2 | /* |
Davide Pesavento | d1f1df8 | 2022-03-12 16:40:37 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2022, The University of Memphis, |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 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/>. |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 20 | */ |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 21 | |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 22 | #include "nlsr.hpp" |
| 23 | |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 24 | #include "tests/io-key-chain-fixture.hpp" |
| 25 | #include "tests/test-common.hpp" |
Junxiao Shi | 008c9b1 | 2019-01-13 23:15:56 +0000 | [diff] [blame] | 26 | |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 27 | namespace nlsr { |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 28 | namespace test { |
| 29 | |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 30 | class AdvertiseCrashFixture : public IoKeyChainFixture |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 31 | { |
| 32 | public: |
| 33 | AdvertiseCrashFixture() |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 34 | : face(m_io, m_keyChain, {true, true}) |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 35 | , conf(face, m_keyChain) |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 36 | , confProcessor(conf) |
| 37 | , nlsr(face, m_keyChain, conf) |
| 38 | , namePrefixList(conf.getNamePrefixList()) |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 39 | { |
| 40 | // Add an adjacency to nlsr |
| 41 | Adjacent adj("/ndn/edu/test-site-2/%C1.Router/test", |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 42 | ndn::FaceUri("udp://1.0.0.2"), 10, Adjacent::STATUS_INACTIVE, 0, 0); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 43 | conf.getAdjacencyList().insert(adj); |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 44 | |
| 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 Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 53 | m_keyChain.createIdentity(conf.getRouterPrefix()); |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 54 | |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 55 | // 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 Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 60 | this->advanceClocks(ndn::time::milliseconds(1), 10); |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 61 | |
| 62 | face.sentInterests.clear(); |
| 63 | } |
| 64 | |
| 65 | public: |
| 66 | ndn::util::DummyClientFace face; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 67 | ConfParameter conf; |
| 68 | DummyConfFileProcessor confProcessor; |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 69 | |
| 70 | Nlsr nlsr; |
| 71 | NamePrefixList& namePrefixList; |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 72 | }; |
| 73 | |
Davide Pesavento | d1f1df8 | 2022-03-12 16:40:37 -0500 | [diff] [blame] | 74 | BOOST_FIXTURE_TEST_SUITE(TestAdvertiseCrash, AdvertiseCrashFixture) |
| 75 | |
| 76 | BOOST_AUTO_TEST_CASE(ReceiveAdvertiseInterest) |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 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 Shi | 008c9b1 | 2019-01-13 23:15:56 +0000 | [diff] [blame] | 85 | parameters.setName("/prefix/to/advertise"); |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 86 | ndn::Name advertiseCommand("/localhost/nlsr/prefix-update/advertise"); |
Davide Pesavento | e28d875 | 2022-03-19 03:55:25 -0400 | [diff] [blame] | 87 | advertiseCommand.append(ndn::tlv::GenericNameComponent, parameters.wireEncode()); |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 88 | |
Junxiao Shi | 008c9b1 | 2019-01-13 23:15:56 +0000 | [diff] [blame] | 89 | auto advertiseInterest = std::make_shared<ndn::Interest>(advertiseCommand); |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 90 | face.receive(*advertiseInterest); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 91 | this->advanceClocks(ndn::time::milliseconds(10), 10); |
Davide Pesavento | d1f1df8 | 2022-03-12 16:40:37 -0500 | [diff] [blame] | 92 | |
| 93 | // avoid "test case [...] did not check any assertions" message from Boost.Test |
| 94 | BOOST_CHECK(true); |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 95 | } |
| 96 | |
Davide Pesavento | d1f1df8 | 2022-03-12 16:40:37 -0500 | [diff] [blame] | 97 | BOOST_AUTO_TEST_SUITE_END() |
| 98 | |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 99 | } // namespace test |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 100 | } // namespace nlsr |