Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2012 University of California, Los Angeles |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation; |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | * |
| 18 | * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 19 | */ |
| 20 | |
| 21 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 22 | #ifndef BOOST_GRAPH_NDN_GLOBAL_ROUTING_HELPER_H |
| 23 | #define BOOST_GRAPH_NDN_GLOBAL_ROUTING_HELPER_H |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 24 | |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 25 | /// @cond include_hidden |
| 26 | |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 27 | #include <boost/graph/graph_traits.hpp> |
| 28 | #include <boost/graph/properties.hpp> |
Alexander Afanasyev | a5abcd9 | 2012-04-17 13:34:43 -0700 | [diff] [blame] | 29 | #include <boost/ref.hpp> |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 30 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 31 | #include "ns3/ndn-face.h" |
Alexander Afanasyev | a8f5d88 | 2012-11-09 14:22:48 -0800 | [diff] [blame] | 32 | #include "ns3/ndn-limits.h" |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 33 | #include "ns3/node-list.h" |
| 34 | #include "ns3/channel-list.h" |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 35 | #include "../model/ndn-global-router.h" |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 36 | #include <list> |
| 37 | #include <map> |
| 38 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 39 | namespace boost { |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 40 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 41 | class NdnGlobalRouterGraph |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 42 | { |
| 43 | public: |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 44 | typedef ns3::Ptr< ns3::ndn::GlobalRouter > Vertice; |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 45 | typedef uint16_t edge_property_type; |
| 46 | typedef uint32_t vertex_property_type; |
| 47 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 48 | NdnGlobalRouterGraph () |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 49 | { |
| 50 | for (ns3::NodeList::Iterator node = ns3::NodeList::Begin (); node != ns3::NodeList::End (); node++) |
| 51 | { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 52 | ns3::Ptr<ns3::ndn::GlobalRouter> gr = (*node)->GetObject<ns3::ndn::GlobalRouter> (); |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 53 | if (gr != 0) |
| 54 | m_vertices.push_back (gr); |
| 55 | } |
| 56 | |
| 57 | for (ns3::ChannelList::Iterator channel = ns3::ChannelList::Begin (); channel != ns3::ChannelList::End (); channel++) |
| 58 | { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 59 | ns3::Ptr<ns3::ndn::GlobalRouter> gr = (*channel)->GetObject<ns3::ndn::GlobalRouter> (); |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 60 | if (gr != 0) |
| 61 | m_vertices.push_back (gr); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | const std::list< Vertice > & |
| 66 | GetVertices () const |
| 67 | { |
| 68 | return m_vertices; |
| 69 | } |
| 70 | |
| 71 | public: |
| 72 | std::list< Vertice > m_vertices; |
| 73 | }; |
| 74 | |
| 75 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 76 | class ndn_global_router_graph_category : |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 77 | public virtual vertex_list_graph_tag, |
| 78 | public virtual incidence_graph_tag |
| 79 | { |
| 80 | }; |
| 81 | |
| 82 | |
| 83 | template<> |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 84 | struct graph_traits< NdnGlobalRouterGraph > |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 85 | { |
| 86 | // Graph concept |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 87 | typedef NdnGlobalRouterGraph::Vertice vertex_descriptor; |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 88 | typedef ns3::ndn::GlobalRouter::Incidency edge_descriptor; |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 89 | typedef directed_tag directed_category; |
| 90 | typedef disallow_parallel_edge_tag edge_parallel_category; |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 91 | typedef ndn_global_router_graph_category traversal_category; |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 92 | |
| 93 | // VertexList concept |
| 94 | typedef std::list< vertex_descriptor >::const_iterator vertex_iterator; |
| 95 | typedef size_t vertices_size_type; |
| 96 | |
| 97 | // AdjacencyGraph concept |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 98 | typedef ns3::ndn::GlobalRouter::IncidencyList::iterator out_edge_iterator; |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 99 | typedef size_t degree_size_type; |
| 100 | |
| 101 | // typedef size_t edges_size_type; |
| 102 | }; |
| 103 | |
| 104 | } // namespace boost |
| 105 | |
| 106 | namespace boost |
| 107 | { |
| 108 | |
| 109 | inline |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 110 | graph_traits< NdnGlobalRouterGraph >::vertex_descriptor |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 111 | source( |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 112 | graph_traits< NdnGlobalRouterGraph >::edge_descriptor e, |
| 113 | const NdnGlobalRouterGraph& g) |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 114 | { |
| 115 | return e.get<0> (); |
| 116 | } |
| 117 | |
| 118 | inline |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 119 | graph_traits< NdnGlobalRouterGraph >::vertex_descriptor |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 120 | target( |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 121 | graph_traits< NdnGlobalRouterGraph >::edge_descriptor e, |
| 122 | const NdnGlobalRouterGraph& g) |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 123 | { |
| 124 | return e.get<2> (); |
| 125 | } |
| 126 | |
| 127 | inline |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 128 | std::pair< graph_traits< NdnGlobalRouterGraph >::vertex_iterator, |
| 129 | graph_traits< NdnGlobalRouterGraph >::vertex_iterator > |
| 130 | vertices (const NdnGlobalRouterGraph&g) |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 131 | { |
| 132 | return make_pair (g.GetVertices ().begin (), g.GetVertices ().end ()); |
| 133 | } |
| 134 | |
| 135 | inline |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 136 | graph_traits< NdnGlobalRouterGraph >::vertices_size_type |
| 137 | num_vertices(const NdnGlobalRouterGraph &g) |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 138 | { |
| 139 | return g.GetVertices ().size (); |
| 140 | } |
| 141 | |
| 142 | |
| 143 | inline |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 144 | std::pair< graph_traits< NdnGlobalRouterGraph >::out_edge_iterator, |
| 145 | graph_traits< NdnGlobalRouterGraph >::out_edge_iterator > |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 146 | out_edges( |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 147 | graph_traits< NdnGlobalRouterGraph >::vertex_descriptor u, |
| 148 | const NdnGlobalRouterGraph& g) |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 149 | { |
| 150 | return std::make_pair(u->GetIncidencies ().begin (), |
| 151 | u->GetIncidencies ().end ()); |
| 152 | } |
| 153 | |
| 154 | inline |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 155 | graph_traits< NdnGlobalRouterGraph >::degree_size_type |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 156 | out_degree( |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 157 | graph_traits< NdnGlobalRouterGraph >::vertex_descriptor u, |
| 158 | const NdnGlobalRouterGraph& g) |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 159 | { |
| 160 | return u->GetIncidencies ().size (); |
| 161 | } |
| 162 | |
| 163 | |
| 164 | ////////////////////////////////////////////////////////////// |
| 165 | // Property maps |
| 166 | |
| 167 | struct EdgeWeights |
| 168 | { |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 169 | EdgeWeights (const NdnGlobalRouterGraph &graph) |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 170 | : m_graph (graph) |
| 171 | { |
| 172 | } |
| 173 | |
| 174 | private: |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 175 | const NdnGlobalRouterGraph &m_graph; |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 176 | }; |
| 177 | |
| 178 | |
| 179 | struct VertexIds |
| 180 | { |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 181 | VertexIds (const NdnGlobalRouterGraph &graph) |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 182 | : m_graph (graph) |
| 183 | { |
| 184 | } |
| 185 | |
| 186 | private: |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 187 | const NdnGlobalRouterGraph &m_graph; |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 188 | }; |
| 189 | |
| 190 | template<> |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 191 | struct property_map< NdnGlobalRouterGraph, edge_weight_t > |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 192 | { |
| 193 | typedef const EdgeWeights const_type; |
| 194 | typedef EdgeWeights type; |
| 195 | }; |
| 196 | |
| 197 | template<> |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 198 | struct property_map< NdnGlobalRouterGraph, vertex_index_t > |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 199 | { |
| 200 | typedef const VertexIds const_type; |
| 201 | typedef VertexIds type; |
| 202 | }; |
| 203 | |
| 204 | |
| 205 | template<> |
| 206 | struct property_traits< EdgeWeights > |
| 207 | { |
| 208 | // Metric property map |
Alexander Afanasyev | a8f5d88 | 2012-11-09 14:22:48 -0800 | [diff] [blame] | 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; |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 211 | typedef ns3::ndn::GlobalRouter::Incidency key_type; |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 212 | typedef readable_property_map_tag category; |
| 213 | }; |
| 214 | |
Alexander Afanasyev | a8f5d88 | 2012-11-09 14:22:48 -0800 | [diff] [blame] | 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); |
Alexander Afanasyev | a5abcd9 | 2012-04-17 13:34:43 -0700 | [diff] [blame] | 217 | |
| 218 | struct WeightCompare : |
| 219 | public std::binary_function<property_traits< EdgeWeights >::reference, |
| 220 | property_traits< EdgeWeights >::reference, |
| 221 | bool> |
| 222 | { |
| 223 | bool |
Alexander Afanasyev | 52a09bd | 2013-07-29 18:49:01 -0700 | [diff] [blame] | 224 | operator () (tuple< ns3::Ptr<ns3::ndn::Face>, uint32_t, double > a, |
| 225 | tuple< ns3::Ptr<ns3::ndn::Face>, uint32_t, double > b) const |
Alexander Afanasyev | a5abcd9 | 2012-04-17 13:34:43 -0700 | [diff] [blame] | 226 | { |
| 227 | return a.get<1> () < b.get<1> (); |
| 228 | } |
| 229 | |
| 230 | bool |
| 231 | operator () (property_traits< EdgeWeights >::reference a, |
| 232 | uint32_t b) const |
| 233 | { |
| 234 | return a.get<1> () < b; |
| 235 | } |
| 236 | |
| 237 | bool |
| 238 | operator () (uint32_t a, |
| 239 | uint32_t b) const |
| 240 | { |
| 241 | return a < b; |
| 242 | } |
| 243 | |
| 244 | }; |
| 245 | |
| 246 | struct WeightCombine : |
| 247 | public std::binary_function<uint32_t, |
| 248 | property_traits< EdgeWeights >::reference, |
| 249 | uint32_t> |
| 250 | { |
| 251 | uint32_t |
| 252 | operator () (uint32_t a, property_traits< EdgeWeights >::reference b) const |
| 253 | { |
| 254 | return a + b.get<1> (); |
| 255 | } |
| 256 | |
Alexander Afanasyev | a8f5d88 | 2012-11-09 14:22:48 -0800 | [diff] [blame] | 257 | tuple< ns3::Ptr<ns3::ndn::Face>, uint32_t, double > |
| 258 | operator () (tuple< ns3::Ptr<ns3::ndn::Face>, uint32_t, double > a, |
Alexander Afanasyev | a5abcd9 | 2012-04-17 13:34:43 -0700 | [diff] [blame] | 259 | property_traits< EdgeWeights >::reference b) const |
| 260 | { |
| 261 | if (a.get<0> () == 0) |
Alexander Afanasyev | a8f5d88 | 2012-11-09 14:22:48 -0800 | [diff] [blame] | 262 | return make_tuple (b.get<0> (), a.get<1> () + b.get<1> (), a.get<2> () + b.get<2> ()); |
Alexander Afanasyev | a5abcd9 | 2012-04-17 13:34:43 -0700 | [diff] [blame] | 263 | else |
Alexander Afanasyev | a8f5d88 | 2012-11-09 14:22:48 -0800 | [diff] [blame] | 264 | return make_tuple (a.get<0> (), a.get<1> () + b.get<1> (), a.get<2> () + b.get<2> ()); |
Alexander Afanasyev | a5abcd9 | 2012-04-17 13:34:43 -0700 | [diff] [blame] | 265 | } |
| 266 | }; |
| 267 | |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 268 | template<> |
| 269 | struct property_traits< VertexIds > |
| 270 | { |
| 271 | // Metric property map |
| 272 | typedef uint32_t value_type; |
| 273 | typedef uint32_t reference; |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 274 | typedef ns3::Ptr< ns3::ndn::GlobalRouter > key_type; |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 275 | typedef readable_property_map_tag category; |
| 276 | }; |
| 277 | |
| 278 | |
| 279 | inline EdgeWeights |
| 280 | get(edge_weight_t, |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 281 | const NdnGlobalRouterGraph &g) |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 282 | { |
| 283 | return EdgeWeights (g); |
| 284 | } |
| 285 | |
| 286 | |
| 287 | inline VertexIds |
| 288 | get(vertex_index_t, |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 289 | const NdnGlobalRouterGraph &g) |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 290 | { |
| 291 | return VertexIds (g); |
| 292 | } |
| 293 | |
Alexander Afanasyev | a5abcd9 | 2012-04-17 13:34:43 -0700 | [diff] [blame] | 294 | template<class M, class K, class V> |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 295 | inline void |
Alexander Afanasyev | a5abcd9 | 2012-04-17 13:34:43 -0700 | [diff] [blame] | 296 | put (reference_wrapper< M > mapp, |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 297 | K a, V p) |
| 298 | { |
Alexander Afanasyev | a5abcd9 | 2012-04-17 13:34:43 -0700 | [diff] [blame] | 299 | mapp.get ()[a] = p; |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | // void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 303 | // put (cref< std::map< ns3::Ptr<ns3::ndn::GlobalRouter>, ns3::Ptr<ns3::ndn::GlobalRouter> > > map, |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 304 | |
Alexander Afanasyev | b2a11fe | 2012-12-12 11:38:39 -0800 | [diff] [blame] | 305 | inline uint32_t |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 306 | get (const boost::VertexIds&, ns3::Ptr<ns3::ndn::GlobalRouter> &gr) |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 307 | { |
| 308 | return gr->GetId (); |
| 309 | } |
| 310 | |
Alexander Afanasyev | a5abcd9 | 2012-04-17 13:34:43 -0700 | [diff] [blame] | 311 | inline property_traits< EdgeWeights >::reference |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 312 | get(const boost::EdgeWeights&, ns3::ndn::GlobalRouter::Incidency &edge) |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 313 | { |
| 314 | if (edge.get<1> () == 0) |
Alexander Afanasyev | a8f5d88 | 2012-11-09 14:22:48 -0800 | [diff] [blame] | 315 | return property_traits< EdgeWeights >::reference (0, 0, 0.0); |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 316 | else |
Alexander Afanasyev | a8f5d88 | 2012-11-09 14:22:48 -0800 | [diff] [blame] | 317 | { |
| 318 | ns3::Ptr<ns3::ndn::Limits> limits = edge.get<1> ()->GetObject<ns3::ndn::Limits> (); |
| 319 | double delay = 0.0; |
| 320 | if (limits != 0) // valid limits object |
| 321 | { |
| 322 | delay = limits->GetLinkDelay (); |
| 323 | } |
| 324 | return property_traits< EdgeWeights >::reference (edge.get<1> (), edge.get<1> ()->GetMetric (), delay); |
| 325 | } |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 326 | } |
| 327 | |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 328 | struct PredecessorsMap : |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 329 | public std::map< ns3::Ptr< ns3::ndn::GlobalRouter >, ns3::Ptr< ns3::ndn::GlobalRouter > > |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 330 | { |
| 331 | }; |
| 332 | |
| 333 | template<> |
Alexander Afanasyev | a5abcd9 | 2012-04-17 13:34:43 -0700 | [diff] [blame] | 334 | struct property_traits< reference_wrapper<PredecessorsMap> > |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 335 | { |
| 336 | // Metric property map |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 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; |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 340 | typedef read_write_property_map_tag category; |
| 341 | }; |
| 342 | |
| 343 | |
| 344 | struct DistancesMap : |
Alexander Afanasyev | a8f5d88 | 2012-11-09 14:22:48 -0800 | [diff] [blame] | 345 | public std::map< ns3::Ptr< ns3::ndn::GlobalRouter >, tuple< ns3::Ptr<ns3::ndn::Face>, uint32_t, double > > |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 346 | { |
| 347 | }; |
| 348 | |
| 349 | template<> |
Alexander Afanasyev | a5abcd9 | 2012-04-17 13:34:43 -0700 | [diff] [blame] | 350 | struct property_traits< reference_wrapper<DistancesMap> > |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 351 | { |
| 352 | // Metric property map |
Alexander Afanasyev | a8f5d88 | 2012-11-09 14:22:48 -0800 | [diff] [blame] | 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; |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 355 | typedef ns3::Ptr< ns3::ndn::GlobalRouter > key_type; |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 356 | typedef read_write_property_map_tag category; |
| 357 | }; |
| 358 | |
Alexander Afanasyev | a8f5d88 | 2012-11-09 14:22:48 -0800 | [diff] [blame] | 359 | inline tuple< ns3::Ptr<ns3::ndn::Face>, uint32_t, double > |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 360 | get (DistancesMap &map, ns3::Ptr<ns3::ndn::GlobalRouter> key) |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 361 | { |
| 362 | boost::DistancesMap::iterator i = map.find (key); |
| 363 | if (i == map.end ()) |
Alexander Afanasyev | a8f5d88 | 2012-11-09 14:22:48 -0800 | [diff] [blame] | 364 | return tuple< ns3::Ptr<ns3::ndn::Face>, uint32_t, double > (0, std::numeric_limits<uint32_t>::max (), 0.0); |
Alexander Afanasyev | ad3757f | 2012-04-17 10:27:59 -0700 | [diff] [blame] | 365 | else |
| 366 | return i->second; |
| 367 | } |
| 368 | |
| 369 | } // namespace boost |
| 370 | |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 371 | /// @endcond |
| 372 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 373 | #endif // BOOST_GRAPH_NDN_GLOBAL_ROUTING_HELPER_H |