blob: 43f0f20e4d16bb6ce7c3f41998f348fb8d09ebec [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 Afanasyev0c395372014-12-20 15:54:02 -080027#include "ndn-global-routing-helper.hpp"
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070028
Spyridon Mastorakis60f4b992014-11-07 15:51:38 -080029#include "model/ndn-l3-protocol.hpp"
30#include "helper/ndn-fib-helper.hpp"
31#include "model/ndn-net-device-face.hpp"
32#include "model/ndn-global-router.hpp"
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070033
Spyridon Mastorakis60f4b992014-11-07 15:51:38 -080034#include "daemon/table/fib.hpp"
35#include "daemon/fw/forwarder.hpp"
36#include "daemon/table/fib-entry.hpp"
37#include "daemon/table/fib-nexthop.hpp"
38
39#include "ns3/object.h"
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070040#include "ns3/node.h"
Alexander Afanasyevce810142012-04-17 15:50:36 -070041#include "ns3/node-container.h"
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070042#include "ns3/net-device.h"
43#include "ns3/channel.h"
44#include "ns3/log.h"
45#include "ns3/assert.h"
46#include "ns3/names.h"
47#include "ns3/node-list.h"
48#include "ns3/channel-list.h"
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070049#include "ns3/object-factory.h"
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070050
51#include <boost/lexical_cast.hpp>
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -070052#include <boost/foreach.hpp>
Alexander Afanasyeva5abcd92012-04-17 13:34:43 -070053#include <boost/concept/assert.hpp>
Alexander Afanasyeva5abcd92012-04-17 13:34:43 -070054#include <boost/graph/dijkstra_shortest_paths.hpp>
55
Alexander Afanasyev0c395372014-12-20 15:54:02 -080056#include "boost-graph-ndn-global-routing-helper.hpp"
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070057
Alexander Afanasyev73532512012-11-27 00:42:35 -080058#include <math.h>
59
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080060NS_LOG_COMPONENT_DEFINE("ndn.GlobalRoutingHelper");
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070061
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070062namespace ns3 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070063namespace ndn {
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070064
65void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080066GlobalRoutingHelper::Install(Ptr<Node> node)
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070067{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080068 NS_LOG_LOGIC("Node: " << node->GetId());
Alexander Afanasyev49165862013-01-31 00:38:20 -080069
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080070 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 Afanasyevbe55cf62014-12-20 17:51:09 -080073 Ptr<GlobalRouter> gr = node->GetObject<GlobalRouter>();
74 if (gr != 0) {
75 NS_LOG_DEBUG("GlobalRouter is already installed: " << gr);
76 return; // already installed
77 }
78
79 gr = CreateObject<GlobalRouter>();
80 node->AggregateObject(gr);
81
Spyridon Mastorakis60f4b992014-11-07 15:51:38 -080082 for (auto& i : ndn->getForwarder()->getFaceTable()) {
83 shared_ptr<NetDeviceFace> face = std::dynamic_pointer_cast<NetDeviceFace>(i);
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080084 if (face == 0) {
85 NS_LOG_DEBUG("Skipping non-netdevice face");
86 continue;
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070087 }
Alexander Afanasyev49165862013-01-31 00:38:20 -080088
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080089 Ptr<NetDevice> nd = face->GetNetDevice();
90 if (nd == 0) {
91 NS_LOG_DEBUG("Not a NetDevice associated with NetDeviceFace");
92 continue;
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070093 }
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080094
95 Ptr<Channel> ch = nd->GetChannel();
96
97 if (ch == 0) {
98 NS_LOG_DEBUG("Channel is not associated with NetDevice");
99 continue;
100 }
101
102 if (ch->GetNDevices() == 2) // e.g., point-to-point channel
103 {
104 for (uint32_t deviceId = 0; deviceId < ch->GetNDevices(); deviceId++) {
105 Ptr<NetDevice> otherSide = ch->GetDevice(deviceId);
106 if (nd == otherSide)
107 continue;
108
109 Ptr<Node> otherNode = otherSide->GetNode();
110 NS_ASSERT(otherNode != 0);
111
112 Ptr<GlobalRouter> otherGr = otherNode->GetObject<GlobalRouter>();
113 if (otherGr == 0) {
114 Install(otherNode);
115 }
116 otherGr = otherNode->GetObject<GlobalRouter>();
117 NS_ASSERT(otherGr != 0);
118 gr->AddIncidency(face, otherGr);
119 }
120 }
121 else {
122 Ptr<GlobalRouter> grChannel = ch->GetObject<GlobalRouter>();
123 if (grChannel == 0) {
124 Install(ch);
125 }
126 grChannel = ch->GetObject<GlobalRouter>();
127
128 gr->AddIncidency(face, grChannel);
129 }
130 }
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700131}
132
133void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800134GlobalRoutingHelper::Install(Ptr<Channel> channel)
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700135{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800136 NS_LOG_LOGIC("Channel: " << channel->GetId());
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700137
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800138 Ptr<GlobalRouter> gr = channel->GetObject<GlobalRouter>();
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700139 if (gr != 0)
140 return;
141
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800142 gr = CreateObject<GlobalRouter>();
143 channel->AggregateObject(gr);
Alexander Afanasyev49165862013-01-31 00:38:20 -0800144
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800145 for (uint32_t deviceId = 0; deviceId < channel->GetNDevices(); deviceId++) {
146 Ptr<NetDevice> dev = channel->GetDevice(deviceId);
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700147
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800148 Ptr<Node> node = dev->GetNode();
149 NS_ASSERT(node != 0);
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700150
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800151 Ptr<GlobalRouter> grOther = node->GetObject<GlobalRouter>();
152 if (grOther == 0) {
153 Install(node);
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700154 }
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800155 grOther = node->GetObject<GlobalRouter>();
156 NS_ASSERT(grOther != 0);
157
158 gr->AddIncidency(0, grOther);
159 }
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700160}
161
162void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800163GlobalRoutingHelper::Install(const NodeContainer& nodes)
Alexander Afanasyevce810142012-04-17 15:50:36 -0700164{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800165 for (NodeContainer::Iterator node = nodes.Begin(); node != nodes.End(); node++) {
166 Install(*node);
167 }
168}
169
170void
171GlobalRoutingHelper::InstallAll()
172{
173 Install(NodeContainer::GetGlobal());
174}
175
176void
177GlobalRoutingHelper::AddOrigin(const std::string& prefix, Ptr<Node> node)
178{
179 Ptr<GlobalRouter> gr = node->GetObject<GlobalRouter>();
180 NS_ASSERT_MSG(gr != 0, "GlobalRouter is not installed on the node");
181
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -0700182 auto name = make_shared<Name>(prefix);
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800183 gr->AddLocalPrefix(name);
184}
185
186void
187GlobalRoutingHelper::AddOrigins(const std::string& prefix, const NodeContainer& nodes)
188{
189 for (NodeContainer::Iterator node = nodes.Begin(); node != nodes.End(); node++) {
190 AddOrigin(prefix, *node);
191 }
192}
193
194void
195GlobalRoutingHelper::AddOrigin(const std::string& prefix, const std::string& nodeName)
196{
197 Ptr<Node> node = Names::Find<Node>(nodeName);
198 NS_ASSERT_MSG(node != 0, nodeName << "is not a Node");
199
200 AddOrigin(prefix, node);
201}
202
203void
204GlobalRoutingHelper::AddOriginsForAll()
205{
206 for (NodeList::Iterator node = NodeList::Begin(); node != NodeList::End(); node++) {
207 Ptr<GlobalRouter> gr = (*node)->GetObject<GlobalRouter>();
Spyridon Mastorakis60f4b992014-11-07 15:51:38 -0800208 std::string name = Names::FindName(*node);
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800209
210 if (gr != 0 && !name.empty()) {
211 AddOrigin("/" + name, *node);
Alexander Afanasyevce810142012-04-17 15:50:36 -0700212 }
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800213 }
Alexander Afanasyevce810142012-04-17 15:50:36 -0700214}
215
216void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800217GlobalRoutingHelper::CalculateRoutes(bool invalidatedRoutes /* = true*/)
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700218{
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700219 /**
220 * Implementation of route calculation is heavily based on Boost Graph Library
221 * See http://www.boost.org/doc/libs/1_49_0/libs/graph/doc/table_of_contents.html for more details
222 */
Alexander Afanasyev49165862013-01-31 00:38:20 -0800223
Spyridon Mastorakis60f4b992014-11-07 15:51:38 -0800224 BOOST_CONCEPT_ASSERT((boost::VertexListGraphConcept<boost::NdnGlobalRouterGraph>));
225 BOOST_CONCEPT_ASSERT((boost::IncidenceGraphConcept<boost::NdnGlobalRouterGraph>));
Alexander Afanasyev49165862013-01-31 00:38:20 -0800226
Spyridon Mastorakis60f4b992014-11-07 15:51:38 -0800227 boost::NdnGlobalRouterGraph graph;
Zongyi Zhaoc8372632014-04-28 15:36:49 -0700228 // typedef graph_traits < NdnGlobalRouterGraph >::vertex_descriptor vertex_descriptor;
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700229
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700230 // For now we doing Dijkstra for every node. Can be replaced with Bellman-Ford or Floyd-Warshall.
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800231 // Other algorithms should be faster, but they need additional EdgeListGraph concept provided by
232 // the graph, which
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700233 // is not obviously how implement in an efficient manner
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800234 for (NodeList::Iterator node = NodeList::Begin(); node != NodeList::End(); node++) {
235 Ptr<GlobalRouter> source = (*node)->GetObject<GlobalRouter>();
236 if (source == 0) {
237 NS_LOG_DEBUG("Node " << (*node)->GetId() << " does not export GlobalRouter interface");
238 continue;
239 }
Alexander Afanasyev49165862013-01-31 00:38:20 -0800240
Spyridon Mastorakis60f4b992014-11-07 15:51:38 -0800241 boost::DistancesMap distances;
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700242
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800243 dijkstra_shortest_paths(graph, source,
244 // predecessor_map (boost::ref(predecessors))
245 // .
246 distance_map(boost::ref(distances))
Spyridon Mastorakis60f4b992014-11-07 15:51:38 -0800247 .distance_inf(boost::WeightInf)
248 .distance_zero(boost::WeightZero)
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800249 .distance_compare(boost::WeightCompare())
250 .distance_combine(boost::WeightCombine()));
251
252 // NS_LOG_DEBUG (predecessors.size () << ", " << distances.size ());
Spyridon Mastorakis60f4b992014-11-07 15:51:38 -0800253
254 Ptr<L3Protocol> L3protocol = (*node)->GetObject<L3Protocol>();
255 shared_ptr<nfd::Forwarder> forwarder = L3protocol->getForwarder();
256
257 if (invalidatedRoutes) {
258 std::vector<::nfd::fib::NextHop> NextHopList;
259 for (nfd::Fib::const_iterator fibIt = forwarder->getFib().begin();
260 fibIt != forwarder->getFib().end();) {
261 NextHopList.clear();
262 NextHopList = fibIt->getNextHops();
263 ++fibIt;
264 for (int i = 0; i < NextHopList.size(); i++) {
265 NextHopList[i].setCost(std::numeric_limits<uint64_t>::max());
266 }
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -0700267 }
Spyridon Mastorakis60f4b992014-11-07 15:51:38 -0800268 }
269
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800270 NS_LOG_DEBUG("Reachability from Node: " << source->GetObject<Node>()->GetId());
Spyridon Mastorakis60f4b992014-11-07 15:51:38 -0800271 for (const auto& dist : distances) {
272 if (dist.first == source)
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800273 continue;
274 else {
Spyridon Mastorakis60f4b992014-11-07 15:51:38 -0800275 // cout << " Node " << dist.first->GetObject<Node> ()->GetId ();
276 if (std::get<0>(dist.second) == 0) {
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800277 // cout << " is unreachable" << endl;
278 }
279 else {
Spyridon Mastorakis60f4b992014-11-07 15:51:38 -0800280 for (const auto& prefix : dist.first->GetLocalPrefixes()) {
281 NS_LOG_DEBUG(" prefix " << prefix << " reachable via face " << *std::get<0>(dist.second)
282 << " with distance " << std::get<1>(dist.second) << " with delay "
283 << std::get<2>(dist.second));
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800284
Spyridon Mastorakis60f4b992014-11-07 15:51:38 -0800285 FibHelper::AddRoute(*node, *prefix, std::get<0>(dist.second),
286 std::get<1>(dist.second));
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800287 }
288 }
289 }
290 }
291 }
292}
293
294void
295GlobalRoutingHelper::CalculateAllPossibleRoutes(bool invalidatedRoutes /* = true*/)
296{
297 /**
298 * Implementation of route calculation is heavily based on Boost Graph Library
299 * See http://www.boost.org/doc/libs/1_49_0/libs/graph/doc/table_of_contents.html for more details
300 */
301
Spyridon Mastorakis60f4b992014-11-07 15:51:38 -0800302 BOOST_CONCEPT_ASSERT((boost::VertexListGraphConcept<boost::NdnGlobalRouterGraph>));
303 BOOST_CONCEPT_ASSERT((boost::IncidenceGraphConcept<boost::NdnGlobalRouterGraph>));
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800304
Spyridon Mastorakis60f4b992014-11-07 15:51:38 -0800305 boost::NdnGlobalRouterGraph graph;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800306 // typedef graph_traits < NdnGlobalRouterGraph >::vertex_descriptor vertex_descriptor;
307
308 // For now we doing Dijkstra for every node. Can be replaced with Bellman-Ford or Floyd-Warshall.
309 // Other algorithms should be faster, but they need additional EdgeListGraph concept provided by
310 // the graph, which
311 // is not obviously how implement in an efficient manner
312 for (NodeList::Iterator node = NodeList::Begin(); node != NodeList::End(); node++) {
313 Ptr<GlobalRouter> source = (*node)->GetObject<GlobalRouter>();
314 if (source == 0) {
315 NS_LOG_DEBUG("Node " << (*node)->GetId() << " does not export GlobalRouter interface");
316 continue;
317 }
318
Spyridon Mastorakis60f4b992014-11-07 15:51:38 -0800319 Ptr<L3Protocol> L3protocol = (*node)->GetObject<L3Protocol>();
320 shared_ptr<nfd::Forwarder> forwarder = L3protocol->getForwarder();
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800321
Spyridon Mastorakis60f4b992014-11-07 15:51:38 -0800322 if (invalidatedRoutes) {
323 std::vector<::nfd::fib::NextHop> NextHopList;
324 for (nfd::Fib::const_iterator fibIt = forwarder->getFib().begin();
325 fibIt != forwarder->getFib().end();) {
326 NextHopList.clear();
327 NextHopList = fibIt->getNextHops();
328 ++fibIt;
329 for (int i = 0; i < NextHopList.size(); i++) {
330 NextHopList[i].setCost(std::numeric_limits<uint64_t>::max());
331 }
332 }
333 }
334
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800335 NS_LOG_DEBUG("Reachability from Node: " << source->GetObject<Node>()->GetId() << " ("
336 << Names::FindName(source->GetObject<Node>()) << ")");
337
338 Ptr<L3Protocol> l3 = source->GetObject<L3Protocol>();
339 NS_ASSERT(l3 != 0);
340
341 // remember interface statuses
Spyridon Mastorakis60f4b992014-11-07 15:51:38 -0800342 int faceNumber = 0;
343 std::vector<uint16_t> originalMetric(uint32_t(l3->getForwarder()->getFaceTable().size()));
344 for (auto& i : l3->getForwarder()->getFaceTable()) {
345 faceNumber++;
346 shared_ptr<Face> nfdFace = std::dynamic_pointer_cast<Face>(i);
347 originalMetric[uint32_t(faceNumber)] = nfdFace->getMetric();
348 nfdFace->setMetric(std::numeric_limits<uint16_t>::max() - 1);
349 // value std::numeric_limits<uint16_t>::max () MUST NOT be used (reserved)
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800350 }
351
Spyridon Mastorakis60f4b992014-11-07 15:51:38 -0800352 faceNumber = 0;
353 for (auto& k : l3->getForwarder()->getFaceTable()) {
354 faceNumber++;
355 shared_ptr<NetDeviceFace> face = std::dynamic_pointer_cast<NetDeviceFace>(k);
356 if (face == 0) {
357 NS_LOG_DEBUG("Skipping non-netdevice face");
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800358 continue;
Spyridon Mastorakis60f4b992014-11-07 15:51:38 -0800359 }
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800360
361 // enabling only faceId
Spyridon Mastorakis60f4b992014-11-07 15:51:38 -0800362 face->setMetric(originalMetric[uint32_t(faceNumber)]);
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800363
Spyridon Mastorakis60f4b992014-11-07 15:51:38 -0800364 boost::DistancesMap distances;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800365
366 NS_LOG_DEBUG("-----------");
367
368 dijkstra_shortest_paths(graph, source,
369 // predecessor_map (boost::ref(predecessors))
370 // .
371 distance_map(boost::ref(distances))
Spyridon Mastorakis60f4b992014-11-07 15:51:38 -0800372 .distance_inf(boost::WeightInf)
373 .distance_zero(boost::WeightZero)
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800374 .distance_compare(boost::WeightCompare())
375 .distance_combine(boost::WeightCombine()));
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700376
Alexander Afanasyeva5abcd92012-04-17 13:34:43 -0700377 // NS_LOG_DEBUG (predecessors.size () << ", " << distances.size ());
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700378
Spyridon Mastorakis60f4b992014-11-07 15:51:38 -0800379 for (const auto& dist : distances) {
380 if (dist.first == source)
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800381 continue;
382 else {
Spyridon Mastorakis60f4b992014-11-07 15:51:38 -0800383 // cout << " Node " << dist.first->GetObject<Node> ()->GetId ();
384 if (std::get<0>(dist.second) == 0) {
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800385 // cout << " is unreachable" << endl;
386 }
387 else {
Spyridon Mastorakis60f4b992014-11-07 15:51:38 -0800388 for (const auto& prefix : dist.first->GetLocalPrefixes()) {
389 NS_LOG_DEBUG(" prefix " << *prefix << " reachable via face "
390 << *std::get<0>(dist.second)
391 << " with distance " << std::get<1>(dist.second)
392 << " with delay " << std::get<2>(dist.second));
Alexander Afanasyev49165862013-01-31 00:38:20 -0800393
Spyridon Mastorakis60f4b992014-11-07 15:51:38 -0800394 if (std::get<0>(dist.second)->getMetric() == std::numeric_limits<uint16_t>::max() - 1)
Alexander Afanasyevf484fb92013-03-04 10:37:27 -0800395 continue;
Alexander Afanasyevf484fb92013-03-04 10:37:27 -0800396
Spyridon Mastorakis60f4b992014-11-07 15:51:38 -0800397 FibHelper::AddRoute(*node, *prefix, std::get<0>(dist.second),
398 std::get<1>(dist.second));
Alexander Afanasyevf484fb92013-03-04 10:37:27 -0800399 }
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800400 }
Alexander Afanasyevf484fb92013-03-04 10:37:27 -0800401 }
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800402 }
Alexander Afanasyevf484fb92013-03-04 10:37:27 -0800403
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800404 // disabling the face again
Spyridon Mastorakis60f4b992014-11-07 15:51:38 -0800405 face->setMetric(std::numeric_limits<uint16_t>::max() - 1);
Alexander Afanasyevf484fb92013-03-04 10:37:27 -0800406 }
Alexander Afanasyevf484fb92013-03-04 10:37:27 -0800407
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800408 // recover original interface statuses
Spyridon Mastorakis60f4b992014-11-07 15:51:38 -0800409 faceNumber = 0;
410 for (auto& i : l3->getForwarder()->getFaceTable()) {
411 faceNumber++;
412 shared_ptr<Face> face = std::dynamic_pointer_cast<Face>(i);
413 face->setMetric(originalMetric[faceNumber]);
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800414 }
415 }
416}
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700417
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700418} // namespace ndn
419} // namespace ns3