NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
tables-config-section.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
27 
28 namespace nfd {
29 
30 const size_t TablesConfigSection::DEFAULT_CS_MAX_PACKETS = 65536;
31 
33  : m_forwarder(forwarder)
34  , m_isConfigured(false)
35 {
36 }
37 
38 void
40 {
41  configFile.addSectionHandler("tables",
42  bind(&TablesConfigSection::processConfig, this, _1, _2));
43 }
44 
45 void
47 {
48  if (m_isConfigured) {
49  return;
50  }
51 
52  m_forwarder.getCs().setLimit(DEFAULT_CS_MAX_PACKETS);
53  m_forwarder.setUnsolicitedDataPolicy(make_unique<fw::DefaultUnsolicitedDataPolicy>());
54 
55  m_isConfigured = true;
56 }
57 
58 void
59 TablesConfigSection::processConfig(const ConfigSection& section, bool isDryRun)
60 {
61  typedef boost::optional<const ConfigSection&> OptionalNode;
62 
63  size_t nCsMaxPackets = DEFAULT_CS_MAX_PACKETS;
64  OptionalNode csMaxPacketsNode = section.get_child_optional("cs_max_packets");
65  if (csMaxPacketsNode) {
66  nCsMaxPackets = ConfigFile::parseNumber<size_t>(*csMaxPacketsNode, "cs_max_packets", "tables");
67  }
68 
69  unique_ptr<fw::UnsolicitedDataPolicy> unsolicitedDataPolicy;
70  OptionalNode unsolicitedDataPolicyNode = section.get_child_optional("cs_unsolicited_policy");
71  if (unsolicitedDataPolicyNode) {
72  std::string policyKey = unsolicitedDataPolicyNode->get_value<std::string>();
73  unsolicitedDataPolicy = fw::UnsolicitedDataPolicy::create(policyKey);
74  if (unsolicitedDataPolicy == nullptr) {
75  BOOST_THROW_EXCEPTION(ConfigFile::Error(
76  "Unknown cs_unsolicited_policy \"" + policyKey + "\" in \"tables\" section"));
77  }
78  }
79  else {
80  unsolicitedDataPolicy = make_unique<fw::DefaultUnsolicitedDataPolicy>();
81  }
82 
83  OptionalNode strategyChoiceSection = section.get_child_optional("strategy_choice");
84  if (strategyChoiceSection) {
85  processStrategyChoiceSection(*strategyChoiceSection, isDryRun);
86  }
87 
88  OptionalNode networkRegionSection = section.get_child_optional("network_region");
89  if (networkRegionSection) {
90  processNetworkRegionSection(*networkRegionSection, isDryRun);
91  }
92 
93  if (isDryRun) {
94  return;
95  }
96 
97  m_forwarder.getCs().setLimit(nCsMaxPackets);
98 
99  m_forwarder.setUnsolicitedDataPolicy(std::move(unsolicitedDataPolicy));
100 
101  m_isConfigured = true;
102 }
103 
104 void
105 TablesConfigSection::processStrategyChoiceSection(const ConfigSection& section, bool isDryRun)
106 {
107  StrategyChoice& sc = m_forwarder.getStrategyChoice();
108 
109  std::map<Name, Name> choices;
110 
111  for (const auto& prefixAndStrategy : section) {
112  Name prefix(prefixAndStrategy.first);
113  Name strategy(prefixAndStrategy.second.get_value<std::string>());
114 
115  if (!sc.hasStrategy(strategy)) {
116  BOOST_THROW_EXCEPTION(ConfigFile::Error(
117  "Unknown strategy \"" + prefixAndStrategy.second.get_value<std::string>() +
118  "\" for prefix \"" + prefix.toUri() + "\" in \"strategy_choice\" section"));
119  }
120 
121  if (!choices.emplace(prefix, strategy).second) {
122  BOOST_THROW_EXCEPTION(ConfigFile::Error(
123  "Duplicate strategy choice for prefix \"" + prefix.toUri() +
124  "\" in \"strategy_choice\" section"));
125  }
126  }
127 
128  if (isDryRun) {
129  return;
130  }
131 
132  for (const auto& prefixAndStrategy : choices) {
133  if (!sc.insert(prefixAndStrategy.first, prefixAndStrategy.second)) {
134  BOOST_THROW_EXCEPTION(ConfigFile::Error(
135  "Failed to set strategy \"" + prefixAndStrategy.second.toUri() + "\" for "
136  "prefix \"" + prefixAndStrategy.first.toUri() + "\" in \"strategy_choicev\""));
137  }
138  }
139 }
140 
141 void
142 TablesConfigSection::processNetworkRegionSection(const ConfigSection& section, bool isDryRun)
143 {
144  if (isDryRun) {
145  return;
146  }
147 
148  NetworkRegionTable& nrt = m_forwarder.getNetworkRegionTable();
149  nrt.clear();
150  for (const auto& pair : section) {
151  Name region(pair.first);
152  nrt.insert(region);
153  }
154 }
155 
156 } // namespace nfd
bool hasStrategy(const Name &strategyName, bool isExact=false) const
determines if a strategy is installed
std::string toUri() const
Encode this name as a URI.
Definition: name.cpp:171
configuration file parsing utility
Definition: config-file.hpp:50
main class of NFD
Definition: forwarder.hpp:54
void ensureConfigured()
apply default configuration, if tables section was omitted in configuration file
stores a collection of producer region names
StrategyChoice & getStrategyChoice()
Definition: forwarder.hpp:161
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
void addSectionHandler(const std::string &sectionName, ConfigSectionHandler subscriber)
setup notification of configuration file sections
Definition: config-file.cpp:79
void setLimit(size_t nMaxPackets)
changes capacity (in number of packets)
Definition: cs.cpp:61
boost::property_tree::ptree ConfigSection
Name abstraction to represent an absolute name.
Definition: name.hpp:46
bool insert(const Name &prefix, const Name &strategyName)
set strategy of prefix to be strategyName
represents the Strategy Choice table
NetworkRegionTable & getNetworkRegionTable()
Definition: forwarder.hpp:173
void setConfigFile(ConfigFile &configFile)
static unique_ptr< UnsolicitedDataPolicy > create(const std::string &key)
void setUnsolicitedDataPolicy(unique_ptr< fw::UnsolicitedDataPolicy > policy)
Definition: forwarder.hpp:102
TablesConfigSection(Forwarder &forwarder)