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