Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 2 | /* |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 3 | * Copyright (c) 2011 University of California, Los Angeles |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 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 |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 17 | * |
| 18 | * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 19 | * Ilya Moiseenko <iliamo@cs.ucla.edu> |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #include "ns3/assert.h" |
| 23 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 24 | #include "ccnx-forwarding-strategy.h" |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 25 | #include "ns3/ptr.h" |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 26 | #include "ns3/log.h" |
| 27 | #include "ns3/simulator.h" |
Alexander Afanasyev | f377b33 | 2011-12-16 15:32:12 -0800 | [diff] [blame] | 28 | |
| 29 | #include "ccnx-pit.h" |
| 30 | #include "ccnx-pit-entry.h" |
| 31 | |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 32 | #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> |
| 38 | namespace ll = boost::lambda; |
| 39 | |
| 40 | NS_LOG_COMPONENT_DEFINE ("CcnxForwardingStrategy"); |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 41 | |
| 42 | namespace ns3 { |
| 43 | |
Alexander Afanasyev | 23d2b54 | 2011-12-07 18:54:46 -0800 | [diff] [blame] | 44 | using namespace __ccnx_private; |
| 45 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 46 | NS_OBJECT_ENSURE_REGISTERED (CcnxForwardingStrategy); |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 47 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 48 | TypeId CcnxForwardingStrategy::GetTypeId (void) |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 49 | { |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 50 | static TypeId tid = TypeId ("ns3::CcnxForwardingStrategy") |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 51 | .SetGroupName ("Ccnx") |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 52 | .SetParent<Object> () |
Alexander Afanasyev | f377b33 | 2011-12-16 15:32:12 -0800 | [diff] [blame] | 53 | |
| 54 | .AddTraceSource ("OutInterests", "Interests that were transmitted", |
| 55 | MakeTraceSourceAccessor (&CcnxForwardingStrategy::m_transmittedInterestsTrace)) |
| 56 | |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 57 | ; |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 58 | return tid; |
| 59 | } |
| 60 | |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 61 | CcnxForwardingStrategy::CcnxForwardingStrategy () |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 62 | { |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Alexander Afanasyev | 4fa5e84 | 2011-11-21 13:38:39 -0800 | [diff] [blame] | 65 | CcnxForwardingStrategy::~CcnxForwardingStrategy () |
| 66 | { |
| 67 | } |
| 68 | |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 69 | void |
Alexander Afanasyev | 3a4a0b3 | 2012-06-28 14:14:22 -0700 | [diff] [blame] | 70 | CcnxForwardingStrategy::NotifyNewAggregate () |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 71 | { |
Alexander Afanasyev | 3a4a0b3 | 2012-06-28 14:14:22 -0700 | [diff] [blame] | 72 | if (m_pit == 0) |
| 73 | { |
| 74 | m_pit = GetObject<CcnxPit> (); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | void |
| 79 | CcnxForwardingStrategy::DoDispose () |
| 80 | { |
| 81 | // nothing to do... |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 82 | } |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 83 | |
| 84 | bool |
Alexander Afanasyev | 30f60e3 | 2012-07-10 14:21:16 -0700 | [diff] [blame] | 85 | CcnxForwardingStrategy::PropagateInterestViaGreen (Ptr<CcnxPitEntry> pitEntry, |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 86 | const Ptr<CcnxFace> &incomingFace, |
| 87 | Ptr<CcnxInterestHeader> &header, |
| 88 | const Ptr<const Packet> &packet) |
| 89 | { |
Alexander Afanasyev | 120bf31 | 2011-12-19 01:24:47 -0800 | [diff] [blame] | 90 | NS_LOG_FUNCTION (this); |
Alexander Afanasyev | 3a4a0b3 | 2012-06-28 14:14:22 -0700 | [diff] [blame] | 91 | NS_ASSERT_MSG (m_pit != 0, "PIT should be aggregated with forwarding strategy"); |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 92 | |
| 93 | int propagatedCount = 0; |
| 94 | |
Alexander Afanasyev | 36b4577 | 2012-07-10 16:57:42 -0700 | [diff] [blame] | 95 | BOOST_FOREACH (const CcnxFibFaceMetric &metricFace, pitEntry->GetFibEntry ()->m_faces.get<i_metric> ()) |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 96 | { |
| 97 | if (metricFace.m_status == CcnxFibFaceMetric::NDN_FIB_RED || |
| 98 | metricFace.m_status == CcnxFibFaceMetric::NDN_FIB_YELLOW) |
| 99 | break; //propagate only to green faces |
| 100 | |
Alexander Afanasyev | 36b4577 | 2012-07-10 16:57:42 -0700 | [diff] [blame] | 101 | if (pitEntry->GetIncoming ().find (metricFace.m_face) != pitEntry->GetIncoming ().end ()) |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 102 | continue; // don't forward to face that we received interest from |
| 103 | |
| 104 | CcnxPitEntryOutgoingFaceContainer::type::iterator outgoing = |
Alexander Afanasyev | 36b4577 | 2012-07-10 16:57:42 -0700 | [diff] [blame] | 105 | pitEntry->GetOutgoing ().find (metricFace.m_face); |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 106 | |
Alexander Afanasyev | 36b4577 | 2012-07-10 16:57:42 -0700 | [diff] [blame] | 107 | if (outgoing != pitEntry->GetOutgoing ().end () && |
| 108 | outgoing->m_retxCount >= pitEntry->GetMaxRetxCount ()) |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 109 | { |
Alexander Afanasyev | 36b4577 | 2012-07-10 16:57:42 -0700 | [diff] [blame] | 110 | NS_LOG_DEBUG ("retxCount: " << outgoing->m_retxCount << ", maxRetxCount: " << pitEntry->GetMaxRetxCount ()); |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 111 | continue; |
| 112 | } |
| 113 | |
| 114 | bool faceAvailable = metricFace.m_face->IsBelowLimit (); |
| 115 | if (!faceAvailable) // huh... |
| 116 | { |
| 117 | // let's try different green face |
| 118 | continue; |
| 119 | } |
| 120 | |
Alexander Afanasyev | 30f60e3 | 2012-07-10 14:21:16 -0700 | [diff] [blame] | 121 | pitEntry->AddOutgoing (metricFace.m_face); |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 122 | |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 123 | Ptr<Packet> packetToSend = packet->Copy (); |
Ilya Moiseenko | 1a8be03 | 2012-01-18 12:51:09 -0800 | [diff] [blame] | 124 | |
| 125 | //transmission |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 126 | metricFace.m_face->Send (packetToSend); |
Alexander Afanasyev | f377b33 | 2011-12-16 15:32:12 -0800 | [diff] [blame] | 127 | m_transmittedInterestsTrace (header, metricFace.m_face); |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 128 | |
| 129 | propagatedCount++; |
| 130 | break; // propagate only one interest |
| 131 | } |
| 132 | |
| 133 | return propagatedCount > 0; |
| 134 | } |
| 135 | |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 136 | } //namespace ns3 |