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-face.hpp"
32 #include "ns3/ndnSIM/model/ndn-global-router.hpp"
34 #include "ns3/node-list.h"
35 #include "ns3/channel-list.h"
42 class NdnGlobalRouterGraph {
44 typedef ns3::Ptr<ns3::ndn::GlobalRouter> Vertice;
45 typedef uint16_t edge_property_type;
46 typedef uint32_t vertex_property_type;
48 NdnGlobalRouterGraph()
50 for (ns3::NodeList::Iterator node = ns3::NodeList::Begin(); node != ns3::NodeList::End();
54 m_vertices.push_back(gr);
57 for (ns3::ChannelList::Iterator channel = ns3::ChannelList::Begin();
58 channel != ns3::ChannelList::End(); channel++) {
61 m_vertices.push_back(gr);
65 const std::list<Vertice>&
72 std::list<Vertice> m_vertices;
75 class ndn_global_router_graph_category :
public virtual vertex_list_graph_tag,
76 public virtual incidence_graph_tag {
80 struct graph_traits<NdnGlobalRouterGraph> {
82 typedef NdnGlobalRouterGraph::Vertice vertex_descriptor;
84 typedef directed_tag directed_category;
85 typedef disallow_parallel_edge_tag edge_parallel_category;
86 typedef ndn_global_router_graph_category traversal_category;
89 typedef std::list<vertex_descriptor>::const_iterator vertex_iterator;
90 typedef size_t vertices_size_type;
93 typedef ns3::ndn::GlobalRouter::IncidencyList::iterator out_edge_iterator;
94 typedef size_t degree_size_type;
103 inline graph_traits<NdnGlobalRouterGraph>::vertex_descriptor
104 source(graph_traits<NdnGlobalRouterGraph>::edge_descriptor e,
const NdnGlobalRouterGraph& g)
106 return std::get<0>(e);
109 inline graph_traits<NdnGlobalRouterGraph>::vertex_descriptor
110 target(graph_traits<NdnGlobalRouterGraph>::edge_descriptor e,
const NdnGlobalRouterGraph& g)
112 return std::get<2>(e);
115 inline std::pair<graph_traits<NdnGlobalRouterGraph>::vertex_iterator,
116 graph_traits<NdnGlobalRouterGraph>::vertex_iterator>
117 vertices(
const NdnGlobalRouterGraph& g)
119 return make_pair(g.GetVertices().begin(), g.GetVertices().end());
122 inline graph_traits<NdnGlobalRouterGraph>::vertices_size_type
123 num_vertices(
const NdnGlobalRouterGraph& g)
125 return g.GetVertices().size();
128 inline std::pair<graph_traits<NdnGlobalRouterGraph>::out_edge_iterator,
129 graph_traits<NdnGlobalRouterGraph>::out_edge_iterator>
130 out_edges(graph_traits<NdnGlobalRouterGraph>::vertex_descriptor u,
const NdnGlobalRouterGraph& g)
132 return std::make_pair(u->GetIncidencies().begin(), u->GetIncidencies().end());
135 inline graph_traits<NdnGlobalRouterGraph>::degree_size_type
136 out_degree(graph_traits<NdnGlobalRouterGraph>::vertex_descriptor u,
const NdnGlobalRouterGraph& g)
138 return u->GetIncidencies().size();
145 EdgeWeights(
const NdnGlobalRouterGraph& graph)
151 const NdnGlobalRouterGraph& m_graph;
155 VertexIds(
const NdnGlobalRouterGraph& graph)
161 const NdnGlobalRouterGraph& m_graph;
165 struct property_map<NdnGlobalRouterGraph, edge_weight_t> {
166 typedef const EdgeWeights const_type;
167 typedef EdgeWeights type;
171 struct property_map<NdnGlobalRouterGraph, vertex_index_t> {
172 typedef const VertexIds const_type;
173 typedef VertexIds type;
177 struct property_traits<EdgeWeights> {
179 typedef std::tuple<std::shared_ptr<nfd::Face>, uint16_t,
double> value_type;
180 typedef std::tuple<std::shared_ptr<nfd::Face>, uint16_t,
double> reference;
182 typedef readable_property_map_tag category;
185 const property_traits<EdgeWeights>::value_type WeightZero(
nullptr, 0, 0.0);
186 const property_traits<EdgeWeights>::value_type
187 WeightInf(
nullptr, std::numeric_limits<uint16_t>::max(), 0.0);
189 struct WeightCompare :
public std::binary_function<property_traits<EdgeWeights>::reference,
190 property_traits<EdgeWeights>::reference, bool> {
192 operator()(std::tuple<std::shared_ptr<nfd::Face>, uint32_t,
double> a,
193 std::tuple<std::shared_ptr<nfd::Face>, uint32_t,
double> b)
const
195 return std::get<1>(a) < std::get<1>(b);
199 operator()(property_traits<EdgeWeights>::reference a, uint32_t b)
const
201 return std::get<1>(a) < b;
205 operator()(uint32_t a, uint32_t b)
const
212 :
public std::binary_function<uint32_t, property_traits<EdgeWeights>::reference, uint32_t> {
214 operator()(uint32_t a, property_traits<EdgeWeights>::reference b)
const
216 return a + std::get<1>(b);
219 std::tuple<std::shared_ptr<nfd::Face>, uint32_t,
double>
220 operator()(std::tuple<std::shared_ptr<nfd::Face>, uint32_t,
double> a,
221 property_traits<EdgeWeights>::reference b)
const
223 if (std::get<0>(a) ==
nullptr)
224 return std::make_tuple(std::get<0>(b), std::get<1>(a) + std::get<1>(b),
225 std::get<2>(a) + std::get<2>(b));
227 return std::make_tuple(std::get<0>(a), std::get<1>(a) + std::get<1>(b),
228 std::get<2>(a) + std::get<2>(b));
233 struct property_traits<VertexIds> {
235 typedef uint32_t value_type;
236 typedef uint32_t reference;
237 typedef ns3::Ptr<ns3::ndn::GlobalRouter> key_type;
238 typedef readable_property_map_tag category;
242 get(edge_weight_t,
const NdnGlobalRouterGraph& g)
244 return EdgeWeights(g);
248 get(vertex_index_t,
const NdnGlobalRouterGraph& g)
253 template<
class M,
class K,
class V>
255 put(reference_wrapper<M> mapp, K a, V p)
264 get(
const boost::VertexIds&, ns3::Ptr<ns3::ndn::GlobalRouter>& gr)
269 inline property_traits<EdgeWeights>::reference
272 if (std::get<1>(edge) == 0)
273 return property_traits<EdgeWeights>::reference(
nullptr, 0, 0.0);
275 return property_traits<EdgeWeights>::reference(std::get<1>(edge),
276 static_cast<uint16_t>(
277 std::get<1>(edge)->getMetric()),
282 struct PredecessorsMap
283 :
public std::map<ns3::Ptr<ns3::ndn::GlobalRouter>, ns3::Ptr<ns3::ndn::GlobalRouter>> {
287 struct property_traits<reference_wrapper<PredecessorsMap>> {
289 typedef ns3::Ptr<ns3::ndn::GlobalRouter> value_type;
290 typedef ns3::Ptr<ns3::ndn::GlobalRouter> reference;
291 typedef ns3::Ptr<ns3::ndn::GlobalRouter> key_type;
292 typedef read_write_property_map_tag category;
295 struct DistancesMap :
public std::map<ns3::Ptr<ns3::ndn::GlobalRouter>,
296 std::tuple<std::shared_ptr<nfd::Face>, uint32_t, double>> {
300 struct property_traits<reference_wrapper<DistancesMap>> {
302 typedef std::tuple<std::shared_ptr<nfd::Face>, uint32_t,
double> value_type;
303 typedef std::tuple<std::shared_ptr<nfd::Face>, uint32_t,
double> reference;
304 typedef ns3::Ptr<ns3::ndn::GlobalRouter> key_type;
305 typedef read_write_property_map_tag category;
312 class numeric_limits<std::tuple<std::shared_ptr<nfd::Face>, uint32_t, double>>
315 typedef std::tuple<std::shared_ptr<nfd::Face>, uint32_t,
double> value;
319 return boost::WeightInf;
326 inline std::tuple<std::shared_ptr<nfd::Face>, uint32_t,
double>
327 get(DistancesMap& map, ns3::Ptr<ns3::ndn::GlobalRouter> key)
329 boost::DistancesMap::iterator i = map.find(key);
331 return std::tuple<std::shared_ptr<nfd::Face>, uint32_t,
332 double>(
nullptr, std::numeric_limits<uint32_t>::max(), 0.0);
341 #endif // BOOST_GRAPH_NDN_GLOBAL_ROUTING_HELPER_H
Class representing global router interface for ndnSIM.
std::tuple< Ptr< GlobalRouter >, shared_ptr< Face >, Ptr< GlobalRouter > > Incidency
Graph edge.