blob: 2bbe28756d00e3a8c6263bc954b76fafbe1f9aff [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 Afanasyevf377b332011-12-16 15:32:12 -080022
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080023#include "ccnx-interest-header.h"
Alexander Afanasyevf377b332011-12-16 15:32:12 -080024#include "ccnx-pit.h"
25#include "ccnx-pit-entry.h"
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080026
Ilya Moiseenko4e473482011-10-31 17:58:14 -070027#include "ns3/assert.h"
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080028#include "ns3/log.h"
Ilya Moiseenko4e473482011-10-31 17:58:14 -070029
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080030#include <boost/lambda/lambda.hpp>
31#include <boost/lambda/bind.hpp>
32namespace ll = boost::lambda;
33
Ilya Moiseenko4e473482011-10-31 17:58:14 -070034NS_LOG_COMPONENT_DEFINE ("CcnxBestRouteStrategy");
Ilya Moiseenko4e473482011-10-31 17:58:14 -070035
36namespace ns3
37{
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080038
39using namespace __ccnx_private;
40
Ilya Moiseenko4e473482011-10-31 17:58:14 -070041NS_OBJECT_ENSURE_REGISTERED (CcnxBestRouteStrategy);
42
43TypeId CcnxBestRouteStrategy::GetTypeId (void)
44{
45 static TypeId tid = TypeId ("ns3::CcnxBestRouteStrategy")
Alexander Afanasyev11453142011-11-25 16:13:33 -080046 .SetGroupName ("Ccnx")
47 .SetParent <CcnxForwardingStrategy> ()
48 .AddConstructor <CcnxBestRouteStrategy> ()
49 ;
Ilya Moiseenko4e473482011-10-31 17:58:14 -070050 return tid;
51}
52
53CcnxBestRouteStrategy::CcnxBestRouteStrategy ()
54{
55}
56
Ilya Moiseenko4e473482011-10-31 17:58:14 -070057bool
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080058CcnxBestRouteStrategy::PropagateInterest (const CcnxPitEntry &pitEntry,
Ilya Moiseenko4e473482011-10-31 17:58:14 -070059 const Ptr<CcnxFace> &incomingFace,
60 Ptr<CcnxInterestHeader> &header,
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080061 const Ptr<const Packet> &packet)
Ilya Moiseenko4e473482011-10-31 17:58:14 -070062{
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080063 NS_LOG_FUNCTION (this);
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080064
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080065 // Try to work out with just green faces
66 bool greenOk = PropagateInterestViaGreen (pitEntry, incomingFace, header, packet);
67 if (greenOk)
68 return true;
69
70 int propagatedCount = 0;
71
72 BOOST_FOREACH (const CcnxFibFaceMetric &metricFace, pitEntry.m_fibEntry.m_faces.get<i_metric> ())
Ilya Moiseenko4e473482011-10-31 17:58:14 -070073 {
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080074 if (metricFace.m_status == CcnxFibFaceMetric::NDN_FIB_RED) // all non-read faces are in front
75 break;
76
77 if (metricFace.m_face == incomingFace)
78 continue; // same face as incoming, don't forward
79
80 if (pitEntry.m_incoming.find (metricFace.m_face) != pitEntry.m_incoming.end ())
81 continue; // don't forward to face that we received interest from
82
83 CcnxPitEntryOutgoingFaceContainer::type::iterator outgoing =
84 pitEntry.m_outgoing.find (metricFace.m_face);
85
86 if (outgoing != pitEntry.m_outgoing.end () &&
87 outgoing->m_retxCount >= pitEntry.m_maxRetxCount)
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080088 {
Alexander Afanasyev120bf312011-12-19 01:24:47 -080089 NS_LOG_ERROR (outgoing->m_retxCount << " >= " << pitEntry.m_maxRetxCount);
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080090 continue; // already forwarded before during this retransmission cycle
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080091 }
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080092
93 bool faceAvailable = metricFace.m_face->IsBelowLimit ();
94 if (!faceAvailable) // huh...
95 {
96 continue;
97 }
98
99 m_pit->modify (m_pit->iterator_to (pitEntry),
100 ll::bind(&CcnxPitEntry::AddOutgoing, ll::_1, metricFace.m_face));
101
102 metricFace.m_face->Send (packet->Copy ());
Alexander Afanasyevf377b332011-12-16 15:32:12 -0800103 m_transmittedInterestsTrace (header, metricFace.m_face);
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800104
105 propagatedCount++;
106 break; // do only once
Ilya Moiseenko4e473482011-10-31 17:58:14 -0700107 }
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800108
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800109 NS_LOG_INFO ("Propagated to " << propagatedCount << " faces");
110 return propagatedCount > 0;
Ilya Moiseenko4e473482011-10-31 17:58:14 -0700111}
112
113} //namespace ns3