Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | 008c9b1 | 2019-01-13 23:15:56 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2019, 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/>. |
| 20 | **/ |
| 21 | |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 22 | #include "nlsr.hpp" |
| 23 | |
Junxiao Shi | 008c9b1 | 2019-01-13 23:15:56 +0000 | [diff] [blame] | 24 | #include "../test-common.hpp" |
| 25 | |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 26 | namespace nlsr { |
| 27 | namespace update { |
| 28 | namespace test { |
| 29 | |
| 30 | class AdvertiseCrashFixture : public nlsr::test::UnitTestTimeFixture |
| 31 | { |
| 32 | public: |
| 33 | AdvertiseCrashFixture() |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 34 | : face(m_ioService, m_keyChain, {true, true}) |
| 35 | , nlsr(m_ioService, m_scheduler, face, m_keyChain) |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 36 | , namePrefixList(nlsr.getNamePrefixList()) |
| 37 | , updatePrefixUpdateProcessor(nlsr.getPrefixUpdateProcessor()) |
| 38 | { |
| 39 | // Add an adjacency to nlsr |
| 40 | Adjacent adj("/ndn/edu/test-site-2/%C1.Router/test", |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 41 | ndn::FaceUri("udp://1.0.0.2"), 10, Adjacent::STATUS_INACTIVE, 0, 0); |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 42 | nlsr.getAdjacencyList().insert(adj); |
| 43 | |
| 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 | |
| 52 | // Set the network so the LSA prefix is constructed |
| 53 | nlsr.getConfParameter().setNetwork("/ndn"); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 54 | nlsr.getConfParameter().setRouterName(ndn::Name("/This/router")); |
| 55 | |
| 56 | addIdentity(ndn::Name("/ndn/This/router")); |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 57 | |
| 58 | // So that NLSR starts listening on prefixes |
| 59 | nlsr.initialize(); |
| 60 | |
| 61 | // Simulate a callback with fake response |
| 62 | // This will trigger the undefined behavior found |
| 63 | // in fib.cpp if an operation is done on non-existent faceUri |
| 64 | nlsr.processFaceDataset(faces); |
| 65 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 66 | this->advanceClocks(ndn::time::milliseconds(1), 10); |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 67 | |
| 68 | face.sentInterests.clear(); |
| 69 | } |
| 70 | |
| 71 | public: |
| 72 | ndn::util::DummyClientFace face; |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 73 | |
| 74 | Nlsr nlsr; |
| 75 | NamePrefixList& namePrefixList; |
| 76 | PrefixUpdateProcessor& updatePrefixUpdateProcessor; |
| 77 | }; |
| 78 | |
| 79 | BOOST_FIXTURE_TEST_CASE(TestAdvertiseCrash, AdvertiseCrashFixture) |
| 80 | { |
| 81 | // Note that this test does not setup any security |
| 82 | // and the interest will be rejected by NLSR. |
| 83 | // This is because the bug triggers upon merely receiving |
| 84 | // an advertise interest so security was not needed. |
| 85 | |
| 86 | // Advertise |
| 87 | ndn::nfd::ControlParameters parameters; |
Junxiao Shi | 008c9b1 | 2019-01-13 23:15:56 +0000 | [diff] [blame] | 88 | parameters.setName("/prefix/to/advertise"); |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 89 | ndn::Name advertiseCommand("/localhost/nlsr/prefix-update/advertise"); |
| 90 | advertiseCommand.append(parameters.wireEncode()); |
| 91 | |
Junxiao Shi | 008c9b1 | 2019-01-13 23:15:56 +0000 | [diff] [blame] | 92 | auto advertiseInterest = std::make_shared<ndn::Interest>(advertiseCommand); |
| 93 | advertiseInterest->setCanBePrefix(false); |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 94 | face.receive(*advertiseInterest); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 95 | this->advanceClocks(ndn::time::milliseconds(10), 10); |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | } // namespace test |
| 99 | } // namespace update |
| 100 | } // namespace nlsr |