blob: 3295d31180941095cfa6ceffaf76557e9f4995c2 [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 *
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070018 * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
19 * Ilya Moiseenko <iliamo@cs.ucla.edu>
Ilya Moiseenko4e473482011-10-31 17:58:14 -070020 */
21
22#include "ccnx-bestroute-strategy.h"
Alexander Afanasyevf377b332011-12-16 15:32:12 -080023
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080024#include "ccnx-interest-header.h"
Alexander Afanasyevf377b332011-12-16 15:32:12 -080025#include "ccnx-pit.h"
26#include "ccnx-pit-entry.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 Afanasyev11f7bb42012-07-09 17:06:30 -070031#include <boost/foreach.hpp>
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080032#include <boost/lambda/lambda.hpp>
33#include <boost/lambda/bind.hpp>
34namespace ll = boost::lambda;
35
Ilya Moiseenko4e473482011-10-31 17:58:14 -070036NS_LOG_COMPONENT_DEFINE ("CcnxBestRouteStrategy");
Ilya Moiseenko4e473482011-10-31 17:58:14 -070037
38namespace ns3
39{
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080040
41using namespace __ccnx_private;
42
Ilya Moiseenko4e473482011-10-31 17:58:14 -070043NS_OBJECT_ENSURE_REGISTERED (CcnxBestRouteStrategy);
44
45TypeId CcnxBestRouteStrategy::GetTypeId (void)
46{
47 static TypeId tid = TypeId ("ns3::CcnxBestRouteStrategy")
Alexander Afanasyev11453142011-11-25 16:13:33 -080048 .SetGroupName ("Ccnx")
49 .SetParent <CcnxForwardingStrategy> ()
50 .AddConstructor <CcnxBestRouteStrategy> ()
51 ;
Ilya Moiseenko4e473482011-10-31 17:58:14 -070052 return tid;
53}
54
55CcnxBestRouteStrategy::CcnxBestRouteStrategy ()
56{
57}
58
Ilya Moiseenko4e473482011-10-31 17:58:14 -070059bool
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080060CcnxBestRouteStrategy::PropagateInterest (const CcnxPitEntry &pitEntry,
Ilya Moiseenko4e473482011-10-31 17:58:14 -070061 const Ptr<CcnxFace> &incomingFace,
62 Ptr<CcnxInterestHeader> &header,
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080063 const Ptr<const Packet> &packet)
Ilya Moiseenko4e473482011-10-31 17:58:14 -070064{
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080065 NS_LOG_FUNCTION (this);
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080066
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080067
68
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080069 // Try to work out with just green faces
70 bool greenOk = PropagateInterestViaGreen (pitEntry, incomingFace, header, packet);
71 if (greenOk)
72 return true;
73
74 int propagatedCount = 0;
75
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -070076 BOOST_FOREACH (const CcnxFibFaceMetric &metricFace, pitEntry.m_fibEntry->m_faces.get<i_metric> ())
Ilya Moiseenko4e473482011-10-31 17:58:14 -070077 {
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080078 if (metricFace.m_status == CcnxFibFaceMetric::NDN_FIB_RED) // all non-read faces are in front
79 break;
80
81 if (metricFace.m_face == incomingFace)
82 continue; // same face as incoming, don't forward
83
84 if (pitEntry.m_incoming.find (metricFace.m_face) != pitEntry.m_incoming.end ())
85 continue; // don't forward to face that we received interest from
86
87 CcnxPitEntryOutgoingFaceContainer::type::iterator outgoing =
88 pitEntry.m_outgoing.find (metricFace.m_face);
89
90 if (outgoing != pitEntry.m_outgoing.end () &&
91 outgoing->m_retxCount >= pitEntry.m_maxRetxCount)
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080092 {
Alexander Afanasyev120bf312011-12-19 01:24:47 -080093 NS_LOG_ERROR (outgoing->m_retxCount << " >= " << pitEntry.m_maxRetxCount);
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080094 continue; // already forwarded before during this retransmission cycle
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080095 }
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080096
97 bool faceAvailable = metricFace.m_face->IsBelowLimit ();
98 if (!faceAvailable) // huh...
99 {
100 continue;
101 }
102
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700103 m_pit->modify (pitEntry,
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800104 ll::bind(&CcnxPitEntry::AddOutgoing, ll::_1, metricFace.m_face));
105
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800106 Ptr<Packet> packetToSend = packet->Copy ();
Ilya Moiseenko1a8be032012-01-18 12:51:09 -0800107
108 //transmission
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800109 metricFace.m_face->Send (packetToSend);
Alexander Afanasyevf377b332011-12-16 15:32:12 -0800110 m_transmittedInterestsTrace (header, metricFace.m_face);
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800111
112 propagatedCount++;
113 break; // do only once
Ilya Moiseenko4e473482011-10-31 17:58:14 -0700114 }
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800115
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800116 NS_LOG_INFO ("Propagated to " << propagatedCount << " faces");
117 return propagatedCount > 0;
Ilya Moiseenko4e473482011-10-31 17:58:14 -0700118}
119
120} //namespace ns3