Vinod Kumar S
Committed by Gerrit Code Review

[ONOS-3895, ONOS-3896, ONOS-3897] Data type interfaces

Change-Id: I9cd9d80ce0accc017118a944dff96367bca89bde
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.yangutils.datamodel;
18 +
19 +/**
20 + * ENUM to identify the YANG data type.
21 + */
22 +public enum YangDataTypes {
23 + /**
24 + * Reference:RFC 6020.
25 + * int8 represents integer values between -128 and 127, inclusively.
26 + */
27 + INT8,
28 +
29 + /**
30 + * Reference:RFC 6020.
31 + * int16 represents integer values between -32768 and 32767, inclusively.
32 + */
33 + INT16,
34 +
35 + /**
36 + * Reference:RFC 6020.
37 + * int32 represents integer values between -2147483648 and 2147483647,
38 + * inclusively.
39 + */
40 + INT32,
41 +
42 + /**
43 + * Reference:RFC 6020.
44 + * int64 represents integer values between -9223372036854775808 and
45 + * 9223372036854775807, inclusively.
46 + */
47 + INT64,
48 +
49 + /**
50 + * Reference:RFC 6020.
51 + * uint8 represents integer values between 0 and 255, inclusively.
52 + */
53 + UINT8,
54 +
55 + /**
56 + * Reference:RFC 6020.
57 + * uint16 represents integer values between 0 and 65535, inclusively.
58 + */
59 + UINT16,
60 +
61 + /**
62 + * Reference:RFC 6020.
63 + * uint32 represents integer values between 0 and 4294967295, inclusively.
64 + */
65 + UINT32,
66 +
67 + /**
68 + * Reference:RFC 6020.
69 + * uint64 represents integer values between 0 and 18446744073709551615,
70 + * inclusively.
71 + */
72 + UINT64,
73 +
74 + /**
75 + * Reference:RFC 6020.
76 + * The decimal64 type represents a subset of the real numbers, which can be
77 + * represented by decimal numerals. The value space of decimal64 is the set
78 + * of numbers that can be obtained by multiplying a 64-bit signed integer by
79 + * a negative power of ten, i.e., expressible as "i x 10^-n" where i is an
80 + * integer64 and n is an integer between 1 and 18, inclusively.
81 + */
82 + DECIMAL64, // TODO: need to implement in type.
83 +
84 + /**
85 + * Reference:RFC 6020.
86 + * The string built-in type represents human-readable strings in YANG. Legal
87 + * characters are tab, carriage return, line feed, and the legal characters
88 + * of Unicode and ISO/IEC 10646
89 + */
90 + STRING,
91 +
92 + /**
93 + * Reference:RFC 6020.
94 + * The boolean built-in type represents a boolean value.
95 + */
96 + BOOLEAN,
97 +
98 + /**
99 + * Reference:RFC 6020.
100 + * The enumeration built-in type represents values from a set of assigned
101 + * names.
102 + */
103 + ENUMERATION,
104 +
105 + /**
106 + * Reference:RFC 6020.
107 + * The bits built-in type represents a bit set. That is, a bits value is a
108 + * set of flags identified by small integer position numbers starting at 0.
109 + * Each bit number has an assigned name.
110 + */
111 + BITS,
112 +
113 + /**
114 + * Reference:RFC 6020.
115 + * The binary built-in type represents any binary data, i.e., a sequence of
116 + * octets.
117 + */
118 + BINARY,
119 +
120 + /**
121 + * Reference:RFC 6020.
122 + * The leafref type is used to reference a particular leaf instance in the
123 + * data tree. The "path" sub-statement (Section 9.9.2) selects a set of leaf
124 + * instances, and the leafref value space is the set of values of these leaf
125 + * instances.
126 + *
127 + * If the leaf with the leafref type represents configuration data, the leaf
128 + * it refers to MUST also represent configuration. Such a leaf puts a
129 + * constraint on valid data. All leafref nodes MUST reference existing leaf
130 + * instances or leafs with default values in use for the data to be valid.
131 + *
132 + * There MUST NOT be any circular chains of leafrefs.
133 + *
134 + * If the leaf that the leafref refers to is conditional based on one or
135 + * more features, then the leaf with the leafref type MUST also be
136 + * conditional based on at least the same set of features.
137 + */
138 + LEAFREF, // TODO: need to implement in type.
139 +
140 + /**
141 + * Reference:RFC 6020.
142 + * The identityref type is used to reference an existing identity.
143 + */
144 + IDENTITYREF,
145 +
146 + /**
147 + * Reference:RFC 6020.
148 + * The empty built-in type represents a leaf that does not have any value,
149 + * it conveys information by its presence or absence.
150 + *
151 + * An empty type cannot have a default value.
152 + */
153 + EMPTY,
154 +
155 + /**
156 + * Reference:RFC 6020.
157 + * The union built-in type represents a value that corresponds to one of its
158 + * member types.
159 + *
160 + * When the type is "union", the "type" statement MUST be present. It is
161 + * used to repeatedly specify each member type of the union. It takes as an
162 + * argument a string that is the name of a member type.
163 + *
164 + * A member type can be of any built-in or derived type, except it MUST NOT
165 + * be one of the built-in types "empty" or "leafref".
166 + *
167 + * When a string representing a union data type is validated, the string is
168 + * validated against each member type, in the order they are specified in
169 + * the "type" statement, until a match is found.
170 + *
171 + * Any default value or "units" property defined in the member types is not
172 + * inherited by the union type.
173 + */
174 + UNION,
175 +
176 + /**
177 + * Reference:RFC 6020.
178 + * The instance-identifier built-in type is used to uniquely identify a
179 + * particular instance node in the data tree.
180 + *
181 + * The syntax for an instance-identifier is a subset of the XPath
182 + * abbreviated syntax, formally defined by the rule "instance-identifier".
183 + * It is used to uniquely identify a node in the data tree. Predicates are
184 + * used only for specifying the values for the key nodes for list entries, a
185 + * value of a leaf-list entry, or a positional index for a list without
186 + * keys. For identifying list entries with keys, each predicate consists of
187 + * one equality test per key, and each key MUST have a corresponding
188 + * predicate.
189 + *
190 + * If the leaf with the instance-identifier type represents configuration
191 + * data, and the "require-instance" property is "true", the node it refers
192 + * to MUST also represent configuration. Such a leaf puts a constraint on
193 + * valid data. All such leaf nodes MUST reference existing nodes or leaf
194 + * nodes with their default value in use for the data to be valid.
195 + */
196 + INSTANCE_IDENTIFIER,
197 +
198 + /**
199 + * Derived Data type.
200 + */
201 + DERIVED
202 +}
...@@ -151,7 +151,7 @@ public abstract class YangNode { ...@@ -151,7 +151,7 @@ public abstract class YangNode {
151 * @param newChild refers to a child to be added 151 * @param newChild refers to a child to be added
152 * @throws DataModelException due to violation in data model rules 152 * @throws DataModelException due to violation in data model rules
153 */ 153 */
154 - void addChild(YangNode newChild) throws DataModelException { 154 + public void addChild(YangNode newChild) throws DataModelException {
155 if (newChild.getNodeType() == null) { 155 if (newChild.getNodeType() == null) {
156 throw new DataModelException("Abstract node cannot be inserted into a tree"); 156 throw new DataModelException("Abstract node cannot be inserted into a tree");
157 } 157 }
......
1 +/*Copyright 2016.year Open Networking Laboratory
2 +
3 +Licensed under the Apache License, Version 2.0 (the "License");
4 +you may not use this file except in compliance with the License.
5 +You may obtain a copy of the License at
6 +
7 + http://www.apache.org/licenses/LICENSE-2.0
8 +
9 +Unless required by applicable law or agreed to in writing, software
10 +distributed under the License is distributed on an "AS IS" BASIS,
11 +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 +See the License for the specific language governing permissions and
13 +limitations under the License.*/
14 +package org.onosproject.yangutils.datamodel;
15 +
16 +/**
17 + * Abstraction for status on a YANG entity. Abstracted to unify the parsing and
18 + * translator processing of status.
19 + */
20 +public interface YangStatus {
21 + /**
22 + * Get the status.
23 + *
24 + * @return the status
25 + */
26 + YangStatusType getStatus();
27 +
28 + /**
29 + * Set the status.
30 + *
31 + * @param status the status to set
32 + */
33 + void setStatus(YangStatusType status);
34 +}
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.yangutils.datamodel;
17 +
18 +/*
19 + * Reference:RFC 6020.
20 + * The "status" statement takes as an argument one of the strings
21 + * "current", "deprecated", or "obsolete". If no status is specified,
22 + * the default is "current".
23 + */
24 +
25 +/**
26 + * ENUM to represent the status of YANG entities.
27 + */
28 +public enum YangStatusType {
29 + /**
30 + * Reference:RFC 6020.
31 + * "current" means that the definition is current and valid.
32 + */
33 + CURRENT,
34 +
35 + /**
36 + * Reference:RFC 6020.
37 + * "deprecated" indicates an obsolete definition, but it permits new/
38 + * continued implementation in order to foster interoperability with
39 + * older/existing implementations.
40 + */
41 + DEPRECATED,
42 +
43 + /**
44 + * Reference:RFC 6020.
45 + * "obsolete" means the definition is obsolete and SHOULD NOT be implemented
46 + * and/or can be removed from implementations.
47 + */
48 + OBSOLETE
49 +}
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.yangutils.datamodel;
18 +
19 +import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
20 +import org.onosproject.yangutils.parser.Parsable;
21 +import org.onosproject.yangutils.parser.ParsableDataType;
22 +
23 +/*
24 + * Reference:RFC 6020.
25 + * The "type" statement takes as an argument a string that is the name
26 + * of a YANG built-in type or a derived type, followed by an optional
27 + * block of sub-statements that are used to put further restrictions
28 + * on the type.
29 + *
30 + * The restrictions that can be applied depend on the type being restricted.
31 + * The type's sub-statements
32 + *
33 + * +------------------+---------+-------------+------------------------------------+
34 + * | substatement | section | cardinality | mapped data type |
35 + * +------------------+---------+-------------+------------------------------------+
36 + * | bit | 9.7.4 | 0..n | - YangBit used in YangBits |
37 + * | enum | 9.6.4 | 0..n | - YangEnum used in YangEnumeration |
38 + * | length | 9.4.4 | 0..1 | - used for string |
39 + * | path | 9.9.2 | 0..1 | - TODO leaf-ref |
40 + * | pattern | 9.4.6 | 0..n | - used for string |
41 + * | range | 9.2.4 | 0..1 | - used for integer data type |
42 + * | require-instance | 9.13.2 | 0..1 | - TODO instance-identifier |
43 + * | type | 7.4 | 0..n | - TODO union |
44 + * +------------------+---------+-------------+------------------------------------+
45 + */
46 +
47 +/**
48 + * Maintains the data type information.
49 + *
50 + * @param <T> YANG data type info.
51 + */
52 +public class YangType<T> implements Parsable {
53 +
54 + /**
55 + * YANG data type name.
56 + */
57 + private String dataTypeName;
58 +
59 + /**
60 + * YANG data type.
61 + */
62 + private YangDataTypes dataType;
63 +
64 + private T dataTypeInfo;
65 +
66 + /**
67 + * Default constructor.
68 + */
69 + public YangType() {
70 + }
71 +
72 + /**
73 + * Get the name of data type.
74 + *
75 + * @return the name of data type.
76 + */
77 + public String getDataTypeName() {
78 + return dataTypeName;
79 + }
80 +
81 + /**
82 + * Set the name of the data type.
83 + *
84 + * @param typeName the name to set
85 + */
86 + public void setDataTypeName(String typeName) {
87 + dataTypeName = typeName;
88 + }
89 +
90 + /**
91 + * Get the type of data.
92 + *
93 + * @return the data type.
94 + */
95 + public YangDataTypes getDataType() {
96 + return dataType;
97 + }
98 +
99 + /**
100 + * Set the type of data.
101 + *
102 + * @param dataType data type.
103 + */
104 + public void setDataType(YangDataTypes dataType) {
105 + this.dataType = dataType;
106 + }
107 +
108 + /**
109 + * Get the data type meta data.
110 + *
111 + * @return the data type meta data.
112 + */
113 + public T getDataTypeInfo() {
114 + return dataTypeInfo;
115 + }
116 +
117 + /**
118 + * Set the data type meta data.
119 + *
120 + * @param dataTypeInfo the meta data to set
121 + */
122 + public void setDataTypeInfo(T dataTypeInfo) {
123 + this.dataTypeInfo = dataTypeInfo;
124 + }
125 +
126 + /**
127 + * Returns the type of the parsed data.
128 + *
129 + * @return returns TYPE_DATA.
130 + */
131 + public ParsableDataType getParsableDataType() {
132 + return ParsableDataType.TYPE_DATA;
133 + }
134 +
135 + /**
136 + * Validate the data on entering the corresponding parse tree node.
137 + *
138 + * @throws DataModelException a violation of data model rules.
139 + */
140 + public void validateDataOnEntry() throws DataModelException {
141 + // TODO auto-generated method stub, to be implemented by parser
142 +
143 + }
144 +
145 + /**
146 + * Validate the data on exiting the corresponding parse tree node.
147 + *
148 + * @throws DataModelException a violation of data model rules.
149 + */
150 + public void validateDataOnExit() throws DataModelException {
151 + // TODO auto-generated method stub, to be implemented by parser
152 +
153 + }
154 +}