Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2014 Named Data Networking Project |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #ifndef NFD_TABLE_PIT_ENTRY_HPP |
| 8 | #define NFD_TABLE_PIT_ENTRY_HPP |
| 9 | |
| 10 | #include "pit-in-record.hpp" |
| 11 | #include "pit-out-record.hpp" |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 12 | #include "core/scheduler.hpp" |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 13 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 14 | namespace nfd { |
HangZhang | cb4fc83 | 2014-03-11 16:57:11 +0800 | [diff] [blame] | 15 | |
| 16 | class NameTree; |
| 17 | |
| 18 | namespace name_tree { |
| 19 | class Entry; |
| 20 | } |
| 21 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 22 | namespace pit { |
| 23 | |
| 24 | /** \class InRecordCollection |
| 25 | * \brief represents an unordered collection of InRecords |
| 26 | */ |
| 27 | typedef std::list< InRecord> InRecordCollection; |
| 28 | |
| 29 | /** \class OutRecordCollection |
| 30 | * \brief represents an unordered collection of OutRecords |
| 31 | */ |
| 32 | typedef std::list<OutRecord> OutRecordCollection; |
| 33 | |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 34 | /** \brief represents a PIT entry |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 35 | */ |
Junxiao Shi | 408a700 | 2014-02-12 17:53:47 -0700 | [diff] [blame] | 36 | class Entry : public StrategyInfoHost, noncopyable |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 37 | { |
| 38 | public: |
| 39 | explicit |
| 40 | Entry(const Interest& interest); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 41 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 42 | const Interest& |
| 43 | getInterest() const; |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 44 | |
| 45 | /** \return Interest Name |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 46 | */ |
| 47 | const Name& |
| 48 | getName() const; |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 49 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 50 | const InRecordCollection& |
| 51 | getInRecords() const; |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 52 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 53 | const OutRecordCollection& |
| 54 | getOutRecords() const; |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 55 | |
| 56 | /** \brief decides whether Interest can be forwarded to face |
| 57 | * |
| 58 | * \return true if OutRecord of this face does not exist or has expired, |
| 59 | * and there is an InRecord not of this face |
| 60 | */ |
| 61 | bool |
| 62 | canForwardTo(shared_ptr<Face> face) const; |
| 63 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 64 | /** \brief records a nonce |
| 65 | * |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 66 | * \return true if nonce is new; false if nonce is seen before |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 67 | */ |
| 68 | bool |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 69 | addNonce(uint32_t nonce); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 70 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 71 | /** \brief inserts a InRecord for face, and updates it with interest |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 72 | * |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 73 | * If InRecord for face exists, the existing one is updated. |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 74 | * This method does not add the Nonce as a seen Nonce. |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 75 | * \return an iterator to the InRecord |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 76 | */ |
| 77 | InRecordCollection::iterator |
| 78 | insertOrUpdateInRecord(shared_ptr<Face> face, const Interest& interest); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 79 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 80 | /// deletes all InRecords |
| 81 | void |
| 82 | deleteInRecords(); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 83 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 84 | /** \brief inserts a OutRecord for face, and updates it with interest |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 85 | * |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 86 | * If OutRecord for face exists, the existing one is updated. |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 87 | * \return an iterator to the OutRecord |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 88 | */ |
| 89 | OutRecordCollection::iterator |
| 90 | insertOrUpdateOutRecord(shared_ptr<Face> face, const Interest& interest); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 91 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 92 | /// deletes one OutRecord for face if exists |
| 93 | void |
| 94 | deleteOutRecord(shared_ptr<Face> face); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 95 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 96 | public: |
| 97 | EventId m_unsatisfyTimer; |
| 98 | EventId m_stragglerTimer; |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 99 | |
| 100 | private: |
| 101 | std::set<uint32_t> m_nonces; |
| 102 | const Interest m_interest; |
| 103 | InRecordCollection m_inRecords; |
| 104 | OutRecordCollection m_outRecords; |
HangZhang | cb4fc83 | 2014-03-11 16:57:11 +0800 | [diff] [blame] | 105 | shared_ptr<name_tree::Entry> m_nameTreeEntry; |
| 106 | |
| 107 | friend class nfd::NameTree; |
| 108 | friend class nfd::name_tree::Entry; |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 109 | }; |
| 110 | |
| 111 | inline const Interest& |
| 112 | Entry::getInterest() const |
| 113 | { |
| 114 | return m_interest; |
| 115 | } |
| 116 | |
| 117 | } // namespace pit |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 118 | } // namespace nfd |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 119 | |
| 120 | #endif // NFD_TABLE_PIT_ENTRY_HPP |