blob: 468b2fe4e355afa75999a1563f3c8b55931165b7 [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:
39 LsaSegmentStorage(ndn::Scheduler& scheduler,
40 const ndn::time::seconds lsaDeletionTimepoint);
41
42 /*! \brief Get connected to the signal emitted by SegmentFetcher
43 * \param fetcher The SegmentFetcher to whose signal LsaSegmentStorage will subscribe to.
44 */
45 void
46 connectToFetcher(ndn::util::SegmentFetcher& fetcher);
47
48 /*! \brief Returns an LSA segment for an interest from LsaSegmentStorage
49 * \param interest Interest corresponding to the returned LSA segment.
50 */
51 const ndn::Data*
52 getLsaSegment(const ndn::Interest& interest);
53
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +000054PUBLIC_WITH_TESTS_ELSE_PRIVATE:
55 /*! \brief Callback when SegmentFetcher retrieves a segment.
56 */
57 void
58 afterFetcherSignalEmitted(const ndn::Data& lsaSegment);
59
60private:
61 /*! \brief Given an LSA name check whether Data for the same name exists in the
62 * LsaSegmentStorage. If the matched LSA data are of a lower sequence number,
63 * then remove them from LsaSegmentStorage.
64 * \param newLsaName Name of the LSA that will be matched against
65 */
66 void
67 deleteOldLsas(const ndn::Name& newLsaName);
68
69 /*! \brief Schedules the deletion of a LSA data given the segmentKey
70 */
71 void
72 scheduleLsaSegmentDeletion(const ndn::Name& segmentKey);
73
74
75private:
76 ndn::Scheduler& m_scheduler;
77
78 // Key: /<router-prefix>/<LS type>/<sequence no.>/<segment no.>
79 // Value: corresponding LSA data packet
80 // Data name: /<router-prefix>/<LS type>/<sequence no.>/<version no.>/<segment no.>
81 std::unordered_map<ndn::Name, ndn::Data> m_lsaSegments;
82
83 const ndn::time::seconds m_lsaDeletionTimepoint;
84};
85
86} // namespace nlsr
87
Ashlesh Gawande304bebf2018-02-07 17:10:35 -060088#endif // NLSR_LSA_SEGMENT_STORAGE_HPP