blob: 625b6d7e0f86ec02fa625a70b7c53bda8d5b6e66 [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"
22#include "ns3/assert.h"
23
24#include "ccnx-route.h"
25
26
27NS_LOG_COMPONENT_DEFINE ("CcnxBestRouteStrategy");
28namespace __ccnx_private {
29
30 struct CcnxFibFaceMetricByFace;
31}
32
33namespace ns3
34{
35
36using namespace __ccnx_private;
37
38NS_OBJECT_ENSURE_REGISTERED (CcnxBestRouteStrategy);
39
40TypeId CcnxBestRouteStrategy::GetTypeId (void)
41{
42 static TypeId tid = TypeId ("ns3::CcnxBestRouteStrategy")
43 .SetGroupName ("Ccnx")
44 .SetParent<Object> ()
45 ;
46 return tid;
47}
48
49CcnxBestRouteStrategy::CcnxBestRouteStrategy ()
50{
51}
52
53
54bool
55CcnxBestRouteStrategy::PropagateInterest (CcnxPitEntryContainer::type::iterator pitEntry,
56 CcnxFibEntryContainer::type::iterator fibEntry,
57 const Ptr<CcnxFace> &incomingFace,
58 Ptr<CcnxInterestHeader> &header,
59 const Ptr<const Packet> &packet,
60 SendCallback ucb)
61{
Ilya Moiseenkoaa1154b2011-11-16 16:30:11 -080062 //NS_LOG_FUNCTION(this);
63 //NS_LOG_INFO(*fibEntry);
Ilya Moiseenko4e473482011-10-31 17:58:14 -070064
65 Ptr<CcnxFace> bestFace = fibEntry->FindBestCandidate(0);
66
67 if( bestFace == NULL )
68 {
69 return false;
70 }
71 else
72 {
73 bool tryResult = GetPit ()->TryAddOutgoing (pitEntry, bestFace);
74 if (tryResult == false)
75 {
Ilya Moiseenkoaa1154b2011-11-16 16:30:11 -080076 NS_LOG_INFO("!!!!!!!!!!!!!Trying different face!!!!!!!!!!!!!!!!");
77 for(uint32_t i = 1; i<fibEntry->m_faces.size(); i++ )
78 {
79 bestFace = fibEntry->FindBestCandidate(i);
80 tryResult = GetPit ()->TryAddOutgoing (pitEntry, bestFace);
81 if(tryResult == true)
82 break;
83 NS_LOG_INFO("Trying different face");
84 }
85
86 if(tryResult == false)
87 {
88 NS_LOG_INFO("FAILURE");
89 return false;
90 }
Ilya Moiseenko4e473482011-10-31 17:58:14 -070091 }
92
93 ucb (bestFace, header, packet->Copy());
94 }
95
96 return true;
97}
98
99} //namespace ns3