Commit 6bbb2c23 authored by Francis Dupont's avatar Francis Dupont

[5-netconf-extend-syntax_rebased] Addressed rebase conflicts

parents 3aaecb8b f31f89a5
......@@ -4,6 +4,16 @@
{
"Netconf":
{
// Three flags control netconf (default values are true):
// - "boot-update" about the YANG configuration load when
// netconf boots.
// - "subscribe-changes" about the subscription to notifications
// when the running YANG module is changed.
// - "validate-changes" alloes to validate or not changes.
"boot-update": true,
"subscribe-changes": true,
"validate-changes": true,
// This map specifies how each server is managed:
// the YANG model to use and the control channel.
"managed-servers":
......@@ -16,6 +26,12 @@
// DHCPv4 server is kea-dhcp4-server model.
"model": "kea-dhcp4-server",
// The three control flags can be defined in this scope too
// and takes precedence over global and default values.
"boot-update": false,
"subscribe-changes": false,
"validate-changes": false,
// Currently three control channel types are supported:
// - "stdout" which output the configuration on the standard
// output (this is mainly for testing purposes, but you can
......
// Generated 201809281126
// Generated 201810092120
// A Bison parser, made by GNU Bison 3.0.5.
// Locations for Bison parsers in C++
......
......@@ -21,12 +21,29 @@ namespace isc {
namespace netconf {
NetconfConfig::NetconfConfig()
: servers_map_(new CfgServersMap()) {
: configured_globals_(Element::createMap()),
servers_map_(new CfgServersMap()) {
}
NetconfConfig::NetconfConfig(const NetconfConfig& orig)
: ConfigBase(), servers_map_(orig.servers_map_),
hooks_config_(orig.hooks_config_) {
: ConfigBase(), configured_globals_(orig.configured_globals_),
servers_map_(orig.servers_map_), hooks_config_(orig.hooks_config_) {
}
void
NetconfConfig::extractConfiguredGlobals(ConstElementPtr config) {
if (config->getType() != Element::map) {
isc_throw(BadValue,
"extractConfiguredGlobals must be given a map element");
}
const std::map<std::string, ConstElementPtr>& values = config->mapValue();
for (auto value = values.begin(); value != values.end(); ++value) {
if (value->second->getType() != Element::list &&
value->second->getType() != Element::map) {
addConfiguredGlobal(value->first, value->second);
}
}
}
NetconfCfgMgr::NetconfCfgMgr()
......@@ -81,9 +98,13 @@ NetconfCfgMgr::parse(isc::data::ConstElementPtr config_set,
NetconfConfigPtr ctx = getNetconfConfig();
// Set the defaults
// Preserve all scalar global parameters.
ctx->extractConfiguredGlobals(config_set);
// Set the defaults and derive parameters.
ElementPtr cfg = boost::const_pointer_cast<Element>(config_set);
NetconfSimpleParser::setAllDefaults(cfg);
NetconfSimpleParser::deriveParameters(cfg);
// And parse the configuration.
ConstElementPtr answer;
......@@ -121,13 +142,13 @@ NetconfCfgMgr::parse(isc::data::ConstElementPtr config_set,
return (answer);
}
ElementPtr
NetconfConfig::toElement() const {
ElementPtr netconf = Element::createMap();
// Set user-context
contextToElement(netconf);
// Add in explicitly configured globals.
netconf->setValue(configured_globals_->mapValue());
// Set hooks-libraries
netconf->set("hooks-libraries", hooks_config_.toElement());
// Set managed-servers
......
......@@ -35,6 +35,25 @@ public:
/// @brief Default constructor
NetconfConfig();
/// @brief Returns pointer to configured global parameters.
///
/// @todo revisit this at the toElement first use.
isc::data::ConstElementPtr getConfiguredGlobals() const {
return (isc::data::ConstElementPtr(configured_globals_));
}
/// @brief Saves scalar elements from the global scope of a configuration.
void extractConfiguredGlobals(isc::data::ConstElementPtr config);
/// @brief Adds a parameter to the collection configured globals.
///
/// @param name std::string name of the global to add.
/// @param value ElementPtr containing the value of the global.
void addConfiguredGlobal(const std::string& name,
isc::data::ConstElementPtr value) {
configured_globals_->set(name, value);
}
/// @brief Returns non-const reference to the managed servers map.
///
/// @return non-const reference to the managed servers map.
......@@ -88,6 +107,9 @@ private:
/// @param rhs Context to be assigned.
NetconfConfig& operator=(const NetconfConfig& rhs);
/// @brief Stores the global parameters specified via configuration.
isc::data::ElementPtr configured_globals_;
/// @brief CfgServers map.
CfgServersMapPtr servers_map_;
......
......@@ -79,7 +79,8 @@ CfgControlSocket::toElement() const {
// *********************** CfgServer *************************
CfgServer::CfgServer(const string& model, CfgControlSocketPtr ctrl_sock)
: model_(model), control_socket_(ctrl_sock) {
: model_(model), boot_update_(true), subscribe_changes_(true),
validate_changes_(true), control_socket_(ctrl_sock) {
}
CfgServer::~CfgServer() {
......@@ -114,6 +115,12 @@ CfgServer::toElement() const {
contextToElement(result);
// Set model
result->set("model", Element::create(model_));
// Set boot-update
result->set("boot-update", Element::create(boot_update_));
// Set subscribe-changes
result->set("subscribe-changes", Element::create(subscribe_changes_));
// Set validate-changes
result->set("validate-changes", Element::create(validate_changes_));
// Set control-socket
if (control_socket_) {
result->set("control-socket", control_socket_->toElement());
......@@ -192,6 +199,11 @@ ServerConfigParser::parse(ConstElementPtr server_config) {
<< server_config->getPosition() << ")");
}
// Add flags.
result->setBootUpdate(getBoolean(server_config, "boot-update"));
result->setSubscribeChanges(getBoolean(server_config, "subscribe-changes"));
result->setValidateChanges(getBoolean(server_config, "validate-changes"));
// Add user-context.
if (user_context) {
result->setContext(user_context);
......
......@@ -172,6 +172,48 @@ public:
return (control_socket_);
}
/// @brief Getter which returns the boot-update flag.
///
/// @return returns the boot-update flag as a bool.
bool getBootUpdate() const {
return (boot_update_);
}
/// @brief Set the boot-update flag.
///
/// @param boot_update The boot-update flag.
void setBootUpdate(bool boot_update) {
boot_update_ = boot_update;
}
/// @brief Getter which returns the subscribe-changes flag.
///
/// @return returns the subscribe-changes flag as a bool.
bool getSubscribeChanges() const {
return (subscribe_changes_);
}
/// @brief Set the subscribe-changes flag.
///
/// @param subscribe_changes The subscribe-changes flag.
void setSubscribeChanges(bool subscribe_changes) {
subscribe_changes_ = subscribe_changes;
}
/// @brief Getter which returns the validate-changes flag.
///
/// @return returns the validate-changes flag as a bool.
bool getValidateChanges() const {
return (validate_changes_);
}
/// @brief Set the validate-changes flag.
///
/// @param validate_changes The validate-changes flag.
void setValidateChanges(bool validate_changes) {
validate_changes_ = validate_changes;
}
/// @brief Returns a text representation for the server.
std::string toText() const;
......@@ -184,6 +226,24 @@ private:
/// @brief The model name.
const std::string model_;
/// @brief The boot-update flag.
///
/// If true (the defaul) Kea server configuration is updated at (netconf
/// agent) boot time.
bool boot_update_;
/// @brief The subscribe-changes flag.
///
/// If true (the deault) the netconf agent subscribes module changes
/// so will be notified when the YANG running configuration is changed.
bool subscribe_changes_;
/// @brief The validate-changes flag.
///
/// If true (the deault) the netconf agent validates module changes
/// and can reject bad configurations.
bool validate_changes_;
/// @brief The control socket.
CfgControlSocketPtr control_socket_;
};
......
This diff is collapsed.
......@@ -206,6 +206,36 @@ ControlCharacterFill [^"\\]|\\{JSONEscapeSequence}
}
}
\"boot-update\" {
switch(driver.ctx_) {
case ParserContext::NETCONF:
case ParserContext::SERVER:
return NetconfParser::make_BOOT_UPDATE(driver.loc_);
default:
return NetconfParser::make_STRING("boot-update", driver.loc_);
}
}
\"subscribe-changes\" {
switch(driver.ctx_) {
case ParserContext::NETCONF:
case ParserContext::SERVER:
return NetconfParser::make_SUBSCRIBE_CHANGES(driver.loc_);
default:
return NetconfParser::make_STRING("subscribe-changes", driver.loc_);
}
}
\"validate-changes\" {
switch(driver.ctx_) {
case ParserContext::NETCONF:
case ParserContext::SERVER:
return NetconfParser::make_VALIDATE_CHANGES(driver.loc_);
default:
return NetconfParser::make_STRING("validate-changes", driver.loc_);
}
}
\"managed-servers\" {
switch(driver.ctx_) {
case ParserContext::NETCONF:
......
This diff is collapsed.
......@@ -352,39 +352,42 @@ namespace isc { namespace netconf {
TOKEN_NETCONF = 265,
TOKEN_USER_CONTEXT = 266,
TOKEN_COMMENT = 267,
TOKEN_MANAGED_SERVERS = 268,
TOKEN_DHCP4_SERVER = 269,
TOKEN_DHCP6_SERVER = 270,
TOKEN_D2_SERVER = 271,
TOKEN_CA_SERVER = 272,
TOKEN_MODEL = 273,
TOKEN_CONTROL_SOCKET = 274,
TOKEN_SOCKET_TYPE = 275,
TOKEN_UNIX = 276,
TOKEN_HTTP = 277,
TOKEN_STDOUT = 278,
TOKEN_SOCKET_NAME = 279,
TOKEN_SOCKET_URL = 280,
TOKEN_HOOKS_LIBRARIES = 281,
TOKEN_LIBRARY = 282,
TOKEN_PARAMETERS = 283,
TOKEN_LOGGING = 284,
TOKEN_LOGGERS = 285,
TOKEN_NAME = 286,
TOKEN_OUTPUT_OPTIONS = 287,
TOKEN_OUTPUT = 288,
TOKEN_DEBUGLEVEL = 289,
TOKEN_SEVERITY = 290,
TOKEN_FLUSH = 291,
TOKEN_MAXSIZE = 292,
TOKEN_MAXVER = 293,
TOKEN_START_JSON = 294,
TOKEN_START_NETCONF = 295,
TOKEN_START_SUB_NETCONF = 296,
TOKEN_STRING = 297,
TOKEN_INTEGER = 298,
TOKEN_FLOAT = 299,
TOKEN_BOOLEAN = 300
TOKEN_BOOT_UPDATE = 268,
TOKEN_SUBSCRIBE_CHANGES = 269,
TOKEN_VALIDATE_CHANGES = 270,
TOKEN_MANAGED_SERVERS = 271,
TOKEN_DHCP4_SERVER = 272,
TOKEN_DHCP6_SERVER = 273,
TOKEN_D2_SERVER = 274,
TOKEN_CA_SERVER = 275,
TOKEN_MODEL = 276,
TOKEN_CONTROL_SOCKET = 277,
TOKEN_SOCKET_TYPE = 278,
TOKEN_UNIX = 279,
TOKEN_HTTP = 280,
TOKEN_STDOUT = 281,
TOKEN_SOCKET_NAME = 282,
TOKEN_SOCKET_URL = 283,
TOKEN_HOOKS_LIBRARIES = 284,
TOKEN_LIBRARY = 285,
TOKEN_PARAMETERS = 286,
TOKEN_LOGGING = 287,
TOKEN_LOGGERS = 288,
TOKEN_NAME = 289,
TOKEN_OUTPUT_OPTIONS = 290,
TOKEN_OUTPUT = 291,
TOKEN_DEBUGLEVEL = 292,
TOKEN_SEVERITY = 293,
TOKEN_FLUSH = 294,
TOKEN_MAXSIZE = 295,
TOKEN_MAXVER = 296,
TOKEN_START_JSON = 297,
TOKEN_START_NETCONF = 298,
TOKEN_START_SUB_NETCONF = 299,
TOKEN_STRING = 300,
TOKEN_INTEGER = 301,
TOKEN_FLOAT = 302,
TOKEN_BOOLEAN = 303
};
};
......@@ -543,6 +546,18 @@ namespace isc { namespace netconf {
symbol_type
make_COMMENT (const location_type& l);
static inline
symbol_type
make_BOOT_UPDATE (const location_type& l);
static inline
symbol_type
make_SUBSCRIBE_CHANGES (const location_type& l);
static inline
symbol_type
make_VALIDATE_CHANGES (const location_type& l);
static inline
symbol_type
make_MANAGED_SERVERS (const location_type& l);
......@@ -882,12 +897,12 @@ namespace isc { namespace netconf {
enum
{
yyeof_ = 0,
yylast_ = 221, ///< Last index in yytable_.
yynnts_ = 100, ///< Number of nonterminal symbols.
yylast_ = 238, ///< Last index in yytable_.
yynnts_ = 103, ///< Number of nonterminal symbols.
yyfinal_ = 8, ///< Termination state number.
yyterror_ = 1,
yyerrcode_ = 256,
yyntokens_ = 46 ///< Number of tokens.
yyntokens_ = 49 ///< Number of tokens.
};
......@@ -934,9 +949,9 @@ namespace isc { namespace netconf {
15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
45
45, 46, 47, 48
};
const unsigned user_token_number_max_ = 300;
const unsigned user_token_number_max_ = 303;
const token_number_type undef_token_ = 2;
if (static_cast<int> (t) <= yyeof_)
......@@ -967,25 +982,25 @@ namespace isc { namespace netconf {
{
switch (other.type_get ())
{
case 54: // value
case 57: // map_value
case 113: // socket_type_value
case 57: // value
case 60: // map_value
case 119: // socket_type_value
value.copy< ElementPtr > (other.value);
break;
case 45: // "boolean"
case 48: // "boolean"
value.copy< bool > (other.value);
break;
case 44: // "floating point"
case 47: // "floating point"
value.copy< double > (other.value);
break;
case 43: // "integer"
case 46: // "integer"
value.copy< int64_t > (other.value);
break;
case 42: // "constant string"
case 45: // "constant string"
value.copy< std::string > (other.value);
break;
......@@ -1004,25 +1019,25 @@ namespace isc { namespace netconf {
(void) v;
switch (this->type_get ())
{
case 54: // value
case 57: // map_value
case 113: // socket_type_value
case 57: // value
case 60: // map_value
case 119: // socket_type_value
value.copy< ElementPtr > (v);
break;
case 45: // "boolean"
case 48: // "boolean"
value.copy< bool > (v);
break;
case 44: // "floating point"
case 47: // "floating point"
value.copy< double > (v);
break;
case 43: // "integer"
case 46: // "integer"
value.copy< int64_t > (v);
break;
case 42: // "constant string"
case 45: // "constant string"
value.copy< std::string > (v);
break;
......@@ -1100,25 +1115,25 @@ namespace isc { namespace netconf {
// Type destructor.
switch (yytype)
{
case 54: // value
case 57: // map_value
case 113: // socket_type_value
case 57: // value
case 60: // map_value
case 119: // socket_type_value
value.template destroy< ElementPtr > ();
break;
case 45: // "boolean"
case 48: // "boolean"
value.template destroy< bool > ();
break;
case 44: // "floating point"
case 47: // "floating point"
value.template destroy< double > ();
break;
case 43: // "integer"
case 46: // "integer"
value.template destroy< int64_t > ();
break;
case 42: // "constant string"
case 45: // "constant string"
value.template destroy< std::string > ();
break;
......@@ -1143,25 +1158,25 @@ namespace isc { namespace netconf {
super_type::move (s);
switch (this->type_get ())
{
case 54: // value
case 57: // map_value
case 113: // socket_type_value
case 57: // value
case 60: // map_value
case 119: // socket_type_value
value.move< ElementPtr > (s.value);
break;
case 45: // "boolean"
case 48: // "boolean"
value.move< bool > (s.value);
break;
case 44: // "floating point"
case 47: // "floating point"
value.move< double > (s.value);
break;
case 43: // "integer"
case 46: // "integer"
value.move< int64_t > (s.value);
break;
case 42: // "constant string"
case 45: // "constant string"
value.move< std::string > (s.value);
break;
......@@ -1224,7 +1239,7 @@ namespace isc { namespace netconf {
265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
285, 286, 287, 288, 289, 290, 291, 292, 293, 294,
295, 296, 297, 298, 299, 300
295, 296, 297, 298, 299, 300, 301, 302, 303
};
return static_cast<token_type> (yytoken_number_[type]);
}
......@@ -1295,6 +1310,24 @@ namespace isc { namespace netconf {
return symbol_type (token::TOKEN_COMMENT, l);
}
NetconfParser::symbol_type
NetconfParser::make_BOOT_UPDATE (const location_type& l)
{
return symbol_type (token::TOKEN_BOOT_UPDATE, l);
}
NetconfParser::symbol_type
NetconfParser::make_SUBSCRIBE_CHANGES (const location_type& l)
{
return symbol_type (token::TOKEN_SUBSCRIBE_CHANGES, l);
}
NetconfParser::symbol_type
NetconfParser::make_VALIDATE_CHANGES (const location_type& l)
{
return symbol_type (token::TOKEN_VALIDATE_CHANGES, l);
}
NetconfParser::symbol_type
NetconfParser::make_MANAGED_SERVERS (const location_type& l)
{
......@@ -1496,7 +1529,7 @@ namespace isc { namespace netconf {
#line 14 "netconf_parser.yy" // lalr1.cc:379
} } // isc::netconf
#line 1500 "netconf_parser.h" // lalr1.cc:379
#line 1533 "netconf_parser.h" // lalr1.cc:379
......
......@@ -53,6 +53,10 @@ using namespace std;
USER_CONTEXT "user-context"
COMMENT "comment"
BOOT_UPDATE "boot-update"
SUBSCRIBE_CHANGES "subscribe-changes"
VALIDATE_CHANGES "validate-changes"
MANAGED_SERVERS "managed-servers"
DHCP4_SERVER "dhcp4"
DHCP6_SERVER "dhcp6"
......@@ -268,13 +272,31 @@ not_empty_global_params: global_param
// These are the parameters that are allowed in the top-level for
// Netconf.
global_param: managed_servers
global_param: boot_update
| subscribe_changes
| validate_changes
| managed_servers
| hooks_libraries
| user_context
| comment
| unknown_map_entry
;
boot_update: BOOT_UPDATE COLON BOOLEAN {
ElementPtr flag(new BoolElement($3, ctx.loc2pos(@3)));
ctx.stack_.back()->set("boot-update", flag);
};
subscribe_changes: SUBSCRIBE_CHANGES COLON BOOLEAN {
ElementPtr flag(new BoolElement($3, ctx.loc2pos(@3)));
ctx.stack_.back()->set("subscribe-changes", flag);
};
validate_changes: VALIDATE_CHANGES COLON BOOLEAN {
ElementPtr flag(new BoolElement($3, ctx.loc2pos(@3)));
ctx.stack_.back()->set("validate-changes", flag);
};
user_context: USER_CONTEXT {
ctx.enter(ctx.NO_KEYWORDS);
} COLON map_value {
......@@ -460,6 +482,9 @@ managed_server_params: managed_server_param
// We currently support two server parameters: model and control-socket.
managed_server_param: model
| boot_update
| subscribe_changes
| validate_changes
| control_socket
| user_context
| comment
......
// Generated 201809281126
// Generated 201810092120
// A Bison parser, made by GNU Bison 3.0.5.
// Positions for Bison parsers in C++
......
......@@ -36,6 +36,9 @@ namespace netconf {