blob: 94c65129bc331da25cd2bb3d455a71eba35a822f [file] [log] [blame]
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -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-flooding-strategy.h"
22#include "ns3/assert.h"
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080023#include "ns3/log.h"
Alexander Afanasyeve67a97f2011-11-29 14:28:59 -080024#include "ns3/simulator.h"
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080025#include "ccnx-interest-header.h"
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070026
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080027#include <boost/ref.hpp>
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080028#include <boost/foreach.hpp>
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080029#include <boost/lambda/lambda.hpp>
30#include <boost/lambda/bind.hpp>
31namespace ll = boost::lambda;
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070032
33NS_LOG_COMPONENT_DEFINE ("CcnxFloodingStrategy");
34
35namespace ns3
36{
37
38NS_OBJECT_ENSURE_REGISTERED (CcnxFloodingStrategy);
39
40TypeId CcnxFloodingStrategy::GetTypeId (void)
41{
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080042 static TypeId tid = TypeId ("ns3::CcnxFloodingStrategy")
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070043 .SetGroupName ("Ccnx")
Alexander Afanasyev11453142011-11-25 16:13:33 -080044 .SetParent <CcnxForwardingStrategy> ()
45 .AddConstructor <CcnxFloodingStrategy> ()
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070046 ;
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080047 return tid;
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070048}
49
50CcnxFloodingStrategy::CcnxFloodingStrategy ()
51{
52}
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080053
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070054bool
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080055CcnxFloodingStrategy::PropagateInterest (const CcnxPitEntry &pitEntry,
56 const Ptr<CcnxFace> &incomingFace,
57 Ptr<CcnxInterestHeader> &header,
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080058 const Ptr<const Packet> &packet)
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070059{
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080060 NS_LOG_FUNCTION (this);
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070061
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080062 int propagatedCount = 0;
63 BOOST_FOREACH (const CcnxFibFaceMetric &metricFace, pitEntry.m_fibEntry.m_faces)
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070064 {
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080065 if (metricFace.m_status == CcnxFibFaceMetric::NDN_FIB_RED) // all non-read faces are in front
66 break;
67
Alexander Afanasyev5a595072011-11-25 14:49:07 -080068 if (metricFace.m_face == incomingFace)
69 continue; // same face as incoming, don't forward
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080070
Alexander Afanasyev5a595072011-11-25 14:49:07 -080071 if (pitEntry.m_incoming.find (metricFace.m_face) != pitEntry.m_incoming.end ())
72 continue; // don't forward to face that we received interest from
73
74 if (pitEntry.m_outgoing.find (metricFace.m_face) != pitEntry.m_outgoing.end ())
75 continue; // already forwarded before
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080076
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080077 bool faceAvailable = metricFace.m_face->IsBelowLimit ();
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080078 if (!faceAvailable) // huh...
Alexander Afanasyeve67a97f2011-11-29 14:28:59 -080079 {
80 // NS_LOG_ERROR (boost::cref (*metricFace.m_face) << " limit !!!");
81 continue;
82 }
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080083
84 m_pit->modify (m_pit->iterator_to (pitEntry),
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080085 ll::bind(&CcnxPitEntry::AddOutgoing, ll::_1, metricFace.m_face));
86
Alexander Afanasyeve67a97f2011-11-29 14:28:59 -080087 // if (Simulator::GetContext ()==2)
88 // {
89 // NS_LOG_ERROR ("new outgoing entry for " << boost::cref (*metricFace.m_face));
90 // NS_LOG_ERROR ("size: " << pitEntry.m_outgoing.size ());
91 // }
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080092
93 metricFace.m_face->Send (packet->Copy ());
94
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080095 propagatedCount++;
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070096 }
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080097
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080098 NS_LOG_INFO ("Propagated to " << propagatedCount << " faces");
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080099 return propagatedCount > 0;
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -0700100}
101
102} //namespace ns3