14#include <boost/lexical_cast.hpp>
21using namespace libyang;
22using namespace sysrepo;
36 if (
model_ == IETF_DHCPV6_SERVER) {
38 }
else if ((
model_ == KEA_DHCP4_SERVER) ||
39 (
model_ == KEA_DHCP6_SERVER)) {
42 }
catch (Error
const& ex) {
48 "getPool not implemented for the model: " <<
model_);
81 return (result->empty() ?
ElementPtr() : result);
89 result->set(
"pool", prefix);
93 if (!start_addr || !end_addr) {
95 "both start and end addresses");
98 range << start_addr->stringValue() <<
" - "
99 << end_addr->stringValue();
104 result->set(
"option-data", options);
114 return (result->empty() ?
ElementPtr() : result);
120 if (
model_ == IETF_DHCPV6_SERVER) {
122 }
else if ((
model_ == KEA_DHCP4_SERVER) ||
123 (
model_ == KEA_DHCP6_SERVER)) {
127 "setPool not implemented for the model: " <<
model_);
129 }
catch (Error
const& ex) {
131 "setting pool '" << elem->str()
132 <<
"' : " << ex.
what());
142 string prefix = pool->stringValue();
143 if (prefix.find(
"/") == string::npos) {
145 "setPoolIetf only supports pools in prefix (vs range) "
146 "format and was called with '" << prefix <<
"'");
148 setItem(xpath +
"/pool-prefix", pool, LeafBaseType::String);
149 string addr = prefix.substr(0, prefix.find_first_of(
" /"));
150 uint8_t plen = boost::lexical_cast<unsigned>
151 (prefix.substr(prefix.find_last_of(
" /") + 1, string::npos));
153 setItem(xpath +
"/start-address",
155 LeafBaseType::String);
156 setItem(xpath +
"/end-address",
158 LeafBaseType::String);
161 checkAndSetLeaf(elem, xpath,
"preferred-lifetime", LeafBaseType::Uint32);
168 setItem(xpath +
"/max-address-count",
201 string prefix = pool->stringValue();
205 if (prefix.find(
"/") != string::npos) {
206 setItem(xpath +
"/prefix", pool, LeafBaseType::String);
209 if (options && !options->empty()) {
216 string& start_address,
string& end_address) {
217 size_t slash = prefix.find(
"/");
218 if (slash != string::npos) {
219 string addr = prefix.substr(0, prefix.find_first_of(
" /"));
220 uint8_t plen = boost::lexical_cast<unsigned>
221 (prefix.substr(prefix.find_last_of(
" /") + 1, string::npos));
226 size_t dash = prefix.find(
"-");
227 if (dash == string::npos) {
229 "getAddresses called with invalid prefix: " << prefix);
231 start_address = prefix.substr(0, prefix.find_first_of(
" -"));
232 end_address = prefix.substr(prefix.find_last_of(
" -") + 1, string::npos);
245 if (
model_ == IETF_DHCPV6_SERVER) {
247 }
else if ((
model_ == KEA_DHCP4_SERVER) ||
248 (
model_ == KEA_DHCP6_SERVER)) {
251 }
catch (Error
const& ex) {
257 "getPools not implemented for the model: " <<
model_);
284 if (
model_ == IETF_DHCPV6_SERVER) {
286 }
else if ((
model_ == KEA_DHCP4_SERVER) ||
287 (
model_ == KEA_DHCP6_SERVER)) {
291 "setPools not implemented for the model: " <<
model_);
293 }
catch (Error
const& ex) {
295 "setting pools '" << elem->str()
296 <<
"' : " << ex.
what());
302 for (
size_t i = 0; i < elem->size(); ++i) {
304 ostringstream prefix;
305 prefix << xpath <<
"/address-pool[pool-id='" << i <<
"']";
313 for (
size_t i = 0; i < elem->size(); ++i) {
315 if (!pool->contains(
"pool")) {
319 string pref = pool->get(
"pool")->stringValue();
323 ostringstream prefix;
324 prefix << xpath <<
"/pool[start-address='" << start_addr
325 <<
"'][end-address='" << end_addr <<
"']";
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
A generic exception that is thrown when a function is not implemented.
The IOAddress class represents an IP addresses (version agnostic)
std::string toText() const
Convert the address to a string.
static ElementPtr create(const Position &pos=ZERO_POSITION())
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
A translator class for converting an option data list between YANG and JSON.
void setOptionDataList(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set option data list from JSON to YANG.
isc::data::ConstElementPtr getOptionDataList(libyang::DataNode const &data_node)
Translate option data list from YANG to JSON.
Option data translation between YANG and JSON.
A translator class for converting a pool between YANG and JSON.
void setPool(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set (address) pool from JSON to YANG.
void setPoolKea(const std::string &xpath, isc::data::ConstElementPtr elem)
setPool for kea-dhcp[46]-server.
isc::data::ElementPtr getPoolIetf6(libyang::DataNode const &data_node)
getPool for ietf-dhcpv6-server.
isc::data::ElementPtr getPool(libyang::DataNode const &data_node)
Translate a pool from YANG to JSON.
isc::data::ElementPtr getPoolKea(libyang::DataNode const &data_node)
getPool for kea-dhcp[46]-server.
TranslatorPool(sysrepo::Session session, const std::string &model)
Constructor.
isc::data::ElementPtr getPoolFromAbsoluteXpath(std::string const &xpath)
Translate a pool from YANG to JSON.
static void getAddresses(const std::string &prefix, std::string &start_address, std::string &end_address)
Get start and end addresses from prefix.
void setPoolIetf6(const std::string &xpath, isc::data::ConstElementPtr elem)
setPool for ietf-dhcpv6-server.
void setPoolsByAddresses(const std::string &xpath, isc::data::ConstElementPtr elem)
setPools using address pair.
void setPoolsById(const std::string &xpath, isc::data::ConstElementPtr elem)
setPools using pool-id.
isc::data::ElementPtr getPoolsKea(libyang::DataNode const &data_node)
getPools for kea-dhcp[46]-server.
isc::data::ElementPtr getPoolsFromAbsoluteXpath(std::string const &xpath)
Translate pools from YANG to JSON.
TranslatorPools(sysrepo::Session session, const std::string &model)
Constructor.
void setPools(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set (address) pools from JSON to YANG.
isc::data::ElementPtr getPoolsIetf(libyang::DataNode const &data_node)
getPools for ietf-dhcpv6-server.
isc::data::ElementPtr getPools(libyang::DataNode const &data_node)
Translate pools from YANG to JSON.
Between YANG and JSON translator class for basic values.
void getMandatoryDivergingLeaf(isc::data::ElementPtr &storage, libyang::DataNode const &data_node, std::string const &name, std::string const &yang_name) const
Retrieves a child YANG data node identified by one name from the given parent YANG container node and...
isc::data::ElementPtr getList(libyang::DataNode const &data_node, std::string const &xpath, T &t, isc::data::ElementPtr(T::*f)(libyang::DataNode const &)) const
Retrieve a list as ElementPtr from sysrepo from a certain xpath.
void checkAndSetLeaf(isc::data::ConstElementPtr const &from, std::string const &xpath, std::string const &name, libyang::LeafBaseType const type)
Get an element from given ElementPtr node and set it in sysrepo at given xpath.
isc::data::ElementPtr getItem(libyang::DataNode const &data_node, std::string const &xpath) const
Translate a basic value from YANG to JSON for a given xpath that is relative to the given source node...
libyang::DataNode findXPath(std::string const &xpath) const
Retrieves a YANG data node by xpath.
void checkAndGetLeaf(isc::data::ElementPtr &storage, libyang::DataNode const &data_node, std::string const &name) const
Retrieves a child YANG data node identified by name from the given parent YANG container node and sto...
void checkAndSetUserContext(isc::data::ConstElementPtr const &from, std::string const &xpath)
Get an element from given ElementPtr node and set it in sysrepo at given xpath.
void checkAndGetDivergingLeaf(isc::data::ElementPtr &storage, libyang::DataNode const &data_node, std::string const &name, std::string const &yang_name) const
Retrieves a child YANG data node identified by name from the given parent YANG container node and sto...
void setItem(const std::string &xpath, isc::data::ConstElementPtr const elem, libyang::LeafBaseType const type)
Translate and set basic value from JSON to YANG.
std::string model_
The model.
void checkAndSetDivergingLeaf(isc::data::ConstElementPtr const &from, std::string const &xpath, std::string const &name, std::string const &yang_name, libyang::LeafBaseType const type)
Get an element from given ElementPtr node and set it in sysrepo at given xpath.
void checkAndGetAndJsonifyLeaf(isc::data::ElementPtr &storage, libyang::DataNode const &data_node, const std::string &name) const
Retrieves a child YANG data node identified by name from the given parent YANG container node,...
void checkAndSetLeafList(isc::data::ConstElementPtr const &from, std::string const &xpath, std::string const &name, libyang::LeafBaseType const type)
Get an element from given ElementPtr node and set it in sysrepo at given xpath as a leaf-list.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
IOAddress firstAddrInPrefix(const IOAddress &prefix, uint8_t len)
This code is based on similar code from the Dibbler project.
IOAddress lastAddrInPrefix(const IOAddress &prefix, uint8_t len)
returns a last address in a given prefix
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
Defines the logger used by the top-level component of kea-lfc.