blob: 0844eb21e1bc150adca4e14d26d99d1e44f5c821 [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 Shi2d9bdc82014-03-02 20:55:42 -070010#include "forwarder.hpp"
Junxiao Shidbe71732014-02-21 22:23:28 -070011#include "table/measurements-accessor.hpp"
Junxiao Shid3c792f2014-01-30 00:46:13 -070012
13namespace nfd {
Junxiao Shi8c8d2182014-01-30 22:33:00 -070014namespace fw {
15
Junxiao Shibb5105f2014-03-03 12:06:45 -070016/** \brief represents a forwarding strategy
Junxiao Shid3c792f2014-01-30 00:46:13 -070017 */
Junxiao Shibb5105f2014-03-03 12:06:45 -070018class Strategy : public enable_shared_from_this<Strategy>, noncopyable
Junxiao Shid3c792f2014-01-30 00:46:13 -070019{
20public:
Junxiao Shibb5105f2014-03-03 12:06:45 -070021 Strategy(Forwarder& forwarder, const Name& name);
Junxiao Shidbe71732014-02-21 22:23:28 -070022
Junxiao Shid3c792f2014-01-30 00:46:13 -070023 virtual
24 ~Strategy();
Junxiao Shidbe71732014-02-21 22:23:28 -070025
Junxiao Shibb5105f2014-03-03 12:06:45 -070026 /// a Name that represent the Strategy program
27 const Name&
28 getName() const;
29
Junxiao Shi679e9272014-02-15 20:10:21 -070030public: // triggers
31 /** \brief trigger after Interest is received
32 *
33 * The Interest:
34 * - does not violate Scope
35 * - is not looped
36 * - cannot be satisfied by ContentStore
37 * - is under a namespace managed by this strategy
38 *
39 * The strategy should decide whether and where to forward this Interest.
40 * - If the strategy decides to forward this Interest,
41 * invoke this->sendInterest one or more times, either now or shortly after
42 * - If strategy concludes that this Interest cannot be forwarded,
Junxiao Shi09498f02014-02-26 19:41:08 -070043 * invoke this->rejectPendingInterest so that PIT entry will be deleted shortly
Junxiao Shi679e9272014-02-15 20:10:21 -070044 */
Junxiao Shid3c792f2014-01-30 00:46:13 -070045 virtual void
46 afterReceiveInterest(const Face& inFace,
47 const Interest& interest,
48 shared_ptr<fib::Entry> fibEntry,
Junxiao Shi8c8d2182014-01-30 22:33:00 -070049 shared_ptr<pit::Entry> pitEntry) =0;
Junxiao Shidbe71732014-02-21 22:23:28 -070050
Junxiao Shi22be22c2014-02-16 22:53:48 -070051 /** \brief trigger before PIT entry is satisfied
52 *
53 * In this base class this method does nothing.
54 */
55 virtual void
56 beforeSatisfyPendingInterest(shared_ptr<pit::Entry> pitEntry,
57 const Face& inFace, const Data& data);
Junxiao Shidbe71732014-02-21 22:23:28 -070058
Junxiao Shi679e9272014-02-15 20:10:21 -070059 /** \brief trigger before PIT entry expires
60 *
61 * PIT entry expires when InterestLifetime has elapsed for all InRecords,
62 * and it is not satisfied by an incoming Data.
63 *
64 * This trigger is not invoked for PIT entry already satisfied.
65 *
66 * In this base class this method does nothing.
67 */
68 virtual void
69 beforeExpirePendingInterest(shared_ptr<pit::Entry> pitEntry);
Junxiao Shidbe71732014-02-21 22:23:28 -070070
Junxiao Shi22be22c2014-02-16 22:53:48 -070071// /** \brief trigger after FIB entry is being inserted
72// * and becomes managed by this strategy
73// *
74// * In this base class this method does nothing.
75// */
76// virtual void
77// afterAddFibEntry(shared_ptr<fib::Entry> fibEntry);
Junxiao Shidbe71732014-02-21 22:23:28 -070078//
Junxiao Shi22be22c2014-02-16 22:53:48 -070079// /** \brief trigger after FIB entry being managed by this strategy is updated
80// *
81// * In this base class this method does nothing.
82// */
83// virtual void
84// afterUpdateFibEntry(shared_ptr<fib::Entry> fibEntry);
Junxiao Shidbe71732014-02-21 22:23:28 -070085//
Junxiao Shi22be22c2014-02-16 22:53:48 -070086// /** \brief trigger before FIB entry ceises to be managed by this strategy
87// * or is being deleted
88// *
89// * In this base class this method does nothing.
90// */
91// virtual void
92// beforeRemoveFibEntry(shared_ptr<fib::Entry> fibEntry);
Junxiao Shidbe71732014-02-21 22:23:28 -070093
Junxiao Shid3c792f2014-01-30 00:46:13 -070094protected: // actions
95 /// send Interest to outFace
Junxiao Shi727ed292014-02-19 23:26:45 -070096 VIRTUAL_WITH_TESTS void
Junxiao Shid3c792f2014-01-30 00:46:13 -070097 sendInterest(shared_ptr<pit::Entry> pitEntry,
98 shared_ptr<Face> outFace);
Junxiao Shidbe71732014-02-21 22:23:28 -070099
Junxiao Shid3c792f2014-01-30 00:46:13 -0700100 /** \brief decide that a pending Interest cannot be forwarded
Junxiao Shi679e9272014-02-15 20:10:21 -0700101 *
Junxiao Shid3c792f2014-01-30 00:46:13 -0700102 * This shall not be called if the pending Interest has been
103 * forwarded earlier, and does not need to be resent now.
104 */
Junxiao Shi727ed292014-02-19 23:26:45 -0700105 VIRTUAL_WITH_TESTS void
Junxiao Shi09498f02014-02-26 19:41:08 -0700106 rejectPendingInterest(shared_ptr<pit::Entry> pitEntry);
Junxiao Shidbe71732014-02-21 22:23:28 -0700107
108protected: // accessors
109 MeasurementsAccessor&
110 getMeasurements();
111
Junxiao Shi2d9bdc82014-03-02 20:55:42 -0700112 shared_ptr<Face>
113 getFace(FaceId id);
114
Junxiao Shid3c792f2014-01-30 00:46:13 -0700115private:
Junxiao Shibb5105f2014-03-03 12:06:45 -0700116 Name m_name;
117
Junxiao Shi679e9272014-02-15 20:10:21 -0700118 /** \brief reference to the forwarder
119 *
120 * Triggers can access forwarder indirectly via actions.
121 */
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700122 Forwarder& m_forwarder;
Junxiao Shidbe71732014-02-21 22:23:28 -0700123
124 MeasurementsAccessor m_measurements;
Junxiao Shid3c792f2014-01-30 00:46:13 -0700125};
126
Junxiao Shibb5105f2014-03-03 12:06:45 -0700127inline const Name&
128Strategy::getName() const
129{
130 return m_name;
131}
132
Junxiao Shi2d9bdc82014-03-02 20:55:42 -0700133inline void
134Strategy::sendInterest(shared_ptr<pit::Entry> pitEntry,
135 shared_ptr<Face> outFace)
136{
137 m_forwarder.onOutgoingInterest(pitEntry, *outFace);
138}
139
140inline void
141Strategy::rejectPendingInterest(shared_ptr<pit::Entry> pitEntry)
142{
143 m_forwarder.onInterestReject(pitEntry);
144}
145
Junxiao Shidbe71732014-02-21 22:23:28 -0700146inline MeasurementsAccessor&
147Strategy::getMeasurements()
148{
149 return m_measurements;
150}
151
Junxiao Shi2d9bdc82014-03-02 20:55:42 -0700152inline shared_ptr<Face>
153Strategy::getFace(FaceId id)
154{
155 return m_forwarder.getFace(id);
156}
157
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700158} // namespace fw
Junxiao Shid3c792f2014-01-30 00:46:13 -0700159} // namespace nfd
160
161#endif // NFD_FW_STRATEGY_HPP