...
| Name | Organization | |
|---|---|---|
| Adarsh M | Huawei Technologies | adarsh.m@huawei.com |
| Bharat Saraswal | Huawei Technologies | bharat.saraswal@huawei.com |
| Gaurav Agrawal | Huawei Technologies | gaurav.agrawal@huawei.com |
| Janani B | Huawei Technologies | janani.b@huawei.com |
| Sathish Kumar M | Huawei Technologies | sathishkumar.m@huawei.com |
| Suchitra H N | Huawei Technologies | suchitra.hn@huawei.com |
| Vidyashree Rama | Huawei Technologies | vidyashree.rama@huawei.com |
| Vinod Kumar S | Huawei Technologies | vinods.kumar@huawei.com |
Overview
YANG is a data modeling language used to model configuration & state data. Modeling languages such as SMI (SNMP), UML, XML Schema, and others already existed. However, none of these languages were specifically targeted to the needs of configuration management. They lacked critical capabilities like being easily read and understood by human implementers, and fell short in providing mechanisms to validate models of configuration data for semantics and syntax.
YANG Utils are the basic building block to achieve the final goal of abstracting the language based Syntax/Semantics processing by APPs.
...
Create a folder structure as “src/main/yang” in the test app folder and place your YANG files in it. If incase user want to give desired path for source YANG files and generated java files, the following configuration can be appended to the above pom.xml file.
Code Block <configuration> <yangFilesDir>/opt/src/yang/</yangFilesDir> <genFilesDir>/opt/src/java/</genFilesDir> </configuration>In YANG, identifier has the support of having “.”, ”-”, “_”. But, in java, we cannot use these characters in class name or attribute name. Hence, by default, these characters will be removed and the successive character will be capitalized for making it camel case. Similarly, in YANG, we can have java keywords and starting with digits, in namespace and identifiers. But, in java, we cannot use it in class name or attribute name or package. Hence, by default, a prefix "yangAutoPrefix" will be added to the identifier name.Here users are given options to change this default behaviour.“.”, ”-”, “_” in identifier name can be replaced by the values given inside the configuration of pom.xml and will be used in java, respectively. Similarly, the prefix value can also be provided in configuration of pom.xml and that will be used as prefix for identifiers.(refer identifier for more details)
Code Block <configuration> <replacementForPeriod>dot</replacementForPeriod> <replacementForHyphen>hyphen</replacementForHyphen> <replacementForUnderscore>underscore</replacementForUnderscore> <prefixForIdentifier>prefix</prefixForIdentifier> </configuration>yang-._constuct-generation will be mapped as yangHyphenDotUnderscoreConstuctHyphenGeneration
const will be mapped as prefixConst
Default package/folder structure for generated code will be constructed from the namespace of the YANG file and if user wants to generated code with specific folder structure/package he can configure it , using below configurations.
Code Block <configuration> <defaultPackage>org.onosproject.sfc</defaultPackage> </configuration>In above example code will be generated in org.onosproject.sfc package.As Grouping construct being an special case in YANG. we are giving user a flexibility to choose whether to generate code for grouping node or not. So if user does not wants to generate code he should set the configurations as false. By default code will be generated.
Code Block <configuration> <groupingCodeGenFlag>true</groupingCodeGenFlag> </configuration>In case of RPC construct we have given flexibility for controlling the generation of code for input and output sub statements in a special cases where Input or output contains only one leaf/leaf-list/Yang construct. In such case user can configure whether he wants to generate code for input or output. By default code will be generated and in case input or output contains multiple leaf/leaf-list/Yang constructs code will be generated even the configuration is false.
Code Block <configuration> <rpcSubStatementCodeGenFlag>true</rpcSubStatementCodeGenFlag> </configuration>
...
TESTNAME will be mapped to testname
TEST-NAME will be mapped to testName
TestName will be mapped to testName
TEST3NAME will be mapped to test3Name
Note : When the identifier has to be used as java class name, after the above conversion, the first letter will be capitalized and if consecutive capital letters are present, it will be corrected and assigned as java class name. |
|---|
Namespace
The namespace is a mandatory statement in the module. We define namespace for URL/URI and for folder structure of generated java code. Here in ONOS YANG plugin, namespace forms a folder structure which in turn will be the package name in java.
...