blob: 076234f021a9a363af145b799f178572f1911a83 [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 Afanasyev4aac5572012-08-09 10:49:55 -070024#include "ns3/ndn-interest-header.h"
25#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 Afanasyev2b4c9472012-08-09 15:00:38 -070036NS_LOG_COMPONENT_DEFINE ("ndn.fw.BestRoute");
Ilya Moiseenko4e473482011-10-31 17:58:14 -070037
Alexander Afanasyev996b4872012-07-17 17:07:56 -070038namespace ns3 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070039namespace ndn {
40namespace fw {
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080041
Alexander Afanasyev996b4872012-07-17 17:07:56 -070042NS_OBJECT_ENSURE_REGISTERED (BestRoute);
Ilya Moiseenko4e473482011-10-31 17:58:14 -070043
Alexander Afanasyev996b4872012-07-17 17:07:56 -070044TypeId
45BestRoute::GetTypeId (void)
Ilya Moiseenko4e473482011-10-31 17:58:14 -070046{
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070047 static TypeId tid = TypeId ("ns3::ndn::fw::BestRoute")
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070048 .SetGroupName ("Ndn")
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070049 .SetParent <super> ()
Alexander Afanasyev996b4872012-07-17 17:07:56 -070050 .AddConstructor <BestRoute> ()
Alexander Afanasyev11453142011-11-25 16:13:33 -080051 ;
Ilya Moiseenko4e473482011-10-31 17:58:14 -070052 return tid;
53}
54
Alexander Afanasyev996b4872012-07-17 17:07:56 -070055BestRoute::BestRoute ()
Ilya Moiseenko4e473482011-10-31 17:58:14 -070056{
57}
58
Ilya Moiseenko4e473482011-10-31 17:58:14 -070059bool
Alexander Afanasyev5db92172012-08-21 16:52:07 -070060BestRoute::DoPropagateInterest (Ptr<Face> inFace,
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070061 Ptr<const InterestHeader> header,
62 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070063 Ptr<pit::Entry> pitEntry)
Ilya Moiseenko4e473482011-10-31 17:58:14 -070064{
Alexander Afanasyev0ffa7162012-08-21 22:39:22 -070065 NS_LOG_FUNCTION (this << header->GetName ());
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080066
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080067 // Try to work out with just green faces
Alexander Afanasyev5db92172012-08-21 16:52:07 -070068 bool greenOk = super::DoPropagateInterest (inFace, header, origPacket, pitEntry);
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080069 if (greenOk)
70 return true;
71
72 int propagatedCount = 0;
Alexander Afanasyev5db92172012-08-21 16:52:07 -070073
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070074 BOOST_FOREACH (const fib::FaceMetric &metricFace, pitEntry->GetFibEntry ()->m_faces.get<fib::i_metric> ())
Ilya Moiseenko4e473482011-10-31 17:58:14 -070075 {
Alexander Afanasyev5db92172012-08-21 16:52:07 -070076 NS_LOG_DEBUG ("Trying " << boost::cref(metricFace));
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070077 if (metricFace.m_status == fib::FaceMetric::NDN_FIB_RED) // all non-read faces are in front
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080078 break;
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080079
Alexander Afanasyev5db92172012-08-21 16:52:07 -070080 if (!TrySendOutInterest (inFace, metricFace.m_face, header, origPacket, pitEntry))
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080081 {
82 continue;
83 }
84
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080085 propagatedCount++;
86 break; // do only once
Ilya Moiseenko4e473482011-10-31 17:58:14 -070087 }
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080088
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080089 NS_LOG_INFO ("Propagated to " << propagatedCount << " faces");
90 return propagatedCount > 0;
Ilya Moiseenko4e473482011-10-31 17:58:14 -070091}
Alexander Afanasyev996b4872012-07-17 17:07:56 -070092
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070093} // namespace fw
94} // namespace ndn
Alexander Afanasyev996b4872012-07-17 17:07:56 -070095} // namespace ns3