blob: b1bb6c27d78974339ee5381b0d71f90d8d024fd6 [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,
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -070047 Ptr<const Interest> interest,
Alexander Afanasyeve74cc1c2012-11-21 13:10:03 -080048 Ptr<pit::Entry> pitEntry)
49{
50 typedef fib::FaceMetricContainer::type::index<fib::i_metric>::type FacesByMetric;
51 FacesByMetric &faces = pitEntry->GetFibEntry ()->m_faces.get<fib::i_metric> ();
52 FacesByMetric::iterator faceIterator = faces.begin ();
53
54 int propagatedCount = 0;
55
56 // forward to best-metric face
57 if (faceIterator != faces.end ())
58 {
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -070059 if (TrySendOutInterest (inFace, faceIterator->GetFace (), interest, pitEntry))
Alexander Afanasyeve74cc1c2012-11-21 13:10:03 -080060 propagatedCount ++;
61
62 faceIterator ++;
63 }
64
65 // forward to second-best-metric face
66 if (faceIterator != faces.end ())
67 {
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -070068 if (TrySendOutInterest (inFace, faceIterator->GetFace (), interest, pitEntry))
Alexander Afanasyeve74cc1c2012-11-21 13:10:03 -080069 propagatedCount ++;
70
71 faceIterator ++;
72 }
73 return propagatedCount > 0;
74}
75
76void
Alexander Afanasyev932d3312012-11-26 23:55:01 -080077CustomStrategy::DidSendOutInterest (Ptr<Face> inFace, Ptr<Face> outFace,
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -070078 Ptr<const Interest> interest,
Alexander Afanasyeve74cc1c2012-11-21 13:10:03 -080079 Ptr<pit::Entry> pitEntry)
80{
81 m_counter ++;
82}
83
84void
85CustomStrategy::WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry)
86{
87 for (pit::Entry::out_container::iterator face = pitEntry->GetOutgoing ().begin ();
88 face != pitEntry->GetOutgoing ().end ();
89 face ++)
90 {
91 m_counter --;
92 }
Alexander Afanasyev06dba7c2013-02-21 11:36:26 -080093
Alexander Afanasyeve74cc1c2012-11-21 13:10:03 -080094 BaseStrategy::WillEraseTimedOutPendingInterest (pitEntry);
95}
Alexander Afanasyev06dba7c2013-02-21 11:36:26 -080096
97
Alexander Afanasyeve74cc1c2012-11-21 13:10:03 -080098void
99CustomStrategy::WillSatisfyPendingInterest (Ptr<Face> inFace,
100 Ptr<pit::Entry> pitEntry)
101{
102 for (pit::Entry::out_container::iterator face = pitEntry->GetOutgoing ().begin ();
103 face != pitEntry->GetOutgoing ().end ();
104 face ++)
105 {
106 m_counter --;
107 }
Alexander Afanasyev06dba7c2013-02-21 11:36:26 -0800108
Alexander Afanasyeve74cc1c2012-11-21 13:10:03 -0800109 BaseStrategy::WillSatisfyPendingInterest (inFace, pitEntry);
110}
111
Alexander Afanasyev06dba7c2013-02-21 11:36:26 -0800112
Alexander Afanasyeve74cc1c2012-11-21 13:10:03 -0800113} // namespace fw
114} // namespace ndn
115} // namespace ns3