blob: e3d43221a161c555d61d71ebee3269c67f0ae610 [file] [log] [blame]
Alexander Afanasyev996b4872012-07-17 17:07:56 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2011 University of California, Los Angeles
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
19 * Ilya Moiseenko <iliamo@cs.ucla.edu>
20 */
21
22#include "green-yellow-red.h"
23
24#include "ns3/ccnx-pit.h"
25#include "ns3/ccnx-pit-entry.h"
26#include "ns3/ccnx-interest-header.h"
27#include "ns3/ccnx-content-object-header.h"
28#include "ns3/ccnx-pit.h"
29#include "ns3/ccnx-fib.h"
30#include "ns3/ccnx-content-store.h"
31
32#include "ns3/assert.h"
33#include "ns3/ptr.h"
34#include "ns3/log.h"
35#include "ns3/simulator.h"
36#include "ns3/boolean.h"
37#include "ns3/string.h"
38
39#include <boost/ref.hpp>
40#include <boost/foreach.hpp>
41#include <boost/lambda/lambda.hpp>
42#include <boost/lambda/bind.hpp>
43#include <boost/tuple/tuple.hpp>
44namespace ll = boost::lambda;
45
46NS_LOG_COMPONENT_DEFINE ("NdnSimGreenYellowRed");
47
48namespace ns3 {
49
50using namespace __ccnx_private;
51
52namespace ndnSIM {
53
54NS_OBJECT_ENSURE_REGISTERED (GreenYellowRed);
55
56TypeId
57GreenYellowRed::GetTypeId (void)
58{
59 static TypeId tid = TypeId ("ns3::ndnSIM::GreenYellowRed")
60 .SetGroupName ("Ccnx")
Alexander Afanasyev786936a2012-07-17 19:48:15 -070061 .SetParent<Nacks> ()
Alexander Afanasyev996b4872012-07-17 17:07:56 -070062
63 ;
64 return tid;
65}
66
67bool
68GreenYellowRed::DoPropagateInterest (const Ptr<CcnxFace> &incomingFace,
69 Ptr<CcnxInterestHeader> &header,
70 const Ptr<const Packet> &packet,
71 Ptr<CcnxPitEntry> pitEntry)
72{
73 NS_LOG_FUNCTION (this);
74 NS_ASSERT_MSG (m_pit != 0, "PIT should be aggregated with forwarding strategy");
75
76 int propagatedCount = 0;
77
78 BOOST_FOREACH (const CcnxFibFaceMetric &metricFace, pitEntry->GetFibEntry ()->m_faces.get<i_metric> ())
79 {
80 if (metricFace.m_status == CcnxFibFaceMetric::NDN_FIB_RED ||
81 metricFace.m_status == CcnxFibFaceMetric::NDN_FIB_YELLOW)
82 break; //propagate only to green faces
83
84 if (pitEntry->GetIncoming ().find (metricFace.m_face) != pitEntry->GetIncoming ().end ())
85 continue; // don't forward to face that we received interest from
86
87 CcnxPitEntryOutgoingFaceContainer::type::iterator outgoing =
88 pitEntry->GetOutgoing ().find (metricFace.m_face);
89
90 if (outgoing != pitEntry->GetOutgoing ().end () &&
91 outgoing->m_retxCount >= pitEntry->GetMaxRetxCount ())
92 {
93 NS_LOG_DEBUG ("retxCount: " << outgoing->m_retxCount << ", maxRetxCount: " << pitEntry->GetMaxRetxCount ());
94 continue;
95 }
96
97 bool faceAvailable = metricFace.m_face->IsBelowLimit ();
98 if (!faceAvailable) // huh...
99 {
100 // let's try different green face
101 continue;
102 }
103
104 pitEntry->AddOutgoing (metricFace.m_face);
105
106 Ptr<Packet> packetToSend = packet->Copy ();
107
108 //transmission
109 metricFace.m_face->Send (packetToSend);
110 m_outInterests (header, metricFace.m_face);
111
112 propagatedCount++;
113 break; // propagate only one interest
114 }
115
116 return propagatedCount > 0;
117}
118
119void
120GreenYellowRed::WillSatisfyPendingInterest (const Ptr<CcnxFace> &incomingFace,
121 Ptr<CcnxPitEntry> pitEntry)
122{
123 // Update metric status for the incoming interface in the corresponding FIB entry
124 pitEntry->GetFibEntry ()->UpdateStatus (incomingFace, CcnxFibFaceMetric::NDN_FIB_GREEN);
125
126 super::WillSatisfyPendingInterest (incomingFace, pitEntry);
127}
128
Alexander Afanasyev786936a2012-07-17 19:48:15 -0700129void
130GreenYellowRed::DidReceiveValidNack (const Ptr<CcnxFace> &incomingFace,
131 uint32_t nackCode,
132 Ptr<CcnxPitEntry> pitEntry)
133{
134 super::DidReceiveValidNack (incomingFace, nackCode, pitEntry);
135
136 if (nackCode != CcnxInterestHeader::NACK_LOOP)
137 {
138 pitEntry->GetFibEntry ()->UpdateStatus (incomingFace, CcnxFibFaceMetric::NDN_FIB_YELLOW);
139 }
140}
141
142
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700143} // namespace ndnSIM
144} // namespace ns3