Table of Contents |
---|
Status | ||||||
---|---|---|---|---|---|---|
|
...
- https://docs.opendaylight.org/en/latest/developer-guide/yang-tools.html*
- https://git.opendaylight.org/gerrit/admin/repos/yangtools
- https://gerrit.onap.org/r/admin/repos/ccsdk/sli/plugins
- https://javadoc.io/doc/org.opendaylight.yangtools.yangtools
Additional Resources (still to be examined)
*Although this documentation link is to the latest ODL doc revision, it is very outdated and the code examples need significant updates, see findings in Mini-PoC below (bug reported: https://jira.opendaylight.org/browse/DOCS-126)
...
The package org.opendaylight.yangtools.yang.model.util.type
contains classes for all the possible data types including:
- BaseBinaryType
- BaseBitsType
- BaseBooleanType
- BaseDecimalType
- BaseEnumerationType
- BaseInt8Type
- BaseInt16Type
- BaseInt32Type
- BaseInt64Type
- BaseStringType
- BaseUint8Type
- BaseUint16Type
- BaseUint32Type
- BaseUint64Type
There are also some special data types such as:
- BaseEmptyType
- BaseIdentityrefType
- BaseInstanceIdentifierType
- BaseLeafrefType
- BaseUnionType
And also 'restricted' versions of the base types such as:
- RestrictedStringType
- RestrictedUint64Type
...
JSON
Validation
...
Datatypes and basic constraints
...
leaf response-code {
type string;
}
...
...
.yang.model.util.type
contains classes for all the possible data types including:
- BaseBinaryType
- BaseBitsType
- BaseBooleanType
- BaseDecimalType
- BaseEnumerationType
- BaseInt8Type
- BaseInt16Type
- BaseInt32Type
- BaseInt64Type
- BaseStringType
- BaseUint8Type
- BaseUint16Type
- BaseUint32Type
- BaseUint64Type
There are also some special data types such as:
- BaseEmptyType
- BaseIdentityrefType
- BaseInstanceIdentifierType
- BaseLeafrefType
- BaseUnionType
And also 'restricted' versions of the base types such as:
- RestrictedStringType
- RestrictedUint64Type
Description | Yang | Java Object View | Notes | XML Validation | JSON | |||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Datatypes and basic constraints | ||||||||||||
Basic String |
| TypeStatement TypeAwareDeclaredStatement.getType() | Yes | Yes | ||||||||
Mandatory Basic String |
|
| No | No | ||||||||
Limited String | leaf pnf-name { type string { length "0..256"; } |
| Yes | Yes | ||||||||
typedef (String) with pattern |
| Optional<MandatoryStatement> MandatoryStatementAwareDeclaredStatementList<PatternConstraint> RestrictedStringType. getMandatorygetPatternConstraints() | NoYes | NoYes | ||||||||
Limited Stringuint64 | leaf | pnf-name cid { type | string uint64 { | length range "0.. | 256503"; } | } | org.opendaylight.yangtools.yang.model.util.type.RestrictedUint64Type | Yes | Yes | typedef (String) with pattern | ||
typedef dotted-quad boolean with default value |
| List<PatternConstraint> RestrictedStringType.getPatternConstraints() | Yes | Yes | ||||||||
Limited uint64 | leaf cid { type uint64 { range "0..503"; } } | org.opendaylight.yangtools.yang.model.util.type.RestrictedUint64Type | Yes | Yes | ||||||||
boolean with default value |
|
| org.opendaylight.yangtools.yang.model.util.type.DerivedBooleanType | N/A | N/A | |||||||
Unique | ||||||||||||
Unique | list server { key "name"; unique "ip port"; leaf name { type string; } leaf ip { type dotted-quad; } leaf port { type uint32; } } | org.opendaylight.yangtools.yang.model.utilapi.typestmt.DerivedBooleanTypeUniqueStatement | N/A | N/A | ||||||||
Unique | ||||||||||||
Unique | No | No | ||||||||||
Choice | ||||||||||||
Choice | choice transfer-method { leaf transfer-interval { type string; uint64 { range "15..2880"; } leaf ip { type dotted-quad; units minutes; } leaf port transfer-on-commit { type uint32empty; } } | org.opendaylight.yangtools.yang.model.api.stmt.UniqueStatement | No | No | ||||||||
Choice | ||||||||||||
Choice | choice transfer-method { leaf transfer-interval { type uint64 { range "15..2880"; } units minutes; } leaf transfer-on-commit { type empty; } } | ChoiceStatement | N/A | N/A | ||||||||
Must | ||||||||||||
Must | leaf ifType { type enumeration { enum ethernet; enum atm; } } leaf ifMTU { type uint32; } must "ifType != 'ethernet' or " + "(ifType = 'ethernet' and ifMTU = 1500)" error-message 466px"An ethernet MTU must be 1500"; } | org.opendaylight.yangtools.yang.model.api.stmt. | ChoiceStatementErrorMessageStatement | N/A | N/A | |||||||
Must | ||||||||||||
Must | leaf ifType { type enumeration { enum ethernet; enum atm; } } leaf ifMTU { type uint32; } must "ifType != 'ethernet' or " + "(ifType = 'ethernet' and ifMTU = 1500)" error-message 466px"An ethernet MTU must be 1500"; } | No | No | |||||||||
When | ||||||||||||
When | leaf a {
type boolean;
}
leaf b {
type string;
when "../a = 'true'";
} | org.opendaylight.yangtools.yang.model.api.stmt. | ErrorMessageStatementNo | No | ||||||||
When | ||||||||||||
When | leaf a {
type boolean;
}
leaf b {
type string;
when "../a = 'true'";
} | WhenStatement | No | No | ||||||||
Extension | ||||||||||||
Extension declaration |
| N/A | ||||||||||
Extension usage | leaf attribute-with-temporal-storage { type string; cm-notify-api:store-state-ext "3d"; } |
| No | No | ||||||||
Extension | ||||||||||||
Extension declaration |
| N/A | Extension usage | leaf attribute-with-temporal-storage { type string; cm-notify-api:store-state-ext "3d"; } | org.opendaylight.yangtools.yang.model.api.stmt.UnrecognizedStatement
which extends public interface UnknownStatement<A> extends DeclaredStatement<A> { | N/A | ||||||
Augmentation | ||||||||||||
augment "server" { when "port = '8787'"; leaf enable-debug { type boolean; } } } | The additional leaf just appears in the SchemaTree (without any reference that it is an augmentation) | N/A | ||||||||||
RPC | ||||||||||||
rpc | rpc nbrlist-change-notification { | N/A | ||||||||||
rpc input | input { in a neighbor list for this fap service"; } | N/A | ||||||||||
rpc output | output { | N/A |
Yang Data Parsing and Validation
...
- As expected the parsing of string, originating form XML or JSON is done by the same code and the results are identical to those for XML Data Parsing
Conclusion
Pros
- EXTENSIVE - The YangTools model parser is comprehensive and covers all possible Yang Language elements we might require
- AVAILABLE - Extensively used throughout ONAP and ODL projects (able to convert to Java objects, code & API). These parsers are already used in many ONAP platform projects.
- MATURE CODE - Mature code, dates back to 2013 with contributions from many companies including Cisco and RedhatParsing and Redhat and Pantheon Tech. (No need for licenses, these are also open source Yang parser). ODL is open source.
- VALIDATION - Testing with parsing of JSON and XML data with validated for a a (parsed) model included. Files to objects and vice versa is possible. Model violation & compilation validation is available.
- OBJECTIVES - Meets our two high-level requirements & objectives. Parse models from SDC into Java objects relate to persistence of data. Parsing of documents compliant to those schemas.
Cons
- LEARNING CURVE - Due to its completeness it also is a complicated piece of software which will take some time to get familiar with.
- DOCUMENTATION - Documentation out of date, this page hopes to address that somewhat
...