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