Alexander Afanasyev | e74cc1c | 2012-11-21 13:10:03 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | // custom-strategy.cc |
| 3 | |
| 4 | #include "custom-strategy.h" |
| 5 | #include "ns3/ndn-fib.h" |
| 6 | #include "ns3/ndn-fib-entry.h" |
| 7 | #include "ns3/ndn-pit-entry.h" |
| 8 | #include "ns3/ndn-interest.h" |
| 9 | |
| 10 | namespace ns3 { |
| 11 | namespace ndn { |
| 12 | namespace fw { |
| 13 | |
| 14 | NS_OBJECT_ENSURE_REGISTERED(CustomStrategy); |
| 15 | |
| 16 | LogComponent CustomStrategy::g_log = LogComponent (CustomStrategy::GetLogName ().c_str ()); |
Alexander Afanasyev | 06dba7c | 2013-02-21 11:36:26 -0800 | [diff] [blame] | 17 | |
Alexander Afanasyev | e74cc1c | 2012-11-21 13:10:03 -0800 | [diff] [blame] | 18 | std::string |
| 19 | CustomStrategy::GetLogName () |
| 20 | { |
| 21 | return "ndn.fw.CustomStrategy"; |
| 22 | } |
Alexander Afanasyev | 06dba7c | 2013-02-21 11:36:26 -0800 | [diff] [blame] | 23 | |
Alexander Afanasyev | e74cc1c | 2012-11-21 13:10:03 -0800 | [diff] [blame] | 24 | TypeId |
| 25 | CustomStrategy::GetTypeId (void) |
| 26 | { |
| 27 | static TypeId tid = TypeId ("ns3::ndn::fw::CustomStrategy") |
| 28 | .SetGroupName ("Ndn") |
| 29 | .SetParent <BaseStrategy> () |
| 30 | .AddConstructor <CustomStrategy> () |
Alexander Afanasyev | 06dba7c | 2013-02-21 11:36:26 -0800 | [diff] [blame] | 31 | |
Alexander Afanasyev | e74cc1c | 2012-11-21 13:10:03 -0800 | [diff] [blame] | 32 | // .AddAttribute ("Attribute", "Attribute spec", |
| 33 | // StringValue ("DefaultValue"), |
| 34 | // MakeStringAccessor (&BaseStrategy::m_variable), |
Alexander Afanasyev | 06dba7c | 2013-02-21 11:36:26 -0800 | [diff] [blame] | 35 | // MakeStringChecker ()) |
Alexander Afanasyev | e74cc1c | 2012-11-21 13:10:03 -0800 | [diff] [blame] | 36 | ; |
| 37 | return tid; |
| 38 | } |
| 39 | |
| 40 | CustomStrategy::CustomStrategy () |
| 41 | : m_counter (0) |
| 42 | { |
| 43 | } |
| 44 | |
| 45 | bool |
| 46 | CustomStrategy::DoPropagateInterest (Ptr<Face> inFace, |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame^] | 47 | Ptr<const Interest> header, |
Alexander Afanasyev | e74cc1c | 2012-11-21 13:10:03 -0800 | [diff] [blame] | 48 | Ptr<const Packet> origPacket, |
| 49 | Ptr<pit::Entry> pitEntry) |
| 50 | { |
| 51 | typedef fib::FaceMetricContainer::type::index<fib::i_metric>::type FacesByMetric; |
| 52 | FacesByMetric &faces = pitEntry->GetFibEntry ()->m_faces.get<fib::i_metric> (); |
| 53 | FacesByMetric::iterator faceIterator = faces.begin (); |
| 54 | |
| 55 | int propagatedCount = 0; |
| 56 | |
| 57 | // forward to best-metric face |
| 58 | if (faceIterator != faces.end ()) |
| 59 | { |
Alexander Afanasyev | 06dba7c | 2013-02-21 11:36:26 -0800 | [diff] [blame] | 60 | if (TrySendOutInterest (inFace, faceIterator->GetFace (), header, origPacket, pitEntry)) |
Alexander Afanasyev | e74cc1c | 2012-11-21 13:10:03 -0800 | [diff] [blame] | 61 | propagatedCount ++; |
| 62 | |
| 63 | faceIterator ++; |
| 64 | } |
| 65 | |
| 66 | // forward to second-best-metric face |
| 67 | if (faceIterator != faces.end ()) |
| 68 | { |
Alexander Afanasyev | 06dba7c | 2013-02-21 11:36:26 -0800 | [diff] [blame] | 69 | if (TrySendOutInterest (inFace, faceIterator->GetFace (), header, origPacket, pitEntry)) |
Alexander Afanasyev | e74cc1c | 2012-11-21 13:10:03 -0800 | [diff] [blame] | 70 | propagatedCount ++; |
| 71 | |
| 72 | faceIterator ++; |
| 73 | } |
| 74 | return propagatedCount > 0; |
| 75 | } |
| 76 | |
| 77 | void |
Alexander Afanasyev | 932d331 | 2012-11-26 23:55:01 -0800 | [diff] [blame] | 78 | CustomStrategy::DidSendOutInterest (Ptr<Face> inFace, Ptr<Face> outFace, |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame^] | 79 | Ptr<const Interest> header, |
Alexander Afanasyev | e74cc1c | 2012-11-21 13:10:03 -0800 | [diff] [blame] | 80 | Ptr<const Packet> origPacket, |
| 81 | Ptr<pit::Entry> pitEntry) |
| 82 | { |
| 83 | m_counter ++; |
| 84 | } |
| 85 | |
| 86 | void |
| 87 | CustomStrategy::WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry) |
| 88 | { |
| 89 | for (pit::Entry::out_container::iterator face = pitEntry->GetOutgoing ().begin (); |
| 90 | face != pitEntry->GetOutgoing ().end (); |
| 91 | face ++) |
| 92 | { |
| 93 | m_counter --; |
| 94 | } |
Alexander Afanasyev | 06dba7c | 2013-02-21 11:36:26 -0800 | [diff] [blame] | 95 | |
Alexander Afanasyev | e74cc1c | 2012-11-21 13:10:03 -0800 | [diff] [blame] | 96 | BaseStrategy::WillEraseTimedOutPendingInterest (pitEntry); |
| 97 | } |
Alexander Afanasyev | 06dba7c | 2013-02-21 11:36:26 -0800 | [diff] [blame] | 98 | |
| 99 | |
Alexander Afanasyev | e74cc1c | 2012-11-21 13:10:03 -0800 | [diff] [blame] | 100 | void |
| 101 | CustomStrategy::WillSatisfyPendingInterest (Ptr<Face> inFace, |
| 102 | Ptr<pit::Entry> pitEntry) |
| 103 | { |
| 104 | for (pit::Entry::out_container::iterator face = pitEntry->GetOutgoing ().begin (); |
| 105 | face != pitEntry->GetOutgoing ().end (); |
| 106 | face ++) |
| 107 | { |
| 108 | m_counter --; |
| 109 | } |
Alexander Afanasyev | 06dba7c | 2013-02-21 11:36:26 -0800 | [diff] [blame] | 110 | |
Alexander Afanasyev | e74cc1c | 2012-11-21 13:10:03 -0800 | [diff] [blame] | 111 | BaseStrategy::WillSatisfyPendingInterest (inFace, pitEntry); |
| 112 | } |
| 113 | |
Alexander Afanasyev | 06dba7c | 2013-02-21 11:36:26 -0800 | [diff] [blame] | 114 | |
Alexander Afanasyev | e74cc1c | 2012-11-21 13:10:03 -0800 | [diff] [blame] | 115 | } // namespace fw |
| 116 | } // namespace ndn |
| 117 | } // namespace ns3 |