blob: f5ab20563b0d54faa04ab49991030c706a695336 [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
Alexander Afanasyev996b4872012-07-17 17:07:56 -070022#include "best-route.h"
Alexander Afanasyevf377b332011-12-16 15:32:12 -080023
Alexander Afanasyevbd9c18e2012-11-19 15:23:41 -080024#include "ns3/ndn-interest.h"
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070025#include "ns3/ndn-pit.h"
26#include "ns3/ndn-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
Alexander Afanasyev996b4872012-07-17 17:07:56 -070036namespace ns3 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070037namespace ndn {
38namespace fw {
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080039
Alexander Afanasyev996b4872012-07-17 17:07:56 -070040NS_OBJECT_ENSURE_REGISTERED (BestRoute);
Alexander Afanasyev042b4a72012-11-09 17:47:48 -080041
42LogComponent BestRoute::g_log = LogComponent (BestRoute::GetLogName ().c_str ());
43
44std::string
45BestRoute::GetLogName ()
46{
47 return super::GetLogName ()+".BestRoute";
48}
49
50
Alexander Afanasyev996b4872012-07-17 17:07:56 -070051TypeId
52BestRoute::GetTypeId (void)
Ilya Moiseenko4e473482011-10-31 17:58:14 -070053{
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070054 static TypeId tid = TypeId ("ns3::ndn::fw::BestRoute")
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070055 .SetGroupName ("Ndn")
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070056 .SetParent <super> ()
Alexander Afanasyev996b4872012-07-17 17:07:56 -070057 .AddConstructor <BestRoute> ()
Alexander Afanasyev11453142011-11-25 16:13:33 -080058 ;
Ilya Moiseenko4e473482011-10-31 17:58:14 -070059 return tid;
60}
Alexander Afanasyev06dba7c2013-02-21 11:36:26 -080061
Alexander Afanasyev996b4872012-07-17 17:07:56 -070062BestRoute::BestRoute ()
Ilya Moiseenko4e473482011-10-31 17:58:14 -070063{
64}
Alexander Afanasyev06dba7c2013-02-21 11:36:26 -080065
Ilya Moiseenko4e473482011-10-31 17:58:14 -070066bool
Alexander Afanasyev5db92172012-08-21 16:52:07 -070067BestRoute::DoPropagateInterest (Ptr<Face> inFace,
Alexander Afanasyevb989b122013-07-10 17:15:46 -070068 Ptr<const Interest> interest,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070069 Ptr<pit::Entry> pitEntry)
Ilya Moiseenko4e473482011-10-31 17:58:14 -070070{
Alexander Afanasyevb989b122013-07-10 17:15:46 -070071 NS_LOG_FUNCTION (this << interest->GetName ());
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080072
Alexander Afanasyev6fa950d2013-04-14 13:44:56 -070073 // No real need to call parent's (green-yellow-red's strategy) method, since it is incorporated
74 // in the logic of the BestRoute strategy
75 //
76 // // Try to work out with just green faces
Alexander Afanasyevb989b122013-07-10 17:15:46 -070077 // bool greenOk = super::DoPropagateInterest (inFace, interest, origPacket, pitEntry);
Alexander Afanasyev6fa950d2013-04-14 13:44:56 -070078 // if (greenOk)
79 // return true;
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080080
81 int propagatedCount = 0;
Alexander Afanasyev06dba7c2013-02-21 11:36:26 -080082
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070083 BOOST_FOREACH (const fib::FaceMetric &metricFace, pitEntry->GetFibEntry ()->m_faces.get<fib::i_metric> ())
Ilya Moiseenko4e473482011-10-31 17:58:14 -070084 {
Alexander Afanasyev5db92172012-08-21 16:52:07 -070085 NS_LOG_DEBUG ("Trying " << boost::cref(metricFace));
Alexander Afanasyev06dba7c2013-02-21 11:36:26 -080086 if (metricFace.GetStatus () == fib::FaceMetric::NDN_FIB_RED) // all non-read faces are in front
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080087 break;
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080088
Alexander Afanasyevb989b122013-07-10 17:15:46 -070089 if (!TrySendOutInterest (inFace, metricFace.GetFace (), interest, pitEntry))
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080090 {
91 continue;
92 }
93
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080094 propagatedCount++;
95 break; // do only once
Ilya Moiseenko4e473482011-10-31 17:58:14 -070096 }
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080097
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080098 NS_LOG_INFO ("Propagated to " << propagatedCount << " faces");
99 return propagatedCount > 0;
Ilya Moiseenko4e473482011-10-31 17:58:14 -0700100}
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700101
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700102} // namespace fw
103} // namespace ndn
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700104} // namespace ns3