Mahesh Poojary Huawei
Committed by Ray Milkey

[ONOS-4348] Yang Bits, Binary and Decimal64

Change-Id: I8e4e54a19a8f9634cbc56a07579a1730174f53f6
Showing 44 changed files with 1476 additions and 474 deletions
1 /*- 1 /*-
2 - * Copyright 2016 Open Networking Laboratory 2 + * Copyright 2016-present Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 package org.onosproject.yangutils.datamodel; 16 package org.onosproject.yangutils.datamodel;
17 17
18 import java.io.Serializable; 18 import java.io.Serializable;
19 +import java.math.BigDecimal;
19 import org.onosproject.yangutils.datamodel.utils.builtindatatype.DataTypeException; 20 import org.onosproject.yangutils.datamodel.utils.builtindatatype.DataTypeException;
20 import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangBuiltInDataTypeInfo; 21 import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangBuiltInDataTypeInfo;
21 import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes; 22 import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
...@@ -78,11 +79,12 @@ public final class BuiltInTypeObjectFactory implements Serializable { ...@@ -78,11 +79,12 @@ public final class BuiltInTypeObjectFactory implements Serializable {
78 case UINT64: { 79 case UINT64: {
79 return (T) new YangUint64(valueInStr); 80 return (T) new YangUint64(valueInStr);
80 } 81 }
82 + case DECIMAL64: {
83 + return (T) new YangDecimal64(new BigDecimal(valueInStr));
84 + }
81 default: { 85 default: {
82 throw new DataTypeException("YANG file error : Unsupported data type"); 86 throw new DataTypeException("YANG file error : Unsupported data type");
83 } 87 }
84 } 88 }
85 -
86 } 89 }
87 -
88 } 90 }
......
1 +/*
2 + * Copyright 2016-present 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 java.io.Serializable;
20 +import java.util.Base64;
21 +
22 +import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangBuiltInDataTypeInfo;
23 +import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
24 +
25 +/*
26 + * Reference RFC 6020.
27 + *
28 + * The binary built-in type represents any binary data,
29 + * i.e., a sequence of octets.
30 + */
31 +public class YangBinary implements YangBuiltInDataTypeInfo<YangBinary>, Serializable, Comparable<YangBinary> {
32 +
33 + private static final long serialVersionUID = 2106201608L;
34 +
35 + // Binary data is a decoded value by base64 decoding scheme from data input (jason)
36 + private byte[] binaryData;
37 +
38 + /**
39 + * Creates a binary object corresponding to the base 64 encoding value.
40 + *
41 + * @param strValue base64 encoded value
42 + */
43 + public YangBinary(String strValue) {
44 + setBinaryData(Base64.getDecoder().decode(strValue));
45 + }
46 +
47 + /**
48 + * Retrieves decoded binary data.
49 + *
50 + * @return binary data
51 + */
52 + public byte[] getBinaryData() {
53 + return binaryData;
54 + }
55 +
56 + /**
57 + * Sets binary data.
58 + *
59 + * @param binaryData binary data
60 + */
61 + public void setBinaryData(byte[] binaryData) {
62 + this.binaryData = binaryData;
63 + }
64 +
65 + /**
66 + * Encodes binary data by base64 encoding scheme.
67 + *
68 + * @return encoded binary data
69 + */
70 + public String toString() {
71 + return Base64.getEncoder()
72 + .encodeToString(binaryData);
73 + }
74 +
75 + @Override
76 + public YangDataTypes getYangType() {
77 + return YangDataTypes.BINARY;
78 + }
79 +
80 + @Override
81 + public int compareTo(YangBinary o) {
82 + for (int i = 0, j = 0; i < this.binaryData.length && j < o.binaryData.length; i++, j++) {
83 + int a = (this.binaryData[i] & 0xff);
84 + int b = (o.binaryData[j] & 0xff);
85 + if (a != b) {
86 + return a - b;
87 + }
88 + }
89 + return this.binaryData.length - o.binaryData.length;
90 + }
91 +}
...@@ -17,8 +17,10 @@ ...@@ -17,8 +17,10 @@
17 package org.onosproject.yangutils.datamodel; 17 package org.onosproject.yangutils.datamodel;
18 18
19 import java.io.Serializable; 19 import java.io.Serializable;
20 -import java.util.HashSet; 20 +import java.util.BitSet;
21 -import java.util.Set; 21 +import java.util.HashMap;
22 +import java.util.Map;
23 +import java.util.regex.Pattern;
22 24
23 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 25 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
24 import org.onosproject.yangutils.datamodel.utils.Parsable; 26 import org.onosproject.yangutils.datamodel.utils.Parsable;
...@@ -38,36 +40,142 @@ import org.onosproject.yangutils.datamodel.utils.YangConstructType; ...@@ -38,36 +40,142 @@ import org.onosproject.yangutils.datamodel.utils.YangConstructType;
38 public class YangBits implements Parsable, Serializable { 40 public class YangBits implements Parsable, Serializable {
39 41
40 private static final long serialVersionUID = 806201641L; 42 private static final long serialVersionUID = 806201641L;
43 + private static final String SPACE = " ";
41 44
42 - // Bits information set. 45 + // Bits name
43 - private Set<YangBit> bitSet;
44 -
45 - // BITS name.
46 private String bitsName; 46 private String bitsName;
47 + // Bits data contains bit-positions will be used to send to ONOS application
48 + private BitSet bitDataSet;
49 + /**
50 + * Mapping bit name to YangBit. In data input (jason), only bit name will be received.
51 + * By using the bit name corresponding (yang) bit-position will be retrieved from bitNameMap map.
52 + */
53 + private Map<String, YangBit> bitNameMap;
54 + /**
55 + * Mapping bit position to YangBit. The bit-position received from ONOS application
56 + * will be converted into bit-name by using bitPositionMap map to send (jason) output data as response.
57 + */
58 + private Map<Integer, YangBit> bitPositionMap;
47 59
48 /** 60 /**
49 * Creates a YANG bits type object. 61 * Creates a YANG bits type object.
50 */ 62 */
51 public YangBits() { 63 public YangBits() {
52 - setBitSet(new HashSet<YangBit>()); 64 + bitDataSet = new BitSet();
65 + setBitNameMap(new HashMap<>());
66 + setBitPositionMap(new HashMap<>());
53 } 67 }
54 68
55 /** 69 /**
56 - * Returns the bit set. 70 + * Creates an instance of YANG bits.
57 * 71 *
58 - * @return the bit set 72 + * @param bits set of bit names
73 + * @throws DataModelException due to violation in data model rules
59 */ 74 */
60 - public Set<YangBit> getBitSet() { 75 + public YangBits(String bits) throws DataModelException {
61 - return bitSet; 76 + String[] bitNames = bits.trim().split(Pattern.quote(SPACE));
77 + setBitDataSet(bitNames);
62 } 78 }
63 79
64 /** 80 /**
65 - * Sets the bit set. 81 + * Returns the bits name.
66 * 82 *
67 - * @param bitSet the bit set 83 + * @return the bits name
68 */ 84 */
69 - private void setBitSet(Set<YangBit> bitSet) { 85 + public String getBitsName() {
70 - this.bitSet = bitSet; 86 + return bitsName;
87 + }
88 +
89 + /**
90 + * Sets the bits name.
91 + *
92 + * @param bitsName the bits name
93 + */
94 + public void setBitsName(String bitsName) {
95 + this.bitsName = bitsName;
96 + }
97 +
98 + /**
99 + * Returns the bit data set.
100 + *
101 + * @return the bit data set
102 + */
103 + public BitSet getBitDataSet() {
104 + return bitDataSet;
105 + }
106 +
107 + /**
108 + * Sets the bit data set.
109 + *
110 + * @param bitNames the set of bit names
111 + * @throws DataModelException due to violation in data model rules
112 + */
113 + public void setBitDataSet(String[] bitNames) throws DataModelException {
114 + YangBit bit;
115 + for (String bitName : bitNames) {
116 + bit = bitNameMap.get(bitName);
117 + if (bit == null) {
118 + throw new DataModelException("YANG file error: Unable to find " +
119 + "corresponding bit position for bit name: " + bitName);
120 + }
121 + bitDataSet.set(bit.getPosition());
122 + }
123 + }
124 +
125 + /**
126 + * Returns the bit name map.
127 + *
128 + * @return the bit name map
129 + */
130 + public Map<String, YangBit> getBitNameMap() {
131 + return bitNameMap;
132 + }
133 +
134 + /**
135 + * Sets the bit name map.
136 + *
137 + * @param bitNameMap the bit name map
138 + */
139 + public void setBitNameMap(Map<String, YangBit> bitNameMap) {
140 + this.bitNameMap = bitNameMap;
141 + }
142 +
143 + /**
144 + * Checks whether bit name already available.
145 + *
146 + * @param bitName bit name
147 + * @return true if bit name already available otherwise returns false
148 + */
149 + public boolean isBitNameExists(String bitName) {
150 + return bitNameMap.containsKey(bitName);
151 + }
152 +
153 + /**
154 + * Returns the bit position map.
155 + *
156 + * @return the bit position map
157 + */
158 + public Map<Integer, YangBit> getBitPositionMap() {
159 + return bitPositionMap;
160 + }
161 +
162 + /**
163 + * Sets the bit position map.
164 + *
165 + * @param bitPositionMap the bit position map
166 + */
167 + public void setBitPositionMap(Map<Integer, YangBit> bitPositionMap) {
168 + this.bitPositionMap = bitPositionMap;
169 + }
170 +
171 + /**
172 + * Checks whether bit position already available.
173 + *
174 + * @param bitPosition bit position
175 + * @return true if bit position already available otherwise returns false
176 + */
177 + public boolean isBitPositionExists(Integer bitPosition) {
178 + return bitPositionMap.containsKey(bitPosition);
71 } 179 }
72 180
73 /** 181 /**
...@@ -77,10 +185,14 @@ public class YangBits implements Parsable, Serializable { ...@@ -77,10 +185,14 @@ public class YangBits implements Parsable, Serializable {
77 * @throws DataModelException due to violation in data model rules 185 * @throws DataModelException due to violation in data model rules
78 */ 186 */
79 public void addBitInfo(YangBit bitInfo) throws DataModelException { 187 public void addBitInfo(YangBit bitInfo) throws DataModelException {
80 - if (!getBitSet().add(bitInfo)) { 188 + if (bitNameMap.put(bitInfo.getBitName(), bitInfo) != null) {
81 - throw new DataModelException("YANG file error: Duplicate identifier detected, same as bit \"" 189 + throw new DataModelException("YANG file error: Duplicate bit name detected, same as bit name \""
82 + bitInfo.getBitName() + "\""); 190 + bitInfo.getBitName() + "\"");
83 } 191 }
192 + if (bitPositionMap.put(bitInfo.getPosition(), bitInfo) != null) {
193 + throw new DataModelException("YANG file error: Duplicate bit position detected, same as bit position \""
194 + + bitInfo.getPosition() + "\"");
195 + }
84 } 196 }
85 197
86 /** 198 /**
...@@ -93,22 +205,36 @@ public class YangBits implements Parsable, Serializable { ...@@ -93,22 +205,36 @@ public class YangBits implements Parsable, Serializable {
93 return YangConstructType.BITS_DATA; 205 return YangConstructType.BITS_DATA;
94 } 206 }
95 207
96 - /** 208 + @Override
97 - * Returns the bits name. 209 + public String toString() {
98 - * 210 + YangBit bit;
99 - * @return name of the bits 211 + String bits = new String();
100 - */ 212 + for (int i = bitDataSet.nextSetBit(0); i >= 0; i = bitDataSet.nextSetBit(i + 1)) {
101 - public String getBitsName() { 213 + bit = bitPositionMap.get(i);
102 - return bitsName; 214 + if (bit == null) {
215 + return null;
216 + }
217 + if (bits.isEmpty()) {
218 + bits = bit.getBitName();
219 + } else {
220 + bits += " " + bit.getBitName();
221 + }
222 + }
223 + return bits.trim();
103 } 224 }
104 225
105 /** 226 /**
106 - * Sets bits name. 227 + * Returns the object of YANG bits based on specific set of bit names.
107 * 228 *
108 - * @param bitsName bit name to be set 229 + * @param bits set of bit names
230 + * @return Object of YANG bits
109 */ 231 */
110 - public void setBitsName(String bitsName) { 232 + public static YangBits fromString(String bits) {
111 - this.bitsName = bitsName; 233 + try {
234 + return new YangBits(bits);
235 + } catch (Exception e) {
236 + }
237 + return null;
112 } 238 }
113 239
114 /** 240 /**
......
1 +/*
2 + * Copyright 2016-present 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.datamodel.utils.FractionDigits;
21 +import org.onosproject.yangutils.datamodel.utils.Parsable;
22 +import org.onosproject.yangutils.datamodel.utils.YangConstructType;
23 +import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangBuiltInDataTypeInfo;
24 +import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
25 +
26 +import java.io.Serializable;
27 +import java.math.BigDecimal;
28 +import java.util.ListIterator;
29 +
30 +/**
31 + * Represents YANG decimal 64.
32 + */
33 +public class YangDecimal64<T>
34 + implements YangBuiltInDataTypeInfo<YangDecimal64>, Parsable, Serializable, Comparable<YangDecimal64> {
35 +
36 + private static final long serialVersionUID = 8006201668L;
37 +
38 + /**
39 + * YANG's min keyword.
40 + */
41 + private static final String MIN_KEYWORD = "min";
42 +
43 + /**
44 + * YANG's max keyword.
45 + */
46 + private static final String MAX_KEYWORD = "max";
47 +
48 + /**
49 + * Valid minimum value of YANG's fraction-digits.
50 + */
51 + public static final int MIN_FRACTION_DIGITS_VALUE = 1;
52 +
53 + /**
54 + * Valid maximum value of YANG's fraction-digits.
55 + */
56 + public static final int MAX_FRACTION_DIGITS_VALUE = 18;
57 +
58 + // Decimal64 value
59 + private BigDecimal value;
60 +
61 + // fraction-digits
62 + private int fractionDigit;
63 +
64 + /**
65 + * Additional information about range restriction.
66 + */
67 + private T rangeRestrictedExtendedInfo;
68 +
69 + /**
70 + * Creates an instance of YANG decimal64.
71 + */
72 + public YangDecimal64() {
73 + }
74 +
75 + /**
76 + * Creates an instance of YANG decimal64.
77 + *
78 + * @param value of decimal64
79 + */
80 + public YangDecimal64(BigDecimal value) {
81 + setValue(value);
82 + }
83 +
84 + /**
85 + * Creates an instance of YANG decimal64.
86 + *
87 + * @param value of decimal64 in string
88 + * @throws DataModelException a violation of data model rules
89 + */
90 + public YangDecimal64(String value) throws DataModelException {
91 + fromString(value);
92 + }
93 +
94 + /**
95 + * Returns decimal64 value.
96 + *
97 + * @return value
98 + */
99 + public BigDecimal getValue() {
100 + return value;
101 + }
102 +
103 + /**
104 + * Sets the decimal64 value.
105 + *
106 + * @param value of decimal64
107 + */
108 + public void setValue(BigDecimal value) {
109 + this.value = value;
110 + }
111 +
112 + /**
113 + * Returns fraction digit.
114 + *
115 + * @return the fractionDigit
116 + */
117 + public int getFractionDigit() {
118 + return fractionDigit;
119 + }
120 +
121 + /**
122 + * Sets fraction digit.
123 + *
124 + * @param fractionDigit fraction digits.
125 + */
126 + public void setFractionDigit(int fractionDigit) {
127 + this.fractionDigit = fractionDigit;
128 + }
129 +
130 + /**
131 + * Returns additional information about range restriction.
132 + *
133 + * @return resolved range restricted extended information
134 + */
135 + public T getRangeRestrictedExtendedInfo() {
136 + return rangeRestrictedExtendedInfo;
137 + }
138 +
139 + /**
140 + * Sets additional information about range restriction.
141 + *
142 + * @param resolvedExtendedInfo resolved range restricted extended information
143 + */
144 + public void setRangeRestrictedExtendedInfo(T resolvedExtendedInfo) {
145 + this.rangeRestrictedExtendedInfo = resolvedExtendedInfo;
146 + }
147 +
148 + /**
149 + * Returns object of YANG decimal64.
150 + *
151 + * @param value of decimal64
152 + * @return YANG decimal64 object
153 + */
154 + public static YangDecimal64 of(BigDecimal value) {
155 + return new YangDecimal64(value);
156 + }
157 +
158 + @Override
159 + public YangDataTypes getYangType() {
160 + return YangDataTypes.DECIMAL64;
161 + }
162 +
163 + @Override
164 + public YangConstructType getYangConstructType() {
165 + return YangConstructType.DECIMAL64_DATA;
166 + }
167 +
168 + @Override
169 + public String toString() {
170 + return value.toString();
171 + }
172 +
173 + /**
174 + * Returns the object of YANG decimal64 from input string.
175 + *
176 + * @param valInString input String
177 + * @return Object of YANG decimal64
178 + * @throws DataModelException a violation of data model rules
179 + */
180 + public static YangDecimal64 fromString(String valInString) throws DataModelException {
181 + YangDecimal64 decimal64;
182 + decimal64 = of(new BigDecimal(valInString));
183 + decimal64.validateValue();
184 + return decimal64;
185 + }
186 +
187 + /**
188 + * Validate decimal64 value.
189 + *
190 + * @throws DataModelException a violation of data model rules
191 + */
192 + public void validateValue() throws DataModelException {
193 + if (!(FractionDigits.isValidDecimal64(this.value, this.fractionDigit))) {
194 + throw new DataModelException("YANG file error : decimal64 validation failed.");
195 + }
196 + }
197 +
198 + /**
199 + * Validate range restriction values based on fraction-digits decimal64 range value.
200 + *
201 + * @throws DataModelException a violation of data model rules
202 + */
203 + public void validateRange() throws DataModelException {
204 + YangRangeRestriction rangeRestriction = (YangRangeRestriction) getRangeRestrictedExtendedInfo();
205 + if (rangeRestriction == null) {
206 + return;
207 + }
208 +
209 + ListIterator<YangRangeInterval> rangeListIterator = rangeRestriction.getAscendingRangeIntervals()
210 + .listIterator();
211 + while (rangeListIterator.hasNext()) {
212 + YangRangeInterval rangeInterval = rangeListIterator.next();
213 + if (!(FractionDigits.isValidDecimal64(((YangDecimal64) rangeInterval.getStartValue()).getValue(),
214 + getFractionDigit()))) {
215 + throw new DataModelException("YANG file error : decimal64 validation failed.");
216 + }
217 +
218 + if (!(FractionDigits.isValidDecimal64(((YangDecimal64) rangeInterval.getEndValue()).getValue(),
219 + getFractionDigit()))) {
220 + throw new DataModelException("YANG file error : decimal64 validation failed.");
221 + }
222 + }
223 + }
224 +
225 + @Override
226 + public int compareTo(YangDecimal64 o) {
227 + return Double.compare(value.doubleValue(), o.value.doubleValue());
228 + }
229 +
230 + /**
231 + * Returns decimal64 default range restriction based on fraction-digits.
232 + * If range restriction is not provided then this default range value will be applicable.
233 + *
234 + * @return range restriction
235 + * @throws DataModelException a violation of data model rules
236 + */
237 + public YangRangeRestriction getDefaultRangeRestriction() throws DataModelException {
238 + YangRangeRestriction refRangeRestriction = new YangRangeRestriction();
239 + YangRangeInterval rangeInterval = new YangRangeInterval<>();
240 + FractionDigits.Range range = FractionDigits.getRange(this.fractionDigit);
241 + rangeInterval.setStartValue(new YangDecimal64(new BigDecimal((range.getMin()))));
242 + rangeInterval.setEndValue(new YangDecimal64(new BigDecimal((range.getMax()))));
243 + refRangeRestriction.addRangeRestrictionInterval(rangeInterval);
244 + return refRangeRestriction;
245 + }
246 +
247 + /**
248 + * Validates the data on entering the corresponding parse tree node.
249 + *
250 + * @throws DataModelException a violation of data model rules
251 + */
252 + @Override
253 + public void validateDataOnEntry() throws DataModelException {
254 + // TODO auto-generated method stub, to be implemented by parser
255 + }
256 +
257 + /**
258 + * Validates the data on exiting the corresponding parse tree node.
259 + *
260 + * @throws DataModelException a violation of data model rules
261 + */
262 + @Override
263 + public void validateDataOnExit() throws DataModelException {
264 + // TODO auto-generated method stub, to be implemented by parser
265 + }
266 +}
...@@ -102,6 +102,7 @@ public class YangLengthRestriction implements YangDesc, YangReference, YangAppEr ...@@ -102,6 +102,7 @@ public class YangLengthRestriction implements YangDesc, YangReference, YangAppEr
102 * Creates a YANG length restriction object. 102 * Creates a YANG length restriction object.
103 */ 103 */
104 public YangLengthRestriction() { 104 public YangLengthRestriction() {
105 + setLengthRestriction(new YangRangeRestriction<YangUint64>());
105 } 106 }
106 107
107 /** 108 /**
......
1 +/*
2 + * Copyright 2016-present 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.utils;
18 +
19 +import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
20 +
21 +import java.math.BigDecimal;
22 +import java.util.ArrayList;
23 +
24 +/**
25 + * The "fraction-digits" statement, which is a substatement to the
26 + * "type" statement, MUST be present if the type is "decimal64". It
27 + * takes as an argument an integer between 1 and 18, inclusively. It
28 + * controls the size of the minimum difference between values of a
29 + * decimal64 type, by restricting the value space to numbers that are
30 + * expressible as "i x 10^-n" where n is the fraction-digits argument.
31 + *
32 + * +----------------+-----------------------+----------------------+
33 + * | fraction-digit | min | max |
34 + * +----------------+-----------------------+----------------------+
35 + * | 1 | -922337203685477580.8 | 922337203685477580.7 |
36 + * | 2 | -92233720368547758.08 | 92233720368547758.07 |
37 + * | 3 | -9223372036854775.808 | 9223372036854775.807 |
38 + * | 4 | -922337203685477.5808 | 922337203685477.5807 |
39 + * | 5 | -92233720368547.75808 | 92233720368547.75807 |
40 + * | 6 | -9223372036854.775808 | 9223372036854.775807 |
41 + * | 7 | -922337203685.4775808 | 922337203685.4775807 |
42 + * | 8 | -92233720368.54775808 | 92233720368.54775807 |
43 + * | 9 | -9223372036.854775808 | 9223372036.854775807 |
44 + * | 10 | -922337203.6854775808 | 922337203.6854775807 |
45 + * | 11 | -92233720.36854775808 | 92233720.36854775807 |
46 + * | 12 | -9223372.036854775808 | 9223372.036854775807 |
47 + * | 13 | -922337.2036854775808 | 922337.2036854775807 |
48 + * | 14 | -92233.72036854775808 | 92233.72036854775807 |
49 + * | 15 | -9223.372036854775808 | 9223.372036854775807 |
50 + * | 16 | -922.3372036854775808 | 922.3372036854775807 |
51 + * | 17 | -92.23372036854775808 | 92.23372036854775807 |
52 + * | 18 | -9.223372036854775808 | 9.223372036854775807 |
53 + * +----------------+-----------------------+----------------------+
54 + */
55 +
56 +/**
57 + * Represents the decimal64 value range based on fraction-digits.
58 + */
59 +public final class FractionDigits {
60 +
61 + public static class Range {
62 + private double min;
63 + private double max;
64 +
65 + /**
66 + * Creates an instance of range.
67 + *
68 + * @param min minimum value of decimal64
69 + * @param max maximum value of decimal64
70 + */
71 + protected Range(double min, double max) {
72 + this.min = min;
73 + this.max = max;
74 + }
75 +
76 + /**
77 + * Retrieve minimum value range.
78 + *
79 + * @return minimum value range
80 + */
81 + public double getMin() {
82 + return min;
83 + }
84 +
85 + /**
86 + * Retrieve maximum value range.
87 + *
88 + * @return maximum value range
89 + */
90 + public double getMax() {
91 + return max;
92 + }
93 + }
94 +
95 + private static ArrayList<Range> decimal64ValueRange = null;
96 +
97 + /**
98 + * Creates a fraction-digits instance.
99 + */
100 + private FractionDigits() {
101 + }
102 +
103 + /**
104 + * Generates decimal64 value range based on fraction-digits.
105 + *
106 + * @return decimal64 value range by fraction-digits as index
107 + */
108 + private static ArrayList<Range> getDecimal64ValueRange() {
109 + if (decimal64ValueRange == null) {
110 + decimal64ValueRange = new ArrayList<>();
111 + decimal64ValueRange.add(new Range(-922337203685477580.8, 922337203685477580.7)); // fraction-digit: 1
112 + decimal64ValueRange.add(new Range(-92233720368547758.08, 92233720368547758.07)); // fraction-digit: 2
113 + decimal64ValueRange.add(new Range(-9223372036854775.808, 9223372036854775.807)); // fraction-digit: 3
114 + decimal64ValueRange.add(new Range(-922337203685477.5808, 922337203685477.5807)); // fraction-digit: 4
115 + decimal64ValueRange.add(new Range(-92233720368547.75808, 92233720368547.75807)); // fraction-digit: 5
116 + decimal64ValueRange.add(new Range(-9223372036854.775808, 9223372036854.775807)); // fraction-digit: 6
117 + decimal64ValueRange.add(new Range(-922337203685.4775808, 922337203685.4775807)); // fraction-digit: 7
118 + decimal64ValueRange.add(new Range(-92233720368.54775808, 92233720368.54775807)); // fraction-digit: 8
119 + decimal64ValueRange.add(new Range(-9223372036.854775808, 9223372036.854775807)); // fraction-digit: 9
120 + decimal64ValueRange.add(new Range(-922337203.6854775808, 922337203.6854775807)); // fraction-digit: 10
121 + decimal64ValueRange.add(new Range(-92233720.36854775808, 92233720.36854775807)); // fraction-digit: 11
122 + decimal64ValueRange.add(new Range(-9223372.036854775808, 9223372.036854775807)); // fraction-digit: 12
123 + decimal64ValueRange.add(new Range(-922337.2036854775808, 922337.2036854775807)); // fraction-digit: 13
124 + decimal64ValueRange.add(new Range(-92233.72036854775808, 92233.72036854775807)); // fraction-digit: 14
125 + decimal64ValueRange.add(new Range(-9223.372036854775808, 9223.372036854775807)); // fraction-digit: 15
126 + decimal64ValueRange.add(new Range(-922.3372036854775808, 922.3372036854775807)); // fraction-digit: 16
127 + decimal64ValueRange.add(new Range(-92.23372036854775808, 92.23372036854775807)); // fraction-digit: 17
128 + decimal64ValueRange.add(new Range(-9.223372036854775808, 9.223372036854775807)); // fraction-digit: 18
129 + }
130 + return decimal64ValueRange;
131 + }
132 +
133 + /**
134 + * Checks given decimal64 value is in the specific range based on given fraction-digit.
135 + *
136 + * @param value decimal64 value
137 + * @param fractionDigit fraction-digits
138 + * @return success when it is in specific range otherwise false
139 + */
140 + public static boolean isValidDecimal64(BigDecimal value, int fractionDigit) {
141 + if (!((fractionDigit >= 1) && (fractionDigit <= 18))) {
142 + return false;
143 + }
144 +
145 + // ArrayList index starts from 0.
146 + Range range = getDecimal64ValueRange().get(fractionDigit - 1);
147 + if ((value.doubleValue() >= range.min) && (value.doubleValue() <= range.max)) {
148 + return true;
149 + }
150 + return false;
151 + }
152 +
153 + /**
154 + * Retrieve range based on fraction-digits.
155 + *
156 + * @param fractionDigit fraction-digits
157 + * @return range
158 + * @throws DataModelException a violation of data model rules
159 + */
160 + public static Range getRange(int fractionDigit) throws DataModelException {
161 + if (!((fractionDigit >= 1) && (fractionDigit <= 18))) {
162 + throw new DataModelException("YANG file error : given fraction-digit is not in its range (1..18).");
163 + }
164 +
165 + return getDecimal64ValueRange().get(fractionDigit - 1);
166 + }
167 +}
...@@ -95,6 +95,16 @@ public enum YangConstructType { ...@@ -95,6 +95,16 @@ public enum YangConstructType {
95 BITS_DATA, 95 BITS_DATA,
96 96
97 /** 97 /**
98 + * Identifies the YANG decimal64 parsed data.
99 + */
100 + DECIMAL64_DATA,
101 +
102 + /**
103 + * Identifies the YANG fraction-digits parsed data.
104 + */
105 + FRACTION_DIGITS_DATA,
106 +
107 + /**
98 * Identifies the YANG enum parsed data. 108 * Identifies the YANG enum parsed data.
99 */ 109 */
100 ENUM_DATA, 110 ENUM_DATA,
...@@ -413,6 +423,10 @@ public enum YangConstructType { ...@@ -413,6 +423,10 @@ public enum YangConstructType {
413 return "bit"; 423 return "bit";
414 case BITS_DATA: 424 case BITS_DATA:
415 return "bits"; 425 return "bits";
426 + case DECIMAL64_DATA:
427 + return "decimal64";
428 + case FRACTION_DIGITS_DATA:
429 + return "fraction-digits";
416 case ENUM_DATA: 430 case ENUM_DATA:
417 return "enum"; 431 return "enum";
418 case IMPORT_DATA: 432 case IMPORT_DATA:
......
1 -/*
2 - * Copyright 2016-present 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.utils.builtindatatype;
18 -
19 -import java.io.Serializable;
20 -import java.util.Objects;
21 -
22 -import com.google.common.base.MoreObjects;
23 -
24 -/**
25 - * Represents binary data type.
26 - */
27 -public final class YangBinary implements Serializable {
28 -
29 - private static final long serialVersionUID = 8006201670L;
30 -
31 - private byte[] byteArray;
32 -
33 - /**
34 - * Creates an instance of YANG binary.
35 - */
36 - private YangBinary() {
37 - }
38 -
39 - /**
40 - * Creates an instance of YANG binary.
41 - *
42 - * @param bytes byte array
43 - */
44 - public YangBinary(byte[] bytes) {
45 - byteArray = bytes;
46 - }
47 -
48 - /**
49 - * Returns object of YANG binary.
50 - *
51 - * @param bytes byte array
52 - * @return object of YANG binary
53 - */
54 - public static YangBinary of(byte[] bytes) {
55 - return new YangBinary(bytes);
56 - }
57 -
58 - /**
59 - * Returns byte array.
60 - *
61 - * @return byte array
62 - */
63 - public byte[] byteArray() {
64 - return byteArray;
65 - }
66 -
67 - @Override
68 - public int hashCode() {
69 - return Objects.hash(byteArray);
70 - }
71 -
72 - @Override
73 - public boolean equals(Object obj) {
74 - if (this == obj) {
75 - return true;
76 - }
77 - if (obj instanceof YangBinary) {
78 - YangBinary other = (YangBinary) obj;
79 - return Objects.equals(byteArray, other.byteArray);
80 - }
81 - return false;
82 - }
83 -
84 - @Override
85 - public String toString() {
86 - return MoreObjects.toStringHelper(getClass())
87 - .omitNullValues()
88 - .add("byteArray", byteArray)
89 - .toString();
90 - }
91 -
92 - /**
93 - * Returns the object of YANG binary fromString input String.
94 - *
95 - * @param valInString input String
96 - * @return Object of YANG binary
97 - */
98 - public static YangBinary fromString(String valInString) {
99 - try {
100 - byte[] tmpVal = valInString.getBytes();
101 - return of(tmpVal);
102 - } catch (Exception e) {
103 - }
104 - return null;
105 - }
106 -
107 -}
1 -/*
2 - * Copyright 2016-present 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.utils.builtindatatype;
18 -
19 -import java.io.Serializable;
20 -import java.util.Objects;
21 -
22 -import com.google.common.base.MoreObjects;
23 -
24 -/**
25 - * Represents bits data type.
26 - */
27 -public class YangBits implements Serializable {
28 -
29 - private static final long serialVersionUID = 8006201669L;
30 -
31 - private byte[] byteArray;
32 -
33 - /**
34 - * Creates an instance of YANG bits.
35 - */
36 - private YangBits() {
37 - }
38 -
39 - /**
40 - * Creates an instance of YANG bits.
41 - *
42 - * @param bytes byte array
43 - */
44 - public YangBits(byte[] bytes) {
45 - byteArray = bytes;
46 - }
47 -
48 - /**
49 - * Returns object of YANG bits.
50 - *
51 - * @param bytes byte array
52 - * @return object of YANG bits
53 - */
54 - public static YangBits of(byte[] bytes) {
55 - return new YangBits(bytes);
56 - }
57 -
58 - /**
59 - * Returns byte array.
60 - *
61 - * @return byte array
62 - */
63 - public byte[] byteArray() {
64 - return byteArray;
65 - }
66 -
67 - @Override
68 - public int hashCode() {
69 - return Objects.hash(byteArray);
70 - }
71 -
72 - @Override
73 - public boolean equals(Object obj) {
74 - if (this == obj) {
75 - return true;
76 - }
77 - if (obj instanceof YangBits) {
78 - YangBits other = (YangBits) obj;
79 - return Objects.equals(byteArray, other.byteArray);
80 - }
81 - return false;
82 - }
83 -
84 - @Override
85 - public String toString() {
86 - return MoreObjects.toStringHelper(getClass())
87 - .omitNullValues()
88 - .add("byteArray", byteArray)
89 - .toString();
90 - }
91 -
92 - /**
93 - * Returns the object of YANG bits fromString input String.
94 - *
95 - * @param valInString input String
96 - * @return Object of YANG bits
97 - */
98 - public static YangBits fromString(String valInString) {
99 - try {
100 - byte[] tmpVal = valInString.getBytes();
101 - return of(tmpVal);
102 - } catch (Exception e) {
103 - }
104 - return null;
105 - }
106 -
107 -}
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
16 16
17 package org.onosproject.yangutils.datamodel.utils.builtindatatype; 17 package org.onosproject.yangutils.datamodel.utils.builtindatatype;
18 18
19 -import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DECIMAL64;
20 import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT16; 19 import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT16;
21 import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT32; 20 import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT32;
22 import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT64; 21 import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT64;
...@@ -51,7 +50,6 @@ public final class YangDataTypeUtils { ...@@ -51,7 +50,6 @@ public final class YangDataTypeUtils {
51 || dataType == UINT8 50 || dataType == UINT8
52 || dataType == UINT16 51 || dataType == UINT16
53 || dataType == UINT32 52 || dataType == UINT32
54 - || dataType == UINT64 53 + || dataType == UINT64;
55 - || dataType == DECIMAL64;
56 } 54 }
57 } 55 }
......
1 -/*
2 - * Copyright 2016-present 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.utils.builtindatatype;
18 -
19 -import java.io.Serializable;
20 -import java.util.Objects;
21 -
22 -import com.google.common.base.MoreObjects;
23 -
24 -/**
25 - * Represents YANG decimal 64.
26 - */
27 -public class YangDecimal64 implements Serializable {
28 -
29 - private static final long serialVersionUID = 8006201668L;
30 -
31 - private int fractionDigit;
32 -
33 - /**
34 - * Creates an instance of YANG decimal64.
35 - */
36 - public YangDecimal64() {
37 - }
38 -
39 - /**
40 - * Creates an instance of of YANG decimal64.
41 - *
42 - * @param fractionDigit fraction digit
43 - */
44 - public YangDecimal64(int fractionDigit) {
45 - setFractionDigit(fractionDigit);
46 - }
47 -
48 - /**
49 - * Returns fraction digit.
50 - *
51 - * @return the fractionDigit
52 - */
53 - public int getFractionDigit() {
54 - return fractionDigit;
55 - }
56 -
57 - /**
58 - * Sets fraction digit.
59 - *
60 - * @param fractionDigit fraction digits.
61 - */
62 - public void setFractionDigit(int fractionDigit) {
63 - this.fractionDigit = fractionDigit;
64 - }
65 -
66 - /**
67 - * Returns object of YANG decimal64.
68 - *
69 - * @param value fraction digit
70 - * @return YANG decimal64
71 - */
72 - public static YangDecimal64 of(int value) {
73 - return new YangDecimal64(value);
74 - }
75 -
76 - @Override
77 - public int hashCode() {
78 - return Objects.hash(fractionDigit);
79 - }
80 -
81 - @Override
82 - public boolean equals(Object obj) {
83 - if (this == obj) {
84 - return true;
85 - }
86 - if (obj instanceof YangDecimal64) {
87 - YangDecimal64 other = (YangDecimal64) obj;
88 - return Objects.equals(fractionDigit, other.fractionDigit);
89 - }
90 - return false;
91 - }
92 -
93 - @Override
94 - public String toString() {
95 - return MoreObjects.toStringHelper(getClass())
96 - .omitNullValues()
97 - .add("fractionDigit", fractionDigit)
98 - .toString();
99 - }
100 -
101 - /**
102 - * Returns the object of YANG decimal64 fromString input String.
103 - *
104 - * @param valInString input String
105 - * @return Object of YANG decimal64
106 - */
107 - public static YangDecimal64 fromString(String valInString) {
108 - try {
109 - int tmpVal = Integer.parseInt(valInString);
110 - return of(tmpVal);
111 - } catch (Exception e) {
112 - }
113 - return null;
114 - }
115 -}
...@@ -632,6 +632,22 @@ public interface GeneratedYangListener extends ParseTreeListener { ...@@ -632,6 +632,22 @@ public interface GeneratedYangListener extends ParseTreeListener {
632 * 632 *
633 * @param currentContext current context in the parsed tree 633 * @param currentContext current context in the parsed tree
634 */ 634 */
635 + void enterFractionDigitStatement(GeneratedYangParser.FractionDigitStatementContext currentContext);
636 +
637 + /**
638 + * Exits a parse tree produced by GeneratedYangParser for grammar rule
639 + * numericalRestrictions.
640 + *
641 + * @param currentContext current context in the parsed tree
642 + */
643 + void exitFractionDigitStatement(GeneratedYangParser.FractionDigitStatementContext currentContext);
644 +
645 + /**
646 + * Enters a parse tree produced by GeneratedYangParser for grammar rule
647 + * numericalRestrictions.
648 + *
649 + * @param currentContext current context in the parsed tree
650 + */
635 void enterNumericalRestrictions(GeneratedYangParser.NumericalRestrictionsContext currentContext); 651 void enterNumericalRestrictions(GeneratedYangParser.NumericalRestrictionsContext currentContext);
636 652
637 /** 653 /**
......
...@@ -37,11 +37,13 @@ import org.onosproject.yangutils.parser.impl.listeners.ChoiceListener; ...@@ -37,11 +37,13 @@ import org.onosproject.yangutils.parser.impl.listeners.ChoiceListener;
37 import org.onosproject.yangutils.parser.impl.listeners.ConfigListener; 37 import org.onosproject.yangutils.parser.impl.listeners.ConfigListener;
38 import org.onosproject.yangutils.parser.impl.listeners.ContactListener; 38 import org.onosproject.yangutils.parser.impl.listeners.ContactListener;
39 import org.onosproject.yangutils.parser.impl.listeners.ContainerListener; 39 import org.onosproject.yangutils.parser.impl.listeners.ContainerListener;
40 +import org.onosproject.yangutils.parser.impl.listeners.Decimal64Listener;
40 import org.onosproject.yangutils.parser.impl.listeners.DefaultListener; 41 import org.onosproject.yangutils.parser.impl.listeners.DefaultListener;
41 import org.onosproject.yangutils.parser.impl.listeners.DescriptionListener; 42 import org.onosproject.yangutils.parser.impl.listeners.DescriptionListener;
42 import org.onosproject.yangutils.parser.impl.listeners.EnumListener; 43 import org.onosproject.yangutils.parser.impl.listeners.EnumListener;
43 import org.onosproject.yangutils.parser.impl.listeners.EnumerationListener; 44 import org.onosproject.yangutils.parser.impl.listeners.EnumerationListener;
44 import org.onosproject.yangutils.parser.impl.listeners.FeatureListener; 45 import org.onosproject.yangutils.parser.impl.listeners.FeatureListener;
46 +import org.onosproject.yangutils.parser.impl.listeners.FractionDigitsListener;
45 import org.onosproject.yangutils.parser.impl.listeners.GroupingListener; 47 import org.onosproject.yangutils.parser.impl.listeners.GroupingListener;
46 import org.onosproject.yangutils.parser.impl.listeners.IdentityrefListener; 48 import org.onosproject.yangutils.parser.impl.listeners.IdentityrefListener;
47 import org.onosproject.yangutils.parser.impl.listeners.IfFeatureListener; 49 import org.onosproject.yangutils.parser.impl.listeners.IfFeatureListener;
...@@ -563,12 +565,22 @@ public class TreeWalkListener implements GeneratedYangListener { ...@@ -563,12 +565,22 @@ public class TreeWalkListener implements GeneratedYangListener {
563 565
564 @Override 566 @Override
565 public void enterDecimal64Specification(GeneratedYangParser.Decimal64SpecificationContext ctx) { 567 public void enterDecimal64Specification(GeneratedYangParser.Decimal64SpecificationContext ctx) {
566 - // TODO: implement the method. 568 + Decimal64Listener.processDecimal64Entry(this, ctx);
567 } 569 }
568 570
569 @Override 571 @Override
570 public void exitDecimal64Specification(GeneratedYangParser.Decimal64SpecificationContext ctx) { 572 public void exitDecimal64Specification(GeneratedYangParser.Decimal64SpecificationContext ctx) {
571 - // TODO: implement the method. 573 + Decimal64Listener.processDecimal64Exit(this, ctx);
574 + }
575 +
576 + @Override
577 + public void enterFractionDigitStatement(GeneratedYangParser.FractionDigitStatementContext ctx) {
578 + FractionDigitsListener.processFractionDigitsEntry(this, ctx);
579 + }
580 +
581 + @Override
582 + public void exitFractionDigitStatement(GeneratedYangParser.FractionDigitStatementContext currentContext) {
583 + // do nothing
572 } 584 }
573 585
574 @Override 586 @Override
......
...@@ -61,6 +61,8 @@ package org.onosproject.yangutils.parser.impl.listeners; ...@@ -61,6 +61,8 @@ package org.onosproject.yangutils.parser.impl.listeners;
61 * ; 61 * ;
62 */ 62 */
63 63
64 +import java.util.Map;
65 +
64 import org.onosproject.yangutils.datamodel.YangBit; 66 import org.onosproject.yangutils.datamodel.YangBit;
65 import org.onosproject.yangutils.datamodel.YangBits; 67 import org.onosproject.yangutils.datamodel.YangBits;
66 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 68 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
...@@ -141,12 +143,13 @@ public final class BitListener { ...@@ -141,12 +143,13 @@ public final class BitListener {
141 int maxPosition = 0; 143 int maxPosition = 0;
142 boolean isPositionPresent = false; 144 boolean isPositionPresent = false;
143 145
144 - for (YangBit curBit : yangBits.getBitSet()) { 146 + for (Map.Entry<Integer, YangBit> element : yangBits.getBitPositionMap().entrySet()) {
145 - if (maxPosition <= curBit.getPosition()) { 147 + if (maxPosition <= element.getKey()) {
146 - maxPosition = curBit.getPosition(); 148 + maxPosition = element.getKey();
147 isPositionPresent = true; 149 isPositionPresent = true;
148 } 150 }
149 } 151 }
152 +
150 if (isPositionPresent) { 153 if (isPositionPresent) {
151 maxPosition++; 154 maxPosition++;
152 } 155 }
......
1 +/*
2 + * Copyright 2016-present 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.parser.impl.listeners;
18 +
19 +/*
20 + * Reference: RFC6020 and YANG ANTLR Grammar
21 + *
22 + * ABNF grammar as per RFC6020
23 + * type-body-stmts = numerical-restrictions /
24 + * decimal64-specification /
25 + * string-restrictions /
26 + * enum-specification /
27 + * leafref-specification /
28 + * identityref-specification /
29 + * instance-identifier-specification /
30 + * bits-specification /
31 + * union-specification
32 + *
33 + * decimal64-specification = fraction-digits-stmt [range-stmt stmtsep]
34 + *
35 + * fraction-digits-stmt = fraction-digits-keyword sep
36 + * fraction-digits-arg-str stmtend
37 + *
38 + * fraction-digits-arg-str = < a string that matches the rule
39 + * fraction-digits-arg >
40 + *
41 + * fraction-digits-arg = ("1" ["0" / "1" / "2" / "3" / "4" /
42 + * "5" / "6" / "7" / "8"])
43 + * / "2" / "3" / "4" / "5" / "6" / "7" / "8" / "9"
44 + *
45 + * range-stmt = range-keyword sep range-arg-str optsep
46 + * (";" /
47 + * "{" stmtsep
48 + * ;; these stmts can appear in any order
49 + * [error-message-stmt stmtsep]
50 + * [error-app-tag-stmt stmtsep]
51 + * [description-stmt stmtsep]
52 + * [reference-stmt stmtsep]
53 + * "}")
54 + * ANTLR grammar rule
55 + *
56 + * typeBodyStatements : numericalRestrictions | decimal64Specification | stringRestrictions | enumSpecification
57 + * | leafrefSpecification | identityrefSpecification | instanceIdentifierSpecification
58 + * | bitsSpecification | unionSpecification;
59 + *
60 + * decimal64Specification : fractionDigitStatement rangeStatement?;
61 + *
62 + * fractionDigitStatement : FRACTION_DIGITS_KEYWORD fraction STMTEND;
63 + *
64 + * fraction : string;
65 + */
66 +
67 +import org.onosproject.yangutils.datamodel.YangDecimal64;
68 +import org.onosproject.yangutils.datamodel.YangRangeRestriction;
69 +import org.onosproject.yangutils.datamodel.YangType;
70 +import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
71 +import org.onosproject.yangutils.datamodel.utils.Parsable;
72 +import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
73 +import org.onosproject.yangutils.parser.exceptions.ParserException;
74 +import org.onosproject.yangutils.parser.impl.TreeWalkListener;
75 +
76 +import static org.onosproject.yangutils.datamodel.utils.YangConstructType.DECIMAL64_DATA;
77 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
78 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
79 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
80 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
81 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
82 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
83 +
84 +/**
85 + * Represents listener based call back function corresponding to the "decimal64" rule
86 + * defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
87 + */
88 +public final class Decimal64Listener {
89 +
90 + /**
91 + * Creates a new Decimal64 listener.
92 + */
93 + private Decimal64Listener() {
94 + }
95 +
96 + /**
97 + * It is called when parser enters grammar rule (decimal64), it perform
98 + * validations and updates the data model tree.
99 + *
100 + * @param listener listener's object
101 + * @param ctx context object of the grammar rule
102 + */
103 + public static void processDecimal64Entry(TreeWalkListener listener,
104 + GeneratedYangParser.Decimal64SpecificationContext ctx) {
105 +
106 + // Check for stack to be non empty.
107 + checkStackIsNotEmpty(listener, MISSING_HOLDER, DECIMAL64_DATA, "", ENTRY);
108 +
109 + Parsable tmpNode = listener.getParsedDataStack().peek();
110 + if (tmpNode instanceof YangType) {
111 + YangType<YangDecimal64<YangRangeRestriction>> typeNode =
112 + (YangType<YangDecimal64<YangRangeRestriction>>) tmpNode;
113 + YangDecimal64 decimal64Node = new YangDecimal64();
114 + typeNode.setDataTypeExtendedInfo(decimal64Node);
115 + } else {
116 + throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, DECIMAL64_DATA, "", ENTRY));
117 + }
118 + }
119 +
120 + /**
121 + * Performs validation and updates the data model tree.
122 + * It is called when parser exits from grammar rule (decimal64).
123 + *
124 + * @param listener listener's object
125 + * @param ctx context object of the grammar rule
126 + */
127 + public static void processDecimal64Exit(TreeWalkListener listener,
128 + GeneratedYangParser.Decimal64SpecificationContext ctx) {
129 +
130 + // Check for stack to be non empty.
131 + checkStackIsNotEmpty(listener, MISSING_HOLDER, DECIMAL64_DATA, "", EXIT);
132 +
133 + Parsable tmpNode = listener.getParsedDataStack().peek();
134 + if (tmpNode instanceof YangType) {
135 + YangType<YangDecimal64<YangRangeRestriction>> typeNode =
136 + (YangType<YangDecimal64<YangRangeRestriction>>) tmpNode;
137 + YangDecimal64<YangRangeRestriction> decimal64Node = typeNode.getDataTypeExtendedInfo();
138 + try {
139 + decimal64Node.validateRange();
140 + } catch (DataModelException e) {
141 + throw new ParserException(e);
142 + }
143 + } else {
144 + throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, DECIMAL64_DATA, "", EXIT));
145 + }
146 + }
147 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016-present 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.parser.impl.listeners;
18 +
19 +/*
20 + * Reference: RFC6020 and YANG ANTLR Grammar
21 + *
22 + * ABNF grammar as per RFC6020
23 + * decimal64-specification = fraction-digits-stmt
24 + *
25 + * fraction-digits-stmt = fraction-digits-keyword sep
26 + * fraction-digits-arg-str stmtend
27 + *
28 + * fraction-digits-arg-str = < a string that matches the rule
29 + * fraction-digits-arg >
30 + *
31 + * fraction-digits-arg = ("1" ["0" / "1" / "2" / "3" / "4" /
32 + * "5" / "6" / "7" / "8"])
33 + * / "2" / "3" / "4" / "5" / "6" / "7" / "8" / "9"
34 + *
35 + * ANTLR grammar rule
36 + * decimal64Specification : FRACTION_DIGITS_KEYWORD fraction STMTEND;
37 + *
38 + * fraction : string;
39 + */
40 +
41 +import org.onosproject.yangutils.datamodel.YangDecimal64;
42 +import org.onosproject.yangutils.datamodel.YangRangeRestriction;
43 +import org.onosproject.yangutils.datamodel.YangType;
44 +import org.onosproject.yangutils.datamodel.utils.Parsable;
45 +import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
46 +import org.onosproject.yangutils.parser.exceptions.ParserException;
47 +import org.onosproject.yangutils.parser.impl.TreeWalkListener;
48 +
49 +import static org.onosproject.yangutils.datamodel.utils.YangConstructType.FRACTION_DIGITS_DATA;
50 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
51 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
52 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
53 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
54 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
55 +
56 +/**
57 + * Represents listener based call back function corresponding to the "fraction-digits"
58 + * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
59 + */
60 +public final class FractionDigitsListener {
61 +
62 + /**
63 + * Creates a new bit listener.
64 + */
65 + private FractionDigitsListener() {
66 + }
67 +
68 + /**
69 + * It is called when parser enters grammar rule (fraction-digits), it perform
70 + * validations and updates the data model tree.
71 + *
72 + * @param listener listener's object
73 + * @param ctx context object of the grammar rule
74 + */
75 + public static void processFractionDigitsEntry(TreeWalkListener listener,
76 + GeneratedYangParser.FractionDigitStatementContext ctx) {
77 +
78 + // Check for stack to be non empty.
79 + checkStackIsNotEmpty(listener, MISSING_HOLDER, FRACTION_DIGITS_DATA, ctx.fraction().getText(), ENTRY);
80 +
81 + int value = getValidFractionDigits(ctx);
82 +
83 + Parsable tmpNode = listener.getParsedDataStack().peek();
84 + if (tmpNode instanceof YangType) {
85 + YangType<YangDecimal64<YangRangeRestriction>> typeNode =
86 + (YangType<YangDecimal64<YangRangeRestriction>>) tmpNode;
87 + YangDecimal64 decimal64Node = typeNode.getDataTypeExtendedInfo();
88 + decimal64Node.setFractionDigit(value);
89 + } else {
90 + throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, FRACTION_DIGITS_DATA,
91 + ctx.fraction().getText(), ENTRY));
92 + }
93 + }
94 +
95 + /**
96 + * Validate fraction digits.
97 + *
98 + * @param ctx context object of the grammar rule
99 + * @return validated fraction-digits
100 + */
101 + public static int getValidFractionDigits(GeneratedYangParser.FractionDigitStatementContext ctx) {
102 + String value = ctx.fraction().getText().trim();
103 + ParserException parserException;
104 +
105 + int fractionDigits = Integer.parseInt(value);
106 + if ((fractionDigits >= YangDecimal64.MIN_FRACTION_DIGITS_VALUE) &&
107 + (fractionDigits <= YangDecimal64.MAX_FRACTION_DIGITS_VALUE)) {
108 + return fractionDigits;
109 + } else {
110 + parserException =
111 + new ParserException("YANG file error : fraction-digits value should be between 1 and 18.");
112 + parserException.setLine(ctx.getStart().getLine());
113 + parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
114 + throw parserException;
115 + }
116 + }
117 +}
...@@ -109,17 +109,14 @@ public final class PositionListener { ...@@ -109,17 +109,14 @@ public final class PositionListener {
109 switch (tmpNode.getYangConstructType()) { 109 switch (tmpNode.getYangConstructType()) {
110 case BITS_DATA: { 110 case BITS_DATA: {
111 YangBits yangBits = (YangBits) tmpNode; 111 YangBits yangBits = (YangBits) tmpNode;
112 - for (YangBit curBit : yangBits.getBitSet()) {
113 - if (positionValue == curBit.getPosition()) {
114 listener.getParsedDataStack().push(bitNode); 112 listener.getParsedDataStack().push(bitNode);
113 + if (yangBits.isBitPositionExists(positionValue)) {
115 ParserException parserException = new ParserException("YANG file error: Duplicate value of " + 114 ParserException parserException = new ParserException("YANG file error: Duplicate value of " +
116 "position is invalid."); 115 "position is invalid.");
117 parserException.setLine(ctx.getStart().getLine()); 116 parserException.setLine(ctx.getStart().getLine());
118 parserException.setCharPosition(ctx.getStart().getCharPositionInLine()); 117 parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
119 throw parserException; 118 throw parserException;
120 } 119 }
121 - }
122 - listener.getParsedDataStack().push(bitNode);
123 return positionValue; 120 return positionValue;
124 } 121 }
125 default: 122 default:
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 16
17 package org.onosproject.yangutils.parser.impl.listeners; 17 package org.onosproject.yangutils.parser.impl.listeners;
18 18
19 +import org.onosproject.yangutils.datamodel.YangDecimal64;
19 import org.onosproject.yangutils.datamodel.YangDerivedInfo; 20 import org.onosproject.yangutils.datamodel.YangDerivedInfo;
20 import org.onosproject.yangutils.datamodel.YangRangeRestriction; 21 import org.onosproject.yangutils.datamodel.YangRangeRestriction;
21 import org.onosproject.yangutils.datamodel.YangType; 22 import org.onosproject.yangutils.datamodel.YangType;
...@@ -25,6 +26,7 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; ...@@ -25,6 +26,7 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
25 import org.onosproject.yangutils.parser.exceptions.ParserException; 26 import org.onosproject.yangutils.parser.exceptions.ParserException;
26 import org.onosproject.yangutils.parser.impl.TreeWalkListener; 27 import org.onosproject.yangutils.parser.impl.TreeWalkListener;
27 28
29 +import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DECIMAL64;
28 import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DERIVED; 30 import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DERIVED;
29 import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypeUtils.isOfRangeRestrictedType; 31 import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypeUtils.isOfRangeRestrictedType;
30 import static org.onosproject.yangutils.datamodel.utils.RestrictionResolver.processRangeRestriction; 32 import static org.onosproject.yangutils.datamodel.utils.RestrictionResolver.processRangeRestriction;
...@@ -112,7 +114,7 @@ public final class RangeRestrictionListener { ...@@ -112,7 +114,7 @@ public final class RangeRestrictionListener {
112 return; 114 return;
113 } 115 }
114 116
115 - if (!(isOfRangeRestrictedType(type.getDataType()))) { 117 + if (!(isOfRangeRestrictedType(type.getDataType())) && (type.getDataType() != DECIMAL64)) {
116 ParserException parserException = new ParserException("YANG file error: Range restriction can't be " + 118 ParserException parserException = new ParserException("YANG file error: Range restriction can't be " +
117 "applied to a given type"); 119 "applied to a given type");
118 parserException.setLine(ctx.getStart().getLine()); 120 parserException.setLine(ctx.getStart().getLine());
...@@ -122,8 +124,17 @@ public final class RangeRestrictionListener { ...@@ -122,8 +124,17 @@ public final class RangeRestrictionListener {
122 124
123 YangRangeRestriction rangeRestriction = null; 125 YangRangeRestriction rangeRestriction = null;
124 try { 126 try {
127 + if (type.getDataType() == DECIMAL64) {
128 + YangDecimal64 yangDecimal64 = (YangDecimal64) type.getDataTypeExtendedInfo();
129 + rangeRestriction = processRangeRestriction(yangDecimal64.getDefaultRangeRestriction(),
130 + ctx.getStart().getLine(),
131 + ctx.getStart().getCharPositionInLine(),
132 + true, ctx.range().getText(), type.getDataType());
133 + } else {
125 rangeRestriction = processRangeRestriction(null, ctx.getStart().getLine(), 134 rangeRestriction = processRangeRestriction(null, ctx.getStart().getLine(),
126 - ctx.getStart().getCharPositionInLine(), false, ctx.range().getText(), type.getDataType()); 135 + ctx.getStart().getCharPositionInLine(),
136 + false, ctx.range().getText(), type.getDataType());
137 + }
127 } catch (DataModelException e) { 138 } catch (DataModelException e) {
128 ParserException parserException = new ParserException(e.getMessage()); 139 ParserException parserException = new ParserException(e.getMessage());
129 parserException.setCharPosition(e.getCharPositionInLine()); 140 parserException.setCharPosition(e.getCharPositionInLine());
...@@ -132,8 +143,13 @@ public final class RangeRestrictionListener { ...@@ -132,8 +143,13 @@ public final class RangeRestrictionListener {
132 } 143 }
133 144
134 if (rangeRestriction != null) { 145 if (rangeRestriction != null) {
146 + if (type.getDataType() == DECIMAL64) {
147 + ((YangDecimal64<YangRangeRestriction>) type.getDataTypeExtendedInfo())
148 + .setRangeRestrictedExtendedInfo(rangeRestriction);
149 + } else {
135 type.setDataTypeExtendedInfo(rangeRestriction); 150 type.setDataTypeExtendedInfo(rangeRestriction);
136 } 151 }
152 + }
137 listener.getParsedDataStack().push(rangeRestriction); 153 listener.getParsedDataStack().push(rangeRestriction);
138 } 154 }
139 155
......
...@@ -94,6 +94,7 @@ public final class TypeListener { ...@@ -94,6 +94,7 @@ public final class TypeListener {
94 // Obtain the YANG data type. 94 // Obtain the YANG data type.
95 YangDataTypes yangDataTypes = YangDataTypes.getType(ctx.string().getText()); 95 YangDataTypes yangDataTypes = YangDataTypes.getType(ctx.string().getText());
96 96
97 + // validate type sub-statement cardinality
97 validateTypeSubStatementCardinality(ctx, yangDataTypes); 98 validateTypeSubStatementCardinality(ctx, yangDataTypes);
98 99
99 // Create YANG type object and fill the values. 100 // Create YANG type object and fill the values.
...@@ -306,6 +307,10 @@ public final class TypeListener { ...@@ -306,6 +307,10 @@ public final class TypeListener {
306 parserException = new ParserException("YANG file error : a type bits" + 307 parserException = new ParserException("YANG file error : a type bits" +
307 " must have atleast one bit statement."); 308 " must have atleast one bit statement.");
308 break; 309 break;
310 + case DECIMAL64:
311 + parserException = new ParserException("YANG file error : a type decimal64" +
312 + " must have fraction-digits statement.");
313 + break;
309 case LEAFREF: 314 case LEAFREF:
310 parserException = new ParserException("YANG file error : a type leafref" + 315 parserException = new ParserException("YANG file error : a type leafref" +
311 " must have one path statement."); 316 " must have one path statement.");
...@@ -314,7 +319,6 @@ public final class TypeListener { ...@@ -314,7 +319,6 @@ public final class TypeListener {
314 parserException = new ParserException("YANG file error : a type identityref" + 319 parserException = new ParserException("YANG file error : a type identityref" +
315 " must have base statement."); 320 " must have base statement.");
316 break; 321 break;
317 - // TODO : decimal64,
318 default: 322 default:
319 return; 323 return;
320 } 324 }
......
...@@ -37,10 +37,13 @@ import org.onosproject.yangutils.utils.io.impl.YangToJavaNamingConflictUtil; ...@@ -37,10 +37,13 @@ import org.onosproject.yangutils.utils.io.impl.YangToJavaNamingConflictUtil;
37 import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.getCurNodePackage; 37 import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.getCurNodePackage;
38 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage; 38 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
39 import static org.onosproject.yangutils.utils.UtilConstants.BIG_INTEGER; 39 import static org.onosproject.yangutils.utils.UtilConstants.BIG_INTEGER;
40 +import static org.onosproject.yangutils.utils.UtilConstants.BIG_DECIMAL;
41 +import static org.onosproject.yangutils.utils.UtilConstants.BIT_SET;
40 import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE; 42 import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE;
41 import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_WRAPPER; 43 import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_WRAPPER;
42 import static org.onosproject.yangutils.utils.UtilConstants.BYTE; 44 import static org.onosproject.yangutils.utils.UtilConstants.BYTE;
43 import static org.onosproject.yangutils.utils.UtilConstants.BYTE_WRAPPER; 45 import static org.onosproject.yangutils.utils.UtilConstants.BYTE_WRAPPER;
46 +import static org.onosproject.yangutils.utils.UtilConstants.COLLECTION_IMPORTS;
44 import static org.onosproject.yangutils.utils.UtilConstants.INT; 47 import static org.onosproject.yangutils.utils.UtilConstants.INT;
45 import static org.onosproject.yangutils.utils.UtilConstants.INTEGER_WRAPPER; 48 import static org.onosproject.yangutils.utils.UtilConstants.INTEGER_WRAPPER;
46 import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG; 49 import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG;
...@@ -50,11 +53,8 @@ import static org.onosproject.yangutils.utils.UtilConstants.LONG_WRAPPER; ...@@ -50,11 +53,8 @@ import static org.onosproject.yangutils.utils.UtilConstants.LONG_WRAPPER;
50 import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; 53 import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
51 import static org.onosproject.yangutils.utils.UtilConstants.SHORT; 54 import static org.onosproject.yangutils.utils.UtilConstants.SHORT;
52 import static org.onosproject.yangutils.utils.UtilConstants.SHORT_WRAPPER; 55 import static org.onosproject.yangutils.utils.UtilConstants.SHORT_WRAPPER;
56 +import static org.onosproject.yangutils.utils.UtilConstants.SQUARE_BRACKETS;
53 import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE; 57 import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE;
54 -import static org.onosproject.yangutils.utils.UtilConstants.YANG_BINARY_CLASS;
55 -import static org.onosproject.yangutils.utils.UtilConstants.YANG_BITS_CLASS;
56 -import static org.onosproject.yangutils.utils.UtilConstants.YANG_DECIMAL64_CLASS;
57 -import static org.onosproject.yangutils.utils.UtilConstants.YANG_TYPES_PKG;
58 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase; 58 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
59 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase; 59 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
60 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPackageDirPathFromJavaJPackage; 60 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPackageDirPathFromJavaJPackage;
...@@ -97,10 +97,12 @@ public final class AttributesJavaDataType { ...@@ -97,10 +97,12 @@ public final class AttributesJavaDataType {
97 return LONG; 97 return LONG;
98 case UINT64: 98 case UINT64:
99 return BIG_INTEGER; 99 return BIG_INTEGER;
100 + case BITS:
101 + return BIT_SET;
100 case BINARY: 102 case BINARY:
101 - return YANG_BINARY_CLASS; 103 + return BYTE + SQUARE_BRACKETS;
102 case DECIMAL64: 104 case DECIMAL64:
103 - return YANG_DECIMAL64_CLASS; 105 + return BIG_DECIMAL;
104 case STRING: 106 case STRING:
105 return STRING_DATA_TYPE; 107 return STRING_DATA_TYPE;
106 case BOOLEAN: 108 case BOOLEAN:
...@@ -146,7 +148,7 @@ public final class AttributesJavaDataType { ...@@ -146,7 +148,7 @@ public final class AttributesJavaDataType {
146 case UINT64: 148 case UINT64:
147 return BIG_INTEGER; 149 return BIG_INTEGER;
148 case DECIMAL64: 150 case DECIMAL64:
149 - return YANG_DECIMAL64_CLASS; 151 + return BIG_DECIMAL;
150 case STRING: 152 case STRING:
151 return STRING_DATA_TYPE; 153 return STRING_DATA_TYPE;
152 case BOOLEAN: 154 case BOOLEAN:
...@@ -156,9 +158,9 @@ public final class AttributesJavaDataType { ...@@ -156,9 +158,9 @@ public final class AttributesJavaDataType {
156 getCamelCase(((YangJavaEnumeration) yangType.getDataTypeExtendedInfo()).getName(), 158 getCamelCase(((YangJavaEnumeration) yangType.getDataTypeExtendedInfo()).getName(),
157 pluginConfig)); 159 pluginConfig));
158 case BITS: 160 case BITS:
159 - return YANG_BITS_CLASS; 161 + return BIT_SET;
160 case BINARY: 162 case BINARY:
161 - return YANG_BINARY_CLASS; 163 + return BYTE + SQUARE_BRACKETS;
162 case LEAFREF: 164 case LEAFREF:
163 YangType<?> referredType = getReferredTypeFromLeafref(yangType); 165 YangType<?> referredType = getReferredTypeFromLeafref(yangType);
164 return getJavaImportClass(referredType, isListAttr, pluginConfig); 166 return getJavaImportClass(referredType, isListAttr, pluginConfig);
...@@ -184,8 +186,6 @@ public final class AttributesJavaDataType { ...@@ -184,8 +186,6 @@ public final class AttributesJavaDataType {
184 switch (type) { 186 switch (type) {
185 case UINT64: 187 case UINT64:
186 return BIG_INTEGER; 188 return BIG_INTEGER;
187 - case DECIMAL64:
188 - return YANG_DECIMAL64_CLASS;
189 case STRING: 189 case STRING:
190 return STRING_DATA_TYPE; 190 return STRING_DATA_TYPE;
191 case ENUMERATION: 191 case ENUMERATION:
...@@ -193,9 +193,9 @@ public final class AttributesJavaDataType { ...@@ -193,9 +193,9 @@ public final class AttributesJavaDataType {
193 getCamelCase(((YangJavaEnumeration) yangType.getDataTypeExtendedInfo()).getName(), 193 getCamelCase(((YangJavaEnumeration) yangType.getDataTypeExtendedInfo()).getName(),
194 pluginConfig)); 194 pluginConfig));
195 case BITS: 195 case BITS:
196 - return YANG_BITS_CLASS; 196 + return BIT_SET;
197 - case BINARY: 197 + case DECIMAL64:
198 - return YANG_BINARY_CLASS; 198 + return BIG_DECIMAL;
199 case LEAFREF: 199 case LEAFREF:
200 YangType<?> referredType = getReferredTypeFromLeafref(yangType); 200 YangType<?> referredType = getReferredTypeFromLeafref(yangType);
201 return getJavaImportClass(referredType, isListAttr, pluginConfig); 201 return getJavaImportClass(referredType, isListAttr, pluginConfig);
...@@ -241,18 +241,18 @@ public final class AttributesJavaDataType { ...@@ -241,18 +241,18 @@ public final class AttributesJavaDataType {
241 case UINT8: 241 case UINT8:
242 case UINT16: 242 case UINT16:
243 case UINT32: 243 case UINT32:
244 + case BINARY:
244 case STRING: 245 case STRING:
245 case BOOLEAN: 246 case BOOLEAN:
246 case EMPTY: 247 case EMPTY:
247 return JAVA_LANG; 248 return JAVA_LANG;
248 case UINT64: 249 case UINT64:
250 + case DECIMAL64:
249 return JAVA_MATH; 251 return JAVA_MATH;
250 case ENUMERATION: 252 case ENUMERATION:
251 return getEnumsPackage(yangType, conflictResolver); 253 return getEnumsPackage(yangType, conflictResolver);
252 - case DECIMAL64:
253 case BITS: 254 case BITS:
254 - case BINARY: 255 + return COLLECTION_IMPORTS;
255 - return YANG_TYPES_PKG;
256 case LEAFREF: 256 case LEAFREF:
257 YangType<?> referredType = getReferredTypeFromLeafref(yangType); 257 YangType<?> referredType = getReferredTypeFromLeafref(yangType);
258 return getJavaImportPackage(referredType, isListAttr, conflictResolver); 258 return getJavaImportPackage(referredType, isListAttr, conflictResolver);
...@@ -270,22 +270,20 @@ public final class AttributesJavaDataType { ...@@ -270,22 +270,20 @@ public final class AttributesJavaDataType {
270 } else { 270 } else {
271 switch (type) { 271 switch (type) {
272 case UINT64: 272 case UINT64:
273 + case DECIMAL64:
273 return JAVA_MATH; 274 return JAVA_MATH;
275 + case EMPTY:
274 case STRING: 276 case STRING:
275 return JAVA_LANG; 277 return JAVA_LANG;
276 case ENUMERATION: 278 case ENUMERATION:
277 return getEnumsPackage(yangType, conflictResolver); 279 return getEnumsPackage(yangType, conflictResolver);
278 - case DECIMAL64:
279 case BITS: 280 case BITS:
280 - case BINARY: 281 + return COLLECTION_IMPORTS;
281 - return YANG_TYPES_PKG;
282 case LEAFREF: 282 case LEAFREF:
283 YangType<?> referredType = getReferredTypeFromLeafref(yangType); 283 YangType<?> referredType = getReferredTypeFromLeafref(yangType);
284 return getJavaImportPackage(referredType, isListAttr, conflictResolver); 284 return getJavaImportPackage(referredType, isListAttr, conflictResolver);
285 case IDENTITYREF: 285 case IDENTITYREF:
286 return getIdentityRefPackage(yangType, conflictResolver); 286 return getIdentityRefPackage(yangType, conflictResolver);
287 - case EMPTY:
288 - return JAVA_LANG;
289 case UNION: 287 case UNION:
290 return getUnionPackage(yangType, conflictResolver); 288 return getUnionPackage(yangType, conflictResolver);
291 case INSTANCE_IDENTIFIER: 289 case INSTANCE_IDENTIFIER:
......
...@@ -35,6 +35,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.AND; ...@@ -35,6 +35,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.AND;
35 import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION; 35 import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION;
36 import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO; 36 import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO;
37 import static org.onosproject.yangutils.utils.UtilConstants.BIG_INTEGER; 37 import static org.onosproject.yangutils.utils.UtilConstants.BIG_INTEGER;
38 +import static org.onosproject.yangutils.utils.UtilConstants.BIG_DECIMAL;
38 import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE; 39 import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE;
39 import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_WRAPPER; 40 import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_WRAPPER;
40 import static org.onosproject.yangutils.utils.UtilConstants.BUILD; 41 import static org.onosproject.yangutils.utils.UtilConstants.BUILD;
...@@ -54,6 +55,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.DEACTIVATE_ANNOTATIO ...@@ -54,6 +55,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.DEACTIVATE_ANNOTATIO
54 import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT; 55 import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT;
55 import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET; 56 import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET;
56 import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET; 57 import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET;
58 +import static org.onosproject.yangutils.utils.UtilConstants.DOUBLE;
57 import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION; 59 import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
58 import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; 60 import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
59 import static org.onosproject.yangutils.utils.UtilConstants.EQUAL; 61 import static org.onosproject.yangutils.utils.UtilConstants.EQUAL;
...@@ -64,6 +66,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.FALSE; ...@@ -64,6 +66,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.FALSE;
64 import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; 66 import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
65 import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_METHOD_NAME; 67 import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_METHOD_NAME;
66 import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_PARAM_NAME; 68 import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_PARAM_NAME;
69 +import static org.onosproject.yangutils.utils.UtilConstants.GET_BYTES;
67 import static org.onosproject.yangutils.utils.UtilConstants.GET_METHOD_PREFIX; 70 import static org.onosproject.yangutils.utils.UtilConstants.GET_METHOD_PREFIX;
68 import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_METHOD_STRING; 71 import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_METHOD_STRING;
69 import static org.onosproject.yangutils.utils.UtilConstants.HASH; 72 import static org.onosproject.yangutils.utils.UtilConstants.HASH;
...@@ -133,6 +136,7 @@ import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase; ...@@ -133,6 +136,7 @@ import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
133 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase; 136 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
134 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase; 137 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase;
135 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast; 138 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
139 +import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BINARY;
136 140
137 /** 141 /**
138 * Represents generator for methods of generated files based on the file type. 142 * Represents generator for methods of generated files based on the file type.
...@@ -296,6 +300,7 @@ public final class MethodsGenerator { ...@@ -296,6 +300,7 @@ public final class MethodsGenerator {
296 case INT: 300 case INT:
297 case SHORT: 301 case SHORT:
298 case LONG: 302 case LONG:
303 + case DOUBLE:
299 return "0"; 304 return "0";
300 case BOOLEAN_DATA_TYPE: 305 case BOOLEAN_DATA_TYPE:
301 return FALSE; 306 return FALSE;
...@@ -748,11 +753,16 @@ public final class MethodsGenerator { ...@@ -748,11 +753,16 @@ public final class MethodsGenerator {
748 JavaAttributeInfo fromStringAttributeInfo) { 753 JavaAttributeInfo fromStringAttributeInfo) {
749 754
750 String targetDataType = getReturnType(attr); 755 String targetDataType = getReturnType(attr);
756 + if (fromStringAttributeInfo.getAttributeType().getDataType() == BINARY) {
757 + return targetDataType + SPACE + TMP_VAL + SPACE + EQUAL + SPACE + FROM_STRING_PARAM_NAME
758 + + PERIOD + GET_BYTES + OPEN_PARENTHESIS + CLOSE_PARENTHESIS;
759 + } else {
751 String parseFromStringMethod = getParseFromStringMethod(targetDataType, 760 String parseFromStringMethod = getParseFromStringMethod(targetDataType,
752 fromStringAttributeInfo.getAttributeType()); 761 fromStringAttributeInfo.getAttributeType());
753 return targetDataType + SPACE + TMP_VAL + SPACE + EQUAL + SPACE + parseFromStringMethod 762 return targetDataType + SPACE + TMP_VAL + SPACE + EQUAL + SPACE + parseFromStringMethod
754 + OPEN_PARENTHESIS + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS; 763 + OPEN_PARENTHESIS + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS;
755 } 764 }
765 + }
756 766
757 /** 767 /**
758 * Returns hash code method open strings. 768 * Returns hash code method open strings.
...@@ -1092,14 +1102,14 @@ public final class MethodsGenerator { ...@@ -1092,14 +1102,14 @@ public final class MethodsGenerator {
1092 return LONG_WRAPPER + PERIOD + PARSE_LONG; 1102 return LONG_WRAPPER + PERIOD + PARSE_LONG;
1093 case UINT64: 1103 case UINT64:
1094 return NEW + SPACE + BIG_INTEGER; 1104 return NEW + SPACE + BIG_INTEGER;
1105 + case DECIMAL64:
1106 + return NEW + SPACE + BIG_DECIMAL;
1095 case STRING: 1107 case STRING:
1096 return EMPTY_STRING; 1108 return EMPTY_STRING;
1097 case EMPTY: 1109 case EMPTY:
1098 case BOOLEAN: 1110 case BOOLEAN:
1099 return BOOLEAN_WRAPPER + PERIOD + PARSE_BOOLEAN; 1111 return BOOLEAN_WRAPPER + PERIOD + PARSE_BOOLEAN;
1100 - case DECIMAL64:
1101 case BITS: 1112 case BITS:
1102 - case BINARY:
1103 case UNION: 1113 case UNION:
1104 case ENUMERATION: 1114 case ENUMERATION:
1105 case DERIVED: 1115 case DERIVED:
......
...@@ -197,6 +197,11 @@ public final class UtilConstants { ...@@ -197,6 +197,11 @@ public final class UtilConstants {
197 public static final String PARSE_BYTE = "parseByte"; 197 public static final String PARSE_BYTE = "parseByte";
198 198
199 /** 199 /**
200 + * Static attribute for get bytes.
201 + */
202 + public static final String GET_BYTES = "getBytes";
203 +
204 + /**
200 * Static attribute for parse boolean. 205 * Static attribute for parse boolean.
201 */ 206 */
202 public static final String PARSE_BOOLEAN = "parseBoolean"; 207 public static final String PARSE_BOOLEAN = "parseBoolean";
...@@ -567,6 +572,11 @@ public final class UtilConstants { ...@@ -567,6 +572,11 @@ public final class UtilConstants {
567 public static final String CLOSE_CURLY_BRACKET = "}"; 572 public static final String CLOSE_CURLY_BRACKET = "}";
568 573
569 /** 574 /**
575 + * Static attribute for square brackets syntax.
576 + */
577 + public static final String SQUARE_BRACKETS = "[]";
578 +
579 + /**
570 * Static attribute for getter method prefix. 580 * Static attribute for getter method prefix.
571 */ 581 */
572 public static final String GET_METHOD_PREFIX = "get"; 582 public static final String GET_METHOD_PREFIX = "get";
...@@ -687,6 +697,16 @@ public final class UtilConstants { ...@@ -687,6 +697,16 @@ public final class UtilConstants {
687 public static final String BIG_INTEGER = "BigInteger"; 697 public static final String BIG_INTEGER = "BigInteger";
688 698
689 /** 699 /**
700 + * BigDecimal built in java type.
701 + */
702 + public static final String BIG_DECIMAL = "BigDecimal";
703 +
704 + /**
705 + * BitSet built in java type.
706 + */
707 + public static final String BIT_SET = "BitSet";
708 +
709 + /**
690 * Byte java built in type. 710 * Byte java built in type.
691 */ 711 */
692 public static final String BYTE = "byte"; 712 public static final String BYTE = "byte";
...@@ -747,6 +767,11 @@ public final class UtilConstants { ...@@ -747,6 +767,11 @@ public final class UtilConstants {
747 public static final String YANG_UINT64 = "YangUint64"; 767 public static final String YANG_UINT64 = "YangUint64";
748 768
749 /** 769 /**
770 + * Double java built in wrapper type.
771 + */
772 + public static final String DOUBLE_WRAPPER = "Double";
773 +
774 + /**
750 * List of keywords in java, this is used for checking if the input does not contain these keywords. 775 * List of keywords in java, this is used for checking if the input does not contain these keywords.
751 */ 776 */
752 public static final List<String> JAVA_KEY_WORDS = Arrays.asList( 777 public static final List<String> JAVA_KEY_WORDS = Arrays.asList(
...@@ -1136,16 +1161,6 @@ public final class UtilConstants { ...@@ -1136,16 +1161,6 @@ public final class UtilConstants {
1136 public static final String EVENT_LISTENER = "EventListener"; 1161 public static final String EVENT_LISTENER = "EventListener";
1137 1162
1138 /** 1163 /**
1139 - * Static attribute for YangBinary class.
1140 - */
1141 - public static final String YANG_BINARY_CLASS = "YangBinary";
1142 -
1143 - /**
1144 - * Static attribute for YangBinary class.
1145 - */
1146 - public static final String YANG_BITS_CLASS = "YangBits";
1147 -
1148 - /**
1149 * Static attribute for YANG types package. 1164 * Static attribute for YANG types package.
1150 */ 1165 */
1151 public static final String YANG_TYPES_PKG = "org.onosproject.yangutils.datamodel.utils.builtindatatype"; 1166 public static final String YANG_TYPES_PKG = "org.onosproject.yangutils.datamodel.utils.builtindatatype";
...@@ -1156,11 +1171,6 @@ public final class UtilConstants { ...@@ -1156,11 +1171,6 @@ public final class UtilConstants {
1156 public static final String MATH_CONTEXT = "MathContext"; 1171 public static final String MATH_CONTEXT = "MathContext";
1157 1172
1158 /** 1173 /**
1159 - * Static attribute for DECIMAL64 class.
1160 - */
1161 - public static final String YANG_DECIMAL64_CLASS = "YangDecimal64";
1162 -
1163 - /**
1164 * Static attribute for YANG file error. 1174 * Static attribute for YANG file error.
1165 */ 1175 */
1166 public static final String YANG_FILE_ERROR = "YANG file error : "; 1176 public static final String YANG_FILE_ERROR = "YANG file error : ";
......
...@@ -375,6 +375,13 @@ package org.onosproject.yangutils.parser.antlrgencode; ...@@ -375,6 +375,13 @@ package org.onosproject.yangutils.parser.antlrgencode;
375 | bitsSpecification | unionSpecification; 375 | bitsSpecification | unionSpecification;
376 376
377 /** 377 /**
378 + * decimal64-specification = ;; these stmts can appear in any order
379 + * fraction-digits-stmt
380 + * [range-stmt]
381 + */
382 + decimal64Specification : fractionDigitStatement rangeStatement?;
383 +
384 + /**
378 * fraction-digits-stmt = fraction-digits-keyword sep 385 * fraction-digits-stmt = fraction-digits-keyword sep
379 * fraction-digits-arg-str stmtend 386 * fraction-digits-arg-str stmtend
380 * 387 *
...@@ -385,7 +392,7 @@ package org.onosproject.yangutils.parser.antlrgencode; ...@@ -385,7 +392,7 @@ package org.onosproject.yangutils.parser.antlrgencode;
385 * "5" / "6" / "7" / "8"]) 392 * "5" / "6" / "7" / "8"])
386 * / "2" / "3" / "4" / "5" / "6" / "7" / "8" / "9" 393 * / "2" / "3" / "4" / "5" / "6" / "7" / "8" / "9"
387 */ 394 */
388 - decimal64Specification : FRACTION_DIGITS_KEYWORD fraction STMTEND; 395 + fractionDigitStatement : FRACTION_DIGITS_KEYWORD fraction STMTEND;
389 396
390 /** 397 /**
391 * numerical-restrictions = range-stmt stmtsep 398 * numerical-restrictions = range-stmt stmtsep
......
...@@ -35,7 +35,7 @@ import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; ...@@ -35,7 +35,7 @@ import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
35 import java.io.IOException; 35 import java.io.IOException;
36 import java.util.List; 36 import java.util.List;
37 import java.util.ListIterator; 37 import java.util.ListIterator;
38 -import java.util.Set; 38 +import java.util.Map;
39 39
40 /** 40 /**
41 * Test cases for bit listener. 41 * Test cases for bit listener.
...@@ -71,14 +71,38 @@ public class BitListenerTest { ...@@ -71,14 +71,38 @@ public class BitListenerTest {
71 assertThat(((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo()).getBitsName(), 71 assertThat(((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo()).getBitsName(),
72 is("mybits")); 72 is("mybits"));
73 73
74 - Set<YangBit> bitSet = ((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo()).getBitSet(); 74 + // Check bit name map
75 - for (YangBit tmp : bitSet) { 75 + Map<String, YangBit> bitNameMap = ((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo()).getBitNameMap();
76 - if (tmp.getBitName().equals("disable-nagle")) { 76 + assertThat(bitNameMap.size(), is(3));
77 - assertThat(tmp.getPosition(), is(0)); 77 + for (Map.Entry<String, YangBit> element : bitNameMap.entrySet()) {
78 - } else if (tmp.getBitName().equals("auto-sense-speed")) { 78 + String bitName = element.getKey();
79 - assertThat(tmp.getPosition(), is(1)); 79 + YangBit yangBit = element.getValue();
80 - } else if (tmp.getBitName().equals("Ten-Mb-only")) { 80 + if (bitName.equals("disable-nagle")) {
81 - assertThat(tmp.getPosition(), is(2)); 81 + assertThat(yangBit.getPosition(), is(0));
82 + } else if (bitName.equals("auto-sense-speed")) {
83 + assertThat(yangBit.getPosition(), is(1));
84 + } else if (bitName.equals("Ten-Mb-only")) {
85 + assertThat(yangBit.getPosition(), is(2));
86 + } else {
87 + throw new IOException("Invalid bit name: " + bitName);
88 + }
89 + }
90 +
91 + // Check bit position map
92 + Map<Integer, YangBit> bitPositionMap = ((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo())
93 + .getBitPositionMap();
94 + assertThat(bitPositionMap.size(), is(3));
95 + for (Map.Entry<Integer, YangBit> element : bitPositionMap.entrySet()) {
96 + int position = element.getKey();
97 + YangBit yangBit = element.getValue();
98 + if (position == 0) {
99 + assertThat(yangBit.getBitName(), is("disable-nagle"));
100 + } else if (position == 1) {
101 + assertThat(yangBit.getBitName(), is("auto-sense-speed"));
102 + } else if (position == 2) {
103 + assertThat(yangBit.getBitName(), is("Ten-Mb-only"));
104 + } else {
105 + throw new IOException("Invalid bit position: " + position);
82 } 106 }
83 } 107 }
84 } 108 }
...@@ -107,12 +131,38 @@ public class BitListenerTest { ...@@ -107,12 +131,38 @@ public class BitListenerTest {
107 YangType type = typedef.getTypeList().iterator().next(); 131 YangType type = typedef.getTypeList().iterator().next();
108 assertThat(type.getDataType(), is(YangDataTypes.BITS)); 132 assertThat(type.getDataType(), is(YangDataTypes.BITS));
109 assertThat(type.getDataTypeName(), is("bits")); 133 assertThat(type.getDataTypeName(), is("bits"));
110 - Set<YangBit> bitSet = ((YangBits) type.getDataTypeExtendedInfo()).getBitSet(); 134 +
111 - for (YangBit tmp : bitSet) { 135 + // Check bit name map
112 - if (tmp.getBitName().equals("disable-nagle")) { 136 + Map<String, YangBit> bitNameMap = ((YangBits) type.getDataTypeExtendedInfo()).getBitNameMap();
113 - assertThat(tmp.getPosition(), is(0)); 137 + assertThat(bitNameMap.size(), is(3));
114 - } else if (tmp.getBitName().equals("auto-sense-speed")) { 138 + for (Map.Entry<String, YangBit> element : bitNameMap.entrySet()) {
115 - assertThat(tmp.getPosition(), is(1)); 139 + String bitName = element.getKey();
140 + YangBit yangBit = element.getValue();
141 + if (bitName.equals("disable-nagle")) {
142 + assertThat(yangBit.getPosition(), is(0));
143 + } else if (bitName.equals("auto-sense-speed")) {
144 + assertThat(yangBit.getPosition(), is(1));
145 + } else if (bitName.equals("Mb-only")) {
146 + assertThat(yangBit.getPosition(), is(2));
147 + } else {
148 + throw new IOException("Invalid bit name: " + bitName);
149 + }
150 + }
151 +
152 + // Check bit position map
153 + Map<Integer, YangBit> bitPositionMap = ((YangBits) type.getDataTypeExtendedInfo()).getBitPositionMap();
154 + assertThat(bitPositionMap.size(), is(3));
155 + for (Map.Entry<Integer, YangBit> element : bitPositionMap.entrySet()) {
156 + int position = element.getKey();
157 + YangBit yangBit = element.getValue();
158 + if (position == 0) {
159 + assertThat(yangBit.getBitName(), is("disable-nagle"));
160 + } else if (position == 1) {
161 + assertThat(yangBit.getBitName(), is("auto-sense-speed"));
162 + } else if (position == 2) {
163 + assertThat(yangBit.getBitName(), is("Mb-only"));
164 + } else {
165 + throw new IOException("Invalid bit position: " + position);
116 } 166 }
117 } 167 }
118 } 168 }
...@@ -151,12 +201,38 @@ public class BitListenerTest { ...@@ -151,12 +201,38 @@ public class BitListenerTest {
151 201
152 assertThat(yangType.getDataType(), is(YangDataTypes.BITS)); 202 assertThat(yangType.getDataType(), is(YangDataTypes.BITS));
153 assertThat(yangType.getDataTypeName(), is("bits")); 203 assertThat(yangType.getDataTypeName(), is("bits"));
154 - Set<YangBit> bitSet = ((YangBits) yangType.getDataTypeExtendedInfo()).getBitSet(); 204 +
155 - for (YangBit tmp : bitSet) { 205 + // Check bit name map
156 - if (tmp.getBitName().equals("disable-nagle")) { 206 + Map<String, YangBit> bitNameMap = ((YangBits) yangType.getDataTypeExtendedInfo()).getBitNameMap();
157 - assertThat(tmp.getPosition(), is(0)); 207 + assertThat(bitNameMap.size(), is(3));
158 - } else if (tmp.getBitName().equals("auto-sense-speed")) { 208 + for (Map.Entry<String, YangBit> element : bitNameMap.entrySet()) {
159 - assertThat(tmp.getPosition(), is(1)); 209 + String bitName = element.getKey();
210 + YangBit yangBit = element.getValue();
211 + if (bitName.equals("disable-nagle")) {
212 + assertThat(yangBit.getPosition(), is(0));
213 + } else if (bitName.equals("auto-sense-speed")) {
214 + assertThat(yangBit.getPosition(), is(1));
215 + } else if (bitName.equals("Mb-only")) {
216 + assertThat(yangBit.getPosition(), is(2));
217 + } else {
218 + throw new IOException("Invalid bit name: " + bitName);
219 + }
220 + }
221 +
222 + // Check bit position map
223 + Map<Integer, YangBit> bitPositionMap = ((YangBits) yangType.getDataTypeExtendedInfo()).getBitPositionMap();
224 + assertThat(bitPositionMap.size(), is(3));
225 + for (Map.Entry<Integer, YangBit> element : bitPositionMap.entrySet()) {
226 + int position = element.getKey();
227 + YangBit yangBit = element.getValue();
228 + if (position == 0) {
229 + assertThat(yangBit.getBitName(), is("disable-nagle"));
230 + } else if (position == 1) {
231 + assertThat(yangBit.getBitName(), is("auto-sense-speed"));
232 + } else if (position == 2) {
233 + assertThat(yangBit.getBitName(), is("Mb-only"));
234 + } else {
235 + throw new IOException("Invalid bit position: " + position);
160 } 236 }
161 } 237 }
162 } 238 }
......
...@@ -138,6 +138,37 @@ public class LengthRestrictionListenerTest { ...@@ -138,6 +138,37 @@ public class LengthRestrictionListenerTest {
138 } 138 }
139 139
140 /** 140 /**
141 + * Checks valid length statement as sub-statement of binary statement.
142 + */
143 + @Test
144 + public void processValidBinaryLengthStatement() throws IOException, ParserException {
145 +
146 + YangNode node = manager.getDataModel("src/test/resources/ValidBinaryLengthStatement.yang");
147 +
148 + assertThat((node instanceof YangModule), is(true));
149 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
150 + YangModule yangNode = (YangModule) node;
151 + assertThat(yangNode.getName(), is("Test"));
152 +
153 + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
154 + YangLeaf leafInfo = leafIterator.next();
155 +
156 + assertThat(leafInfo.getName(), is("message"));
157 + assertThat(leafInfo.getDataType().getDataTypeName(), is("binary"));
158 + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.BINARY));
159 + YangRangeRestriction lengthRestriction = (YangRangeRestriction) leafInfo
160 + .getDataType().getDataTypeExtendedInfo();
161 +
162 + ListIterator<YangRangeInterval> lengthListIterator = lengthRestriction.getAscendingRangeIntervals()
163 + .listIterator();
164 +
165 + YangRangeInterval rangeInterval = lengthListIterator.next();
166 +
167 + assertThat(((YangUint64) rangeInterval.getStartValue()).getValue(), is(BigInteger.valueOf(4)));
168 + assertThat(((YangUint64) rangeInterval.getEndValue()).getValue(), is(BigInteger.valueOf(4)));
169 + }
170 +
171 + /**
141 * Checks length statement with invalid type. 172 * Checks length statement with invalid type.
142 */ 173 */
143 @Test 174 @Test
......
...@@ -31,7 +31,7 @@ import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; ...@@ -31,7 +31,7 @@ import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
31 31
32 import java.io.IOException; 32 import java.io.IOException;
33 import java.util.ListIterator; 33 import java.util.ListIterator;
34 -import java.util.Set; 34 +import java.util.Map;
35 35
36 /** 36 /**
37 * Test cases for position listener. 37 * Test cases for position listener.
...@@ -67,14 +67,38 @@ public class PositionListenerTest { ...@@ -67,14 +67,38 @@ public class PositionListenerTest {
67 assertThat(((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo()).getBitsName(), 67 assertThat(((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo()).getBitsName(),
68 is("mybits")); 68 is("mybits"));
69 69
70 - Set<YangBit> bitSet = ((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo()).getBitSet(); 70 + // Check bit name map
71 - for (YangBit tmp : bitSet) { 71 + Map<String, YangBit> bitNameMap = ((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo()).getBitNameMap();
72 - if (tmp.getBitName().equals("disable-nagle")) { 72 + assertThat(bitNameMap.size(), is(3));
73 - assertThat(tmp.getPosition(), is(0)); 73 + for (Map.Entry<String, YangBit> element : bitNameMap.entrySet()) {
74 - } else if (tmp.getBitName().equals("auto-sense-speed")) { 74 + String bitName = element.getKey();
75 - assertThat(tmp.getPosition(), is(1)); 75 + YangBit yangBit = element.getValue();
76 - } else if (tmp.getBitName().equals("Ten-Mb-only")) { 76 + if (bitName.equals("disable-nagle")) {
77 - assertThat(tmp.getPosition(), is(2)); 77 + assertThat(yangBit.getPosition(), is(0));
78 + } else if (bitName.equals("auto-sense-speed")) {
79 + assertThat(yangBit.getPosition(), is(1));
80 + } else if (bitName.equals("Ten-Mb-only")) {
81 + assertThat(yangBit.getPosition(), is(2));
82 + } else {
83 + throw new IOException("Invalid bit name: " + bitName);
84 + }
85 + }
86 +
87 + // Check bit position map
88 + Map<Integer, YangBit> bitPositionMap = ((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo())
89 + .getBitPositionMap();
90 + assertThat(bitPositionMap.size(), is(3));
91 + for (Map.Entry<Integer, YangBit> element : bitPositionMap.entrySet()) {
92 + int position = element.getKey();
93 + YangBit yangBit = element.getValue();
94 + if (position == 0) {
95 + assertThat(yangBit.getBitName(), is("disable-nagle"));
96 + } else if (position == 1) {
97 + assertThat(yangBit.getBitName(), is("auto-sense-speed"));
98 + } else if (position == 2) {
99 + assertThat(yangBit.getBitName(), is("Ten-Mb-only"));
100 + } else {
101 + throw new IOException("Invalid bit position: " + position);
78 } 102 }
79 } 103 }
80 } 104 }
...@@ -106,14 +130,38 @@ public class PositionListenerTest { ...@@ -106,14 +130,38 @@ public class PositionListenerTest {
106 assertThat(((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo()).getBitsName(), 130 assertThat(((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo()).getBitsName(),
107 is("mybits")); 131 is("mybits"));
108 132
109 - Set<YangBit> bitSet = ((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo()).getBitSet(); 133 + // Check bit name map
110 - for (YangBit tmp : bitSet) { 134 + Map<String, YangBit> bitNameMap = ((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo()).getBitNameMap();
111 - if (tmp.getBitName().equals("disable-nagle")) { 135 + assertThat(bitNameMap.size(), is(3));
112 - assertThat(tmp.getPosition(), is(0)); 136 + for (Map.Entry<String, YangBit> element : bitNameMap.entrySet()) {
113 - } else if (tmp.getBitName().equals("auto-sense-speed")) { 137 + String bitName = element.getKey();
114 - assertThat(tmp.getPosition(), is(1)); 138 + YangBit yangBit = element.getValue();
115 - } else if (tmp.getBitName().equals("Ten-Mb-only")) { 139 + if (bitName.equals("disable-nagle")) {
116 - assertThat(tmp.getPosition(), is(2)); 140 + assertThat(yangBit.getPosition(), is(0));
141 + } else if (bitName.equals("auto-sense-speed")) {
142 + assertThat(yangBit.getPosition(), is(1));
143 + } else if (bitName.equals("Ten-Mb-only")) {
144 + assertThat(yangBit.getPosition(), is(2));
145 + } else {
146 + throw new IOException("Invalid bit name: " + bitName);
147 + }
148 + }
149 +
150 + // Check bit position map
151 + Map<Integer, YangBit> bitPositionMap = ((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo())
152 + .getBitPositionMap();
153 + assertThat(bitPositionMap.size(), is(3));
154 + for (Map.Entry<Integer, YangBit> element : bitPositionMap.entrySet()) {
155 + int position = element.getKey();
156 + YangBit yangBit = element.getValue();
157 + if (position == 0) {
158 + assertThat(yangBit.getBitName(), is("disable-nagle"));
159 + } else if (position == 1) {
160 + assertThat(yangBit.getBitName(), is("auto-sense-speed"));
161 + } else if (position == 2) {
162 + assertThat(yangBit.getBitName(), is("Ten-Mb-only"));
163 + } else {
164 + throw new IOException("Invalid bit position: " + position);
117 } 165 }
118 } 166 }
119 } 167 }
...@@ -145,14 +193,38 @@ public class PositionListenerTest { ...@@ -145,14 +193,38 @@ public class PositionListenerTest {
145 assertThat(((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo()).getBitsName(), 193 assertThat(((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo()).getBitsName(),
146 is("mybits")); 194 is("mybits"));
147 195
148 - Set<YangBit> bitSet = ((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo()).getBitSet(); 196 + // Check bit name map
149 - for (YangBit tmp : bitSet) { 197 + Map<String, YangBit> bitNameMap = ((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo()).getBitNameMap();
150 - if (tmp.getBitName().equals("disable-nagle")) { 198 + assertThat(bitNameMap.size(), is(3));
151 - assertThat(tmp.getPosition(), is(0)); 199 + for (Map.Entry<String, YangBit> element : bitNameMap.entrySet()) {
152 - } else if (tmp.getBitName().equals("auto-sense-speed")) { 200 + String bitName = element.getKey();
153 - assertThat(tmp.getPosition(), is(1)); 201 + YangBit yangBit = element.getValue();
154 - } else if (tmp.getBitName().equals("Ten-Mb-only")) { 202 + if (bitName.equals("disable-nagle")) {
155 - assertThat(tmp.getPosition(), is(2)); 203 + assertThat(yangBit.getPosition(), is(0));
204 + } else if (bitName.equals("auto-sense-speed")) {
205 + assertThat(yangBit.getPosition(), is(1));
206 + } else if (bitName.equals("Ten-Mb-only")) {
207 + assertThat(yangBit.getPosition(), is(2));
208 + } else {
209 + throw new IOException("Invalid bit name: " + bitName);
210 + }
211 + }
212 +
213 + // Check bit position map
214 + Map<Integer, YangBit> bitPositionMap = ((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo())
215 + .getBitPositionMap();
216 + assertThat(bitPositionMap.size(), is(3));
217 + for (Map.Entry<Integer, YangBit> element : bitPositionMap.entrySet()) {
218 + int position = element.getKey();
219 + YangBit yangBit = element.getValue();
220 + if (position == 0) {
221 + assertThat(yangBit.getBitName(), is("disable-nagle"));
222 + } else if (position == 1) {
223 + assertThat(yangBit.getBitName(), is("auto-sense-speed"));
224 + } else if (position == 2) {
225 + assertThat(yangBit.getBitName(), is("Ten-Mb-only"));
226 + } else {
227 + throw new IOException("Invalid bit position: " + position);
156 } 228 }
157 } 229 }
158 } 230 }
......
...@@ -26,7 +26,9 @@ module Test { ...@@ -26,7 +26,9 @@ module Test {
26 "Interface has time-division multiplex capabilities."; 26 "Interface has time-division multiplex capabilities.";
27 27
28 leaf minimum-lsp-bandwidth { 28 leaf minimum-lsp-bandwidth {
29 - type decimal64; 29 + type decimal64 {
30 + fraction-digits 4;
31 + }
30 } 32 }
31 } 33 }
32 } 34 }
......
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 +
6 + typedef topDecimal {
7 + type decimal64 {
8 + fraction-digits 4;
9 + }
10 + }
11 +
12 + typedef validDecimal {
13 + type topDecimal;
14 + }
15 +
16 + leaf setFourDecimal {
17 + type validDecimal;
18 + }
19 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 +
6 + leaf invalidDecimal1 {
7 + type decimal64 {
8 + fraction-digits 19;
9 + }
10 + }
11 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 +
6 + leaf invalidDecimal2 {
7 + type decimal64 {
8 + fraction-digits 0;
9 + }
10 + }
11 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 +
6 + leaf invalidDecimal3 {
7 + type decimal64 {
8 + fraction-digits -1;
9 + }
10 + }
11 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf validDecimal {
6 + type decimal64 {
7 + fraction-digits 18;
8 + range "1 .. 20.14";
9 + }
10 + }
11 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf validDecimal {
6 + type decimal64 {
7 + fraction-digits 2;
8 + }
9 + }
10 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf validDecimal {
6 + type decimal64 {
7 + fraction-digits 18;
8 + }
9 + }
10 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf validDecimal {
6 + type decimal64 {
7 + fraction-digits 18;
8 + range "-9.22..7.22 | 8 | 9..max";
9 + }
10 + }
11 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf validDecimal {
6 + type decimal64 {
7 + fraction-digits 8;
8 + range "-92233720368.54775808 .. 92233720368.54775807";
9 + }
10 + }
11 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf validDecimal {
6 + type decimal64;
7 + }
8 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 +
6 + typedef validDecimal {
7 + type decimal64 {
8 + fraction-digits 4;
9 + }
10 + }
11 +
12 + leaf setFourDecimal {
13 + type validDecimal;
14 + }
15 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf message {
6 + type binary {
7 + length "4";
8 + }
9 + }
10 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf message {
6 + type binary {
7 + length "4";
8 + }
9 + }
10 +}
...@@ -430,8 +430,8 @@ ...@@ -430,8 +430,8 @@
430 } 430 }
431 leaf unidirectional-packet-loss { 431 leaf unidirectional-packet-loss {
432 type decimal64 { 432 type decimal64 {
433 - /*fraction-digits 6; 433 + fraction-digits 6;
434 - range "0 .. 50.331642";*/ 434 + range "0 .. 50.331642";
435 } 435 }
436 description 436 description
437 "Packet loss as a percentage of the total traffic sent 437 "Packet loss as a percentage of the total traffic sent
...@@ -440,7 +440,7 @@ ...@@ -440,7 +440,7 @@
440 } 440 }
441 leaf unidirectional-residual-bandwidth { 441 leaf unidirectional-residual-bandwidth {
442 type decimal64 { 442 type decimal64 {
443 - /*fraction-digits 2;*/ 443 + fraction-digits 2;
444 } 444 }
445 description 445 description
446 "Residual bandwidth that subtracts tunnel 446 "Residual bandwidth that subtracts tunnel
...@@ -450,7 +450,7 @@ ...@@ -450,7 +450,7 @@
450 } 450 }
451 leaf unidirectional-available-bandwidth { 451 leaf unidirectional-available-bandwidth {
452 type decimal64 { 452 type decimal64 {
453 - /*fraction-digits 2;*/ 453 + fraction-digits 2;
454 } 454 }
455 description 455 description
456 "Available bandwidth that is defined to be residual 456 "Available bandwidth that is defined to be residual
...@@ -461,7 +461,7 @@ ...@@ -461,7 +461,7 @@
461 } 461 }
462 leaf unidirectional-utilized-bandwidth { 462 leaf unidirectional-utilized-bandwidth {
463 type decimal64 { 463 type decimal64 {
464 - /*fraction-digits 2;*/ 464 + fraction-digits 2;
465 } 465 }
466 description 466 description
467 "Bandwidth utilization that represents the actual 467 "Bandwidth utilization that represents the actual
...@@ -753,7 +753,7 @@ ...@@ -753,7 +753,7 @@
753 } 753 }
754 leaf max-link-bandwidth { 754 leaf max-link-bandwidth {
755 type decimal64 { 755 type decimal64 {
756 - /*fraction-digits 2;*/ 756 + fraction-digits 2;
757 } 757 }
758 description 758 description
759 "Maximum bandwidth that can be seen on this link in this 759 "Maximum bandwidth that can be seen on this link in this
...@@ -765,7 +765,7 @@ ...@@ -765,7 +765,7 @@
765 } 765 }
766 leaf max-resv-link-bandwidth { 766 leaf max-resv-link-bandwidth {
767 type decimal64 { 767 type decimal64 {
768 - /*fraction-digits 2;*/ 768 + fraction-digits 2;
769 } 769 }
770 description 770 description
771 "Maximum amount of bandwidth that can be reserved in this 771 "Maximum amount of bandwidth that can be reserved in this
...@@ -793,7 +793,7 @@ ...@@ -793,7 +793,7 @@
793 } 793 }
794 leaf bandwidth { 794 leaf bandwidth {
795 type decimal64 { 795 type decimal64 {
796 - /*fraction-digits 2;*/ 796 + fraction-digits 2;
797 } 797 }
798 description 798 description
799 "Unreserved bandwidth for this level."; 799 "Unreserved bandwidth for this level.";
...@@ -884,7 +884,7 @@ ...@@ -884,7 +884,7 @@
884 } 884 }
885 leaf bandwidth { 885 leaf bandwidth {
886 type decimal64 { 886 type decimal64 {
887 - /*fraction-digits 2;*/ 887 + fraction-digits 2;
888 } 888 }
889 description 889 description
890 "Max LSP Bandwidth for this level"; 890 "Max LSP Bandwidth for this level";
...@@ -899,7 +899,7 @@ ...@@ -899,7 +899,7 @@
899 899
900 leaf minimum-lsp-bandwidth { 900 leaf minimum-lsp-bandwidth {
901 type decimal64 { 901 type decimal64 {
902 - /*fraction-digits 2;*/ 902 + fraction-digits 2;
903 } 903 }
904 description 904 description
905 "Minimum LSP Bandwidth. Units in bytes per second."; 905 "Minimum LSP Bandwidth. Units in bytes per second.";
...@@ -951,7 +951,7 @@ ...@@ -951,7 +951,7 @@
951 } 951 }
952 leaf bandwidth { 952 leaf bandwidth {
953 type decimal64 { 953 type decimal64 {
954 - /*fraction-digits 2;*/ 954 + fraction-digits 2;
955 } 955 }
956 description 956 description
957 "Max LSP Bandwidth for this level."; 957 "Max LSP Bandwidth for this level.";
......
...@@ -580,7 +580,7 @@ ...@@ -580,7 +580,7 @@
580 580
581 typedef admin-group { 581 typedef admin-group {
582 type binary { 582 type binary {
583 -// length 32; 583 + length 32;
584 } 584 }
585 description 585 description
586 "Administrative group/Resource class/Color."; 586 "Administrative group/Resource class/Color.";
......