blob: 027acdf9656cb44ac78dee16dd6141b5214ce233 [file] [log] [blame]
Junxiao Shid3c792f2014-01-30 00:46:13 -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_FW_STRATEGY_HPP
8#define NFD_FW_STRATEGY_HPP
9
Junxiao Shi8c8d2182014-01-30 22:33:00 -070010#include "face/face.hpp"
Junxiao Shid3c792f2014-01-30 00:46:13 -070011
12namespace nfd {
13
Junxiao Shi8c8d2182014-01-30 22:33:00 -070014class Forwarder;
15namespace fib {
16class Entry;
17}
18namespace pit {
19class Entry;
20}
21
22namespace fw {
23
Junxiao Shid3c792f2014-01-30 00:46:13 -070024/** \class Strategy
25 * \brief represents a forwarding strategy
26 */
27class Strategy
28{
29public:
30 explicit
Junxiao Shi8c8d2182014-01-30 22:33:00 -070031 Strategy(Forwarder& forwarder);
Junxiao Shid3c792f2014-01-30 00:46:13 -070032
33 virtual
34 ~Strategy();
35
Junxiao Shi679e9272014-02-15 20:10:21 -070036public: // triggers
37 /** \brief trigger after Interest is received
38 *
39 * The Interest:
40 * - does not violate Scope
41 * - is not looped
42 * - cannot be satisfied by ContentStore
43 * - is under a namespace managed by this strategy
44 *
45 * The strategy should decide whether and where to forward this Interest.
46 * - If the strategy decides to forward this Interest,
47 * invoke this->sendInterest one or more times, either now or shortly after
48 * - If strategy concludes that this Interest cannot be forwarded,
49 * invoke this->rebuffPendingInterest so that PIT entry will be deleted shortly
50 */
Junxiao Shid3c792f2014-01-30 00:46:13 -070051 virtual void
52 afterReceiveInterest(const Face& inFace,
53 const Interest& interest,
54 shared_ptr<fib::Entry> fibEntry,
Junxiao Shi8c8d2182014-01-30 22:33:00 -070055 shared_ptr<pit::Entry> pitEntry) =0;
Junxiao Shid3c792f2014-01-30 00:46:13 -070056
Junxiao Shi679e9272014-02-15 20:10:21 -070057 /** \brief trigger before PIT entry expires
58 *
59 * PIT entry expires when InterestLifetime has elapsed for all InRecords,
60 * and it is not satisfied by an incoming Data.
61 *
62 * This trigger is not invoked for PIT entry already satisfied.
63 *
64 * In this base class this method does nothing.
65 */
66 virtual void
67 beforeExpirePendingInterest(shared_ptr<pit::Entry> pitEntry);
Junxiao Shid3c792f2014-01-30 00:46:13 -070068
Junxiao Shi679e9272014-02-15 20:10:21 -070069 /** \brief trigger after FIB entry is being inserted
70 * and becomes managed by this strategy
71 *
72 * In this base class this method does nothing.
73 */
74 virtual void
75 afterAddFibEntry(shared_ptr<fib::Entry> fibEntry);
Junxiao Shid3c792f2014-01-30 00:46:13 -070076
Junxiao Shi679e9272014-02-15 20:10:21 -070077 /** \brief trigger after FIB entry being managed by this strategy is updated
78 *
79 * In this base class this method does nothing.
80 */
81 virtual void
82 afterUpdateFibEntry(shared_ptr<fib::Entry> fibEntry);
Junxiao Shid3c792f2014-01-30 00:46:13 -070083
Junxiao Shi679e9272014-02-15 20:10:21 -070084 /** \brief trigger before FIB entry ceises to be managed by this strategy
85 * or is being deleted
86 *
87 * In this base class this method does nothing.
88 */
89 virtual void
90 beforeRemoveFibEntry(shared_ptr<fib::Entry> fibEntry);
Junxiao Shid3c792f2014-01-30 00:46:13 -070091
92protected: // actions
93 /// send Interest to outFace
94 void
95 sendInterest(shared_ptr<pit::Entry> pitEntry,
96 shared_ptr<Face> outFace);
97
98 /** \brief decide that a pending Interest cannot be forwarded
Junxiao Shi679e9272014-02-15 20:10:21 -070099 *
Junxiao Shid3c792f2014-01-30 00:46:13 -0700100 * This shall not be called if the pending Interest has been
101 * forwarded earlier, and does not need to be resent now.
102 */
103 void
104 rebuffPendingInterest(shared_ptr<pit::Entry> pitEntry);
105
106private:
Junxiao Shi679e9272014-02-15 20:10:21 -0700107 /** \brief reference to the forwarder
108 *
109 * Triggers can access forwarder indirectly via actions.
110 */
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700111 Forwarder& m_forwarder;
Junxiao Shid3c792f2014-01-30 00:46:13 -0700112};
113
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700114} // namespace fw
Junxiao Shid3c792f2014-01-30 00:46:13 -0700115} // namespace nfd
116
117#endif // NFD_FW_STRATEGY_HPP