blob: 20d1a816b7c406411ef74d0416e587f0714fd04b [file] [log] [blame]
Ilya Moiseenko4e473482011-10-31 17:58:14 -07001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
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: Ilya Moiseenko <iliamo@cs.ucla.edu>
19 */
20
21#include "ccnx-bestroute-strategy.h"
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080022#include "ccnx-interest-header.h"
23
Ilya Moiseenko4e473482011-10-31 17:58:14 -070024#include "ns3/assert.h"
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080025#include "ns3/log.h"
Ilya Moiseenko4e473482011-10-31 17:58:14 -070026
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080027#include <boost/lambda/lambda.hpp>
28#include <boost/lambda/bind.hpp>
29namespace ll = boost::lambda;
30
Ilya Moiseenko4e473482011-10-31 17:58:14 -070031NS_LOG_COMPONENT_DEFINE ("CcnxBestRouteStrategy");
Ilya Moiseenko4e473482011-10-31 17:58:14 -070032
33namespace ns3
34{
35
Ilya Moiseenko4e473482011-10-31 17:58:14 -070036NS_OBJECT_ENSURE_REGISTERED (CcnxBestRouteStrategy);
37
38TypeId CcnxBestRouteStrategy::GetTypeId (void)
39{
40 static TypeId tid = TypeId ("ns3::CcnxBestRouteStrategy")
41 .SetGroupName ("Ccnx")
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080042 .SetParent<CcnxForwardingStrategy> ()
Ilya Moiseenko4e473482011-10-31 17:58:14 -070043 ;
44 return tid;
45}
46
47CcnxBestRouteStrategy::CcnxBestRouteStrategy ()
48{
49}
50
Ilya Moiseenko4e473482011-10-31 17:58:14 -070051bool
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080052CcnxBestRouteStrategy::PropagateInterest (const CcnxPitEntry &pitEntry,
Ilya Moiseenko4e473482011-10-31 17:58:14 -070053 const Ptr<CcnxFace> &incomingFace,
54 Ptr<CcnxInterestHeader> &header,
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080055 const Ptr<const Packet> &packet)
Ilya Moiseenko4e473482011-10-31 17:58:14 -070056{
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080057 NS_LOG_FUNCTION (this);
58 bool forwardedCount = 0;
59
60 try
Ilya Moiseenko4e473482011-10-31 17:58:14 -070061 {
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080062 for (uint32_t skip = 0; skip < pitEntry.m_fibEntry.m_faces.size (); skip++)
63 {
64 const CcnxFibFaceMetric bestMetric = pitEntry.m_fibEntry.FindBestCandidate (skip);
65
66 if (bestMetric.m_status == CcnxFibFaceMetric::NDN_FIB_RED) // no point to send there
67 continue;
68
Alexander Afanasyev5a595072011-11-25 14:49:07 -080069 if (pitEntry.m_incoming.find (bestMetric.m_face) != pitEntry.m_incoming.end ())
70 continue; // don't forward to face that we received interest from
71
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080072 if (pitEntry.m_outgoing.find (bestMetric.m_face) != pitEntry.m_outgoing.end ()) // already forwarded before
73 continue;
74
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080075 bool faceAvailable = bestMetric.m_face->IsBelowLimit ();
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080076 if (!faceAvailable) // huh...
77 continue;
78
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080079 m_pit->modify (m_pit->iterator_to (pitEntry),
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080080 ll::bind(&CcnxPitEntry::AddOutgoing, ll::_1, bestMetric.m_face));
81
82 // NS_LOG_DEBUG ("new outgoing entry for " << boost::cref (*metricFace.m_face));
83
84 bestMetric.m_face->Send (packet->Copy ());
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080085
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080086 forwardedCount++;
87 break; // if we succeeded in sending one packet, stop
88 }
Ilya Moiseenko4e473482011-10-31 17:58:14 -070089 }
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080090 catch (CcnxFibEntry::NoFaces)
Ilya Moiseenko4e473482011-10-31 17:58:14 -070091 {
Ilya Moiseenko4e473482011-10-31 17:58:14 -070092 }
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080093
94 return forwardedCount > 0;
Ilya Moiseenko4e473482011-10-31 17:58:14 -070095}
96
97} //namespace ns3