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 ()); |
| 17 | |
| 18 | std::string |
| 19 | CustomStrategy::GetLogName () |
| 20 | { |
| 21 | return "ndn.fw.CustomStrategy"; |
| 22 | } |
| 23 | |
| 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> () |
| 31 | |
| 32 | // .AddAttribute ("Attribute", "Attribute spec", |
| 33 | // StringValue ("DefaultValue"), |
| 34 | // MakeStringAccessor (&BaseStrategy::m_variable), |
| 35 | // MakeStringChecker ()) |
| 36 | ; |
| 37 | return tid; |
| 38 | } |
| 39 | |
| 40 | CustomStrategy::CustomStrategy () |
| 41 | : m_counter (0) |
| 42 | { |
| 43 | } |
| 44 | |
| 45 | bool |
| 46 | CustomStrategy::DoPropagateInterest (Ptr<Face> inFace, |
| 47 | Ptr<const InterestHeader> header, |
| 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 | { |
| 60 | if (TrySendOutInterest (inFace, faceIterator->m_face, header, origPacket, pitEntry)) |
| 61 | propagatedCount ++; |
| 62 | |
| 63 | faceIterator ++; |
| 64 | } |
| 65 | |
| 66 | // forward to second-best-metric face |
| 67 | if (faceIterator != faces.end ()) |
| 68 | { |
| 69 | if (TrySendOutInterest (inFace, faceIterator->m_face, header, origPacket, pitEntry)) |
| 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 | e74cc1c | 2012-11-21 13:10:03 -0800 | [diff] [blame] | 79 | Ptr<const InterestHeader> header, |
| 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 | } |
| 95 | |
| 96 | BaseStrategy::WillEraseTimedOutPendingInterest (pitEntry); |
| 97 | } |
| 98 | |
| 99 | |
| 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 | } |
| 110 | |
| 111 | BaseStrategy::WillSatisfyPendingInterest (inFace, pitEntry); |
| 112 | } |
| 113 | |
| 114 | |
| 115 | } // namespace fw |
| 116 | } // namespace ndn |
| 117 | } // namespace ns3 |