diff --git a/sdk/cpp/core/src/netconf_service.cpp b/sdk/cpp/core/src/netconf_service.cpp index 9b38530d0..e62d72e81 100644 --- a/sdk/cpp/core/src/netconf_service.cpp +++ b/sdk/cpp/core/src/netconf_service.cpp @@ -241,7 +241,7 @@ bool NetconfService::edit_config(NetconfServiceProvider& provider, DataStore tar string payload = ""; for (auto entity : config_list) { - payload += get_xml_subtree_filter_payload(*entity, provider); + payload += get_data_payload(*entity, provider); } return edit_payload(provider, target, payload, default_operation, test_option, error_option); @@ -256,7 +256,9 @@ get_from_list(NetconfServiceProvider& provider, DataStore source, vectoris_top_level_class) ? + get_xml_subtree_filter_payload(*entity, provider) : + get_data_payload(*entity, provider); } // Source options: candidate | running | startup @@ -328,7 +330,9 @@ get_entity(NetconfServiceProvider& provider, DataStore source, Entity& filter, c } // filter - std::string filter_string = get_xml_subtree_filter_payload(filter, provider); + string filter_string = (filter.is_top_level_class) ? + get_xml_subtree_filter_payload(filter, provider) : + get_data_payload(filter, provider); rpc->get_input_node().create_datanode("filter", filter_string); shared_ptr result_datanode = (*rpc)(provider.get_session()); diff --git a/sdk/cpp/tests/test_netconf_service.cpp b/sdk/cpp/tests/test_netconf_service.cpp index 0de06833f..a678afad7 100644 --- a/sdk/cpp/tests/test_netconf_service.cpp +++ b/sdk/cpp/tests/test_netconf_service.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -98,7 +99,6 @@ TEST_CASE("delete_config") DataStore target = DataStore::url; -// auto reply = ns.delete_config(session, target, "http://test"); CHECK_THROWS_AS(ns.delete_config(provider, target, "http://test"), YError); } @@ -331,6 +331,66 @@ TEST_CASE("ietf_get_rpc") } } +TEST_CASE("create_list_with_yfilter") +{ + path::Repository repo{TEST_HOME}; + NetconfServiceProvider provider{repo, "127.0.0.1", "admin", "admin", 12022}; + ydk::path::RootSchemaNode& schema = provider.get_session().get_root_schema(); + NetconfService ns{}; + + auto runner = ydktest_sanity::Runner{}; + runner.yfilter = YFilter::delete_; + auto reply = ns.edit_config(provider, DataStore::running, runner); + REQUIRE(reply); + + runner.yfilter = YFilter::merge; + vector merge_list{}; + merge_list.push_back(&runner); + + reply = ns.edit_config(provider, DataStore::running, merge_list); + REQUIRE(reply); + + reply = ns.discard_changes(provider); + REQUIRE(reply); +} + +TEST_CASE("create_get_non_top") +{ + ydk::path::Repository repo{TEST_HOME}; + NetconfServiceProvider provider{repo, "127.0.0.1", "admin", "admin", 12022}; + NetconfService ns{}; + + // Create global configuration + auto bgp_set = openconfig_bgp::Bgp(); + bgp_set.yfilter = YFilter::replace; + bgp_set.global->config->as = 65001; + bgp_set.global->config->router_id = "1.2.3.4"; + auto reply = ns.edit_config(provider, DataStore::candidate, bgp_set); + REQUIRE(reply); + + // Add neighbor configuration + auto neighbor = openconfig_bgp::Bgp::Neighbors::Neighbor(); + neighbor.neighbor_address = "1.2.3.4"; + neighbor.config->neighbor_address = "1.2.3.4"; + reply = ns.edit_config(provider, DataStore::candidate, neighbor); + REQUIRE(reply); + + // Get and validate neighbor configuration + auto bgp_filter = openconfig_bgp::Bgp(); + auto neighbor_filter = make_shared(); + neighbor_filter->neighbor_address = "1.2.3.4"; + bgp_filter.neighbors->neighbor.append(neighbor_filter); + auto neighbor_entity = ns.get_config(provider, DataStore::candidate, *neighbor_filter); + REQUIRE(neighbor_entity!=nullptr); + + auto neighbor_ptr = dynamic_cast(neighbor_entity.get()); + REQUIRE(neighbor_ptr!=nullptr); + REQUIRE(*neighbor_ptr == neighbor); + + reply = ns.discard_changes(provider); + REQUIRE(reply); +} + TEST_CASE("get_openconfig_interfaces_and_bgp") { NetconfServiceProvider provider{"127.0.0.1", "admin", "admin", 12022};