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