blob: cad2d6759842b8b1d998e18cd7ab5ae9e147d235 [file] [log] [blame]
Ilya Moiseenko4e473482011-10-31 17:58:14 -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-bestroute-strategy.h"
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080022#include "ccnx-interest-header.h"
23
Ilya Moiseenko4e473482011-10-31 17:58:14 -070024#include "ns3/assert.h"
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080025#include "ns3/log.h"
Ilya Moiseenko4e473482011-10-31 17:58:14 -070026
27NS_LOG_COMPONENT_DEFINE ("CcnxBestRouteStrategy");
Ilya Moiseenko4e473482011-10-31 17:58:14 -070028
29namespace ns3
30{
31
Ilya Moiseenko4e473482011-10-31 17:58:14 -070032NS_OBJECT_ENSURE_REGISTERED (CcnxBestRouteStrategy);
33
34TypeId CcnxBestRouteStrategy::GetTypeId (void)
35{
36 static TypeId tid = TypeId ("ns3::CcnxBestRouteStrategy")
37 .SetGroupName ("Ccnx")
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080038 .SetParent<CcnxForwardingStrategy> ()
Ilya Moiseenko4e473482011-10-31 17:58:14 -070039 ;
40 return tid;
41}
42
43CcnxBestRouteStrategy::CcnxBestRouteStrategy ()
44{
45}
46
Ilya Moiseenko4e473482011-10-31 17:58:14 -070047bool
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080048CcnxBestRouteStrategy::PropagateInterest (const CcnxPitEntry &pitEntry,
Ilya Moiseenko4e473482011-10-31 17:58:14 -070049 const Ptr<CcnxFace> &incomingFace,
50 Ptr<CcnxInterestHeader> &header,
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080051 const Ptr<const Packet> &packet)
Ilya Moiseenko4e473482011-10-31 17:58:14 -070052{
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080053 NS_LOG_FUNCTION (this);
54 bool forwardedCount = 0;
55
56 try
Ilya Moiseenko4e473482011-10-31 17:58:14 -070057 {
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080058 for (uint32_t skip = 0; skip < pitEntry.m_fibEntry.m_faces.size (); skip++)
59 {
60 const CcnxFibFaceMetric bestMetric = pitEntry.m_fibEntry.FindBestCandidate (skip);
61
62 if (bestMetric.m_status == CcnxFibFaceMetric::NDN_FIB_RED) // no point to send there
63 continue;
64
65 if (pitEntry.m_outgoing.find (bestMetric.m_face) != pitEntry.m_outgoing.end ()) // already forwarded before
66 continue;
67
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080068 bool faceAvailable = bestMetric.m_face->SendWithLimit (packet->Copy ());
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080069 if (!faceAvailable) // huh...
70 continue;
71
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080072 m_pit->modify (m_pit->iterator_to (pitEntry),
73 bind(&CcnxPitEntry::AddOutgoing, lambda::_1, bestMetric.m_face));
74
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080075 forwardedCount++;
76 break; // if we succeeded in sending one packet, stop
77 }
Ilya Moiseenko4e473482011-10-31 17:58:14 -070078 }
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080079 catch (CcnxFibEntry::NoFaces)
Ilya Moiseenko4e473482011-10-31 17:58:14 -070080 {
Ilya Moiseenko4e473482011-10-31 17:58:14 -070081 }
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080082
83 return forwardedCount > 0;
Ilya Moiseenko4e473482011-10-31 17:58:14 -070084}
85
86} //namespace ns3