blob: 4bb81998b18afdc12e0c1742581f6f2aac57ca4e [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 *
18 * Author: Ilya Moiseenko <iliamo@cs.ucla.edu>
19 */
20
21#include "ccnx-bestroute-strategy.h"
Alexander Afanasyevf377b332011-12-16 15:32:12 -080022
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080023#include "ccnx-interest-header.h"
Alexander Afanasyevf377b332011-12-16 15:32:12 -080024#include "ccnx-pit.h"
25#include "ccnx-pit-entry.h"
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080026
Ilya Moiseenko4e473482011-10-31 17:58:14 -070027#include "ns3/assert.h"
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080028#include "ns3/log.h"
Ilya Moiseenko4e473482011-10-31 17:58:14 -070029
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080030#include <boost/lambda/lambda.hpp>
31#include <boost/lambda/bind.hpp>
32namespace ll = boost::lambda;
33
Ilya Moiseenko4e473482011-10-31 17:58:14 -070034NS_LOG_COMPONENT_DEFINE ("CcnxBestRouteStrategy");
Ilya Moiseenko4e473482011-10-31 17:58:14 -070035
36namespace ns3
37{
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080038
39using namespace __ccnx_private;
40
Ilya Moiseenko4e473482011-10-31 17:58:14 -070041NS_OBJECT_ENSURE_REGISTERED (CcnxBestRouteStrategy);
42
43TypeId CcnxBestRouteStrategy::GetTypeId (void)
44{
45 static TypeId tid = TypeId ("ns3::CcnxBestRouteStrategy")
Alexander Afanasyev11453142011-11-25 16:13:33 -080046 .SetGroupName ("Ccnx")
47 .SetParent <CcnxForwardingStrategy> ()
48 .AddConstructor <CcnxBestRouteStrategy> ()
49 ;
Ilya Moiseenko4e473482011-10-31 17:58:14 -070050 return tid;
51}
52
53CcnxBestRouteStrategy::CcnxBestRouteStrategy ()
54{
55}
56
Ilya Moiseenko4e473482011-10-31 17:58:14 -070057bool
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080058CcnxBestRouteStrategy::PropagateInterest (const CcnxPitEntry &pitEntry,
Ilya Moiseenko4e473482011-10-31 17:58:14 -070059 const Ptr<CcnxFace> &incomingFace,
60 Ptr<CcnxInterestHeader> &header,
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080061 const Ptr<const Packet> &packet)
Ilya Moiseenko4e473482011-10-31 17:58:14 -070062{
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080063 NS_LOG_FUNCTION (this);
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080064
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080065
66
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080067 // Try to work out with just green faces
68 bool greenOk = PropagateInterestViaGreen (pitEntry, incomingFace, header, packet);
69 if (greenOk)
70 return true;
71
72 int propagatedCount = 0;
73
74 BOOST_FOREACH (const CcnxFibFaceMetric &metricFace, pitEntry.m_fibEntry.m_faces.get<i_metric> ())
Ilya Moiseenko4e473482011-10-31 17:58:14 -070075 {
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080076 if (metricFace.m_status == CcnxFibFaceMetric::NDN_FIB_RED) // all non-read faces are in front
77 break;
78
79 if (metricFace.m_face == incomingFace)
80 continue; // same face as incoming, don't forward
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)
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080090 {
Alexander Afanasyev120bf312011-12-19 01:24:47 -080091 NS_LOG_ERROR (outgoing->m_retxCount << " >= " << pitEntry.m_maxRetxCount);
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080092 continue; // already forwarded before during this retransmission cycle
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080093 }
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080094
95 bool faceAvailable = metricFace.m_face->IsBelowLimit ();
96 if (!faceAvailable) // huh...
97 {
98 continue;
99 }
100
101 m_pit->modify (m_pit->iterator_to (pitEntry),
102 ll::bind(&CcnxPitEntry::AddOutgoing, ll::_1, metricFace.m_face));
103
Ilya Moiseenko1a8be032012-01-18 12:51:09 -0800104 //update path stretch
105 WeightsPathStretchTag pathStretch;
106 //packet->PeekPacketTag(pathStretch);
107
108 pathStretch.AddNewHop(metricFace.m_routingCost);
109 packet->AddPacketTag(pathStretch);
110
111 //transmission
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800112 metricFace.m_face->Send (packet->Copy ());
Alexander Afanasyevf377b332011-12-16 15:32:12 -0800113 m_transmittedInterestsTrace (header, metricFace.m_face);
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800114
115 propagatedCount++;
116 break; // do only once
Ilya Moiseenko4e473482011-10-31 17:58:14 -0700117 }
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800118
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800119 NS_LOG_INFO ("Propagated to " << propagatedCount << " faces");
120 return propagatedCount > 0;
Ilya Moiseenko4e473482011-10-31 17:58:14 -0700121}
122
123} //namespace ns3