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 | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 11 | |
| 12 | namespace nfd { |
| 13 | |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 14 | class Forwarder; |
| 15 | namespace fib { |
| 16 | class Entry; |
| 17 | } |
| 18 | namespace pit { |
| 19 | class Entry; |
| 20 | } |
| 21 | |
| 22 | namespace fw { |
| 23 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 24 | /** \class Strategy |
| 25 | * \brief represents a forwarding strategy |
| 26 | */ |
| 27 | class Strategy |
| 28 | { |
| 29 | public: |
| 30 | explicit |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 31 | Strategy(Forwarder& forwarder); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 32 | |
| 33 | virtual |
| 34 | ~Strategy(); |
| 35 | |
Junxiao Shi | 679e927 | 2014-02-15 20:10:21 -0700 | [diff] [blame] | 36 | public: // 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 Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 51 | virtual void |
| 52 | afterReceiveInterest(const Face& inFace, |
| 53 | const Interest& interest, |
| 54 | shared_ptr<fib::Entry> fibEntry, |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 55 | shared_ptr<pit::Entry> pitEntry) =0; |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 56 | |
Junxiao Shi | 22be22c | 2014-02-16 22:53:48 -0700 | [diff] [blame^] | 57 | /** \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 Shi | 679e927 | 2014-02-15 20:10:21 -0700 | [diff] [blame] | 65 | /** \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 Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 76 | |
Junxiao Shi | 22be22c | 2014-02-16 22:53:48 -0700 | [diff] [blame^] | 77 | // /** \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 Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 99 | |
| 100 | protected: // actions |
| 101 | /// send Interest to outFace |
| 102 | void |
| 103 | sendInterest(shared_ptr<pit::Entry> pitEntry, |
| 104 | shared_ptr<Face> outFace); |
| 105 | |
| 106 | /** \brief decide that a pending Interest cannot be forwarded |
Junxiao Shi | 679e927 | 2014-02-15 20:10:21 -0700 | [diff] [blame] | 107 | * |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 108 | * This shall not be called if the pending Interest has been |
| 109 | * forwarded earlier, and does not need to be resent now. |
| 110 | */ |
| 111 | void |
| 112 | rebuffPendingInterest(shared_ptr<pit::Entry> pitEntry); |
| 113 | |
| 114 | private: |
Junxiao Shi | 679e927 | 2014-02-15 20:10:21 -0700 | [diff] [blame] | 115 | /** \brief reference to the forwarder |
| 116 | * |
| 117 | * Triggers can access forwarder indirectly via actions. |
| 118 | */ |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 119 | Forwarder& m_forwarder; |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 120 | }; |
| 121 | |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 122 | } // namespace fw |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 123 | } // namespace nfd |
| 124 | |
| 125 | #endif // NFD_FW_STRATEGY_HPP |