blob: 474f4229f82daf25c7b7cc8bad83a10c09bad33a [file] [log] [blame]
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2018, 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#ifndef NLSR_LSA_SEGMENT_STORAGE_HPP
23#define NLSR_LSA_SEGMENT_STORAGE_HPP
24
25#include "test-access-control.hpp"
26
27#include <ndn-cxx/util/segment-fetcher.hpp>
28#include <ndn-cxx/util/signal.hpp>
29#include <ndn-cxx/util/time.hpp>
30
31#include <vector>
32#include <tuple>
33
34namespace nlsr {
35
36class LsaSegmentStorage
37{
38public:
Ashlesh Gawande8c6d8c82018-02-28 21:41:31 -060039 LsaSegmentStorage(ndn::Scheduler& scheduler);
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +000040
41 /*! \brief Get connected to the signal emitted by SegmentFetcher
42 * \param fetcher The SegmentFetcher to whose signal LsaSegmentStorage will subscribe to.
43 */
44 void
45 connectToFetcher(ndn::util::SegmentFetcher& fetcher);
46
47 /*! \brief Returns an LSA segment for an interest from LsaSegmentStorage
48 * \param interest Interest corresponding to the returned LSA segment.
49 */
50 const ndn::Data*
51 getLsaSegment(const ndn::Interest& interest);
52
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +000053PUBLIC_WITH_TESTS_ELSE_PRIVATE:
54 /*! \brief Callback when SegmentFetcher retrieves a segment.
55 */
56 void
57 afterFetcherSignalEmitted(const ndn::Data& lsaSegment);
58
59private:
60 /*! \brief Given an LSA name check whether Data for the same name exists in the
61 * LsaSegmentStorage. If the matched LSA data are of a lower sequence number,
62 * then remove them from LsaSegmentStorage.
63 * \param newLsaName Name of the LSA that will be matched against
64 */
65 void
66 deleteOldLsas(const ndn::Name& newLsaName);
67
68 /*! \brief Schedules the deletion of a LSA data given the segmentKey
69 */
70 void
Ashlesh Gawande8c6d8c82018-02-28 21:41:31 -060071 scheduleLsaSegmentDeletion(const ndn::Name& segmentKey, ndn::time::seconds expirationTime);
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +000072
73
74private:
75 ndn::Scheduler& m_scheduler;
76
77 // Key: /<router-prefix>/<LS type>/<sequence no.>/<segment no.>
78 // Value: corresponding LSA data packet
79 // Data name: /<router-prefix>/<LS type>/<sequence no.>/<version no.>/<segment no.>
80 std::unordered_map<ndn::Name, ndn::Data> m_lsaSegments;
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +000081};
82
83} // namespace nlsr
84
Ashlesh Gawande304bebf2018-02-07 17:10:35 -060085#endif // NLSR_LSA_SEGMENT_STORAGE_HPP