blob: eee399c2592095cce08b312fb5beccab7c899be6 [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
José Quevedo1914d492013-12-19 11:53:14 +0000136 gr->AddIncidency (face, grChannel);
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700137 }
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 Afanasyev16d252a2013-12-19 10:54:24 -0800237GlobalRoutingHelper::CalculateRoutes (bool invalidatedRoutes/* = true*/)
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;
Zongyi Zhaoc8372632014-04-28 15:36:49 -0700248 // 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 Afanasyev16d252a2013-12-19 10:54:24 -0800281 if (invalidatedRoutes)
282 {
283 fib->InvalidateAll ();
284 }
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700285 NS_ASSERT (fib != 0);
Alexander Afanasyev49165862013-01-31 00:38:20 -0800286
Alexander Afanasyev5bcdc992012-11-19 22:25:55 -0800287 NS_LOG_DEBUG ("Reachability from Node: " << source->GetObject<Node> ()->GetId ());
Alexander Afanasyeva5abcd92012-04-17 13:34:43 -0700288 for (DistancesMap::iterator i = distances.begin ();
289 i != distances.end ();
290 i++)
291 {
292 if (i->first == source)
293 continue;
294 else
295 {
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700296 // cout << " Node " << i->first->GetObject<Node> ()->GetId ();
297 if (i->second.get<0> () == 0)
298 {
299 // cout << " is unreachable" << endl;
300 }
Alexander Afanasyeva5abcd92012-04-17 13:34:43 -0700301 else
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700302 {
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -0700303 BOOST_FOREACH (const Ptr<const Name> &prefix, i->first->GetLocalPrefixes ())
Alexander Afanasyeva8f5d882012-11-09 14:22:48 -0800304 {
Alexander Afanasyev5bcdc992012-11-19 22:25:55 -0800305 NS_LOG_DEBUG (" prefix " << prefix << " reachable via face " << *i->second.get<0> ()
306 << " with distance " << i->second.get<1> ()
307 << " with delay " << i->second.get<2> ());
Alexander Afanasyev49165862013-01-31 00:38:20 -0800308
Alexander Afanasyeva8f5d882012-11-09 14:22:48 -0800309 Ptr<fib::Entry> entry = fib->Add (prefix, i->second.get<0> (), i->second.get<1> ());
Alexander Afanasyev6b0c88f2012-12-01 12:24:27 -0800310 entry->SetRealDelayToProducer (i->second.get<0> (), Seconds (i->second.get<2> ()));
Alexander Afanasyev49165862013-01-31 00:38:20 -0800311
Alexander Afanasyevadcccf42012-11-26 23:55:34 -0800312 Ptr<Limits> faceLimits = i->second.get<0> ()->GetObject<Limits> ();
313
314 Ptr<Limits> fibLimits = entry->GetObject<Limits> ();
315 if (fibLimits != 0)
Alexander Afanasyeva8f5d882012-11-09 14:22:48 -0800316 {
Alexander Afanasyevadcccf42012-11-26 23:55:34 -0800317 // if it was created by the forwarding strategy via DidAddFibEntry event
Alexander Afanasyev73532512012-11-27 00:42:35 -0800318 fibLimits->SetLimits (faceLimits->GetMaxRate (), 2 * i->second.get<2> () /*exact RTT*/);
319 NS_LOG_DEBUG ("Set limit for prefix " << *prefix << " " << faceLimits->GetMaxRate () << " / " <<
320 2*i->second.get<2> () << "s (" << faceLimits->GetMaxRate () * 2 * i->second.get<2> () << ")");
Alexander Afanasyeva8f5d882012-11-09 14:22:48 -0800321 }
322 }
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700323 }
Alexander Afanasyeva5abcd92012-04-17 13:34:43 -0700324 }
325 }
Alexander Afanasyeva5abcd92012-04-17 13:34:43 -0700326 }
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700327}
328
Alexander Afanasyevf484fb92013-03-04 10:37:27 -0800329void
Alexander Afanasyev16d252a2013-12-19 10:54:24 -0800330GlobalRoutingHelper::CalculateAllPossibleRoutes (bool invalidatedRoutes/* = true*/)
Alexander Afanasyevf484fb92013-03-04 10:37:27 -0800331{
332 /**
333 * Implementation of route calculation is heavily based on Boost Graph Library
334 * See http://www.boost.org/doc/libs/1_49_0/libs/graph/doc/table_of_contents.html for more details
335 */
336
Alexander Afanasyevf484fb92013-03-04 10:37:27 -0800337 BOOST_CONCEPT_ASSERT(( VertexListGraphConcept< NdnGlobalRouterGraph > ));
338 BOOST_CONCEPT_ASSERT(( IncidenceGraphConcept< NdnGlobalRouterGraph > ));
339
340 NdnGlobalRouterGraph graph;
Zongyi Zhaoc8372632014-04-28 15:36:49 -0700341 // typedef graph_traits < NdnGlobalRouterGraph >::vertex_descriptor vertex_descriptor;
Alexander Afanasyevf484fb92013-03-04 10:37:27 -0800342
343 // For now we doing Dijkstra for every node. Can be replaced with Bellman-Ford or Floyd-Warshall.
344 // Other algorithms should be faster, but they need additional EdgeListGraph concept provided by the graph, which
345 // is not obviously how implement in an efficient manner
346 for (NodeList::Iterator node = NodeList::Begin (); node != NodeList::End (); node++)
347 {
348 Ptr<GlobalRouter> source = (*node)->GetObject<GlobalRouter> ();
349 if (source == 0)
350 {
351 NS_LOG_DEBUG ("Node " << (*node)->GetId () << " does not export GlobalRouter interface");
352 continue;
353 }
354
355 Ptr<Fib> fib = source->GetObject<Fib> ();
Alexander Afanasyev16d252a2013-12-19 10:54:24 -0800356 if (invalidatedRoutes)
357 {
358 fib->InvalidateAll ();
359 }
Alexander Afanasyevf484fb92013-03-04 10:37:27 -0800360 NS_ASSERT (fib != 0);
361
362 NS_LOG_DEBUG ("===========");
363 NS_LOG_DEBUG ("Reachability from Node: " << source->GetObject<Node> ()->GetId () << " (" << Names::FindName (source->GetObject<Node> ()) << ")");
364
365 Ptr<L3Protocol> l3 = source->GetObject<L3Protocol> ();
366 NS_ASSERT (l3 != 0);
367
368 // remember interface statuses
369 std::vector<uint16_t> originalMetric (l3->GetNFaces ());
370 for (uint32_t faceId = 0; faceId < l3->GetNFaces (); faceId++)
371 {
372 originalMetric[faceId] = l3->GetFace (faceId)->GetMetric ();
Alexander Afanasyev52a09bd2013-07-29 18:49:01 -0700373 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 -0800374 }
375
376 for (uint32_t enabledFaceId = 0; enabledFaceId < l3->GetNFaces (); enabledFaceId++)
377 {
378 if (DynamicCast<ndn::NetDeviceFace> (l3->GetFace (enabledFaceId)) == 0)
379 continue;
380
381 // enabling only faceId
382 l3->GetFace (enabledFaceId)->SetMetric (originalMetric[enabledFaceId]);
383
384 DistancesMap distances;
385
386 NS_LOG_DEBUG ("-----------");
387
388 dijkstra_shortest_paths (graph, source,
389 // predecessor_map (boost::ref(predecessors))
390 // .
391 distance_map (boost::ref(distances))
392 .
393 distance_inf (WeightInf)
394 .
395 distance_zero (WeightZero)
396 .
397 distance_compare (boost::WeightCompare ())
398 .
399 distance_combine (boost::WeightCombine ())
400 );
401
402 // NS_LOG_DEBUG (predecessors.size () << ", " << distances.size ());
403
404 for (DistancesMap::iterator i = distances.begin ();
405 i != distances.end ();
406 i++)
407 {
408 if (i->first == source)
409 continue;
410 else
411 {
412 // cout << " Node " << i->first->GetObject<Node> ()->GetId ();
413 if (i->second.get<0> () == 0)
414 {
415 // cout << " is unreachable" << endl;
416 }
417 else
418 {
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -0700419 BOOST_FOREACH (const Ptr<const Name> &prefix, i->first->GetLocalPrefixes ())
Alexander Afanasyevf484fb92013-03-04 10:37:27 -0800420 {
421 NS_LOG_DEBUG (" prefix " << *prefix << " reachable via face " << *i->second.get<0> ()
422 << " with distance " << i->second.get<1> ()
423 << " with delay " << i->second.get<2> ());
424
425 if (i->second.get<0> ()->GetMetric () == std::numeric_limits<uint16_t>::max ()-1)
426 continue;
427
428 Ptr<fib::Entry> entry = fib->Add (prefix, i->second.get<0> (), i->second.get<1> ());
429 entry->SetRealDelayToProducer (i->second.get<0> (), Seconds (i->second.get<2> ()));
430
431 Ptr<Limits> faceLimits = i->second.get<0> ()->GetObject<Limits> ();
432
433 Ptr<Limits> fibLimits = entry->GetObject<Limits> ();
434 if (fibLimits != 0)
435 {
436 // if it was created by the forwarding strategy via DidAddFibEntry event
437 fibLimits->SetLimits (faceLimits->GetMaxRate (), 2 * i->second.get<2> () /*exact RTT*/);
438 NS_LOG_DEBUG ("Set limit for prefix " << *prefix << " " << faceLimits->GetMaxRate () << " / " <<
439 2*i->second.get<2> () << "s (" << faceLimits->GetMaxRate () * 2 * i->second.get<2> () << ")");
440 }
441 }
442 }
443 }
444 }
445
446 // disabling the face again
447 l3->GetFace (enabledFaceId)->SetMetric (std::numeric_limits<uint16_t>::max ()-1);
448 }
449
450 // recover original interface statuses
451 for (uint32_t faceId = 0; faceId < l3->GetNFaces (); faceId++)
452 {
453 l3->GetFace (faceId)->SetMetric (originalMetric[faceId]);
454 }
455 }
456}
457
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700458
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700459} // namespace ndn
460} // namespace ns3