Vinod Kumar S
Committed by Gerrit Code Review

[ONOS-3892] implement YANG leaf data model

Change-Id: I996d4d3d60a0ad2142e173c6ba26c9cc355ccc80
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.yangutils.datamodel;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
/*
* Reference:RFC 6020.
* The "import" statement makes definitions from one module available
* inside another module or submodule. The argument is the name of the
* module to import, and the statement is followed by a block of
* sub statements that holds detailed import information.
* When a module is imported, the importing module may:
* o use any grouping and typedef defined at the top level in the
* imported module or its submodules.
*
* o use any extension, feature, and identity defined in the imported
* module or its submodules.
*
* o use any node in the imported module's schema tree in "must",
* "path", and "when" statements, or as the target node in "augment"
* and "deviation" statements.
*
* The mandatory "prefix" sub statement assigns a prefix for the imported
* module that is scoped to the importing module or submodule. Multiple
* "import" statements may be specified to import from different
* modules.
* When the optional "revision-date" sub-statement is present, any
* typedef, grouping, extension, feature, and identity referenced by
* definitions in the local module are taken from the specified revision
* of the imported module. It is an error if the specified revision of
* the imported module does not exist. If no "revision-date"
* sub-statement is present, it is undefined from which revision of the
* module they are taken.
*
* Multiple revisions of the same module MUST NOT be imported.
*
* The import's Substatements
*
* +---------------+---------+-------------+------------------+
* | substatement | section | cardinality |data model mapping|
* +---------------+---------+-------------+------------------+
* | prefix | 7.1.4 | 1 | string |
* | revision-date | 7.1.5.1 | 0..1 | string |
* +---------------+---------+-------------+------------------+
*/
/**
* Maintains the information about the imported modules.
*/
public class YangImport implements Parsable {
/**
* Name of the module that is being imported.
*/
private String name;
/**
* Prefix used to identify the entities from the imported module.
*/
private String prefixId;
/**
* Reference:RFC 6020.
* The import's "revision-date" statement is used to specify the exact
* version of the module to import. The "revision-date" statement MUST match
* the most recent "revision" statement in the imported module. organization
* which defined the YANG module.
*/
private String revision;
/**
* Default constructor.
*/
public YangImport() {
}
/**
* Get the imported module name.
*
* @return the module name.
*/
public String getModuleName() {
return name;
}
/**
* Set module name.
*
* @param moduleName the module name to set
*/
public void setModuleName(String moduleName) {
name = moduleName;
}
/**
* Get the prefix used to identify the entities from the imported module.
*
* @return the prefix used to identify the entities from the imported
* module.
*/
public String getPrefixId() {
return prefixId;
}
/**
* Set prefix identifier.
*
* @param prefixId set the prefix identifier of the imported module.
*/
public void setPrefixId(String prefixId) {
this.prefixId = prefixId;
}
/**
* Get the revision of the imported module.
*
* @return the revision of the imported module.
*/
public String getRevision() {
return revision;
}
/**
* Set the revision of the imported module.
*
* @param rev set the revision of the imported module.
*/
public void setRevision(String rev) {
revision = rev;
}
/**
* Returns the type of the parsed data.
*
* @return returns IMPORT_DATA
*/
public ParsableDataType getParsableDataType() {
return ParsableDataType.IMPORT_DATA;
}
/**
* Validate the data on entering the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules
*/
public void validateDataOnEntry() throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
/**
* Validate the data on exiting the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules
*/
public void validateDataOnExit() throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
}
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.yangutils.datamodel;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
/*
* Reference:RFC 6020.
* The "include" statement is used to make content from a submodule
* available to that submodule's parent module, or to another submodule
* of that parent module. The argument is an identifier that is the
* name of the submodule to include.
* The includes's Substatements
*
* +---------------+---------+-------------+------------------+
* | substatement | section | cardinality |data model mapping|
* +---------------+---------+-------------+------------------+
* | revision-date | 7.1.5.1 | 0..1 | string |
* +---------------+---------+-------------+------------------+
*/
/**
* Maintains the information about the included sub-modules.
*
*/
public class YangInclude implements Parsable {
/**
* Name of the sub-module that is being included.
*/
private String subModuleName;
/**
* The include's "revision-date" statement is used to specify the exact
* version of the submodule to import.
*/
private String revision;
/**
* Default constructor.
*/
public YangInclude() {
}
/**
* Get the name of included sub-module.
*
* @return the sub-module name
*/
public String getSubModuleName() {
return subModuleName;
}
/**
* Set the name of included sub-modules.
*
* @param subModuleName the sub-module name to set
*/
public void setSubModuleName(String subModuleName) {
this.subModuleName = subModuleName;
}
/**
* Get the revision.
*
* @return the revision
*/
public String getRevision() {
return revision;
}
/**
* Set the revision.
*
* @param revision the revision to set
*/
public void setRevision(String revision) {
this.revision = revision;
}
/**
* Returns the type of parsed data.
*
* @return returns INCLUDE_DATA
*/
public ParsableDataType getParsableDataType() {
return ParsableDataType.INCLUDE_DATA;
}
/**
* Validate the data on entering the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules
*/
public void validateDataOnEntry() throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
/**
* Validate the data on exiting the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules
*/
public void validateDataOnExit() throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
}
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.yangutils.datamodel;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
/*
* Reference:RFC 6020.
* The "leaf" statement is used to define a leaf node in the schema
* tree. It takes one argument, which is an identifier, followed by a
* block of sub-statements that holds detailed leaf information.
*
* A leaf node has a value, but no child nodes in the data tree.
* Conceptually, the value in the data tree is always in the canonical
* form.
*
* A leaf node exists in zero or one instances in the data tree.
*
* The "leaf" statement is used to define a scalar variable of a
* particular built-in or derived type.
*
* The leaf's sub-statements
*
* +--------------+---------+-------------+------------------+
* | substatement | section | cardinality |data model mapping|
* +--------------+---------+-------------+------------------+
* | config | 7.19.1 | 0..1 | - boolean |
* | default | 7.6.4 | 0..1 | - TODO |
* | description | 7.19.3 | 0..1 | - string |
* | if-feature | 7.18.2 | 0..n | - TODO |
* | mandatory | 7.6.5 | 0..1 | - boolean |
* | must | 7.5.3 | 0..n | - TODO |
* | reference | 7.19.4 | 0..1 | - string |
* | status | 7.19.2 | 0..1 | - YangStatus |
* | type | 7.6.3 | 1 | - YangType |
* | units | 7.3.3 | 0..1 | - String |
* | when | 7.19.5 | 0..1 | - TODO |
* +--------------+---------+-------------+------------------+
*/
/**
* Leaf data represented in YANG.
*
* @param <T> YANG data type
*/
public class YangLeaf<T> implements YangCommonInfo, Parsable {
/**
* Name of leaf.
*/
private String name;
/**
* If the leaf is a config parameter.
*/
private boolean isConfig;
/**
* description of leaf.
*/
private String description;
/**
* If mandatory leaf.
*/
private boolean isMandatory;
/**
* The textual reference to this leaf.
*/
private String reference;
/**
* Status of leaf in YANG definition.
*/
private YangStatusType status;
/**
* Textual units info.
*/
private String units;
/**
* Data type of the leaf.
*/
private YangType<T> dataType;
/**
* Default constructor to create a YANG leaf.
*/
public YangLeaf() {
}
/**
* Get the name of leaf.
*
* @return the leaf name.
*/
public String getLeafName() {
return name;
}
/**
* Set the name of leaf.
*
* @param leafName the leaf name to set.
*/
public void setLeafName(String leafName) {
this.name = leafName;
}
/**
* Get the config flag.
*
* @return if config flag.
*/
public boolean isConfig() {
return isConfig;
}
/**
* Set the config flag.
*
* @param isCfg the flag value to set.
*/
public void setConfig(boolean isCfg) {
isConfig = isCfg;
}
/**
* Get the description.
*
* @return the description.
*/
public String getDescription() {
return description;
}
/**
* Set the description.
*
* @param description set the description.
*/
public void setDescription(String description) {
this.description = description;
}
/**
* Get if the leaf is mandatory.
*
* @return if leaf is mandatory.
*/
public boolean isMandatory() {
return isMandatory;
}
/**
* Set if the leaf is mandatory.
*
* @param isReq if the leaf is mandatory
*/
public void setMandatory(boolean isReq) {
isMandatory = isReq;
}
/**
* Get the textual reference.
*
* @return the reference.
*/
public String getReference() {
return reference;
}
/**
* Set the textual reference.
*
* @param reference the reference to set.
*/
public void setReference(String reference) {
this.reference = reference;
}
/**
* Get the status.
*
* @return the status.
*/
public YangStatusType getStatus() {
return status;
}
/**
* Set the status.
*
* @param status the status to set.
*/
public void setStatus(YangStatusType status) {
this.status = status;
}
/**
* Get the units.
*
* @return the units.
*/
public String getUnits() {
return units;
}
/**
* Set the units.
*
* @param units the units to set.
*/
public void setUnits(String units) {
this.units = units;
}
/**
* Get the data type.
*
* @return the data type.
*/
public YangType<T> getDataType() {
return dataType;
}
/**
* Set the data type.
*
* @param dataType the data type to set.
*/
public void setDataType(YangType<T> dataType) {
this.dataType = dataType;
}
/**
* Returns the type of the parsed data.
*
* @return returns LEAF_DATA.
*/
public ParsableDataType getParsableDataType() {
return ParsableDataType.LEAF_DATA;
}
/**
* Validate the data on entering the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
*/
public void validateDataOnEntry() throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
/**
* Validate the data on exiting the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
*/
public void validateDataOnExit() throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
}
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.yangutils.datamodel;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
/*
* Reference:RFC 6020.
* Where the "leaf" statement is used to define a simple scalar variable
* of a particular type, the "leaf-list" statement is used to define an
* array of a particular type. The "leaf-list" statement takes one
* argument, which is an identifier, followed by a block of
* sub-statements that holds detailed leaf-list information.
*
* The values in a leaf-list MUST be unique.
*
* The leaf-list's sub-statements
*
* +--------------+---------+-------------+------------------+
* | substatement | section | cardinality |data model mapping|
* +--------------+---------+-------------+------------------+
* | config | 7.19.1 | 0..1 | -boolean |
* | description | 7.19.3 | 0..1 | -string |
* | if-feature | 7.18.2 | 0..n | -TODO |
* | max-elements | 7.7.4 | 0..1 | -int |
* | min-elements | 7.7.3 | 0..1 | -int |
* | must | 7.5.3 | 0..n | -TODO |
* | ordered-by | 7.7.5 | 0..1 | -TODO |
* | reference | 7.19.4 | 0..1 | -string |
* | status | 7.19.2 | 0..1 | -YangStatus |
* | type | 7.4 | 1 | -YangType |
* | units | 7.3.3 | 0..1 | -string |
* | when | 7.19.5 | 0..1 | -TODO |
* +--------------+---------+-------------+------------------+
*/
/**
* Leaf-list data represented in YANG.
*
* @param <T> YANG data type
*/
public class YangLeafList<T> implements YangCommonInfo, Parsable {
/**
* Name of leaf-list.
*/
private String name;
/**
* If the leaf-list is a config parameter.
*/
private boolean isConfig;
/**
* Description of leaf-list.
*/
private String description;
/**
* Reference:RFC 6020.
* The "max-elements" statement, which is optional, takes as an argument a
* positive integer or the string "unbounded", which puts a constraint on
* valid list entries. A valid leaf-list or list always has at most
* max-elements entries.
*
* If no "max-elements" statement is present, it defaults to "unbounded".
*/
private int maxElelements;
/**
* Reference:RFC 6020.
* The "min-elements" statement, which is optional, takes as an argument a
* non-negative integer that puts a constraint on valid list entries. A
* valid leaf-list or list MUST have at least min-elements entries.
*
* If no "min-elements" statement is present, it defaults to zero.
*
* The behavior of the constraint depends on the type of the leaf-list's or
* list's closest ancestor node in the schema tree that is not a non-
* presence container:
*
* o If this ancestor is a case node, the constraint is enforced if any
* other node from the case exists.
*
* o Otherwise, it is enforced if the ancestor node exists.
*/
private int minElements;
/**
* The textual reference to this leaf-list.
*/
private String reference;
/**
* Status of the leaf-list in the YANG definition.
*/
private YangStatusType status;
/**
* Textual units.
*/
private String units;
/**
* Data type of leaf-list.
*/
private YangType<T> dataType;
/**
* Default Constructor to create a YANG leaf-list.
*/
public YangLeafList() {
}
/**
* Get the leaf-list name.
*
* @return the leaf-list name.
*/
public String getLeafName() {
return name;
}
/**
* Set the leaf-list name.
*
* @param leafListName the leaf-list name to set.
*/
public void setLeafName(String leafListName) {
this.name = leafListName;
}
/**
* Get the config flag.
*
* @return the config flag.
*/
public boolean isConfig() {
return isConfig;
}
/**
* Set the config flag.
*
* @param isCfg the config flag.
*/
public void setConfig(boolean isCfg) {
isConfig = isCfg;
}
/**
* Get the description.
*
* @return the description.
*/
public String getDescription() {
return description;
}
/**
* Set the description.
*
* @param description set the description.
*/
public void setDescription(String description) {
this.description = description;
}
/**
* Get the max elements no.
*
* @return the max elements no.
*/
public int getMaxElelements() {
return maxElelements;
}
/**
* Set the max elements no.
*
* @param maxElelements max elements no.
*/
public void setMaxElelements(int maxElelements) {
this.maxElelements = maxElelements;
}
/**
* Get the min elements no.
*
* @return the min elements no.
*/
public int getMinElements() {
return minElements;
}
/**
* Set the min elements no.
*
* @param minElements the min elements no.
*/
public void setMinElements(int minElements) {
this.minElements = minElements;
}
/**
* Get the textual reference.
*
* @return the reference.
*/
public String getReference() {
return reference;
}
/**
* Set the textual reference.
*
* @param reference the reference to set.
*/
public void setReference(String reference) {
this.reference = reference;
}
/**
* Get the status.
*
* @return the status.
*/
public YangStatusType getStatus() {
return status;
}
/**
* Set the status.
*
* @param status the status to set.
*/
public void setStatus(YangStatusType status) {
this.status = status;
}
/**
* Get the units.
*
* @return the units.
*/
public String getUnits() {
return units;
}
/**
* Set the units.
*
* @param units the units to set.
*/
public void setUnits(String units) {
this.units = units;
}
/**
* Get the data type.
*
* @return the data type.
*/
public YangType<T> getDataType() {
return dataType;
}
/**
* Set the data type.
*
* @param dataType the data type to set.
*/
public void setDataType(YangType<T> dataType) {
this.dataType = dataType;
}
/**
* Returns the type of the parsed data.
*
* @return returns LEAF_LIST_DATA.
*/
public ParsableDataType getParsableDataType() {
return ParsableDataType.LEAF_LIST_DATA;
}
/**
* Validate the data on entering the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
*/
public void validateDataOnEntry() throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
/**
* Validate the data on exiting the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
*/
public void validateDataOnExit() throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
}
/*Copyright 2016.year Open Networking Laboratory
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.*/
package org.onosproject.yangutils.datamodel;
import java.util.List;
/**
* Abstraction of atomic configurable/status entity. It is used to abstract the
* data holders of leaf or leaf list. Used in leaves parsing or attribute code
* generation.
*/
public interface YangLeavesHolder {
/**
* Get the list of leaves from data holder like container / list.
*
* @return the list of leaves.
*/
@SuppressWarnings("rawtypes")
public List<YangLeaf> getListOfLeaf();
/**
* Add a leaf in data holder like container / list.
*
* @param leaf the leaf to be added.
*/
void addLeaf(YangLeaf<?> leaf);
/**
* Get the list of leaf-list from data holder like container / list.
*
* @return the list of leaf-list.
*/
@SuppressWarnings("rawtypes")
List<YangLeafList> getListOfLeafList();
/**
* Add a leaf-list in data holder like container / list.
*
* @param leafList the leaf-list to be added.
*/
void addLeafList(YangLeafList<?> leafList);
}