blob: 823ddbe8f08931d39696c586486c151477be7dc2 [file] [log] [blame]
Alexander Afanasyevc74a6022011-08-15 20:01:35 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Alexander Afanasyevab1d5602011-08-17 19:17:18 -07002/*
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 Moiseenko172763c2011-10-28 13:21:53 -070019 * Ilya Moiseenko <iliamo@cs.ucla.edu>
Alexander Afanasyevab1d5602011-08-17 19:17:18 -070020 */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070021
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070022#include "ccnx-l3-protocol.h"
23
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070024#include "ns3/packet.h"
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070025#include "ns3/node.h"
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070026#include "ns3/log.h"
27#include "ns3/callback.h"
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070028#include "ns3/uinteger.h"
29#include "ns3/trace-source-accessor.h"
30#include "ns3/object-vector.h"
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070031#include "ns3/boolean.h"
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070032
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070033#include "ns3/ccnx-header-helper.h"
34
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070035#include "ccnx-face.h"
36#include "ccnx-route.h"
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070037#include "ccnx-forwarding-strategy.h"
38#include "ccnx-interest-header.h"
39#include "ccnx-content-object-header.h"
40
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -080041#include "ccnx-net-device-face.h"
42
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070043#include <boost/foreach.hpp>
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070044
45NS_LOG_COMPONENT_DEFINE ("CcnxL3Protocol");
46
47namespace ns3 {
48
Alexander Afanasyev7112f482011-08-17 14:05:57 -070049const uint16_t CcnxL3Protocol::ETHERNET_FRAME_TYPE = 0x7777;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070050
51NS_OBJECT_ENSURE_REGISTERED (CcnxL3Protocol);
52
53TypeId
54CcnxL3Protocol::GetTypeId (void)
55{
56 static TypeId tid = TypeId ("ns3::CcnxL3Protocol")
57 .SetParent<Ccnx> ()
Alexander Afanasyev070aa482011-08-20 00:38:25 -070058 .SetGroupName ("Ccnx")
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070059 .AddConstructor<CcnxL3Protocol> ()
Alexander Afanasyev7112f482011-08-17 14:05:57 -070060 // .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 Afanasyevc5a23e22011-09-07 00:37:36 -070066 // .AddAttribute ("InterfaceList", "The set of Ccnx interfaces associated to this Ccnx stack.",
67 // ObjectVectorValue (),
68 // MakeObjectVectorAccessor (&CcnxL3Protocol::m_faces),
69 // MakeObjectVectorChecker<CcnxFace> ())
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070070
Alexander Afanasyev7112f482011-08-17 14:05:57 -070071 // .AddTraceSource ("SendOutgoing", "A newly-generated packet by this node is about to be queued for transmission",
72 // MakeTraceSourceAccessor (&CcnxL3Protocol::m_sendOutgoingTrace))
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070073
74 ;
75 return tid;
76}
77
78CcnxL3Protocol::CcnxL3Protocol()
Alexander Afanasyevab1d5602011-08-17 19:17:18 -070079: m_faceCounter (0)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070080{
81 NS_LOG_FUNCTION (this);
Alexander Afanasyevcf133f02011-09-06 12:13:48 -070082
83 m_rit = CreateObject<CcnxRit> ();
84 m_pit = CreateObject<CcnxPit> ();
85 m_contentStore = CreateObject<CcnxContentStore> ();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070086}
87
88CcnxL3Protocol::~CcnxL3Protocol ()
89{
90 NS_LOG_FUNCTION (this);
91}
92
93void
94CcnxL3Protocol::SetNode (Ptr<Node> node)
95{
96 m_node = node;
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070097 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 Afanasyev08d984e2011-08-13 19:20:22 -0700101}
102
103/*
104 * This method is called by AddAgregate and completes the aggregation
105 * by setting the node in the ccnx stack
106 */
107void
108CcnxL3Protocol::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 Afanasyev08d984e2011-08-13 19:20:22 -0700123void
124CcnxL3Protocol::DoDispose (void)
125{
126 NS_LOG_FUNCTION (this);
127
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700128 for (CcnxFaceList::iterator i = m_faces.begin (); i != m_faces.end (); ++i)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700129 {
130 *i = 0;
131 }
Alexander Afanasyev98256102011-08-14 01:00:02 -0700132 m_faces.clear ();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700133 m_node = 0;
Alexander Afanasyevd02a5d62011-11-21 11:01:51 -0800134
135 // Force delete on objects
136 m_rit = 0;
137 m_pit = 0;
138 m_contentStore = 0;
139
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700140 // m_forwardingStrategy = 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700141 Object::DoDispose ();
142}
143
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -0700144void
145CcnxL3Protocol::SetForwardingStrategy (Ptr<CcnxForwardingStrategy> forwardingStrategy)
146{
147 NS_LOG_FUNCTION (this);
148 m_forwardingStrategy = forwardingStrategy;
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700149 // m_forwardingStrategy->SetCcnx (this);
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -0700150}
151
152Ptr<CcnxForwardingStrategy>
153CcnxL3Protocol::GetForwardingStrategy (void) const
154{
155 return m_forwardingStrategy;
156}
157
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700158uint32_t
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700159CcnxL3Protocol::AddFace (const Ptr<CcnxFace> &face)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700160{
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700161 NS_LOG_FUNCTION (this << &face);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700162
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700163 face->SetNode (m_node);
Alexander Afanasyevab1d5602011-08-17 19:17:18 -0700164 face->SetId (m_faceCounter); // sets a unique ID of the face. This ID serves only informational purposes
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700165
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -0700166 // ask face to register in lower-layer stack
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700167 face->RegisterProtocolHandler (MakeCallback (&CcnxL3Protocol::Receive, this));
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700168
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700169 m_faces.push_back (face);
Alexander Afanasyevab1d5602011-08-17 19:17:18 -0700170 m_faceCounter ++;
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700171 return face->GetId ();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700172}
173
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700174void
175CcnxL3Protocol::RemoveFace (Ptr<CcnxFace> face)
176{
177 // ask face to register in lower-layer stack
178 face->RegisterProtocolHandler (MakeNullCallback<void,const Ptr<CcnxFace>&,const Ptr<const Packet>&> ());
179 CcnxFaceList::iterator face_it = find (m_faces.begin(), m_faces.end(), face);
180 NS_ASSERT_MSG (face_it != m_faces.end (), "Attempt to remove face that doesn't exist");
181 m_faces.erase (face_it);
182}
183
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700184Ptr<CcnxFace>
Alexander Afanasyev98256102011-08-14 01:00:02 -0700185CcnxL3Protocol::GetFace (uint32_t index) const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700186{
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700187 BOOST_FOREACH (const Ptr<CcnxFace> &face, m_faces) // this function is not supposed to be called often, so linear search is fine
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700188 {
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700189 if (face->GetId () == index)
190 return face;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700191 }
192 return 0;
193}
194
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800195Ptr<CcnxFace>
196CcnxL3Protocol::GetFaceByNetDevice (Ptr<NetDevice> netDevice) const
197{
198 BOOST_FOREACH (const Ptr<CcnxFace> &face, m_faces) // this function is not supposed to be called often, so linear search is fine
199 {
200 Ptr<CcnxNetDeviceFace> netDeviceFace = DynamicCast<CcnxNetDeviceFace> (face);
201 if (netDeviceFace == 0) continue;
202
203 if (netDeviceFace->GetNetDevice () == netDevice)
204 return face;
205 }
206 return 0;
207}
208
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700209uint32_t
Alexander Afanasyev98256102011-08-14 01:00:02 -0700210CcnxL3Protocol::GetNFaces (void) const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700211{
Alexander Afanasyev98256102011-08-14 01:00:02 -0700212 return m_faces.size ();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700213}
214
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700215void
216CcnxL3Protocol::TransmittedDataTrace (Ptr<Packet> packet,
217 ContentObjectSource type,
218 Ptr<Ccnx> ccnx, Ptr<const CcnxFace> face)
219{
220 // a "small" inefficiency for logging purposes
221 Ptr<CcnxContentObjectHeader> header = Create<CcnxContentObjectHeader> ();
222 static CcnxContentObjectTail tail;
223 packet->RemoveHeader (*header);
224 packet->RemoveTrailer (tail);
225
226 m_transmittedDataTrace (header, packet/*payload*/, type, ccnx, face);
227
228 packet->AddHeader (*header);
229 packet->AddTrailer (tail);
230}
231
232
Alexander Afanasyev98256102011-08-14 01:00:02 -0700233// Callback from lower layer
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700234void
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700235CcnxL3Protocol::Receive (const Ptr<CcnxFace> &face, const Ptr<const Packet> &p)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700236{
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700237 if (!face->IsUp ())
Alexander Afanasyev070aa482011-08-20 00:38:25 -0700238 {
239 NS_LOG_LOGIC ("Dropping received packet -- interface is down");
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700240 // m_dropTrace (p, INTERFACE_DOWN, m_node->GetObject<Ccnx> ()/*this*/, face);
Alexander Afanasyev070aa482011-08-20 00:38:25 -0700241 return;
242 }
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700243 NS_LOG_LOGIC ("Packet from face " << *face << " received on node " << m_node->GetId ());
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700244
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700245 Ptr<Packet> packet = p->Copy (); // give upper layers a rw copy of the packet
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700246 try
247 {
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700248 CcnxHeaderHelper::Type type = CcnxHeaderHelper::GetCcnxHeaderType (p);
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -0700249 switch (type)
250 {
251 case CcnxHeaderHelper::INTEREST:
252 {
253 Ptr<CcnxInterestHeader> header = Create<CcnxInterestHeader> ();
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700254
255 // Deserialization. Exception may be thrown
256 packet->RemoveHeader (*header);
257 NS_ASSERT_MSG (packet->GetSize () == 0, "Payload of Interests should be zero");
258
259 OnInterest (face, header, p/*original packet*/);
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -0700260 break;
261 }
262 case CcnxHeaderHelper::CONTENT_OBJECT:
263 {
264 Ptr<CcnxContentObjectHeader> header = Create<CcnxContentObjectHeader> ();
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700265
266 static CcnxContentObjectTail contentObjectTrailer; //there is no data in this object
267
268 // Deserialization. Exception may be thrown
269 packet->RemoveHeader (*header);
270 packet->RemoveTrailer (contentObjectTrailer);
271
272 OnData (face, header, packet/*payload*/, p/*original packet*/);
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -0700273 break;
274 }
275 }
276
277 // exception will be thrown if packet is not recognized
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700278 }
279 catch (CcnxUnknownHeaderException)
280 {
281 NS_ASSERT_MSG (false, "Unknown CCNx header. Should not happen");
282 }
Alexander Afanasyev98256102011-08-14 01:00:02 -0700283}
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700284
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700285// Processing Interests
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -0700286void CcnxL3Protocol::OnInterest (const Ptr<CcnxFace> &incomingFace,
287 Ptr<CcnxInterestHeader> &header,
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700288 const Ptr<const Packet> &packet)
Alexander Afanasyev98256102011-08-14 01:00:02 -0700289{
Alexander Afanasyev070aa482011-08-20 00:38:25 -0700290 NS_LOG_LOGIC ("Receiving interest from " << &incomingFace);
Ilya Moiseenko172763c2011-10-28 13:21:53 -0700291 m_receivedInterestsTrace (header, m_node->GetObject<Ccnx> (), incomingFace);
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700292
Ilya Moiseenkod83eb0d2011-11-16 15:23:46 -0800293
294 if( header->IsNack () )
295 {
296 NS_LOG_INFO("============");
297 NS_LOG_INFO("NACK");
298 NS_LOG_INFO("==========");
299 /*if( header->IsCongested () == false )
300 m_pit->LeakBucket(incomingFace,1);
301
302
303 m_droppedInterestsTrace (header, DROP_CONGESTION,
304 m_node->GetObject<Ccnx> (), incomingFace);
305
306 m_pit->modify(pitEntry, CcnxPitEntry::DeleteOutgoing(incomingFace));*/
307 }
308
309
310
311
Ilya Moiseenko172763c2011-10-28 13:21:53 -0700312 // Lookup of Pit and Fib entries for this Interest
313 CcnxFibEntryContainer::type::iterator fibEntry;
314 CcnxPitEntryContainer::type::iterator pitEntry = m_pit->Lookup (*header, fibEntry);
315
316 // No matter is it duplicate or not, if it is a NACK message, remove all possible incoming
317 // entries for this interface (NACK means that neighbor gave up trying and there is no
318 // point of sending data in this direction)
Ilya Moiseenkob405d9b2011-10-28 16:23:11 -0700319 NS_LOG_INFO("Before (header->IsNack()) && (pitEntry != m_pit->end ())");
Ilya Moiseenko172763c2011-10-28 13:21:53 -0700320 if ((header->IsNack()) && (pitEntry != m_pit->end ()))
321 {
322 //m_pit->erase (pitEntry);
Ilya Moiseenkoc9266042011-11-02 17:49:21 -0700323 NS_LOG_INFO("TRUE");
Ilya Moiseenko172763c2011-10-28 13:21:53 -0700324 m_pit->modify(pitEntry, CcnxPitEntry::DeleteIncoming(incomingFace));
325 }
326
Ilya Moiseenkob405d9b2011-10-28 16:23:11 -0700327 NS_LOG_INFO("Before WasRecentlySatisfied");
Ilya Moiseenkod83eb0d2011-11-16 15:23:46 -0800328 /*if (m_rit->WasRecentlySatisfied (*header))
Ilya Moiseenkoc9266042011-11-02 17:49:21 -0700329 {
330 return;
Ilya Moiseenkod83eb0d2011-11-16 15:23:46 -0800331 }*/
332 if (m_rit->WasRecentlySatisfied (*header))
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700333 {
Ilya Moiseenkod83eb0d2011-11-16 15:23:46 -0800334 NS_LOG_INFO("------------");
Ilya Moiseenkob405d9b2011-10-28 16:23:11 -0700335 NS_LOG_INFO("Entering WasRecentlySatisfied");
Ilya Moiseenkod83eb0d2011-11-16 15:23:46 -0800336 NS_LOG_INFO("------------");
Ilya Moiseenko172763c2011-10-28 13:21:53 -0700337 // duplicate interests (same nonce) from applications are just ignored
338 if (incomingFace->IsLocal() == true)
339 return;
340
341 // Update metric status for the incoming interface in the corresponding FIB entry
Ilya Moiseenkod83eb0d2011-11-16 15:23:46 -0800342 /*if (fibEntry != m_fib->end())
Ilya Moiseenko172763c2011-10-28 13:21:53 -0700343 m_fib->modify (m_fib->iterator_to (pitEntry->m_fibEntry),
344 CcnxFibEntry::UpdateStatus(incomingFace, CcnxFibFaceMetric::NDN_FIB_YELLOW));
345
346 //Trace duplicate interest
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700347 m_droppedInterestsTrace (header, NDN_DUPLICATE_INTEREST,
Ilya Moiseenko172763c2011-10-28 13:21:53 -0700348 m_node->GetObject<Ccnx> (), incomingFace);
349
350 bool isMine = false;
Ilya Moiseenkoc9266042011-11-02 17:49:21 -0700351 //TypeId tid = TypeId ("ns3::CcnxProducer");
Ilya Moiseenko172763c2011-10-28 13:21:53 -0700352 for(uint32_t i=0; i<m_node->GetNApplications();i++)
353 {
354 Ptr<Application> app = m_node->GetApplication(i);
Ilya Moiseenkoc9266042011-11-02 17:49:21 -0700355 NS_LOG_INFO("ApplicationName = " << app->GetTypeId().GetName());
356 if(app->GetTypeId().GetName() == "ns3::CcnxProducer")
Ilya Moiseenko172763c2011-10-28 13:21:53 -0700357 {
358 if((DynamicCast<CcnxProducer>(app))->GetPrefix () == header->GetName ())
359 {
360 isMine = true;
361 break;
362 }
363 }
364 }
365
366 Ptr<Packet> contentObject = m_contentStore->Lookup (header);
367 if ((isMine == true) || (contentObject != NULL))
368 {
369 //never respond with NACK to NACK
370 if(header->IsNack () )
371 return;
372
373 // always return a duplicate packet
374 header->SetNack(true);
375 //Trace duplicate interest
376 m_droppedInterestsTrace (header, NDN_DUPLICATE_INTEREST,
377 m_node->GetObject<Ccnx> (), incomingFace);
378
379 SendInterest(incomingFace, header, packet->Copy());
380
381 return;
382 }
383
384
385 // check PIT. or there is no outgoing entry for this interface,
386 // silently drop the duplicate packet
387
388 // If no entry found, silently drop
389 if( pitEntry == m_pit->end() )
390 return;
391
392 // If PIT entry timed out, silently drop
393 if( pitEntry->m_timerExpired == true )
394 return;
395
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700396 // loop?
Ilya Moiseenko172763c2011-10-28 13:21:53 -0700397
398 // Check if there is no outgoing entry for the interface or different nonce
399 // (i.e., got a duplicate packet, but we haven't sent interest to this
400 // interface)
401 //
402 // This case means that there is a loop in the network.
403 // So, prune this link, but do not remove PIT entry
404
405 // Alex, check this condition!!
406 if(pitEntry->m_outgoing.size () == 0)
407 {
408 //never respond with NACK to NACK
409 if(header->IsNack () )
410 return;
411
412 // always return a duplicate packet
413 header->SetNack(true);
414 //Trace duplicate interest
415 m_droppedInterestsTrace (header, NDN_DUPLICATE_INTEREST,
416 m_node->GetObject<Ccnx> (), incomingFace);
417
418 SendInterest(incomingFace, header, packet->Copy());
419 return;
420 }
421
422
423 // At this point:
424 // - there is a non-expired PIT entry,
425 // - there is an outgoing interest to the interface, and
426 // - a nonce in outgoing entry is equal to a nonce in the received duplicate packet
427
428 // Should perform:
429 // Cleaning outgoing entry
430 // If there are no outgoing interests and available interfaces left (pe->availableInterfaces),
431 // prune all incoming interests, otherwise allow forwarding of the interest
432 if( header->IsNack () )
433 {
434 if( header->IsCongested () == false )
435 m_pit->LeakBucket(incomingFace,1);
436
437 m_pit->modify(pitEntry, CcnxPitEntry::DeleteOutgoing(incomingFace));
438 }
439 else
440 {
441 //poit->waitingInVain = true;
442 }
443
444
445 // prune all incoming interests
446 if((pitEntry->m_outgoing.size() ==0) && (pitEntry->m_fibEntry.m_faces.size() == 0))
447 {
448 BOOST_FOREACH (const CcnxPitEntryIncomingFace face, pitEntry->m_incoming)
449 {
450 if(face.m_face->IsLocal() == false)
451 {
452 // check all entries if the name of RIT entry matches the name of interest
453 for (CcnxRitByNonce::type::iterator it = m_rit->begin(); it != m_rit->end(); it++)
454 {
455 if (it->m_prefix == pitEntry->GetPrefix() )
456 {
457
458 header->SetNonce(it->m_nonce);
459 header->SetNack(true);
460 SendInterest(face.m_face, header, packet->Copy());
461 break;
462 }
463 }
464 }
465 }
466
467 // Finally, remote the PIT entry
468 m_pit->erase (pitEntry);
469
470 return; // stop processing
471 }
472
473 if(pitEntry->m_fibEntry.m_faces.size() == 0)
Ilya Moiseenkod83eb0d2011-11-16 15:23:46 -0800474 return;*/
Ilya Moiseenko172763c2011-10-28 13:21:53 -0700475 return;
Ilya Moiseenkod83eb0d2011-11-16 15:23:46 -0800476 }
477
478
Ilya Moiseenko172763c2011-10-28 13:21:53 -0700479
480 // Otherwise,
481 // propagate the interest
482 //
483 // method `propagateInterest' can/should try different interface
484 // from `availableInterfaces' list
485
Ilya Moiseenkob405d9b2011-10-28 16:23:11 -0700486 NS_LOG_INFO("Before SetRecentlySatisfied");
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700487 m_rit->SetRecentlySatisfied (*header);
488
Ilya Moiseenko172763c2011-10-28 13:21:53 -0700489 NS_LOG_INFO("Cache Lookup for " << header->GetName());
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700490 Ptr<Packet> contentObject = m_contentStore->Lookup (header);
Ilya Moiseenko172763c2011-10-28 13:21:53 -0700491 if (contentObject != NULL)
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700492 {
Ilya Moiseenko172763c2011-10-28 13:21:53 -0700493 NS_LOG_INFO("Found in cache");
494
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700495 TransmittedDataTrace (contentObject, CACHED,
Ilya Moiseenko172763c2011-10-28 13:21:53 -0700496 m_node->GetObject<Ccnx> (), incomingFace);
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700497 incomingFace->Send (contentObject);
498 return;
499 }
Alexander Afanasyev070aa482011-08-20 00:38:25 -0700500
Ilya Moiseenko172763c2011-10-28 13:21:53 -0700501 // Data is not in cache
Ilya Moiseenkob405d9b2011-10-28 16:23:11 -0700502 NS_LOG_INFO("Before inFace and OutFace");
Ilya Moiseenko172763c2011-10-28 13:21:53 -0700503 CcnxPitEntryIncomingFaceContainer::type::iterator inFace = pitEntry->m_incoming.find (incomingFace);
504 CcnxPitEntryOutgoingFaceContainer::type::iterator outFace = pitEntry->m_outgoing.find (incomingFace);
505
Alexander Afanasyevd02a5d62011-11-21 11:01:51 -0800506 NS_LOG_INFO("Before (pitEntry != m_pit->end()) && (pitEntry->m_timerExpired == false)");
Ilya Moiseenko172763c2011-10-28 13:21:53 -0700507 if ((pitEntry != m_pit->end()) && (pitEntry->m_timerExpired == false))
508 {
Ilya Moiseenkob405d9b2011-10-28 16:23:11 -0700509 NS_LOG_INFO("Entering (pitEntry != m_pit->end()) && (pitEntry->m_timerExpired == false)");
510
Alexander Afanasyevd02a5d62011-11-21 11:01:51 -0800511 if(inFace->m_face == 0)
Ilya Moiseenkob405d9b2011-10-28 16:23:11 -0700512 NS_LOG_INFO("in face is null");
Alexander Afanasyevd02a5d62011-11-21 11:01:51 -0800513 if(outFace->m_face == 0)
Ilya Moiseenkob405d9b2011-10-28 16:23:11 -0700514 NS_LOG_INFO("outface is null");
Ilya Moiseenkod83eb0d2011-11-16 15:23:46 -0800515 if(outFace == pitEntry->m_outgoing.end())
516 NS_LOG_INFO("OUTFACE = END");
Ilya Moiseenko172763c2011-10-28 13:21:53 -0700517
518 // If we're expecting data from the interface we got the interest from ("producer" asks us for "his own" data)
519 // Give up this interface, but keep a small hope when the returned packet doesn't have PRUNE status
Ilya Moiseenkod83eb0d2011-11-16 15:23:46 -0800520 if(outFace != pitEntry->m_outgoing.end()) // this is correct
Ilya Moiseenko172763c2011-10-28 13:21:53 -0700521 {
Ilya Moiseenkob405d9b2011-10-28 16:23:11 -0700522 NS_LOG_INFO("Entering outFace != pitEntry->m_outgoing.end()");
Ilya Moiseenko172763c2011-10-28 13:21:53 -0700523 if( header->IsCongested() == true )
524 {
Ilya Moiseenkob405d9b2011-10-28 16:23:11 -0700525 NS_LOG_INFO("Entering header->IsCongested() == true");
Ilya Moiseenko172763c2011-10-28 13:21:53 -0700526 m_pit->LeakBucket(incomingFace, 1);
527 m_pit->modify (pitEntry, CcnxPitEntry::DeleteOutgoing(outFace->m_face));
528 }
529 //else
530 // poit->waitingInVain = true;
531
532 // Update metric status for the incoming interface in the corresponding FIB entry
533 if(fibEntry != m_fib->end())
534 m_fib->modify(m_fib->iterator_to (pitEntry->m_fibEntry),
535 CcnxFibEntry::UpdateStatus(incomingFace, CcnxFibFaceMetric::NDN_FIB_YELLOW));
536 }
537 }
538
Ilya Moiseenkob405d9b2011-10-28 16:23:11 -0700539 NS_LOG_INFO("Before (pitEntry->m_outgoing.size() == 0) && (pitEntry->m_fibEntry.m_faces.size() == 0)");
Ilya Moiseenko172763c2011-10-28 13:21:53 -0700540 if((pitEntry->m_outgoing.size() == 0) && (pitEntry->m_fibEntry.m_faces.size() == 0))
541 // prune all incoming interests
542 {
543
544 for(CcnxPitEntryContainer::type::iterator iter = m_pit->begin();
545 iter != m_pit->end();
546 iter++)
547 {
548 /*for(CcnxPitEntryIncomingFaceContainer::type::iterator face = iter->m_incoming.begin();
549 face != iter->m_incoming.end();
550 face++)*/
551 BOOST_FOREACH (const CcnxPitEntryIncomingFace face, iter->m_incoming)
552 {
553 if(face.m_face->IsLocal() == true)
554 {
555 //returnInterestToApp( pkt, -piit->interfaceIndex );
556 //continue;
557 }
558
559 // check all entries if the name of RIT entry matches the name of interest
560 for (CcnxRitByNonce::type::iterator it = m_rit->begin(); it != m_rit->end(); it++)
561 {
562 if (it->m_prefix == iter->GetPrefix() )
563 {
564 header->SetNonce(it->m_nonce);
565 header->SetNack(true);
566 SendInterest(face.m_face, header, packet->Copy());
567 }
568 }
569 }
570
571 }
572
573 m_pit->erase(pitEntry);
574
575 return; // there is nothing else to do
576 }
577
578 // Suppress this interest only if we're still expecting data from some other interface
579 if( pitEntry->m_outgoing.size() > 0 )
580 {
581 return; //ok. Now we can suppress this interest
582 }
583
584
585 // Prune and delete PIT entry if there are no available interfaces to propagate interest
586 if( pitEntry->m_fibEntry.m_faces.size() == 0)
587 {
588 //if no match is found in the FIB, drop packet
589 //printf( "Node %d: cannot process Interest packet %s (no interfaces left)\n", _node->nodeId, pkt->contentName );
590
591 if(incomingFace->IsLocal() == false)
592 {
593 header->SetNack(true);
594 m_droppedInterestsTrace (header, NDN_SUPPRESSED_INTEREST,
595 m_node->GetObject<Ccnx> (), incomingFace);
596 SendInterest(incomingFace, header, packet->Copy());
597 }
598
599 m_pit->erase(pitEntry);
600
601 }
602
603
604
605 // otherwise, try one of the available interfaces
606
607 // suppress interest if
608 /*if (pitEntry->m_incoming.size () != 0 && // not a new PIT entry and
609 inFace != pitEntry->m_incoming.end ()) // existing entry, but interest received via different face
610 {
611 m_droppedInterestsTrace (header, NDN_SUPPRESSED_INTEREST,
612 m_node->GetObject<Ccnx> (), incomingFace);
613 return;
614 }*/
615
616
617 //just in case of bug
618 header->SetNack(false);
619 header->SetCongested(false);
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700620
Ilya Moiseenko00b30482011-11-15 17:58:00 -0800621 NS_ASSERT_MSG (m_forwardingStrategy != 0, "Need a forwarding protocol object to process packets");
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700622
Ilya Moiseenko00b30482011-11-15 17:58:00 -0800623 m_pit->modify (pitEntry, CcnxPitEntry::AddIncoming(incomingFace));
Ilya Moiseenko172763c2011-10-28 13:21:53 -0700624
Ilya Moiseenko00b30482011-11-15 17:58:00 -0800625 bool propagated = m_forwardingStrategy->
626 PropagateInterest (pitEntry, fibEntry,incomingFace, header, packet,
627 MakeCallback (&CcnxL3Protocol::SendInterest, this)
628 );
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700629
Ilya Moiseenko00b30482011-11-15 17:58:00 -0800630 // If interest wasn't propagated further (probably, a limit is reached),
631 // prune and delete PIT entry if there are no outstanding interests.
632 // Stop processing otherwise.
Ilya Moiseenkod83eb0d2011-11-16 15:23:46 -0800633 if( (!propagated) && (pitEntry->m_outgoing.size() == 0)) // this line works
Ilya Moiseenko00b30482011-11-15 17:58:00 -0800634 {
635 BOOST_FOREACH (const CcnxPitEntryIncomingFace face, pitEntry->m_incoming)
636 {
637 header->SetNack(true);
638 header->SetCongested(true);
Ilya Moiseenkod83eb0d2011-11-16 15:23:46 -0800639 NS_LOG_INFO("Sending CONGESTION packet");
Ilya Moiseenko00b30482011-11-15 17:58:00 -0800640 SendInterest (face.m_face, header, packet->Copy());
Ilya Moiseenko172763c2011-10-28 13:21:53 -0700641
Ilya Moiseenko00b30482011-11-15 17:58:00 -0800642 m_droppedInterestsTrace (header, DROP_CONGESTION,
Ilya Moiseenko172763c2011-10-28 13:21:53 -0700643 m_node->GetObject<Ccnx> (), incomingFace);
Ilya Moiseenko00b30482011-11-15 17:58:00 -0800644 }
Ilya Moiseenko172763c2011-10-28 13:21:53 -0700645
646 m_pit->erase (pitEntry);
Ilya Moiseenko00b30482011-11-15 17:58:00 -0800647 }
Ilya Moiseenko172763c2011-10-28 13:21:53 -0700648 /*}
649 else
650 {
651 m_droppedInterestsTrace (header, NDN_PIT_TIMER_EXPIRED,
652 m_node->GetObject<Ccnx> (), incomingFace);
653 return;
654 }*/
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700655}
656
657// Processing ContentObjects
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -0700658void CcnxL3Protocol::OnData (const Ptr<CcnxFace> &incomingFace,
659 Ptr<CcnxContentObjectHeader> &header,
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700660 Ptr<Packet> &payload,
661 const Ptr<const Packet> &packet)
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700662{
Ilya Moiseenko172763c2011-10-28 13:21:53 -0700663
Alexander Afanasyev070aa482011-08-20 00:38:25 -0700664 NS_LOG_LOGIC ("Receiving contentObject from " << &incomingFace);
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700665 m_receivedDataTrace (header, payload, m_node->GetObject<Ccnx> ()/*this*/, incomingFace);
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700666
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700667 // 1. Lookup PIT entry
668 try
669 {
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700670 const CcnxPitEntry &pitEntry = m_pit->Lookup (*header);
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700671
672 // Note that with MultiIndex we need to modify entries indirectly
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -0700673
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700674 // Update metric status for the incoming interface in the corresponding FIB entry
675 m_fib->modify (m_fib->iterator_to (pitEntry.m_fibEntry),
676 CcnxFibEntry::UpdateStatus (incomingFace, CcnxFibFaceMetric::NDN_FIB_GREEN));
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700677
678 // Add or update entry in the content store
Ilya Moiseenko172763c2011-10-28 13:21:53 -0700679 NS_LOG_INFO("Cached " << header->GetName());
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700680 m_contentStore->Add (header, payload);
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700681
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700682 CcnxPitEntryOutgoingFaceContainer::type::iterator
683 out = pitEntry.m_outgoing.find (incomingFace);
684
685 // If we have sent interest for this data via this face, then update stats.
686 if (out != pitEntry.m_outgoing.end ())
687 {
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700688 m_pit->modify (m_pit->iterator_to (pitEntry),
689 CcnxPitEntry::EstimateRttAndRemoveFace(out, m_fib));
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700690 // face will be removed in the above call
691 }
692 else
693 {
694 NS_LOG_WARN ("Node "<< m_node->GetId() <<
695 ". PIT entry for "<< header->GetName ()<<" is valid, "
696 "but outgoing entry for interface "<< incomingFace <<" doesn't exist\n");
697 }
698
699 //satisfy all pending incoming Interests
700 BOOST_FOREACH (const CcnxPitEntryIncomingFace &interest, pitEntry.m_incoming)
701 {
702 if (interest.m_face == incomingFace) continue;
703
704 // may not work either because of 'const' thing
705 interest.m_face->Send (packet->Copy ()); // unfortunately, we have to copy packet...
706 m_transmittedDataTrace (header, payload, FORWARDED, m_node->GetObject<Ccnx> (), interest.m_face);
707 }
708
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700709 m_pit->modify (m_pit->iterator_to (pitEntry), CcnxPitEntry::ClearIncoming()); // satisfy all incoming interests
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700710
711 if( pitEntry.m_outgoing.size()==0 ) // remove PIT when all outgoing interests are "satisfied"
712 {
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700713 m_pit->erase (m_pit->iterator_to (pitEntry));
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700714 }
715
716 }
717 catch (CcnxPitEntryNotFound)
718 {
719 // 2. Drop data packet if PIT entry is not found
720 // (unsolicited data packets should not "poison" content store)
721
722 //drop dulicated or not requested data packet
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700723 m_droppedDataTrace (header, payload, NDN_UNSOLICITED_DATA, m_node->GetObject<Ccnx> (), incomingFace);
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700724 return; // do not process unsoliced data packets
725 }
726}
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700727
728void
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700729CcnxL3Protocol::SendInterest (const Ptr<CcnxFace> &face,
730 const Ptr<CcnxInterestHeader> &header,
731 const Ptr<Packet> &packet)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700732{
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700733 NS_LOG_FUNCTION (this << "packet: " << &packet << ", face: "<< &face);
Alexander Afanasyev070aa482011-08-20 00:38:25 -0700734 NS_ASSERT_MSG (face != 0, "Face should never be NULL");
735
736 if (face->IsUp ())
737 {
738 NS_LOG_LOGIC ("Sending via face " << &face); //
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700739 m_transmittedInterestsTrace (header, m_node->GetObject<Ccnx> (), face);
740 face->Send (packet);
741 }
742 else
743 {
744 NS_LOG_LOGIC ("Dropping -- outgoing interface is down: " << &face);
745 m_droppedInterestsTrace (header, INTERFACE_DOWN, m_node->GetObject<Ccnx> (), face);
746 }
747}
748
749void
750CcnxL3Protocol::SendContentObject (const Ptr<CcnxFace> &face,
751 const Ptr<CcnxContentObjectHeader> &header,
752 const Ptr<Packet> &packet)
753{
754 NS_LOG_FUNCTION (this << "packet: " << &packet << ", face: "<< &face);
755 NS_ASSERT_MSG (face != 0, "Face should never be NULL");
756
757 NS_ASSERT_MSG (false, "Should not be called for now");
758
759 if (face->IsUp ())
760 {
761 NS_LOG_LOGIC ("Sending via face " << &face); //
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -0700762 // m_txTrace (packet, m_node->GetObject<Ccnx> (), face);
Alexander Afanasyev070aa482011-08-20 00:38:25 -0700763 face->Send (packet);
764 }
765 else
766 {
767 NS_LOG_LOGIC ("Dropping -- outgoing interface is down: " << &face);
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700768 // m_dropTrace (packet, INTERFACE_DOWN, m_node->GetObject<Ccnx> (), face);
Alexander Afanasyev070aa482011-08-20 00:38:25 -0700769 }
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700770}
771
Ilya Moiseenko172763c2011-10-28 13:21:53 -0700772Ptr<CcnxPit>
773CcnxL3Protocol::GetPit()
774{
775 return m_pit;
776}
Ilya Moiseenkod83eb0d2011-11-16 15:23:46 -0800777
778void
779CcnxL3Protocol::ScheduleLeakage()
780{
781 m_pit->LeakBuckets();
782 Time interval = MilliSeconds (NDN_INTEREST_RESET_PERIOD);
783 Simulator::Schedule (interval, &CcnxL3Protocol::ScheduleLeakage, this);
784}
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700785} //namespace ns3