blob: 4a1c3a8b736c21e0b910768828e070ddd981b660 [file] [log] [blame]
Alexander Afanasyevc74a6022011-08-15 20:01:35 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Alexander Afanasyev98256102011-08-14 01:00:02 -07002/*
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -07003 * Copyright (c) 2011 University of California, Los Angeles
Alexander Afanasyev98256102011-08-14 01:00:02 -07004 *
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
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070017 *
18 * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
19 * Ilya Moiseenko <iliamo@cs.ucla.edu>
Alexander Afanasyev98256102011-08-14 01:00:02 -070020 */
21
22#include "ns3/assert.h"
23
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070024#include "ccnx-forwarding-strategy.h"
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080025#include "ns3/log.h"
26#include "ns3/simulator.h"
27#include "ccnx-interest-header.h"
28
29#include <boost/ref.hpp>
30#include <boost/foreach.hpp>
31#include <boost/lambda/lambda.hpp>
32#include <boost/lambda/bind.hpp>
33namespace ll = boost::lambda;
34
35NS_LOG_COMPONENT_DEFINE ("CcnxForwardingStrategy");
Alexander Afanasyev98256102011-08-14 01:00:02 -070036
37namespace ns3 {
38
Alexander Afanasyev23d2b542011-12-07 18:54:46 -080039using namespace __ccnx_private;
40
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070041NS_OBJECT_ENSURE_REGISTERED (CcnxForwardingStrategy);
Alexander Afanasyev98256102011-08-14 01:00:02 -070042
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070043TypeId CcnxForwardingStrategy::GetTypeId (void)
Alexander Afanasyev98256102011-08-14 01:00:02 -070044{
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070045 static TypeId tid = TypeId ("ns3::CcnxForwardingStrategy")
Alexander Afanasyev070aa482011-08-20 00:38:25 -070046 .SetGroupName ("Ccnx")
Alexander Afanasyev98256102011-08-14 01:00:02 -070047 .SetParent<Object> ()
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080048 ;
Alexander Afanasyev98256102011-08-14 01:00:02 -070049 return tid;
50}
51
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070052CcnxForwardingStrategy::CcnxForwardingStrategy ()
Alexander Afanasyev98256102011-08-14 01:00:02 -070053{
Alexander Afanasyev98256102011-08-14 01:00:02 -070054}
55
Alexander Afanasyev4fa5e842011-11-21 13:38:39 -080056CcnxForwardingStrategy::~CcnxForwardingStrategy ()
57{
58}
59
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070060void
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080061CcnxForwardingStrategy::SetPit (Ptr<CcnxPit> pit)
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070062{
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080063 m_pit = pit;
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070064}
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080065
66bool
67CcnxForwardingStrategy::PropagateInterestViaGreen (const CcnxPitEntry &pitEntry,
68 const Ptr<CcnxFace> &incomingFace,
69 Ptr<CcnxInterestHeader> &header,
70 const Ptr<const Packet> &packet)
71{
Alexander Afanasyev23d2b542011-12-07 18:54:46 -080072 // NS_LOG_FUNCTION (this);
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080073
74 int propagatedCount = 0;
75
Alexander Afanasyev23d2b542011-12-07 18:54:46 -080076 BOOST_FOREACH (const CcnxFibFaceMetric &metricFace, pitEntry.m_fibEntry.m_faces.get<i_metric> ())
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080077 {
78 if (metricFace.m_status == CcnxFibFaceMetric::NDN_FIB_RED ||
79 metricFace.m_status == CcnxFibFaceMetric::NDN_FIB_YELLOW)
80 break; //propagate only to green faces
81
82 if (pitEntry.m_incoming.find (metricFace.m_face) != pitEntry.m_incoming.end ())
83 continue; // don't forward to face that we received interest from
84
85 CcnxPitEntryOutgoingFaceContainer::type::iterator outgoing =
86 pitEntry.m_outgoing.find (metricFace.m_face);
87
88 if (outgoing != pitEntry.m_outgoing.end () &&
89 outgoing->m_retxCount >= pitEntry.m_maxRetxCount)
90 {
91 continue;
92 }
93
94 bool faceAvailable = metricFace.m_face->IsBelowLimit ();
95 if (!faceAvailable) // huh...
96 {
97 // let's try different green face
98 continue;
99 }
100
101 m_pit->modify (m_pit->iterator_to (pitEntry),
102 ll::bind(&CcnxPitEntry::AddOutgoing, ll::_1, metricFace.m_face));
103
104 metricFace.m_face->Send (packet->Copy ());
105
106 propagatedCount++;
107 break; // propagate only one interest
108 }
109
Alexander Afanasyev23d2b542011-12-07 18:54:46 -0800110 // if (Simulator::GetContext ()==1)
111 // {
112 // if (propagatedCount > 0)
113 // NS_LOG_DEBUG ("Propagate via a green face");
114 // else
115 // NS_LOG_DEBUG ("Can't :(");
116 // }
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800117 return propagatedCount > 0;
118}
119
120
Alexander Afanasyev98256102011-08-14 01:00:02 -0700121} //namespace ns3