blob: 03400b77a517606a042f55a84046e1e762b9d22e [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}
61
Alexander Afanasyev996b4872012-07-17 17:07:56 -070062BestRoute::BestRoute ()
Ilya Moiseenko4e473482011-10-31 17:58:14 -070063{
64}
65
Ilya Moiseenko4e473482011-10-31 17:58:14 -070066bool
Alexander Afanasyev5db92172012-08-21 16:52:07 -070067BestRoute::DoPropagateInterest (Ptr<Face> inFace,
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070068 Ptr<const InterestHeader> header,
69 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 Afanasyev0a61c342011-12-06 12:48:55 -080074 // Try to work out with just green faces
Alexander Afanasyev5db92172012-08-21 16:52:07 -070075 bool greenOk = super::DoPropagateInterest (inFace, header, origPacket, pitEntry);
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080076 if (greenOk)
77 return true;
78
79 int propagatedCount = 0;
Alexander Afanasyev5db92172012-08-21 16:52:07 -070080
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070081 BOOST_FOREACH (const fib::FaceMetric &metricFace, pitEntry->GetFibEntry ()->m_faces.get<fib::i_metric> ())
Ilya Moiseenko4e473482011-10-31 17:58:14 -070082 {
Alexander Afanasyev5db92172012-08-21 16:52:07 -070083 NS_LOG_DEBUG ("Trying " << boost::cref(metricFace));
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070084 if (metricFace.m_status == fib::FaceMetric::NDN_FIB_RED) // all non-read faces are in front
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080085 break;
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080086
Alexander Afanasyev5db92172012-08-21 16:52:07 -070087 if (!TrySendOutInterest (inFace, metricFace.m_face, header, origPacket, pitEntry))
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080088 {
89 continue;
90 }
91
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080092 propagatedCount++;
93 break; // do only once
Ilya Moiseenko4e473482011-10-31 17:58:14 -070094 }
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080095
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080096 NS_LOG_INFO ("Propagated to " << propagatedCount << " faces");
97 return propagatedCount > 0;
Ilya Moiseenko4e473482011-10-31 17:58:14 -070098}
Alexander Afanasyev996b4872012-07-17 17:07:56 -070099
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700100} // namespace fw
101} // namespace ndn
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700102} // namespace ns3