blob: df4c946706e49261e389349088b3f364c3ea3842 [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 Shibb5105f2014-03-03 12:06:45 -070021/** \brief represents a forwarding strategy
Junxiao Shid3c792f2014-01-30 00:46:13 -070022 */
Junxiao Shibb5105f2014-03-03 12:06:45 -070023class Strategy : public enable_shared_from_this<Strategy>, noncopyable
Junxiao Shid3c792f2014-01-30 00:46:13 -070024{
25public:
Junxiao Shibb5105f2014-03-03 12:06:45 -070026 Strategy(Forwarder& forwarder, const Name& name);
Junxiao Shidbe71732014-02-21 22:23:28 -070027
Junxiao Shid3c792f2014-01-30 00:46:13 -070028 virtual
29 ~Strategy();
Junxiao Shidbe71732014-02-21 22:23:28 -070030
Junxiao Shibb5105f2014-03-03 12:06:45 -070031 /// a Name that represent the Strategy program
32 const Name&
33 getName() const;
34
Junxiao Shi679e9272014-02-15 20:10:21 -070035public: // triggers
36 /** \brief trigger after Interest is received
37 *
38 * The Interest:
39 * - does not violate Scope
40 * - is not looped
41 * - cannot be satisfied by ContentStore
42 * - is under a namespace managed by this strategy
43 *
44 * The strategy should decide whether and where to forward this Interest.
45 * - If the strategy decides to forward this Interest,
46 * invoke this->sendInterest one or more times, either now or shortly after
47 * - If strategy concludes that this Interest cannot be forwarded,
Junxiao Shi09498f02014-02-26 19:41:08 -070048 * invoke this->rejectPendingInterest so that PIT entry will be deleted shortly
Junxiao Shi679e9272014-02-15 20:10:21 -070049 */
Junxiao Shid3c792f2014-01-30 00:46:13 -070050 virtual void
51 afterReceiveInterest(const Face& inFace,
52 const Interest& interest,
53 shared_ptr<fib::Entry> fibEntry,
Junxiao Shi8c8d2182014-01-30 22:33:00 -070054 shared_ptr<pit::Entry> pitEntry) =0;
Junxiao Shidbe71732014-02-21 22:23:28 -070055
Junxiao Shi22be22c2014-02-16 22:53:48 -070056 /** \brief trigger before PIT entry is satisfied
57 *
58 * In this base class this method does nothing.
59 */
60 virtual void
61 beforeSatisfyPendingInterest(shared_ptr<pit::Entry> pitEntry,
62 const Face& inFace, const Data& data);
Junxiao Shidbe71732014-02-21 22:23:28 -070063
Junxiao Shi679e9272014-02-15 20:10:21 -070064 /** \brief trigger before PIT entry expires
65 *
66 * PIT entry expires when InterestLifetime has elapsed for all InRecords,
67 * and it is not satisfied by an incoming Data.
68 *
69 * This trigger is not invoked for PIT entry already satisfied.
70 *
71 * In this base class this method does nothing.
72 */
73 virtual void
74 beforeExpirePendingInterest(shared_ptr<pit::Entry> pitEntry);
Junxiao Shidbe71732014-02-21 22:23:28 -070075
Junxiao Shi22be22c2014-02-16 22:53:48 -070076// /** \brief trigger after FIB entry is being inserted
77// * and becomes managed by this strategy
78// *
79// * In this base class this method does nothing.
80// */
81// virtual void
82// afterAddFibEntry(shared_ptr<fib::Entry> fibEntry);
Junxiao Shidbe71732014-02-21 22:23:28 -070083//
Junxiao Shi22be22c2014-02-16 22:53:48 -070084// /** \brief trigger after FIB entry being managed by this strategy is updated
85// *
86// * In this base class this method does nothing.
87// */
88// virtual void
89// afterUpdateFibEntry(shared_ptr<fib::Entry> fibEntry);
Junxiao Shidbe71732014-02-21 22:23:28 -070090//
Junxiao Shi22be22c2014-02-16 22:53:48 -070091// /** \brief trigger before FIB entry ceises to be managed by this strategy
92// * or is being deleted
93// *
94// * In this base class this method does nothing.
95// */
96// virtual void
97// beforeRemoveFibEntry(shared_ptr<fib::Entry> fibEntry);
Junxiao Shidbe71732014-02-21 22:23:28 -070098
Junxiao Shid3c792f2014-01-30 00:46:13 -070099protected: // actions
100 /// send Interest to outFace
Junxiao Shi727ed292014-02-19 23:26:45 -0700101 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -0700102 sendInterest(shared_ptr<pit::Entry> pitEntry,
103 shared_ptr<Face> outFace);
Junxiao Shidbe71732014-02-21 22:23:28 -0700104
Junxiao Shid3c792f2014-01-30 00:46:13 -0700105 /** \brief decide that a pending Interest cannot be forwarded
Junxiao Shi679e9272014-02-15 20:10:21 -0700106 *
Junxiao Shid3c792f2014-01-30 00:46:13 -0700107 * This shall not be called if the pending Interest has been
108 * forwarded earlier, and does not need to be resent now.
109 */
Junxiao Shi727ed292014-02-19 23:26:45 -0700110 VIRTUAL_WITH_TESTS void
Junxiao Shi09498f02014-02-26 19:41:08 -0700111 rejectPendingInterest(shared_ptr<pit::Entry> pitEntry);
Junxiao Shidbe71732014-02-21 22:23:28 -0700112
113protected: // accessors
114 MeasurementsAccessor&
115 getMeasurements();
116
Junxiao Shid3c792f2014-01-30 00:46:13 -0700117private:
Junxiao Shibb5105f2014-03-03 12:06:45 -0700118 Name m_name;
119
Junxiao Shi679e9272014-02-15 20:10:21 -0700120 /** \brief reference to the forwarder
121 *
122 * Triggers can access forwarder indirectly via actions.
123 */
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700124 Forwarder& m_forwarder;
Junxiao Shidbe71732014-02-21 22:23:28 -0700125
126 MeasurementsAccessor m_measurements;
Junxiao Shid3c792f2014-01-30 00:46:13 -0700127};
128
Junxiao Shibb5105f2014-03-03 12:06:45 -0700129inline const Name&
130Strategy::getName() const
131{
132 return m_name;
133}
134
Junxiao Shidbe71732014-02-21 22:23:28 -0700135inline MeasurementsAccessor&
136Strategy::getMeasurements()
137{
138 return m_measurements;
139}
140
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700141} // namespace fw
Junxiao Shid3c792f2014-01-30 00:46:13 -0700142} // namespace nfd
143
144#endif // NFD_FW_STRATEGY_HPP