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

Path api refactor #494

Merged
merged 13 commits into from
Jul 19, 2017
18 changes: 9 additions & 9 deletions sdk/cpp/core/docsgen/api/nodes/core_node_data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ Class represents the :cpp:class:`DataNode<DataNode>`.

A :cpp:class:`DataNode<DataNode>` represents a containment hierarchy. So invocation of the destructor will lead to the children of this node being destroyed.

.. cpp:function:: virtual const SchemaNode& schema() const
.. cpp:function:: virtual const SchemaNode& get_schema_node() const

Returns the :cpp:class:`SchemaNode<SchemaNode>` associated with this :cpp:class:`DataNode<DataNode>`.

:return: :cpp:class:`SchemaNode<SchemaNode>` associated with this :cpp:class:`DataNode<DataNode>`.

.. cpp:function:: virtual std::string path() const
.. cpp:function:: virtual std::string get_path() const

Returns the path expression representing this Node in in the NodeTree.

:return: ``std::string`` representing the path to this Node.

.. cpp:function:: virtual DataNode& create(const std::string& path)
.. cpp:function:: virtual DataNode& create_datanode(const std::string& path)

Creates a :cpp:class:`DataNode<DataNode>` corresponding to the path and set its value.

Expand All @@ -50,7 +50,7 @@ Class represents the :cpp:class:`DataNode<DataNode>`.
:raises: :cpp:class:`YCPPInvalidArgumentError<YCPPInvalidArgumentError>` In case the argument is invalid.
:raises: :cpp:class:`YCPPPathError<YCPPPathError>` In case the path is invalid.

.. cpp:function:: virtual DataNode& create(const std::string& path, const std::string& value)
.. cpp:function:: virtual DataNode& create_datanode(const std::string& path, const std::string& value)

Create a :cpp:class:`DataNode<DataNode>` corresponding to the path and set its value.

Expand All @@ -69,7 +69,7 @@ Class represents the :cpp:class:`DataNode<DataNode>`.
:raises: :cpp:class:`YCPPInvalidArgumentError<YCPPInvalidArgumentError>` In case the argument is invalid.
:raises: :cpp:class:`YCPPPathError<YCPPPathError>` In case the path is invalid.

.. cpp:function:: virtual void set(const std::string& value)
.. cpp:function:: virtual void set_value(const std::string& value)

Set the value of this :cpp:class:`DataNode<DataNode>`.

Expand All @@ -81,7 +81,7 @@ Class represents the :cpp:class:`DataNode<DataNode>`.
:param value: The value to set. This should be the string representation of the YANG type.
:raises: :cpp:class:`YCPPInvalidArgumentError<YCPPInvalidArgumentError>` if the :cpp:class:`DataNode<DataNode>`'s value cannot be set (for example it represents a container)

.. cpp:function:: virtual std::string get() const
.. cpp:function:: virtual std::string get_value() const

Returns a copy of the value of this :cpp:class:`DataNode<DataNode>`.

Expand All @@ -94,15 +94,15 @@ Class represents the :cpp:class:`DataNode<DataNode>`.
:param path: The path expression.
:return: Vector of :cpp:class:`DataNode<DataNode>` that satisfy the path expression supplied.

.. cpp:function:: virtual DataNode* parent() const
.. cpp:function:: virtual DataNode* get_parent() const

:return: Pointer to the parent of this :cpp:class:`DataNode<DataNode>` or ``nullptr`` if None exist.

.. cpp:function:: virtual std::vector<std::shared_ptr<DataNode>> children() const
.. cpp:function:: virtual std::vector<std::shared_ptr<DataNode>> get_children() const

:return: Pointer to the children of this :cpp:class:`DataNode<DataNode>`.

.. cpp:function:: virtual const DataNode& root() const
.. cpp:function:: virtual const DataNode& get_root() const

:return: Pointer to the root :cpp:class:`DataNode<DataNode>` of this tree.

Expand Down
22 changes: 14 additions & 8 deletions sdk/cpp/core/docsgen/api/nodes/core_node_rootschema.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Instances of this class represent the Root of the :cpp:class:`SchemaNode<SchemaN

Destructor for the :cpp:class:`RootSchemaNode<RootSchemaNode>`

.. cpp:function:: std::string path() const
.. cpp:function:: std::string get_path() const

Get the path expression representing this Node in in the NodeTree.

Expand All @@ -31,25 +31,25 @@ Instances of this class represent the Root of the :cpp:class:`SchemaNode<SchemaN
:raises: :cpp:class:`YCPPPathError<YCPPPathError>` if the path expression in invalid, See error code for details.
:raises: :cpp:class:`YCPPInvalidArgumentError<YCPPInvalidArgumentError>` if the argument is invalid.

