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 | * |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 18 | * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 19 | * Ilya Moiseenko <iliamo@cs.ucla.edu> |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 22 | #include "best-route.h" |
Alexander Afanasyev | f377b33 | 2011-12-16 15:32:12 -0800 | [diff] [blame] | 23 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 24 | #include "ns3/ndn-interest-header.h" |
| 25 | #include "ns3/ndn-pit.h" |
| 26 | #include "ns3/ndn-pit-entry.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 | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 31 | #include <boost/foreach.hpp> |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 32 | #include <boost/lambda/lambda.hpp> |
| 33 | #include <boost/lambda/bind.hpp> |
| 34 | namespace ll = boost::lambda; |
| 35 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 36 | NS_LOG_COMPONENT_DEFINE ("ndn.fw.BestRoute"); |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 37 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 38 | namespace ns3 { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 39 | namespace ndn { |
| 40 | namespace fw { |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 41 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 42 | NS_OBJECT_ENSURE_REGISTERED (BestRoute); |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 43 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 44 | TypeId |
| 45 | BestRoute::GetTypeId (void) |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 46 | { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 47 | static TypeId tid = TypeId ("ns3::ndn::fw::BestRoute") |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 48 | .SetGroupName ("Ndn") |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame^] | 49 | .SetParent <super> () |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 50 | .AddConstructor <BestRoute> () |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 51 | ; |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 52 | return tid; |
| 53 | } |
| 54 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 55 | BestRoute::BestRoute () |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 56 | { |
| 57 | } |
| 58 | |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 59 | bool |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame^] | 60 | BestRoute::DoPropagateInterest (Ptr<Face> incomingFace, |
| 61 | Ptr<const InterestHeader> header, |
| 62 | Ptr<const Packet> origPacket, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 63 | Ptr<pit::Entry> pitEntry) |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 64 | { |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 65 | NS_LOG_FUNCTION (this); |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 66 | |
Ilya Moiseenko | 1a8be03 | 2012-01-18 12:51:09 -0800 | [diff] [blame] | 67 | |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 68 | // Try to work out with just green faces |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame^] | 69 | bool greenOk = super::DoPropagateInterest (incomingFace, header, origPacket, pitEntry); |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 70 | if (greenOk) |
| 71 | return true; |
| 72 | |
| 73 | int propagatedCount = 0; |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 74 | BOOST_FOREACH (const fib::FaceMetric &metricFace, pitEntry->GetFibEntry ()->m_faces.get<fib::i_metric> ()) |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 75 | { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 76 | if (metricFace.m_status == fib::FaceMetric::NDN_FIB_RED) // all non-read faces are in front |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 77 | break; |
| 78 | |
| 79 | if (metricFace.m_face == incomingFace) |
| 80 | continue; // same face as incoming, don't forward |
| 81 | |
Alexander Afanasyev | 36b4577 | 2012-07-10 16:57:42 -0700 | [diff] [blame] | 82 | if (pitEntry->GetIncoming ().find (metricFace.m_face) != pitEntry->GetIncoming ().end ()) |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 83 | continue; // don't forward to face that we received interest from |
| 84 | |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 85 | if (!WillSendOutInterest (metricFace.m_face, header, pitEntry)) |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 86 | { |
| 87 | continue; |
| 88 | } |
| 89 | |
Ilya Moiseenko | 1a8be03 | 2012-01-18 12:51:09 -0800 | [diff] [blame] | 90 | //transmission |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame^] | 91 | Ptr<Packet> packetToSend = origPacket->Copy (); |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 92 | metricFace.m_face->Send (packetToSend); |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 93 | |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame^] | 94 | DidSendOutInterest (metricFace.m_face, header, origPacket, pitEntry); |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 95 | |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 96 | propagatedCount++; |
| 97 | break; // do only once |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 98 | } |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 99 | |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 100 | NS_LOG_INFO ("Propagated to " << propagatedCount << " faces"); |
| 101 | return propagatedCount > 0; |
Ilya Moiseenko | 4e47348 | 2011-10-31 17:58:14 -0700 | [diff] [blame] | 102 | } |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 103 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 104 | } // namespace fw |
| 105 | } // namespace ndn |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 106 | } // namespace ns3 |