blob: c9cfdac09e2080885541cbf9d8c4477daf8af774 [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 {
Junxiao Shicbba04c2014-01-26 14:21:22 -070015namespace pit {
16
17/** \class InRecordCollection
18 * \brief represents an unordered collection of InRecords
19 */
20typedef std::list< InRecord> InRecordCollection;
21
22/** \class OutRecordCollection
23 * \brief represents an unordered collection of OutRecords
24 */
25typedef std::list<OutRecord> OutRecordCollection;
26
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070027/** \brief represents a PIT entry
Junxiao Shicbba04c2014-01-26 14:21:22 -070028 */
Junxiao Shi408a7002014-02-12 17:53:47 -070029class Entry : public StrategyInfoHost, noncopyable
Junxiao Shicbba04c2014-01-26 14:21:22 -070030{
31public:
32 explicit
33 Entry(const Interest& interest);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070034
Junxiao Shicbba04c2014-01-26 14:21:22 -070035 const Interest&
36 getInterest() const;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070037
38 /** \return Interest Name
Junxiao Shicbba04c2014-01-26 14:21:22 -070039 */
40 const Name&
41 getName() const;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070042
Junxiao Shicbba04c2014-01-26 14:21:22 -070043 const InRecordCollection&
44 getInRecords() const;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070045
Junxiao Shicbba04c2014-01-26 14:21:22 -070046 const OutRecordCollection&
47 getOutRecords() const;
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070048
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 Shid3c792f2014-01-30 00:46:13 -070057 /** \brief records a nonce
58 *
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070059 * \return true if nonce is new; false if nonce is seen before
Junxiao Shicbba04c2014-01-26 14:21:22 -070060 */
61 bool
Junxiao Shid3c792f2014-01-30 00:46:13 -070062 addNonce(uint32_t nonce);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070063
Junxiao Shicbba04c2014-01-26 14:21:22 -070064 /** \brief inserts a InRecord for face, and updates it with interest
Junxiao Shid3c792f2014-01-30 00:46:13 -070065 *
Junxiao Shicbba04c2014-01-26 14:21:22 -070066 * If InRecord for face exists, the existing one is updated.
Junxiao Shid3c792f2014-01-30 00:46:13 -070067 * This method does not add the Nonce as a seen Nonce.
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070068 * \return an iterator to the InRecord
Junxiao Shicbba04c2014-01-26 14:21:22 -070069 */
70 InRecordCollection::iterator
71 insertOrUpdateInRecord(shared_ptr<Face> face, const Interest& interest);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070072
Junxiao Shicbba04c2014-01-26 14:21:22 -070073 /// deletes all InRecords
74 void
75 deleteInRecords();
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070076
Junxiao Shicbba04c2014-01-26 14:21:22 -070077 /** \brief inserts a OutRecord for face, and updates it with interest
Junxiao Shid3c792f2014-01-30 00:46:13 -070078 *
Junxiao Shicbba04c2014-01-26 14:21:22 -070079 * If OutRecord for face exists, the existing one is updated.
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070080 * \return an iterator to the OutRecord
Junxiao Shicbba04c2014-01-26 14:21:22 -070081 */
82 OutRecordCollection::iterator
83 insertOrUpdateOutRecord(shared_ptr<Face> face, const Interest& interest);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070084
Junxiao Shicbba04c2014-01-26 14:21:22 -070085 /// deletes one OutRecord for face if exists
86 void
87 deleteOutRecord(shared_ptr<Face> face);
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070088
Junxiao Shid3c792f2014-01-30 00:46:13 -070089public:
90 EventId m_unsatisfyTimer;
91 EventId m_stragglerTimer;
Junxiao Shicbba04c2014-01-26 14:21:22 -070092
93private:
94 std::set<uint32_t> m_nonces;
95 const Interest m_interest;
96 InRecordCollection m_inRecords;
97 OutRecordCollection m_outRecords;
98};
99
100inline const Interest&
101Entry::getInterest() const
102{
103 return m_interest;
104}
105
106} // namespace pit
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800107} // namespace nfd
Junxiao Shicbba04c2014-01-26 14:21:22 -0700108
109#endif // NFD_TABLE_PIT_ENTRY_HPP