blob: b850d08946d324ae21f654a904727c178145f744 [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{
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080035
36using namespace __ccnx_private;
37
Ilya Moiseenko4e473482011-10-31 17:58:14 -070038NS_OBJECT_ENSURE_REGISTERED (CcnxBestRouteStrategy);
39
40TypeId CcnxBestRouteStrategy::GetTypeId (void)
41{
42 static TypeId tid = TypeId ("ns3::CcnxBestRouteStrategy")
Alexander Afanasyev11453142011-11-25 16:13:33 -080043 .SetGroupName ("Ccnx")
44 .SetParent <CcnxForwardingStrategy> ()
45 .AddConstructor <CcnxBestRouteStrategy> ()
46 ;
Ilya Moiseenko4e473482011-10-31 17:58:14 -070047 return tid;
48}
49
50CcnxBestRouteStrategy::CcnxBestRouteStrategy ()
51{
52}
53
Ilya Moiseenko4e473482011-10-31 17:58:14 -070054bool
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080055CcnxBestRouteStrategy::PropagateInterest (const CcnxPitEntry &pitEntry,
Ilya Moiseenko4e473482011-10-31 17:58:14 -070056 const Ptr<CcnxFace> &incomingFace,
57 Ptr<CcnxInterestHeader> &header,
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080058 const Ptr<const Packet> &packet)
Ilya Moiseenko4e473482011-10-31 17:58:14 -070059{
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080060 NS_LOG_FUNCTION (this);
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080061
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080062 // Try to work out with just green faces
63 bool greenOk = PropagateInterestViaGreen (pitEntry, incomingFace, header, packet);
64 if (greenOk)
65 return true;
66
67 int propagatedCount = 0;
68
69 BOOST_FOREACH (const CcnxFibFaceMetric &metricFace, pitEntry.m_fibEntry.m_faces.get<i_metric> ())
Ilya Moiseenko4e473482011-10-31 17:58:14 -070070 {
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080071 if (metricFace.m_status == CcnxFibFaceMetric::NDN_FIB_RED) // all non-read faces are in front
72 break;
73
74 if (metricFace.m_face == incomingFace)
75 continue; // same face as incoming, don't forward
76
77 if (pitEntry.m_incoming.find (metricFace.m_face) != pitEntry.m_incoming.end ())
78 continue; // don't forward to face that we received interest from
79
80 CcnxPitEntryOutgoingFaceContainer::type::iterator outgoing =
81 pitEntry.m_outgoing.find (metricFace.m_face);
82
83 if (outgoing != pitEntry.m_outgoing.end () &&
84 outgoing->m_retxCount >= pitEntry.m_maxRetxCount)
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080085 {
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080086 continue; // already forwarded before during this retransmission cycle
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080087 }
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080088
89 bool faceAvailable = metricFace.m_face->IsBelowLimit ();
90 if (!faceAvailable) // huh...
91 {
92 continue;
93 }
94
95 m_pit->modify (m_pit->iterator_to (pitEntry),
96 ll::bind(&CcnxPitEntry::AddOutgoing, ll::_1, metricFace.m_face));
97
98 metricFace.m_face->Send (packet->Copy ());
99
100 propagatedCount++;
101 break; // do only once
Ilya Moiseenko4e473482011-10-31 17:58:14 -0700102 }
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800103
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800104 NS_LOG_INFO ("Propagated to " << propagatedCount << " faces");
105 return propagatedCount > 0;
Ilya Moiseenko4e473482011-10-31 17:58:14 -0700106}
107
108} //namespace ns3