blob: aeff8d83fcd30b2b75a63d5510c2fab20283600d [file] [log] [blame]
Junxiao Shicbba04c2014-01-26 14:21:22 -07001/* -*- 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 Shid3c792f2014-01-30 00:46:13 -070012#include "core/scheduler.hpp"
Junxiao Shicbba04c2014-01-26 14:21:22 -070013
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080014namespace nfd {
HangZhangcb4fc832014-03-11 16:57:11 +080015
16class NameTree;
17
18namespace name_tree {
19class Entry;
20}
21
Junxiao Shicbba04c2014-01-26 14:21:22 -070022namespace pit {
23
24/** \class InRecordCollection
25 * \brief represents an unordered collection of InRecords
26 */
27typedef std::list< InRecord> InRecordCollection;
28
29/** \class OutRecordCollection
30 * \brief represents an unordered collection of OutRecords
31 */
32typedef std::list<OutRecord> OutRecordCollection;
33
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070034/** \brief represents a PIT entry
Junxiao Shicbba04c2014-01-26 14:21:22 -070035 */
Junxiao Shi408a7002014-02-12 17:53:47 -070036class Entry : public StrategyInfoHost, noncopyable
Junxiao Shicbba04c2014-01-26 14:21:22 -070037{
38public:
39 explicit
40 Entry(const Interest& interest);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070041
Junxiao Shicbba04c2014-01-26 14:21:22 -070042 const Interest&
43 getInterest() const;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070044
45 /** \return Interest Name
Junxiao Shicbba04c2014-01-26 14:21:22 -070046 */
47 const Name&
48 getName() const;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070049
Junxiao Shicbba04c2014-01-26 14:21:22 -070050 const InRecordCollection&
51 getInRecords() const;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070052
Junxiao Shicbba04c2014-01-26 14:21:22 -070053 const OutRecordCollection&
54 getOutRecords() const;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070055
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 Shid3c792f2014-01-30 00:46:13 -070064 /** \brief records a nonce
65 *
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070066 * \return true if nonce is new; false if nonce is seen before
Junxiao Shicbba04c2014-01-26 14:21:22 -070067 */
68 bool
Junxiao Shid3c792f2014-01-30 00:46:13 -070069 addNonce(uint32_t nonce);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070070
Junxiao Shicbba04c2014-01-26 14:21:22 -070071 /** \brief inserts a InRecord for face, and updates it with interest
Junxiao Shid3c792f2014-01-30 00:46:13 -070072 *
Junxiao Shicbba04c2014-01-26 14:21:22 -070073 * If InRecord for face exists, the existing one is updated.
Junxiao Shid3c792f2014-01-30 00:46:13 -070074 * This method does not add the Nonce as a seen Nonce.
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070075 * \return an iterator to the InRecord
Junxiao Shicbba04c2014-01-26 14:21:22 -070076 */
77 InRecordCollection::iterator
78 insertOrUpdateInRecord(shared_ptr<Face> face, const Interest& interest);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070079
Junxiao Shicbba04c2014-01-26 14:21:22 -070080 /// deletes all InRecords
81 void
82 deleteInRecords();
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070083
Junxiao Shicbba04c2014-01-26 14:21:22 -070084 /** \brief inserts a OutRecord for face, and updates it with interest
Junxiao Shid3c792f2014-01-30 00:46:13 -070085 *
Junxiao Shicbba04c2014-01-26 14:21:22 -070086 * If OutRecord for face exists, the existing one is updated.
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070087 * \return an iterator to the OutRecord
Junxiao Shicbba04c2014-01-26 14:21:22 -070088 */
89 OutRecordCollection::iterator
90 insertOrUpdateOutRecord(shared_ptr<Face> face, const Interest& interest);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070091
Junxiao Shicbba04c2014-01-26 14:21:22 -070092 /// deletes one OutRecord for face if exists
93 void
94 deleteOutRecord(shared_ptr<Face> face);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070095
Junxiao Shid3c792f2014-01-30 00:46:13 -070096public:
97 EventId m_unsatisfyTimer;
98 EventId m_stragglerTimer;
Junxiao Shicbba04c2014-01-26 14:21:22 -070099
100private:
101 std::set<uint32_t> m_nonces;
102 const Interest m_interest;
103 InRecordCollection m_inRecords;
104 OutRecordCollection m_outRecords;
HangZhangcb4fc832014-03-11 16:57:11 +0800105 shared_ptr<name_tree::Entry> m_nameTreeEntry;
106
107 friend class nfd::NameTree;
108 friend class nfd::name_tree::Entry;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700109};
110
111inline const Interest&
112Entry::getInterest() const
113{
114 return m_interest;
115}
116
117} // namespace pit
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800118} // namespace nfd
Junxiao Shicbba04c2014-01-26 14:21:22 -0700119
120#endif // NFD_TABLE_PIT_ENTRY_HPP