Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 1 | /* -*- 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 Afanasyev | f377b33 | 2011-12-16 15:32:12 -0800 | [diff] [blame] | 22 | |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 23 | #include "ccnx-interest-header.h" |
Alexander Afanasyev | f377b33 | 2011-12-16 15:32:12 -0800 | [diff] [blame] | 24 | #include "ccnx-pit.h" |
| 25 | #include "ccnx-pit-entry.h" |
Alexander Afanasyev | 161a5c4 | 2012-04-17 15:14:04 -0700 | [diff] [blame] | 26 | #include "ns3/weights-path-stretch-tag.h" |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 27 | |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 28 | #include "ns3/assert.h" |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 29 | #include "ns3/log.h" |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 30 | |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 31 | #include <boost/lambda/lambda.hpp> |
| 32 | #include <boost/lambda/bind.hpp> |
| 33 | namespace ll = boost::lambda; |
| 34 | |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 35 | NS_LOG_COMPONENT_DEFINE ("CcnxBestRouteStrategy"); |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 36 | |
| 37 | namespace ns3 |
| 38 | { |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 39 | |
| 40 | using namespace __ccnx_private; |
| 41 | |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 42 | NS_OBJECT_ENSURE_REGISTERED (CcnxBestRouteStrategy); |
| 43 | |
| 44 | TypeId CcnxBestRouteStrategy::GetTypeId (void) |
| 45 | { |
| 46 | static TypeId tid = TypeId ("ns3::CcnxBestRouteStrategy") |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 47 | .SetGroupName ("Ccnx") |
| 48 | .SetParent <CcnxForwardingStrategy> () |
| 49 | .AddConstructor <CcnxBestRouteStrategy> () |
| 50 | ; |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 51 | return tid; |
| 52 | } |
| 53 | |
| 54 | CcnxBestRouteStrategy::CcnxBestRouteStrategy () |
| 55 | { |
| 56 | } |
| 57 | |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 58 | bool |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 59 | CcnxBestRouteStrategy::PropagateInterest (const CcnxPitEntry &pitEntry, |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 60 | const Ptr<CcnxFace> &incomingFace, |
| 61 | Ptr<CcnxInterestHeader> &header, |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 62 | const Ptr<const Packet> &packet) |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 63 | { |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 64 | NS_LOG_FUNCTION (this); |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 65 | |
Ilya Moiseenko | 1a8be03 | 2012-01-18 12:51:09 -0800 | [diff] [blame] | 66 | |
| 67 | |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 68 | // Try to work out with just green faces |
| 69 | bool greenOk = PropagateInterestViaGreen (pitEntry, incomingFace, header, packet); |
| 70 | if (greenOk) |
| 71 | return true; |
| 72 | |
| 73 | int propagatedCount = 0; |
| 74 | |
| 75 | BOOST_FOREACH (const CcnxFibFaceMetric &metricFace, pitEntry.m_fibEntry.m_faces.get<i_metric> ()) |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 76 | { |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 77 | if (metricFace.m_status == CcnxFibFaceMetric::NDN_FIB_RED) // all non-read faces are in front |
| 78 | break; |
| 79 | |
| 80 | if (metricFace.m_face == incomingFace) |
| 81 | continue; // same face as incoming, don't forward |
| 82 | |
| 83 | if (pitEntry.m_incoming.find (metricFace.m_face) != pitEntry.m_incoming.end ()) |
| 84 | continue; // don't forward to face that we received interest from |
| 85 | |
| 86 | CcnxPitEntryOutgoingFaceContainer::type::iterator outgoing = |
| 87 | pitEntry.m_outgoing.find (metricFace.m_face); |
| 88 | |
| 89 | if (outgoing != pitEntry.m_outgoing.end () && |
| 90 | outgoing->m_retxCount >= pitEntry.m_maxRetxCount) |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 91 | { |
Alexander Afanasyev | 120bf31 | 2011-12-19 01:24:47 -0800 | [diff] [blame] | 92 | NS_LOG_ERROR (outgoing->m_retxCount << " >= " << pitEntry.m_maxRetxCount); |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 93 | continue; // already forwarded before during this retransmission cycle |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 94 | } |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 95 | |
| 96 | bool faceAvailable = metricFace.m_face->IsBelowLimit (); |
| 97 | if (!faceAvailable) // huh... |
| 98 | { |
| 99 | continue; |
| 100 | } |
| 101 | |
| 102 | m_pit->modify (m_pit->iterator_to (pitEntry), |
| 103 | ll::bind(&CcnxPitEntry::AddOutgoing, ll::_1, metricFace.m_face)); |
| 104 | |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 105 | Ptr<Packet> packetToSend = packet->Copy (); |
Ilya Moiseenko | 1a8be03 | 2012-01-18 12:51:09 -0800 | [diff] [blame] | 106 | |
| 107 | //transmission |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 108 | metricFace.m_face->Send (packetToSend); |
Alexander Afanasyev | f377b33 | 2011-12-16 15:32:12 -0800 | [diff] [blame] | 109 | m_transmittedInterestsTrace (header, metricFace.m_face); |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 110 | |
| 111 | propagatedCount++; |
| 112 | break; // do only once |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 113 | } |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 114 | |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 115 | NS_LOG_INFO ("Propagated to " << propagatedCount << " faces"); |
| 116 | return propagatedCount > 0; |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | } //namespace ns3 |