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 | |
| 23 | #include "ns3/ccnx-pit.h" |
| 24 | #include "ns3/ccnx-pit-entry.h" |
| 25 | #include "ns3/ccnx-interest-header.h" |
| 26 | #include "ns3/ccnx-content-object-header.h" |
| 27 | #include "ns3/ccnx-pit.h" |
| 28 | #include "ns3/ccnx-fib.h" |
| 29 | #include "ns3/ccnx-content-store.h" |
| 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") |
| 56 | .SetGroupName ("Ccnx") |
| 57 | .SetParent<CcnxForwardingStrategy> () |
| 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 |
| 75 | Nacks::OnInterest (const Ptr<CcnxFace> &incomingFace, |
| 76 | Ptr<CcnxInterestHeader> &header, |
| 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 |
| 86 | Nacks::OnNack (const Ptr<CcnxFace> &face, |
| 87 | Ptr<CcnxInterestHeader> &header, |
| 88 | const Ptr<const Packet> &p) |
| 89 | { |
| 90 | NS_ASSERT (false); |
| 91 | } |
| 92 | |
| 93 | void |
| 94 | Nacks::DidReceiveDuplicateInterest (const Ptr<CcnxFace> &incomingFace, |
| 95 | Ptr<CcnxInterestHeader> &header, |
| 96 | const Ptr<const Packet> &packet, |
| 97 | Ptr<CcnxPitEntry> pitEntry) |
| 98 | { |
| 99 | super::DidReceiveDuplicateInterest (incomingFace, header, packet, pitEntry); |
| 100 | |
| 101 | if (m_nacksEnabled) |
| 102 | { |
| 103 | NS_LOG_DEBUG ("Sending NACK_LOOP"); |
| 104 | header->SetNack (CcnxInterestHeader::NACK_LOOP); |
| 105 | Ptr<Packet> nack = Create<Packet> (); |
| 106 | nack->AddHeader (*header); |
| 107 | |
| 108 | incomingFace->Send (nack); |
| 109 | m_outNacks (header, incomingFace); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | void |
| 114 | Nacks::DidExhaustForwardingOptions (const Ptr<CcnxFace> &incomingFace, |
| 115 | Ptr<CcnxInterestHeader> header, |
| 116 | const Ptr<const Packet> &packet, |
| 117 | Ptr<CcnxPitEntry> pitEntry) |
| 118 | { |
| 119 | super::DidExhaustForwardingOptions (incomingFace, header, packet, pitEntry); |
| 120 | |
| 121 | if (m_nacksEnabled) |
| 122 | { |
| 123 | Ptr<Packet> packet = Create<Packet> (); |
| 124 | header->SetNack (CcnxInterestHeader::NACK_GIVEUP_PIT); |
| 125 | packet->AddHeader (*header); |
| 126 | |
| 127 | BOOST_FOREACH (const CcnxPitEntryIncomingFace &incoming, pitEntry->GetIncoming ()) |
| 128 | { |
| 129 | NS_LOG_DEBUG ("Send NACK for " << boost::cref (header->GetName ()) << " to " << boost::cref (*incoming.m_face)); |
| 130 | incoming.m_face->Send (packet->Copy ()); |
| 131 | |
| 132 | m_outNacks (header, incoming.m_face); |
| 133 | } |
| 134 | |
| 135 | // All incoming interests cannot be satisfied. Remove them |
| 136 | pitEntry->ClearIncoming (); |
| 137 | |
| 138 | // Remove also outgoing |
| 139 | pitEntry->ClearOutgoing (); |
| 140 | |
| 141 | // Set pruning timout on PIT entry (instead of deleting the record) |
| 142 | m_pit->MarkErased (pitEntry); |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | |
| 147 | } // namespace ndnSIM |
| 148 | } // namespace ns3 |