blob: d13c93ae0f94e80d8197cbeb4c759317fd913ac1 [file] [log] [blame]
Zhiyi Zhangcea58d52015-08-26 10:19:56 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Zhiyi Zhang19a11d22018-04-12 22:58:20 -07003 * Copyright (c) 2014-2018, Regents of the University of California
Zhiyi Zhangcea58d52015-08-26 10:19:56 -07004 *
Alexander Afanasyev9091d832018-04-18 17:21:08 -04005 * This file is part of NAC (Name-Based Access Control for NDN).
6 * See AUTHORS.md for complete list of NAC authors and contributors.
Zhiyi Zhangcea58d52015-08-26 10:19:56 -07007 *
Alexander Afanasyev9091d832018-04-18 17:21:08 -04008 * NAC is free software: you can redistribute it and/or modify it under the terms
Zhiyi Zhangcea58d52015-08-26 10:19:56 -07009 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
11 *
Alexander Afanasyev9091d832018-04-18 17:21:08 -040012 * NAC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
Zhiyi Zhangcea58d52015-08-26 10:19:56 -070013 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
Alexander Afanasyev9091d832018-04-18 17:21:08 -040017 * NAC, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Zhiyi Zhangcea58d52015-08-26 10:19:56 -070018 *
Zhiyi Zhang19a11d22018-04-12 22:58:20 -070019 * @author Zhiyi Zhang <zhiyi@cs.ucla.edu>
Zhiyi Zhangcea58d52015-08-26 10:19:56 -070020 */
21
Alexander Afanasyev9091d832018-04-18 17:21:08 -040022#ifndef NDN_NAC_SCHEDULE_HPP
23#define NDN_NAC_SCHEDULE_HPP
Zhiyi Zhangcea58d52015-08-26 10:19:56 -070024
25#include "common.hpp"
26#include "repetitive-interval.hpp"
27
28namespace ndn {
Alexander Afanasyev9091d832018-04-18 17:21:08 -040029namespace nac {
Zhiyi Zhangcea58d52015-08-26 10:19:56 -070030
31/**
32 * @brief Schedule is used to manage the time, which contains two sets of RepetitiveIntervals
33 *
34 * whiteIntervalList is used to define the time allowing member's access to data
35 * blackIntervalList is used to define the time not allowing member's access to data
36 */
37class Schedule
38{
39public:
40 Schedule();
41
Alexander Afanasyev9091d832018-04-18 17:21:08 -040042 explicit
43 Schedule(const Block& block);
Zhiyi Zhangcea58d52015-08-26 10:19:56 -070044
45public:
46 template<encoding::Tag TAG>
47 size_t
48 wireEncode(EncodingImpl<TAG>& encoder) const;
49
50 const Block&
51 wireEncode() const;
52
53 void
54 wireDecode(const Block& wire);
55
56 ///@brief Add an RepetitiveInterval @p repetitiveInterval into white list
57 Schedule&
58 addWhiteInterval(const RepetitiveInterval& repetitiveInterval);
59
60 ///@brief Add the RepetitiveInterval into black list
61 Schedule&
62 addBlackInterval(const RepetitiveInterval& repetitiveInterval);
63
64 /**
65 * @brief Get the Interval that covers the @p ts
66 *
67 * Function iterates two repetitive interval sets and find out
68 * the shortest interval that allows group member to have the access to the data
Zhiyi Zhang7cc09fc2015-09-01 13:40:32 -070069 * if there's no interval covering the @p ts, function will return false and
70 * return a negative interval
Zhiyi Zhangcea58d52015-08-26 10:19:56 -070071 */
Zhiyi Zhang7cc09fc2015-09-01 13:40:32 -070072 std::tuple<bool, Interval>
Zhiyi Zhangcea58d52015-08-26 10:19:56 -070073 getCoveringInterval(const TimeStamp& ts) const;
74
75private:
76 std::set<RepetitiveInterval> m_whiteIntervalList;
77 std::set<RepetitiveInterval> m_blackIntervalList;
78
79 mutable Block m_wire;
80};
81
Alexander Afanasyev9091d832018-04-18 17:21:08 -040082} // namespace nac
Zhiyi Zhangcea58d52015-08-26 10:19:56 -070083} // namespace ndn
84
Alexander Afanasyev9091d832018-04-18 17:21:08 -040085#endif // NDN_NAC_SCHEDULE_HPP