22 #pragma clang diagnostic push 
   23 #pragma clang diagnostic ignored "-Wunused-variable" 
   24 #pragma clang diagnostic ignored "-Wunneeded-internal-declaration" 
   27 #include "ndn-global-routing-helper.h" 
   29 #include "ns3/ndn-l3-protocol.h" 
   30 #include "../model/ndn-net-device-face.h" 
   31 #include "../model/ndn-global-router.h" 
   32 #include "ns3/ndn-name.h" 
   33 #include "ns3/ndn-fib.h" 
   36 #include "ns3/node-container.h" 
   37 #include "ns3/net-device.h" 
   38 #include "ns3/channel.h" 
   40 #include "ns3/assert.h" 
   41 #include "ns3/names.h" 
   42 #include "ns3/node-list.h" 
   43 #include "ns3/channel-list.h" 
   44 #include "ns3/object-factory.h" 
   46 #include <boost/lexical_cast.hpp> 
   47 #include <boost/foreach.hpp> 
   48 #include <boost/concept/assert.hpp> 
   51 #include <boost/graph/dijkstra_shortest_paths.hpp> 
   53 #include "boost-graph-ndn-global-routing-helper.h" 
   57 NS_LOG_COMPONENT_DEFINE (
"ndn.GlobalRoutingHelper");
 
   60 using namespace boost;
 
   66 GlobalRoutingHelper::Install (Ptr<Node> node)
 
   68   NS_LOG_LOGIC (
"Node: " << node->GetId ());
 
   70   Ptr<L3Protocol> ndn = node->GetObject<
L3Protocol> ();
 
   71   NS_ASSERT_MSG (ndn != 0, 
"Cannot install GlobalRoutingHelper before Ndn is installed on a node");
 
   76       NS_LOG_DEBUG (
"GlobalRouter is already installed: " << gr);
 
   80   gr = CreateObject<GlobalRouter> ();
 
   81   node->AggregateObject (gr);
 
   83   for (uint32_t faceId = 0; faceId < ndn->GetNFaces (); faceId++)
 
   85       Ptr<NetDeviceFace> face = DynamicCast<NetDeviceFace> (ndn->GetFace (faceId));
 
   88       NS_LOG_DEBUG (
"Skipping non-netdevice face");
 
   92       Ptr<NetDevice> nd = face->GetNetDevice ();
 
   95       NS_LOG_DEBUG (
"Not a NetDevice associated with NetDeviceFace");
 
   99       Ptr<Channel> ch = nd->GetChannel ();
 
  103       NS_LOG_DEBUG (
"Channel is not associated with NetDevice");
 
  107       if (ch->GetNDevices () == 2) 
 
  109       for (uint32_t deviceId = 0; deviceId < ch->GetNDevices (); deviceId ++)
 
  111           Ptr<NetDevice> otherSide = ch->GetDevice (deviceId);
 
  112           if (nd == otherSide) 
continue;
 
  114           Ptr<Node> otherNode = otherSide->GetNode ();
 
  115           NS_ASSERT (otherNode != 0);
 
  117           Ptr<GlobalRouter> otherGr = otherNode->GetObject<
GlobalRouter> ();
 
  123           NS_ASSERT (otherGr != 0);
 
  124           gr->AddIncidency (face, otherGr);
 
  129       Ptr<GlobalRouter> grChannel = ch->GetObject<
GlobalRouter> ();
 
  142 GlobalRoutingHelper::Install (Ptr<Channel> channel)
 
  144   NS_LOG_LOGIC (
"Channel: " << channel->GetId ());
 
  146   Ptr<GlobalRouter> gr = channel->GetObject<
GlobalRouter> ();
 
  150   gr = CreateObject<GlobalRouter> ();
 
  151   channel->AggregateObject (gr);
 
  153   for (uint32_t deviceId = 0; deviceId < channel->GetNDevices (); deviceId ++)
 
  155       Ptr<NetDevice> dev = channel->GetDevice (deviceId);
 
  157       Ptr<Node> node = dev->GetNode ();
 
  158       NS_ASSERT (node != 0);
 
  160       Ptr<GlobalRouter> grOther = node->GetObject<
