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