blob: f1095687a8f914acaa36ad1743dea6f40d5e3ea2 [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 Afanasyeve3d126f2012-07-16 17:07:31 -070024#include "ns3/ccnx-interest-header.h"
25#include "ns3/ccnx-pit.h"
26#include "ns3/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
Alexander Afanasyev996b4872012-07-17 17:07:56 -070036NS_LOG_COMPONENT_DEFINE ("NdnSimBestRoute");
Ilya Moiseenko4e473482011-10-31 17:58:14 -070037
Alexander Afanasyev996b4872012-07-17 17:07:56 -070038namespace ns3 {
39namespace ndnSIM {
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080040
41using namespace __ccnx_private;
42
Alexander Afanasyev996b4872012-07-17 17:07:56 -070043NS_OBJECT_ENSURE_REGISTERED (BestRoute);
Ilya Moiseenko4e473482011-10-31 17:58:14 -070044
Alexander Afanasyev996b4872012-07-17 17:07:56 -070045TypeId
46BestRoute::GetTypeId (void)
Ilya Moiseenko4e473482011-10-31 17:58:14 -070047{
Alexander Afanasyev996b4872012-07-17 17:07:56 -070048 static TypeId tid = TypeId ("ns3::ndnSIM::BestRoute")
Alexander Afanasyev11453142011-11-25 16:13:33 -080049 .SetGroupName ("Ccnx")
Alexander Afanasyev996b4872012-07-17 17:07:56 -070050 .SetParent <GreenYellowRed> ()
51 .AddConstructor <BestRoute> ()
Alexander Afanasyev11453142011-11-25 16:13:33 -080052 ;
Ilya Moiseenko4e473482011-10-31 17:58:14 -070053 return tid;
54}
55
Alexander Afanasyev996b4872012-07-17 17:07:56 -070056BestRoute::BestRoute ()
Ilya Moiseenko4e473482011-10-31 17:58:14 -070057{
58}
59
Ilya Moiseenko4e473482011-10-31 17:58:14 -070060bool
Alexander Afanasyev996b4872012-07-17 17:07:56 -070061BestRoute::DoPropagateInterest (const Ptr<CcnxFace> &incomingFace,
Alexander Afanasyevf249a192012-07-18 16:52:51 -070062 Ptr<CcnxInterestHeader> header,
Alexander Afanasyev996b4872012-07-17 17:07:56 -070063 const Ptr<const Packet> &packet,
64 Ptr<CcnxPitEntry> pitEntry)
Ilya Moiseenko4e473482011-10-31 17:58:14 -070065{
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080066 NS_LOG_FUNCTION (this);
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080067
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080068
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080069 // Try to work out with just green faces
Alexander Afanasyev996b4872012-07-17 17:07:56 -070070 bool greenOk = super::DoPropagateInterest (incomingFace, header, packet, pitEntry);
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080071 if (greenOk)
72 return true;
73
74 int propagatedCount = 0;
75
Alexander Afanasyev36b45772012-07-10 16:57:42 -070076 BOOST_FOREACH (const CcnxFibFaceMetric &metricFace, pitEntry->GetFibEntry ()->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
Alexander Afanasyev36b45772012-07-10 16:57:42 -070084 if (pitEntry->GetIncoming ().find (metricFace.m_face) != pitEntry->GetIncoming ().end ())
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080085 continue; // don't forward to face that we received interest from
86
Alexander Afanasyevf249a192012-07-18 16:52:51 -070087 if (!WillSendOutInterest (metricFace.m_face, header, pitEntry))
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080088 {
89 continue;
90 }
91
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080092 //transmission
Alexander Afanasyevf249a192012-07-18 16:52:51 -070093 Ptr<Packet> packetToSend = packet->Copy ();
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080094 metricFace.m_face->Send (packetToSend);
Alexander Afanasyevf249a192012-07-18 16:52:51 -070095
96 DidSendOutInterest (metricFace.m_face, header, pitEntry);
97
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080098 propagatedCount++;
99 break; // do only once
Ilya Moiseenko4e473482011-10-31 17:58:14 -0700100 }
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800101
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800102 NS_LOG_INFO ("Propagated to " << propagatedCount << " faces");
103 return propagatedCount > 0;
Ilya Moiseenko4e473482011-10-31 17:58:14 -0700104}
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700105
106} // namespace ndnSIM
107} // namespace ns3