[ONOS-4348] Yang Bits, Binary and Decimal64
Change-Id: I8e4e54a19a8f9634cbc56a07579a1730174f53f6
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/antlrgencode/GeneratedYangListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/antlrgencode/GeneratedYangListener.java
index 9f5e0cc..5e55e15 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/antlrgencode/GeneratedYangListener.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/parser/antlrgencode/GeneratedYangListener.java
@@ -632,6 +632,22 @@
*
* @param currentContext current context in the parsed tree
*/
+ void enterFractionDigitStatement(GeneratedYangParser.FractionDigitStatementContext currentContext);
+
+ /**
+ * Exits a parse tree produced by GeneratedYangParser for grammar rule
+ * numericalRestrictions.
+ *
+ * @param currentContext current context in the parsed tree
+ */
+ void exitFractionDigitStatement(GeneratedYangParser.FractionDigitStatementContext currentContext);
+
+ /**
+ * Enters a parse tree produced by GeneratedYangParser for grammar rule
+ * numericalRestrictions.
+ *
+ * @param currentContext current context in the parsed tree
+ */
void enterNumericalRestrictions(GeneratedYangParser.NumericalRestrictionsContext currentContext);
/**
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/TreeWalkListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/TreeWalkListener.java
index a1daf0f..3d81e0d 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/TreeWalkListener.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/TreeWalkListener.java
@@ -37,11 +37,13 @@
import org.onosproject.yangutils.parser.impl.listeners.ConfigListener;
import org.onosproject.yangutils.parser.impl.listeners.ContactListener;
import org.onosproject.yangutils.parser.impl.listeners.ContainerListener;
+import org.onosproject.yangutils.parser.impl.listeners.Decimal64Listener;
import org.onosproject.yangutils.parser.impl.listeners.DefaultListener;
import org.onosproject.yangutils.parser.impl.listeners.DescriptionListener;
import org.onosproject.yangutils.parser.impl.listeners.EnumListener;
import org.onosproject.yangutils.parser.impl.listeners.EnumerationListener;
import org.onosproject.yangutils.parser.impl.listeners.FeatureListener;
+import org.onosproject.yangutils.parser.impl.listeners.FractionDigitsListener;
import org.onosproject.yangutils.parser.impl.listeners.GroupingListener;
import org.onosproject.yangutils.parser.impl.listeners.IdentityrefListener;
import org.onosproject.yangutils.parser.impl.listeners.IfFeatureListener;
@@ -563,12 +565,22 @@
@Override
public void enterDecimal64Specification(GeneratedYangParser.Decimal64SpecificationContext ctx) {
- // TODO: implement the method.
+ Decimal64Listener.processDecimal64Entry(this, ctx);
}
@Override
public void exitDecimal64Specification(GeneratedYangParser.Decimal64SpecificationContext ctx) {
- // TODO: implement the method.
+ Decimal64Listener.processDecimal64Exit(this, ctx);
+ }
+
+ @Override
+ public void enterFractionDigitStatement(GeneratedYangParser.FractionDigitStatementContext ctx) {
+ FractionDigitsListener.processFractionDigitsEntry(this, ctx);
+ }
+
+ @Override
+ public void exitFractionDigitStatement(GeneratedYangParser.FractionDigitStatementContext currentContext) {
+ // do nothing
}
@Override
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BitListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BitListener.java
index 39084e0..4dce199 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BitListener.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BitListener.java
@@ -61,6 +61,8 @@
* ;
*/
+import java.util.Map;
+
import org.onosproject.yangutils.datamodel.YangBit;
import org.onosproject.yangutils.datamodel.YangBits;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
@@ -141,12 +143,13 @@
int maxPosition = 0;
boolean isPositionPresent = false;
- for (YangBit curBit : yangBits.getBitSet()) {
- if (maxPosition <= curBit.getPosition()) {
- maxPosition = curBit.getPosition();
+ for (Map.Entry<Integer, YangBit> element : yangBits.getBitPositionMap().entrySet()) {
+ if (maxPosition <= element.getKey()) {
+ maxPosition = element.getKey();
isPositionPresent = true;
}
}
+
if (isPositionPresent) {
maxPosition++;
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/Decimal64Listener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/Decimal64Listener.java
new file mode 100644
index 0000000..45f58c8
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/Decimal64Listener.java
@@ -0,0 +1,147 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.parser.impl.listeners;
+
+/*
+ * Reference: RFC6020 and YANG ANTLR Grammar
+ *
+ * ABNF grammar as per RFC6020
+ * type-body-stmts = numerical-restrictions /
+ * decimal64-specification /
+ * string-restrictions /
+ * enum-specification /
+ * leafref-specification /
+ * identityref-specification /
+ * instance-identifier-specification /
+ * bits-specification /
+ * union-specification
+ *
+ * decimal64-specification = fraction-digits-stmt [range-stmt stmtsep]
+ *
+ * fraction-digits-stmt = fraction-digits-keyword sep
+ * fraction-digits-arg-str stmtend
+ *
+ * fraction-digits-arg-str = < a string that matches the rule
+ * fraction-digits-arg >
+ *
+ * fraction-digits-arg = ("1" ["0" / "1" / "2" / "3" / "4" /
+ * "5" / "6" / "7" / "8"])
+ * / "2" / "3" / "4" / "5" / "6" / "7" / "8" / "9"
+ *
+ * range-stmt = range-keyword sep range-arg-str optsep
+ * (";" /
+ * "{" stmtsep
+ * ;; these stmts can appear in any order
+ * [error-message-stmt stmtsep]
+ * [error-app-tag-stmt stmtsep]
+ * [description-stmt stmtsep]
+ * [reference-stmt stmtsep]
+ * "}")
+ * ANTLR grammar rule
+ *
+ * typeBodyStatements : numericalRestrictions | decimal64Specification | stringRestrictions | enumSpecification
+ * | leafrefSpecification | identityrefSpecification | instanceIdentifierSpecification
+ * | bitsSpecification | unionSpecification;
+ *
+ * decimal64Specification : fractionDigitStatement rangeStatement?;
+ *
+ * fractionDigitStatement : FRACTION_DIGITS_KEYWORD fraction STMTEND;
+ *
+ * fraction : string;
+ */
+
+import org.onosproject.yangutils.datamodel.YangDecimal64;
+import org.onosproject.yangutils.datamodel.YangRangeRestriction;
+import org.onosproject.yangutils.datamodel.YangType;
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.TreeWalkListener;
+
+import static org.onosproject.yangutils.datamodel.utils.YangConstructType.DECIMAL64_DATA;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
+
+/**
+ * Represents listener based call back function corresponding to the "decimal64" rule
+ * defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
+ */
+public final class Decimal64Listener {
+
+ /**
+ * Creates a new Decimal64 listener.
+ */
+ private Decimal64Listener() {
+ }
+
+ /**
+ * It is called when parser enters grammar rule (decimal64), it perform
+ * validations and updates the data model tree.
+ *
+ * @param listener listener's object
+ * @param ctx context object of the grammar rule
+ */
+ public static void processDecimal64Entry(TreeWalkListener listener,
+ GeneratedYangParser.Decimal64SpecificationContext ctx) {
+
+ // Check for stack to be non empty.
+ checkStackIsNotEmpty(listener, MISSING_HOLDER, DECIMAL64_DATA, "", ENTRY);
+
+ Parsable tmpNode = listener.getParsedDataStack().peek();
+ if (tmpNode instanceof YangType) {
+ YangType<YangDecimal64<YangRangeRestriction>> typeNode =
+ (YangType<YangDecimal64<YangRangeRestriction>>) tmpNode;
+ YangDecimal64 decimal64Node = new YangDecimal64();
+ typeNode.setDataTypeExtendedInfo(decimal64Node);
+ } else {
+ throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, DECIMAL64_DATA, "", ENTRY));
+ }
+ }
+
+ /**
+ * Performs validation and updates the data model tree.
+ * It is called when parser exits from grammar rule (decimal64).
+ *
+ * @param listener listener's object
+ * @param ctx context object of the grammar rule
+ */
+ public static void processDecimal64Exit(TreeWalkListener listener,
+ GeneratedYangParser.Decimal64SpecificationContext ctx) {
+
+ // Check for stack to be non empty.
+ checkStackIsNotEmpty(listener, MISSING_HOLDER, DECIMAL64_DATA, "", EXIT);
+
+ Parsable tmpNode = listener.getParsedDataStack().peek();
+ if (tmpNode instanceof YangType) {
+ YangType<YangDecimal64<YangRangeRestriction>> typeNode =
+ (YangType<YangDecimal64<YangRangeRestriction>>) tmpNode;
+ YangDecimal64<YangRangeRestriction> decimal64Node = typeNode.getDataTypeExtendedInfo();
+ try {
+ decimal64Node.validateRange();
+ } catch (DataModelException e) {
+ throw new ParserException(e);
+ }
+ } else {
+ throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, DECIMAL64_DATA, "", EXIT));
+ }
+ }
+}
\ No newline at end of file
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/FractionDigitsListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/FractionDigitsListener.java
new file mode 100644
index 0000000..baeb252
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/FractionDigitsListener.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.parser.impl.listeners;
+
+/*
+ * Reference: RFC6020 and YANG ANTLR Grammar
+ *
+ * ABNF grammar as per RFC6020
+ * decimal64-specification = fraction-digits-stmt
+ *
+ * fraction-digits-stmt = fraction-digits-keyword sep
+ * fraction-digits-arg-str stmtend
+ *
+ * fraction-digits-arg-str = < a string that matches the rule
+ * fraction-digits-arg >
+ *
+ * fraction-digits-arg = ("1" ["0" / "1" / "2" / "3" / "4" /
+ * "5" / "6" / "7" / "8"])
+ * / "2" / "3" / "4" / "5" / "6" / "7" / "8" / "9"
+ *
+ * ANTLR grammar rule
+ * decimal64Specification : FRACTION_DIGITS_KEYWORD fraction STMTEND;
+ *
+ * fraction : string;
+ */
+
+import org.onosproject.yangutils.datamodel.YangDecimal64;
+import org.onosproject.yangutils.datamodel.YangRangeRestriction;
+import org.onosproject.yangutils.datamodel.YangType;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.TreeWalkListener;
+
+import static org.onosproject.yangutils.datamodel.utils.YangConstructType.FRACTION_DIGITS_DATA;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
+
+/**
+ * Represents listener based call back function corresponding to the "fraction-digits"
+ * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
+ */
+public final class FractionDigitsListener {
+
+ /**
+ * Creates a new bit listener.
+ */
+ private FractionDigitsListener() {
+ }
+
+ /**
+ * It is called when parser enters grammar rule (fraction-digits), it perform
+ * validations and updates the data model tree.
+ *
+ * @param listener listener's object
+ * @param ctx context object of the grammar rule
+ */
+ public static void processFractionDigitsEntry(TreeWalkListener listener,
+ GeneratedYangParser.FractionDigitStatementContext ctx) {
+
+ // Check for stack to be non empty.
+ checkStackIsNotEmpty(listener, MISSING_HOLDER, FRACTION_DIGITS_DATA, ctx.fraction().getText(), ENTRY);
+
+ int value = getValidFractionDigits(ctx);
+
+ Parsable tmpNode = listener.getParsedDataStack().peek();
+ if (tmpNode instanceof YangType) {
+ YangType<YangDecimal64<YangRangeRestriction>> typeNode =
+ (YangType<YangDecimal64<YangRangeRestriction>>) tmpNode;
+ YangDecimal64 decimal64Node = typeNode.getDataTypeExtendedInfo();
+ decimal64Node.setFractionDigit(value);
+ } else {
+ throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, FRACTION_DIGITS_DATA,
+ ctx.fraction().getText(), ENTRY));
+ }
+ }
+
+ /**
+ * Validate fraction digits.
+ *
+ * @param ctx context object of the grammar rule
+ * @return validated fraction-digits
+ */
+ public static int getValidFractionDigits(GeneratedYangParser.FractionDigitStatementContext ctx) {
+ String value = ctx.fraction().getText().trim();
+ ParserException parserException;
+
+ int fractionDigits = Integer.parseInt(value);
+ if ((fractionDigits >= YangDecimal64.MIN_FRACTION_DIGITS_VALUE) &&
+ (fractionDigits <= YangDecimal64.MAX_FRACTION_DIGITS_VALUE)) {
+ return fractionDigits;
+ } else {
+ parserException =
+ new ParserException("YANG file error : fraction-digits value should be between 1 and 18.");
+ parserException.setLine(ctx.getStart().getLine());
+ parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
+ throw parserException;
+ }
+ }
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/PositionListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/PositionListener.java
index 4ae66bb..3a14927 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/PositionListener.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/PositionListener.java
@@ -109,17 +109,14 @@
switch (tmpNode.getYangConstructType()) {
case BITS_DATA: {
YangBits yangBits = (YangBits) tmpNode;
- for (YangBit curBit : yangBits.getBitSet()) {
- if (positionValue == curBit.getPosition()) {
- listener.getParsedDataStack().push(bitNode);
- ParserException parserException = new ParserException("YANG file error: Duplicate value of " +
- "position is invalid.");
- parserException.setLine(ctx.getStart().getLine());
- parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
- throw parserException;
- }
- }
listener.getParsedDataStack().push(bitNode);
+ if (yangBits.isBitPositionExists(positionValue)) {
+ ParserException parserException = new ParserException("YANG file error: Duplicate value of " +
+ "position is invalid.");
+ parserException.setLine(ctx.getStart().getLine());
+ parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
+ throw parserException;
+ }
return positionValue;
}
default:
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RangeRestrictionListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RangeRestrictionListener.java
index 9c2a4bd..3b4ae43 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RangeRestrictionListener.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RangeRestrictionListener.java
@@ -16,6 +16,7 @@
package org.onosproject.yangutils.parser.impl.listeners;
+import org.onosproject.yangutils.datamodel.YangDecimal64;
import org.onosproject.yangutils.datamodel.YangDerivedInfo;
import org.onosproject.yangutils.datamodel.YangRangeRestriction;
import org.onosproject.yangutils.datamodel.YangType;
@@ -25,6 +26,7 @@
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
+import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DECIMAL64;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DERIVED;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypeUtils.isOfRangeRestrictedType;
import static org.onosproject.yangutils.datamodel.utils.RestrictionResolver.processRangeRestriction;
@@ -112,7 +114,7 @@
return;
}
- if (!(isOfRangeRestrictedType(type.getDataType()))) {
+ if (!(isOfRangeRestrictedType(type.getDataType())) && (type.getDataType() != DECIMAL64)) {
ParserException parserException = new ParserException("YANG file error: Range restriction can't be " +
"applied to a given type");
parserException.setLine(ctx.getStart().getLine());
@@ -122,8 +124,17 @@
YangRangeRestriction rangeRestriction = null;
try {
- rangeRestriction = processRangeRestriction(null, ctx.getStart().getLine(),
- ctx.getStart().getCharPositionInLine(), false, ctx.range().getText(), type.getDataType());
+ if (type.getDataType() == DECIMAL64) {
+ YangDecimal64 yangDecimal64 = (YangDecimal64) type.getDataTypeExtendedInfo();
+ rangeRestriction = processRangeRestriction(yangDecimal64.getDefaultRangeRestriction(),
+ ctx.getStart().getLine(),
+ ctx.getStart().getCharPositionInLine(),
+ true, ctx.range().getText(), type.getDataType());
+ } else {
+ rangeRestriction = processRangeRestriction(null, ctx.getStart().getLine(),
+ ctx.getStart().getCharPositionInLine(),
+ false, ctx.range().getText(), type.getDataType());
+ }
} catch (DataModelException e) {
ParserException parserException = new ParserException(e.getMessage());
parserException.setCharPosition(e.getCharPositionInLine());
@@ -132,7 +143,12 @@
}
if (rangeRestriction != null) {
- type.setDataTypeExtendedInfo(rangeRestriction);
+ if (type.getDataType() == DECIMAL64) {
+ ((YangDecimal64<YangRangeRestriction>) type.getDataTypeExtendedInfo())
+ .setRangeRestrictedExtendedInfo(rangeRestriction);
+ } else {
+ type.setDataTypeExtendedInfo(rangeRestriction);
+ }
}
listener.getParsedDataStack().push(rangeRestriction);
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeListener.java
index e108d14..3c7fba9 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeListener.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeListener.java
@@ -94,6 +94,7 @@
// Obtain the YANG data type.
YangDataTypes yangDataTypes = YangDataTypes.getType(ctx.string().getText());
+ // validate type sub-statement cardinality
validateTypeSubStatementCardinality(ctx, yangDataTypes);
// Create YANG type object and fill the values.
@@ -306,6 +307,10 @@
parserException = new ParserException("YANG file error : a type bits" +
" must have atleast one bit statement.");
break;
+ case DECIMAL64:
+ parserException = new ParserException("YANG file error : a type decimal64" +
+ " must have fraction-digits statement.");
+ break;
case LEAFREF:
parserException = new ParserException("YANG file error : a type leafref" +
" must have one path statement.");
@@ -314,7 +319,6 @@
parserException = new ParserException("YANG file error : a type identityref" +
" must have base statement.");
break;
- // TODO : decimal64,
default:
return;
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/AttributesJavaDataType.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/AttributesJavaDataType.java
index 52595c7..91849b2 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/AttributesJavaDataType.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/AttributesJavaDataType.java
@@ -37,10 +37,13 @@
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.getCurNodePackage;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
import static org.onosproject.yangutils.utils.UtilConstants.BIG_INTEGER;
+import static org.onosproject.yangutils.utils.UtilConstants.BIG_DECIMAL;
+import static org.onosproject.yangutils.utils.UtilConstants.BIT_SET;
import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE;
import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_WRAPPER;
import static org.onosproject.yangutils.utils.UtilConstants.BYTE;
import static org.onosproject.yangutils.utils.UtilConstants.BYTE_WRAPPER;
+import static org.onosproject.yangutils.utils.UtilConstants.COLLECTION_IMPORTS;
import static org.onosproject.yangutils.utils.UtilConstants.INT;
import static org.onosproject.yangutils.utils.UtilConstants.INTEGER_WRAPPER;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG;
@@ -50,11 +53,8 @@
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.SHORT;
import static org.onosproject.yangutils.utils.UtilConstants.SHORT_WRAPPER;
+import static org.onosproject.yangutils.utils.UtilConstants.SQUARE_BRACKETS;
import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE;
-import static org.onosproject.yangutils.utils.UtilConstants.YANG_BINARY_CLASS;
-import static org.onosproject.yangutils.utils.UtilConstants.YANG_BITS_CLASS;
-import static org.onosproject.yangutils.utils.UtilConstants.YANG_DECIMAL64_CLASS;
-import static org.onosproject.yangutils.utils.UtilConstants.YANG_TYPES_PKG;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPackageDirPathFromJavaJPackage;
@@ -97,10 +97,12 @@
return LONG;
case UINT64:
return BIG_INTEGER;
+ case BITS:
+ return BIT_SET;
case BINARY:
- return YANG_BINARY_CLASS;
+ return BYTE + SQUARE_BRACKETS;
case DECIMAL64:
- return YANG_DECIMAL64_CLASS;
+ return BIG_DECIMAL;
case STRING:
return STRING_DATA_TYPE;
case BOOLEAN:
@@ -146,7 +148,7 @@
case UINT64:
return BIG_INTEGER;
case DECIMAL64:
- return YANG_DECIMAL64_CLASS;
+ return BIG_DECIMAL;
case STRING:
return STRING_DATA_TYPE;
case BOOLEAN:
@@ -156,9 +158,9 @@
getCamelCase(((YangJavaEnumeration) yangType.getDataTypeExtendedInfo()).getName(),
pluginConfig));
case BITS:
- return YANG_BITS_CLASS;
+ return BIT_SET;
case BINARY:
- return YANG_BINARY_CLASS;
+ return BYTE + SQUARE_BRACKETS;
case LEAFREF:
YangType<?> referredType = getReferredTypeFromLeafref(yangType);
return getJavaImportClass(referredType, isListAttr, pluginConfig);
@@ -184,8 +186,6 @@
switch (type) {
case UINT64:
return BIG_INTEGER;
- case DECIMAL64:
- return YANG_DECIMAL64_CLASS;
case STRING:
return STRING_DATA_TYPE;
case ENUMERATION:
@@ -193,9 +193,9 @@
getCamelCase(((YangJavaEnumeration) yangType.getDataTypeExtendedInfo()).getName(),
pluginConfig));
case BITS:
- return YANG_BITS_CLASS;
- case BINARY:
- return YANG_BINARY_CLASS;
+ return BIT_SET;
+ case DECIMAL64:
+ return BIG_DECIMAL;
case LEAFREF:
YangType<?> referredType = getReferredTypeFromLeafref(yangType);
return getJavaImportClass(referredType, isListAttr, pluginConfig);
@@ -241,18 +241,18 @@
case UINT8:
case UINT16:
case UINT32:
+ case BINARY:
case STRING:
case BOOLEAN:
case EMPTY:
return JAVA_LANG;
case UINT64:
+ case DECIMAL64:
return JAVA_MATH;
case ENUMERATION:
return getEnumsPackage(yangType, conflictResolver);
- case DECIMAL64:
case BITS:
- case BINARY:
- return YANG_TYPES_PKG;
+ return COLLECTION_IMPORTS;
case LEAFREF:
YangType<?> referredType = getReferredTypeFromLeafref(yangType);
return getJavaImportPackage(referredType, isListAttr, conflictResolver);
@@ -270,22 +270,20 @@
} else {
switch (type) {
case UINT64:
+ case DECIMAL64:
return JAVA_MATH;
+ case EMPTY:
case STRING:
return JAVA_LANG;
case ENUMERATION:
return getEnumsPackage(yangType, conflictResolver);
- case DECIMAL64:
case BITS:
- case BINARY:
- return YANG_TYPES_PKG;
+ return COLLECTION_IMPORTS;
case LEAFREF:
YangType<?> referredType = getReferredTypeFromLeafref(yangType);
return getJavaImportPackage(referredType, isListAttr, conflictResolver);
case IDENTITYREF:
return getIdentityRefPackage(yangType, conflictResolver);
- case EMPTY:
- return JAVA_LANG;
case UNION:
return getUnionPackage(yangType, conflictResolver);
case INSTANCE_IDENTIFIER:
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java
index 2f8c8d1..a5fc104 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java
@@ -35,6 +35,7 @@
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO;
import static org.onosproject.yangutils.utils.UtilConstants.BIG_INTEGER;
+import static org.onosproject.yangutils.utils.UtilConstants.BIG_DECIMAL;
import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE;
import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_WRAPPER;
import static org.onosproject.yangutils.utils.UtilConstants.BUILD;
@@ -54,6 +55,7 @@
import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT;
import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET;
+import static org.onosproject.yangutils.utils.UtilConstants.DOUBLE;
import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.EQUAL;
@@ -64,6 +66,7 @@
import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_METHOD_NAME;
import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_PARAM_NAME;
+import static org.onosproject.yangutils.utils.UtilConstants.GET_BYTES;
import static org.onosproject.yangutils.utils.UtilConstants.GET_METHOD_PREFIX;
import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_METHOD_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.HASH;
@@ -133,6 +136,7 @@
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
+import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BINARY;
/**
* Represents generator for methods of generated files based on the file type.
@@ -296,6 +300,7 @@
case INT:
case SHORT:
case LONG:
+ case DOUBLE:
return "0";
case BOOLEAN_DATA_TYPE:
return FALSE;
@@ -748,10 +753,15 @@
JavaAttributeInfo fromStringAttributeInfo) {
String targetDataType = getReturnType(attr);
- String parseFromStringMethod = getParseFromStringMethod(targetDataType,
- fromStringAttributeInfo.getAttributeType());
- return targetDataType + SPACE + TMP_VAL + SPACE + EQUAL + SPACE + parseFromStringMethod
- + OPEN_PARENTHESIS + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS;
+ if (fromStringAttributeInfo.getAttributeType().getDataType() == BINARY) {
+ return targetDataType + SPACE + TMP_VAL + SPACE + EQUAL + SPACE + FROM_STRING_PARAM_NAME
+ + PERIOD + GET_BYTES + OPEN_PARENTHESIS + CLOSE_PARENTHESIS;
+ } else {
+ String parseFromStringMethod = getParseFromStringMethod(targetDataType,
+ fromStringAttributeInfo.getAttributeType());
+ return targetDataType + SPACE + TMP_VAL + SPACE + EQUAL + SPACE + parseFromStringMethod
+ + OPEN_PARENTHESIS + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS;
+ }
}
/**
@@ -1092,14 +1102,14 @@
return LONG_WRAPPER + PERIOD + PARSE_LONG;
case UINT64:
return NEW + SPACE + BIG_INTEGER;
+ case DECIMAL64:
+ return NEW + SPACE + BIG_DECIMAL;
case STRING:
return EMPTY_STRING;
case EMPTY:
case BOOLEAN:
return BOOLEAN_WRAPPER + PERIOD + PARSE_BOOLEAN;
- case DECIMAL64:
case BITS:
- case BINARY:
case UNION:
case ENUMERATION:
case DERIVED:
diff --git a/plugin/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java b/plugin/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
index d56a2ed..fec23d3 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
@@ -197,6 +197,11 @@
public static final String PARSE_BYTE = "parseByte";
/**
+ * Static attribute for get bytes.
+ */
+ public static final String GET_BYTES = "getBytes";
+
+ /**
* Static attribute for parse boolean.
*/
public static final String PARSE_BOOLEAN = "parseBoolean";
@@ -567,6 +572,11 @@
public static final String CLOSE_CURLY_BRACKET = "}";
/**
+ * Static attribute for square brackets syntax.
+ */
+ public static final String SQUARE_BRACKETS = "[]";
+
+ /**
* Static attribute for getter method prefix.
*/
public static final String GET_METHOD_PREFIX = "get";
@@ -687,6 +697,16 @@
public static final String BIG_INTEGER = "BigInteger";
/**
+ * BigDecimal built in java type.
+ */
+ public static final String BIG_DECIMAL = "BigDecimal";
+
+ /**
+ * BitSet built in java type.
+ */
+ public static final String BIT_SET = "BitSet";
+
+ /**
* Byte java built in type.
*/
public static final String BYTE = "byte";
@@ -747,6 +767,11 @@
public static final String YANG_UINT64 = "YangUint64";
/**
+ * Double java built in wrapper type.
+ */
+ public static final String DOUBLE_WRAPPER = "Double";
+
+ /**
* List of keywords in java, this is used for checking if the input does not contain these keywords.
*/
public static final List<String> JAVA_KEY_WORDS = Arrays.asList(
@@ -1136,16 +1161,6 @@
public static final String EVENT_LISTENER = "EventListener";
/**
- * Static attribute for YangBinary class.
- */
- public static final String YANG_BINARY_CLASS = "YangBinary";
-
- /**
- * Static attribute for YangBinary class.
- */
- public static final String YANG_BITS_CLASS = "YangBits";
-
- /**
* Static attribute for YANG types package.
*/
public static final String YANG_TYPES_PKG = "org.onosproject.yangutils.datamodel.utils.builtindatatype";
@@ -1156,11 +1171,6 @@
public static final String MATH_CONTEXT = "MathContext";
/**
- * Static attribute for DECIMAL64 class.
- */
- public static final String YANG_DECIMAL64_CLASS = "YangDecimal64";
-
- /**
* Static attribute for YANG file error.
*/
public static final String YANG_FILE_ERROR = "YANG file error : ";
diff --git a/plugin/src/main/resources/GeneratedYang.g4 b/plugin/src/main/resources/GeneratedYang.g4
index 4fce152..eb23364 100644
--- a/plugin/src/main/resources/GeneratedYang.g4
+++ b/plugin/src/main/resources/GeneratedYang.g4
@@ -375,6 +375,13 @@
| bitsSpecification | unionSpecification;
/**
+ * decimal64-specification = ;; these stmts can appear in any order
+ * fraction-digits-stmt
+ * [range-stmt]
+ */
+ decimal64Specification : fractionDigitStatement rangeStatement?;
+
+ /**
* fraction-digits-stmt = fraction-digits-keyword sep
* fraction-digits-arg-str stmtend
*
@@ -385,7 +392,7 @@
* "5" / "6" / "7" / "8"])
* / "2" / "3" / "4" / "5" / "6" / "7" / "8" / "9"
*/
- decimal64Specification : FRACTION_DIGITS_KEYWORD fraction STMTEND;
+ fractionDigitStatement : FRACTION_DIGITS_KEYWORD fraction STMTEND;
/**
* numerical-restrictions = range-stmt stmtsep
diff --git a/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/BitListenerTest.java b/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/BitListenerTest.java
index 4b2b185..ef25c97 100644
--- a/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/BitListenerTest.java
+++ b/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/BitListenerTest.java
@@ -35,7 +35,7 @@
import java.io.IOException;
import java.util.List;
import java.util.ListIterator;
-import java.util.Set;
+import java.util.Map;
/**
* Test cases for bit listener.
@@ -71,14 +71,38 @@
assertThat(((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo()).getBitsName(),
is("mybits"));
- Set<YangBit> bitSet = ((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo()).getBitSet();
- for (YangBit tmp : bitSet) {
- if (tmp.getBitName().equals("disable-nagle")) {
- assertThat(tmp.getPosition(), is(0));
- } else if (tmp.getBitName().equals("auto-sense-speed")) {
- assertThat(tmp.getPosition(), is(1));
- } else if (tmp.getBitName().equals("Ten-Mb-only")) {
- assertThat(tmp.getPosition(), is(2));
+ // Check bit name map
+ Map<String, YangBit> bitNameMap = ((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo()).getBitNameMap();
+ assertThat(bitNameMap.size(), is(3));
+ for (Map.Entry<String, YangBit> element : bitNameMap.entrySet()) {
+ String bitName = element.getKey();
+ YangBit yangBit = element.getValue();
+ if (bitName.equals("disable-nagle")) {
+ assertThat(yangBit.getPosition(), is(0));
+ } else if (bitName.equals("auto-sense-speed")) {
+ assertThat(yangBit.getPosition(), is(1));
+ } else if (bitName.equals("Ten-Mb-only")) {
+ assertThat(yangBit.getPosition(), is(2));
+ } else {
+ throw new IOException("Invalid bit name: " + bitName);
+ }
+ }
+
+ // Check bit position map
+ Map<Integer, YangBit> bitPositionMap = ((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo())
+ .getBitPositionMap();
+ assertThat(bitPositionMap.size(), is(3));
+ for (Map.Entry<Integer, YangBit> element : bitPositionMap.entrySet()) {
+ int position = element.getKey();
+ YangBit yangBit = element.getValue();
+ if (position == 0) {
+ assertThat(yangBit.getBitName(), is("disable-nagle"));
+ } else if (position == 1) {
+ assertThat(yangBit.getBitName(), is("auto-sense-speed"));
+ } else if (position == 2) {
+ assertThat(yangBit.getBitName(), is("Ten-Mb-only"));
+ } else {
+ throw new IOException("Invalid bit position: " + position);
}
}
}
@@ -107,12 +131,38 @@
YangType type = typedef.getTypeList().iterator().next();
assertThat(type.getDataType(), is(YangDataTypes.BITS));
assertThat(type.getDataTypeName(), is("bits"));
- Set<YangBit> bitSet = ((YangBits) type.getDataTypeExtendedInfo()).getBitSet();
- for (YangBit tmp : bitSet) {
- if (tmp.getBitName().equals("disable-nagle")) {
- assertThat(tmp.getPosition(), is(0));
- } else if (tmp.getBitName().equals("auto-sense-speed")) {
- assertThat(tmp.getPosition(), is(1));
+
+ // Check bit name map
+ Map<String, YangBit> bitNameMap = ((YangBits) type.getDataTypeExtendedInfo()).getBitNameMap();
+ assertThat(bitNameMap.size(), is(3));
+ for (Map.Entry<String, YangBit> element : bitNameMap.entrySet()) {
+ String bitName = element.getKey();
+ YangBit yangBit = element.getValue();
+ if (bitName.equals("disable-nagle")) {
+ assertThat(yangBit.getPosition(), is(0));
+ } else if (bitName.equals("auto-sense-speed")) {
+ assertThat(yangBit.getPosition(), is(1));
+ } else if (bitName.equals("Mb-only")) {
+ assertThat(yangBit.getPosition(), is(2));
+ } else {
+ throw new IOException("Invalid bit name: " + bitName);
+ }
+ }
+
+ // Check bit position map
+ Map<Integer, YangBit> bitPositionMap = ((YangBits) type.getDataTypeExtendedInfo()).getBitPositionMap();
+ assertThat(bitPositionMap.size(), is(3));
+ for (Map.Entry<Integer, YangBit> element : bitPositionMap.entrySet()) {
+ int position = element.getKey();
+ YangBit yangBit = element.getValue();
+ if (position == 0) {
+ assertThat(yangBit.getBitName(), is("disable-nagle"));
+ } else if (position == 1) {
+ assertThat(yangBit.getBitName(), is("auto-sense-speed"));
+ } else if (position == 2) {
+ assertThat(yangBit.getBitName(), is("Mb-only"));
+ } else {
+ throw new IOException("Invalid bit position: " + position);
}
}
}
@@ -151,12 +201,38 @@
assertThat(yangType.getDataType(), is(YangDataTypes.BITS));
assertThat(yangType.getDataTypeName(), is("bits"));
- Set<YangBit> bitSet = ((YangBits) yangType.getDataTypeExtendedInfo()).getBitSet();
- for (YangBit tmp : bitSet) {
- if (tmp.getBitName().equals("disable-nagle")) {
- assertThat(tmp.getPosition(), is(0));
- } else if (tmp.getBitName().equals("auto-sense-speed")) {
- assertThat(tmp.getPosition(), is(1));
+
+ // Check bit name map
+ Map<String, YangBit> bitNameMap = ((YangBits) yangType.getDataTypeExtendedInfo()).getBitNameMap();
+ assertThat(bitNameMap.size(), is(3));
+ for (Map.Entry<String, YangBit> element : bitNameMap.entrySet()) {
+ String bitName = element.getKey();
+ YangBit yangBit = element.getValue();
+ if (bitName.equals("disable-nagle")) {
+ assertThat(yangBit.getPosition(), is(0));
+ } else if (bitName.equals("auto-sense-speed")) {
+ assertThat(yangBit.getPosition(), is(1));
+ } else if (bitName.equals("Mb-only")) {
+ assertThat(yangBit.getPosition(), is(2));
+ } else {
+ throw new IOException("Invalid bit name: " + bitName);
+ }
+ }
+
+ // Check bit position map
+ Map<Integer, YangBit> bitPositionMap = ((YangBits) yangType.getDataTypeExtendedInfo()).getBitPositionMap();
+ assertThat(bitPositionMap.size(), is(3));
+ for (Map.Entry<Integer, YangBit> element : bitPositionMap.entrySet()) {
+ int position = element.getKey();
+ YangBit yangBit = element.getValue();
+ if (position == 0) {
+ assertThat(yangBit.getBitName(), is("disable-nagle"));
+ } else if (position == 1) {
+ assertThat(yangBit.getBitName(), is("auto-sense-speed"));
+ } else if (position == 2) {
+ assertThat(yangBit.getBitName(), is("Mb-only"));
+ } else {
+ throw new IOException("Invalid bit position: " + position);
}
}
}
diff --git a/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/Decimal64ListenerTest.java b/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/Decimal64ListenerTest.java
new file mode 100644
index 0000000..ec5b3fc
--- /dev/null
+++ b/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/Decimal64ListenerTest.java
@@ -0,0 +1,371 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.parser.impl.listeners;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.onosproject.yangutils.datamodel.YangDecimal64;
+import org.onosproject.yangutils.datamodel.YangDerivedInfo;
+import org.onosproject.yangutils.datamodel.YangLeaf;
+import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangNodeType;
+import org.onosproject.yangutils.datamodel.YangRangeRestriction;
+import org.onosproject.yangutils.datamodel.YangRangeInterval;
+import org.onosproject.yangutils.datamodel.YangType;
+import org.onosproject.yangutils.datamodel.YangTypeDef;
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
+import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
+
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.util.ListIterator;
+
+/**
+ * Test cases for decimal64 listener.
+ */
+public class Decimal64ListenerTest {
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ private final YangUtilsParserManager manager = new YangUtilsParserManager();
+
+ /**
+ * Checks decimal64 statement with fraction-digits.
+ */
+ @Test
+ public void processDecimal64TypeStatement() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/Decimal64TypeStatement.yang");
+
+ // Check whether the data model tree returned is of type module.
+ assertThat((node instanceof YangModule), is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
+
+ // Check whether the module name is set correctly.
+ YangModule yangNode = (YangModule) node;
+ assertThat(yangNode.getName(), is("Test"));
+
+ ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+ YangLeaf leafInfo = leafIterator.next();
+
+ assertThat(leafInfo.getName(), is("validDecimal"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("decimal64"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.DECIMAL64));
+ assertThat(((YangDecimal64) leafInfo.getDataType().getDataTypeExtendedInfo()).getFractionDigit(),
+ is(2));
+ }
+
+ /**
+ * Checks decimal64 statement with range statement.
+ */
+ @Test
+ public void processDecimal64TypeWithRangeStatement() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/Decimal64TypeWithRangeStatement.yang");
+
+ // Check whether the data model tree returned is of type module.
+ assertThat((node instanceof YangModule), is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
+
+ // Check whether the module name is set correctly.
+ YangModule yangNode = (YangModule) node;
+ assertThat(yangNode.getName(), is("Test"));
+
+ ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+ YangLeaf leafInfo = leafIterator.next();
+
+ assertThat(leafInfo.getName(), is("validDecimal"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("decimal64"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.DECIMAL64));
+ assertThat(((YangDecimal64) leafInfo.getDataType().getDataTypeExtendedInfo()).getFractionDigit(),
+ is(8));
+
+ YangRangeRestriction rangeRestriction = ((YangDecimal64<YangRangeRestriction>) leafInfo.getDataType()
+ .getDataTypeExtendedInfo())
+ .getRangeRestrictedExtendedInfo();
+
+ ListIterator<YangRangeInterval> rangeListIterator = rangeRestriction.getAscendingRangeIntervals()
+ .listIterator();
+ YangRangeInterval rangeInterval = rangeListIterator.next();
+ assertThat(((YangDecimal64) rangeInterval.getStartValue()).getValue().doubleValue(), is(-92233720368.54775808));
+ assertThat(((YangDecimal64) rangeInterval.getEndValue()).getValue().doubleValue(), is(92233720368.54775807));
+ }
+
+ /**
+ * Successful validation of decimal64 statement.
+ */
+ @Test
+ public void processDecimal64ValueSuccessfulValidation() throws IOException, ParserException, DataModelException {
+
+ YangNode node = manager.getDataModel("src/test/resources/Decimal64TypeValidation.yang");
+
+ // Check whether the data model tree returned is of type module.
+ assertThat((node instanceof YangModule), is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
+
+ // Check whether the module name is set correctly.
+ YangModule yangNode = (YangModule) node;
+ assertThat(yangNode.getName(), is("Test"));
+
+ ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+ YangLeaf leafInfo = leafIterator.next();
+ YangDecimal64 decimal64 = (YangDecimal64) leafInfo.getDataType().getDataTypeExtendedInfo();
+
+ assertThat(leafInfo.getName(), is("validDecimal"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("decimal64"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.DECIMAL64));
+ assertThat(decimal64.getFractionDigit(), is(18));
+
+ decimal64.setValue(new BigDecimal(-9.223372036854775808));
+ decimal64.validateValue();
+ decimal64.setValue(new BigDecimal(9.223372036854775807));
+ decimal64.validateValue();
+ }
+
+ /**
+ * Failure validation of decimal64 statement.
+ */
+ @Test
+ public void processDecimal64ValueFailureValidation() throws IOException, ParserException, DataModelException {
+ thrown.expect(DataModelException.class);
+ thrown.expectMessage("YANG file error : decimal64 validation failed.");
+
+ YangNode node = manager.getDataModel("src/test/resources/Decimal64TypeValidation.yang");
+
+ // Check whether the data model tree returned is of type module.
+ assertThat((node instanceof YangModule), is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
+
+ // Check whether the module name is set correctly.
+ YangModule yangNode = (YangModule) node;
+ assertThat(yangNode.getName(), is("Test"));
+
+ ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+ YangLeaf leafInfo = leafIterator.next();
+ YangDecimal64 decimal64 = (YangDecimal64) leafInfo.getDataType().getDataTypeExtendedInfo();
+
+ assertThat(leafInfo.getName(), is("validDecimal"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("decimal64"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.DECIMAL64));
+ assertThat(decimal64.getFractionDigit(), is(18));
+
+ decimal64.setValue(new BigDecimal(-92233720368547758.08));
+ // validation should fail
+ decimal64.validateValue();
+ }
+
+ /**
+ * Validation of invalid maximum value limit of fraction-digits.
+ */
+ @Test
+ public void processDecimal64InvalidMaxFraction() throws IOException, ParserException, DataModelException {
+ thrown.expect(ParserException.class);
+ thrown.expectMessage("YANG file error : fraction-digits value should be between 1 and 18.");
+
+ manager.getDataModel("src/test/resources/Decimal64TypeInvalidMaxValueFraction.yang");
+ }
+
+ /**
+ * Validation of invalid (0) minimum value limit of fraction-digits.
+ */
+ @Test
+ public void processDecimal64InvalidMinFraction1() throws IOException, ParserException, DataModelException {
+ thrown.expect(ParserException.class);
+ thrown.expectMessage("YANG file error : fraction-digits value should be between 1 and 18.");
+
+ manager.getDataModel("src/test/resources/Decimal64TypeInvalidMinValueFraction1.yang");
+ }
+
+ /**
+ * Validation of invalid (-1) minimum value limit of fraction-digits.
+ */
+ @Test
+ public void processDecimal64InvalidMinFraction2() throws IOException, ParserException, DataModelException {
+ thrown.expect(ParserException.class);
+ thrown.expectMessage("YANG file error : fraction-digits value should be between 1 and 18.");
+
+ manager.getDataModel("src/test/resources/Decimal64TypeInvalidMinValueFraction2.yang");
+ }
+
+ /**
+ * Validation of decimal64 range statement.
+ */
+ @Test
+ public void processDecimal64TypeWithMultiValueRangeStatement() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/Decimal64TypeWithMultiValueRangeStmnt.yang");
+
+ // Check whether the data model tree returned is of type module.
+ assertThat((node instanceof YangModule), is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
+
+ // Check whether the module name is set correctly.
+ YangModule yangNode = (YangModule) node;
+ assertThat(yangNode.getName(), is("Test"));
+
+ ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+ YangLeaf leafInfo = leafIterator.next();
+
+ assertThat(leafInfo.getName(), is("validDecimal"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("decimal64"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.DECIMAL64));
+ assertThat(((YangDecimal64) leafInfo.getDataType().getDataTypeExtendedInfo()).getFractionDigit(),
+ is(18));
+
+ YangRangeRestriction rangeRestriction = ((YangDecimal64<YangRangeRestriction>) leafInfo.getDataType()
+ .getDataTypeExtendedInfo())
+ .getRangeRestrictedExtendedInfo();
+
+ ListIterator<YangRangeInterval> rangeListIterator = rangeRestriction.getAscendingRangeIntervals()
+ .listIterator();
+ // range "1 .. 3.14 | 10 | 20..max";
+ // check first range 1 .. 3.14
+ YangRangeInterval rangeInterval = rangeListIterator.next();
+ assertThat(((YangDecimal64) rangeInterval.getStartValue()).getValue().doubleValue(), is(-9.22));
+ assertThat(((YangDecimal64) rangeInterval.getEndValue()).getValue().doubleValue(), is(7.22));
+ // check second range 10
+ rangeInterval = rangeListIterator.next();
+ assertThat(((YangDecimal64) rangeInterval.getStartValue()).getValue().doubleValue(), is(8.0));
+ assertThat(((YangDecimal64) rangeInterval.getEndValue()).getValue().doubleValue(), is(8.0));
+ // check third range 20..max
+ rangeInterval = rangeListIterator.next();
+ assertThat(((YangDecimal64) rangeInterval.getStartValue()).getValue().doubleValue(), is(9.0));
+ assertThat(((YangDecimal64) rangeInterval.getEndValue()).getValue().doubleValue(), is(9.223372036854776));
+ }
+
+ /**
+ * Validation of decimal64 with invalid range.
+ */
+ @Test
+ public void processDecimal64InvalidRange() throws IOException, ParserException, DataModelException {
+ thrown.expect(ParserException.class);
+ thrown.expectMessage("YANG file error : decimal64 validation failed.");
+
+ manager.getDataModel("src/test/resources/Decimal64TypeInvalidRangeStmnt.yang");
+ }
+
+ /**
+ * Validation of decimal64 without fraction-digits. Fraction-digits must be present for decimal64.
+ */
+ @Test
+ public void processDecimal64WithoutFraction() throws IOException, ParserException, DataModelException {
+ thrown.expect(ParserException.class);
+ thrown.expectMessage("YANG file error : a type decimal64 must have fraction-digits statement.");
+
+ manager.getDataModel("src/test/resources/Decimal64TypeWithoutFraction.yang");
+ }
+
+ /**
+ * Checks decimal64 with typedef statement.
+ */
+ @Test
+ public void processDecimal64TypedefStatement() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/Decimal64TypedefStatement.yang");
+
+ // Check whether the data model tree returned is of type module.
+ assertThat((node instanceof YangModule), is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
+
+ // Check whether the module name is set correctly.
+ YangModule yangNode = (YangModule) node;
+ assertThat(yangNode.getName(), is("Test"));
+
+ ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+ YangLeaf leafInfo = leafIterator.next();
+
+ assertThat(leafInfo.getName(), is("setFourDecimal"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("validDecimal"));
+ YangType<YangDerivedInfo> derivedInfoType = (YangType<YangDerivedInfo>) leafInfo.getDataType();
+ YangDerivedInfo derivedInfo = (YangDerivedInfo) derivedInfoType.getDataTypeExtendedInfo();
+ YangTypeDef typedef = (YangTypeDef) derivedInfo.getReferredTypeDef();
+ assertThat(typedef.getName(), is("validDecimal"));
+
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.DERIVED));
+ YangType type = typedef.getTypeList().iterator().next();
+ assertThat(type.getDataType(), is(YangDataTypes.DECIMAL64));
+ assertThat(type.getDataTypeName(), is("decimal64"));
+ YangType<YangDecimal64> decimal64Type = (YangType<YangDecimal64>) typedef.getTypeList().iterator().next();
+ YangDecimal64 decimal64 = decimal64Type.getDataTypeExtendedInfo();
+ assertThat(decimal64.getFractionDigit(), is(4));
+ }
+
+ /**
+ * Checks decimal64 with multiple typedef statement.
+ */
+ @Test
+ public void processDecimal64MultiTypedefStatement() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/Decimal64MultiTypedefStatement.yang");
+
+ // Check whether the data model tree returned is of type module.
+ assertThat((node instanceof YangModule), is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
+
+ // Check whether the module name is set correctly.
+ YangModule yangNode = (YangModule) node;
+ assertThat(yangNode.getName(), is("Test"));
+
+ ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+ YangLeaf leafInfo = leafIterator.next();
+
+ // check leaf type
+ assertThat(leafInfo.getName(), is("setFourDecimal"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("validDecimal"));
+ YangType<YangDerivedInfo> derivedInfoType = (YangType<YangDerivedInfo>) leafInfo.getDataType();
+ assertThat(derivedInfoType.getDataType(), is(YangDataTypes.DERIVED));
+ YangDerivedInfo derivedInfo = (YangDerivedInfo) derivedInfoType.getDataTypeExtendedInfo();
+
+ // check previous typedef
+ YangTypeDef prevTypedef = (YangTypeDef) derivedInfo.getReferredTypeDef();
+ assertThat(prevTypedef.getName(), is("validDecimal"));
+ YangType type = prevTypedef.getTypeList().iterator().next();
+ assertThat(type.getDataType(), is(YangDataTypes.DERIVED));
+ derivedInfo = (YangDerivedInfo) type.getDataTypeExtendedInfo();
+
+ // check top typedef
+ YangTypeDef topTypedef = (YangTypeDef) derivedInfo.getReferredTypeDef();
+ assertThat(topTypedef.getName(), is("topDecimal"));
+ type = topTypedef.getTypeList().iterator().next();
+ assertThat(type.getDataType(), is(YangDataTypes.DECIMAL64));
+ assertThat(type.getDataTypeName(), is("decimal64"));
+ YangType<YangDecimal64> decimal64Type = (YangType<YangDecimal64>) type;
+ YangDecimal64 decimal64 = decimal64Type.getDataTypeExtendedInfo();
+ assertThat(decimal64.getFractionDigit(), is(4));
+ }
+}
diff --git a/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/LengthRestrictionListenerTest.java b/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/LengthRestrictionListenerTest.java
index 1f65023..a67aa53 100644
--- a/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/LengthRestrictionListenerTest.java
+++ b/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/LengthRestrictionListenerTest.java
@@ -138,6 +138,37 @@
}
/**
+ * Checks valid length statement as sub-statement of binary statement.
+ */
+ @Test
+ public void processValidBinaryLengthStatement() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/ValidBinaryLengthStatement.yang");
+
+ assertThat((node instanceof YangModule), is(true));
+ assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
+ YangModule yangNode = (YangModule) node;
+ assertThat(yangNode.getName(), is("Test"));
+
+ ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+ YangLeaf leafInfo = leafIterator.next();
+
+ assertThat(leafInfo.getName(), is("message"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("binary"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.BINARY));
+ YangRangeRestriction lengthRestriction = (YangRangeRestriction) leafInfo
+ .getDataType().getDataTypeExtendedInfo();
+
+ ListIterator<YangRangeInterval> lengthListIterator = lengthRestriction.getAscendingRangeIntervals()
+ .listIterator();
+
+ YangRangeInterval rangeInterval = lengthListIterator.next();
+
+ assertThat(((YangUint64) rangeInterval.getStartValue()).getValue(), is(BigInteger.valueOf(4)));
+ assertThat(((YangUint64) rangeInterval.getEndValue()).getValue(), is(BigInteger.valueOf(4)));
+ }
+
+ /**
* Checks length statement with invalid type.
*/
@Test
diff --git a/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/PositionListenerTest.java b/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/PositionListenerTest.java
index 699f530..7b59894 100644
--- a/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/PositionListenerTest.java
+++ b/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/PositionListenerTest.java
@@ -31,7 +31,7 @@
import java.io.IOException;
import java.util.ListIterator;
-import java.util.Set;
+import java.util.Map;
/**
* Test cases for position listener.
@@ -67,14 +67,38 @@
assertThat(((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo()).getBitsName(),
is("mybits"));
- Set<YangBit> bitSet = ((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo()).getBitSet();
- for (YangBit tmp : bitSet) {
- if (tmp.getBitName().equals("disable-nagle")) {
- assertThat(tmp.getPosition(), is(0));
- } else if (tmp.getBitName().equals("auto-sense-speed")) {
- assertThat(tmp.getPosition(), is(1));
- } else if (tmp.getBitName().equals("Ten-Mb-only")) {
- assertThat(tmp.getPosition(), is(2));
+ // Check bit name map
+ Map<String, YangBit> bitNameMap = ((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo()).getBitNameMap();
+ assertThat(bitNameMap.size(), is(3));
+ for (Map.Entry<String, YangBit> element : bitNameMap.entrySet()) {
+ String bitName = element.getKey();
+ YangBit yangBit = element.getValue();
+ if (bitName.equals("disable-nagle")) {
+ assertThat(yangBit.getPosition(), is(0));
+ } else if (bitName.equals("auto-sense-speed")) {
+ assertThat(yangBit.getPosition(), is(1));
+ } else if (bitName.equals("Ten-Mb-only")) {
+ assertThat(yangBit.getPosition(), is(2));
+ } else {
+ throw new IOException("Invalid bit name: " + bitName);
+ }
+ }
+
+ // Check bit position map
+ Map<Integer, YangBit> bitPositionMap = ((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo())
+ .getBitPositionMap();
+ assertThat(bitPositionMap.size(), is(3));
+ for (Map.Entry<Integer, YangBit> element : bitPositionMap.entrySet()) {
+ int position = element.getKey();
+ YangBit yangBit = element.getValue();
+ if (position == 0) {
+ assertThat(yangBit.getBitName(), is("disable-nagle"));
+ } else if (position == 1) {
+ assertThat(yangBit.getBitName(), is("auto-sense-speed"));
+ } else if (position == 2) {
+ assertThat(yangBit.getBitName(), is("Ten-Mb-only"));
+ } else {
+ throw new IOException("Invalid bit position: " + position);
}
}
}
@@ -106,14 +130,38 @@
assertThat(((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo()).getBitsName(),
is("mybits"));
- Set<YangBit> bitSet = ((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo()).getBitSet();
- for (YangBit tmp : bitSet) {
- if (tmp.getBitName().equals("disable-nagle")) {
- assertThat(tmp.getPosition(), is(0));
- } else if (tmp.getBitName().equals("auto-sense-speed")) {
- assertThat(tmp.getPosition(), is(1));
- } else if (tmp.getBitName().equals("Ten-Mb-only")) {
- assertThat(tmp.getPosition(), is(2));
+ // Check bit name map
+ Map<String, YangBit> bitNameMap = ((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo()).getBitNameMap();
+ assertThat(bitNameMap.size(), is(3));
+ for (Map.Entry<String, YangBit> element : bitNameMap.entrySet()) {
+ String bitName = element.getKey();
+ YangBit yangBit = element.getValue();
+ if (bitName.equals("disable-nagle")) {
+ assertThat(yangBit.getPosition(), is(0));
+ } else if (bitName.equals("auto-sense-speed")) {
+ assertThat(yangBit.getPosition(), is(1));
+ } else if (bitName.equals("Ten-Mb-only")) {
+ assertThat(yangBit.getPosition(), is(2));
+ } else {
+ throw new IOException("Invalid bit name: " + bitName);
+ }
+ }
+
+ // Check bit position map
+ Map<Integer, YangBit> bitPositionMap = ((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo())
+ .getBitPositionMap();
+ assertThat(bitPositionMap.size(), is(3));
+ for (Map.Entry<Integer, YangBit> element : bitPositionMap.entrySet()) {
+ int position = element.getKey();
+ YangBit yangBit = element.getValue();
+ if (position == 0) {
+ assertThat(yangBit.getBitName(), is("disable-nagle"));
+ } else if (position == 1) {
+ assertThat(yangBit.getBitName(), is("auto-sense-speed"));
+ } else if (position == 2) {
+ assertThat(yangBit.getBitName(), is("Ten-Mb-only"));
+ } else {
+ throw new IOException("Invalid bit position: " + position);
}
}
}
@@ -145,14 +193,38 @@
assertThat(((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo()).getBitsName(),
is("mybits"));
- Set<YangBit> bitSet = ((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo()).getBitSet();
- for (YangBit tmp : bitSet) {
- if (tmp.getBitName().equals("disable-nagle")) {
- assertThat(tmp.getPosition(), is(0));
- } else if (tmp.getBitName().equals("auto-sense-speed")) {
- assertThat(tmp.getPosition(), is(1));
- } else if (tmp.getBitName().equals("Ten-Mb-only")) {
- assertThat(tmp.getPosition(), is(2));
+ // Check bit name map
+ Map<String, YangBit> bitNameMap = ((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo()).getBitNameMap();
+ assertThat(bitNameMap.size(), is(3));
+ for (Map.Entry<String, YangBit> element : bitNameMap.entrySet()) {
+ String bitName = element.getKey();
+ YangBit yangBit = element.getValue();
+ if (bitName.equals("disable-nagle")) {
+ assertThat(yangBit.getPosition(), is(0));
+ } else if (bitName.equals("auto-sense-speed")) {
+ assertThat(yangBit.getPosition(), is(1));
+ } else if (bitName.equals("Ten-Mb-only")) {
+ assertThat(yangBit.getPosition(), is(2));
+ } else {
+ throw new IOException("Invalid bit name: " + bitName);
+ }
+ }
+
+ // Check bit position map
+ Map<Integer, YangBit> bitPositionMap = ((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo())
+ .getBitPositionMap();
+ assertThat(bitPositionMap.size(), is(3));
+ for (Map.Entry<Integer, YangBit> element : bitPositionMap.entrySet()) {
+ int position = element.getKey();
+ YangBit yangBit = element.getValue();
+ if (position == 0) {
+ assertThat(yangBit.getBitName(), is("disable-nagle"));
+ } else if (position == 1) {
+ assertThat(yangBit.getBitName(), is("auto-sense-speed"));
+ } else if (position == 2) {
+ assertThat(yangBit.getBitName(), is("Ten-Mb-only"));
+ } else {
+ throw new IOException("Invalid bit position: " + position);
}
}
}
diff --git a/plugin/src/test/resources/ContainerSubStatementWhen.yang b/plugin/src/test/resources/ContainerSubStatementWhen.yang
index 644b2ff..7a2674f 100644
--- a/plugin/src/test/resources/ContainerSubStatementWhen.yang
+++ b/plugin/src/test/resources/ContainerSubStatementWhen.yang
@@ -26,7 +26,9 @@
"Interface has time-division multiplex capabilities.";
leaf minimum-lsp-bandwidth {
- type decimal64;
+ type decimal64 {
+ fraction-digits 4;
+ }
}
}
}
diff --git a/plugin/src/test/resources/Decimal64MultiTypedefStatement.yang b/plugin/src/test/resources/Decimal64MultiTypedefStatement.yang
new file mode 100644
index 0000000..fdce08e
--- /dev/null
+++ b/plugin/src/test/resources/Decimal64MultiTypedefStatement.yang
@@ -0,0 +1,19 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+
+ typedef topDecimal {
+ type decimal64 {
+ fraction-digits 4;
+ }
+ }
+
+ typedef validDecimal {
+ type topDecimal;
+ }
+
+ leaf setFourDecimal {
+ type validDecimal;
+ }
+}
diff --git a/plugin/src/test/resources/Decimal64TypeInvalidMaxValueFraction.yang b/plugin/src/test/resources/Decimal64TypeInvalidMaxValueFraction.yang
new file mode 100644
index 0000000..68bd8df
--- /dev/null
+++ b/plugin/src/test/resources/Decimal64TypeInvalidMaxValueFraction.yang
@@ -0,0 +1,11 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+
+ leaf invalidDecimal1 {
+ type decimal64 {
+ fraction-digits 19;
+ }
+ }
+}
diff --git a/plugin/src/test/resources/Decimal64TypeInvalidMinValueFraction1.yang b/plugin/src/test/resources/Decimal64TypeInvalidMinValueFraction1.yang
new file mode 100644
index 0000000..3d7445a
--- /dev/null
+++ b/plugin/src/test/resources/Decimal64TypeInvalidMinValueFraction1.yang
@@ -0,0 +1,11 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+
+ leaf invalidDecimal2 {
+ type decimal64 {
+ fraction-digits 0;
+ }
+ }
+}
diff --git a/plugin/src/test/resources/Decimal64TypeInvalidMinValueFraction2.yang b/plugin/src/test/resources/Decimal64TypeInvalidMinValueFraction2.yang
new file mode 100644
index 0000000..4e17bbe
--- /dev/null
+++ b/plugin/src/test/resources/Decimal64TypeInvalidMinValueFraction2.yang
@@ -0,0 +1,11 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+
+ leaf invalidDecimal3 {
+ type decimal64 {
+ fraction-digits -1;
+ }
+ }
+}
diff --git a/plugin/src/test/resources/Decimal64TypeInvalidRangeStmnt.yang b/plugin/src/test/resources/Decimal64TypeInvalidRangeStmnt.yang
new file mode 100644
index 0000000..2ac3d94
--- /dev/null
+++ b/plugin/src/test/resources/Decimal64TypeInvalidRangeStmnt.yang
@@ -0,0 +1,11 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ leaf validDecimal {
+ type decimal64 {
+ fraction-digits 18;
+ range "1 .. 20.14";
+ }
+ }
+}
diff --git a/plugin/src/test/resources/Decimal64TypeStatement.yang b/plugin/src/test/resources/Decimal64TypeStatement.yang
new file mode 100644
index 0000000..9824c12
--- /dev/null
+++ b/plugin/src/test/resources/Decimal64TypeStatement.yang
@@ -0,0 +1,10 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ leaf validDecimal {
+ type decimal64 {
+ fraction-digits 2;
+ }
+ }
+}
diff --git a/plugin/src/test/resources/Decimal64TypeValidation.yang b/plugin/src/test/resources/Decimal64TypeValidation.yang
new file mode 100644
index 0000000..06bf5b7
--- /dev/null
+++ b/plugin/src/test/resources/Decimal64TypeValidation.yang
@@ -0,0 +1,10 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ leaf validDecimal {
+ type decimal64 {
+ fraction-digits 18;
+ }
+ }
+}
diff --git a/plugin/src/test/resources/Decimal64TypeWithMultiValueRangeStmnt.yang b/plugin/src/test/resources/Decimal64TypeWithMultiValueRangeStmnt.yang
new file mode 100644
index 0000000..f657134
--- /dev/null
+++ b/plugin/src/test/resources/Decimal64TypeWithMultiValueRangeStmnt.yang
@@ -0,0 +1,11 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ leaf validDecimal {
+ type decimal64 {
+ fraction-digits 18;
+ range "-9.22..7.22 | 8 | 9..max";
+ }
+ }
+}
diff --git a/plugin/src/test/resources/Decimal64TypeWithRangeStatement.yang b/plugin/src/test/resources/Decimal64TypeWithRangeStatement.yang
new file mode 100644
index 0000000..f184927
--- /dev/null
+++ b/plugin/src/test/resources/Decimal64TypeWithRangeStatement.yang
@@ -0,0 +1,11 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ leaf validDecimal {
+ type decimal64 {
+ fraction-digits 8;
+ range "-92233720368.54775808 .. 92233720368.54775807";
+ }
+ }
+}
diff --git a/plugin/src/test/resources/Decimal64TypeWithoutFraction.yang b/plugin/src/test/resources/Decimal64TypeWithoutFraction.yang
new file mode 100644
index 0000000..e7b8beb
--- /dev/null
+++ b/plugin/src/test/resources/Decimal64TypeWithoutFraction.yang
@@ -0,0 +1,8 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ leaf validDecimal {
+ type decimal64;
+ }
+}
diff --git a/plugin/src/test/resources/Decimal64TypedefStatement.yang b/plugin/src/test/resources/Decimal64TypedefStatement.yang
new file mode 100644
index 0000000..66addd2
--- /dev/null
+++ b/plugin/src/test/resources/Decimal64TypedefStatement.yang
@@ -0,0 +1,15 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+
+ typedef validDecimal {
+ type decimal64 {
+ fraction-digits 4;
+ }
+ }
+
+ leaf setFourDecimal {
+ type validDecimal;
+ }
+}
diff --git a/plugin/src/test/resources/ValidBinaryLengthStatement.yang b/plugin/src/test/resources/ValidBinaryLengthStatement.yang
new file mode 100644
index 0000000..7182eb3
--- /dev/null
+++ b/plugin/src/test/resources/ValidBinaryLengthStatement.yang
@@ -0,0 +1,10 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ leaf message {
+ type binary {
+ length "4";
+ }
+ }
+}
diff --git a/plugin/src/test/resources/ValidLengthStatementInsideBinary.yang b/plugin/src/test/resources/ValidLengthStatementInsideBinary.yang
new file mode 100644
index 0000000..7182eb3
--- /dev/null
+++ b/plugin/src/test/resources/ValidLengthStatementInsideBinary.yang
@@ -0,0 +1,10 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ leaf message {
+ type binary {
+ length "4";
+ }
+ }
+}
diff --git a/plugin/src/test/resources/interfileietf/ietf-te-topology.yang b/plugin/src/test/resources/interfileietf/ietf-te-topology.yang
index b5fd1d9..5b65dff 100644
--- a/plugin/src/test/resources/interfileietf/ietf-te-topology.yang
+++ b/plugin/src/test/resources/interfileietf/ietf-te-topology.yang
@@ -430,8 +430,8 @@
}
leaf unidirectional-packet-loss {
type decimal64 {
- /*fraction-digits 6;
- range "0 .. 50.331642";*/
+ fraction-digits 6;
+ range "0 .. 50.331642";
}
description
"Packet loss as a percentage of the total traffic sent
@@ -440,7 +440,7 @@
}
leaf unidirectional-residual-bandwidth {
type decimal64 {
- /*fraction-digits 2;*/
+ fraction-digits 2;
}
description
"Residual bandwidth that subtracts tunnel
@@ -450,7 +450,7 @@
}
leaf unidirectional-available-bandwidth {
type decimal64 {
- /*fraction-digits 2;*/
+ fraction-digits 2;
}
description
"Available bandwidth that is defined to be residual
@@ -461,7 +461,7 @@
}
leaf unidirectional-utilized-bandwidth {
type decimal64 {
- /*fraction-digits 2;*/
+ fraction-digits 2;
}
description
"Bandwidth utilization that represents the actual
@@ -753,7 +753,7 @@
}
leaf max-link-bandwidth {
type decimal64 {
- /*fraction-digits 2;*/
+ fraction-digits 2;
}
description
"Maximum bandwidth that can be seen on this link in this
@@ -765,7 +765,7 @@
}
leaf max-resv-link-bandwidth {
type decimal64 {
- /*fraction-digits 2;*/
+ fraction-digits 2;
}
description
"Maximum amount of bandwidth that can be reserved in this
@@ -793,7 +793,7 @@
}
leaf bandwidth {
type decimal64 {
- /*fraction-digits 2;*/
+ fraction-digits 2;
}
description
"Unreserved bandwidth for this level.";
@@ -884,7 +884,7 @@
}
leaf bandwidth {
type decimal64 {
- /*fraction-digits 2;*/
+ fraction-digits 2;
}
description
"Max LSP Bandwidth for this level";
@@ -899,7 +899,7 @@
leaf minimum-lsp-bandwidth {
type decimal64 {
- /*fraction-digits 2;*/
+ fraction-digits 2;
}
description
"Minimum LSP Bandwidth. Units in bytes per second.";
@@ -951,7 +951,7 @@
}
leaf bandwidth {
type decimal64 {
- /*fraction-digits 2;*/
+ fraction-digits 2;
}
description
"Max LSP Bandwidth for this level.";
diff --git a/plugin/src/test/resources/interfileietf/ietf-te-types.yang b/plugin/src/test/resources/interfileietf/ietf-te-types.yang
index ffa1984..4b9d3be 100644
--- a/plugin/src/test/resources/interfileietf/ietf-te-types.yang
+++ b/plugin/src/test/resources/interfileietf/ietf-te-types.yang
@@ -580,7 +580,7 @@
typedef admin-group {
type binary {
-// length 32;
+ length 32;
}
description
"Administrative group/Resource class/Color.";