Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issues 627 and 682. #691

Merged
8 commits merged into from
Feb 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ gen-api/
*.sublime-project
*.sublime-workspace
*.idea
scripts
sdk/cpp/core/tests/confd/ydktest/cli-history
sdk/python/core/ydk/models/ydktest
26 changes: 13 additions & 13 deletions sdk/cpp/core/src/path/data_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,17 @@

namespace ydk
{
namespace path
{

static void check_ly_schema_node_for_path(lyd_node* node, const std::string & path)
{
if(node == nullptr || node->schema == nullptr || node->schema->priv == nullptr)
{
YLOG_ERROR("Couldn't fetch schema node {}!", path);
throw(YCoreError{"Couldn't fetch schema node " + path});
}
}

}
namespace path
{
static void check_ly_schema_node_for_path(lyd_node* node, const std::string & path)
{
if(node == nullptr || node->schema == nullptr || node->schema->priv == nullptr)
{
YLOG_ERROR("Could not fetch schema node '{}'", path);
throw(YCoreError{"Could not fetch schema node: " + path});
}
}
}
}

////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -86,6 +84,7 @@ ydk::path::DataNodeImpl::~DataNodeImpl()
const ydk::path::SchemaNode&
ydk::path::DataNodeImpl::get_schema_node() const
{
YLOG_DEBUG("get_schema_node: Getting schema node for '{}'", m_node->schema->name);
check_ly_schema_node_for_path(m_node, get_path());
auto schema_ptr = reinterpret_cast<const SchemaNode*>(m_node->schema->priv);
return *schema_ptr;
Expand All @@ -106,6 +105,7 @@ ydk::path::DataNodeImpl::get_path() const
void
ydk::path::DataNodeImpl::populate_new_schemas_from_path(const std::string& path)
{
YLOG_DEBUG("populate_new_schemas_from_path: Getting schema node for '{}'", m_node->schema->name);
check_ly_schema_node_for_path(m_node, path);
auto snode = reinterpret_cast<SchemaNodeImpl*>(m_node->schema->priv);
snode->populate_new_schemas_from_path(path);
Expand Down
6 changes: 3 additions & 3 deletions sdk/cpp/core/src/path/netconf_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,19 +194,19 @@ void NetconfSession::initialize_repo(path::Repository & repo, bool on_demand)

std::vector<path::Capability> yang_caps;
std::vector<std::string> empty_caps;

std::vector<path::Capability> all_caps = capabilities_parser.parse(server_capabilities);
if (on_demand)
yang_caps = capabilities_parser.parse(empty_caps);
else
yang_caps = capabilities_parser.parse(server_capabilities);
yang_caps = all_caps;

root_schema = repo.create_root_schema(lookup_table, yang_caps);

if(root_schema.get() == nullptr)
{
YLOG_ERROR("Root schema cannot be obtained");
throw(YIllegalStateError{"Root schema cannot be obtained"});
}
repo.set_server_capabilities(all_caps);
}

NetconfSession::~NetconfSession()
Expand Down
3 changes: 3 additions & 0 deletions sdk/cpp/core/src/path/path_private.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ namespace ydk {

public:
std::string path;
std::vector<path::Capability> server_caps;

private:
ly_ctx* create_ly_context();
Expand All @@ -82,6 +83,8 @@ namespace ydk {
const lys_module* load_module(ly_ctx* ctx, const std::string& module_name, const std::string& revision);
const lys_module* load_module(ly_ctx* ctx, const std::string& module_name, const std::string& revision, const std::vector<std::string>& features, bool& new_module);

void get_module_capabilities(ydk::path::Capability& capability);

private:
std::vector<ModelProvider*> model_providers;
bool using_temp_directory;
Expand Down
43 changes: 35 additions & 8 deletions sdk/cpp/core/src/path/repository.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ void libyang_log_callback(LY_LOG_LEVEL level, const char *msg, const char *path)
}

ydk::path::RepositoryPtr::RepositoryPtr (path::ModelCachingOption caching_option)
: using_temp_directory(true), caching_option(caching_option)
: using_temp_directory(true), caching_option(caching_option), server_caps()
{
path = get_models_download_path();
ly_set_log_clb(libyang_log_callback, 1);
}


ydk::path::RepositoryPtr::RepositoryPtr(const std::string& search_dir, path::ModelCachingOption caching_option)
: path{search_dir}, using_temp_directory(false), caching_option(caching_option)
: path{search_dir}, using_temp_directory(false), caching_option(caching_option), server_caps()
{

if (!file_exists(path))
Expand Down Expand Up @@ -428,13 +428,19 @@ const lys_module*
ydk::path::RepositoryPtr::load_module(ly_ctx* ctx, const std::string& module_name)
{
bool new_module = true;
return load_module(ctx, module_name, "", {}, new_module);
std::string revision = "";
ydk::path::Capability mod_cap = ydk::path::Capability{module_name, revision};
get_module_capabilities(mod_cap);
return load_module(ctx, mod_cap, new_module);
}

const lys_module*
ydk::path::RepositoryPtr::load_module(ly_ctx* ctx, const std::string& module_name, bool& new_module)
{
return load_module(ctx, module_name, "", {}, new_module);
std::string revision = "";
ydk::path::Capability mod_cap = ydk::path::Capability{module_name, revision};
get_module_capabilities(mod_cap);
return load_module(ctx, mod_cap, new_module);
}

const lys_module*
Expand All @@ -454,14 +460,16 @@ const lys_module*
ydk::path::RepositoryPtr::load_module(ly_ctx* ctx, const std::string& module_name, const std::string& revision)
{
bool new_module = true;
return load_module(ctx, module_name, revision, {}, new_module);
ydk::path::Capability mod_cap = ydk::path::Capability{module_name, revision};
get_module_capabilities(mod_cap);
return load_module(ctx, mod_cap, new_module);
}

const lys_module*
ydk::path::RepositoryPtr::load_module(ly_ctx* ctx, const std::string& module, const std::string& revision, const std::vector<std::string>& features, bool& new_module)
{

YLOG_DEBUG("Module '{}' Revision '{}'", module.c_str(), revision.c_str());
YLOG_DEBUG("Loading Module '{}' Revision '{}'", module.c_str(), revision.c_str());

auto p = ly_ctx_get_module(ctx, module.c_str(), revision.empty() ? NULL : revision.c_str(), 1);

Expand All @@ -477,12 +485,27 @@ ydk::path::RepositoryPtr::load_module(ly_ctx* ctx, const std::string& module, co
YLOG_WARN("Unable to parse module: '{}'. This model cannot be used with YDK", module);
}

for (auto f : features)
for (auto f : features) {
YLOG_DEBUG("Adding feature '{}'", f.c_str());
lys_features_enable(p, f.c_str());

}
return p;
}

void
ydk::path::RepositoryPtr::get_module_capabilities(ydk::path::Capability & mod_cap)
{
for (auto & cap: server_caps) {
if (cap.module == mod_cap.module &&
(mod_cap.revision == "" || cap.revision == mod_cap.revision))
{
mod_cap.features = cap.features;
mod_cap.deviations = cap.deviations;
break;
}
}
}

///
/// @brief Adds a model provider.
///
Expand Down Expand Up @@ -568,5 +591,9 @@ std::vector<ydk::path::ModelProvider*> ydk::path::Repository::get_model_provider
return m_priv_repo->get_model_providers();
}

void
ydk::path::Repository::set_server_capabilities(std::vector<path::Capability> & serv_caps) {
m_priv_repo->server_caps = serv_caps;
}
////////////////////////////////////////////////////////////////////////

8 changes: 4 additions & 4 deletions sdk/cpp/core/src/path/schema_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,16 @@ ydk::path::SchemaNodeImpl::populate_augmented_schema_node(vector<lys_node*>& anc
}
}
else {
while(node) {
auto p = node;
while(p && (p->nodetype == LYS_USES)) {
const struct lys_node *last = nullptr;
while (auto p = lys_getnext(last, node->parent, nullptr, 0)) {
last = p;
while (p->nodetype == LYS_USES) {
p = p->child;
}
if (p) {
YLOG_DEBUG("Populating new schema node '{}'", string(p->name));
m_children.emplace_back(make_unique<SchemaNodeImpl>(this, const_cast<struct lys_node*>(p)));
}
node = node->next;
}
}
}
Expand Down
1 change: 1 addition & 0 deletions sdk/cpp/core/src/path_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,7 @@ class Repository {
///
std::vector<ModelProvider*> get_model_providers() const;

void set_server_capabilities(std::vector<path::Capability> & serv_caps);

std::string path;
private:
Expand Down
71 changes: 70 additions & 1 deletion sdk/cpp/core/tests/models/ydktest-sanity-augm.yang
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module ydktest-sanity-augm {
//import ietf-inet-types { prefix "inet"; }

//import Cisco-IOS-XR-types { prefix "xr"; }

import ydktest-sanity { prefix "ysanity"; }


Expand Down Expand Up @@ -97,7 +98,71 @@ module ydktest-sanity-augm {
}
}

/////////////////////////////////////////////////////////
// native / interface / Tunnel
/////////////////////////////////////////////////////////
grouping config-interface-tunnel-grouping {
container nhrp {
description
"NHRP Interface commands";
container event-publisher {
description
"Enable NHRP smart spoke feature";
leaf max-event-timeout {
description
"Number of seconds";
type uint8 {
range "1..22";
}
}
}
leaf group {
description
"group name string";
type string;
}
}

container tunnel {
description
"protocol-over-protocol tunneling";

// interface * / tunnel bandwidth
container bandwidth {
description
"Set tunnel bandwidth informational parameter";
leaf receive {
description
"Receive bandwidth";
type uint32;
}
leaf transmit {
description
"Transmit bandwidth";
type uint32;
}
}

// interface * / tunnel source
leaf source {
description
"source of tunnel packets";
type string;
}

// interface * / tunnel destination
leaf destination {
description
"destination of tunnel";
type string;
}
}
}


/////////////////////////////////////////////////////////
// augmentation
/////////////////////////////////////////////////////////
augment "/ysanity:runner" {
description "augment to one";
uses one-twin-aug;
Expand All @@ -108,7 +173,7 @@ module ydktest-sanity-augm {
uses one-aug-level;
}

augment "/ysanity:runner/ysanity:one" {
augment "/ysanity:runner/ysanity:one" {
description "augment leaf to one";
uses leaf-aug;
}
Expand All @@ -127,4 +192,8 @@ module ydktest-sanity-augm {
}
}

augment "/ysanity:native/ysanity:interface/ysanity:Tunnel" {
uses config-interface-tunnel-grouping;
}

}
Loading