blob: f13b29b7efbf6c010e1513c560d60765b00c8385 [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
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070024#include "ns3/ndn-pit.h"
25#include "ns3/ndn-pit-entry.h"
26#include "ns3/ndn-interest-header.h"
27#include "ns3/ndn-content-object-header.h"
28#include "ns3/ndn-pit.h"
29#include "ns3/ndn-fib.h"
30#include "ns3/ndn-content-store.h"
Alexander Afanasyev996b4872012-07-17 17:07:56 -070031
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
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070046NS_LOG_COMPONENT_DEFINE ("ndn.fw.GreenYellowRed");
Alexander Afanasyev996b4872012-07-17 17:07:56 -070047
48namespace ns3 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070049namespace ndn {
50namespace fw {
Alexander Afanasyev996b4872012-07-17 17:07:56 -070051
52NS_OBJECT_ENSURE_REGISTERED (GreenYellowRed);
53
54TypeId
55GreenYellowRed::GetTypeId (void)
56{
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070057 static TypeId tid = TypeId ("ns3::ndn::fw::GreenYellowRed")
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070058 .SetGroupName ("Ndn")
Alexander Afanasyev786936a2012-07-17 19:48:15 -070059 .SetParent<Nacks> ()
Alexander Afanasyev996b4872012-07-17 17:07:56 -070060
61 ;
62 return tid;
63}
64
65bool
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070066GreenYellowRed::DoPropagateInterest (Ptr<Face> inFace,
67 Ptr<const InterestHeader> header,
68 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070069 Ptr<pit::Entry> pitEntry)
Alexander Afanasyev996b4872012-07-17 17:07:56 -070070{
71 NS_LOG_FUNCTION (this);
72 NS_ASSERT_MSG (m_pit != 0, "PIT should be aggregated with forwarding strategy");
73
74 int propagatedCount = 0;
75
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070076 BOOST_FOREACH (const fib::FaceMetric &metricFace, pitEntry->GetFibEntry ()->m_faces.get<fib::i_metric> ())
Alexander Afanasyev996b4872012-07-17 17:07:56 -070077 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070078 if (metricFace.m_status == fib::FaceMetric::NDN_FIB_RED ||
79 metricFace.m_status == fib::FaceMetric::NDN_FIB_YELLOW)
Alexander Afanasyev996b4872012-07-17 17:07:56 -070080 break; //propagate only to green faces
81
82 if (pitEntry->GetIncoming ().find (metricFace.m_face) != pitEntry->GetIncoming ().end ())
83 continue; // don't forward to face that we received interest from
84
Alexander Afanasyevf249a192012-07-18 16:52:51 -070085 if (!WillSendOutInterest (metricFace.m_face, header, pitEntry))
Alexander Afanasyev996b4872012-07-17 17:07:56 -070086 {
Alexander Afanasyev996b4872012-07-17 17:07:56 -070087 continue;
88 }
Alexander Afanasyev996b4872012-07-17 17:07:56 -070089
90 //transmission
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070091 Ptr<Packet> packetToSend = origPacket->Copy ();
Alexander Afanasyev996b4872012-07-17 17:07:56 -070092 metricFace.m_face->Send (packetToSend);
Alexander Afanasyevf249a192012-07-18 16:52:51 -070093
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070094 DidSendOutInterest (metricFace.m_face, header, origPacket, pitEntry);
Alexander Afanasyev996b4872012-07-17 17:07:56 -070095
96 propagatedCount++;
97 break; // propagate only one interest
98 }
99
100 return propagatedCount > 0;
101}
102
103void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700104GreenYellowRed::WillSatisfyPendingInterest (Ptr<Face> inFace,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700105 Ptr<pit::Entry> pitEntry)
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700106{
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700107 if (inFace != 0)
Alexander Afanasyev39e0f342012-07-20 15:33:23 -0700108 {
109 // Update metric status for the incoming interface in the corresponding FIB entry
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700110 pitEntry->GetFibEntry ()->UpdateStatus (inFace, fib::FaceMetric::NDN_FIB_GREEN);
Alexander Afanasyev39e0f342012-07-20 15:33:23 -0700111 }
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700112
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700113 super::WillSatisfyPendingInterest (inFace, pitEntry);
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700114}
115
Alexander Afanasyev786936a2012-07-17 19:48:15 -0700116void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700117GreenYellowRed::DidReceiveValidNack (Ptr<Face> inFace,
Alexander Afanasyev786936a2012-07-17 19:48:15 -0700118 uint32_t nackCode,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700119 Ptr<pit::Entry> pitEntry)
Alexander Afanasyev786936a2012-07-17 19:48:15 -0700120{
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700121 super::DidReceiveValidNack (inFace, nackCode, pitEntry);
Alexander Afanasyev786936a2012-07-17 19:48:15 -0700122
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700123 if (inFace != 0 &&
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700124 nackCode != InterestHeader::NACK_LOOP)
Alexander Afanasyev786936a2012-07-17 19:48:15 -0700125 {
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700126 pitEntry->GetFibEntry ()->UpdateStatus (inFace, fib::FaceMetric::NDN_FIB_YELLOW);
Alexander Afanasyev786936a2012-07-17 19:48:15 -0700127 }
128}
129
130
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700131} // namespace fw
132} // namespace ndn
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700133} // namespace ns3