blob: edffdb3a256f5f11979cbfc33ce2dded6281fad0 [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 Shidbe71732014-02-21 22:23:28 -070011#include "table/fib-entry.hpp"
12#include "table/pit-entry.hpp"
13#include "table/measurements-accessor.hpp"
Junxiao Shid3c792f2014-01-30 00:46:13 -070014
15namespace nfd {
16
Junxiao Shi8c8d2182014-01-30 22:33:00 -070017class Forwarder;
Junxiao Shi8c8d2182014-01-30 22:33:00 -070018
19namespace fw {
20
Junxiao Shid3c792f2014-01-30 00:46:13 -070021/** \class Strategy
22 * \brief represents a forwarding strategy
23 */
24class Strategy
25{
26public:
27 explicit
Junxiao Shi8c8d2182014-01-30 22:33:00 -070028 Strategy(Forwarder& forwarder);
Junxiao Shidbe71732014-02-21 22:23:28 -070029
Junxiao Shid3c792f2014-01-30 00:46:13 -070030 virtual
31 ~Strategy();
Junxiao Shidbe71732014-02-21 22:23:28 -070032
Junxiao Shi679e9272014-02-15 20:10:21 -070033public: // triggers
34 /** \brief trigger after Interest is received
35 *
36 * The Interest:
37 * - does not violate Scope
38 * - is not looped
39 * - cannot be satisfied by ContentStore
40 * - is under a namespace managed by this strategy
41 *
42 * The strategy should decide whether and where to forward this Interest.
43 * - If the strategy decides to forward this Interest,
44 * invoke this->sendInterest one or more times, either now or shortly after
45 * - If strategy concludes that this Interest cannot be forwarded,
Junxiao Shi09498f02014-02-26 19:41:08 -070046 * invoke this->rejectPendingInterest so that PIT entry will be deleted shortly
Junxiao Shi679e9272014-02-15 20:10:21 -070047 */
Junxiao Shid3c792f2014-01-30 00:46:13 -070048 virtual void
49 afterReceiveInterest(const Face& inFace,
50 const Interest& interest,
51 shared_ptr<fib::Entry> fibEntry,
Junxiao Shi8c8d2182014-01-30 22:33:00 -070052 shared_ptr<pit::Entry> pitEntry) =0;
Junxiao Shidbe71732014-02-21 22:23:28 -070053
Junxiao Shi22be22c2014-02-16 22:53:48 -070054 /** \brief trigger before PIT entry is satisfied
55 *
56 * In this base class this method does nothing.
57 */
58 virtual void
59 beforeSatisfyPendingInterest(shared_ptr<pit::Entry> pitEntry,
60 const Face& inFace, const Data& data);
Junxiao Shidbe71732014-02-21 22:23:28 -070061
Junxiao Shi679e9272014-02-15 20:10:21 -070062 /** \brief trigger before PIT entry expires
63 *
64 * PIT entry expires when InterestLifetime has elapsed for all InRecords,
65 * and it is not satisfied by an incoming Data.
66 *
67 * This trigger is not invoked for PIT entry already satisfied.
68 *
69 * In this base class this method does nothing.
70 */
71 virtual void
72 beforeExpirePendingInterest(shared_ptr<pit::Entry> pitEntry);
Junxiao Shidbe71732014-02-21 22:23:28 -070073
Junxiao Shi22be22c2014-02-16 22:53:48 -070074// /** \brief trigger after FIB entry is being inserted
75// * and becomes managed by this strategy
76// *
77// * In this base class this method does nothing.
78// */
79// virtual void
80// afterAddFibEntry(shared_ptr<fib::Entry> fibEntry);
Junxiao Shidbe71732014-02-21 22:23:28 -070081//
Junxiao Shi22be22c2014-02-16 22:53:48 -070082// /** \brief trigger after FIB entry being managed by this strategy is updated
83// *
84// * In this base class this method does nothing.
85// */
86// virtual void
87// afterUpdateFibEntry(shared_ptr<fib::Entry> fibEntry);
Junxiao Shidbe71732014-02-21 22:23:28 -070088//
Junxiao Shi22be22c2014-02-16 22:53:48 -070089// /** \brief trigger before FIB entry ceises to be managed by this strategy
90// * or is being deleted
91// *
92// * In this base class this method does nothing.
93// */
94// virtual void
95// beforeRemoveFibEntry(shared_ptr<fib::Entry> fibEntry);
Junxiao Shidbe71732014-02-21 22:23:28 -070096
Junxiao Shid3c792f2014-01-30 00:46:13 -070097protected: // actions
98 /// send Interest to outFace
Junxiao Shi727ed292014-02-19 23:26:45 -070099 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700100 sendInterest(shared_ptr<pit::Entry> pitEntry,
101 shared_ptr<Face> outFace);
Junxiao Shidbe71732014-02-21 22:23:28 -0700102
Junxiao Shid3c792f2014-01-30 00:46:13 -0700103 /** \brief decide that a pending Interest cannot be forwarded
Junxiao Shi679e9272014-02-15 20:10:21 -0700104 *
Junxiao Shid3c792f2014-01-30 00:46:13 -0700105 * This shall not be called if the pending Interest has been
106 * forwarded earlier, and does not need to be resent now.
107 */
Junxiao Shi727ed292014-02-19 23:26:45 -0700108 VIRTUAL_WITH_TESTS void
Junxiao Shi09498f02014-02-26 19:41:08 -0700109 rejectPendingInterest(shared_ptr<pit::Entry> pitEntry);
Junxiao Shidbe71732014-02-21 22:23:28 -0700110
111protected: // accessors
112 MeasurementsAccessor&
113 getMeasurements();
114
Junxiao Shid3c792f2014-01-30 00:46:13 -0700115private:
Junxiao Shi679e9272014-02-15 20:10:21 -0700116 /** \brief reference to the forwarder
117 *
118 * Triggers can access forwarder indirectly via actions.
119 */
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700120 Forwarder& m_forwarder;
Junxiao Shidbe71732014-02-21 22:23:28 -0700121
122 MeasurementsAccessor m_measurements;
Junxiao Shid3c792f2014-01-30 00:46:13 -0700123};
124
Junxiao Shidbe71732014-02-21 22:23:28 -0700125inline MeasurementsAccessor&
126Strategy::getMeasurements()
127{
128 return m_measurements;
129}
130
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700131} // namespace fw
Junxiao Shid3c792f2014-01-30 00:46:13 -0700132} // namespace nfd
133
134#endif // NFD_FW_STRATEGY_HPP