21 #include "ns3/ndnSIM/helper/ndn-global-routing-helper.hpp" 23 #include <boost/graph/dijkstra_shortest_paths.hpp> 24 #include <boost/graph/graph_utility.hpp> 26 #include "ns3/ndnSIM/helper/boost-graph-ndn-global-routing-helper.hpp" 27 #include "ns3/ndnSIM/helper/lfid/abstract-fib.hpp" 28 #include "ns3/ndnSIM/helper/lfid/remove-loops.hpp" 29 #include "ns3/ndnSIM/helper/ndn-fib-helper.hpp" 30 #include "ns3/ndnSIM/model/ndn-global-router.hpp" 32 NS_LOG_COMPONENT_DEFINE(
"ndn.GlobalRoutingHelperLfid");
38 using std::unordered_map;
43 BOOST_CONCEPT_ASSERT((boost::VertexListGraphConcept<boost::NdnGlobalRouterGraph>));
44 BOOST_CONCEPT_ASSERT((boost::IncidenceGraphConcept<boost::NdnGlobalRouterGraph>));
47 boost::NdnGlobalRouterGraph graph{};
52 unordered_map<int, unordered_map<nfd::FaceId, shared_ptr<Face>>> faceMap;
55 for (
auto node = NodeList::Begin(); node != NodeList::End(); node++) {
57 int nodeId =
static_cast<int>((*node)->GetId());
58 const Ptr<GlobalRouter>& source = (*node)->GetObject<
GlobalRouter>();
62 if (source ==
nullptr) {
63 NS_LOG_ERROR(
"Node " << (*node)->GetId() <<
" does not export GlobalRouter interface");
68 unordered_map<int, boost::DistancesMap> nbSp;
71 boost::DistancesMap distMap;
72 unordered_map<int, boost::DistancesMap> neighborSpMap;
74 dijkstra_shortest_paths(graph, source,
75 distance_map(boost::ref(distMap))
76 .distance_inf(boost::WeightInf)
77 .distance_zero(boost::WeightZero)
78 .distance_compare(boost::WeightCompare())
79 .distance_combine(boost::WeightCombine()));
82 unordered_map<nfd::FaceId, uint64_t> originalMetrics;
83 auto& originalFace = faceMap[nodeId];
87 for (
const auto& neighbor : neighbors) {
88 int nbId = get<2>(neighbor)->GetObject<ns3::Node>()->GetId();
89 NS_ABORT_UNLESS(nbId != nodeId);
91 auto& face = get<shared_ptr<Face>>(neighbor);
92 NS_ABORT_UNLESS(face !=
nullptr);
94 originalMetrics[nbId] = face->getMetric();
95 originalFace[nbId] = face;
96 face->setMetric(get<uint16_t>(boost::WeightInf));
100 for (
const auto& neighbor : neighbors) {
101 const auto& nSource = get<0>(neighbor);
102 const auto& target = get<2>(neighbor);
104 int nbId = target->GetObject<
ns3::Node>()->GetId();
105 Ptr<GlobalRouter> nbRouter = target;
107 NS_ABORT_UNLESS(target != source && nbId != nodeId);
108 NS_ABORT_UNLESS(nSource == source);
110 dijkstra_shortest_paths(graph, nbRouter,
111 distance_map(boost::ref(neighborSpMap[nbId]))
112 .distance_inf(boost::WeightInf)
113 .distance_zero(boost::WeightZero)
114 .distance_compare(boost::WeightCompare())
115 .distance_combine(boost::WeightCombine()));
119 for (
const auto& neighbor : neighbors) {
120 int nbId = get<2>(neighbor)->GetObject<ns3::Node>()->GetId();
121 NS_ABORT_UNLESS(nbId != nodeId);
123 const auto& face = get<shared_ptr<Face>>(neighbor);
124 NS_ABORT_UNLESS(face->getMetric() == get<uint16_t>(boost::WeightInf));
125 face->setMetric(originalMetrics.at(nbId));
130 for (
const auto& dstEntry : distMap) {
131 Ptr<GlobalRouter> dstRouter = dstEntry.first;
132 int dstId = dstRouter->GetObject<
ns3::Node>()->GetId();
133 if (dstRouter == source)
136 int spTotalCost =
static_cast<int>(get<uint32_t>(dstEntry.second));
139 for (
const auto& nb : neighborSpMap) {
140 int neighborId = nb.first;
141 const uint32_t nbDist{get<uint32_t>(nb.second.at(dstRouter))};
143 int neighborCost =
static_cast<int>(nbDist);
144 int neighborTotalCost = neighborCost +
static_cast<int>(originalFace.at(neighborId)->getMetric());
146 NS_ABORT_UNLESS(neighborTotalCost >= spTotalCost);
149 if (neighborTotalCost >= static_cast<int>(get<uint16_t>(boost::WeightInf)))
153 if (neighborCost < spTotalCost) {
160 int costDelta = neighborTotalCost - spTotalCost;
161 FibNextHop nh = {neighborTotalCost, neighborId, costDelta, nbType};
162 nodeFib.insert(dstId, nh);
168 allNodeFIB.emplace(nodeId, nodeFib);
177 for (
const auto& nodeEntry : allNodeFIB) {
178 int nodeId = nodeEntry.first;
179 const auto& fib = nodeEntry.second;
182 for (
const auto& dst : fib) {
183 int dstId = dst.first;
184 const auto& dstRouter = allNodeFIB.at(dstId).getGR();
187 for (
const auto& nh : dst.second) {
188 int neighborId = nh.getNexthopId();
189 int neighborTotalCost = nh.getCost();
191 for (
const auto& prefix : dstRouter->GetLocalPrefixes()) {
192 Ptr<Node> node = NodeList::GetNode(static_cast<uint32_t>(nodeId));
Copyright (c) 2011-2015 Regents of the University of California.
Class representing global router interface for ndnSIM.
static void AddRoute(Ptr< Node > node, const Name &prefix, shared_ptr< Face > face, int32_t metric)
Add forwarding entry to FIB.
R & get(variant< T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15 > &v, nonstd_lite_in_place_type_t(R)=nonstd_lite_in_place_type(R))
static void CalculateLfidRoutes()
Calculates a set of loop-free multipath routes.
int removeLoops(AllNodeFib &allNodeFIB, bool printOutput)
An abstract, lightweight representation of the FIB.
int removeDeadEnds(AllNodeFib &allNodeFIB, bool printOutput)
std::unordered_map< int, AbstractFib > AllNodeFib
std::list< Incidency > IncidencyList
List of graph edges.
Copyright (c) 2011-2015 Regents of the University of California.