blob: 45e0fd7b2e4d5b18a5ce73d1020e73193d4c5646 [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#include "ns3/double.h"
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080029#include "ns3/boolean.h"
Alexander Afanasyevf377b332011-12-16 15:32:12 -080030
31#include "ccnx-pit.h"
32#include "ccnx-pit-entry.h"
33
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080034#include "ccnx-interest-header.h"
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080035#include "ccnx-path-stretch-tag.h"
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080036
37#include <boost/ref.hpp>
38#include <boost/foreach.hpp>
39#include <boost/lambda/lambda.hpp>
40#include <boost/lambda/bind.hpp>
41namespace ll = boost::lambda;
42
43NS_LOG_COMPONENT_DEFINE ("CcnxForwardingStrategy");
Alexander Afanasyev98256102011-08-14 01:00:02 -070044
45namespace ns3 {
46
Alexander Afanasyev23d2b542011-12-07 18:54:46 -080047using namespace __ccnx_private;
48
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070049NS_OBJECT_ENSURE_REGISTERED (CcnxForwardingStrategy);
Alexander Afanasyev98256102011-08-14 01:00:02 -070050
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070051TypeId CcnxForwardingStrategy::GetTypeId (void)
Alexander Afanasyev98256102011-08-14 01:00:02 -070052{
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070053 static TypeId tid = TypeId ("ns3::CcnxForwardingStrategy")
Alexander Afanasyev070aa482011-08-20 00:38:25 -070054 .SetGroupName ("Ccnx")
Alexander Afanasyev98256102011-08-14 01:00:02 -070055 .SetParent<Object> ()
Alexander Afanasyevf377b332011-12-16 15:32:12 -080056
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080057 .AddAttribute ("MetricTagging", "Enable metric tagging (path-stretch calculation)",
58 BooleanValue (false),
59 MakeBooleanAccessor (&CcnxForwardingStrategy::m_enableMetricTagging),
60 MakeBooleanChecker ())
61
Alexander Afanasyevf377b332011-12-16 15:32:12 -080062 .AddTraceSource ("OutInterests", "Interests that were transmitted",
63 MakeTraceSourceAccessor (&CcnxForwardingStrategy::m_transmittedInterestsTrace))
64
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080065 ;
Alexander Afanasyev98256102011-08-14 01:00:02 -070066 return tid;
67}
68
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070069CcnxForwardingStrategy::CcnxForwardingStrategy ()
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080070 : m_enableMetricTagging (false)
Alexander Afanasyev98256102011-08-14 01:00:02 -070071{
Alexander Afanasyev98256102011-08-14 01:00:02 -070072}
73
Alexander Afanasyev4fa5e842011-11-21 13:38:39 -080074CcnxForwardingStrategy::~CcnxForwardingStrategy ()
75{
76}
77
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070078void
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080079CcnxForwardingStrategy::SetPit (Ptr<CcnxPit> pit)
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070080{
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080081 m_pit = pit;
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070082}
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080083
84bool
85CcnxForwardingStrategy::PropagateInterestViaGreen (const CcnxPitEntry &pitEntry,
86 const Ptr<CcnxFace> &incomingFace,
87 Ptr<CcnxInterestHeader> &header,
88 const Ptr<const Packet> &packet)
89{
Alexander Afanasyev120bf312011-12-19 01:24:47 -080090 NS_LOG_FUNCTION (this);
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080091
92 int propagatedCount = 0;
93
Alexander Afanasyev23d2b542011-12-07 18:54:46 -080094 BOOST_FOREACH (const CcnxFibFaceMetric &metricFace, pitEntry.m_fibEntry.m_faces.get<i_metric> ())
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080095 {
96 if (metricFace.m_status == CcnxFibFaceMetric::NDN_FIB_RED ||
97 metricFace.m_status == CcnxFibFaceMetric::NDN_FIB_YELLOW)
98 break; //propagate only to green faces
99
100 if (pitEntry.m_incoming.find (metricFace.m_face) != pitEntry.m_incoming.end ())
101 continue; // don't forward to face that we received interest from
102
103 CcnxPitEntryOutgoingFaceContainer::type::iterator outgoing =
104 pitEntry.m_outgoing.find (metricFace.m_face);
105
106 if (outgoing != pitEntry.m_outgoing.end () &&
107 outgoing->m_retxCount >= pitEntry.m_maxRetxCount)
108 {
Alexander Afanasyev120bf312011-12-19 01:24:47 -0800109 NS_LOG_DEBUG ("retxCount: " << outgoing->m_retxCount << ", maxRetxCount: " << pitEntry.m_maxRetxCount);
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800110 continue;
111 }
112
113 bool faceAvailable = metricFace.m_face->IsBelowLimit ();
114 if (!faceAvailable) // huh...
115 {
116 // let's try different green face
117 continue;
118 }
119
120 m_pit->modify (m_pit->iterator_to (pitEntry),
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800121 ll::bind (&CcnxPitEntry::AddOutgoing, ll::_1, metricFace.m_face));
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800122
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800123 Ptr<Packet> packetToSend = packet->Copy ();
124 TagPacket (packetToSend, metricFace);
Ilya Moiseenko1a8be032012-01-18 12:51:09 -0800125
126 //transmission
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800127 metricFace.m_face->Send (packetToSend);
Alexander Afanasyevf377b332011-12-16 15:32:12 -0800128 m_transmittedInterestsTrace (header, metricFace.m_face);
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800129
130 propagatedCount++;
131 break; // propagate only one interest
132 }
133
134 return propagatedCount > 0;
135}
136
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800137void
138CcnxForwardingStrategy::TagPacket (Ptr<Packet> packet, const CcnxFibFaceMetric &metricFace)
139{
140 // if (m_enableMetricTagging)
141 {
142 // update path information
143
144 Ptr<const WeightsPathStretchTag> origTag = packet->RemovePacketTag<WeightsPathStretchTag> ();
145 Ptr<WeightsPathStretchTag> tag;
146 if (origTag == 0)
147 {
148 tag = CreateObject<WeightsPathStretchTag> (); // create a new tag
149 }
150 else
151 {
152 tag = CreateObject<WeightsPathStretchTag> (*origTag); // will update existing tag
153 }
154
155 tag->AddPathInfo (metricFace.m_face->GetNode (), metricFace.m_routingCost);
156 packet->AddPacketTag (tag);
157 }
158}
159
Alexander Afanasyev98256102011-08-14 01:00:02 -0700160} //namespace ns3