Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 1 | /* -*- 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> |
| 44 | namespace ll = boost::lambda; |
| 45 | |
| 46 | NS_LOG_COMPONENT_DEFINE ("NdnSimGreenYellowRed"); |
| 47 | |
| 48 | namespace ns3 { |
| 49 | |
| 50 | using namespace __ccnx_private; |
| 51 | |
| 52 | namespace ndnSIM { |
| 53 | |
| 54 | NS_OBJECT_ENSURE_REGISTERED (GreenYellowRed); |
| 55 | |
| 56 | TypeId |
| 57 | GreenYellowRed::GetTypeId (void) |
| 58 | { |
| 59 | static TypeId tid = TypeId ("ns3::ndnSIM::GreenYellowRed") |
| 60 | .SetGroupName ("Ccnx") |
Alexander Afanasyev | 786936a | 2012-07-17 19:48:15 -0700 | [diff] [blame] | 61 | .SetParent<Nacks> () |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 62 | |
| 63 | ; |
| 64 | return tid; |
| 65 | } |
| 66 | |
| 67 | bool |
| 68 | GreenYellowRed::DoPropagateInterest (const Ptr<CcnxFace> &incomingFace, |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame^] | 69 | Ptr<CcnxInterestHeader> header, |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 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 | |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame^] | 87 | if (!WillSendOutInterest (metricFace.m_face, header, pitEntry)) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 88 | { |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 89 | continue; |
| 90 | } |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 91 | |
| 92 | //transmission |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame^] | 93 | Ptr<Packet> packetToSend = packet->Copy (); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 94 | metricFace.m_face->Send (packetToSend); |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame^] | 95 | |
| 96 | DidSendOutInterest (metricFace.m_face, header, pitEntry); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 97 | |
| 98 | propagatedCount++; |
| 99 | break; // propagate only one interest |
| 100 | } |
| 101 | |
| 102 | return propagatedCount > 0; |
| 103 | } |
| 104 | |
| 105 | void |
| 106 | GreenYellowRed::WillSatisfyPendingInterest (const Ptr<CcnxFace> &incomingFace, |
| 107 | Ptr<CcnxPitEntry> pitEntry) |
| 108 | { |
| 109 | // Update metric status for the incoming interface in the corresponding FIB entry |
| 110 | pitEntry->GetFibEntry ()->UpdateStatus (incomingFace, CcnxFibFaceMetric::NDN_FIB_GREEN); |
| 111 | |
| 112 | super::WillSatisfyPendingInterest (incomingFace, pitEntry); |
| 113 | } |
| 114 | |
Alexander Afanasyev | 786936a | 2012-07-17 19:48:15 -0700 | [diff] [blame] | 115 | void |
| 116 | GreenYellowRed::DidReceiveValidNack (const Ptr<CcnxFace> &incomingFace, |
| 117 | uint32_t nackCode, |
| 118 | Ptr<CcnxPitEntry> pitEntry) |
| 119 | { |
| 120 | super::DidReceiveValidNack (incomingFace, nackCode, pitEntry); |
| 121 | |
| 122 | if (nackCode != CcnxInterestHeader::NACK_LOOP) |
| 123 | { |
| 124 | pitEntry->GetFibEntry ()->UpdateStatus (incomingFace, CcnxFibFaceMetric::NDN_FIB_YELLOW); |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 129 | } // namespace ndnSIM |
| 130 | } // namespace ns3 |