blob: 1e13726027bb42d93fcaacae1bf8ec2602c9d571 [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 Afanasyev161a5c42012-04-17 15:14:04 -070026#include "ns3/weights-path-stretch-tag.h"
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080027
Ilya Moiseenko4e473482011-10-31 17:58:14 -070028#include "ns3/assert.h"
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080029#include "ns3/log.h"
Ilya Moiseenko4e473482011-10-31 17:58:14 -070030
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080031#include <boost/lambda/lambda.hpp>
32#include <boost/lambda/bind.hpp>
33namespace ll = boost::lambda;
34
Ilya Moiseenko4e473482011-10-31 17:58:14 -070035NS_LOG_COMPONENT_DEFINE ("CcnxBestRouteStrategy");
Ilya Moiseenko4e473482011-10-31 17:58:14 -070036
37namespace ns3
38{
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080039
40using namespace __ccnx_private;
41
Ilya Moiseenko4e473482011-10-31 17:58:14 -070042NS_OBJECT_ENSURE_REGISTERED (CcnxBestRouteStrategy);
43
44TypeId CcnxBestRouteStrategy::GetTypeId (void)
45{
46 static TypeId tid = TypeId ("ns3::CcnxBestRouteStrategy")
Alexander Afanasyev11453142011-11-25 16:13:33 -080047 .SetGroupName ("Ccnx")
48 .SetParent <CcnxForwardingStrategy> ()
49 .AddConstructor <CcnxBestRouteStrategy> ()
50 ;
Ilya Moiseenko4e473482011-10-31 17:58:14 -070051 return tid;
52}
53
54CcnxBestRouteStrategy::CcnxBestRouteStrategy ()
55{
56}
57
Ilya Moiseenko4e473482011-10-31 17:58:14 -070058bool
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080059CcnxBestRouteStrategy::PropagateInterest (const CcnxPitEntry &pitEntry,
Ilya Moiseenko4e473482011-10-31 17:58:14 -070060 const Ptr<CcnxFace> &incomingFace,
61 Ptr<CcnxInterestHeader> &header,
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080062 const Ptr<const Packet> &packet)
Ilya Moiseenko4e473482011-10-31 17:58:14 -070063{
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080064 NS_LOG_FUNCTION (this);
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080065
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080066
67
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080068 // Try to work out with just green faces
69 bool greenOk = PropagateInterestViaGreen (pitEntry, incomingFace, header, packet);
70 if (greenOk)
71 return true;
72
73 int propagatedCount = 0;
74
75 BOOST_FOREACH (const CcnxFibFaceMetric &metricFace, pitEntry.m_fibEntry.m_faces.get<i_metric> ())
Ilya Moiseenko4e473482011-10-31 17:58:14 -070076 {
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080077 if (metricFace.m_status == CcnxFibFaceMetric::NDN_FIB_RED) // all non-read faces are in front
78 break;
79
80 if (metricFace.m_face == incomingFace)
81 continue; // same face as incoming, don't forward
82
83 if (pitEntry.m_incoming.find (metricFace.m_face) != pitEntry.m_incoming.end ())
84 continue; // don't forward to face that we received interest from
85
86 CcnxPitEntryOutgoingFaceContainer::type::iterator outgoing =
87 pitEntry.m_outgoing.find (metricFace.m_face);
88
89 if (outgoing != pitEntry.m_outgoing.end () &&
90 outgoing->m_retxCount >= pitEntry.m_maxRetxCount)
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080091 {
Alexander Afanasyev120bf312011-12-19 01:24:47 -080092 NS_LOG_ERROR (outgoing->m_retxCount << " >= " << pitEntry.m_maxRetxCount);
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080093 continue; // already forwarded before during this retransmission cycle
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080094 }
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080095
96 bool faceAvailable = metricFace.m_face->IsBelowLimit ();
97 if (!faceAvailable) // huh...
98 {
99 continue;
100 }
101
102 m_pit->modify (m_pit->iterator_to (pitEntry),
103 ll::bind(&CcnxPitEntry::AddOutgoing, ll::_1, metricFace.m_face));
104
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800105 Ptr<Packet> packetToSend = packet->Copy ();
Ilya Moiseenko1a8be032012-01-18 12:51:09 -0800106
107 //transmission
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800108 metricFace.m_face->Send (packetToSend);
Alexander Afanasyevf377b332011-12-16 15:32:12 -0800109 m_transmittedInterestsTrace (header, metricFace.m_face);
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800110
111 propagatedCount++;
112 break; // do only once
Ilya Moiseenko4e473482011-10-31 17:58:14 -0700113 }
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800114
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800115 NS_LOG_INFO ("Propagated to " << propagatedCount << " faces");
116 return propagatedCount > 0;
Ilya Moiseenko4e473482011-10-31 17:58:14 -0700117}
118
119} //namespace ns3