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" |
| 25 | #include "ns3/ndn-interest-header.h" |
| 26 | #include "ns3/ndn-content-object-header.h" |
| 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 | |
| 45 | NS_LOG_COMPONENT_DEFINE ("NdnSimNacks"); |
| 46 | |
| 47 | namespace ns3 { |
| 48 | namespace ndnSIM { |
| 49 | |
| 50 | NS_OBJECT_ENSURE_REGISTERED (Nacks); |
| 51 | |
| 52 | TypeId |
| 53 | Nacks::GetTypeId (void) |
| 54 | { |
| 55 | static TypeId tid = TypeId ("ns3::ndnSIM::Nacks") |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame^] | 56 | .SetGroupName ("Ndn") |
| 57 | .SetParent<NdnForwardingStrategy> () |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 58 | |
| 59 | //////////////////////////////////////////////////////////////////// |
| 60 | //////////////////////////////////////////////////////////////////// |
| 61 | |
| 62 | .AddTraceSource ("OutNacks", "OutNacks", MakeTraceSourceAccessor (&Nacks::m_outNacks)) |
| 63 | .AddTraceSource ("InNacks", "InNacks", MakeTraceSourceAccessor (&Nacks::m_inNacks)) |
| 64 | .AddTraceSource ("DropNacks", "DropNacks", MakeTraceSourceAccessor (&Nacks::m_dropNacks)) |
| 65 | |
| 66 | .AddAttribute ("EnableNACKs", "Enabling support of NACKs", |
| 67 | BooleanValue (false), |
| 68 | MakeBooleanAccessor (&Nacks::m_nacksEnabled), |
| 69 | MakeBooleanChecker ()) |
| 70 | ; |
| 71 | return tid; |
| 72 | } |
| 73 | |
| 74 | void |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame^] | 75 | Nacks::OnInterest (const Ptr<NdnFace> &incomingFace, |
| 76 | Ptr<NdnInterestHeader> &header, |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 77 | const Ptr<const Packet> &packet) |
| 78 | { |
| 79 | if (header->GetNack () > 0) |
| 80 | OnNack (incomingFace, header, packet/*original packet*/); |
| 81 | else |
| 82 | super::OnInterest (incomingFace, header, packet/*original packet*/); |
| 83 | } |
| 84 | |
| 85 | void |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame^] | 86 | Nacks::OnNack (const Ptr<NdnFace> &incomingFace, |
| 87 | Ptr<NdnInterestHeader> &header, |
Alexander Afanasyev | 786936a | 2012-07-17 19:48:15 -0700 | [diff] [blame] | 88 | const Ptr<const Packet> &packet) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 89 | { |
Alexander Afanasyev | 786936a | 2012-07-17 19:48:15 -0700 | [diff] [blame] | 90 | NS_ASSERT (m_nacksEnabled); |
| 91 | |
| 92 | // NS_LOG_FUNCTION (incomingFace << header << packet); |
| 93 | m_inNacks (header, incomingFace); |
| 94 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame^] | 95 | Ptr<NdnPitEntry> pitEntry = m_pit->Lookup (*header); |
Alexander Afanasyev | 786936a | 2012-07-17 19:48:15 -0700 | [diff] [blame] | 96 | if (pitEntry == 0) |
| 97 | { |
| 98 | // somebody is doing something bad |
| 99 | m_dropNacks (header, incomingFace); |
| 100 | return; |
| 101 | } |
| 102 | |
| 103 | // This was done in error. Never, never do anything, except normal leakage. This way we ensure that we will not have losses, |
| 104 | // at least when there is only one client |
| 105 | // |
| 106 | // incomingFace->LeakBucketByOnePacket (); |
| 107 | |
| 108 | pitEntry->SetWaitingInVain (incomingFace); |
| 109 | |
| 110 | DidReceiveValidNack (incomingFace, header->GetNack (), pitEntry); |
| 111 | |
| 112 | if (!pitEntry->AreAllOutgoingInVain ()) // not all ougtoing are in vain |
| 113 | { |
| 114 | NS_LOG_DEBUG ("Not all outgoing are in vain"); |
| 115 | // suppress |
| 116 | // Don't do anything, we are still expecting data from some other face |
| 117 | m_dropNacks (header, incomingFace); |
| 118 | return; |
| 119 | } |
| 120 | |
| 121 | Ptr<Packet> nonNackInterest = Create<Packet> (); |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame^] | 122 | header->SetNack (NdnInterestHeader::NORMAL_INTEREST); |
Alexander Afanasyev | 786936a | 2012-07-17 19:48:15 -0700 | [diff] [blame] | 123 | nonNackInterest->AddHeader (*header); |
| 124 | |
| 125 | bool propagated = DoPropagateInterest (incomingFace, header, nonNackInterest, pitEntry); |
| 126 | if (!propagated) |
| 127 | { |
| 128 | DidExhaustForwardingOptions (incomingFace, header, nonNackInterest, pitEntry); |
| 129 | } |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | void |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame^] | 133 | Nacks::DidReceiveDuplicateInterest (const Ptr<NdnFace> &incomingFace, |
| 134 | Ptr<NdnInterestHeader> &header, |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 135 | const Ptr<const Packet> &packet, |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame^] | 136 | Ptr<NdnPitEntry> pitEntry) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 137 | { |
| 138 | super::DidReceiveDuplicateInterest (incomingFace, header, packet, pitEntry); |
| 139 | |
| 140 | if (m_nacksEnabled) |
| 141 | { |
| 142 | NS_LOG_DEBUG ("Sending NACK_LOOP"); |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame^] | 143 | header->SetNack (NdnInterestHeader::NACK_LOOP); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 144 | Ptr<Packet> nack = Create<Packet> (); |
| 145 | nack->AddHeader (*header); |
| 146 | |
| 147 | incomingFace->Send (nack); |
| 148 | m_outNacks (header, incomingFace); |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | void |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame^] | 153 | Nacks::DidExhaustForwardingOptions (const Ptr<NdnFace> &incomingFace, |
| 154 | Ptr<NdnInterestHeader> header, |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 155 | const Ptr<const Packet> &packet, |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame^] | 156 | Ptr<NdnPitEntry> pitEntry) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 157 | { |
| 158 | super::DidExhaustForwardingOptions (incomingFace, header, packet, pitEntry); |
| 159 | |
| 160 | if (m_nacksEnabled) |
| 161 | { |
| 162 | Ptr<Packet> packet = Create<Packet> (); |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame^] | 163 | header->SetNack (NdnInterestHeader::NACK_GIVEUP_PIT); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 164 | packet->AddHeader (*header); |
| 165 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame^] | 166 | BOOST_FOREACH (const NdnPitEntryIncomingFace &incoming, pitEntry->GetIncoming ()) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 167 | { |
| 168 | NS_LOG_DEBUG ("Send NACK for " << boost::cref (header->GetName ()) << " to " << boost::cref (*incoming.m_face)); |
| 169 | incoming.m_face->Send (packet->Copy ()); |
| 170 | |
| 171 | m_outNacks (header, incoming.m_face); |
| 172 | } |
| 173 | |
| 174 | // All incoming interests cannot be satisfied. Remove them |
| 175 | pitEntry->ClearIncoming (); |
| 176 | |
| 177 | // Remove also outgoing |
| 178 | pitEntry->ClearOutgoing (); |
| 179 | |
| 180 | // Set pruning timout on PIT entry (instead of deleting the record) |
| 181 | m_pit->MarkErased (pitEntry); |
| 182 | } |
| 183 | } |
| 184 | |
Alexander Afanasyev | 786936a | 2012-07-17 19:48:15 -0700 | [diff] [blame] | 185 | void |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame^] | 186 | Nacks::DidReceiveValidNack (const Ptr<NdnFace> &incomingFace, |
Alexander Afanasyev | 786936a | 2012-07-17 19:48:15 -0700 | [diff] [blame] | 187 | uint32_t nackCode, |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame^] | 188 | Ptr<NdnPitEntry> pitEntry) |
Alexander Afanasyev | 786936a | 2012-07-17 19:48:15 -0700 | [diff] [blame] | 189 | { |
| 190 | // If NACK is NACK_GIVEUP_PIT, then neighbor gave up trying to and removed it's PIT entry. |
| 191 | // So, if we had an incoming entry to this neighbor, then we can remove it now |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame^] | 192 | if (nackCode == NdnInterestHeader::NACK_GIVEUP_PIT) |
Alexander Afanasyev | 786936a | 2012-07-17 19:48:15 -0700 | [diff] [blame] | 193 | { |
| 194 | pitEntry->RemoveIncoming (incomingFace); |
| 195 | } |
| 196 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame^] | 197 | pitEntry->GetFibEntry ()->UpdateStatus (incomingFace, NdnFibFaceMetric::NDN_FIB_YELLOW); |
Alexander Afanasyev | 786936a | 2012-07-17 19:48:15 -0700 | [diff] [blame] | 198 | } |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 199 | |
| 200 | } // namespace ndnSIM |
| 201 | } // namespace ns3 |