.. cpp:function:: virtual SchemaNode* parent() const noexcept
.. cpp:function:: virtual SchemaNode* get_parent() const noexcept

Get the parent node of this :cpp:class:`SchemaNode<SchemaNode>` in the tree.

:return: Pointer to the parent node or ``nullptr`` in case this is the root.

.. cpp:function:: virtual std::vector<SchemaNode*> children() const
.. cpp:function:: virtual std::vector<SchemaNode*> get_children() const

Get the children of this :cpp:class:`SchemaNode<SchemaNode>` in the NodeTree.

:return: The children of this node.

.. cpp:function:: virtual const SchemaNode* root() const noexcept
.. cpp:function:: virtual const SchemaNode* get_root() const noexcept

Get the root of NodeTree this node is part of.

:return: The pointer to the root.

.. cpp:function:: virtual DataNode* create(const std::string& path, const std::string& value) const
.. cpp:function:: virtual DataNode* create_datanode(const std::string& path, const std::string& value) const

Create a :cpp:class:`DataNode<DataNode>` corresponding to the path and set its value.

Expand All @@ -67,7 +67,7 @@ Instances of this class represent the Root of the :cpp:class:`SchemaNode<SchemaN
:raises: :cpp:class:`YCPPInvalidArgumentError<YCPPInvalidArgumentError>` In case the argument is invalid.
:raises: :cpp:class:`YCPPPathError<YCPPPathError>` In case the path is invalid.

.. cpp:function:: virtual DataNode* create(const std::string& path, const std::string& value) const
.. cpp:function:: virtual DataNode* create_datanode(const std::string& path, const std::string& value) const

Create a :cpp:class:`DataNode<DataNode>` corresponding to the path and set its value.

Expand All @@ -84,7 +84,7 @@ Instances of this class represent the Root of the :cpp:class:`SchemaNode<SchemaN
:raises: :cpp:class:`YCPPInvalidArgumentError<YCPPInvalidArgumentError>` In case the argument is invalid.
:raises: :cpp:class:`YCPPPathError<YCPPPathError>` In case the path is invalid.

.. cpp:function:: virtual Statement statement() const
.. cpp:function:: virtual Statement get_statement() const

Return the :cpp:class:`Statement<Statement>` representing this :cpp:class:`SchemaNode<SchemaNode>`.

Expand All @@ -94,7 +94,13 @@ Instances of this class represent the Root of the :cpp:class:`SchemaNode<SchemaN

:return: An empty statement.

.. cpp:function:: virtual Rpc* rpc(const std::string& path) const
.. cpp:function:: virtual std::vector<Statement> get_keys() const

Returns vector of YANG statement corresponding the the keys.

:return: Vector of :cpp:class:`Statement` that represent keys.

.. cpp:function:: virtual Rpc* create_rpc(const std::string& path) const

Create an :cpp:class:`Rpc<Rpc>` instance.

Expand Down
12 changes: 6 additions & 6 deletions sdk/cpp/core/docsgen/api/nodes/core_node_schema.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Represents a Node in the SchemaTree.

A :cpp:class:`SchemaNode<SchemaNode>` represents a containment hierarchy. So invocation of the destructor will lead to the children of this node being destroyed.

.. cpp:function:: virtual std::string path() const
.. cpp:function:: virtual std::string get_path() const

Get the path expression representing this Node in in the NodeTree.

Expand All @@ -41,31 +41,31 @@ Represents a Node in the SchemaTree.
:raises: :cpp:class:`YCPPPathError<YCPPPathError>` if the path expression in invalid, see error code for details.
:raises: :cpp:class:`YCPPInvalidArgumentError<YCPPInvalidArgumentError>` if the argument is invalid.

.. cpp:function:: virtual const SchemaNode* parent() const noexcept
.. cpp:function:: virtual const SchemaNode* get_parent() const noexcept

Get the Parent Node of this SchemaNode in the tree.

:return: ``SchemaNode*`` the children of this node.

.. cpp:function:: virtual std::vector<std::unique_ptr<SchemaNode>> & children() const
.. cpp:function:: virtual std::vector<std::unique_ptr<SchemaNode>> & get_children() const

Returns the children of this :cpp:class:`SchemaNode <SchemaNode>` in the NodeTree.

:return: Child schema nodes.

.. cpp:function:: virtual const SchemaNode& root() const noexcept
.. cpp:function:: virtual const SchemaNode& get_root() const noexcept

Get the root of NodeTree this node is part of

:return: The pointer to the root.

.. cpp:function:: virtual Statement statement() const
.. cpp:function:: virtual Statement get_statement() const

Returns the YANG statement associated with this :cpp:class:`SchemaNode<SchemaNode>`

:return: The pointer to the yang statement for this :cpp:class:`SchemaNode<SchemaNode>`

.. cpp:function:: virtual std::vector<Statement> keys() const
.. cpp:function:: virtual std::vector<Statement> get_keys() const

Returns vector of YANG statement corresponding the the keys.

Expand Down
4 changes: 2 additions & 2 deletions sdk/cpp/core/docsgen/api/rpc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ if any. The Callable takes as a parameter the :cpp:class:`ServiceProvider<Servic
:param sp: The Service provider.
:return: Pointer to the :cpp:class:`DataNode<DataNode>` or ``nullptr`` if none exists.

