blob: d881b00a250b89d8152b774e708d7a70224f6faa [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,
Alexander Afanasyevf249a192012-07-18 16:52:51 -070069 Ptr<CcnxInterestHeader> header,
Alexander Afanasyev996b4872012-07-17 17:07:56 -070070 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
Alexander Afanasyevf249a192012-07-18 16:52:51 -070087 if (!WillSendOutInterest (metricFace.m_face, header, pitEntry))
Alexander Afanasyev996b4872012-07-17 17:07:56 -070088 {
Alexander Afanasyev996b4872012-07-17 17:07:56 -070089 continue;
90 }
Alexander Afanasyev996b4872012-07-17 17:07:56 -070091
92 //transmission
Alexander Afanasyevf249a192012-07-18 16:52:51 -070093 Ptr<Packet> packetToSend = packet->Copy ();
Alexander Afanasyev996b4872012-07-17 17:07:56 -070094 metricFace.m_face->Send (packetToSend);
Alexander Afanasyevf249a192012-07-18 16:52:51 -070095
96 DidSendOutInterest (metricFace.m_face, header, pitEntry);
Alexander Afanasyev996b4872012-07-17 17:07:56 -070097
98 propagatedCount++;
99 break; // propagate only one interest
100 }
101
102 return propagatedCount > 0;
103}
104
105void
106GreenYellowRed::WillSatisfyPendingInterest (const Ptr<CcnxFace> &incomingFace,
107 Ptr<CcnxPitEntry> pitEntry)
108{
Alexander Afanasyev39e0f342012-07-20 15:33:23 -0700109 if (incomingFace != 0)
110 {
111 // Update metric status for the incoming interface in the corresponding FIB entry
112 pitEntry->GetFibEntry ()->UpdateStatus (incomingFace, CcnxFibFaceMetric::NDN_FIB_GREEN);
113 }
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700114
115 super::WillSatisfyPendingInterest (incomingFace, pitEntry);
116}
117
Alexander Afanasyev786936a2012-07-17 19:48:15 -0700118void
119GreenYellowRed::DidReceiveValidNack (const Ptr<CcnxFace> &incomingFace,
120 uint32_t nackCode,
121 Ptr<CcnxPitEntry> pitEntry)
122{
123 super::DidReceiveValidNack (incomingFace, nackCode, pitEntry);
124
Alexander Afanasyev39e0f342012-07-20 15:33:23 -0700125 if (incomingFace != 0 &&
126 nackCode != CcnxInterestHeader::NACK_LOOP)
Alexander Afanasyev786936a2012-07-17 19:48:15 -0700127 {
128 pitEntry->GetFibEntry ()->UpdateStatus (incomingFace, CcnxFibFaceMetric::NDN_FIB_YELLOW);
129 }
130}
131
132
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700133} // namespace ndnSIM
134} // namespace ns3