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 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 24 | #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 Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 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 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 46 | NS_LOG_COMPONENT_DEFINE ("ndn.fw.GreenYellowRed"); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 47 | |
| 48 | namespace ns3 { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 49 | namespace ndn { |
| 50 | namespace fw { |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 51 | |
| 52 | NS_OBJECT_ENSURE_REGISTERED (GreenYellowRed); |
| 53 | |
| 54 | TypeId |
| 55 | GreenYellowRed::GetTypeId (void) |
| 56 | { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 57 | static TypeId tid = TypeId ("ns3::ndn::fw::GreenYellowRed") |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 58 | .SetGroupName ("Ndn") |
Alexander Afanasyev | 786936a | 2012-07-17 19:48:15 -0700 | [diff] [blame] | 59 | .SetParent<Nacks> () |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 60 | |
| 61 | ; |
| 62 | return tid; |
| 63 | } |
| 64 | |
| 65 | bool |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 66 | GreenYellowRed::DoPropagateInterest (const Ptr<Face> &incomingFace, |
| 67 | Ptr<InterestHeader> header, |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 68 | const Ptr<const Packet> &packet, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 69 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 70 | { |
| 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 Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 76 | BOOST_FOREACH (const fib::FaceMetric &metricFace, pitEntry->GetFibEntry ()->m_faces.get<fib::i_metric> ()) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 77 | { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 78 | if (metricFace.m_status == fib::FaceMetric::NDN_FIB_RED || |
| 79 | metricFace.m_status == fib::FaceMetric::NDN_FIB_YELLOW) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 80 | 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 Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 85 | if (!WillSendOutInterest (metricFace.m_face, header, pitEntry)) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 86 | { |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 87 | continue; |
| 88 | } |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 89 | |
| 90 | //transmission |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 91 | Ptr<Packet> packetToSend = packet->Copy (); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 92 | metricFace.m_face->Send (packetToSend); |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 93 | |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 94 | DidSendOutInterest (metricFace.m_face, header, packet, pitEntry); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 95 | |
| 96 | propagatedCount++; |
| 97 | break; // propagate only one interest |
| 98 | } |
| 99 | |
| 100 | return propagatedCount > 0; |
| 101 | } |
| 102 | |
| 103 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 104 | GreenYellowRed::WillSatisfyPendingInterest (const Ptr<Face> &incomingFace, |
| 105 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 106 | { |
Alexander Afanasyev | 39e0f34 | 2012-07-20 15:33:23 -0700 | [diff] [blame] | 107 | if (incomingFace != 0) |
| 108 | { |
| 109 | // Update metric status for the incoming interface in the corresponding FIB entry |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 110 | pitEntry->GetFibEntry ()->UpdateStatus (incomingFace, fib::FaceMetric::NDN_FIB_GREEN); |
Alexander Afanasyev | 39e0f34 | 2012-07-20 15:33:23 -0700 | [diff] [blame] | 111 | } |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 112 | |
| 113 | super::WillSatisfyPendingInterest (incomingFace, pitEntry); |
| 114 | } |
| 115 | |
Alexander Afanasyev | 786936a | 2012-07-17 19:48:15 -0700 | [diff] [blame] | 116 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 117 | GreenYellowRed::DidReceiveValidNack (const Ptr<Face> &incomingFace, |
Alexander Afanasyev | 786936a | 2012-07-17 19:48:15 -0700 | [diff] [blame] | 118 | uint32_t nackCode, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 119 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | 786936a | 2012-07-17 19:48:15 -0700 | [diff] [blame] | 120 | { |
| 121 | super::DidReceiveValidNack (incomingFace, nackCode, pitEntry); |
| 122 | |
Alexander Afanasyev | 39e0f34 | 2012-07-20 15:33:23 -0700 | [diff] [blame] | 123 | if (incomingFace != 0 && |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 124 | nackCode != InterestHeader::NACK_LOOP) |
Alexander Afanasyev | 786936a | 2012-07-17 19:48:15 -0700 | [diff] [blame] | 125 | { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 126 | pitEntry->GetFibEntry ()->UpdateStatus (incomingFace, fib::FaceMetric::NDN_FIB_YELLOW); |
Alexander Afanasyev | 786936a | 2012-07-17 19:48:15 -0700 | [diff] [blame] | 127 | } |
| 128 | } |
| 129 | |
| 130 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 131 | } // namespace fw |
| 132 | } // namespace ndn |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 133 | } // namespace ns3 |