blob: 869e42436ebc4bb8fd9370d2a2f84d3311e6acb4 [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 Afanasyevc74a6022011-08-15 20:01:35 -070039NS_OBJECT_ENSURE_REGISTERED (CcnxForwardingStrategy);
Alexander Afanasyev98256102011-08-14 01:00:02 -070040
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070041TypeId CcnxForwardingStrategy::GetTypeId (void)
Alexander Afanasyev98256102011-08-14 01:00:02 -070042{
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070043 static TypeId tid = TypeId ("ns3::CcnxForwardingStrategy")
Alexander Afanasyev070aa482011-08-20 00:38:25 -070044 .SetGroupName ("Ccnx")
Alexander Afanasyev98256102011-08-14 01:00:02 -070045 .SetParent<Object> ()
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080046 ;
Alexander Afanasyev98256102011-08-14 01:00:02 -070047 return tid;
48}
49
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070050CcnxForwardingStrategy::CcnxForwardingStrategy ()
Alexander Afanasyev98256102011-08-14 01:00:02 -070051{
Alexander Afanasyev98256102011-08-14 01:00:02 -070052}
53
Alexander Afanasyev4fa5e842011-11-21 13:38:39 -080054CcnxForwardingStrategy::~CcnxForwardingStrategy ()
55{
56}
57
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070058void
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080059CcnxForwardingStrategy::SetPit (Ptr<CcnxPit> pit)
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070060{
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080061 m_pit = pit;
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070062}
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080063
64bool
65CcnxForwardingStrategy::PropagateInterestViaGreen (const CcnxPitEntry &pitEntry,
66 const Ptr<CcnxFace> &incomingFace,
67 Ptr<CcnxInterestHeader> &header,
68 const Ptr<const Packet> &packet)
69{
70 NS_LOG_FUNCTION (this);
71
72 int propagatedCount = 0;
73
74 BOOST_FOREACH (const CcnxFibFaceMetric &metricFace, pitEntry.m_fibEntry.m_faces)
75 {
76 if (metricFace.m_status == CcnxFibFaceMetric::NDN_FIB_RED ||
77 metricFace.m_status == CcnxFibFaceMetric::NDN_FIB_YELLOW)
78 break; //propagate only to green faces
79
80 if (pitEntry.m_incoming.find (metricFace.m_face) != pitEntry.m_incoming.end ())
81 continue; // don't forward to face that we received interest from
82
83 CcnxPitEntryOutgoingFaceContainer::type::iterator outgoing =
84 pitEntry.m_outgoing.find (metricFace.m_face);
85
86 if (outgoing != pitEntry.m_outgoing.end () &&
87 outgoing->m_retxCount >= pitEntry.m_maxRetxCount)
88 {
89 continue;
90 }
91
92 bool faceAvailable = metricFace.m_face->IsBelowLimit ();
93 if (!faceAvailable) // huh...
94 {
95 // let's try different green face
96 continue;
97 }
98
99 m_pit->modify (m_pit->iterator_to (pitEntry),
100 ll::bind(&CcnxPitEntry::AddOutgoing, ll::_1, metricFace.m_face));
101
102 metricFace.m_face->Send (packet->Copy ());
103
104 propagatedCount++;
105 break; // propagate only one interest
106 }
107
108 return propagatedCount > 0;
109}
110
111
Alexander Afanasyev98256102011-08-14 01:00:02 -0700112} //namespace ns3