Reputation: 129
AS far as I understand, instance-identifier type has an XPath statement which points to some node is a tree. And what's next? How does instance-identifier identify this node? How do I apply instance-identifier to the node it points to? Or do I get it totally wrong... I also don't have any example of this except those found in google like
leaf instance-identifier-leaf {
type instance-identifier;
}
Upvotes: 1
Views: 1508
Reputation: 176
An instance-identifier can be a reference to any data node in the system. Think of it as a pointer; it doesn't contain the data itself, just a reference to it (e.g. an address) It is useful for example to represent a reference to an object that is modeled as a YANG container or list instance..
Given that YANG data can be expressed as an XML document, the way you 'point' to a specific element within that is therefore similar to 'pointing' to a specific XML element. The way you do that in XML is by using XPath, which allows to use a
Here's an example:
container a {
list b {
key x;
leaf x { type int8; }
list c {
key y;
leaf y { type int8; }
}
}
}
leaf ref {
type instance-identifier;
}
So imagine that a real system has its datastore containing this data (for simplification, I'm using XML format, and ignoring namespaces; a real system doesn't need to keep its datastore in XML format):
<a>
<b>
<x>1</x>
</b>
<b>
<x>5</x>
<c>
<y>1</y>
</c>
<c>
<y>2</y>
</c>
</b>
<b>
<x>10</x>
<c>
<y>5</y>
</c>
</b>
</a>
So basically we have a bunch of list entries, some of them cascaded. If you'd represent all these nodes in xpath, you'd get a list with:
/a
/a/b[x=1]
/a/b[x=5]
/a/b[x=5]/c[y=1]
/a/b[x=5]/c[y=2]
/a/b[x=10]
/a/b[x=10]/c[y=5]
If you had an instance identifier outside this hierarchy called ref, it could take any of these xpaths as possible values, as a string value. So it contain a reference to one of those nodes; it would not contain the node itself, just a reference to it.
One final note is that it is not mandatory that the node referenced by the instance-identifier actually exists in the datastore; you can have an instance-identifier that is pointing to a non-existent node. There is a yang statement (requires-instance) that can be added as a substatement of the type statement, that allows to control whether only existing instances can be referenced, or whether non-existing ones can also be accepted.
Regarding the format of the value, note that the way the instance-identifier is represented depends on the protocol you are using. An instance identifier in NETCONF is different from one in RESTCONF (although they are very similar). You could imagine a CLI to have a custom way to represent YANG objects, for example:
In short, the format depends on the protocol you are using.
Upvotes: 1