NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ndn-strategy-choice-helper.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
20 #ifndef NDN_STRATEGY_CHOICE_HELPER_H
21 #define NDN_STRATEGY_CHOICE_HELPER_H
22 
23 #include "ns3/ndnSIM/model/ndn-common.hpp"
24 
25 #include "ns3/node.h"
26 #include "ns3/ptr.h"
27 #include "ns3/node-container.h"
28 
29 #include "ns3/ndnSIM/model/ndn-l3-protocol.hpp"
30 #include "ns3/ndnSIM/NFD/daemon/mgmt/strategy-choice-manager.hpp"
31 #include "ns3/ndnSIM/NFD/daemon/fw/available-strategies.hpp"
32 
33 namespace ndn {
34 namespace nfd {
35 class ControlParameters;
36 } // namespace nfd
37 } // namespace ndn
38 
39 namespace nfd {
40 namespace fw {
41 class Strategy;
42 } // namespace fw
43 } // namespace nfd
44 
45 
46 namespace ns3 {
47 namespace ndn {
48 
49 using ::ndn::nfd::ControlParameters;
50 
60 public:
61  static void
62  Install(const NodeContainer& c, const Name& namePrefix, const Name& strategy);
63 
64  static void
65  Install(Ptr<Node> node, const Name& namePrefix, const Name& strategy);
66 
67  static void
68  InstallAll(const Name& namePrefix, const Name& strategy);
69 
70  template<class Strategy>
71  static void
72  Install(Ptr<Node> node, const Name& namePrefix);
73 
74  template<class Strategy>
75  static void
76  Install(const NodeContainer& c, const Name& namePrefix);
77 
78  template<class Strategy>
79  static void
80  InstallAll(const Name& namePrefix);
81 
82 private:
83  static void
84  sendCommand(const ControlParameters& parameters, Ptr<Node> node);
85 };
86 
87 template<class Strategy>
88 inline void
89 StrategyChoiceHelper::Install(Ptr<Node> node, const Name& namePrefix)
90 {
91  Ptr<L3Protocol> l3Protocol = node->GetObject<L3Protocol>();
92  NS_ASSERT(l3Protocol != nullptr);
93  NS_ASSERT(l3Protocol->getForwarder() != nullptr);
94 
95  nfd::Forwarder& forwarder = *l3Protocol->getForwarder();
96  nfd::StrategyChoice& strategyChoice = forwarder.getStrategyChoice();
97 
98  if (!strategyChoice.hasStrategy(Strategy::STRATEGY_NAME)) {
99  strategyChoice.install(make_shared<Strategy>(ref(forwarder)));
100  }
101 
102  Install(node, namePrefix, Strategy::STRATEGY_NAME);
103 }
104 
105 template<class Strategy>
106 inline void
107 StrategyChoiceHelper::Install(const NodeContainer& c, const Name& namePrefix)
108 {
109  for (NodeContainer::Iterator i = c.Begin(); i != c.End(); ++i) {
110  Install<Strategy>(*i, namePrefix);
111  }
112 }
113 
114 template<class Strategy>
115 inline void
117 {
118  Install<Strategy>(NodeContainer::GetGlobal(), namePrefix);
119 }
120 
121 } // namespace ndn
122 } // namespace ns3
123 
124 #endif // NDN_STRATEGY_CHOICE_HELPER_H
represents the Strategy Choice table
NFD Strategy Choice Helper (FIB) helper.
main class of NFD
Definition: forwarder.hpp:54
bool install(shared_ptr< fw::Strategy > strategy)
install a strategy
bool hasStrategy(const Name &strategyName, bool isExact=false) const
determines if a strategy is installed
Implementation network-layer of NDN stack.
represents a forwarding strategy
Definition: strategy.hpp:37
static void Install(const NodeContainer &c, const Name &namePrefix, const Name &strategy)
static void InstallAll(const Name &namePrefix, const Name &strategy)