Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 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> |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 19 | * Ilya Moiseenko <iliamo@cs.ucla.edu> |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 20 | */ |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 21 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 22 | #include "ccnx-l3-protocol.h" |
| 23 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 24 | #include "ns3/packet.h" |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 25 | #include "ns3/node.h" |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 26 | #include "ns3/log.h" |
| 27 | #include "ns3/callback.h" |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 28 | #include "ns3/uinteger.h" |
| 29 | #include "ns3/trace-source-accessor.h" |
| 30 | #include "ns3/object-vector.h" |
Alexander Afanasyev | cbe92ae | 2011-12-16 13:06:18 -0800 | [diff] [blame] | 31 | #include "ns3/pointer.h" |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 32 | #include "ns3/boolean.h" |
Alexander Afanasyev | 0782718 | 2011-12-13 01:07:32 -0800 | [diff] [blame] | 33 | #include "ns3/string.h" |
Alexander Afanasyev | 4975f73 | 2011-12-20 17:52:19 -0800 | [diff] [blame] | 34 | #include "ns3/simulator.h" |
Alexander Afanasyev | ff8c5d6 | 2012-04-25 15:14:51 -0700 | [diff] [blame] | 35 | #include "ns3/random-variable.h" |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 36 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 37 | #include "ns3/ccnx-header-helper.h" |
| 38 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 39 | #include "ccnx-face.h" |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 40 | #include "ccnx-forwarding-strategy.h" |
| 41 | #include "ccnx-interest-header.h" |
| 42 | #include "ccnx-content-object-header.h" |
| 43 | |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 44 | #include "ccnx-net-device-face.h" |
| 45 | |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 46 | #include <boost/foreach.hpp> |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 47 | #include <boost/lambda/lambda.hpp> |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 48 | #include <boost/lambda/bind.hpp> |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 49 | |
| 50 | using namespace boost::tuples; |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 51 | namespace ll = boost::lambda; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 52 | |
| 53 | NS_LOG_COMPONENT_DEFINE ("CcnxL3Protocol"); |
| 54 | |
| 55 | namespace ns3 { |
| 56 | |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 57 | const uint16_t CcnxL3Protocol::ETHERNET_FRAME_TYPE = 0x7777; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 58 | |
Alexander Afanasyev | 0782718 | 2011-12-13 01:07:32 -0800 | [diff] [blame] | 59 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 60 | NS_OBJECT_ENSURE_REGISTERED (CcnxL3Protocol); |
| 61 | |
| 62 | TypeId |
| 63 | CcnxL3Protocol::GetTypeId (void) |
| 64 | { |
| 65 | static TypeId tid = TypeId ("ns3::CcnxL3Protocol") |
| 66 | .SetParent<Ccnx> () |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 67 | .SetGroupName ("Ccnx") |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 68 | .AddConstructor<CcnxL3Protocol> () |
Alexander Afanasyev | cbe92ae | 2011-12-16 13:06:18 -0800 | [diff] [blame] | 69 | .AddAttribute ("FaceList", "List of faces associated with CCNx stack", |
| 70 | ObjectVectorValue (), |
| 71 | MakeObjectVectorAccessor (&CcnxL3Protocol::m_faces), |
| 72 | MakeObjectVectorChecker<CcnxFace> ()) |
| 73 | |
| 74 | .AddAttribute ("ForwardingStrategy", "Forwarding strategy used by CCNx stack", |
| 75 | PointerValue (), |
| 76 | MakePointerAccessor (&CcnxL3Protocol::SetForwardingStrategy, &CcnxL3Protocol::GetForwardingStrategy), |
| 77 | MakePointerChecker<CcnxForwardingStrategy> ()) |
| 78 | |
Alexander Afanasyev | bab81b1 | 2012-02-04 14:20:09 -0800 | [diff] [blame] | 79 | .AddAttribute ("EnableNACKs", "Enabling support of NACKs", |
Alexander Afanasyev | 082dbca | 2012-02-14 18:43:13 -0800 | [diff] [blame] | 80 | BooleanValue (false), |
Alexander Afanasyev | bab81b1 | 2012-02-04 14:20:09 -0800 | [diff] [blame] | 81 | MakeBooleanAccessor (&CcnxL3Protocol::m_nacksEnabled), |
| 82 | MakeBooleanChecker ()) |
Alexander Afanasyev | de00999 | 2012-02-04 18:54:54 -0800 | [diff] [blame] | 83 | .AddAttribute ("CacheUnsolicitedData", "Cache overheard data that have not been requested", |
| 84 | BooleanValue (false), |
| 85 | MakeBooleanAccessor (&CcnxL3Protocol::m_cacheUnsolicitedData), |
| 86 | MakeBooleanChecker ()) |
Alexander Afanasyev | ff8c5d6 | 2012-04-25 15:14:51 -0700 | [diff] [blame] | 87 | .AddAttribute ("RandomDataDelaying", "Delaying data processing", |
| 88 | BooleanValue (false), |
| 89 | MakeBooleanAccessor (&CcnxL3Protocol::m_delayingDataProcessing), |
| 90 | MakeBooleanChecker ()) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 91 | ; |
| 92 | return tid; |
| 93 | } |
| 94 | |
| 95 | CcnxL3Protocol::CcnxL3Protocol() |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 96 | : m_faceCounter (0) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 97 | { |
| 98 | NS_LOG_FUNCTION (this); |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 99 | |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 100 | m_pit = CreateObject<CcnxPit> (); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | CcnxL3Protocol::~CcnxL3Protocol () |
| 104 | { |
| 105 | NS_LOG_FUNCTION (this); |
| 106 | } |
| 107 | |
| 108 | void |
| 109 | CcnxL3Protocol::SetNode (Ptr<Node> node) |
| 110 | { |
| 111 | m_node = node; |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 112 | m_fib = m_node->GetObject<CcnxFib> (); |
| 113 | NS_ASSERT_MSG (m_fib != 0, "FIB should be created and aggregated to a node before calling Ccnx::SetNode"); |
| 114 | |
| 115 | m_pit->SetFib (m_fib); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | /* |
| 119 | * This method is called by AddAgregate and completes the aggregation |
| 120 | * by setting the node in the ccnx stack |
| 121 | */ |
| 122 | void |
| 123 | CcnxL3Protocol::NotifyNewAggregate () |
| 124 | { |
| 125 | if (m_node == 0) |
| 126 | { |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame^] | 127 | Ptr<Node> node = this->GetObject<Node>(); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 128 | // verify that it's a valid node and that |
| 129 | // the node has not been set before |
| 130 | if (node != 0) |
| 131 | { |
| 132 | this->SetNode (node); |
| 133 | } |
| 134 | } |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame^] | 135 | if (m_contentStore == 0) |
| 136 | { |
| 137 | m_contentStore = this->GetObject<CcnxContentStore> (); |
| 138 | } |
| 139 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 140 | Object::NotifyNewAggregate (); |
| 141 | } |
| 142 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 143 | void |
| 144 | CcnxL3Protocol::DoDispose (void) |
| 145 | { |
| 146 | NS_LOG_FUNCTION (this); |
| 147 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 148 | for (CcnxFaceList::iterator i = m_faces.begin (); i != m_faces.end (); ++i) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 149 | { |
| 150 | *i = 0; |
| 151 | } |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 152 | m_faces.clear (); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 153 | m_node = 0; |
Alexander Afanasyev | d02a5d6 | 2011-11-21 11:01:51 -0800 | [diff] [blame] | 154 | |
| 155 | // Force delete on objects |
Alexander Afanasyev | 1825285 | 2011-11-21 13:35:31 -0800 | [diff] [blame] | 156 | m_forwardingStrategy = 0; // there is a reference to PIT stored in here |
Alexander Afanasyev | d02a5d6 | 2011-11-21 11:01:51 -0800 | [diff] [blame] | 157 | m_pit = 0; |
| 158 | m_contentStore = 0; |
Alexander Afanasyev | 1825285 | 2011-11-21 13:35:31 -0800 | [diff] [blame] | 159 | m_fib = 0; |
| 160 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 161 | // m_forwardingStrategy = 0; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 162 | Object::DoDispose (); |
| 163 | } |
| 164 | |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 165 | void |
| 166 | CcnxL3Protocol::SetForwardingStrategy (Ptr<CcnxForwardingStrategy> forwardingStrategy) |
| 167 | { |
| 168 | NS_LOG_FUNCTION (this); |
| 169 | m_forwardingStrategy = forwardingStrategy; |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 170 | m_forwardingStrategy->SetPit (m_pit); |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | Ptr<CcnxForwardingStrategy> |
| 174 | CcnxL3Protocol::GetForwardingStrategy (void) const |
| 175 | { |
| 176 | return m_forwardingStrategy; |
| 177 | } |
| 178 | |
Alexander Afanasyev | 7f3e49e | 2012-04-30 00:17:07 -0700 | [diff] [blame] | 179 | Ptr<CcnxPit> |
| 180 | CcnxL3Protocol::GetPit () const |
| 181 | { |
| 182 | return m_pit; |
| 183 | } |
| 184 | |
| 185 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 186 | uint32_t |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 187 | CcnxL3Protocol::AddFace (const Ptr<CcnxFace> &face) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 188 | { |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 189 | NS_LOG_FUNCTION (this << &face); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 190 | |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 191 | face->SetId (m_faceCounter); // sets a unique ID of the face. This ID serves only informational purposes |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 192 | |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 193 | // ask face to register in lower-layer stack |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 194 | face->RegisterProtocolHandler (MakeCallback (&CcnxL3Protocol::Receive, this)); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 195 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 196 | m_faces.push_back (face); |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 197 | m_faceCounter++; |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 198 | return face->GetId (); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 201 | void |
| 202 | CcnxL3Protocol::RemoveFace (Ptr<CcnxFace> face) |
| 203 | { |
| 204 | // ask face to register in lower-layer stack |
| 205 | face->RegisterProtocolHandler (MakeNullCallback<void,const Ptr<CcnxFace>&,const Ptr<const Packet>&> ()); |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 206 | |
| 207 | // just to be on a safe side. Do the process in two steps |
Alexander Afanasyev | 4a5c2c1 | 2011-12-12 18:50:57 -0800 | [diff] [blame] | 208 | std::list<boost::reference_wrapper<const CcnxPitEntry> > entriesToRemoves; |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 209 | BOOST_FOREACH (const CcnxPitEntry &pitEntry, *m_pit) |
| 210 | { |
| 211 | m_pit->modify (m_pit->iterator_to (pitEntry), |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 212 | ll::bind (&CcnxPitEntry::RemoveAllReferencesToFace, ll::_1, face)); |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 213 | |
| 214 | // If this face is the only for the associated FIB entry, then FIB entry will be removed soon. |
| 215 | // Thus, we have to remove the whole PIT entry |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 216 | if (pitEntry.m_fibEntry.m_faces.size () == 1 && |
| 217 | pitEntry.m_fibEntry.m_faces.begin ()->m_face == face) |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 218 | { |
Alexander Afanasyev | 4a5c2c1 | 2011-12-12 18:50:57 -0800 | [diff] [blame] | 219 | entriesToRemoves.push_back (boost::cref (pitEntry)); |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 220 | } |
| 221 | } |
Alexander Afanasyev | 4a5c2c1 | 2011-12-12 18:50:57 -0800 | [diff] [blame] | 222 | BOOST_FOREACH (const CcnxPitEntry &removedEntry, entriesToRemoves) |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 223 | { |
Alexander Afanasyev | 4a5c2c1 | 2011-12-12 18:50:57 -0800 | [diff] [blame] | 224 | m_pit->erase (m_pit->iterator_to (removedEntry)); |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 225 | } |
| 226 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 227 | CcnxFaceList::iterator face_it = find (m_faces.begin(), m_faces.end(), face); |
| 228 | NS_ASSERT_MSG (face_it != m_faces.end (), "Attempt to remove face that doesn't exist"); |
| 229 | m_faces.erase (face_it); |
| 230 | } |
| 231 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 232 | Ptr<CcnxFace> |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 233 | CcnxL3Protocol::GetFace (uint32_t index) const |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 234 | { |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 235 | BOOST_FOREACH (const Ptr<CcnxFace> &face, m_faces) // this function is not supposed to be called often, so linear search is fine |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 236 | { |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 237 | if (face->GetId () == index) |
| 238 | return face; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 239 | } |
| 240 | return 0; |
| 241 | } |
| 242 | |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 243 | Ptr<CcnxFace> |
| 244 | CcnxL3Protocol::GetFaceByNetDevice (Ptr<NetDevice> netDevice) const |
| 245 | { |
| 246 | BOOST_FOREACH (const Ptr<CcnxFace> &face, m_faces) // this function is not supposed to be called often, so linear search is fine |
| 247 | { |
| 248 | Ptr<CcnxNetDeviceFace> netDeviceFace = DynamicCast<CcnxNetDeviceFace> (face); |
| 249 | if (netDeviceFace == 0) continue; |
| 250 | |
| 251 | if (netDeviceFace->GetNetDevice () == netDevice) |
| 252 | return face; |
| 253 | } |
| 254 | return 0; |
| 255 | } |
| 256 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 257 | uint32_t |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 258 | CcnxL3Protocol::GetNFaces (void) const |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 259 | { |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 260 | return m_faces.size (); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 261 | } |
| 262 | |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 263 | // Callback from lower layer |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 264 | void |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 265 | CcnxL3Protocol::Receive (const Ptr<CcnxFace> &face, const Ptr<const Packet> &p) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 266 | { |
Alexander Afanasyev | d459ec3 | 2012-04-30 13:58:20 -0700 | [diff] [blame] | 267 | if (!face->IsUp ()) |
| 268 | return; |
| 269 | |
| 270 | NS_LOG_DEBUG (*p); |
| 271 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 272 | NS_LOG_LOGIC ("Packet from face " << *face << " received on node " << m_node->GetId ()); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 273 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 274 | Ptr<Packet> packet = p->Copy (); // give upper layers a rw copy of the packet |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 275 | try |
| 276 | { |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 277 | CcnxHeaderHelper::Type type = CcnxHeaderHelper::GetCcnxHeaderType (p); |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 278 | switch (type) |
| 279 | { |
| 280 | case CcnxHeaderHelper::INTEREST: |
| 281 | { |
| 282 | Ptr<CcnxInterestHeader> header = Create<CcnxInterestHeader> (); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 283 | |
| 284 | // Deserialization. Exception may be thrown |
| 285 | packet->RemoveHeader (*header); |
| 286 | NS_ASSERT_MSG (packet->GetSize () == 0, "Payload of Interests should be zero"); |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 287 | |
| 288 | if (header->GetNack () > 0) |
| 289 | OnNack (face, header, p/*original packet*/); |
| 290 | else |
| 291 | OnInterest (face, header, p/*original packet*/); |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 292 | break; |
| 293 | } |
| 294 | case CcnxHeaderHelper::CONTENT_OBJECT: |
| 295 | { |
| 296 | Ptr<CcnxContentObjectHeader> header = Create<CcnxContentObjectHeader> (); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 297 | |
| 298 | static CcnxContentObjectTail contentObjectTrailer; //there is no data in this object |
| 299 | |
| 300 | // Deserialization. Exception may be thrown |
| 301 | packet->RemoveHeader (*header); |
| 302 | packet->RemoveTrailer (contentObjectTrailer); |
| 303 | |
| 304 | OnData (face, header, packet/*payload*/, p/*original packet*/); |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 305 | break; |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | // exception will be thrown if packet is not recognized |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 310 | } |
| 311 | catch (CcnxUnknownHeaderException) |
| 312 | { |
| 313 | NS_ASSERT_MSG (false, "Unknown CCNx header. Should not happen"); |
Alexander Afanasyev | d459ec3 | 2012-04-30 13:58:20 -0700 | [diff] [blame] | 314 | NS_LOG_ERROR ("Unknown CCNx header. Should not happen"); |
| 315 | return; |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 316 | } |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 317 | } |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 318 | |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 319 | void |
Alexander Afanasyev | 9d313d4 | 2011-11-25 13:36:15 -0800 | [diff] [blame] | 320 | CcnxL3Protocol::OnNack (const Ptr<CcnxFace> &incomingFace, |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 321 | Ptr<CcnxInterestHeader> &header, |
Alexander Afanasyev | 9d313d4 | 2011-11-25 13:36:15 -0800 | [diff] [blame] | 322 | const Ptr<const Packet> &packet) |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 323 | { |
Alexander Afanasyev | 9d313d4 | 2011-11-25 13:36:15 -0800 | [diff] [blame] | 324 | NS_LOG_FUNCTION (incomingFace << header << packet); |
Alexander Afanasyev | f377b33 | 2011-12-16 15:32:12 -0800 | [diff] [blame] | 325 | m_inNacks (header, incomingFace); |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 326 | |
Alexander Afanasyev | 9d313d4 | 2011-11-25 13:36:15 -0800 | [diff] [blame] | 327 | tuple<const CcnxPitEntry&,bool,bool> ret = m_pit->Lookup (*header); |
| 328 | CcnxPitEntry const& pitEntry = ret.get<0> (); |
Alexander Afanasyev | a7a2b8b | 2011-11-28 18:19:09 -0800 | [diff] [blame] | 329 | bool isNew = ret.get<1> (); |
Alexander Afanasyev | e67a97f | 2011-11-29 14:28:59 -0800 | [diff] [blame] | 330 | bool isDuplicated = ret.get<2> (); |
Alexander Afanasyev | 9d313d4 | 2011-11-25 13:36:15 -0800 | [diff] [blame] | 331 | |
Alexander Afanasyev | e67a97f | 2011-11-29 14:28:59 -0800 | [diff] [blame] | 332 | if (isNew || !isDuplicated) // potential flow |
Alexander Afanasyev | a7a2b8b | 2011-11-28 18:19:09 -0800 | [diff] [blame] | 333 | { |
| 334 | // somebody is doing something bad |
Alexander Afanasyev | f377b33 | 2011-12-16 15:32:12 -0800 | [diff] [blame] | 335 | m_dropNacks (header, NON_DUPLICATED, incomingFace); |
Alexander Afanasyev | a7a2b8b | 2011-11-28 18:19:09 -0800 | [diff] [blame] | 336 | return; |
| 337 | } |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 338 | |
Alexander Afanasyev | 9d313d4 | 2011-11-25 13:36:15 -0800 | [diff] [blame] | 339 | // CcnxPitEntryIncomingFaceContainer::type::iterator inFace = pitEntry.m_incoming.find (incomingFace); |
| 340 | CcnxPitEntryOutgoingFaceContainer::type::iterator outFace = pitEntry.m_outgoing.find (incomingFace); |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 341 | |
Alexander Afanasyev | e67a97f | 2011-11-29 14:28:59 -0800 | [diff] [blame] | 342 | if (outFace == pitEntry.m_outgoing.end ()) |
Alexander Afanasyev | a7a2b8b | 2011-11-28 18:19:09 -0800 | [diff] [blame] | 343 | { |
Alexander Afanasyev | 8f5a9bb | 2011-12-18 19:49:02 -0800 | [diff] [blame] | 344 | // NS_ASSERT_MSG (false, |
| 345 | // "Node " << GetObject<Node> ()->GetId () << ", outgoing entry should exist for face " << boost::cref(*incomingFace) << "\n" << |
| 346 | // "size: " << pitEntry.m_outgoing.size ()); |
Alexander Afanasyev | a7a2b8b | 2011-11-28 18:19:09 -0800 | [diff] [blame] | 347 | |
Alexander Afanasyev | f377b33 | 2011-12-16 15:32:12 -0800 | [diff] [blame] | 348 | // m_dropNacks (header, NON_DUPLICATE, incomingFace); |
Alexander Afanasyev | a7a2b8b | 2011-11-28 18:19:09 -0800 | [diff] [blame] | 349 | return; |
| 350 | } |
Alexander Afanasyev | 9d313d4 | 2011-11-25 13:36:15 -0800 | [diff] [blame] | 351 | |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 352 | // This was done in error. Never, never do anything, except normal leakage. This way we ensure that we will not have losses, |
| 353 | // at least when there is only one client |
| 354 | // |
| 355 | // incomingFace->LeakBucketByOnePacket (); |
Alexander Afanasyev | e67a97f | 2011-11-29 14:28:59 -0800 | [diff] [blame] | 356 | |
Alexander Afanasyev | 23d2b54 | 2011-12-07 18:54:46 -0800 | [diff] [blame] | 357 | NS_LOG_ERROR ("Nack on " << boost::cref(*incomingFace)); |
| 358 | |
Alexander Afanasyev | 5a59507 | 2011-11-25 14:49:07 -0800 | [diff] [blame] | 359 | m_pit->modify (m_pit->iterator_to (pitEntry), |
| 360 | ll::bind (&CcnxPitEntry::SetWaitingInVain, ll::_1, outFace)); |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 361 | |
Alexander Afanasyev | 9d313d4 | 2011-11-25 13:36:15 -0800 | [diff] [blame] | 362 | // If NACK is NACK_GIVEUP_PIT, then neighbor gave up trying to and removed it's PIT entry. |
| 363 | // So, if we had an incoming entry to this neighbor, then we can remove it now |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 364 | |
Alexander Afanasyev | 9d313d4 | 2011-11-25 13:36:15 -0800 | [diff] [blame] | 365 | if (header->GetNack () == CcnxInterestHeader::NACK_GIVEUP_PIT) |
| 366 | { |
| 367 | m_pit->modify (m_pit->iterator_to (pitEntry), |
| 368 | ll::bind (&CcnxPitEntry::RemoveIncoming, ll::_1, incomingFace)); |
| 369 | } |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 370 | |
Alexander Afanasyev | 0782718 | 2011-12-13 01:07:32 -0800 | [diff] [blame] | 371 | m_fib->m_fib.modify (m_fib->m_fib.iterator_to (pitEntry.m_fibEntry), |
| 372 | ll::bind (&CcnxFibEntry::UpdateStatus, |
| 373 | ll::_1, incomingFace, CcnxFibFaceMetric::NDN_FIB_YELLOW)); |
Alexander Afanasyev | a7a2b8b | 2011-11-28 18:19:09 -0800 | [diff] [blame] | 374 | |
Alexander Afanasyev | 23d2b54 | 2011-12-07 18:54:46 -0800 | [diff] [blame] | 375 | if (pitEntry.m_incoming.size () == 0) // interest was actually satisfied |
| 376 | { |
| 377 | // no need to do anything |
Alexander Afanasyev | f377b33 | 2011-12-16 15:32:12 -0800 | [diff] [blame] | 378 | m_dropNacks (header, AFTER_SATISFIED, incomingFace); |
Alexander Afanasyev | 23d2b54 | 2011-12-07 18:54:46 -0800 | [diff] [blame] | 379 | return; |
| 380 | } |
| 381 | |
Alexander Afanasyev | e67a97f | 2011-11-29 14:28:59 -0800 | [diff] [blame] | 382 | if (!pitEntry.AreAllOutgoingInVain ()) // not all ougtoing are in vain |
Alexander Afanasyev | a7a2b8b | 2011-11-28 18:19:09 -0800 | [diff] [blame] | 383 | { |
Alexander Afanasyev | 23d2b54 | 2011-12-07 18:54:46 -0800 | [diff] [blame] | 384 | NS_LOG_DEBUG ("Not all outgoing are in vain"); |
Alexander Afanasyev | a7a2b8b | 2011-11-28 18:19:09 -0800 | [diff] [blame] | 385 | // suppress |
| 386 | // Don't do anything, we are still expecting data from some other face |
Alexander Afanasyev | f377b33 | 2011-12-16 15:32:12 -0800 | [diff] [blame] | 387 | m_dropNacks (header, SUPPRESSED, incomingFace); |
Alexander Afanasyev | a7a2b8b | 2011-11-28 18:19:09 -0800 | [diff] [blame] | 388 | return; |
| 389 | } |
Alexander Afanasyev | 9d313d4 | 2011-11-25 13:36:15 -0800 | [diff] [blame] | 390 | |
| 391 | NS_ASSERT_MSG (m_forwardingStrategy != 0, "Need a forwarding protocol object to process packets"); |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 392 | |
Alexander Afanasyev | 9d313d4 | 2011-11-25 13:36:15 -0800 | [diff] [blame] | 393 | Ptr<Packet> nonNackInterest = Create<Packet> (); |
| 394 | header->SetNack (CcnxInterestHeader::NORMAL_INTEREST); |
| 395 | nonNackInterest->AddHeader (*header); |
| 396 | |
| 397 | bool propagated = m_forwardingStrategy-> |
| 398 | PropagateInterest (pitEntry, incomingFace, header, nonNackInterest); |
| 399 | |
Alexander Afanasyev | 23d2b54 | 2011-12-07 18:54:46 -0800 | [diff] [blame] | 400 | // // ForwardingStrategy will try its best to forward packet to at least one interface. |
| 401 | // // If no interests was propagated, then there is not other option for forwarding or |
| 402 | // // ForwardingStrategy failed to find it. |
Alexander Afanasyev | e67a97f | 2011-11-29 14:28:59 -0800 | [diff] [blame] | 403 | if (!propagated) |
Alexander Afanasyev | f377b33 | 2011-12-16 15:32:12 -0800 | [diff] [blame] | 404 | { |
| 405 | m_dropNacks (header, NO_FACES, incomingFace); // this headers doesn't have NACK flag set |
| 406 | GiveUpInterest (pitEntry, header); |
| 407 | } |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 408 | } |
| 409 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 410 | // Processing Interests |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 411 | // |
| 412 | // !!! Key point. |
| 413 | // !!! All interests should be answerred!!! Either later with data, immediately with data, or immediately with NACK |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 414 | void CcnxL3Protocol::OnInterest (const Ptr<CcnxFace> &incomingFace, |
| 415 | Ptr<CcnxInterestHeader> &header, |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 416 | const Ptr<const Packet> &packet) |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 417 | { |
Alexander Afanasyev | f377b33 | 2011-12-16 15:32:12 -0800 | [diff] [blame] | 418 | m_inInterests (header, incomingFace); |
Alexander Afanasyev | ff8c5d6 | 2012-04-25 15:14:51 -0700 | [diff] [blame] | 419 | // NS_LOG_DEBUG (*m_pit); |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 420 | |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 421 | // Lookup of Pit (and associated Fib) entry for this Interest |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 422 | tuple<const CcnxPitEntry&,bool,bool> ret = m_pit->Lookup (*header); |
| 423 | CcnxPitEntry const& pitEntry = ret.get<0> (); |
Alexander Afanasyev | 4e97094 | 2012-03-09 10:58:11 -0800 | [diff] [blame] | 424 | bool isNew = ret.get<1> (); |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 425 | bool isDuplicated = ret.get<2> (); |
Ilya Moiseenko | d83eb0d | 2011-11-16 15:23:46 -0800 | [diff] [blame] | 426 | |
Alexander Afanasyev | 8d11fcc | 2011-12-30 12:42:31 -0800 | [diff] [blame] | 427 | // NS_LOG_DEBUG ("isNew: " << isNew << ", isDup: " << isDuplicated); |
Alexander Afanasyev | 120bf31 | 2011-12-19 01:24:47 -0800 | [diff] [blame] | 428 | |
Alexander Afanasyev | 7f3e49e | 2012-04-30 00:17:07 -0700 | [diff] [blame] | 429 | NS_LOG_FUNCTION (header->GetName () << header->GetNonce () << boost::cref (*incomingFace) << isDuplicated); |
| 430 | |
| 431 | ///////////////////////////////////////////////////////////////////////////////////////// |
| 432 | ///////////////////////////////////////////////////////////////////////////////////////// |
| 433 | ///////////////////////////////////////////////////////////////////////////////////////// |
| 434 | // // |
| 435 | // !!!! IMPORTANT CHANGE !!!! Duplicate interests will create incoming face entry !!!! // |
| 436 | // // |
| 437 | ///////////////////////////////////////////////////////////////////////////////////////// |
| 438 | ///////////////////////////////////////////////////////////////////////////////////////// |
| 439 | ///////////////////////////////////////////////////////////////////////////////////////// |
| 440 | |
| 441 | // Data is not in cache |
| 442 | CcnxPitEntryIncomingFaceContainer::type::iterator inFace = pitEntry.m_incoming.find (incomingFace); |
| 443 | CcnxPitEntryOutgoingFaceContainer::type::iterator outFace = pitEntry.m_outgoing.find (incomingFace); |
| 444 | |
| 445 | bool isRetransmitted = false; |
| 446 | |
| 447 | if (inFace != pitEntry.m_incoming.end ()) |
| 448 | { |
| 449 | // CcnxPitEntryIncomingFace.m_arrivalTime keeps track arrival time of the first packet... why? |
| 450 | |
| 451 | isRetransmitted = true; |
| 452 | // this is almost definitely a retransmission. But should we trust the user on that? |
| 453 | } |
| 454 | else |
| 455 | { |
| 456 | m_pit->modify (m_pit->iterator_to (pitEntry), |
| 457 | ll::var(inFace) = ll::bind (&CcnxPitEntry::AddIncoming, ll::_1, incomingFace)); |
| 458 | } |
| 459 | ////////////////////////////////////////////////////////////////////////////////// |
| 460 | ////////////////////////////////////////////////////////////////////////////////// |
| 461 | ////////////////////////////////////////////////////////////////////////////////// |
| 462 | |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 463 | if (isDuplicated) |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 464 | { |
Alexander Afanasyev | 7f3e49e | 2012-04-30 00:17:07 -0700 | [diff] [blame] | 465 | NS_LOG_DEBUG ("Received duplicatie interest on " << *incomingFace); |
Alexander Afanasyev | f377b33 | 2011-12-16 15:32:12 -0800 | [diff] [blame] | 466 | m_dropInterests (header, DUPLICATED, incomingFace); |
| 467 | |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 468 | /** |
| 469 | * This condition will handle "routing" loops and also recently satisfied interests. |
| 470 | * Every time interest is satisfied, PIT entry (with empty incoming and outgoing faces) |
| 471 | * is kept for another small chunk of time. |
| 472 | */ |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 473 | |
Alexander Afanasyev | bab81b1 | 2012-02-04 14:20:09 -0800 | [diff] [blame] | 474 | if (m_nacksEnabled) |
| 475 | { |
| 476 | NS_LOG_DEBUG ("Sending NACK_LOOP"); |
| 477 | header->SetNack (CcnxInterestHeader::NACK_LOOP); |
| 478 | Ptr<Packet> nack = Create<Packet> (); |
| 479 | nack->AddHeader (*header); |
| 480 | |
| 481 | incomingFace->Send (nack); |
| 482 | m_outNacks (header, incomingFace); |
| 483 | } |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 484 | |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 485 | return; |
| 486 | } |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 487 | |
| 488 | Ptr<Packet> contentObject; |
Alexander Afanasyev | c86c283 | 2011-12-23 02:56:22 -0800 | [diff] [blame] | 489 | Ptr<const CcnxContentObjectHeader> contentObjectHeader; // used for tracing |
| 490 | Ptr<const Packet> payload; // used for tracing |
| 491 | tie (contentObject, contentObjectHeader, payload) = m_contentStore->Lookup (header); |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 492 | if (contentObject != 0) |
| 493 | { |
Alexander Afanasyev | 7f3e49e | 2012-04-30 00:17:07 -0700 | [diff] [blame] | 494 | NS_ASSERT (contentObjectHeader != 0); |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 495 | NS_LOG_LOGIC("Found in cache"); |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 496 | |
Alexander Afanasyev | d459ec3 | 2012-04-30 13:58:20 -0700 | [diff] [blame] | 497 | OnDataDelayed (contentObjectHeader, payload, contentObject); |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 498 | return; |
| 499 | } |
| 500 | |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 501 | // update PIT entry lifetime |
| 502 | m_pit->modify (m_pit->iterator_to (pitEntry), |
| 503 | ll::bind (&CcnxPitEntry::UpdateLifetime, ll::_1, |
| 504 | header->GetInterestLifetime ())); |
| 505 | |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 506 | if (outFace != pitEntry.m_outgoing.end ()) |
| 507 | { |
Alexander Afanasyev | e192a2a | 2012-04-09 14:57:54 -0700 | [diff] [blame] | 508 | NS_LOG_DEBUG ("Non duplicate interests from the face we have sent interest to. Don't suppress"); |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 509 | // got a non-duplicate interest from the face we have sent interest to |
| 510 | // Probably, there is no point in waiting data from that face... Not sure yet |
| 511 | |
| 512 | // If we're expecting data from the interface we got the interest from ("producer" asks us for "his own" data) |
| 513 | // Mark interface YELLOW, but keep a small hope that data will come eventually. |
| 514 | |
| 515 | // ?? not sure if we need to do that ?? ... |
| 516 | |
Alexander Afanasyev | 0782718 | 2011-12-13 01:07:32 -0800 | [diff] [blame] | 517 | m_fib->m_fib.modify(m_fib->m_fib.iterator_to (pitEntry.m_fibEntry), |
| 518 | ll::bind (&CcnxFibEntry::UpdateStatus, |
| 519 | ll::_1, incomingFace, CcnxFibFaceMetric::NDN_FIB_YELLOW)); |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 520 | } |
Alexander Afanasyev | e192a2a | 2012-04-09 14:57:54 -0700 | [diff] [blame] | 521 | else |
| 522 | if (!isNew && !isRetransmitted) |
| 523 | { |
| 524 | // Suppress this interest if we're still expecting data from some other face |
| 525 | NS_LOG_DEBUG ("Suppress interests"); |
| 526 | m_dropInterests (header, SUPPRESSED, incomingFace); |
| 527 | return; |
| 528 | } |
Alexander Afanasyev | a7a2b8b | 2011-11-28 18:19:09 -0800 | [diff] [blame] | 529 | |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 530 | ///////////////////////////////////////////////////////////////////// |
| 531 | // Propagate |
| 532 | ///////////////////////////////////////////////////////////////////// |
| 533 | |
| 534 | NS_ASSERT_MSG (m_forwardingStrategy != 0, "Need a forwarding protocol object to process packets"); |
| 535 | |
| 536 | bool propagated = m_forwardingStrategy-> |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 537 | PropagateInterest (pitEntry, incomingFace, header, packet); |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 538 | |
Alexander Afanasyev | d459ec3 | 2012-04-30 13:58:20 -0700 | [diff] [blame] | 539 | if (!propagated && isRetransmitted) //give another chance if retransmitted |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 540 | { |
| 541 | // increase max number of allowed retransmissions |
| 542 | m_pit->modify (m_pit->iterator_to (pitEntry), |
| 543 | ll::bind (&CcnxPitEntry::IncreaseAllowedRetxCount, ll::_1)); |
| 544 | |
| 545 | // try again |
| 546 | propagated = m_forwardingStrategy-> |
| 547 | PropagateInterest (pitEntry, incomingFace, header, packet); |
| 548 | } |
| 549 | |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 550 | // ForwardingStrategy will try its best to forward packet to at least one interface. |
| 551 | // If no interests was propagated, then there is not other option for forwarding or |
| 552 | // ForwardingStrategy failed to find it. |
Alexander Afanasyev | e67a97f | 2011-11-29 14:28:59 -0800 | [diff] [blame] | 553 | if (!propagated) |
Alexander Afanasyev | 9d313d4 | 2011-11-25 13:36:15 -0800 | [diff] [blame] | 554 | { |
Alexander Afanasyev | 120bf31 | 2011-12-19 01:24:47 -0800 | [diff] [blame] | 555 | NS_LOG_DEBUG ("Not propagated"); |
Alexander Afanasyev | f377b33 | 2011-12-16 15:32:12 -0800 | [diff] [blame] | 556 | m_dropInterests (header, NO_FACES, incomingFace); |
| 557 | GiveUpInterest (pitEntry, header); |
Alexander Afanasyev | 9d313d4 | 2011-11-25 13:36:15 -0800 | [diff] [blame] | 558 | } |
Alexander Afanasyev | 9d313d4 | 2011-11-25 13:36:15 -0800 | [diff] [blame] | 559 | } |
| 560 | |
Alexander Afanasyev | ff8c5d6 | 2012-04-25 15:14:51 -0700 | [diff] [blame] | 561 | void |
Alexander Afanasyev | 7f3e49e | 2012-04-30 00:17:07 -0700 | [diff] [blame] | 562 | CcnxL3Protocol::OnDataDelayed (Ptr<const CcnxContentObjectHeader> header, |
| 563 | Ptr<const Packet> payload, |
Alexander Afanasyev | ff8c5d6 | 2012-04-25 15:14:51 -0700 | [diff] [blame] | 564 | const Ptr<const Packet> &packet) |
| 565 | { |
| 566 | if (m_delayingDataProcessing) |
| 567 | { |
| 568 | NS_LOG_DEBUG ("Delayed processing " << header->GetName ()); |
| 569 | // NS_LOG_DEBUG (*m_pit); |
| 570 | } |
| 571 | |
| 572 | // 1. Lookup PIT entry |
| 573 | try |
| 574 | { |
| 575 | CcnxPitEntryContainer::type::iterator pitEntry = m_pit->Lookup (*header); |
| 576 | |
| 577 | //satisfy all pending incoming Interests |
| 578 | BOOST_FOREACH (const CcnxPitEntryIncomingFace &incoming, pitEntry->m_incoming) |
| 579 | { |
| 580 | incoming.m_face->Send (packet->Copy ()); |
| 581 | m_outData (header, payload, false, incoming.m_face); |
| 582 | NS_LOG_DEBUG ("Satisfy " << *incoming.m_face); |
| 583 | |
| 584 | // successfull forwarded data trace |
| 585 | } |
| 586 | |
| 587 | if (pitEntry->m_incoming.size () > 0) |
| 588 | { |
| 589 | // All incoming interests are satisfied. Remove them |
| 590 | m_pit->modify (pitEntry, |
| 591 | ll::bind (&CcnxPitEntry::ClearIncoming, ll::_1)); |
| 592 | |
| 593 | // Remove all outgoing faces |
| 594 | m_pit->modify (pitEntry, |
| 595 | ll::bind (&CcnxPitEntry::ClearOutgoing, ll::_1)); |
| 596 | |
| 597 | // Set pruning timout on PIT entry (instead of deleting the record) |
| 598 | m_pit->modify (pitEntry, |
| 599 | ll::bind (&CcnxPitEntry::SetExpireTime, ll::_1, |
| 600 | Simulator::Now () + m_pit->GetPitEntryPruningTimeout ())); |
| 601 | } |
| 602 | } |
| 603 | catch (CcnxPitEntryNotFound) |
| 604 | { |
| 605 | NS_LOG_DEBUG ("Pit entry not found (was satisfied and removed before)"); |
| 606 | return; // do not process unsoliced data packets |
| 607 | } |
| 608 | } |
| 609 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 610 | // Processing ContentObjects |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 611 | void |
| 612 | CcnxL3Protocol::OnData (const Ptr<CcnxFace> &incomingFace, |
| 613 | Ptr<CcnxContentObjectHeader> &header, |
| 614 | Ptr<Packet> &payload, |
| 615 | const Ptr<const Packet> &packet) |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 616 | { |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 617 | |
Alexander Afanasyev | 1aeaf92 | 2012-04-23 13:48:09 -0700 | [diff] [blame] | 618 | NS_LOG_FUNCTION (incomingFace << header->GetName () << payload << packet); |
Alexander Afanasyev | c86c283 | 2011-12-23 02:56:22 -0800 | [diff] [blame] | 619 | m_inData (header, payload, incomingFace); |
Alexander Afanasyev | ff8c5d6 | 2012-04-25 15:14:51 -0700 | [diff] [blame] | 620 | // NS_LOG_DEBUG (*m_pit); |
| 621 | |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 622 | // 1. Lookup PIT entry |
| 623 | try |
| 624 | { |
Alexander Afanasyev | ff8c5d6 | 2012-04-25 15:14:51 -0700 | [diff] [blame] | 625 | CcnxPitEntryContainer::type::iterator pitEntry = m_pit->Lookup (*header); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 626 | |
| 627 | // Note that with MultiIndex we need to modify entries indirectly |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 628 | |
Alexander Afanasyev | ff8c5d6 | 2012-04-25 15:14:51 -0700 | [diff] [blame] | 629 | CcnxPitEntryOutgoingFaceContainer::type::iterator out = pitEntry->m_outgoing.find (incomingFace); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 630 | |
| 631 | // If we have sent interest for this data via this face, then update stats. |
Alexander Afanasyev | ff8c5d6 | 2012-04-25 15:14:51 -0700 | [diff] [blame] | 632 | if (out != pitEntry->m_outgoing.end ()) |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 633 | { |
Alexander Afanasyev | ff8c5d6 | 2012-04-25 15:14:51 -0700 | [diff] [blame] | 634 | m_fib->m_fib.modify (m_fib->m_fib.iterator_to (pitEntry->m_fibEntry), |
Alexander Afanasyev | 0782718 | 2011-12-13 01:07:32 -0800 | [diff] [blame] | 635 | ll::bind (&CcnxFibEntry::UpdateFaceRtt, |
| 636 | ll::_1, |
| 637 | incomingFace, |
| 638 | Simulator::Now () - out->m_sendTime)); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 639 | } |
| 640 | else |
| 641 | { |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 642 | // Unsolicited data, but we're interested in it... should we get it? |
| 643 | // Potential hole for attacks |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 644 | |
Alexander Afanasyev | de00999 | 2012-02-04 18:54:54 -0800 | [diff] [blame] | 645 | if (m_cacheUnsolicitedData) |
| 646 | { |
| 647 | // Optimistically add or update entry in the content store |
| 648 | m_contentStore->Add (header, payload); |
| 649 | } |
| 650 | else |
| 651 | { |
| 652 | NS_LOG_ERROR ("Node "<< m_node->GetId() << |
| 653 | ". PIT entry for "<< header->GetName ()<<" is valid, " |
| 654 | "but outgoing entry for interface "<< boost::cref(*incomingFace) <<" doesn't exist\n"); |
| 655 | } |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 656 | // ignore unsolicited data |
| 657 | return; |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 658 | } |
| 659 | |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 660 | // Update metric status for the incoming interface in the corresponding FIB entry |
Alexander Afanasyev | ff8c5d6 | 2012-04-25 15:14:51 -0700 | [diff] [blame] | 661 | m_fib->m_fib.modify (m_fib->m_fib.iterator_to (pitEntry->m_fibEntry), |
Alexander Afanasyev | 0782718 | 2011-12-13 01:07:32 -0800 | [diff] [blame] | 662 | ll::bind (&CcnxFibEntry::UpdateStatus, ll::_1, |
| 663 | incomingFace, CcnxFibFaceMetric::NDN_FIB_GREEN)); |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 664 | |
| 665 | // Add or update entry in the content store |
| 666 | m_contentStore->Add (header, payload); |
| 667 | |
Alexander Afanasyev | ff8c5d6 | 2012-04-25 15:14:51 -0700 | [diff] [blame] | 668 | m_pit->modify (pitEntry, |
| 669 | ll::bind (&CcnxPitEntry::RemoveIncoming, ll::_1, incomingFace)); |
| 670 | |
| 671 | if (pitEntry->m_incoming.size () == 0) |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 672 | { |
Alexander Afanasyev | ff8c5d6 | 2012-04-25 15:14:51 -0700 | [diff] [blame] | 673 | // Set pruning timout on PIT entry (instead of deleting the record) |
| 674 | m_pit->modify (pitEntry, |
| 675 | ll::bind (&CcnxPitEntry::SetExpireTime, ll::_1, |
| 676 | Simulator::Now () + m_pit->GetPitEntryPruningTimeout ())); |
| 677 | } |
| 678 | else |
| 679 | { |
| 680 | if (!m_delayingDataProcessing) |
Alexander Afanasyev | f377b33 | 2011-12-16 15:32:12 -0800 | [diff] [blame] | 681 | { |
Alexander Afanasyev | ff8c5d6 | 2012-04-25 15:14:51 -0700 | [diff] [blame] | 682 | OnDataDelayed (header, payload, packet); |
Alexander Afanasyev | f377b33 | 2011-12-16 15:32:12 -0800 | [diff] [blame] | 683 | } |
Alexander Afanasyev | 1aeaf92 | 2012-04-23 13:48:09 -0700 | [diff] [blame] | 684 | else |
| 685 | { |
Alexander Afanasyev | ff8c5d6 | 2012-04-25 15:14:51 -0700 | [diff] [blame] | 686 | NS_LOG_DEBUG ("Delaying Data forwarding " << header->GetName ()); |
| 687 | UniformVariable delay (0.0001, 0.002); |
| 688 | Simulator::Schedule (Seconds (delay.GetValue ()), |
| 689 | &CcnxL3Protocol::OnDataDelayed, this, header, payload, packet); |
Alexander Afanasyev | 1aeaf92 | 2012-04-23 13:48:09 -0700 | [diff] [blame] | 690 | } |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 691 | } |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 692 | } |
| 693 | catch (CcnxPitEntryNotFound) |
| 694 | { |
Alexander Afanasyev | 1aeaf92 | 2012-04-23 13:48:09 -0700 | [diff] [blame] | 695 | NS_LOG_DEBUG ("Pit entry not found"); |
Alexander Afanasyev | de00999 | 2012-02-04 18:54:54 -0800 | [diff] [blame] | 696 | if (m_cacheUnsolicitedData) |
| 697 | { |
| 698 | // Optimistically add or update entry in the content store |
| 699 | m_contentStore->Add (header, payload); |
| 700 | } |
| 701 | else |
| 702 | { |
| 703 | // Drop data packet if PIT entry is not found |
| 704 | // (unsolicited data packets should not "poison" content store) |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 705 | |
Alexander Afanasyev | de00999 | 2012-02-04 18:54:54 -0800 | [diff] [blame] | 706 | //drop dulicated or not requested data packet |
| 707 | m_dropData (header, payload, UNSOLICITED, incomingFace); |
| 708 | } |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 709 | return; // do not process unsoliced data packets |
| 710 | } |
| 711 | } |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 712 | |
| 713 | void |
Alexander Afanasyev | f377b33 | 2011-12-16 15:32:12 -0800 | [diff] [blame] | 714 | CcnxL3Protocol::GiveUpInterest (const CcnxPitEntry &pitEntry, |
| 715 | Ptr<CcnxInterestHeader> header) |
| 716 | { |
Alexander Afanasyev | de00999 | 2012-02-04 18:54:54 -0800 | [diff] [blame] | 717 | NS_LOG_FUNCTION (this << &pitEntry); |
Alexander Afanasyev | ff8c5d6 | 2012-04-25 15:14:51 -0700 | [diff] [blame] | 718 | // NS_LOG_DEBUG (*m_pit); |
Alexander Afanasyev | bab81b1 | 2012-02-04 14:20:09 -0800 | [diff] [blame] | 719 | if (m_nacksEnabled) |
Alexander Afanasyev | f377b33 | 2011-12-16 15:32:12 -0800 | [diff] [blame] | 720 | { |
Alexander Afanasyev | bab81b1 | 2012-02-04 14:20:09 -0800 | [diff] [blame] | 721 | Ptr<Packet> packet = Create<Packet> (); |
| 722 | header->SetNack (CcnxInterestHeader::NACK_GIVEUP_PIT); |
| 723 | packet->AddHeader (*header); |
Alexander Afanasyev | f377b33 | 2011-12-16 15:32:12 -0800 | [diff] [blame] | 724 | |
Alexander Afanasyev | bab81b1 | 2012-02-04 14:20:09 -0800 | [diff] [blame] | 725 | BOOST_FOREACH (const CcnxPitEntryIncomingFace &incoming, pitEntry.m_incoming) |
| 726 | { |
Alexander Afanasyev | de00999 | 2012-02-04 18:54:54 -0800 | [diff] [blame] | 727 | NS_LOG_DEBUG ("Send NACK for " << boost::cref (header->GetName ()) << " to " << boost::cref (*incoming.m_face)); |
Alexander Afanasyev | bab81b1 | 2012-02-04 14:20:09 -0800 | [diff] [blame] | 728 | incoming.m_face->Send (packet->Copy ()); |
| 729 | |
| 730 | m_outNacks (header, incoming.m_face); |
| 731 | } |
Alexander Afanasyev | bab81b1 | 2012-02-04 14:20:09 -0800 | [diff] [blame] | 732 | |
Alexander Afanasyev | 1aeaf92 | 2012-04-23 13:48:09 -0700 | [diff] [blame] | 733 | // All incoming interests cannot be satisfied. Remove them |
| 734 | m_pit->modify (m_pit->iterator_to (pitEntry), |
| 735 | ll::bind (&CcnxPitEntry::ClearIncoming, ll::_1)); |
Alexander Afanasyev | f377b33 | 2011-12-16 15:32:12 -0800 | [diff] [blame] | 736 | |
Alexander Afanasyev | 1aeaf92 | 2012-04-23 13:48:09 -0700 | [diff] [blame] | 737 | // Remove also outgoing |
| 738 | m_pit->modify (m_pit->iterator_to (pitEntry), |
| 739 | ll::bind (&CcnxPitEntry::ClearOutgoing, ll::_1)); |
Alexander Afanasyev | 120bf31 | 2011-12-19 01:24:47 -0800 | [diff] [blame] | 740 | |
Alexander Afanasyev | 1aeaf92 | 2012-04-23 13:48:09 -0700 | [diff] [blame] | 741 | // Set pruning timout on PIT entry (instead of deleting the record) |
| 742 | m_pit->modify (m_pit->iterator_to (pitEntry), |
| 743 | ll::bind (&CcnxPitEntry::SetExpireTime, ll::_1, |
| 744 | Simulator::Now () + m_pit->GetPitEntryPruningTimeout ())); |
| 745 | } |
Alexander Afanasyev | f377b33 | 2011-12-16 15:32:12 -0800 | [diff] [blame] | 746 | } |
| 747 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 748 | } //namespace ns3 |