.. cpp:function:: virtual DataNode& input() const
.. cpp:function:: virtual DataNode& get_input_node() const

Get the input data tree.

:return: Pointer to the input :cpp:class:`DataNode<DataNode>` or ``nullptr`` if the rpc does not have an input element in the schema.

.. cpp:function:: virtual SchemaNode& schema() const
.. cpp:function:: virtual SchemaNode& get_schema_node() const

:return: Pointer to the :cpp:class:`SchemaNode<SchemaNode>` associated with this rpc.
32 changes: 16 additions & 16 deletions sdk/cpp/core/samples/bgp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

void print_paths(ydk::path::SchemaNode & sn)
{
std::cout << sn.path() << std::endl;
for(auto const& p : sn.children())
std::cout << sn.get_path() << std::endl;
for(auto const& p : sn.get_children())
print_paths(*p);
}

Expand All @@ -30,31 +30,31 @@ void test_bgp_create()
ydk::path::RootSchemaNode& schema = sp.get_root_schema();
print_paths(schema);

auto & bgp = schema.create("openconfig-bgp:bgp", "");
auto & bgp = schema.create_datanode("openconfig-bgp:bgp", "");

// get the root
// std::unique_ptr<const ydk::path::DataNode> data_root{bgp->root()};
// std::unique_ptr<const ydk::path::DataNode> data_root{bgp->get_root()};

bgp.create("global/config/as", "65172");
bgp.create_datanode("global/config/as", "65172");


auto & l3vpn_ipv4_unicast = bgp.create("global/afi-safis/afi-safi[afi-safi-name='openconfig-bgp-types:L3VPN_IPV4_UNICAST']", "");
l3vpn_ipv4_unicast.create("config/afi-safi-name", "openconfig-bgp-types:L3VPN_IPV4_UNICAST");
auto & l3vpn_ipv4_unicast = bgp.create_datanode("global/afi-safis/afi-safi[afi-safi-name='openconfig-bgp-types:L3VPN_IPV4_UNICAST']", "");
l3vpn_ipv4_unicast.create_datanode("config/afi-safi-name", "openconfig-bgp-types:L3VPN_IPV4_UNICAST");


// set the enable flag
l3vpn_ipv4_unicast.create("config/enabled","true");
l3vpn_ipv4_unicast.create_datanode("config/enabled","true");

// bgp/neighbors/neighbor
auto & neighbor = bgp.create("neighbors/neighbor[neighbor-address='172.16.255.2']", "");
neighbor.create("config/neighbor-address", "172.16.255.2");
neighbor.create("config/peer-as","65172");
auto & neighbor = bgp.create_datanode("neighbors/neighbor[neighbor-address='172.16.255.2']", "");
neighbor.create_datanode("config/neighbor-address", "172.16.255.2");
neighbor.create_datanode("config/peer-as","65172");


// bgp/neighbors/neighbor/afi-safis/afi-safi
auto & neighbor_af = neighbor.create("afi-safis/afi-safi[afi-safi-name='openconfig-bgp-types:L3VPN_IPV4_UNICAST']", "");
neighbor_af.create("config/afi-safi-name" , "openconfig-bgp-types:L3VPN_IPV4_UNICAST");
neighbor_af.create("config/enabled","true");
auto & neighbor_af = neighbor.create_datanode("afi-safis/afi-safi[afi-safi-name='openconfig-bgp-types:L3VPN_IPV4_UNICAST']", "");
neighbor_af.create_datanode("config/afi-safi-name" , "openconfig-bgp-types:L3VPN_IPV4_UNICAST");
neighbor_af.create_datanode("config/enabled","true");

