Skip to content

Commit

Permalink
Fixed issue #777 (#791)
Browse files Browse the repository at this point in the history
* Fixed issue #777

* Moved YList functions to new 'ylist' package
  • Loading branch information
ygorelik authored and Abhi Keshav committed May 24, 2018
1 parent 3f87475 commit 7e0b658
Show file tree
Hide file tree
Showing 14 changed files with 248 additions and 310 deletions.
5 changes: 0 additions & 5 deletions sdk/cpp/core/src/path/path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,8 @@ static LYD_FORMAT get_ly_format(ydk::EncodingFormat format)
LYD_FORMAT scheme = LYD_XML;
if (format == ydk::EncodingFormat::JSON)
{
ydk::YLOG_DEBUG("Performing decode operation on JSON");
scheme = LYD_JSON;
}
else
{
ydk::YLOG_DEBUG("Performing decode operation on XML");
}
return scheme;
}

Expand Down
5 changes: 4 additions & 1 deletion sdk/cpp/core/src/path/path_private.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
#include <functional>
#include <cstring>
#include <cassert>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>

#include "libyang/libyang.h"
#include "libyang/tree_schema.h"
Expand Down Expand Up @@ -84,6 +85,8 @@ namespace ydk {
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);
void collect_features_from_imported_modules(const lys_module* module,
std::set<std::pair<lys_module*, std::string>>& features);

private:
std::vector<ModelProvider*> model_providers;
Expand Down
33 changes: 29 additions & 4 deletions sdk/cpp/core/src/path/repository.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include <string.h>

#include <fstream>
#include <unordered_set>

#include "path_private.hpp"
#include "../ydk_yang.hpp"
Expand Down Expand Up @@ -466,6 +465,20 @@ ydk::path::RepositoryPtr::load_module(ly_ctx* ctx, const std::string& module_nam
return load_module(ctx, mod_cap, new_module);
}

void
ydk::path::RepositoryPtr::collect_features_from_imported_modules(const lys_module* module, std::set<std::pair<lys_module*, std::string>>& features)
{
for (int i=0; i<module->imp_size; i++) {
const lys_module* imp_module = module->imp[i].module;
ydk::path::Capability mod_cap = ydk::path::Capability{imp_module->name, ""};
get_module_capabilities(mod_cap);
for (auto f : mod_cap.features) {
features.insert(make_pair((lys_module*)imp_module, f));
}
collect_features_from_imported_modules(imp_module, features);
}
}

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)
{
Expand All @@ -478,7 +491,8 @@ ydk::path::RepositoryPtr::load_module(ly_ctx* ctx, const std::string& module, co
p = ly_ctx_load_module(ctx, module.c_str(), revision.empty() ? NULL : revision.c_str());
if (!p) {
YLOG_WARN("Unable to parse module '{}'. This model cannot be used with YDK", module);
}
return p;
}
}
else {
const struct lys_node *last = nullptr;
Expand All @@ -492,9 +506,20 @@ ydk::path::RepositoryPtr::load_module(ly_ctx* ctx, const std::string& module, co
}
}

// Collect all module features
std::set<std::pair<lys_module*, std::string>> all_features{};
for (auto f : features) {
YLOG_DEBUG("Adding feature '{}'", f.c_str());
lys_features_enable(p, f.c_str());
all_features.insert(make_pair((lys_module*)p, f));
}
collect_features_from_imported_modules(p, all_features);

for (auto elem : all_features) {
if (lys_features_enable((const lys_module*)elem.first, elem.second.c_str())) {
YLOG_DEBUG("Failed to enable feature '{}' in '{}'", elem.second, elem.first->name);
}
else {
YLOG_DEBUG("Enabled feature '{}' in '{}'", elem.second, elem.first->name);
}
}
return p;
}
Expand Down
8 changes: 4 additions & 4 deletions sdk/cpp/core/tests/mock_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ static std::unordered_map<std::string, ydk::path::Capability> test_openconfig_lo
{"urn:ietf:params:xml:ns:yang:ietf-interfaces", {"ietf-interfaces", ""}},
{"http://cisco.com/ns/yang/ydk", {"ydk", ""}},
{"http://cisco.com/ns/yang/ydktest-sanity", {"ydktest-sanity", ""}},
{"http://cisco.com/ns/yang/ydktest-action", {"ydktest-sanity-action", ""}}

{"http://cisco.com/ns/yang/ydktest-action", {"ydktest-sanity-action", ""}},
{"http://cisco.com/ns/yang/ydktest-types", {"ydktest-types", ""}}
};


Expand Down Expand Up @@ -115,7 +115,7 @@ static std::vector<ydk::path::Capability> test_openconfig {
{"ietf-interfaces", ""},
{"ydk", ""},
{"ydktest-sanity", ""},
{"ydktest-sanity-action", ""}

{"ydktest-sanity-action", ""},
{"ydktest-types", ""}
};

185 changes: 0 additions & 185 deletions sdk/cpp/core/tests/models/ydktest-sanity-submodule@2015-11-17.yang

This file was deleted.

26 changes: 26 additions & 0 deletions sdk/cpp/core/tests/models/ydktest-sanity-submodule@2016-04-25.yang
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ submodule ydktest-sanity-submodule {

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

import ydktest-types {
prefix "types";
}

import ietf-yang-types {
prefix yang;
}
Expand Down Expand Up @@ -133,6 +137,23 @@ submodule ydktest-sanity-submodule {
}
}

grouping config-interface-tunnel-ipsec-grouping {
container ipsec {
description
"Use ipsec to protect this tunnel interface";
leaf profile {
description
"Determine the ipsec policy profile to use.";
type string;
}
leaf ikev2-profile {
description
"ikev2 policy profile";
type string;
}
}
}

grouping config-interface-grouping {
container interface {
description
Expand Down Expand Up @@ -177,7 +198,12 @@ submodule ydktest-sanity-submodule {
leaf name {
type uint32;
}

uses interface-common-grouping;

uses config-interface-tunnel-ipsec-grouping {
if-feature types:crypto;
}
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions sdk/cpp/core/tests/models/ydktest-types@2016-05-23.yang
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ module ydktest-types {
description "Identityref type";
}

feature crypto {
description
"crypto feature";
}

grouping tt {
container xyz {
presence true;
Expand Down
Loading

0 comments on commit 7e0b658

Please sign in to comment.