blob: 00d209803838f8e08195c5f99504aed310e46d9b [file] [log] [blame]
Alexander Afanasyevad3757f2012-04-17 10:27:59 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2011 UCLA
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: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
19 */
20
Alexander Afanasyev3898e1b2013-07-27 12:03:17 -070021#if __clang__
22#pragma clang diagnostic push
23#pragma clang diagnostic ignored "-Wunused-variable"
24#pragma clang diagnostic ignored "-Wunneeded-internal-declaration"
25#endif
26
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070027#include "ndn-global-routing-helper.h"
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070028
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070029#include "ns3/ndn-l3-protocol.h"
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070030#include "../model/ndn-net-device-face.h"
31#include "../model/ndn-global-router.h"
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070032#include "ns3/ndn-name.h"
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070033#include "ns3/ndn-fib.h"
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070034
35#include "ns3/node.h"
Alexander Afanasyevce810142012-04-17 15:50:36 -070036#include "ns3/node-container.h"
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070037#include "ns3/net-device.h"
38#include "ns3/channel.h"
39#include "ns3/log.h"
40#include "ns3/assert.h"
41#include "ns3/names.h"
42#include "ns3/node-list.h"
43#include "ns3/channel-list.h"
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070044#include "ns3/object-factory.h"
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070045
46#include <boost/lexical_cast.hpp>
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -070047#include <boost/foreach.hpp>
Alexander Afanasyeva5abcd92012-04-17 13:34:43 -070048#include <boost/concept/assert.hpp>
49// #include <boost/graph/graph_concepts.hpp>
50// #include <boost/graph/adjacency_list.hpp>
51#include <boost/graph/dijkstra_shortest_paths.hpp>
52
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070053#include "boost-graph-ndn-global-routing-helper.h"
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070054
Alexander Afanasyev73532512012-11-27 00:42:35 -080055#include <math.h>
56
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070057NS_LOG_COMPONENT_DEFINE ("ndn.GlobalRoutingHelper");
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070058
59using namespace std;
60using namespace boost;
61
62namespace ns3 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070063namespace ndn {
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070064
65void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070066GlobalRoutingHelper::Install (Ptr<Node> node)
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070067{
68 NS_LOG_LOGIC ("Node: " << node->GetId ());
Alexander Afanasyev49165862013-01-31 00:38:20 -080069
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070070 Ptr<L3Protocol> ndn = node->GetObject<L3Protocol> ();
71 NS_ASSERT_MSG (ndn != 0, "Cannot install GlobalRoutingHelper before Ndn is installed on a node");
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070072
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070073 Ptr<GlobalRouter> gr = node->GetObject<GlobalRouter> ();
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070074 if (gr != 0)
75 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070076 NS_LOG_DEBUG ("GlobalRouter is already installed: " << gr);
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070077 return; // already installed
78 }
Alexander Afanasyev49165862013-01-31 00:38:20 -080079
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070080 gr = CreateObject<GlobalRouter> ();
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070081 node->AggregateObject (gr);
Alexander Afanasyev49165862013-01-31 00:38:20 -080082
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070083 for (uint32_t faceId = 0; faceId < ndn->GetNFaces (); faceId++)
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070084 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070085 Ptr<NetDeviceFace> face = DynamicCast<NetDeviceFace> (ndn->GetFace (faceId));
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070086 if (face == 0)
87 {
88 NS_LOG_DEBUG ("Skipping non-netdevice face");
89 continue;
90 }
Alexander Afanasyev49165862013-01-31 00:38:20 -080091
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070092 Ptr<NetDevice> nd = face->GetNetDevice ();
93 if (nd == 0)
94 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070095 NS_LOG_DEBUG ("Not a NetDevice associated with NetDeviceFace");
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070096 continue;
97 }
Alexander Afanasyev49165862013-01-31 00:38:20 -080098
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070099 Ptr<Channel> ch = nd->GetChannel ();
100
101 if (ch == 0)
102 {
103 NS_LOG_DEBUG ("Channel is not associated with NetDevice");
104 continue;
105 }
106
107 if (ch->GetNDevices () == 2) // e.g., point-to-point channel
108 {
109 for (uint32_t deviceId = 0; deviceId < ch->GetNDevices (); deviceId ++)
110 {
111 Ptr<NetDevice> otherSide = ch->GetDevice (deviceId);
112 if (nd == otherSide) continue;
113
114 Ptr<Node> otherNode = otherSide->GetNode ();
115 NS_ASSERT (otherNode != 0);
Alexander Afanasyev49165862013-01-31 00:38:20 -0800116
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700117 Ptr<GlobalRouter> otherGr = otherNode->GetObject<GlobalRouter> ();
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700118 if (otherGr == 0)
119 {
120 Install (otherNode);
121 }
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700122 otherGr = otherNode->GetObject<GlobalRouter> ();
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700123 NS_ASSERT (otherGr != 0);
124 gr->AddIncidency (face, otherGr);
125 }
126 }
127 else
128 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700129 Ptr<GlobalRouter> grChannel = ch->GetObject<GlobalRouter> ();
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700130 if (grChannel == 0)
131 {
132 Install (ch);
133 }
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700134 grChannel = ch->GetObject<GlobalRouter> ();
Alexander Afanasyev49165862013-01-31 00:38:20 -0800135
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700136 gr->AddIncidency (0, grChannel);
137 }
138 }
139}
140
141void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700142GlobalRoutingHelper::Install (Ptr<Channel> channel)
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700143{
144 NS_LOG_LOGIC ("Channel: " << channel->GetId ());
145
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700146 Ptr<GlobalRouter> gr = channel->GetObject<GlobalRouter> ();
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700147 if (gr != 0)
148 return;
149
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700150 gr = CreateObject<GlobalRouter> ();
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700151 channel->AggregateObject (gr);
Alexander Afanasyev49165862013-01-31 00:38:20 -0800152
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700153 for (uint32_t deviceId = 0; deviceId < channel->GetNDevices (); deviceId ++)
154 {
155 Ptr<NetDevice> dev = channel->GetDevice (deviceId);
156
157 Ptr<Node> node = dev->GetNode ();
158 NS_ASSERT (node != 0);
159
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700160 Ptr<GlobalRouter> grOther = node->GetObject<GlobalRouter> ();
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700161 if (grOther == 0)
162 {
163 Install (node);
164 }
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700165 grOther = node->GetObject<GlobalRouter> ();
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700166 NS_ASSERT (grOther != 0);
167
168 gr->AddIncidency (0, grOther);
169 }
170}
171
172void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700173GlobalRoutingHelper::Install (const NodeContainer &nodes)
Alexander Afanasyevce810142012-04-17 15:50:36 -0700174{
175 for (NodeContainer::Iterator node = nodes.Begin ();
176 node != nodes.End ();
177 node ++)
178 {
179 Install (*node);
180 }
181}
182
183void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700184GlobalRoutingHelper::InstallAll ()
Alexander Afanasyevce810142012-04-17 15:50:36 -0700185{
186 Install (NodeContainer::GetGlobal ());
187}
188
189
190void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700191GlobalRoutingHelper::AddOrigin (const std::string &prefix, Ptr<Node> node)
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700192{
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700193 Ptr<GlobalRouter> gr = node->GetObject<GlobalRouter> ();
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700194 NS_ASSERT_MSG (gr != 0,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700195 "GlobalRouter is not installed on the node");
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700196
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -0700197 Ptr<Name> name = Create<Name> (boost::lexical_cast<Name> (prefix));
Alexander Afanasyev49165862013-01-31 00:38:20 -0800198 gr->AddLocalPrefix (name);
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700199}
200
201void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700202GlobalRoutingHelper::AddOrigins (const std::string &prefix, const NodeContainer &nodes)
Alexander Afanasyev06d3a612012-04-17 22:25:40 -0700203{
204 for (NodeContainer::Iterator node = nodes.Begin ();
205 node != nodes.End ();
206 node++)
207 {
208 AddOrigin (prefix, *node);
209 }
210}
211
212void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700213GlobalRoutingHelper::AddOrigin (const std::string &prefix, const std::string &nodeName)
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700214{
215 Ptr<Node> node = Names::Find<Node> (nodeName);
216 NS_ASSERT_MSG (node != 0, nodeName << "is not a Node");
217
218 AddOrigin (prefix, node);
219}
220
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700221void
Alexander Afanasyev49165862013-01-31 00:38:20 -0800222GlobalRoutingHelper::AddOriginsForAll ()
223{
224 for (NodeList::Iterator node = NodeList::Begin (); node != NodeList::End (); node ++)
225 {
226 Ptr<GlobalRouter> gr = (*node)->GetObject<GlobalRouter> ();
227 string name = Names::FindName (*node);
228
229 if (gr != 0 && !name.empty ())
230 {
231 AddOrigin ("/"+name, *node);
232 }
233 }
234}
235
236void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700237GlobalRoutingHelper::CalculateRoutes ()
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700238{
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700239 /**
240 * Implementation of route calculation is heavily based on Boost Graph Library
241 * See http://www.boost.org/doc/libs/1_49_0/libs/graph/doc/table_of_contents.html for more details
242 */
Alexander Afanasyev49165862013-01-31 00:38:20 -0800243
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700244 BOOST_CONCEPT_ASSERT(( VertexListGraphConcept< NdnGlobalRouterGraph > ));
245 BOOST_CONCEPT_ASSERT(( IncidenceGraphConcept< NdnGlobalRouterGraph > ));
Alexander Afanasyev49165862013-01-31 00:38:20 -0800246
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700247 NdnGlobalRouterGraph graph;
248 typedef graph_traits < NdnGlobalRouterGraph >::vertex_descriptor vertex_descriptor;
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700249
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700250 // For now we doing Dijkstra for every node. Can be replaced with Bellman-Ford or Floyd-Warshall.
251 // Other algorithms should be faster, but they need additional EdgeListGraph concept provided by the graph, which
252 // is not obviously how implement in an efficient manner
Alexander Afanasyeva5abcd92012-04-17 13:34:43 -0700253 for (NodeList::Iterator node = NodeList::Begin (); node != NodeList::End (); node++)
254 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700255 Ptr<GlobalRouter> source = (*node)->GetObject<GlobalRouter> ();
Alexander Afanasyeva5abcd92012-04-17 13:34:43 -0700256 if (source == 0)
257 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700258 NS_LOG_DEBUG ("Node " << (*node)->GetId () << " does not export GlobalRouter interface");
Alexander Afanasyeva5abcd92012-04-17 13:34:43 -0700259 continue;
260 }
Alexander Afanasyev49165862013-01-31 00:38:20 -0800261
Alexander Afanasyeva5abcd92012-04-17 13:34:43 -0700262 DistancesMap distances;
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700263
Alexander Afanasyeva5abcd92012-04-17 13:34:43 -0700264 dijkstra_shortest_paths (graph, source,
265 // predecessor_map (boost::ref(predecessors))
266 // .
267 distance_map (boost::ref(distances))
268 .
269 distance_inf (WeightInf)
270 .
271 distance_zero (WeightZero)
272 .
273 distance_compare (boost::WeightCompare ())
274 .
275 distance_combine (boost::WeightCombine ())
276 );
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700277
Alexander Afanasyeva5abcd92012-04-17 13:34:43 -0700278 // NS_LOG_DEBUG (predecessors.size () << ", " << distances.size ());
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700279
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700280 Ptr<Fib> fib = source->GetObject<Fib> ();
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700281 fib->InvalidateAll ();
282 NS_ASSERT (fib != 0);
Alexander Afanasyev49165862013-01-31 00:38:20 -0800283
Alexander Afanasyev5bcdc992012-11-19 22:25:55 -0800284 NS_LOG_DEBUG ("Reachability from Node: " << source->GetObject<Node> ()->GetId ());
Alexander Afanasyeva5abcd92012-04-17 13:34:43 -0700285 for (DistancesMap::iterator i = distances.begin ();
286 i != distances.end ();
287 i++)
288 {
289 if (i->first == source)
290 continue;
291 else
292 {
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700293 // cout << " Node " << i->first->GetObject<Node> ()->GetId ();
294 if (i->second.get<0> () == 0)
295 {
296 // cout << " is unreachable" << endl;
297 }
Alexander Afanasyeva5abcd92012-04-17 13:34:43 -0700298 else
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700299 {
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -0700300 BOOST_FOREACH (const Ptr<const Name> &prefix, i->first->GetLocalPrefixes ())
Alexander Afanasyeva8f5d882012-11-09 14:22:48 -0800301 {
Alexander Afanasyev5bcdc992012-11-19 22:25:55 -0800302 NS_LOG_DEBUG (" prefix " << prefix << " reachable via face " << *i->second.get<0> ()
303 << " with distance " << i->second.get<1> ()
304 << " with delay " << i->second.get<2> ());
Alexander Afanasyev49165862013-01-31 00:38:20 -0800305
Alexander Afanasyeva8f5d882012-11-09 14:22:48 -0800306 Ptr<fib::Entry> entry = fib->Add (prefix, i->second.get<0> (), i->second.get<1> ());
Alexander Afanasyev6b0c88f2012-12-01 12:24:27 -0800307 entry->SetRealDelayToProducer (i->second.get<0> (), Seconds (i->second.get<2> ()));
Alexander Afanasyev49165862013-01-31 00:38:20 -0800308
Alexander Afanasyevadcccf42012-11-26 23:55:34 -0800309 Ptr<Limits> faceLimits = i->second.get<0> ()->GetObject<Limits> ();
310
311 Ptr<Limits> fibLimits = entry->GetObject<Limits> ();
312 if (fibLimits != 0)
Alexander Afanasyeva8f5d882012-11-09 14:22:48 -0800313 {
Alexander Afanasyevadcccf42012-11-26 23:55:34 -0800314 // if it was created by the forwarding strategy via DidAddFibEntry event
Alexander Afanasyev73532512012-11-27 00:42:35 -0800315 fibLimits->SetLimits (faceLimits->GetMaxRate (), 2 * i->second.get<2> () /*exact RTT*/);
316 NS_LOG_DEBUG ("Set limit for prefix " << *prefix << " " << faceLimits->GetMaxRate () << " / " <<
317 2*i->second.get<2> () << "s (" << faceLimits->GetMaxRate () * 2 * i->second.get<2> () << ")");
Alexander Afanasyeva8f5d882012-11-09 14:22:48 -0800318 }
319 }
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700320 }
Alexander Afanasyeva5abcd92012-04-17 13:34:43 -0700321 }
322 }
Alexander Afanasyeva5abcd92012-04-17 13:34:43 -0700323 }
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700324}
325
Alexander Afanasyevf484fb92013-03-04 10:37:27 -0800326void
327GlobalRoutingHelper::CalculateAllPossibleRoutes ()
328{
329 /**
330 * Implementation of route calculation is heavily based on Boost Graph Library
331 * See http://www.boost.org/doc/libs/1_49_0/libs/graph/doc/table_of_contents.html for more details
332 */
333
Alexander Afanasyevf484fb92013-03-04 10:37:27 -0800334 BOOST_CONCEPT_ASSERT(( VertexListGraphConcept< NdnGlobalRouterGraph > ));
335 BOOST_CONCEPT_ASSERT(( IncidenceGraphConcept< NdnGlobalRouterGraph > ));
336
337 NdnGlobalRouterGraph graph;
338 typedef graph_traits < NdnGlobalRouterGraph >::vertex_descriptor vertex_descriptor;
339
340 // For now we doing Dijkstra for every node. Can be replaced with Bellman-Ford or Floyd-Warshall.
341 // Other algorithms should be faster, but they need additional EdgeListGraph concept provided by the graph, which
342 // is not obviously how implement in an efficient manner
343 for (NodeList::Iterator node = NodeList::Begin (); node != NodeList::End (); node++)
344 {
345 Ptr<GlobalRouter> source = (*node)->GetObject<GlobalRouter> ();
346 if (source == 0)
347 {
348 NS_LOG_DEBUG ("Node " << (*node)->GetId () << " does not export GlobalRouter interface");
349 continue;
350 }
351
352 Ptr<Fib> fib = source->GetObject<Fib> ();
353 fib->InvalidateAll ();
354 NS_ASSERT (fib != 0);
355
356 NS_LOG_DEBUG ("===========");
357 NS_LOG_DEBUG ("Reachability from Node: " << source->GetObject<Node> ()->GetId () << " (" << Names::FindName (source->GetObject<Node> ()) << ")");
358
359 Ptr<L3Protocol> l3 = source->GetObject<L3Protocol> ();
360 NS_ASSERT (l3 != 0);
361
362 // remember interface statuses
363 std::vector<uint16_t> originalMetric (l3->GetNFaces ());
364 for (uint32_t faceId = 0; faceId < l3->GetNFaces (); faceId++)
365 {
366 originalMetric[faceId] = l3->GetFace (faceId)->GetMetric ();
Alexander Afanasyev52a09bd2013-07-29 18:49:01 -0700367 l3->GetFace (faceId)->SetMetric (std::numeric_limits<uint16_t>::max ()-1); // value std::numeric_limits<uint16_t>::max () MUST NOT be used (reserved)
Alexander Afanasyevf484fb92013-03-04 10:37:27 -0800368 }
369
370 for (uint32_t enabledFaceId = 0; enabledFaceId < l3->GetNFaces (); enabledFaceId++)
371 {
372 if (DynamicCast<ndn::NetDeviceFace> (l3->GetFace (enabledFaceId)) == 0)
373 continue;
374
375 // enabling only faceId
376 l3->GetFace (enabledFaceId)->SetMetric (originalMetric[enabledFaceId]);
377
378 DistancesMap distances;
379
380 NS_LOG_DEBUG ("-----------");
381
382 dijkstra_shortest_paths (graph, source,
383 // predecessor_map (boost::ref(predecessors))
384 // .
385 distance_map (boost::ref(distances))
386 .
387 distance_inf (WeightInf)
388 .
389 distance_zero (WeightZero)
390 .
391 distance_compare (boost::WeightCompare ())
392 .
393 distance_combine (boost::WeightCombine ())
394 );
395
396 // NS_LOG_DEBUG (predecessors.size () << ", " << distances.size ());
397
398 for (DistancesMap::iterator i = distances.begin ();
399 i != distances.end ();
400 i++)
401 {
402 if (i->first == source)
403 continue;
404 else
405 {
406 // cout << " Node " << i->first->GetObject<Node> ()->GetId ();
407 if (i->second.get<0> () == 0)
408 {
409 // cout << " is unreachable" << endl;
410 }
411 else
412 {
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -0700413 BOOST_FOREACH (const Ptr<const Name> &prefix, i->first->GetLocalPrefixes ())
Alexander Afanasyevf484fb92013-03-04 10:37:27 -0800414 {
415 NS_LOG_DEBUG (" prefix " << *prefix << " reachable via face " << *i->second.get<0> ()
416 << " with distance " << i->second.get<1> ()
417 << " with delay " << i->second.get<2> ());
418
419 if (i->second.get<0> ()->GetMetric () == std::numeric_limits<uint16_t>::max ()-1)
420 continue;
421
422 Ptr<fib::Entry> entry = fib->Add (prefix, i->second.get<0> (), i->second.get<1> ());
423 entry->SetRealDelayToProducer (i->second.get<0> (), Seconds (i->second.get<2> ()));
424
425 Ptr<Limits> faceLimits = i->second.get<0> ()->GetObject<Limits> ();
426
427 Ptr<Limits> fibLimits = entry->GetObject<Limits> ();
428 if (fibLimits != 0)
429 {
430 // if it was created by the forwarding strategy via DidAddFibEntry event
431 fibLimits->SetLimits (faceLimits->GetMaxRate (), 2 * i->second.get<2> () /*exact RTT*/);
432 NS_LOG_DEBUG ("Set limit for prefix " << *prefix << " " << faceLimits->GetMaxRate () << " / " <<
433 2*i->second.get<2> () << "s (" << faceLimits->GetMaxRate () * 2 * i->second.get<2> () << ")");
434 }
435 }
436 }
437 }
438 }
439
440 // disabling the face again
441 l3->GetFace (enabledFaceId)->SetMetric (std::numeric_limits<uint16_t>::max ()-1);
442 }
443
444 // recover original interface statuses
445 for (uint32_t faceId = 0; faceId < l3->GetNFaces (); faceId++)
446 {
447 l3->GetFace (faceId)->SetMetric (originalMetric[faceId]);
448 }
449 }
450}
451
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700452
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700453} // namespace ndn
454} // namespace ns3