blob: 3b1cea10a8e515254971d58320c58b6265f8d483 [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 ());
17
18std::string
19CustomStrategy::GetLogName ()
20{
21 return "ndn.fw.CustomStrategy";
22}
23
24TypeId
25CustomStrategy::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
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 {
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
77void
78CustomStrategy::DidSendOutInterest (Ptr<Face> outFace,
79 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 }
95
96 BaseStrategy::WillEraseTimedOutPendingInterest (pitEntry);
97}
98
99
100void
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 }
110
111 BaseStrategy::WillSatisfyPendingInterest (inFace, pitEntry);
112}
113
114
115} // namespace fw
116} // namespace ndn
117} // namespace ns3