22 #ifndef BOOST_GRAPH_NDN_GLOBAL_ROUTING_HELPER_H
23 #define BOOST_GRAPH_NDN_GLOBAL_ROUTING_HELPER_H
27 #include <boost/graph/graph_traits.hpp>
28 #include <boost/graph/properties.hpp>
29 #include <boost/ref.hpp>
31 #include "ns3/ndn-face.h"
32 #include "ns3/ndn-limits.h"
33 #include "ns3/node-list.h"
34 #include "ns3/channel-list.h"
35 #include "../model/ndn-global-router.h"
41 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 (); node++)
54 m_vertices.push_back (gr);
57 for (ns3::ChannelList::Iterator channel = ns3::ChannelList::Begin (); channel != ns3::ChannelList::End (); channel++)
61 m_vertices.push_back (gr);
65 const std::list< Vertice > &
72 std::list< Vertice > m_vertices;
76 class ndn_global_router_graph_category :
77 public virtual vertex_list_graph_tag,
78 public virtual incidence_graph_tag
84 struct graph_traits< NdnGlobalRouterGraph >
87 typedef NdnGlobalRouterGraph::Vertice vertex_descriptor;
89 typedef directed_tag directed_category;
90 typedef disallow_parallel_edge_tag edge_parallel_category;
91 typedef ndn_global_router_graph_category traversal_category;
94 typedef std::list< vertex_descriptor >::const_iterator vertex_iterator;
95 typedef size_t vertices_size_type;
98 typedef ns3::ndn::GlobalRouter::IncidencyList::iterator out_edge_iterator;
99 typedef size_t degree_size_type;
110 graph_traits< NdnGlobalRouterGraph >::vertex_descriptor
112 graph_traits< NdnGlobalRouterGraph >::edge_descriptor e,
113 const NdnGlobalRouterGraph& g)
119 graph_traits< NdnGlobalRouterGraph >::vertex_descriptor
121 graph_traits< NdnGlobalRouterGraph >::edge_descriptor e,
122 const NdnGlobalRouterGraph& g)
128 std::pair< graph_traits< NdnGlobalRouterGraph >::vertex_iterator,
129 graph_traits< NdnGlobalRouterGraph >::vertex_iterator >
130 vertices (
const NdnGlobalRouterGraph&g)
132 return make_pair (g.GetVertices ().begin (), g.GetVertices ().end ());
136 graph_traits< NdnGlobalRouterGraph >::vertices_size_type
137 num_vertices(
const NdnGlobalRouterGraph &g)
139 return g.GetVertices ().size ();
144 std::pair< graph_traits< NdnGlobalRouterGraph >::out_edge_iterator,
145 graph_traits< NdnGlobalRouterGraph >::out_edge_iterator >
147 graph_traits< NdnGlobalRouterGraph >::vertex_descriptor u,
148 const NdnGlobalRouterGraph& g)
150 return std::make_pair(u->GetIncidencies ().begin (),
151 u->GetIncidencies ().end ());
155 graph_traits< NdnGlobalRouterGraph >::degree_size_type
157 graph_traits< NdnGlobalRouterGraph >::vertex_descriptor u,
158 const NdnGlobalRouterGraph& g)
160 return u->GetIncidencies ().size ();
169 EdgeWeights (
const NdnGlobalRouterGraph &graph)
175 const NdnGlobalRouterGraph &m_graph;
181 VertexIds (
const NdnGlobalRouterGraph &graph)
187 const NdnGlobalRouterGraph &m_graph;
191 struct property_map< NdnGlobalRouterGraph, edge_weight_t >
193 typedef const EdgeWeights const_type;
194 typedef EdgeWeights type;
198 struct property_map< NdnGlobalRouterGraph, vertex_index_t >
200 typedef const VertexIds const_type;
201 typedef VertexIds type;
206 struct property_traits< EdgeWeights >
209 typedef tuple< ns3::Ptr<ns3::ndn::Face>, uint16_t,
double > value_type;
210 typedef tuple< ns3::Ptr<ns3::ndn::Face>, uint16_t,
double > reference;
212 typedef readable_property_map_tag category;
215 const property_traits< EdgeWeights >::value_type WeightZero (0, 0, 0.0);
216 const property_traits< EdgeWeights >::value_type WeightInf (0, std::numeric_limits<uint16_t>::max (), 0.0);
218 struct WeightCompare :
219 public std::binary_function<property_traits< EdgeWeights >::reference,
220 property_traits< EdgeWeights >::reference,
224 operator () (tuple< ns3::Ptr<ns3::ndn::Face>, uint32_t,
double > a,
225 tuple< ns3::Ptr<ns3::ndn::Face>, uint32_t,
double > b)
const
227 return a.get<1> () < b.get<1> ();
231 operator () (property_traits< EdgeWeights >::reference a,
234 return a.get<1> () < b;
238 operator () (uint32_t a,
246 struct WeightCombine :
247 public std::binary_function<uint32_t,
248 property_traits< EdgeWeights >::reference,
252 operator () (uint32_t a, property_traits< EdgeWeights >::reference b)
const
254 return a + b.get<1> ();
257 tuple< ns3::Ptr<ns3::ndn::Face>, uint32_t,
double >
258 operator () (tuple< ns3::Ptr<ns3::ndn::Face>, uint32_t,
double > a,
259 property_traits< EdgeWeights >::reference b)
const
261 if (a.get<0> () == 0)
262 return make_tuple (b.get<0> (), a.get<1> () + b.get<1> (), a.get<2> () + b.get<2> ());
264 return make_tuple (a.get<0> (), a.get<1> () + b.get<1> (), a.get<2> () + b.get<2> ());
269 struct property_traits< VertexIds >
272 typedef uint32_t value_type;
273 typedef uint32_t reference;
274 typedef ns3::Ptr< ns3::ndn::GlobalRouter > key_type;
275 typedef readable_property_map_tag category;
281 const NdnGlobalRouterGraph &g)
283 return EdgeWeights (g);
289 const NdnGlobalRouterGraph &g)
291 return VertexIds (g);
294 template<
class M,
class K,
class V>
296 put (reference_wrapper< M > mapp,
306 get (
const boost::VertexIds&, ns3::Ptr<ns3::ndn::GlobalRouter> &gr)
311 inline property_traits< EdgeWeights >::reference
314 if (edge.get<1> () == 0)
315 return property_traits< EdgeWeights >::reference (0, 0, 0.0);
318 ns3::Ptr<ns3::ndn::Limits> limits = edge.get<1> ()->GetObject<ns3::ndn::Limits> ();
322 delay = limits->GetLinkDelay ();
324 return property_traits< EdgeWeights >::reference (edge.get<1> (), edge.get<1> ()->GetMetric (), delay);
328 struct PredecessorsMap :
329 public std::map< ns3::Ptr< ns3::ndn::GlobalRouter >, ns3::Ptr< ns3::ndn::GlobalRouter > >
334 struct property_traits< reference_wrapper<PredecessorsMap> >
337 typedef ns3::Ptr< ns3::ndn::GlobalRouter > value_type;
338 typedef ns3::Ptr< ns3::ndn::GlobalRouter > reference;
339 typedef ns3::Ptr< ns3::ndn::GlobalRouter > key_type;
340 typedef read_write_property_map_tag category;
344 struct DistancesMap :
345 public std::map< ns3::Ptr< ns3::ndn::GlobalRouter >, tuple< ns3::Ptr<ns3::ndn::Face>, uint32_t, double > >
350 struct property_traits< reference_wrapper<DistancesMap> >
353 typedef tuple< ns3::Ptr<ns3::ndn::Face>, uint32_t,
double > value_type;
354 typedef tuple< ns3::Ptr<ns3::ndn::Face>, uint32_t,
double > reference;
355 typedef ns3::Ptr< ns3::ndn::GlobalRouter > key_type;
356 typedef read_write_property_map_tag category;
359 inline tuple< ns3::Ptr<ns3::ndn::Face>, uint32_t,
double >
360 get (DistancesMap &map, ns3::Ptr<ns3::ndn::GlobalRouter> key)
362 boost::DistancesMap::iterator i = map.find (key);
364 return tuple< ns3::Ptr<ns3::ndn::Face>, uint32_t,
double > (0, std::numeric_limits<uint32_t>::max (), 0.0);
373 #endif // BOOST_GRAPH_NDN_GLOBAL_ROUTING_HELPER_H
Class representing global router interface for ndnSIM.
boost::tuple< Ptr< GlobalRouter >, Ptr< Face >, Ptr< GlobalRouter > > Incidency
Graph edge.