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 | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 22 | #include "ccnx-interest-header.h" |
| 23 | |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 24 | #include "ns3/assert.h" |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 25 | #include "ns3/log.h" |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 26 | |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 27 | #include <boost/lambda/lambda.hpp> |
| 28 | #include <boost/lambda/bind.hpp> |
| 29 | namespace ll = boost::lambda; |
| 30 | |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 31 | NS_LOG_COMPONENT_DEFINE ("CcnxBestRouteStrategy"); |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 32 | |
| 33 | namespace ns3 |
| 34 | { |
| 35 | |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 36 | NS_OBJECT_ENSURE_REGISTERED (CcnxBestRouteStrategy); |
| 37 | |
| 38 | TypeId CcnxBestRouteStrategy::GetTypeId (void) |
| 39 | { |
| 40 | static TypeId tid = TypeId ("ns3::CcnxBestRouteStrategy") |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame^] | 41 | .SetGroupName ("Ccnx") |
| 42 | .SetParent <CcnxForwardingStrategy> () |
| 43 | .AddConstructor <CcnxBestRouteStrategy> () |
| 44 | ; |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 45 | return tid; |
| 46 | } |
| 47 | |
| 48 | CcnxBestRouteStrategy::CcnxBestRouteStrategy () |
| 49 | { |
| 50 | } |
| 51 | |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 52 | bool |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 53 | CcnxBestRouteStrategy::PropagateInterest (const CcnxPitEntry &pitEntry, |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 54 | const Ptr<CcnxFace> &incomingFace, |
| 55 | Ptr<CcnxInterestHeader> &header, |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 56 | const Ptr<const Packet> &packet) |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 57 | { |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 58 | NS_LOG_FUNCTION (this); |
| 59 | bool forwardedCount = 0; |
| 60 | |
| 61 | try |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 62 | { |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 63 | for (uint32_t skip = 0; skip < pitEntry.m_fibEntry.m_faces.size (); skip++) |
| 64 | { |
| 65 | const CcnxFibFaceMetric bestMetric = pitEntry.m_fibEntry.FindBestCandidate (skip); |
| 66 | |
| 67 | if (bestMetric.m_status == CcnxFibFaceMetric::NDN_FIB_RED) // no point to send there |
| 68 | continue; |
| 69 | |
Alexander Afanasyev | 5a59507 | 2011-11-25 14:49:07 -0800 | [diff] [blame] | 70 | if (pitEntry.m_incoming.find (bestMetric.m_face) != pitEntry.m_incoming.end ()) |
| 71 | continue; // don't forward to face that we received interest from |
| 72 | |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 73 | if (pitEntry.m_outgoing.find (bestMetric.m_face) != pitEntry.m_outgoing.end ()) // already forwarded before |
| 74 | continue; |
| 75 | |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 76 | bool faceAvailable = bestMetric.m_face->IsBelowLimit (); |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 77 | if (!faceAvailable) // huh... |
| 78 | continue; |
| 79 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 80 | m_pit->modify (m_pit->iterator_to (pitEntry), |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 81 | ll::bind(&CcnxPitEntry::AddOutgoing, ll::_1, bestMetric.m_face)); |
| 82 | |
| 83 | // NS_LOG_DEBUG ("new outgoing entry for " << boost::cref (*metricFace.m_face)); |
| 84 | |
| 85 | bestMetric.m_face->Send (packet->Copy ()); |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 86 | |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 87 | forwardedCount++; |
| 88 | break; // if we succeeded in sending one packet, stop |
| 89 | } |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 90 | } |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 91 | catch (CcnxFibEntry::NoFaces) |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 92 | { |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 93 | } |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 94 | |
| 95 | return forwardedCount > 0; |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | } //namespace ns3 |