NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
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 NDNSIM_HELPER_NDN_STRATEGY_CHOICE_HELPER_HPP
21 #define NDNSIM_HELPER_NDN_STRATEGY_CHOICE_HELPER_HPP
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/forwarder.hpp"
32 #include "ns3/ndnSIM/NFD/daemon/table/strategy-choice.hpp"
33 
34 namespace ndn {
35 namespace nfd {
36 class ControlParameters;
37 } // namespace nfd
38 } // namespace ndn
39 
40 namespace nfd {
41 namespace fw {
42 class Strategy;
43 } // namespace fw
44 } // namespace nfd
45 
46 
47 namespace ns3 {
48 namespace ndn {
49 
51 
61 {
62 public:
66  static void
67  Install(Ptr<Node> node, const Name& namePrefix, const Name& strategy);
68 
73  static void
74  Install(const NodeContainer& c, const Name& namePrefix, const Name& strategy);
75 
79  static void
80  InstallAll(const Name& namePrefix, const Name& strategy);
81 
86  template<class Strategy>
87  static void
88  Install(Ptr<Node> node, const Name& namePrefix);
89 
94  template<class Strategy>
95  static void
96  Install(const NodeContainer& c, const Name& namePrefix);
97 
102  template<class Strategy>
103  static void
104  InstallAll(const Name& namePrefix);
105 
106 private:
107  static void
108  sendCommand(const ControlParameters& parameters, Ptr<Node> node);
109 };
110 
111 template<class Strategy>
112 inline void
113 StrategyChoiceHelper::Install(Ptr<Node> node, const Name& namePrefix)
114 {
115  Ptr<L3Protocol> l3Protocol = node->GetObject<L3Protocol>();
116  NS_ASSERT(l3Protocol != nullptr);
117  NS_ASSERT(l3Protocol->getForwarder() != nullptr);
118 
119  nfd::Forwarder& forwarder = *l3Protocol->getForwarder();
120  nfd::StrategyChoice& strategyChoice = forwarder.getStrategyChoice();
121 
122  if (!strategyChoice.hasStrategy(Strategy::STRATEGY_NAME)) {
123  strategyChoice.install(make_shared<Strategy>(ref(forwarder)));
124  }
125 
126  Install(node, namePrefix, Strategy::STRATEGY_NAME);
127 }
128 
129 template<class Strategy>
130 inline void
131 StrategyChoiceHelper::Install(const NodeContainer& c, const Name& namePrefix)
132 {
133  for (NodeContainer::Iterator i = c.Begin(); i != c.End(); ++i) {
134  Install<Strategy>(*i, namePrefix);
135  }
136 }
137 
138 template<class Strategy>
139 inline void
140 StrategyChoiceHelper::InstallAll(const Name& namePrefix)
141 {
142  Install<Strategy>(NodeContainer::GetGlobal(), namePrefix);
143 }
144 
145 } // namespace ndn
146 } // namespace ns3
147 
148 #endif // NDNSIM_HELPER_NDN_STRATEGY_CHOICE_HELPER_HPP
Copyright (c) 2011-2015 Regents of the University of California.
represents the Strategy Choice table
represents parameters in a ControlCommand request or response
bool hasStrategy(const Name &strategyName, bool isExact=false) const
determines if a strategy is installed
NFD Strategy Choice Helper (FIB) helper.
main class of NFD
Definition: forwarder.hpp:55
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
Copyright (c) 2011-2015 Regents of the University of California.
bool install(shared_ptr< fw::Strategy > strategy)
install a strategy
Implementation network-layer of NDN stack.
represents a forwarding strategy
Definition: strategy.hpp:38