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