Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | 1e46be3 | 2015-01-08 20:18:05 -0700 | [diff] [blame^] | 3 | * Copyright (c) 2014-2015, Regents of the University of California, |
| 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
Alexander Afanasyev | 28d586a | 2014-07-10 20:10:54 -0700 | [diff] [blame] | 24 | */ |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 25 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 26 | #ifndef NFD_DAEMON_TABLE_PIT_ENTRY_HPP |
| 27 | #define NFD_DAEMON_TABLE_PIT_ENTRY_HPP |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 28 | |
| 29 | #include "pit-in-record.hpp" |
| 30 | #include "pit-out-record.hpp" |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 31 | #include "core/scheduler.hpp" |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 32 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 33 | namespace nfd { |
HangZhang | cb4fc83 | 2014-03-11 16:57:11 +0800 | [diff] [blame] | 34 | |
| 35 | class NameTree; |
| 36 | |
| 37 | namespace name_tree { |
| 38 | class Entry; |
| 39 | } |
| 40 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 41 | namespace pit { |
| 42 | |
Junxiao Shi | 66f91f8 | 2014-05-10 17:28:58 -0700 | [diff] [blame] | 43 | /** \brief represents an unordered collection of InRecords |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 44 | */ |
| 45 | typedef std::list< InRecord> InRecordCollection; |
| 46 | |
Junxiao Shi | 66f91f8 | 2014-05-10 17:28:58 -0700 | [diff] [blame] | 47 | /** \brief represents an unordered collection of OutRecords |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 48 | */ |
| 49 | typedef std::list<OutRecord> OutRecordCollection; |
| 50 | |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 51 | /** \brief indicates where duplicate Nonces are found |
| 52 | */ |
| 53 | enum DuplicateNonceWhere { |
| 54 | DUPLICATE_NONCE_NONE = 0, |
| 55 | /// in-record of same face |
| 56 | DUPLICATE_NONCE_IN_SAME = (1 << 0), |
| 57 | /// in-record of other face |
| 58 | DUPLICATE_NONCE_IN_OTHER = (1 << 1), |
| 59 | /// out-record of same face |
| 60 | DUPLICATE_NONCE_OUT_SAME = (1 << 2), |
| 61 | /// out-record of other face |
| 62 | DUPLICATE_NONCE_OUT_OTHER = (1 << 3) |
| 63 | }; |
| 64 | |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 65 | /** \brief represents a PIT entry |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 66 | */ |
Junxiao Shi | 408a700 | 2014-02-12 17:53:47 -0700 | [diff] [blame] | 67 | class Entry : public StrategyInfoHost, noncopyable |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 68 | { |
| 69 | public: |
| 70 | explicit |
| 71 | Entry(const Interest& interest); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 72 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 73 | const Interest& |
| 74 | getInterest() const; |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 75 | |
| 76 | /** \return Interest Name |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 77 | */ |
| 78 | const Name& |
| 79 | getName() const; |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 80 | |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 81 | /** \brief decides whether Interest can be forwarded to face |
| 82 | * |
| 83 | * \return true if OutRecord of this face does not exist or has expired, |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 84 | * and there is an InRecord not of this face, |
| 85 | * and scope is not violated |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 86 | */ |
| 87 | bool |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 88 | canForwardTo(const Face& face) const; |
| 89 | |
| 90 | /** \brief decides whether forwarding Interest to face would violate scope |
| 91 | * |
| 92 | * \return true if scope control would be violated |
| 93 | * \note canForwardTo has more comprehensive checks (including scope control) |
| 94 | * and should be used by most strategies. Outgoing Interest pipeline |
| 95 | * should only check scope because some strategy (eg. vehicular) needs |
| 96 | * to retransmit sooner than OutRecord expiry, or forward Interest |
| 97 | * back to incoming face |
| 98 | */ |
| 99 | bool |
| 100 | violatesScope(const Face& face) const; |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 101 | |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 102 | /** \brief finds where a duplicate Nonce appears |
| 103 | * \return OR'ed DuplicateNonceWhere |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 104 | */ |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 105 | int |
| 106 | findNonce(uint32_t nonce, const Face& face) const; |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 107 | |
Junxiao Shi | 66f91f8 | 2014-05-10 17:28:58 -0700 | [diff] [blame] | 108 | public: // InRecord |
| 109 | const InRecordCollection& |
| 110 | getInRecords() const; |
| 111 | |
| 112 | /** \brief determines whether any InRecord is a local Face |
| 113 | * |
| 114 | * \return true if any InRecord is a local Face, |
| 115 | * false if all InRecords are non-local Faces |
| 116 | */ |
| 117 | bool |
| 118 | hasLocalInRecord() const; |
| 119 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 120 | /** \brief inserts a InRecord for face, and updates it with interest |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 121 | * |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 122 | * If InRecord for face exists, the existing one is updated. |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 123 | * This method does not add the Nonce as a seen Nonce. |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 124 | * \return an iterator to the InRecord |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 125 | */ |
| 126 | InRecordCollection::iterator |
| 127 | insertOrUpdateInRecord(shared_ptr<Face> face, const Interest& interest); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 128 | |
Junxiao Shi | 66f91f8 | 2014-05-10 17:28:58 -0700 | [diff] [blame] | 129 | /** \brief get the InRecord for face |
| 130 | * \return an iterator to the InRecord, or .end if it does not exist |
| 131 | */ |
| 132 | InRecordCollection::const_iterator |
Junxiao Shi | b2bcbcd | 2014-11-08 09:30:28 -0700 | [diff] [blame] | 133 | getInRecord(const Face& face) const; |
Junxiao Shi | 66f91f8 | 2014-05-10 17:28:58 -0700 | [diff] [blame] | 134 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 135 | /// deletes all InRecords |
| 136 | void |
| 137 | deleteInRecords(); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 138 | |
Junxiao Shi | 66f91f8 | 2014-05-10 17:28:58 -0700 | [diff] [blame] | 139 | public: // OutRecord |
| 140 | const OutRecordCollection& |
| 141 | getOutRecords() const; |
| 142 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 143 | /** \brief inserts a OutRecord for face, and updates it with interest |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 144 | * |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 145 | * If OutRecord for face exists, the existing one is updated. |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 146 | * \return an iterator to the OutRecord |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 147 | */ |
| 148 | OutRecordCollection::iterator |
| 149 | insertOrUpdateOutRecord(shared_ptr<Face> face, const Interest& interest); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 150 | |
Junxiao Shi | 66f91f8 | 2014-05-10 17:28:58 -0700 | [diff] [blame] | 151 | /** \brief get the OutRecord for face |
| 152 | * \return an iterator to the OutRecord, or .end if it does not exist |
| 153 | */ |
| 154 | OutRecordCollection::const_iterator |
Junxiao Shi | b2bcbcd | 2014-11-08 09:30:28 -0700 | [diff] [blame] | 155 | getOutRecord(const Face& face) const; |
Junxiao Shi | 66f91f8 | 2014-05-10 17:28:58 -0700 | [diff] [blame] | 156 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 157 | /// deletes one OutRecord for face if exists |
| 158 | void |
Junxiao Shi | b2bcbcd | 2014-11-08 09:30:28 -0700 | [diff] [blame] | 159 | deleteOutRecord(const Face& face); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 160 | |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 161 | /** \return true if there is one or more unexpired OutRecords |
| 162 | */ |
| 163 | bool |
| 164 | hasUnexpiredOutRecords() const; |
| 165 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 166 | public: |
Junxiao Shi | 1e46be3 | 2015-01-08 20:18:05 -0700 | [diff] [blame^] | 167 | scheduler::EventId m_unsatisfyTimer; |
| 168 | scheduler::EventId m_stragglerTimer; |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 169 | |
| 170 | private: |
Alexander Afanasyev | 28d586a | 2014-07-10 20:10:54 -0700 | [diff] [blame] | 171 | shared_ptr<const Interest> m_interest; |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 172 | InRecordCollection m_inRecords; |
| 173 | OutRecordCollection m_outRecords; |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 174 | |
| 175 | static const Name LOCALHOST_NAME; |
| 176 | static const Name LOCALHOP_NAME; |
| 177 | |
HangZhang | cb4fc83 | 2014-03-11 16:57:11 +0800 | [diff] [blame] | 178 | shared_ptr<name_tree::Entry> m_nameTreeEntry; |
| 179 | |
| 180 | friend class nfd::NameTree; |
| 181 | friend class nfd::name_tree::Entry; |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 182 | }; |
| 183 | |
| 184 | inline const Interest& |
| 185 | Entry::getInterest() const |
| 186 | { |
Alexander Afanasyev | 28d586a | 2014-07-10 20:10:54 -0700 | [diff] [blame] | 187 | return *m_interest; |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 188 | } |
| 189 | |
Junxiao Shi | b2bcbcd | 2014-11-08 09:30:28 -0700 | [diff] [blame] | 190 | inline const InRecordCollection& |
| 191 | Entry::getInRecords() const |
| 192 | { |
| 193 | return m_inRecords; |
| 194 | } |
| 195 | |
| 196 | inline const OutRecordCollection& |
| 197 | Entry::getOutRecords() const |
| 198 | { |
| 199 | return m_outRecords; |
| 200 | } |
| 201 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 202 | } // namespace pit |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 203 | } // namespace nfd |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 204 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 205 | #endif // NFD_DAEMON_TABLE_PIT_ENTRY_HPP |