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 | */ |
| 20 | |
| 21 | #include "nacks.h" |
| 22 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 23 | #include "ns3/ndn-pit.h" |
| 24 | #include "ns3/ndn-pit-entry.h" |
Alexander Afanasyev | bd9c18e | 2012-11-19 15:23:41 -0800 | [diff] [blame] | 25 | #include "ns3/ndn-interest.h" |
| 26 | #include "ns3/ndn-content-object.h" |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 27 | #include "ns3/ndn-pit.h" |
| 28 | #include "ns3/ndn-fib.h" |
| 29 | #include "ns3/ndn-content-store.h" |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 30 | |
| 31 | #include "ns3/assert.h" |
| 32 | #include "ns3/ptr.h" |
| 33 | #include "ns3/log.h" |
| 34 | #include "ns3/simulator.h" |
| 35 | #include "ns3/boolean.h" |
| 36 | #include "ns3/string.h" |
| 37 | |
| 38 | #include <boost/ref.hpp> |
| 39 | #include <boost/foreach.hpp> |
| 40 | #include <boost/lambda/lambda.hpp> |
| 41 | #include <boost/lambda/bind.hpp> |
| 42 | #include <boost/tuple/tuple.hpp> |
| 43 | namespace ll = boost::lambda; |
| 44 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 45 | NS_LOG_COMPONENT_DEFINE ("ndn.fw.Nacks"); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 46 | |
| 47 | namespace ns3 { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 48 | namespace ndn { |
| 49 | namespace fw { |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 50 | |
| 51 | NS_OBJECT_ENSURE_REGISTERED (Nacks); |
| 52 | |
| 53 | TypeId |
| 54 | Nacks::GetTypeId (void) |
| 55 | { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 56 | static TypeId tid = TypeId ("ns3::ndn::fw::Nacks") |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 57 | .SetGroupName ("Ndn") |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 58 | .SetParent<ForwardingStrategy> () |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame^] | 59 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 60 | //////////////////////////////////////////////////////////////////// |
| 61 | //////////////////////////////////////////////////////////////////// |
| 62 | |
| 63 | .AddTraceSource ("OutNacks", "OutNacks", MakeTraceSourceAccessor (&Nacks::m_outNacks)) |
| 64 | .AddTraceSource ("InNacks", "InNacks", MakeTraceSourceAccessor (&Nacks::m_inNacks)) |
| 65 | .AddTraceSource ("DropNacks", "DropNacks", MakeTraceSourceAccessor (&Nacks::m_dropNacks)) |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame^] | 66 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 67 | .AddAttribute ("EnableNACKs", "Enabling support of NACKs", |
| 68 | BooleanValue (false), |
| 69 | MakeBooleanAccessor (&Nacks::m_nacksEnabled), |
| 70 | MakeBooleanChecker ()) |
| 71 | ; |
| 72 | return tid; |
| 73 | } |
| 74 | |
| 75 | void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 76 | Nacks::OnInterest (Ptr<Face> inFace, |
| 77 | Ptr<const InterestHeader> header, |
| 78 | Ptr<const Packet> origPacket) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 79 | { |
| 80 | if (header->GetNack () > 0) |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 81 | OnNack (inFace, header, origPacket/*original packet*/); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 82 | else |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame^] | 83 | super::OnInterest (inFace, header, origPacket/*original packet*/); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 87 | Nacks::OnNack (Ptr<Face> inFace, |
| 88 | Ptr<const InterestHeader> header, |
| 89 | Ptr<const Packet> origPacket) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 90 | { |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame^] | 91 | // NS_LOG_FUNCTION (inFace << header->GetName ()); |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 92 | m_inNacks (header, inFace); |
Alexander Afanasyev | 786936a | 2012-07-17 19:48:15 -0700 | [diff] [blame] | 93 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 94 | Ptr<pit::Entry> pitEntry = m_pit->Lookup (*header); |
Alexander Afanasyev | 786936a | 2012-07-17 19:48:15 -0700 | [diff] [blame] | 95 | if (pitEntry == 0) |
| 96 | { |
| 97 | // somebody is doing something bad |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 98 | m_dropNacks (header, inFace); |
Alexander Afanasyev | 786936a | 2012-07-17 19:48:15 -0700 | [diff] [blame] | 99 | return; |
| 100 | } |
Alexander Afanasyev | 786936a | 2012-07-17 19:48:15 -0700 | [diff] [blame] | 101 | |
Alexander Afanasyev | 0484e77 | 2012-10-29 11:02:08 -0700 | [diff] [blame] | 102 | DidReceiveValidNack (inFace, header->GetNack (), header, origPacket, pitEntry); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 106 | Nacks::DidReceiveDuplicateInterest (Ptr<Face> inFace, |
| 107 | Ptr<const InterestHeader> header, |
| 108 | Ptr<const Packet> origPacket, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 109 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 110 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 111 | super::DidReceiveDuplicateInterest (inFace, header, origPacket, pitEntry); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 112 | |
| 113 | if (m_nacksEnabled) |
| 114 | { |
| 115 | NS_LOG_DEBUG ("Sending NACK_LOOP"); |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 116 | Ptr<InterestHeader> nackHeader = Create<InterestHeader> (*header); |
| 117 | nackHeader->SetNack (InterestHeader::NACK_LOOP); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 118 | Ptr<Packet> nack = Create<Packet> (); |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 119 | nack->AddHeader (*nackHeader); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 120 | |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 121 | inFace->Send (nack); |
| 122 | m_outNacks (nackHeader, inFace); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 123 | } |
| 124 | } |
| 125 | |
| 126 | void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 127 | Nacks::DidExhaustForwardingOptions (Ptr<Face> inFace, |
| 128 | Ptr<const InterestHeader> header, |
| 129 | Ptr<const Packet> origPacket, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 130 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 131 | { |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 132 | if (m_nacksEnabled) |
| 133 | { |
| 134 | Ptr<Packet> packet = Create<Packet> (); |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 135 | Ptr<InterestHeader> nackHeader = Create<InterestHeader> (*header); |
| 136 | nackHeader->SetNack (InterestHeader::NACK_GIVEUP_PIT); |
| 137 | packet->AddHeader (*nackHeader); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 138 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 139 | BOOST_FOREACH (const pit::IncomingFace &incoming, pitEntry->GetIncoming ()) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 140 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 141 | NS_LOG_DEBUG ("Send NACK for " << boost::cref (nackHeader->GetName ()) << " to " << boost::cref (*incoming.m_face)); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 142 | incoming.m_face->Send (packet->Copy ()); |
| 143 | |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 144 | m_outNacks (nackHeader, incoming.m_face); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 145 | } |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame^] | 146 | |
| 147 | pitEntry->ClearOutgoing (); // to force erasure of the record |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 148 | } |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame^] | 149 | |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 150 | super::DidExhaustForwardingOptions (inFace, header, origPacket, pitEntry); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 151 | } |
| 152 | |
Alexander Afanasyev | 786936a | 2012-07-17 19:48:15 -0700 | [diff] [blame] | 153 | void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 154 | Nacks::DidReceiveValidNack (Ptr<Face> inFace, |
Alexander Afanasyev | 786936a | 2012-07-17 19:48:15 -0700 | [diff] [blame] | 155 | uint32_t nackCode, |
Alexander Afanasyev | 0484e77 | 2012-10-29 11:02:08 -0700 | [diff] [blame] | 156 | Ptr<const InterestHeader> header, |
| 157 | Ptr<const Packet> origPacket, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 158 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | 786936a | 2012-07-17 19:48:15 -0700 | [diff] [blame] | 159 | { |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame^] | 160 | NS_LOG_DEBUG ("nackCode: " << nackCode << " for [" << header->GetName () << "]"); |
| 161 | |
Alexander Afanasyev | 786936a | 2012-07-17 19:48:15 -0700 | [diff] [blame] | 162 | // If NACK is NACK_GIVEUP_PIT, then neighbor gave up trying to and removed it's PIT entry. |
| 163 | // So, if we had an incoming entry to this neighbor, then we can remove it now |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 164 | if (nackCode == InterestHeader::NACK_GIVEUP_PIT) |
Alexander Afanasyev | 786936a | 2012-07-17 19:48:15 -0700 | [diff] [blame] | 165 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 166 | pitEntry->RemoveIncoming (inFace); |
Alexander Afanasyev | 786936a | 2012-07-17 19:48:15 -0700 | [diff] [blame] | 167 | } |
| 168 | |
Alexander Afanasyev | 0484e77 | 2012-10-29 11:02:08 -0700 | [diff] [blame] | 169 | if (nackCode == InterestHeader::NACK_LOOP || |
| 170 | nackCode == InterestHeader::NACK_CONGESTION || |
| 171 | nackCode == InterestHeader::NACK_GIVEUP_PIT) |
| 172 | { |
| 173 | pitEntry->SetWaitingInVain (inFace); |
| 174 | |
| 175 | if (!pitEntry->AreAllOutgoingInVain ()) // not all ougtoing are in vain |
| 176 | { |
| 177 | NS_LOG_DEBUG ("Not all outgoing are in vain"); |
| 178 | // suppress |
| 179 | // Don't do anything, we are still expecting data from some other face |
| 180 | m_dropNacks (header, inFace); |
| 181 | return; |
| 182 | } |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame^] | 183 | |
Alexander Afanasyev | 0484e77 | 2012-10-29 11:02:08 -0700 | [diff] [blame] | 184 | Ptr<Packet> nonNackInterest = Create<Packet> (); |
| 185 | Ptr<InterestHeader> nonNackHeader = Create<InterestHeader> (*header); |
| 186 | nonNackHeader->SetNack (InterestHeader::NORMAL_INTEREST); |
| 187 | nonNackInterest->AddHeader (*nonNackHeader); |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame^] | 188 | |
Alexander Afanasyev | 0484e77 | 2012-10-29 11:02:08 -0700 | [diff] [blame] | 189 | bool propagated = DoPropagateInterest (inFace, nonNackHeader, nonNackInterest, pitEntry); |
| 190 | if (!propagated) |
| 191 | { |
| 192 | DidExhaustForwardingOptions (inFace, nonNackHeader, nonNackInterest, pitEntry); |
| 193 | } |
| 194 | } |
Alexander Afanasyev | 786936a | 2012-07-17 19:48:15 -0700 | [diff] [blame] | 195 | } |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 196 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 197 | } // namespace fw |
| 198 | } // namespace ndn |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 199 | } // namespace ns3 |