blob: bc98f25f1f09969cc4f23f97ad8ccecf68c51b4c [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
54 /*! \brief Inserts an LSA segment into LsaSegmentStorage
55 * \param segmentKey Name of data without the version number.
56 * The format of the key is /router-prefix/LS type/sequence no./segment no.
57 * \param segmentValue The actual data packet.
58 */
59 void
60 insertSegment(const ndn::Name& segmentKey, const ndn::Data& segmentValue);
61
62 /*! \brief Given the key remove the corresponding data packet from LsaSegmentStorage.
63 * \param segmentKey Key of the Data packet that will be deleted.
64 */
65 void
66 deleteSegment(const ndn::Name& segmentKey);
67
68PUBLIC_WITH_TESTS_ELSE_PRIVATE:
69 /*! \brief Callback when SegmentFetcher retrieves a segment.
70 */
71 void
72 afterFetcherSignalEmitted(const ndn::Data& lsaSegment);
73
74private:
75 /*! \brief Given an LSA name check whether Data for the same name exists in the
76 * LsaSegmentStorage. If the matched LSA data are of a lower sequence number,
77 * then remove them from LsaSegmentStorage.
78 * \param newLsaName Name of the LSA that will be matched against
79 */
80 void
81 deleteOldLsas(const ndn::Name& newLsaName);
82
83 /*! \brief Schedules the deletion of a LSA data given the segmentKey
84 */
85 void
86 scheduleLsaSegmentDeletion(const ndn::Name& segmentKey);
87
88
89private:
90 ndn::Scheduler& m_scheduler;
91
92 // Key: /<router-prefix>/<LS type>/<sequence no.>/<segment no.>
93 // Value: corresponding LSA data packet
94 // Data name: /<router-prefix>/<LS type>/<sequence no.>/<version no.>/<segment no.>
95 std::unordered_map<ndn::Name, ndn::Data> m_lsaSegments;
96
97 const ndn::time::seconds m_lsaDeletionTimepoint;
98};
99
100} // namespace nlsr
101
102#endif // NLSR_LSA_SEGMENT_STORAGE_HPP