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 | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 31 | #include "ns3/boolean.h" |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 32 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 33 | #include "ns3/ccnx-header-helper.h" |
| 34 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 35 | #include "ccnx-face.h" |
| 36 | #include "ccnx-route.h" |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 37 | #include "ccnx-forwarding-strategy.h" |
| 38 | #include "ccnx-interest-header.h" |
| 39 | #include "ccnx-content-object-header.h" |
| 40 | |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 41 | #include <boost/foreach.hpp> |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 42 | |
| 43 | NS_LOG_COMPONENT_DEFINE ("CcnxL3Protocol"); |
| 44 | |
| 45 | namespace ns3 { |
| 46 | |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 47 | const uint16_t CcnxL3Protocol::ETHERNET_FRAME_TYPE = 0x7777; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 48 | |
| 49 | NS_OBJECT_ENSURE_REGISTERED (CcnxL3Protocol); |
| 50 | |
| 51 | TypeId |
| 52 | CcnxL3Protocol::GetTypeId (void) |
| 53 | { |
| 54 | static TypeId tid = TypeId ("ns3::CcnxL3Protocol") |
| 55 | .SetParent<Ccnx> () |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 56 | .SetGroupName ("Ccnx") |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 57 | .AddConstructor<CcnxL3Protocol> () |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 58 | // .AddTraceSource ("Tx", "Send ccnx packet to outgoing interface.", |
| 59 | // MakeTraceSourceAccessor (&CcnxL3Protocol::m_txTrace)) |
| 60 | // .AddTraceSource ("Rx", "Receive ccnx packet from incoming interface.", |
| 61 | // MakeTraceSourceAccessor (&CcnxL3Protocol::m_rxTrace)) |
| 62 | // .AddTraceSource ("Drop", "Drop ccnx packet", |
| 63 | // MakeTraceSourceAccessor (&CcnxL3Protocol::m_dropTrace)) |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 64 | // .AddAttribute ("InterfaceList", "The set of Ccnx interfaces associated to this Ccnx stack.", |
| 65 | // ObjectVectorValue (), |
| 66 | // MakeObjectVectorAccessor (&CcnxL3Protocol::m_faces), |
| 67 | // MakeObjectVectorChecker<CcnxFace> ()) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 68 | |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 69 | // .AddTraceSource ("SendOutgoing", "A newly-generated packet by this node is about to be queued for transmission", |
| 70 | // MakeTraceSourceAccessor (&CcnxL3Protocol::m_sendOutgoingTrace)) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 71 | |
| 72 | ; |
| 73 | return tid; |
| 74 | } |
| 75 | |
| 76 | CcnxL3Protocol::CcnxL3Protocol() |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 77 | : m_faceCounter (0) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 78 | { |
| 79 | NS_LOG_FUNCTION (this); |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 80 | |
| 81 | m_rit = CreateObject<CcnxRit> (); |
| 82 | m_pit = CreateObject<CcnxPit> (); |
| 83 | m_contentStore = CreateObject<CcnxContentStore> (); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | CcnxL3Protocol::~CcnxL3Protocol () |
| 87 | { |
| 88 | NS_LOG_FUNCTION (this); |
| 89 | } |
| 90 | |
| 91 | void |
| 92 | CcnxL3Protocol::SetNode (Ptr<Node> node) |
| 93 | { |
| 94 | m_node = node; |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 95 | m_fib = m_node->GetObject<CcnxFib> (); |
| 96 | NS_ASSERT_MSG (m_fib != 0, "FIB should be created and aggregated to a node before calling Ccnx::SetNode"); |
| 97 | |
| 98 | m_pit->SetFib (m_fib); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | /* |
| 102 | * This method is called by AddAgregate and completes the aggregation |
| 103 | * by setting the node in the ccnx stack |
| 104 | */ |
| 105 | void |
| 106 | CcnxL3Protocol::NotifyNewAggregate () |
| 107 | { |
| 108 | if (m_node == 0) |
| 109 | { |
| 110 | Ptr<Node>node = this->GetObject<Node>(); |
| 111 | // verify that it's a valid node and that |
| 112 | // the node has not been set before |
| 113 | if (node != 0) |
| 114 | { |
| 115 | this->SetNode (node); |
| 116 | } |
| 117 | } |
| 118 | Object::NotifyNewAggregate (); |
| 119 | } |
| 120 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 121 | void |
| 122 | CcnxL3Protocol::DoDispose (void) |
| 123 | { |
| 124 | NS_LOG_FUNCTION (this); |
| 125 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 126 | for (CcnxFaceList::iterator i = m_faces.begin (); i != m_faces.end (); ++i) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 127 | { |
| 128 | *i = 0; |
| 129 | } |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 130 | m_faces.clear (); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 131 | m_node = 0; |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 132 | // m_forwardingStrategy = 0; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 133 | Object::DoDispose (); |
| 134 | } |
| 135 | |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 136 | void |
| 137 | CcnxL3Protocol::SetForwardingStrategy (Ptr<CcnxForwardingStrategy> forwardingStrategy) |
| 138 | { |
| 139 | NS_LOG_FUNCTION (this); |
| 140 | m_forwardingStrategy = forwardingStrategy; |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 141 | // m_forwardingStrategy->SetCcnx (this); |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | Ptr<CcnxForwardingStrategy> |
| 145 | CcnxL3Protocol::GetForwardingStrategy (void) const |
| 146 | { |
| 147 | return m_forwardingStrategy; |
| 148 | } |
| 149 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 150 | uint32_t |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 151 | CcnxL3Protocol::AddFace (const Ptr<CcnxFace> &face) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 152 | { |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 153 | NS_LOG_FUNCTION (this << &face); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 154 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 155 | face->SetNode (m_node); |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 156 | 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] | 157 | |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 158 | // ask face to register in lower-layer stack |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 159 | face->RegisterProtocolHandler (MakeCallback (&CcnxL3Protocol::Receive, this)); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 160 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 161 | m_faces.push_back (face); |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 162 | m_faceCounter ++; |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 163 | return face->GetId (); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 164 | } |
| 165 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 166 | void |
| 167 | CcnxL3Protocol::RemoveFace (Ptr<CcnxFace> face) |
| 168 | { |
| 169 | // ask face to register in lower-layer stack |
| 170 | face->RegisterProtocolHandler (MakeNullCallback<void,const Ptr<CcnxFace>&,const Ptr<const Packet>&> ()); |
| 171 | CcnxFaceList::iterator face_it = find (m_faces.begin(), m_faces.end(), face); |
| 172 | NS_ASSERT_MSG (face_it != m_faces.end (), "Attempt to remove face that doesn't exist"); |
| 173 | m_faces.erase (face_it); |
| 174 | } |
| 175 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 176 | Ptr<CcnxFace> |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 177 | CcnxL3Protocol::GetFace (uint32_t index) const |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 178 | { |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 179 | 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] | 180 | { |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 181 | if (face->GetId () == index) |
| 182 | return face; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 183 | } |
| 184 | return 0; |
| 185 | } |
| 186 | |
| 187 | uint32_t |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 188 | CcnxL3Protocol::GetNFaces (void) const |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 189 | { |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 190 | return m_faces.size (); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 191 | } |
| 192 | |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 193 | void |
| 194 | CcnxL3Protocol::TransmittedDataTrace (Ptr<Packet> packet, |
| 195 | ContentObjectSource type, |
| 196 | Ptr<Ccnx> ccnx, Ptr<const CcnxFace> face) |
| 197 | { |
| 198 | // a "small" inefficiency for logging purposes |
| 199 | Ptr<CcnxContentObjectHeader> header = Create<CcnxContentObjectHeader> (); |
| 200 | static CcnxContentObjectTail tail; |
| 201 | packet->RemoveHeader (*header); |
| 202 | packet->RemoveTrailer (tail); |
| 203 | |
| 204 | m_transmittedDataTrace (header, packet/*payload*/, type, ccnx, face); |
| 205 | |
| 206 | packet->AddHeader (*header); |
| 207 | packet->AddTrailer (tail); |
| 208 | } |
| 209 | |
| 210 | |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 211 | // Callback from lower layer |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 212 | void |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 213 | CcnxL3Protocol::Receive (const Ptr<CcnxFace> &face, const Ptr<const Packet> &p) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 214 | { |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 215 | if (!face->IsUp ()) |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 216 | { |
| 217 | NS_LOG_LOGIC ("Dropping received packet -- interface is down"); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 218 | // m_dropTrace (p, INTERFACE_DOWN, m_node->GetObject<Ccnx> ()/*this*/, face); |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 219 | return; |
| 220 | } |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 221 | 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] | 222 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 223 | 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] | 224 | try |
| 225 | { |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 226 | CcnxHeaderHelper::Type type = CcnxHeaderHelper::GetCcnxHeaderType (p); |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 227 | switch (type) |
| 228 | { |
| 229 | case CcnxHeaderHelper::INTEREST: |
| 230 | { |
| 231 | Ptr<CcnxInterestHeader> header = Create<CcnxInterestHeader> (); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 232 | |
| 233 | // Deserialization. Exception may be thrown |
| 234 | packet->RemoveHeader (*header); |
| 235 | NS_ASSERT_MSG (packet->GetSize () == 0, "Payload of Interests should be zero"); |
| 236 | |
| 237 | OnInterest (face, header, p/*original packet*/); |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 238 | break; |
| 239 | } |
| 240 | case CcnxHeaderHelper::CONTENT_OBJECT: |
| 241 | { |
| 242 | Ptr<CcnxContentObjectHeader> header = Create<CcnxContentObjectHeader> (); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 243 | |
| 244 | static CcnxContentObjectTail contentObjectTrailer; //there is no data in this object |
| 245 | |
| 246 | // Deserialization. Exception may be thrown |
| 247 | packet->RemoveHeader (*header); |
| 248 | packet->RemoveTrailer (contentObjectTrailer); |
| 249 | |
| 250 | OnData (face, header, packet/*payload*/, p/*original packet*/); |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 251 | break; |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | // exception will be thrown if packet is not recognized |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 256 | } |
| 257 | catch (CcnxUnknownHeaderException) |
| 258 | { |
| 259 | NS_ASSERT_MSG (false, "Unknown CCNx header. Should not happen"); |
| 260 | } |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 261 | } |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 262 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 263 | // Processing Interests |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 264 | void CcnxL3Protocol::OnInterest (const Ptr<CcnxFace> &incomingFace, |
| 265 | Ptr<CcnxInterestHeader> &header, |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 266 | const Ptr<const Packet> &packet) |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 267 | { |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 268 | NS_LOG_LOGIC ("Receiving interest from " << &incomingFace); |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 269 | m_receivedInterestsTrace (header, m_node->GetObject<Ccnx> (), incomingFace); |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 270 | |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 271 | // Lookup of Pit and Fib entries for this Interest |
| 272 | CcnxFibEntryContainer::type::iterator fibEntry; |
| 273 | CcnxPitEntryContainer::type::iterator pitEntry = m_pit->Lookup (*header, fibEntry); |
| 274 | |
| 275 | // No matter is it duplicate or not, if it is a NACK message, remove all possible incoming |
| 276 | // entries for this interface (NACK means that neighbor gave up trying and there is no |
| 277 | // point of sending data in this direction) |
Ilya Moiseenko | b405d9b | 2011-10-28 16:23:11 -0700 | [diff] [blame] | 278 | NS_LOG_INFO("Before (header->IsNack()) && (pitEntry != m_pit->end ())"); |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 279 | if ((header->IsNack()) && (pitEntry != m_pit->end ())) |
| 280 | { |
| 281 | //m_pit->erase (pitEntry); |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 282 | NS_LOG_INFO("TRUE"); |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 283 | m_pit->modify(pitEntry, CcnxPitEntry::DeleteIncoming(incomingFace)); |
| 284 | } |
| 285 | |
Ilya Moiseenko | b405d9b | 2011-10-28 16:23:11 -0700 | [diff] [blame] | 286 | NS_LOG_INFO("Before WasRecentlySatisfied"); |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 287 | if (m_rit->WasRecentlySatisfied (*header)) |
| 288 | { |
| 289 | return; |
| 290 | } |
| 291 | /*if (m_rit->WasRecentlySatisfied (*header)) |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 292 | { |
Ilya Moiseenko | b405d9b | 2011-10-28 16:23:11 -0700 | [diff] [blame] | 293 | NS_LOG_INFO("Entering WasRecentlySatisfied"); |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 294 | // duplicate interests (same nonce) from applications are just ignored |
| 295 | if (incomingFace->IsLocal() == true) |
| 296 | return; |
| 297 | |
| 298 | // Update metric status for the incoming interface in the corresponding FIB entry |
| 299 | if (fibEntry != m_fib->end()) |
| 300 | m_fib->modify (m_fib->iterator_to (pitEntry->m_fibEntry), |
| 301 | CcnxFibEntry::UpdateStatus(incomingFace, CcnxFibFaceMetric::NDN_FIB_YELLOW)); |
| 302 | |
| 303 | //Trace duplicate interest |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 304 | m_droppedInterestsTrace (header, NDN_DUPLICATE_INTEREST, |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 305 | m_node->GetObject<Ccnx> (), incomingFace); |
| 306 | |
| 307 | bool isMine = false; |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 308 | //TypeId tid = TypeId ("ns3::CcnxProducer"); |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 309 | for(uint32_t i=0; i<m_node->GetNApplications();i++) |
| 310 | { |
| 311 | Ptr<Application> app = m_node->GetApplication(i); |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 312 | NS_LOG_INFO("ApplicationName = " << app->GetTypeId().GetName()); |
| 313 | if(app->GetTypeId().GetName() == "ns3::CcnxProducer") |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 314 | { |
| 315 | if((DynamicCast<CcnxProducer>(app))->GetPrefix () == header->GetName ()) |
| 316 | { |
| 317 | isMine = true; |
| 318 | break; |
| 319 | } |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | Ptr<Packet> contentObject = m_contentStore->Lookup (header); |
| 324 | if ((isMine == true) || (contentObject != NULL)) |
| 325 | { |
| 326 | //never respond with NACK to NACK |
| 327 | if(header->IsNack () ) |
| 328 | return; |
| 329 | |
| 330 | // always return a duplicate packet |
| 331 | header->SetNack(true); |
| 332 | //Trace duplicate interest |
| 333 | m_droppedInterestsTrace (header, NDN_DUPLICATE_INTEREST, |
| 334 | m_node->GetObject<Ccnx> (), incomingFace); |
| 335 | |
| 336 | SendInterest(incomingFace, header, packet->Copy()); |
| 337 | |
| 338 | return; |
| 339 | } |
| 340 | |
| 341 | |
| 342 | // check PIT. or there is no outgoing entry for this interface, |
| 343 | // silently drop the duplicate packet |
| 344 | |
| 345 | // If no entry found, silently drop |
| 346 | if( pitEntry == m_pit->end() ) |
| 347 | return; |
| 348 | |
| 349 | // If PIT entry timed out, silently drop |
| 350 | if( pitEntry->m_timerExpired == true ) |
| 351 | return; |
| 352 | |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 353 | // loop? |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 354 | |
| 355 | // Check if there is no outgoing entry for the interface or different nonce |
| 356 | // (i.e., got a duplicate packet, but we haven't sent interest to this |
| 357 | // interface) |
| 358 | // |
| 359 | // This case means that there is a loop in the network. |
| 360 | // So, prune this link, but do not remove PIT entry |
| 361 | |
| 362 | // Alex, check this condition!! |
| 363 | if(pitEntry->m_outgoing.size () == 0) |
| 364 | { |
| 365 | //never respond with NACK to NACK |
| 366 | if(header->IsNack () ) |
| 367 | return; |
| 368 | |
| 369 | // always return a duplicate packet |
| 370 | header->SetNack(true); |
| 371 | //Trace duplicate interest |
| 372 | m_droppedInterestsTrace (header, NDN_DUPLICATE_INTEREST, |
| 373 | m_node->GetObject<Ccnx> (), incomingFace); |
| 374 | |
| 375 | SendInterest(incomingFace, header, packet->Copy()); |
| 376 | return; |
| 377 | } |
| 378 | |
| 379 | |
| 380 | // At this point: |
| 381 | // - there is a non-expired PIT entry, |
| 382 | // - there is an outgoing interest to the interface, and |
| 383 | // - a nonce in outgoing entry is equal to a nonce in the received duplicate packet |
| 384 | |
| 385 | // Should perform: |
| 386 | // Cleaning outgoing entry |
| 387 | // If there are no outgoing interests and available interfaces left (pe->availableInterfaces), |
| 388 | // prune all incoming interests, otherwise allow forwarding of the interest |
| 389 | if( header->IsNack () ) |
| 390 | { |
| 391 | if( header->IsCongested () == false ) |
| 392 | m_pit->LeakBucket(incomingFace,1); |
| 393 | |
| 394 | m_pit->modify(pitEntry, CcnxPitEntry::DeleteOutgoing(incomingFace)); |
| 395 | } |
| 396 | else |
| 397 | { |
| 398 | //poit->waitingInVain = true; |
| 399 | } |
| 400 | |
| 401 | |
| 402 | // prune all incoming interests |
| 403 | if((pitEntry->m_outgoing.size() ==0) && (pitEntry->m_fibEntry.m_faces.size() == 0)) |
| 404 | { |
| 405 | BOOST_FOREACH (const CcnxPitEntryIncomingFace face, pitEntry->m_incoming) |
| 406 | { |
| 407 | if(face.m_face->IsLocal() == false) |
| 408 | { |
| 409 | // check all entries if the name of RIT entry matches the name of interest |
| 410 | for (CcnxRitByNonce::type::iterator it = m_rit->begin(); it != m_rit->end(); it++) |
| 411 | { |
| 412 | if (it->m_prefix == pitEntry->GetPrefix() ) |
| 413 | { |
| 414 | |
| 415 | header->SetNonce(it->m_nonce); |
| 416 | header->SetNack(true); |
| 417 | SendInterest(face.m_face, header, packet->Copy()); |
| 418 | break; |
| 419 | } |
| 420 | } |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | // Finally, remote the PIT entry |
| 425 | m_pit->erase (pitEntry); |
| 426 | |
| 427 | return; // stop processing |
| 428 | } |
| 429 | |
| 430 | if(pitEntry->m_fibEntry.m_faces.size() == 0) |
| 431 | return; |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 432 | }*/ |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 433 | |
| 434 | // Otherwise, |
| 435 | // propagate the interest |
| 436 | // |
| 437 | // method `propagateInterest' can/should try different interface |
| 438 | // from `availableInterfaces' list |
| 439 | |
Ilya Moiseenko | b405d9b | 2011-10-28 16:23:11 -0700 | [diff] [blame] | 440 | NS_LOG_INFO("Before SetRecentlySatisfied"); |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 441 | m_rit->SetRecentlySatisfied (*header); |
| 442 | |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 443 | NS_LOG_INFO("Cache Lookup for " << header->GetName()); |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 444 | Ptr<Packet> contentObject = m_contentStore->Lookup (header); |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 445 | if (contentObject != NULL) |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 446 | { |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 447 | NS_LOG_INFO("Found in cache"); |
| 448 | |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 449 | TransmittedDataTrace (contentObject, CACHED, |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 450 | m_node->GetObject<Ccnx> (), incomingFace); |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 451 | incomingFace->Send (contentObject); |
| 452 | return; |
| 453 | } |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 454 | |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 455 | // Data is not in cache |
Ilya Moiseenko | b405d9b | 2011-10-28 16:23:11 -0700 | [diff] [blame] | 456 | NS_LOG_INFO("Before inFace and OutFace"); |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 457 | CcnxPitEntryIncomingFaceContainer::type::iterator inFace = pitEntry->m_incoming.find (incomingFace); |
| 458 | CcnxPitEntryOutgoingFaceContainer::type::iterator outFace = pitEntry->m_outgoing.find (incomingFace); |
| 459 | |
Ilya Moiseenko | b405d9b | 2011-10-28 16:23:11 -0700 | [diff] [blame] | 460 | NS_LOG_INFO("Before (pitEntry != m_pit->end()) && (pitEntry->m_timerExpired == false)"); |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 461 | if ((pitEntry != m_pit->end()) && (pitEntry->m_timerExpired == false)) |
| 462 | { |
Ilya Moiseenko | b405d9b | 2011-10-28 16:23:11 -0700 | [diff] [blame] | 463 | NS_LOG_INFO("Entering (pitEntry != m_pit->end()) && (pitEntry->m_timerExpired == false)"); |
| 464 | |
| 465 | if(inFace->m_face == NULL) |
| 466 | NS_LOG_INFO("in face is null"); |
| 467 | if(outFace->m_face == NULL) |
| 468 | NS_LOG_INFO("outface is null"); |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 469 | |
| 470 | // If we're expecting data from the interface we got the interest from ("producer" asks us for "his own" data) |
| 471 | // Give up this interface, but keep a small hope when the returned packet doesn't have PRUNE status |
Ilya Moiseenko | b405d9b | 2011-10-28 16:23:11 -0700 | [diff] [blame] | 472 | if( outFace != pitEntry->m_outgoing.end()) |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 473 | { |
Ilya Moiseenko | b405d9b | 2011-10-28 16:23:11 -0700 | [diff] [blame] | 474 | NS_LOG_INFO("Entering outFace != pitEntry->m_outgoing.end()"); |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 475 | if( header->IsCongested() == true ) |
| 476 | { |
Ilya Moiseenko | b405d9b | 2011-10-28 16:23:11 -0700 | [diff] [blame] | 477 | NS_LOG_INFO("Entering header->IsCongested() == true"); |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 478 | m_pit->LeakBucket(incomingFace, 1); |
| 479 | m_pit->modify (pitEntry, CcnxPitEntry::DeleteOutgoing(outFace->m_face)); |
| 480 | } |
| 481 | //else |
| 482 | // poit->waitingInVain = true; |
| 483 | |
| 484 | // Update metric status for the incoming interface in the corresponding FIB entry |
| 485 | if(fibEntry != m_fib->end()) |
| 486 | m_fib->modify(m_fib->iterator_to (pitEntry->m_fibEntry), |
| 487 | CcnxFibEntry::UpdateStatus(incomingFace, CcnxFibFaceMetric::NDN_FIB_YELLOW)); |
| 488 | } |
| 489 | } |
| 490 | |
Ilya Moiseenko | b405d9b | 2011-10-28 16:23:11 -0700 | [diff] [blame] | 491 | NS_LOG_INFO("Before (pitEntry->m_outgoing.size() == 0) && (pitEntry->m_fibEntry.m_faces.size() == 0)"); |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 492 | if((pitEntry->m_outgoing.size() == 0) && (pitEntry->m_fibEntry.m_faces.size() == 0)) |
| 493 | // prune all incoming interests |
| 494 | { |
| 495 | |
| 496 | for(CcnxPitEntryContainer::type::iterator iter = m_pit->begin(); |
| 497 | iter != m_pit->end(); |
| 498 | iter++) |
| 499 | { |
| 500 | /*for(CcnxPitEntryIncomingFaceContainer::type::iterator face = iter->m_incoming.begin(); |
| 501 | face != iter->m_incoming.end(); |
| 502 | face++)*/ |
| 503 | BOOST_FOREACH (const CcnxPitEntryIncomingFace face, iter->m_incoming) |
| 504 | { |
| 505 | if(face.m_face->IsLocal() == true) |
| 506 | { |
| 507 | //returnInterestToApp( pkt, -piit->interfaceIndex ); |
| 508 | //continue; |
| 509 | } |
| 510 | |
| 511 | // check all entries if the name of RIT entry matches the name of interest |
| 512 | for (CcnxRitByNonce::type::iterator it = m_rit->begin(); it != m_rit->end(); it++) |
| 513 | { |
| 514 | if (it->m_prefix == iter->GetPrefix() ) |
| 515 | { |
| 516 | header->SetNonce(it->m_nonce); |
| 517 | header->SetNack(true); |
| 518 | SendInterest(face.m_face, header, packet->Copy()); |
| 519 | } |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | } |
| 524 | |
| 525 | m_pit->erase(pitEntry); |
| 526 | |
| 527 | return; // there is nothing else to do |
| 528 | } |
| 529 | |
| 530 | // Suppress this interest only if we're still expecting data from some other interface |
| 531 | if( pitEntry->m_outgoing.size() > 0 ) |
| 532 | { |
| 533 | return; //ok. Now we can suppress this interest |
| 534 | } |
| 535 | |
| 536 | |
| 537 | // Prune and delete PIT entry if there are no available interfaces to propagate interest |
| 538 | if( pitEntry->m_fibEntry.m_faces.size() == 0) |
| 539 | { |
| 540 | //if no match is found in the FIB, drop packet |
| 541 | //printf( "Node %d: cannot process Interest packet %s (no interfaces left)\n", _node->nodeId, pkt->contentName ); |
| 542 | |
| 543 | if(incomingFace->IsLocal() == false) |
| 544 | { |
| 545 | header->SetNack(true); |
| 546 | m_droppedInterestsTrace (header, NDN_SUPPRESSED_INTEREST, |
| 547 | m_node->GetObject<Ccnx> (), incomingFace); |
| 548 | SendInterest(incomingFace, header, packet->Copy()); |
| 549 | } |
| 550 | |
| 551 | m_pit->erase(pitEntry); |
| 552 | |
| 553 | } |
| 554 | |
| 555 | |
| 556 | |
| 557 | // otherwise, try one of the available interfaces |
| 558 | |
| 559 | // suppress interest if |
| 560 | /*if (pitEntry->m_incoming.size () != 0 && // not a new PIT entry and |
| 561 | inFace != pitEntry->m_incoming.end ()) // existing entry, but interest received via different face |
| 562 | { |
| 563 | m_droppedInterestsTrace (header, NDN_SUPPRESSED_INTEREST, |
| 564 | m_node->GetObject<Ccnx> (), incomingFace); |
| 565 | return; |
| 566 | }*/ |
| 567 | |
| 568 | |
| 569 | //just in case of bug |
| 570 | header->SetNack(false); |
| 571 | header->SetCongested(false); |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 572 | |
Ilya Moiseenko | 00b3048 | 2011-11-15 17:58:00 -0800 | [diff] [blame^] | 573 | NS_ASSERT_MSG (m_forwardingStrategy != 0, "Need a forwarding protocol object to process packets"); |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 574 | |
Ilya Moiseenko | 00b3048 | 2011-11-15 17:58:00 -0800 | [diff] [blame^] | 575 | m_pit->modify (pitEntry, CcnxPitEntry::AddIncoming(incomingFace)); |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 576 | |
Ilya Moiseenko | 00b3048 | 2011-11-15 17:58:00 -0800 | [diff] [blame^] | 577 | bool propagated = m_forwardingStrategy-> |
| 578 | PropagateInterest (pitEntry, fibEntry,incomingFace, header, packet, |
| 579 | MakeCallback (&CcnxL3Protocol::SendInterest, this) |
| 580 | ); |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 581 | |
Ilya Moiseenko | 00b3048 | 2011-11-15 17:58:00 -0800 | [diff] [blame^] | 582 | // If interest wasn't propagated further (probably, a limit is reached), |
| 583 | // prune and delete PIT entry if there are no outstanding interests. |
| 584 | // Stop processing otherwise. |
| 585 | if( (!propagated) && (pitEntry->m_outgoing.size() == 0)) |
| 586 | { |
| 587 | BOOST_FOREACH (const CcnxPitEntryIncomingFace face, pitEntry->m_incoming) |
| 588 | { |
| 589 | header->SetNack(true); |
| 590 | header->SetCongested(true); |
| 591 | NS_LOG_INFO("Sending CONGESTION packet"); |
| 592 | SendInterest (face.m_face, header, packet->Copy()); |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 593 | |
Ilya Moiseenko | 00b3048 | 2011-11-15 17:58:00 -0800 | [diff] [blame^] | 594 | m_droppedInterestsTrace (header, DROP_CONGESTION, |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 595 | m_node->GetObject<Ccnx> (), incomingFace); |
Ilya Moiseenko | 00b3048 | 2011-11-15 17:58:00 -0800 | [diff] [blame^] | 596 | } |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 597 | |
| 598 | m_pit->erase (pitEntry); |
Ilya Moiseenko | 00b3048 | 2011-11-15 17:58:00 -0800 | [diff] [blame^] | 599 | } |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 600 | /*} |
| 601 | else |
| 602 | { |
| 603 | m_droppedInterestsTrace (header, NDN_PIT_TIMER_EXPIRED, |
| 604 | m_node->GetObject<Ccnx> (), incomingFace); |
| 605 | return; |
| 606 | }*/ |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | // Processing ContentObjects |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 610 | void CcnxL3Protocol::OnData (const Ptr<CcnxFace> &incomingFace, |
| 611 | Ptr<CcnxContentObjectHeader> &header, |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 612 | Ptr<Packet> &payload, |
| 613 | const Ptr<const Packet> &packet) |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 614 | { |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 615 | |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 616 | NS_LOG_LOGIC ("Receiving contentObject from " << &incomingFace); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 617 | m_receivedDataTrace (header, payload, m_node->GetObject<Ccnx> ()/*this*/, incomingFace); |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 618 | |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 619 | // 1. Lookup PIT entry |
| 620 | try |
| 621 | { |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 622 | const CcnxPitEntry &pitEntry = m_pit->Lookup (*header); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 623 | |
| 624 | // Note that with MultiIndex we need to modify entries indirectly |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 625 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 626 | // Update metric status for the incoming interface in the corresponding FIB entry |
| 627 | m_fib->modify (m_fib->iterator_to (pitEntry.m_fibEntry), |
| 628 | CcnxFibEntry::UpdateStatus (incomingFace, CcnxFibFaceMetric::NDN_FIB_GREEN)); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 629 | |
| 630 | // Add or update entry in the content store |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 631 | NS_LOG_INFO("Cached " << header->GetName()); |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 632 | m_contentStore->Add (header, payload); |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 633 | |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 634 | CcnxPitEntryOutgoingFaceContainer::type::iterator |
| 635 | out = pitEntry.m_outgoing.find (incomingFace); |
| 636 | |
| 637 | // If we have sent interest for this data via this face, then update stats. |
| 638 | if (out != pitEntry.m_outgoing.end ()) |
| 639 | { |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 640 | m_pit->modify (m_pit->iterator_to (pitEntry), |
| 641 | CcnxPitEntry::EstimateRttAndRemoveFace(out, m_fib)); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 642 | // face will be removed in the above call |
| 643 | } |
| 644 | else |
| 645 | { |
| 646 | NS_LOG_WARN ("Node "<< m_node->GetId() << |
| 647 | ". PIT entry for "<< header->GetName ()<<" is valid, " |
| 648 | "but outgoing entry for interface "<< incomingFace <<" doesn't exist\n"); |
| 649 | } |
| 650 | |
| 651 | //satisfy all pending incoming Interests |
| 652 | BOOST_FOREACH (const CcnxPitEntryIncomingFace &interest, pitEntry.m_incoming) |
| 653 | { |
| 654 | if (interest.m_face == incomingFace) continue; |
| 655 | |
| 656 | // may not work either because of 'const' thing |
| 657 | interest.m_face->Send (packet->Copy ()); // unfortunately, we have to copy packet... |
| 658 | m_transmittedDataTrace (header, payload, FORWARDED, m_node->GetObject<Ccnx> (), interest.m_face); |
| 659 | } |
| 660 | |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 661 | m_pit->modify (m_pit->iterator_to (pitEntry), CcnxPitEntry::ClearIncoming()); // satisfy all incoming interests |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 662 | |
| 663 | if( pitEntry.m_outgoing.size()==0 ) // remove PIT when all outgoing interests are "satisfied" |
| 664 | { |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 665 | m_pit->erase (m_pit->iterator_to (pitEntry)); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | } |
| 669 | catch (CcnxPitEntryNotFound) |
| 670 | { |
| 671 | // 2. Drop data packet if PIT entry is not found |
| 672 | // (unsolicited data packets should not "poison" content store) |
| 673 | |
| 674 | //drop dulicated or not requested data packet |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 675 | m_droppedDataTrace (header, payload, NDN_UNSOLICITED_DATA, m_node->GetObject<Ccnx> (), incomingFace); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 676 | return; // do not process unsoliced data packets |
| 677 | } |
| 678 | } |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 679 | |
| 680 | void |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 681 | CcnxL3Protocol::SendInterest (const Ptr<CcnxFace> &face, |
| 682 | const Ptr<CcnxInterestHeader> &header, |
| 683 | const Ptr<Packet> &packet) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 684 | { |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 685 | NS_LOG_FUNCTION (this << "packet: " << &packet << ", face: "<< &face); |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 686 | NS_ASSERT_MSG (face != 0, "Face should never be NULL"); |
| 687 | |
| 688 | if (face->IsUp ()) |
| 689 | { |
| 690 | NS_LOG_LOGIC ("Sending via face " << &face); // |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 691 | m_transmittedInterestsTrace (header, m_node->GetObject<Ccnx> (), face); |
| 692 | face->Send (packet); |
| 693 | } |
| 694 | else |
| 695 | { |
| 696 | NS_LOG_LOGIC ("Dropping -- outgoing interface is down: " << &face); |
| 697 | m_droppedInterestsTrace (header, INTERFACE_DOWN, m_node->GetObject<Ccnx> (), face); |
| 698 | } |
| 699 | } |
| 700 | |
| 701 | void |
| 702 | CcnxL3Protocol::SendContentObject (const Ptr<CcnxFace> &face, |
| 703 | const Ptr<CcnxContentObjectHeader> &header, |
| 704 | const Ptr<Packet> &packet) |
| 705 | { |
| 706 | NS_LOG_FUNCTION (this << "packet: " << &packet << ", face: "<< &face); |
| 707 | NS_ASSERT_MSG (face != 0, "Face should never be NULL"); |
| 708 | |
| 709 | NS_ASSERT_MSG (false, "Should not be called for now"); |
| 710 | |
| 711 | if (face->IsUp ()) |
| 712 | { |
| 713 | NS_LOG_LOGIC ("Sending via face " << &face); // |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 714 | // m_txTrace (packet, m_node->GetObject<Ccnx> (), face); |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 715 | face->Send (packet); |
| 716 | } |
| 717 | else |
| 718 | { |
| 719 | NS_LOG_LOGIC ("Dropping -- outgoing interface is down: " << &face); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 720 | // m_dropTrace (packet, INTERFACE_DOWN, m_node->GetObject<Ccnx> (), face); |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 721 | } |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 722 | } |
| 723 | |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 724 | Ptr<CcnxPit> |
| 725 | CcnxL3Protocol::GetPit() |
| 726 | { |
| 727 | return m_pit; |
| 728 | } |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 729 | } //namespace ns3 |