blob: 1ecbfc93f147e40d144a02b7ce39439f3fbaf7d8 [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 Shi22be22c2014-02-16 22:53:48 -070057 /** \brief trigger before PIT entry is satisfied
58 *
59 * In this base class this method does nothing.
60 */
61 virtual void
62 beforeSatisfyPendingInterest(shared_ptr<pit::Entry> pitEntry,
63 const Face& inFace, const Data& data);
64
Junxiao Shi679e9272014-02-15 20:10:21 -070065 /** \brief trigger before PIT entry expires
66 *
67 * PIT entry expires when InterestLifetime has elapsed for all InRecords,
68 * and it is not satisfied by an incoming Data.
69 *
70 * This trigger is not invoked for PIT entry already satisfied.
71 *
72 * In this base class this method does nothing.
73 */
74 virtual void
75 beforeExpirePendingInterest(shared_ptr<pit::Entry> pitEntry);
Junxiao Shid3c792f2014-01-30 00:46:13 -070076
Junxiao Shi22be22c2014-02-16 22:53:48 -070077// /** \brief trigger after FIB entry is being inserted
78// * and becomes managed by this strategy
79// *
80// * In this base class this method does nothing.
81// */
82// virtual void
83// afterAddFibEntry(shared_ptr<fib::Entry> fibEntry);
84//
85// /** \brief trigger after FIB entry being managed by this strategy is updated
86// *
87// * In this base class this method does nothing.
88// */
89// virtual void
90// afterUpdateFibEntry(shared_ptr<fib::Entry> fibEntry);
91//
92// /** \brief trigger before FIB entry ceises to be managed by this strategy
93// * or is being deleted
94// *
95// * In this base class this method does nothing.
96// */
97// virtual void
98// beforeRemoveFibEntry(shared_ptr<fib::Entry> fibEntry);
Junxiao Shid3c792f2014-01-30 00:46:13 -070099
100protected: // actions
101 /// send Interest to outFace
Junxiao Shi727ed292014-02-19 23:26:45 -0700102 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700103 sendInterest(shared_ptr<pit::Entry> pitEntry,
104 shared_ptr<Face> outFace);
105
106 /** \brief decide that a pending Interest cannot be forwarded
Junxiao Shi679e9272014-02-15 20:10:21 -0700107 *
Junxiao Shid3c792f2014-01-30 00:46:13 -0700108 * This shall not be called if the pending Interest has been
109 * forwarded earlier, and does not need to be resent now.
110 */
Junxiao Shi727ed292014-02-19 23:26:45 -0700111 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700112 rebuffPendingInterest(shared_ptr<pit::Entry> pitEntry);
113
114private:
Junxiao Shi679e9272014-02-15 20:10:21 -0700115 /** \brief reference to the forwarder
116 *
117 * Triggers can access forwarder indirectly via actions.
118 */
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700119 Forwarder& m_forwarder;
Junxiao Shid3c792f2014-01-30 00:46:13 -0700120};
121
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700122} // namespace fw
Junxiao Shid3c792f2014-01-30 00:46:13 -0700123} // namespace nfd
124
125#endif // NFD_FW_STRATEGY_HPP