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 { |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 15 | namespace pit { |
| 16 | |
| 17 | /** \class InRecordCollection |
| 18 | * \brief represents an unordered collection of InRecords |
| 19 | */ |
| 20 | typedef std::list< InRecord> InRecordCollection; |
| 21 | |
| 22 | /** \class OutRecordCollection |
| 23 | * \brief represents an unordered collection of OutRecords |
| 24 | */ |
| 25 | typedef std::list<OutRecord> OutRecordCollection; |
| 26 | |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame^] | 27 | /** \brief represents a PIT entry |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 28 | */ |
Junxiao Shi | 408a700 | 2014-02-12 17:53:47 -0700 | [diff] [blame] | 29 | class Entry : public StrategyInfoHost, noncopyable |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 30 | { |
| 31 | public: |
| 32 | explicit |
| 33 | Entry(const Interest& interest); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame^] | 34 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 35 | const Interest& |
| 36 | getInterest() const; |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame^] | 37 | |
| 38 | /** \return Interest Name |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 39 | */ |
| 40 | const Name& |
| 41 | getName() const; |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame^] | 42 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 43 | const InRecordCollection& |
| 44 | getInRecords() const; |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame^] | 45 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 46 | const OutRecordCollection& |
| 47 | getOutRecords() const; |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame^] | 48 | |
| 49 | /** \brief decides whether Interest can be forwarded to face |
| 50 | * |
| 51 | * \return true if OutRecord of this face does not exist or has expired, |
| 52 | * and there is an InRecord not of this face |
| 53 | */ |
| 54 | bool |
| 55 | canForwardTo(shared_ptr<Face> face) const; |
| 56 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 57 | /** \brief records a nonce |
| 58 | * |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame^] | 59 | * \return true if nonce is new; false if nonce is seen before |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 60 | */ |
| 61 | bool |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 62 | addNonce(uint32_t nonce); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame^] | 63 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 64 | /** \brief inserts a InRecord for face, and updates it with interest |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 65 | * |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 66 | * If InRecord for face exists, the existing one is updated. |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 67 | * This method does not add the Nonce as a seen Nonce. |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame^] | 68 | * \return an iterator to the InRecord |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 69 | */ |
| 70 | InRecordCollection::iterator |
| 71 | insertOrUpdateInRecord(shared_ptr<Face> face, 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 | /// deletes all InRecords |
| 74 | void |
| 75 | deleteInRecords(); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame^] | 76 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 77 | /** \brief inserts a OutRecord for face, and updates it with interest |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 78 | * |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 79 | * If OutRecord for face exists, the existing one is updated. |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame^] | 80 | * \return an iterator to the OutRecord |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 81 | */ |
| 82 | OutRecordCollection::iterator |
| 83 | insertOrUpdateOutRecord(shared_ptr<Face> face, const Interest& interest); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame^] | 84 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 85 | /// deletes one OutRecord for face if exists |
| 86 | void |
| 87 | deleteOutRecord(shared_ptr<Face> face); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame^] | 88 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 89 | public: |
| 90 | EventId m_unsatisfyTimer; |
| 91 | EventId m_stragglerTimer; |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 92 | |
| 93 | private: |
| 94 | std::set<uint32_t> m_nonces; |
| 95 | const Interest m_interest; |
| 96 | InRecordCollection m_inRecords; |
| 97 | OutRecordCollection m_outRecords; |
| 98 | }; |
| 99 | |
| 100 | inline const Interest& |
| 101 | Entry::getInterest() const |
| 102 | { |
| 103 | return m_interest; |
| 104 | } |
| 105 | |
| 106 | } // namespace pit |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 107 | } // namespace nfd |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 108 | |
| 109 | #endif // NFD_TABLE_PIT_ENTRY_HPP |