blob: 21a6b57ba33eb29b59e4d2ae8f6d60ef0984e58b [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 Afanasyeveae83ee2013-03-15 15:01:10 -070068 Ptr<const Interest> header,
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070069 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070070 Ptr<pit::Entry> pitEntry)
Ilya Moiseenko4e473482011-10-31 17:58:14 -070071{
Alexander Afanasyev0ffa7162012-08-21 22:39:22 -070072 NS_LOG_FUNCTION (this << header->GetName ());
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080073
Alexander Afanasyev6fa950d2013-04-14 13:44:56 -070074 // No real need to call parent's (green-yellow-red's strategy) method, since it is incorporated
75 // in the logic of the BestRoute strategy
76 //
77 // // Try to work out with just green faces
78 // bool greenOk = super::DoPropagateInterest (inFace, header, origPacket, pitEntry);
79 // if (greenOk)
80 // return true;
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080081
82 int propagatedCount = 0;
Alexander Afanasyev06dba7c2013-02-21 11:36:26 -080083
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070084 BOOST_FOREACH (const fib::FaceMetric &metricFace, pitEntry->GetFibEntry ()->m_faces.get<fib::i_metric> ())
Ilya Moiseenko4e473482011-10-31 17:58:14 -070085 {
Alexander Afanasyev5db92172012-08-21 16:52:07 -070086 NS_LOG_DEBUG ("Trying " << boost::cref(metricFace));
Alexander Afanasyev06dba7c2013-02-21 11:36:26 -080087 if (metricFace.GetStatus () == fib::FaceMetric::NDN_FIB_RED) // all non-read faces are in front
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080088 break;
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080089
Alexander Afanasyev06dba7c2013-02-21 11:36:26 -080090 if (!TrySendOutInterest (inFace, metricFace.GetFace (), header, origPacket, pitEntry))
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080091 {
92 continue;
93 }
94
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080095 propagatedCount++;
96 break; // do only once
Ilya Moiseenko4e473482011-10-31 17:58:14 -070097 }
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080098
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080099 NS_LOG_INFO ("Propagated to " << propagatedCount << " faces");
100 return propagatedCount > 0;
Ilya Moiseenko4e473482011-10-31 17:58:14 -0700101}
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700102
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700103} // namespace fw
104} // namespace ndn
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700105} // namespace ns3