20 #ifndef BOOST_GRAPH_NDN_GLOBAL_ROUTING_HELPER_H
21 #define BOOST_GRAPH_NDN_GLOBAL_ROUTING_HELPER_H
25 #include "ns3/ndnSIM/model/ndn-common.hpp"
27 #include <boost/graph/graph_traits.hpp>
28 #include <boost/graph/properties.hpp>
29 #include <boost/ref.hpp>
31 #include "ns3/ndnSIM/model/ndn-global-router.hpp"
34 #include "ns3/node-list.h"
35 #include "ns3/channel.h"
36 #include "ns3/channel-list.h"
43 class NdnGlobalRouterGraph {
45 typedef ns3::Ptr<ns3::ndn::GlobalRouter> Vertice;
46 typedef uint16_t edge_property_type;
47 typedef uint32_t vertex_property_type;
49 NdnGlobalRouterGraph()
51 for (ns3::NodeList::Iterator node = ns3::NodeList::Begin(); node != ns3::NodeList::End();
55 m_vertices.push_back(gr);
58 for (ns3::ChannelList::Iterator channel = ns3::ChannelList::Begin();
59 channel != ns3::ChannelList::End(); channel++) {
62 m_vertices.push_back(gr);
66 const std::list<Vertice>&
73 std::list<Vertice> m_vertices;
76 class ndn_global_router_graph_category :
public virtual vertex_list_graph_tag,
77 public virtual incidence_graph_tag {
81 struct graph_traits<NdnGlobalRouterGraph> {
83 typedef NdnGlobalRouterGraph::Vertice vertex_descriptor;
85 typedef directed_tag directed_category;
86 typedef disallow_parallel_edge_tag edge_parallel_category;
87 typedef ndn_global_router_graph_category traversal_category;
90 typedef std::list<vertex_descriptor>::const_iterator vertex_iterator;
91 typedef size_t vertices_size_type;
94 typedef ns3::ndn::GlobalRouter::IncidencyList::iterator out_edge_iterator;
95 typedef size_t degree_size_type;
104 inline graph_traits<NdnGlobalRouterGraph>::vertex_descriptor
105 source(graph_traits<NdnGlobalRouterGraph>::edge_descriptor e,
const NdnGlobalRouterGraph& g)
107 return std::get<0>(e);
110 inline graph_traits<NdnGlobalRouterGraph>::vertex_descriptor
111 target(graph_traits<NdnGlobalRouterGraph>::edge_descriptor e,
const NdnGlobalRouterGraph& g)
113 return std::get<2>(e);
116 inline std::pair<graph_traits<NdnGlobalRouterGraph>::vertex_iterator,
117 graph_traits<NdnGlobalRouterGraph>::vertex_iterator>
118 vertices(
const NdnGlobalRouterGraph& g)
120 return make_pair(g.GetVertices().begin(), g.GetVertices().end());
123 inline graph_traits<NdnGlobalRouterGraph>::vertices_size_type
124 num_vertices(
const NdnGlobalRouterGraph& g)
126 return g.GetVertices().size();
129 inline std::pair<graph_traits<NdnGlobalRouterGraph>::out_edge_iterator,
130 graph_traits<NdnGlobalRouterGraph>::out_edge_iterator>
131 out_edges(graph_traits<NdnGlobalRouterGraph>::vertex_descriptor u,
const NdnGlobalRouterGraph& g)
133 return std::make_pair(u->GetIncidencies().begin(), u->GetIncidencies().end());
136 inline graph_traits<NdnGlobalRouterGraph>::degree_size_type
137 out_degree(graph_traits<NdnGlobalRouterGraph>::vertex_descriptor u,
const NdnGlobalRouterGraph& g)
139 return u->GetIncidencies().size();
146 EdgeWeights(
const NdnGlobalRouterGraph& graph)
152 const NdnGlobalRouterGraph& m_graph;
156 VertexIds(
const NdnGlobalRouterGraph& graph)
162 const NdnGlobalRouterGraph& m_graph;
166 struct property_map<NdnGlobalRouterGraph, edge_weight_t> {
167 typedef const EdgeWeights const_type;
168 typedef EdgeWeights type;
172 struct property_map<NdnGlobalRouterGraph, vertex_index_t> {
173 typedef const VertexIds const_type;
174 typedef VertexIds type;
178 struct property_traits<EdgeWeights> {
180 typedef std::tuple<std::shared_ptr<nfd::Face>, uint16_t,
double> value_type;
181 typedef std::tuple<std::shared_ptr<nfd::Face>, uint16_t,
double> reference;
183 typedef readable_property_map_tag category;
186 const property_traits<EdgeWeights>::value_type WeightZero(
nullptr, 0, 0.0);
187 const property_traits<EdgeWeights>::value_type
188 WeightInf(
nullptr, std::numeric_limits<uint16_t>::max(), 0.0);
190 struct WeightCompare :
public std::binary_function<property_traits<EdgeWeights>::reference,
191 property_traits<EdgeWeights>::reference, bool> {
193 operator()(std::tuple<std::shared_ptr<nfd::Face>, uint32_t,
double> a,
194 std::tuple<std::shared_ptr<nfd::Face>, uint32_t,
double> b)
const
196 return std::get<1>(a) < std::get<1>(b);
200 operator()(property_traits<EdgeWeights>::reference a, uint32_t b)
const
202 return std::get<1>(a) < b;
206 operator()(uint32_t a, uint32_t b)
const
213 :
public std::binary_function<uint32_t, property_traits<EdgeWeights>::reference, uint32_t> {
215 operator()(uint32_t a, property_traits<EdgeWeights>::reference b)
const
217 return a + std::get<1>(b);
220 std::tuple<std::shared_ptr<nfd::Face>, uint32_t,
double>
221 operator()(std::tuple<std::shared_ptr<nfd::Face>, uint32_t,
double> a,
222 property_traits<EdgeWeights>::reference b)
const
224 if (std::get<0>(a) ==
nullptr)
225 return std::make_tuple(std::get<0>(b), std::get<1>(a) + std::get<1>(b),
226 std::get<2>(a) + std::get<2>(b));
228 return std::make_tuple(std::get<0>(a), std::get<1>(a) + std::get<1>(b),
229 std::get<2>(a) + std::get<2>(b));
234 struct property_traits<VertexIds> {
236 typedef uint32_t value_type;
237 typedef uint32_t reference;
238 typedef ns3::Ptr<ns3::ndn::GlobalRouter> key_type;
239 typedef readable_property_map_tag category;
243 get(edge_weight_t,
const NdnGlobalRouterGraph& g)
245 return EdgeWeights(g);
249 get(vertex_index_t,
const NdnGlobalRouterGraph& g)
254 template<
class M,
class K,
class V>
256 put(reference_wrapper<M> mapp, K a, V p)
265 get(
const boost::VertexIds&, ns3::Ptr<ns3::ndn::GlobalRouter>& gr)
270 inline property_traits<EdgeWeights>::reference
273 if (std::get<1>(edge) == 0)
274 return property_traits<EdgeWeights>::reference(
nullptr, 0, 0.0);
276 return property_traits<EdgeWeights>::reference(std::get<1>(edge),
277 static_cast<uint16_t
>(
278 std::get<1>(edge)->getMetric()),
283 struct PredecessorsMap
284 :
public std::map<ns3::Ptr<ns3::ndn::GlobalRouter>, ns3::Ptr<ns3::ndn::GlobalRouter>> {
288 struct property_traits<reference_wrapper<PredecessorsMap>> {
290 typedef ns3::Ptr<ns3::ndn::GlobalRouter> value_type;
291 typedef ns3::Ptr<ns3::ndn::GlobalRouter> reference;
292 typedef ns3::Ptr<ns3::ndn::GlobalRouter> key_type;
293 typedef read_write_property_map_tag category;
296 struct DistancesMap :
public std::map<ns3::Ptr<ns3::ndn::GlobalRouter>,
297 std::tuple<std::shared_ptr<nfd::Face>, uint32_t, double>> {
301 struct property_traits<reference_wrapper<DistancesMap>> {
303 typedef std::tuple<std::shared_ptr<nfd::Face>, uint32_t,
double> value_type;
304 typedef std::tuple<std::shared_ptr<nfd::Face>, uint32_t,
double> reference;
305 typedef ns3::Ptr<ns3::ndn::GlobalRouter> key_type;
306 typedef read_write_property_map_tag category;
313 class numeric_limits<std::tuple<std::shared_ptr<nfd::Face>, uint32_t, double>>
316 typedef std::tuple<std::shared_ptr<nfd::Face>, uint32_t,
double> value;
320 return boost::WeightInf;
327 inline std::tuple<std::shared_ptr<nfd::Face>, uint32_t,
double>
328 get(DistancesMap& map, ns3::Ptr<ns3::ndn::GlobalRouter> key)
330 boost::DistancesMap::iterator i = map.find(key);
332 return std::tuple<std::shared_ptr<nfd::Face>, uint32_t,
333 double>(
nullptr, std::numeric_limits<uint32_t>::max(), 0.0);
342 #endif // BOOST_GRAPH_NDN_GLOBAL_ROUTING_HELPER_H