GlobalRouter> ();
 
  165       grOther = node->GetObject<GlobalRouter> ();
 
  166       NS_ASSERT (grOther != 0);
 
  168       gr->AddIncidency (0, grOther);
 
  173 GlobalRoutingHelper::Install (
const NodeContainer &nodes)
 
  175   for (NodeContainer::Iterator node = nodes.Begin ();
 
  176        node != nodes.End ();
 
  184 GlobalRoutingHelper::InstallAll ()
 
  186   Install (NodeContainer::GetGlobal ());
 
  191 GlobalRoutingHelper::AddOrigin (
const std::string &prefix, Ptr<Node> node)
 
  193   Ptr<GlobalRouter> gr = node->GetObject<
GlobalRouter> ();
 
  194   NS_ASSERT_MSG (gr != 0,
 
  195          "GlobalRouter is not installed on the node");
 
  197   Ptr<Name> name = Create<Name> (boost::lexical_cast<
Name> (prefix));
 
  198   gr->AddLocalPrefix (name);
 
  202 GlobalRoutingHelper::AddOrigins (
const std::string &prefix, 
const NodeContainer &nodes)
 
  204   for (NodeContainer::Iterator node = nodes.Begin ();
 
  205        node != nodes.End ();
 
  208       AddOrigin (prefix, *node);
 
  213 GlobalRoutingHelper::AddOrigin (
const std::string &prefix, 
const std::string &nodeName)
 
  215   Ptr<Node> node = Names::Find<Node> (nodeName);
 
  216   NS_ASSERT_MSG (node != 0, nodeName << 
"is not a Node");
 
  218   AddOrigin (prefix, node);
 
  222 GlobalRoutingHelper::AddOriginsForAll ()
 
  224   for (NodeList::Iterator node = NodeList::Begin (); node != NodeList::End (); node ++)
 
  226       Ptr<GlobalRouter> gr = (*node)->GetObject<
GlobalRouter> ();
 
  227       string name = Names::FindName (*node);
 
  229       if (gr != 0 && !name.empty ())
 
  231           AddOrigin (
"/"+name, *node);
 
  237 GlobalRoutingHelper::CalculateRoutes (
bool invalidatedRoutes)
 
  244   BOOST_CONCEPT_ASSERT(( VertexListGraphConcept< NdnGlobalRouterGraph > ));
 
  245   BOOST_CONCEPT_ASSERT(( IncidenceGraphConcept< NdnGlobalRouterGraph > ));
 
  247   NdnGlobalRouterGraph graph;
 
  253   for (NodeList::Iterator node = NodeList::Begin (); node != NodeList::End (); node++)
 
  255       Ptr<GlobalRouter> source = (*node)->GetObject<
GlobalRouter> ();
 
  258       NS_LOG_DEBUG (
"Node " << (*node)->GetId () << 
" does not export GlobalRouter interface");
 
  262       DistancesMap    distances;
 
  264       dijkstra_shortest_paths (graph, source,
 
  267                    distance_map (boost::ref(distances))
 
  269                    distance_inf (WeightInf)
 
  271                    distance_zero (WeightZero)
 
  273                    distance_compare (boost::WeightCompare ())
 
  275                    distance_combine (boost::WeightCombine ())
 
  280       Ptr<Fib>  fib  = source->GetObject<
Fib> ();
 
  281       if (invalidatedRoutes)
 
  285       NS_ASSERT (fib != 0);
 
  287       NS_LOG_DEBUG (
"Reachability from Node: " << source->GetObject<Node> ()->GetId ());
 
  288       for (DistancesMap::iterator i = distances.begin ();
 
  289        i != distances.end ();
 
  292       if (i->first == source)
 
  297           if (i->second.get<0> () == 0)
 
  303                   BOOST_FOREACH (
const Ptr<const Name> &prefix, i->first->GetLocalPrefixes ())
 
  305                       NS_LOG_DEBUG (
" prefix " << prefix << 
" reachable via face " << *i->second.get<0> ()
 
  306                                     << 
" with distance " << i->second.get<1> ()
 
  307                                     << 
" with delay " << i->second.get<2> ());
 
  309                       Ptr<fib::Entry> entry = fib->Add (prefix, i->second.get<0> (), i->second.get<1> ());
 
  310                       entry->SetRealDelayToProducer (i->second.get<0> (), Seconds (i->second.get<2> ()));
 
  312                       Ptr<Limits> faceLimits = i->second.get<0> ()->GetObject<Limits> ();
 
  314                       Ptr<Limits> fibLimits = entry->GetObject<
Limits> ();
 
  318                           fibLimits->
SetLimits (faceLimits->GetMaxRate (), 2 * i->second.get<2> () );
 
  319                           NS_LOG_DEBUG (
"Set limit for prefix " << *prefix << 
" " << faceLimits->GetMaxRate () << 
" / " <<
 
  320                                         2*i->second.get<2> () << 
"s (" << faceLimits->GetMaxRate () * 2 * i->second.get<2> () << 
")");
 
  330 GlobalRoutingHelper::CalculateAllPossibleRoutes (
bool invalidatedRoutes)
 
  337   BOOST_CONCEPT_ASSERT(( VertexListGraphConcept< NdnGlobalRouterGraph > ));
 
  338   BOOST_CONCEPT_ASSERT(( IncidenceGraphConcept< NdnGlobalRouterGraph > ));
 
  340   NdnGlobalRouterGraph graph;
 
  346   for (NodeList::Iterator node = NodeList::Begin (); node != NodeList::End (); node++)
 
  348       Ptr<GlobalRouter> source = (*node)->GetObject<
GlobalRouter> ();
 
  351       NS_LOG_DEBUG (
"Node " << (*node)->GetId () << 
" does not export GlobalRouter interface");
 
  355       Ptr<Fib>  fib  = source->GetObject<
Fib> ();
 
  356       if (invalidatedRoutes)
 
  360       NS_ASSERT (fib != 0);
 
  362       NS_LOG_DEBUG (
"===========");
 
  363       NS_LOG_DEBUG (
"Reachability from Node: " << source->GetObject<Node> ()->GetId () << 
" (" << Names::FindName (source->GetObject<Node> ()) << 
")");
 
  365       Ptr<L3Protocol> l3 = source->GetObject<
L3Protocol> ();
 
  369       std::vector<uint16_t> originalMetric (l3->GetNFaces ());
 
  370       for (uint32_t faceId = 0; faceId < l3->GetNFaces (); faceId++)
 
  372           originalMetric[faceId] = l3->GetFace (faceId)->GetMetric ();
 
  373           l3->GetFace (faceId)->SetMetric (std::numeric_limits<uint16_t>::max ()-1); 
 
  376       for (uint32_t enabledFaceId = 0; enabledFaceId < l3->GetNFaces (); enabledFaceId++)
 
  378           if (DynamicCast<ndn::NetDeviceFace> (l3->GetFace (enabledFaceId)) == 0)
 
  382           l3->GetFace (enabledFaceId)->SetMetric (originalMetric[enabledFaceId]);
 
  384           DistancesMap    distances;
 
  386           NS_LOG_DEBUG (
"-----------");
 
  388           dijkstra_shortest_paths (graph, source,
 
  391                                    distance_map (boost::ref(distances))
 
  393                                    distance_inf (WeightInf)
 
  395                                    distance_zero (WeightZero)
 
  397                                    distance_compare (boost::WeightCompare ())
 
  399                                    distance_combine (boost::WeightCombine ())
 
  404           for (DistancesMap::iterator i = distances.begin ();
 
  405                i != distances.end ();
 
  408               if (i->first == source)
 
  413                   if (i->second.get<0> () == 0)
 
  419                       BOOST_FOREACH (
const Ptr<const Name> &prefix, i->first->GetLocalPrefixes ())
 
  421                           NS_LOG_DEBUG (
" prefix " << *prefix << 
" reachable via face " << *i->second.get<0> ()
 
  422                                         << 
" with distance " << i->second.get<1> ()
 
  423                                         << 
" with delay " << i->second.get<2> ());
 
  425                           if (i->second.get<0> ()->GetMetric () == std::numeric_limits<uint16_t>::max ()-1)
 
  428                           Ptr<fib::Entry> entry = fib->Add (prefix, i->second.get<0> (), i->second.get<1> ());
 
  429                           entry->SetRealDelayToProducer (i->second.get<0> (), Seconds (i->second.get<2> ()));
 
  431                           Ptr<Limits> faceLimits = i->second.get<0> ()->GetObject<Limits> ();
 
  433                           Ptr<Limits> fibLimits = entry->GetObject<
Limits> ();
 
  437                               fibLimits->
SetLimits (faceLimits->GetMaxRate (), 2 * i->second.get<2> () );
 
  438                               NS_LOG_DEBUG (
"Set limit for prefix " << *prefix << 
" " << faceLimits->GetMaxRate () << 
" / " <<
 
  439                                             2*i->second.get<2> () << 
"s (" << faceLimits->GetMaxRate () * 2 * i->second.get<2> () << 
")");
 
  447           l3->GetFace (enabledFaceId)->SetMetric (std::numeric_limits<uint16_t>::max ()-1);
 
  451       for (uint32_t faceId = 0; faceId < l3->GetNFaces (); faceId++)
 
  453           l3->GetFace (faceId)->SetMetric (originalMetric[faceId]);
 
Abstract class to manage Interest limits. 
 
void AddIncidency(Ptr< Face > face, Ptr< GlobalRouter > ndn)
Add edge to the node. 
 
Implementation network-layer of NDN stack. 
 
virtual void InvalidateAll()=0
Invalidate all FIB entries. 
 
Class representing global router interface for ndnSIM. 
 
Class implementing FIB functionality. 
 
virtual void SetLimits(double rate, double delay)
Set limit for the number of outstanding interests.