blob: 5812ca3b27b050c01d7afbaac6368c4fe25d90f3 [file] [log] [blame]
Alexander Afanasyeve74cc1c2012-11-21 13:10:03 -08001/* -*- 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
10namespace ns3 {
11namespace ndn {
12namespace fw {
13
14NS_OBJECT_ENSURE_REGISTERED(CustomStrategy);
15
16LogComponent CustomStrategy::g_log = LogComponent (CustomStrategy::GetLogName ().c_str ());
Alexander Afanasyev06dba7c2013-02-21 11:36:26 -080017
Alexander Afanasyeve74cc1c2012-11-21 13:10:03 -080018std::string
19CustomStrategy::GetLogName ()
20{
21 return "ndn.fw.CustomStrategy";
22}
Alexander Afanasyev06dba7c2013-02-21 11:36:26 -080023
Alexander Afanasyeve74cc1c2012-11-21 13:10:03 -080024TypeId
25CustomStrategy::GetTypeId (void)
26{
27 static TypeId tid = TypeId ("ns3::ndn::fw::CustomStrategy")
28 .SetGroupName ("Ndn")
29 .SetParent <BaseStrategy> ()
30 .AddConstructor <CustomStrategy> ()
Alexander Afanasyev06dba7c2013-02-21 11:36:26 -080031
Alexander Afanasyeve74cc1c2012-11-21 13:10:03 -080032 // .AddAttribute ("Attribute", "Attribute spec",
33 // StringValue ("DefaultValue"),
34 // MakeStringAccessor (&BaseStrategy::m_variable),
Alexander Afanasyev06dba7c2013-02-21 11:36:26 -080035 // MakeStringChecker ())
Alexander Afanasyeve74cc1c2012-11-21 13:10:03 -080036 ;
37 return tid;
38}
39
40CustomStrategy::CustomStrategy ()
41 : m_counter (0)
42{
43}
44
45bool
46CustomStrategy::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 {
Alexander Afanasyev06dba7c2013-02-21 11:36:26 -080060 if (TrySendOutInterest (inFace, faceIterator->GetFace (), header, origPacket, pitEntry))
Alexander Afanasyeve74cc1c2012-11-21 13:10:03 -080061 propagatedCount ++;
62
63 faceIterator ++;
64 }
65
66 // forward to second-best-metric face
67 if (faceIterator != faces.end ())
68 {
Alexander Afanasyev06dba7c2013-02-21 11:36:26 -080069 if (TrySendOutInterest (inFace, faceIterator->GetFace (), header, origPacket, pitEntry))
Alexander Afanasyeve74cc1c2012-11-21 13:10:03 -080070 propagatedCount ++;
71
72 faceIterator ++;
73 }
74 return propagatedCount > 0;
75}
76
77void
Alexander Afanasyev932d3312012-11-26 23:55:01 -080078CustomStrategy::DidSendOutInterest (Ptr<Face> inFace, Ptr<Face> outFace,
Alexander Afanasyeve74cc1c2012-11-21 13:10:03 -080079 Ptr<const InterestHeader> header,
80 Ptr<const Packet> origPacket,
81 Ptr<pit::Entry> pitEntry)
82{
83 m_counter ++;
84}
85
86void
87CustomStrategy::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 Afanasyev06dba7c2013-02-21 11:36:26 -080095
Alexander Afanasyeve74cc1c2012-11-21 13:10:03 -080096 BaseStrategy::WillEraseTimedOutPendingInterest (pitEntry);
97}
Alexander Afanasyev06dba7c2013-02-21 11:36:26 -080098
99
Alexander Afanasyeve74cc1c2012-11-21 13:10:03 -0800100void
101CustomStrategy::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 Afanasyev06dba7c2013-02-21 11:36:26 -0800110
Alexander Afanasyeve74cc1c2012-11-21 13:10:03 -0800111 BaseStrategy::WillSatisfyPendingInterest (inFace, pitEntry);
112}
113
Alexander Afanasyev06dba7c2013-02-21 11:36:26 -0800114
Alexander Afanasyeve74cc1c2012-11-21 13:10:03 -0800115} // namespace fw
116} // namespace ndn
117} // namespace ns3