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" |
Xiaoke Jiang | a732541 | 2013-03-10 00:25:12 +0800 | [diff] [blame] | 30 | #include "ns3/ndnSIM/utils/ndn-fw-hop-count-tag.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.Nacks"); |
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 (Nacks); |
| 53 | |
| 54 | TypeId |
| 55 | Nacks::GetTypeId (void) |
| 56 | { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 57 | static TypeId tid = TypeId ("ns3::ndn::fw::Nacks") |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 58 | .SetGroupName ("Ndn") |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 59 | .SetParent<ForwardingStrategy> () |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 60 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 61 | //////////////////////////////////////////////////////////////////// |
| 62 | //////////////////////////////////////////////////////////////////// |
| 63 | |
| 64 | .AddTraceSource ("OutNacks", "OutNacks", MakeTraceSourceAccessor (&Nacks::m_outNacks)) |
| 65 | .AddTraceSource ("InNacks", "InNacks", MakeTraceSourceAccessor (&Nacks::m_inNacks)) |
| 66 | .AddTraceSource ("DropNacks", "DropNacks", MakeTraceSourceAccessor (&Nacks::m_dropNacks)) |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 67 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 68 | .AddAttribute ("EnableNACKs", "Enabling support of NACKs", |
| 69 | BooleanValue (false), |
| 70 | MakeBooleanAccessor (&Nacks::m_nacksEnabled), |
| 71 | MakeBooleanChecker ()) |
| 72 | ; |
| 73 | return tid; |
| 74 | } |
| 75 | |
| 76 | void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 77 | Nacks::OnInterest (Ptr<Face> inFace, |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 78 | Ptr<Interest> interest) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 79 | { |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 80 | if (interest->GetNack () > 0) |
Alexander Afanasyev | faa01f9 | 2013-07-10 18:34:31 -0700 | [diff] [blame] | 81 | OnNack (inFace, interest); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 82 | else |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 83 | super::OnInterest (inFace, interest); |
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, |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 88 | Ptr<Interest> nack) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 89 | { |
Alexander Afanasyev | faa01f9 | 2013-07-10 18:34:31 -0700 | [diff] [blame] | 90 | // NS_LOG_FUNCTION (inFace << nack->GetName ()); |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 91 | m_inNacks (nack, inFace); |
Alexander Afanasyev | 786936a | 2012-07-17 19:48:15 -0700 | [diff] [blame] | 92 | |
Alexander Afanasyev | faa01f9 | 2013-07-10 18:34:31 -0700 | [diff] [blame] | 93 | Ptr<pit::Entry> pitEntry = m_pit->Lookup (*nack); |
Alexander Afanasyev | 786936a | 2012-07-17 19:48:15 -0700 | [diff] [blame] | 94 | if (pitEntry == 0) |
| 95 | { |
| 96 | // somebody is doing something bad |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 97 | m_dropNacks (nack, inFace); |
Alexander Afanasyev | 786936a | 2012-07-17 19:48:15 -0700 | [diff] [blame] | 98 | return; |
| 99 | } |
Alexander Afanasyev | 786936a | 2012-07-17 19:48:15 -0700 | [diff] [blame] | 100 | |
Alexander Afanasyev | faa01f9 | 2013-07-10 18:34:31 -0700 | [diff] [blame] | 101 | DidReceiveValidNack (inFace, nack->GetNack (), nack, pitEntry); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 105 | Nacks::DidReceiveDuplicateInterest (Ptr<Face> inFace, |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 106 | Ptr<const Interest> interest, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 107 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 108 | { |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 109 | super::DidReceiveDuplicateInterest (inFace, interest, pitEntry); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 110 | |
| 111 | if (m_nacksEnabled) |
| 112 | { |
| 113 | NS_LOG_DEBUG ("Sending NACK_LOOP"); |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 114 | Ptr<Interest> nack = Create<Interest> (*interest); |
| 115 | nack->SetNack (Interest::NACK_LOOP); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 116 | |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 117 | inFace->SendInterest (nack); |
| 118 | m_outNacks (nack, inFace); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 119 | } |
| 120 | } |
| 121 | |
| 122 | void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 123 | Nacks::DidExhaustForwardingOptions (Ptr<Face> inFace, |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 124 | Ptr<const Interest> interest, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 125 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 126 | { |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 127 | if (m_nacksEnabled) |
| 128 | { |
Alexander Afanasyev | faa01f9 | 2013-07-10 18:34:31 -0700 | [diff] [blame] | 129 | Ptr<Interest> nack = Create<Interest> (*interest); |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 130 | nack->SetNack (Interest::NACK_GIVEUP_PIT); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 131 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 132 | BOOST_FOREACH (const pit::IncomingFace &incoming, pitEntry->GetIncoming ()) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 133 | { |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 134 | NS_LOG_DEBUG ("Send NACK for " << boost::cref (nack->GetName ()) << " to " << boost::cref (*incoming.m_face)); |
| 135 | incoming.m_face->SendInterest (nack); |
| 136 | m_outNacks (nack, incoming.m_face); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 137 | } |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 138 | |
| 139 | pitEntry->ClearOutgoing (); // to force erasure of the record |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 140 | } |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 141 | |
Alexander Afanasyev | faa01f9 | 2013-07-10 18:34:31 -0700 | [diff] [blame] | 142 | super::DidExhaustForwardingOptions (inFace, interest, pitEntry); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 143 | } |
| 144 | |
Alexander Afanasyev | 786936a | 2012-07-17 19:48:15 -0700 | [diff] [blame] | 145 | void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 146 | Nacks::DidReceiveValidNack (Ptr<Face> inFace, |
Alexander Afanasyev | 786936a | 2012-07-17 19:48:15 -0700 | [diff] [blame] | 147 | uint32_t nackCode, |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 148 | Ptr<const Interest> nack, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 149 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | 786936a | 2012-07-17 19:48:15 -0700 | [diff] [blame] | 150 | { |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 151 | NS_LOG_DEBUG ("nackCode: " << nackCode << " for [" << nack->GetName () << "]"); |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 152 | |
Alexander Afanasyev | 786936a | 2012-07-17 19:48:15 -0700 | [diff] [blame] | 153 | // If NACK is NACK_GIVEUP_PIT, then neighbor gave up trying to and removed it's PIT entry. |
| 154 | // So, if we had an incoming entry to this neighbor, then we can remove it now |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 155 | if (nackCode == Interest::NACK_GIVEUP_PIT) |
Alexander Afanasyev | 786936a | 2012-07-17 19:48:15 -0700 | [diff] [blame] | 156 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 157 | pitEntry->RemoveIncoming (inFace); |
Alexander Afanasyev | 786936a | 2012-07-17 19:48:15 -0700 | [diff] [blame] | 158 | } |
| 159 | |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 160 | if (nackCode == Interest::NACK_LOOP || |
| 161 | nackCode == Interest::NACK_CONGESTION || |
| 162 | nackCode == Interest::NACK_GIVEUP_PIT) |
Alexander Afanasyev | 0484e77 | 2012-10-29 11:02:08 -0700 | [diff] [blame] | 163 | { |
| 164 | pitEntry->SetWaitingInVain (inFace); |
| 165 | |
| 166 | if (!pitEntry->AreAllOutgoingInVain ()) // not all ougtoing are in vain |
| 167 | { |
| 168 | NS_LOG_DEBUG ("Not all outgoing are in vain"); |
| 169 | // suppress |
| 170 | // Don't do anything, we are still expecting data from some other face |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 171 | m_dropNacks (nack, inFace); |
Alexander Afanasyev | 0484e77 | 2012-10-29 11:02:08 -0700 | [diff] [blame] | 172 | return; |
| 173 | } |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 174 | |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 175 | Ptr<Interest> interest = Create<Interest> (*nack); |
| 176 | interest->SetNack (Interest::NORMAL_INTEREST); |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 177 | |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 178 | bool propagated = DoPropagateInterest (inFace, interest, pitEntry); |
Alexander Afanasyev | 0484e77 | 2012-10-29 11:02:08 -0700 | [diff] [blame] | 179 | if (!propagated) |
| 180 | { |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 181 | DidExhaustForwardingOptions (inFace, interest, pitEntry); |
Alexander Afanasyev | 0484e77 | 2012-10-29 11:02:08 -0700 | [diff] [blame] | 182 | } |
| 183 | } |
Alexander Afanasyev | 786936a | 2012-07-17 19:48:15 -0700 | [diff] [blame] | 184 | } |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 185 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 186 | } // namespace fw |
| 187 | } // namespace ndn |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 188 | } // namespace ns3 |