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