blob: a8565770fd9a068f03676bd017b674683b87e682 [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 Afanasyeve9c9d722012-01-19 16:59:30 -080025#include "ns3/ptr.h"
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080026#include "ns3/log.h"
27#include "ns3/simulator.h"
Alexander Afanasyevf377b332011-12-16 15:32:12 -080028
29#include "ccnx-pit.h"
30#include "ccnx-pit-entry.h"
31
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080032#include "ccnx-interest-header.h"
33
34#include <boost/ref.hpp>
35#include <boost/foreach.hpp>
36#include <boost/lambda/lambda.hpp>
37#include <boost/lambda/bind.hpp>
38namespace ll = boost::lambda;
39
40NS_LOG_COMPONENT_DEFINE ("CcnxForwardingStrategy");
Alexander Afanasyev98256102011-08-14 01:00:02 -070041
42namespace ns3 {
43
Alexander Afanasyev23d2b542011-12-07 18:54:46 -080044using namespace __ccnx_private;
45
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070046NS_OBJECT_ENSURE_REGISTERED (CcnxForwardingStrategy);
Alexander Afanasyev98256102011-08-14 01:00:02 -070047
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070048TypeId CcnxForwardingStrategy::GetTypeId (void)
Alexander Afanasyev98256102011-08-14 01:00:02 -070049{
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070050 static TypeId tid = TypeId ("ns3::CcnxForwardingStrategy")
Alexander Afanasyev070aa482011-08-20 00:38:25 -070051 .SetGroupName ("Ccnx")
Alexander Afanasyev98256102011-08-14 01:00:02 -070052 .SetParent<Object> ()
Alexander Afanasyevf377b332011-12-16 15:32:12 -080053
54 .AddTraceSource ("OutInterests", "Interests that were transmitted",
55 MakeTraceSourceAccessor (&CcnxForwardingStrategy::m_transmittedInterestsTrace))
56
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080057 ;
Alexander Afanasyev98256102011-08-14 01:00:02 -070058 return tid;
59}
60
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070061CcnxForwardingStrategy::CcnxForwardingStrategy ()
Alexander Afanasyev98256102011-08-14 01:00:02 -070062{
Alexander Afanasyev98256102011-08-14 01:00:02 -070063}
64
Alexander Afanasyev4fa5e842011-11-21 13:38:39 -080065CcnxForwardingStrategy::~CcnxForwardingStrategy ()
66{
67}
68
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070069void
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080070CcnxForwardingStrategy::SetPit (Ptr<CcnxPit> pit)
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070071{
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080072 m_pit = pit;
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070073}
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080074
75bool
76CcnxForwardingStrategy::PropagateInterestViaGreen (const CcnxPitEntry &pitEntry,
77 const Ptr<CcnxFace> &incomingFace,
78 Ptr<CcnxInterestHeader> &header,
79 const Ptr<const Packet> &packet)
80{
Alexander Afanasyev120bf312011-12-19 01:24:47 -080081 NS_LOG_FUNCTION (this);
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080082
83 int propagatedCount = 0;
84
Alexander Afanasyev23d2b542011-12-07 18:54:46 -080085 BOOST_FOREACH (const CcnxFibFaceMetric &metricFace, pitEntry.m_fibEntry.m_faces.get<i_metric> ())
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080086 {
87 if (metricFace.m_status == CcnxFibFaceMetric::NDN_FIB_RED ||
88 metricFace.m_status == CcnxFibFaceMetric::NDN_FIB_YELLOW)
89 break; //propagate only to green faces
90
91 if (pitEntry.m_incoming.find (metricFace.m_face) != pitEntry.m_incoming.end ())
92 continue; // don't forward to face that we received interest from
93
94 CcnxPitEntryOutgoingFaceContainer::type::iterator outgoing =
95 pitEntry.m_outgoing.find (metricFace.m_face);
96
97 if (outgoing != pitEntry.m_outgoing.end () &&
98 outgoing->m_retxCount >= pitEntry.m_maxRetxCount)
99 {
Alexander Afanasyev120bf312011-12-19 01:24:47 -0800100 NS_LOG_DEBUG ("retxCount: " << outgoing->m_retxCount << ", maxRetxCount: " << pitEntry.m_maxRetxCount);
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800101 continue;
102 }
103
104 bool faceAvailable = metricFace.m_face->IsBelowLimit ();
105 if (!faceAvailable) // huh...
106 {
107 // let's try different green face
108 continue;
109 }
110
111 m_pit->modify (m_pit->iterator_to (pitEntry),
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800112 ll::bind (&CcnxPitEntry::AddOutgoing, ll::_1, metricFace.m_face));
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800113
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800114 Ptr<Packet> packetToSend = packet->Copy ();
Ilya Moiseenko1a8be032012-01-18 12:51:09 -0800115
116 //transmission
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800117 metricFace.m_face->Send (packetToSend);
Alexander Afanasyevf377b332011-12-16 15:32:12 -0800118 m_transmittedInterestsTrace (header, metricFace.m_face);
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800119
120 propagatedCount++;
121 break; // propagate only one interest
122 }
123
124 return propagatedCount > 0;
125}
126
Alexander Afanasyev98256102011-08-14 01:00:02 -0700127} //namespace ns3