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 | 679e927 | 2014-02-15 20:10:21 -0700 | [diff] [blame] | 57 | /** \brief trigger before PIT entry expires |
| 58 | * |
| 59 | * PIT entry expires when InterestLifetime has elapsed for all InRecords, |
| 60 | * and it is not satisfied by an incoming Data. |
| 61 | * |
| 62 | * This trigger is not invoked for PIT entry already satisfied. |
| 63 | * |
| 64 | * In this base class this method does nothing. |
| 65 | */ |
| 66 | virtual void |
| 67 | beforeExpirePendingInterest(shared_ptr<pit::Entry> pitEntry); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 68 | |
Junxiao Shi | 679e927 | 2014-02-15 20:10:21 -0700 | [diff] [blame] | 69 | /** \brief trigger after FIB entry is being inserted |
| 70 | * and becomes managed by this strategy |
| 71 | * |
| 72 | * In this base class this method does nothing. |
| 73 | */ |
| 74 | virtual void |
| 75 | afterAddFibEntry(shared_ptr<fib::Entry> fibEntry); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 76 | |
Junxiao Shi | 679e927 | 2014-02-15 20:10:21 -0700 | [diff] [blame] | 77 | /** \brief trigger after FIB entry being managed by this strategy is updated |
| 78 | * |
| 79 | * In this base class this method does nothing. |
| 80 | */ |
| 81 | virtual void |
| 82 | afterUpdateFibEntry(shared_ptr<fib::Entry> fibEntry); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 83 | |
Junxiao Shi | 679e927 | 2014-02-15 20:10:21 -0700 | [diff] [blame] | 84 | /** \brief trigger before FIB entry ceises to be managed by this strategy |
| 85 | * or is being deleted |
| 86 | * |
| 87 | * In this base class this method does nothing. |
| 88 | */ |
| 89 | virtual void |
| 90 | beforeRemoveFibEntry(shared_ptr<fib::Entry> fibEntry); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 91 | |
| 92 | protected: // actions |
| 93 | /// send Interest to outFace |
| 94 | void |
| 95 | sendInterest(shared_ptr<pit::Entry> pitEntry, |
| 96 | shared_ptr<Face> outFace); |
| 97 | |
| 98 | /** \brief decide that a pending Interest cannot be forwarded |
Junxiao Shi | 679e927 | 2014-02-15 20:10:21 -0700 | [diff] [blame] | 99 | * |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 100 | * This shall not be called if the pending Interest has been |
| 101 | * forwarded earlier, and does not need to be resent now. |
| 102 | */ |
| 103 | void |
| 104 | rebuffPendingInterest(shared_ptr<pit::Entry> pitEntry); |
| 105 | |
| 106 | private: |
Junxiao Shi | 679e927 | 2014-02-15 20:10:21 -0700 | [diff] [blame] | 107 | /** \brief reference to the forwarder |
| 108 | * |
| 109 | * Triggers can access forwarder indirectly via actions. |
| 110 | */ |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 111 | Forwarder& m_forwarder; |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 112 | }; |
| 113 | |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 114 | } // namespace fw |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 115 | } // namespace nfd |
| 116 | |
| 117 | #endif // NFD_FW_STRATEGY_HPP |