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 | |
| 27 | NS_LOG_COMPONENT_DEFINE ("CcnxBestRouteStrategy"); |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 28 | |
| 29 | namespace ns3 |
| 30 | { |
| 31 | |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 32 | NS_OBJECT_ENSURE_REGISTERED (CcnxBestRouteStrategy); |
| 33 | |
| 34 | TypeId CcnxBestRouteStrategy::GetTypeId (void) |
| 35 | { |
| 36 | static TypeId tid = TypeId ("ns3::CcnxBestRouteStrategy") |
| 37 | .SetGroupName ("Ccnx") |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame^] | 38 | .SetParent<CcnxForwardingStrategy> () |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 39 | ; |
| 40 | return tid; |
| 41 | } |
| 42 | |
| 43 | CcnxBestRouteStrategy::CcnxBestRouteStrategy () |
| 44 | { |
| 45 | } |
| 46 | |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 47 | bool |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame^] | 48 | CcnxBestRouteStrategy::PropagateInterest (const CcnxPitEntry &pitEntry, |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 49 | const Ptr<CcnxFace> &incomingFace, |
| 50 | Ptr<CcnxInterestHeader> &header, |
| 51 | const Ptr<const Packet> &packet, |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame^] | 52 | SendCallback sendCallback) |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 53 | { |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame^] | 54 | NS_LOG_FUNCTION (this); |
| 55 | bool forwardedCount = 0; |
| 56 | |
| 57 | try |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 58 | { |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame^] | 59 | for (uint32_t skip = 0; skip < pitEntry.m_fibEntry.m_faces.size (); skip++) |
| 60 | { |
| 61 | const CcnxFibFaceMetric bestMetric = pitEntry.m_fibEntry.FindBestCandidate (skip); |
| 62 | |
| 63 | if (bestMetric.m_status == CcnxFibFaceMetric::NDN_FIB_RED) // no point to send there |
| 64 | continue; |
| 65 | |
| 66 | if (pitEntry.m_outgoing.find (bestMetric.m_face) != pitEntry.m_outgoing.end ()) // already forwarded before |
| 67 | continue; |
| 68 | |
| 69 | bool faceAvailable = m_pit->TryAddOutgoing (pitEntry, bestMetric.m_face); |
| 70 | if (!faceAvailable) // huh... |
| 71 | continue; |
| 72 | |
| 73 | sendCallback (bestMetric.m_face, header, packet->Copy()); |
| 74 | forwardedCount++; |
| 75 | break; // if we succeeded in sending one packet, stop |
| 76 | } |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 77 | } |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame^] | 78 | catch (CcnxFibEntry::NoFaces) |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 79 | { |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 80 | } |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame^] | 81 | |
| 82 | return forwardedCount > 0; |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | } //namespace ns3 |