ydk::path::Codec s {};
auto xml = s.encode(bgp, ydk::EncodingFormat::XML, true);
Expand Down Expand Up @@ -90,8 +90,8 @@ void test_bgp_create()


// TODO fix rpc
std::shared_ptr<ydk::path::Rpc> create_rpc { schema.rpc("ydk:create") };
create_rpc->input().create("entity", xml);
std::shared_ptr<ydk::path::Rpc> create_rpc { schema.create_rpc("ydk:create") };
create_rpc->get_input_node().create_datanode("entity", xml);

// call create
(*create_rpc)(sp);
Expand Down
8 changes: 4 additions & 4 deletions sdk/cpp/core/src/codec_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ CodecService::encode(CodecServiceProvider & provider, Entity & entity, bool pret
{
path::DataNode& datanode = get_data_node_from_entity(entity, root_schema);
const path::DataNode* dn = &datanode;
while(dn!= nullptr && dn->parent()!=nullptr)
dn = dn->parent();
while(dn!= nullptr && dn->get_parent()!=nullptr)
dn = dn->get_parent();
path::Codec core_codec_service{};
std::string result = core_codec_service.encode(*dn, provider.m_encoding, pretty);
YLOG_INFO("Performing encode operation, resulting in {}", result);
Expand Down Expand Up @@ -118,14 +118,14 @@ CodecService::decode(CodecServiceProvider & provider, const std::string & payloa
path::Codec core_codec_service{};
auto root_data_node = core_codec_service.decode(root_schema, payload, provider.m_encoding);

if (root_data_node->children().size() != 1)
if (root_data_node->get_children().size() != 1)
{
YLOG_ERROR(PAYLOAD_ERROR_MSG);
throw(YCPPServiceProviderError(PAYLOAD_ERROR_MSG));
}
else
{
for (auto data_node: root_data_node->children())
for (auto data_node: root_data_node->get_children())
{
get_entity_from_data_node(data_node.get(), entity);
// Required for validation of decoded entity
Expand Down
12 changes: 6 additions & 6 deletions sdk/cpp/core/src/crud_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ shared_ptr<Entity> CrudService::read_datanode(Entity & filter, shared_ptr<path::
if (read_data_node == nullptr)
return {};
shared_ptr<Entity> top_entity = get_top_entity_from_filter(filter);
get_entity_from_data_node(read_data_node->children()[0].get(), top_entity);
get_entity_from_data_node(read_data_node->get_children()[0].get(), top_entity);
return top_entity;
}

Expand All @@ -117,7 +117,7 @@ static shared_ptr<path::DataNode> execute_rpc(path::ServiceProvider & provider,
// validation.validate(provider, entity, ValidationService::Option::DATASTORE);
// }
path::RootSchemaNode& root_schema = provider.get_root_schema();
shared_ptr<ydk::path::Rpc> ydk_rpc { root_schema.rpc(operation) };
shared_ptr<ydk::path::Rpc> ydk_rpc { root_schema.create_rpc(operation) };
string data;
if(data_tag == "filter" && provider.get_encoding() == EncodingFormat::XML)
{
Expand All @@ -130,9 +130,9 @@ static shared_ptr<path::DataNode> execute_rpc(path::ServiceProvider & provider,

if(set_config_flag)
{
ydk_rpc->input().create("only-config");
ydk_rpc->get_input_node().create_datanode("only-config");
}
ydk_rpc->input().create(data_tag, data);
ydk_rpc->get_input_node().create_datanode(data_tag, data);
return (*ydk_rpc)(provider);
}

Expand All @@ -141,8 +141,8 @@ static string get_config_data_payload(Entity & entity, path::ServiceProvider & p
const ydk::path::DataNode& datanode = get_data_node_from_entity(entity, provider.get_root_schema());

const path::DataNode* dn = &datanode;
while(dn!= nullptr && dn->parent()!=nullptr)
dn = dn->parent();
while(dn!= nullptr && dn->get_parent()!=nullptr)
dn = dn->get_parent();
path::Codec codec{};
YLOG_DEBUG("Encoding the subtree filter request using path API DataNode");
string payload = codec.encode(*dn, provider.get_encoding(), false);
Expand Down
Loading