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