Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 1 | /* -*- 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 Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 10 | #include "face/face.hpp" |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 11 | #include "table/fib-entry.hpp" |
| 12 | #include "table/pit-entry.hpp" |
| 13 | #include "table/measurements-accessor.hpp" |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 14 | |
| 15 | namespace nfd { |
| 16 | |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 17 | class Forwarder; |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 18 | |
| 19 | namespace fw { |
| 20 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 21 | /** \class Strategy |
| 22 | * \brief represents a forwarding strategy |
| 23 | */ |
| 24 | class Strategy |
| 25 | { |
| 26 | public: |
| 27 | explicit |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 28 | Strategy(Forwarder& forwarder); |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 29 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 30 | virtual |
| 31 | ~Strategy(); |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 32 | |
Junxiao Shi | 679e927 | 2014-02-15 20:10:21 -0700 | [diff] [blame] | 33 | public: // 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, |
| 46 | * invoke this->rebuffPendingInterest so that PIT entry will be deleted shortly |
| 47 | */ |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 48 | virtual void |
| 49 | afterReceiveInterest(const Face& inFace, |
| 50 | const Interest& interest, |
| 51 | shared_ptr<fib::Entry> fibEntry, |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 52 | shared_ptr<pit::Entry> pitEntry) =0; |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 53 | |
Junxiao Shi | 22be22c | 2014-02-16 22:53:48 -0700 | [diff] [blame] | 54 | /** \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 Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 61 | |
Junxiao Shi | 679e927 | 2014-02-15 20:10:21 -0700 | [diff] [blame] | 62 | /** \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 Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 73 | |
Junxiao Shi | 22be22c | 2014-02-16 22:53:48 -0700 | [diff] [blame] | 74 | // /** \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 Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 81 | // |
Junxiao Shi | 22be22c | 2014-02-16 22:53:48 -0700 | [diff] [blame] | 82 | // /** \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 Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 88 | // |
Junxiao Shi | 22be22c | 2014-02-16 22:53:48 -0700 | [diff] [blame] | 89 | // /** \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 Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 96 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 97 | protected: // actions |
| 98 | /// send Interest to outFace |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 99 | VIRTUAL_WITH_TESTS void |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 100 | sendInterest(shared_ptr<pit::Entry> pitEntry, |
| 101 | shared_ptr<Face> outFace); |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 102 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 103 | /** \brief decide that a pending Interest cannot be forwarded |
Junxiao Shi | 679e927 | 2014-02-15 20:10:21 -0700 | [diff] [blame] | 104 | * |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 105 | * This shall not be called if the pending Interest has been |
| 106 | * forwarded earlier, and does not need to be resent now. |
| 107 | */ |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 108 | VIRTUAL_WITH_TESTS void |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 109 | rebuffPendingInterest(shared_ptr<pit::Entry> pitEntry); |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 110 | |
| 111 | protected: // accessors |
| 112 | MeasurementsAccessor& |
| 113 | getMeasurements(); |
| 114 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 115 | private: |
Junxiao Shi | 679e927 | 2014-02-15 20:10:21 -0700 | [diff] [blame] | 116 | /** \brief reference to the forwarder |
| 117 | * |
| 118 | * Triggers can access forwarder indirectly via actions. |
| 119 | */ |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 120 | Forwarder& m_forwarder; |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 121 | |
| 122 | MeasurementsAccessor m_measurements; |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 123 | }; |
| 124 | |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 125 | inline MeasurementsAccessor& |
| 126 | Strategy::getMeasurements() |
| 127 | { |
| 128 | return m_measurements; |
| 129 | } |
| 130 | |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 131 | } // namespace fw |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 132 | } // namespace nfd |
| 133 | |
| 134 | #endif // NFD_FW_STRATEGY_HPP |