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" 33 #include "ns3/node-list.h" 34 #include "ns3/channel-list.h" 41 class NdnGlobalRouterGraph {
43 typedef ns3::Ptr<ns3::ndn::GlobalRouter> Vertice;
44 typedef uint16_t edge_property_type;
45 typedef uint32_t vertex_property_type;
47 NdnGlobalRouterGraph()
49 for (ns3::NodeList::Iterator node = ns3::NodeList::Begin(); node != ns3::NodeList::End();
53 m_vertices.push_back(gr);
56 for (ns3::ChannelList::Iterator channel = ns3::ChannelList::Begin();
57 channel != ns3::ChannelList::End(); channel++) {
60 m_vertices.push_back(gr);
64 const std::list<Vertice>&
71 std::list<Vertice> m_vertices;
74 class ndn_global_router_graph_category :
public virtual vertex_list_graph_tag,
75 public virtual incidence_graph_tag {
79 struct graph_traits<NdnGlobalRouterGraph> {
81 typedef NdnGlobalRouterGraph::Vertice vertex_descriptor;
83 typedef directed_tag directed_category;
84 typedef disallow_parallel_edge_tag edge_parallel_category;
85 typedef ndn_global_router_graph_category traversal_category;
88 typedef std::list<vertex_descriptor>::const_iterator vertex_iterator;
89 typedef size_t vertices_size_type;
93 typedef size_t degree_size_type;
102 inline graph_traits<NdnGlobalRouterGraph>::vertex_descriptor
103 source(graph_traits<NdnGlobalRouterGraph>::edge_descriptor e,
const NdnGlobalRouterGraph& g)
105 return std::get<0>(e);
108 inline graph_traits<NdnGlobalRouterGraph>::vertex_descriptor
109 target(graph_traits<NdnGlobalRouterGraph>::edge_descriptor e,
const NdnGlobalRouterGraph& g)
111 return std::get<2>(e);
114 inline std::pair<graph_traits<NdnGlobalRouterGraph>::vertex_iterator,
115 graph_traits<NdnGlobalRouterGraph>::vertex_iterator>
116 vertices(
const NdnGlobalRouterGraph& g)
118 return make_pair(g.GetVertices().begin(), g.GetVertices().end());
121 inline graph_traits<NdnGlobalRouterGraph>::vertices_size_type
122 num_vertices(
const NdnGlobalRouterGraph& g)
124 return g.GetVertices().size();
127 inline std::pair<graph_traits<NdnGlobalRouterGraph>::out_edge_iterator,
128 graph_traits<NdnGlobalRouterGraph>::out_edge_iterator>
129 out_edges(graph_traits<NdnGlobalRouterGraph>::vertex_descriptor u,
const NdnGlobalRouterGraph& g)
131 return std::make_pair(u->GetIncidencies().begin(), u->GetIncidencies().end());
134 inline graph_traits<NdnGlobalRouterGraph>::degree_size_type
135 out_degree(graph_traits<NdnGlobalRouterGraph>::vertex_descriptor u,
const NdnGlobalRouterGraph& g)
137 return u->GetIncidencies().size();
144 EdgeWeights(
const NdnGlobalRouterGraph& graph)
150 const NdnGlobalRouterGraph& m_graph;
154 VertexIds(
const NdnGlobalRouterGraph& graph)
160 const NdnGlobalRouterGraph& m_graph;
164 struct property_map<NdnGlobalRouterGraph, edge_weight_t> {
165 typedef const EdgeWeights const_type;
166 typedef EdgeWeights type;
170 struct property_map<NdnGlobalRouterGraph, vertex_index_t> {
171 typedef const VertexIds const_type;
172 typedef VertexIds type;
176 struct property_traits<EdgeWeights> {
178 typedef std::tuple<std::shared_ptr<nfd::Face>, uint16_t,
double> value_type;
179 typedef std::tuple<std::shared_ptr<nfd::Face>, uint16_t,
double> reference;
181 typedef readable_property_map_tag category;
184 const property_traits<EdgeWeights>::value_type WeightZero(
nullptr, 0, 0.0);
185 const property_traits<EdgeWeights>::value_type
186 WeightInf(
nullptr, std::numeric_limits<uint16_t>::max(), 0.0);
188 struct WeightCompare :
public std::binary_function<property_traits<EdgeWeights>::reference,
189 property_traits<EdgeWeights>::reference, bool> {
191 operator()(std::tuple<std::shared_ptr<nfd::Face>, uint32_t,
double> a,
192 std::tuple<std::shared_ptr<nfd::Face>, uint32_t,
double> b)
const 194 return std::get<1>(a) < std::get<1>(b);
198 operator()(property_traits<EdgeWeights>::reference a, uint32_t b)
const 200 return std::get<1>(a) < b;
204 operator()(uint32_t a, uint32_t b)
const 211 :
public std::binary_function<uint32_t, property_traits<EdgeWeights>::reference, uint32_t> {
213 operator()(uint32_t a, property_traits<EdgeWeights>::reference b)
const 215 return a + std::get<1>(b);
218 std::tuple<std::shared_ptr<nfd::Face>, uint32_t,
double>
219 operator()(std::tuple<std::shared_ptr<nfd::Face>, uint32_t,
double> a,
220 property_traits<EdgeWeights>::reference b)
const 222 if (std::get<0>(a) ==
nullptr)
223 return std::make_tuple(std::get<0>(b), std::get<1>(a) + std::get<1>(b),
224 std::get<2>(a) + std::get<2>(b));
226 return std::make_tuple(std::get<0>(a), std::get<1>(a) + std::get<1>(b),
227 std::get<2>(a) + std::get<2>(b));
232 struct property_traits<VertexIds> {
234 typedef uint32_t value_type;
235 typedef uint32_t reference;
236 typedef ns3::Ptr<ns3::ndn::GlobalRouter> key_type;
237 typedef readable_property_map_tag category;
241 get(edge_weight_t,
const NdnGlobalRouterGraph& g)
243 return EdgeWeights(g);
247 get(vertex_index_t,
const NdnGlobalRouterGraph& g)
252 template<
class M,
class K,
class V>
254 put(reference_wrapper<M> mapp, K a, V p)
263 get(
const boost::VertexIds&, ns3::Ptr<ns3::ndn::GlobalRouter>& gr)
268 inline property_traits<EdgeWeights>::reference
271 if (std::get<1>(edge) == 0)
272 return property_traits<EdgeWeights>::reference(
nullptr, 0, 0.0);
274 return property_traits<EdgeWeights>::reference(std::get<1>(edge),
275 static_cast<uint16_t>(
276 std::get<1>(edge)->getMetric()),
281 struct PredecessorsMap
282 :
public std::map<ns3::Ptr<ns3::ndn::GlobalRouter>, ns3::Ptr<ns3::ndn::GlobalRouter>> {
286 struct property_traits<reference_wrapper<PredecessorsMap>> {
288 typedef ns3::Ptr<ns3::ndn::GlobalRouter> value_type;
289 typedef ns3::Ptr<ns3::ndn::GlobalRouter> reference;
290 typedef ns3::Ptr<ns3::ndn::GlobalRouter> key_type;
291 typedef read_write_property_map_tag category;
294 struct DistancesMap :
public std::map<ns3::Ptr<ns3::ndn::GlobalRouter>,
295 std::tuple<std::shared_ptr<nfd::Face>, uint32_t, double>> {
299 struct property_traits<reference_wrapper<DistancesMap>> {
301 typedef std::tuple<std::shared_ptr<nfd::Face>, uint32_t,
double> value_type;
302 typedef std::tuple<std::shared_ptr<nfd::Face>, uint32_t,
double> reference;
303 typedef ns3::Ptr<ns3::ndn::GlobalRouter> key_type;
304 typedef read_write_property_map_tag category;
311 class numeric_limits<
std::tuple<std::shared_ptr<nfd::Face>, uint32_t, double>>
314 typedef std::tuple<std::shared_ptr<nfd::Face>, uint32_t,
double> value;
318 return boost::WeightInf;
325 inline std::tuple<std::shared_ptr<nfd::Face>, uint32_t,
double>
326 get(DistancesMap& map, ns3::Ptr<ns3::ndn::GlobalRouter> key)
330 return std::tuple<std::shared_ptr<nfd::Face>, uint32_t,
331 double>(
nullptr, std::numeric_limits<uint32_t>::max(), 0.0);
340 #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.
Table::const_iterator iterator