janani b
Committed by Patrick Liu

[ONOS-4744] Leafref implementation and UT

Change-Id: I151797185e0bb1695c0640b667ae76ef87c4d4b0
Showing 73 changed files with 2037 additions and 112 deletions
...@@ -34,5 +34,10 @@ public enum ResolvableType { ...@@ -34,5 +34,10 @@ public enum ResolvableType {
34 /** 34 /**
35 * Identifies the if-feature. 35 * Identifies the if-feature.
36 */ 36 */
37 - YANG_IF_FEATURE 37 + YANG_IF_FEATURE,
38 +
39 + /**
40 + * Identifies the leafref.
41 + */
42 + YANG_LEAFREF
38 } 43 }
......
...@@ -24,6 +24,11 @@ import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes; ...@@ -24,6 +24,11 @@ import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
24 24
25 import com.google.common.base.Strings; 25 import com.google.common.base.Strings;
26 26
27 +import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.INTRA_FILE_RESOLVED;
28 +import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.RESOLVED;
29 +import static org.onosproject.yangutils.datamodel.utils.RestrictionResolver.processLengthRestriction;
30 +import static org.onosproject.yangutils.datamodel.utils.RestrictionResolver.processRangeRestriction;
31 +import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypeUtils.isOfRangeRestrictedType;
27 import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BINARY; 32 import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BINARY;
28 import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BITS; 33 import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BITS;
29 import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BOOLEAN; 34 import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BOOLEAN;
...@@ -34,11 +39,6 @@ import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangData ...@@ -34,11 +39,6 @@ import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangData
34 import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.LEAFREF; 39 import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.LEAFREF;
35 import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.STRING; 40 import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.STRING;
36 import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UNION; 41 import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UNION;
37 -import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.INTRA_FILE_RESOLVED;
38 -import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.RESOLVED;
39 -import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypeUtils.isOfRangeRestrictedType;
40 -import static org.onosproject.yangutils.datamodel.utils.RestrictionResolver.processLengthRestriction;
41 -import static org.onosproject.yangutils.datamodel.utils.RestrictionResolver.processRangeRestriction;
42 42
43 /** 43 /**
44 * Represents the derived information. 44 * Represents the derived information.
...@@ -334,6 +334,9 @@ public class YangDerivedInfo<T> ...@@ -334,6 +334,9 @@ public class YangDerivedInfo<T>
334 return RESOLVED; 334 return RESOLVED;
335 } 335 }
336 } 336 }
337 + } else if (baseType.getDataType() == LEAFREF) {
338 + setEffectiveBuiltInType(baseType.getDataType());
339 + return RESOLVED;
337 } else { 340 } else {
338 setEffectiveBuiltInType(baseType.getDataType()); 341 setEffectiveBuiltInType(baseType.getDataType());
339 /* 342 /*
...@@ -412,7 +415,6 @@ public class YangDerivedInfo<T> ...@@ -412,7 +415,6 @@ public class YangDerivedInfo<T>
412 } 415 }
413 } 416 }
414 } 417 }
415 -
416 /* 418 /*
417 * Check if the data type is the one which can't be restricted, in this 419 * Check if the data type is the one which can't be restricted, in this
418 * case check whether no self restrictions should be present. 420 * case check whether no self restrictions should be present.
...@@ -426,7 +428,6 @@ public class YangDerivedInfo<T> ...@@ -426,7 +428,6 @@ public class YangDerivedInfo<T>
426 throw new DataModelException("YANG file error: Restrictions can't be applied to a given type"); 428 throw new DataModelException("YANG file error: Restrictions can't be applied to a given type");
427 } 429 }
428 } 430 }
429 -
430 // Throw exception for unsupported types 431 // Throw exception for unsupported types
431 throw new DataModelException("Linker error: Unable to process the derived type."); 432 throw new DataModelException("Linker error: Unable to process the derived type.");
432 } 433 }
......
...@@ -211,6 +211,11 @@ public class YangModule ...@@ -211,6 +211,11 @@ public class YangModule
211 private List<YangResolutionInfo> ifFeatureResolutionList; 211 private List<YangResolutionInfo> ifFeatureResolutionList;
212 212
213 /** 213 /**
214 + * leafref resolution list.
215 + */
216 + private List<YangResolutionInfo> leafrefResolutionList;
217 +
218 + /**
214 * Creates a YANG node of module type. 219 * Creates a YANG node of module type.
215 */ 220 */
216 public YangModule() { 221 public YangModule() {
...@@ -219,6 +224,7 @@ public class YangModule ...@@ -219,6 +224,7 @@ public class YangModule
219 derivedTypeResolutionList = new LinkedList<>(); 224 derivedTypeResolutionList = new LinkedList<>();
220 usesResolutionList = new LinkedList<>(); 225 usesResolutionList = new LinkedList<>();
221 ifFeatureResolutionList = new LinkedList<>(); 226 ifFeatureResolutionList = new LinkedList<>();
227 + leafrefResolutionList = new LinkedList<>();
222 importList = new LinkedList<YangImport>(); 228 importList = new LinkedList<YangImport>();
223 includeList = new LinkedList<YangInclude>(); 229 includeList = new LinkedList<YangInclude>();
224 listOfLeaf = new LinkedList<YangLeaf>(); 230 listOfLeaf = new LinkedList<YangLeaf>();
...@@ -589,8 +595,10 @@ public class YangModule ...@@ -589,8 +595,10 @@ public class YangModule
589 return derivedTypeResolutionList; 595 return derivedTypeResolutionList;
590 } else if (type == ResolvableType.YANG_USES) { 596 } else if (type == ResolvableType.YANG_USES) {
591 return usesResolutionList; 597 return usesResolutionList;
592 - } else { 598 + } else if (type == ResolvableType.YANG_IF_FEATURE) {
593 return ifFeatureResolutionList; 599 return ifFeatureResolutionList;
600 + } else {
601 + return leafrefResolutionList;
594 } 602 }
595 } 603 }
596 604
...@@ -603,6 +611,8 @@ public class YangModule ...@@ -603,6 +611,8 @@ public class YangModule
603 usesResolutionList.add(resolutionInfo); 611 usesResolutionList.add(resolutionInfo);
604 } else if (type == ResolvableType.YANG_IF_FEATURE) { 612 } else if (type == ResolvableType.YANG_IF_FEATURE) {
605 ifFeatureResolutionList.add(resolutionInfo); 613 ifFeatureResolutionList.add(resolutionInfo);
614 + } else {
615 + leafrefResolutionList.add(resolutionInfo);
606 } 616 }
607 } 617 }
608 618
...@@ -615,6 +625,8 @@ public class YangModule ...@@ -615,6 +625,8 @@ public class YangModule
615 usesResolutionList = resolutionList; 625 usesResolutionList = resolutionList;
616 } else if (type == ResolvableType.YANG_IF_FEATURE) { 626 } else if (type == ResolvableType.YANG_IF_FEATURE) {
617 ifFeatureResolutionList.add((YangResolutionInfo) resolutionList); 627 ifFeatureResolutionList.add((YangResolutionInfo) resolutionList);
628 + } else if (type == ResolvableType.YANG_LEAFREF) {
629 + leafrefResolutionList = resolutionList;
618 } 630 }
619 631
620 } 632 }
......
...@@ -209,6 +209,11 @@ public class YangSubModule ...@@ -209,6 +209,11 @@ public class YangSubModule
209 private List<YangResolutionInfo> ifFeatureResolutionList; 209 private List<YangResolutionInfo> ifFeatureResolutionList;
210 210
211 /** 211 /**
212 + * leafref resolution list.
213 + */
214 + private List<YangResolutionInfo> leafrefResolutionList;
215 +
216 + /**
212 * Creates a sub module node. 217 * Creates a sub module node.
213 */ 218 */
214 public YangSubModule() { 219 public YangSubModule() {
...@@ -216,6 +221,7 @@ public class YangSubModule ...@@ -216,6 +221,7 @@ public class YangSubModule
216 derivedTypeResolutionList = new LinkedList<>(); 221 derivedTypeResolutionList = new LinkedList<>();
217 usesResolutionList = new LinkedList<>(); 222 usesResolutionList = new LinkedList<>();
218 ifFeatureResolutionList = new LinkedList<>(); 223 ifFeatureResolutionList = new LinkedList<>();
224 + leafrefResolutionList = new LinkedList<>();
219 importList = new LinkedList<YangImport>(); 225 importList = new LinkedList<YangImport>();
220 includeList = new LinkedList<YangInclude>(); 226 includeList = new LinkedList<YangInclude>();
221 listOfLeaf = new LinkedList<YangLeaf>(); 227 listOfLeaf = new LinkedList<YangLeaf>();
...@@ -551,8 +557,10 @@ public class YangSubModule ...@@ -551,8 +557,10 @@ public class YangSubModule
551 return derivedTypeResolutionList; 557 return derivedTypeResolutionList;
552 } else if (type == ResolvableType.YANG_USES) { 558 } else if (type == ResolvableType.YANG_USES) {
553 return usesResolutionList; 559 return usesResolutionList;
554 - } else { 560 + } else if (type == ResolvableType.YANG_IF_FEATURE) {
555 return ifFeatureResolutionList; 561 return ifFeatureResolutionList;
562 + } else {
563 + return leafrefResolutionList;
556 } 564 }
557 } 565 }
558 566
...@@ -565,6 +573,8 @@ public class YangSubModule ...@@ -565,6 +573,8 @@ public class YangSubModule
565 usesResolutionList.add(resolutionInfo); 573 usesResolutionList.add(resolutionInfo);
566 } else if (type == ResolvableType.YANG_IF_FEATURE) { 574 } else if (type == ResolvableType.YANG_IF_FEATURE) {
567 ifFeatureResolutionList.add(resolutionInfo); 575 ifFeatureResolutionList.add(resolutionInfo);
576 + } else {
577 + leafrefResolutionList.add(resolutionInfo);
568 } 578 }
569 } 579 }
570 580
...@@ -576,7 +586,9 @@ public class YangSubModule ...@@ -576,7 +586,9 @@ public class YangSubModule
576 } else if (type == ResolvableType.YANG_USES) { 586 } else if (type == ResolvableType.YANG_USES) {
577 usesResolutionList = resolutionList; 587 usesResolutionList = resolutionList;
578 } else if (type == ResolvableType.YANG_IF_FEATURE) { 588 } else if (type == ResolvableType.YANG_IF_FEATURE) {
579 - ifFeatureResolutionList = resolutionList; 589 + ifFeatureResolutionList.add((YangResolutionInfo) resolutionList);
590 + } else if (type == ResolvableType.YANG_LEAFREF) {
591 + leafrefResolutionList = resolutionList;
580 } 592 }
581 593
582 } 594 }
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
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 +
20 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 21 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
21 import org.onosproject.yangutils.datamodel.utils.Parsable; 22 import org.onosproject.yangutils.datamodel.utils.Parsable;
22 import org.onosproject.yangutils.datamodel.utils.ResolvableStatus; 23 import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
...@@ -43,7 +44,7 @@ import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangData ...@@ -43,7 +44,7 @@ import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangData
43 * | bit | 9.7.4 | 0..n | - YangBit used in YangBits | 44 * | bit | 9.7.4 | 0..n | - YangBit used in YangBits |
44 * | enum | 9.6.4 | 0..n | - YangEnum used in YangEnumeration | 45 * | enum | 9.6.4 | 0..n | - YangEnum used in YangEnumeration |
45 * | length | 9.4.4 | 0..1 | - used for string | 46 * | length | 9.4.4 | 0..1 | - used for string |
46 - * | path | 9.9.2 | 0..1 | - TODO leaf-ref | 47 + * | path | 9.9.2 | 0..1 | - path for referred leaf/leaf-list |
47 * | pattern | 9.4.6 | 0..n | - used for string | 48 * | pattern | 9.4.6 | 0..n | - used for string |
48 * | range | 9.2.4 | 0..1 | - used for integer data type | 49 * | range | 9.2.4 | 0..1 | - used for integer data type |
49 * | require-instance | 9.13.2 | 0..1 | - TODO instance-identifier | 50 * | require-instance | 9.13.2 | 0..1 | - TODO instance-identifier |
...@@ -67,11 +68,6 @@ public class YangType<T> ...@@ -67,11 +68,6 @@ public class YangType<T>
67 private YangNodeIdentifier nodeIdentifier; 68 private YangNodeIdentifier nodeIdentifier;
68 69
69 /** 70 /**
70 - * Java package in which the Java type is defined.
71 - */
72 - private String javaPackage;
73 -
74 - /**
75 * YANG data type. 71 * YANG data type.
76 */ 72 */
77 private YangDataTypes dataType; 73 private YangDataTypes dataType;
...@@ -137,24 +133,6 @@ public class YangType<T> ...@@ -137,24 +133,6 @@ public class YangType<T>
137 } 133 }
138 134
139 /** 135 /**
140 - * Returns the Java package where the type is defined.
141 - *
142 - * @return Java package where the type is defined
143 - */
144 - public String getJavaPackage() {
145 - return javaPackage;
146 - }
147 -
148 - /**
149 - * Sets Java package where the type is defined.
150 - *
151 - * @param javaPackage Java package where the type is defined
152 - */
153 - public void setJavaPackage(String javaPackage) {
154 - this.javaPackage = javaPackage;
155 - }
156 -
157 - /**
158 * Returns the type of data. 136 * Returns the type of data.
159 * 137 *
160 * @return the data type 138 * @return the data type
...@@ -209,6 +187,16 @@ public class YangType<T> ...@@ -209,6 +187,16 @@ public class YangType<T>
209 } 187 }
210 188
211 /** 189 /**
190 + * Resets the class attributes to its default value.
191 + */
192 + public void resetYangType() {
193 + nodeIdentifier = new YangNodeIdentifier();
194 + resolvableStatus = ResolvableStatus.UNRESOLVED;
195 + dataType = null;
196 + dataTypeExtendedInfo = null;
197 + }
198 +
199 + /**
212 * Returns the type of the parsed data. 200 * Returns the type of the parsed data.
213 * 201 *
214 * @return returns TYPE_DATA 202 * @return returns TYPE_DATA
......
...@@ -24,6 +24,7 @@ import org.onosproject.yangutils.datamodel.ResolvableType; ...@@ -24,6 +24,7 @@ import org.onosproject.yangutils.datamodel.ResolvableType;
24 import org.onosproject.yangutils.datamodel.YangIfFeature; 24 import org.onosproject.yangutils.datamodel.YangIfFeature;
25 import org.onosproject.yangutils.datamodel.YangLeaf; 25 import org.onosproject.yangutils.datamodel.YangLeaf;
26 import org.onosproject.yangutils.datamodel.YangLeafList; 26 import org.onosproject.yangutils.datamodel.YangLeafList;
27 +import org.onosproject.yangutils.datamodel.YangLeafRef;
27 import org.onosproject.yangutils.datamodel.YangLeavesHolder; 28 import org.onosproject.yangutils.datamodel.YangLeavesHolder;
28 import org.onosproject.yangutils.datamodel.YangNode; 29 import org.onosproject.yangutils.datamodel.YangNode;
29 import org.onosproject.yangutils.datamodel.YangReferenceResolver; 30 import org.onosproject.yangutils.datamodel.YangReferenceResolver;
...@@ -171,6 +172,10 @@ public final class DataModelUtils { ...@@ -171,6 +172,10 @@ public final class DataModelUtils {
171 .getEntityToResolve() instanceof YangIfFeature) { 172 .getEntityToResolve() instanceof YangIfFeature) {
172 resolutionNode.addToResolutionList(resolutionInfo, 173 resolutionNode.addToResolutionList(resolutionInfo,
173 ResolvableType.YANG_IF_FEATURE); 174 ResolvableType.YANG_IF_FEATURE);
175 + } else if (resolutionInfo.getEntityToResolveInfo()
176 + .getEntityToResolve() instanceof YangLeafRef) {
177 + resolutionNode.addToResolutionList(resolutionInfo,
178 + ResolvableType.YANG_LEAFREF);
174 } 179 }
175 } 180 }
176 181
......
...@@ -25,14 +25,14 @@ public enum YangDataTypes { ...@@ -25,14 +25,14 @@ public enum YangDataTypes {
25 * 25 *
26 * int8 represents integer values between -128 and 127, inclusively. 26 * int8 represents integer values between -128 and 127, inclusively.
27 */ 27 */
28 - INT8, 28 + INT8("int8"),
29 29
30 /** 30 /**
31 * Reference:RFC 6020. 31 * Reference:RFC 6020.
32 * 32 *
33 * int16 represents integer values between -32768 and 32767, inclusively. 33 * int16 represents integer values between -32768 and 32767, inclusively.
34 */ 34 */
35 - INT16, 35 + INT16("int16"),
36 36
37 /** 37 /**
38 * Reference:RFC 6020. 38 * Reference:RFC 6020.
...@@ -40,7 +40,7 @@ public enum YangDataTypes { ...@@ -40,7 +40,7 @@ public enum YangDataTypes {
40 * int32 represents integer values between -2147483648 and 2147483647, 40 * int32 represents integer values between -2147483648 and 2147483647,
41 * inclusively. 41 * inclusively.
42 */ 42 */
43 - INT32, 43 + INT32("int32"),
44 44
45 /** 45 /**
46 * Reference:RFC 6020. 46 * Reference:RFC 6020.
...@@ -48,28 +48,28 @@ public enum YangDataTypes { ...@@ -48,28 +48,28 @@ public enum YangDataTypes {
48 * int64 represents integer values between -9223372036854775808 and 48 * int64 represents integer values between -9223372036854775808 and
49 * 9223372036854775807, inclusively. 49 * 9223372036854775807, inclusively.
50 */ 50 */
51 - INT64, 51 + INT64("int64"),
52 52
53 /** 53 /**
54 * Reference:RFC 6020. 54 * Reference:RFC 6020.
55 * 55 *
56 * uint8 represents integer values between 0 and 255, inclusively. 56 * uint8 represents integer values between 0 and 255, inclusively.
57 */ 57 */
58 - UINT8, 58 + UINT8("uint8"),
59 59
60 /** 60 /**
61 * Reference:RFC 6020. 61 * Reference:RFC 6020.
62 * 62 *
63 * uint16 represents integer values between 0 and 65535, inclusively. 63 * uint16 represents integer values between 0 and 65535, inclusively.
64 */ 64 */
65 - UINT16, 65 + UINT16("uint16"),
66 66
67 /** 67 /**
68 * Reference:RFC 6020. 68 * Reference:RFC 6020.
69 * 69 *
70 * uint32 represents integer values between 0 and 4294967295, inclusively. 70 * uint32 represents integer values between 0 and 4294967295, inclusively.
71 */ 71 */
72 - UINT32, 72 + UINT32("uint32"),
73 73
74 /** 74 /**
75 * Reference:RFC 6020. 75 * Reference:RFC 6020.
...@@ -77,7 +77,7 @@ public enum YangDataTypes { ...@@ -77,7 +77,7 @@ public enum YangDataTypes {
77 * uint64 represents integer values between 0 and 18446744073709551615, 77 * uint64 represents integer values between 0 and 18446744073709551615,
78 * inclusively. 78 * inclusively.
79 */ 79 */
80 - UINT64, 80 + UINT64("uint64"),
81 81
82 /** 82 /**
83 * Reference:RFC 6020. 83 * Reference:RFC 6020.
...@@ -88,7 +88,7 @@ public enum YangDataTypes { ...@@ -88,7 +88,7 @@ public enum YangDataTypes {
88 * a negative power of ten, i.e., expressible as "i x 10^-n" where i is an 88 * a negative power of ten, i.e., expressible as "i x 10^-n" where i is an
89 * integer64 and n is an integer between 1 and 18, inclusively. 89 * integer64 and n is an integer between 1 and 18, inclusively.
90 */ 90 */
91 - DECIMAL64, // TODO: need to implement in type. 91 + DECIMAL64("decimal64"), // TODO: need to implement in type.
92 92
93 /** 93 /**
94 * Reference:RFC 6020. 94 * Reference:RFC 6020.
...@@ -97,14 +97,14 @@ public enum YangDataTypes { ...@@ -97,14 +97,14 @@ public enum YangDataTypes {
97 * characters are tab, carriage return, line feed, and the legal characters 97 * characters are tab, carriage return, line feed, and the legal characters
98 * of Unicode and ISO/IEC 10646 98 * of Unicode and ISO/IEC 10646
99 */ 99 */
100 - STRING, 100 + STRING("string"),
101 101
102 /** 102 /**
103 * Reference:RFC 6020. 103 * Reference:RFC 6020.
104 * 104 *
105 * The boolean built-in type represents a boolean value. 105 * The boolean built-in type represents a boolean value.
106 */ 106 */
107 - BOOLEAN, 107 + BOOLEAN("boolean"),
108 108
109 /** 109 /**
110 * Reference:RFC 6020. 110 * Reference:RFC 6020.
...@@ -112,7 +112,7 @@ public enum YangDataTypes { ...@@ -112,7 +112,7 @@ public enum YangDataTypes {
112 * The enumeration built-in type represents values from a set of assigned 112 * The enumeration built-in type represents values from a set of assigned
113 * names. 113 * names.
114 */ 114 */
115 - ENUMERATION, 115 + ENUMERATION("enumeration"),
116 116
117 /** 117 /**
118 * Reference:RFC 6020. 118 * Reference:RFC 6020.
...@@ -121,7 +121,7 @@ public enum YangDataTypes { ...@@ -121,7 +121,7 @@ public enum YangDataTypes {
121 * set of flags identified by small integer position numbers starting at 0. 121 * set of flags identified by small integer position numbers starting at 0.
122 * Each bit number has an assigned name. 122 * Each bit number has an assigned name.
123 */ 123 */
124 - BITS, 124 + BITS("bits"),
125 125
126 /** 126 /**
127 * Reference:RFC 6020. 127 * Reference:RFC 6020.
...@@ -129,7 +129,7 @@ public enum YangDataTypes { ...@@ -129,7 +129,7 @@ public enum YangDataTypes {
129 * The binary built-in type represents any binary data, i.e., a sequence of 129 * The binary built-in type represents any binary data, i.e., a sequence of
130 * octets. 130 * octets.
131 */ 131 */
132 - BINARY, 132 + BINARY("binary"),
133 133
134 /** 134 /**
135 * Reference:RFC 6020. 135 * Reference:RFC 6020.
...@@ -150,14 +150,14 @@ public enum YangDataTypes { ...@@ -150,14 +150,14 @@ public enum YangDataTypes {
150 * more features, then the leaf with the leafref type MUST also be 150 * more features, then the leaf with the leafref type MUST also be
151 * conditional based on at least the same set of features. 151 * conditional based on at least the same set of features.
152 */ 152 */
153 - LEAFREF, // TODO: need to implement in type. 153 + LEAFREF("leafref"),
154 154
155 /** 155 /**
156 * Reference:RFC 6020. 156 * Reference:RFC 6020.
157 * 157 *
158 * The identityref type is used to reference an existing identity. 158 * The identityref type is used to reference an existing identity.
159 */ 159 */
160 - IDENTITYREF, 160 + IDENTITYREF("identityref"),
161 161
162 /** 162 /**
163 * Reference:RFC 6020. 163 * Reference:RFC 6020.
...@@ -167,7 +167,7 @@ public enum YangDataTypes { ...@@ -167,7 +167,7 @@ public enum YangDataTypes {
167 * 167 *
168 * An empty type cannot have a default value. 168 * An empty type cannot have a default value.
169 */ 169 */
170 - EMPTY, 170 + EMPTY("empty"),
171 171
172 /** 172 /**
173 * Reference:RFC 6020. 173 * Reference:RFC 6020.
...@@ -189,7 +189,7 @@ public enum YangDataTypes { ...@@ -189,7 +189,7 @@ public enum YangDataTypes {
189 * Any default value or "units" property defined in the member types is not 189 * Any default value or "units" property defined in the member types is not
190 * inherited by the union type. 190 * inherited by the union type.
191 */ 191 */
192 - UNION, 192 + UNION("union"),
193 193
194 /** 194 /**
195 * Reference:RFC 6020. 195 * Reference:RFC 6020.
...@@ -212,12 +212,26 @@ public enum YangDataTypes { ...@@ -212,12 +212,26 @@ public enum YangDataTypes {
212 * valid data. All such leaf nodes MUST reference existing nodes or leaf 212 * valid data. All such leaf nodes MUST reference existing nodes or leaf
213 * nodes with their default value in use for the data to be valid. 213 * nodes with their default value in use for the data to be valid.
214 */ 214 */
215 - INSTANCE_IDENTIFIER, 215 + INSTANCE_IDENTIFIER("instance-identifier"),
216 216
217 /** 217 /**
218 * Derived data type. 218 * Derived data type.
219 */ 219 */
220 - DERIVED; 220 + DERIVED("derived");
221 +
222 + /**
223 + * Defined type from the enum value.
224 + */
225 + private String definedType;
226 +
227 + /**
228 + * Constructs type value from enum.
229 + *
230 + * @param definedType value of enum
231 + */
232 + YangDataTypes(String definedType) {
233 + this.definedType = definedType;
234 + }
221 235
222 /** 236 /**
223 * Returns YANG data type for corresponding type name. 237 * Returns YANG data type for corresponding type name.
...@@ -228,7 +242,7 @@ public enum YangDataTypes { ...@@ -228,7 +242,7 @@ public enum YangDataTypes {
228 public static YangDataTypes getType(String name) { 242 public static YangDataTypes getType(String name) {
229 name = name.replace("\"", ""); 243 name = name.replace("\"", "");
230 for (YangDataTypes yangDataType : values()) { 244 for (YangDataTypes yangDataType : values()) {
231 - if (yangDataType.name().toLowerCase().equals(name)) { 245 + if (yangDataType.definedType.toLowerCase().equals(name)) {
232 return yangDataType; 246 return yangDataType;
233 } 247 }
234 } 248 }
......
...@@ -161,6 +161,8 @@ public class YangLinkerManager ...@@ -161,6 +161,8 @@ public class YangLinkerManager
161 ((YangReferenceResolver) yangNode).resolveInterFileLinking(ResolvableType.YANG_USES); 161 ((YangReferenceResolver) yangNode).resolveInterFileLinking(ResolvableType.YANG_USES);
162 ((YangReferenceResolver) yangNode) 162 ((YangReferenceResolver) yangNode)
163 .resolveInterFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE); 163 .resolveInterFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE);
164 + ((YangReferenceResolver) yangNode)
165 + .resolveInterFileLinking(ResolvableType.YANG_LEAFREF);
164 } catch (DataModelException e) { 166 } catch (DataModelException e) {
165 String errorInfo = "Error in file: " + yangNode.getName() + " at line: " 167 String errorInfo = "Error in file: " + yangNode.getName() + " at line: "
166 + e.getLineNumber() + " at position: " + e.getCharPositionInLine() + NEW_LINE + e.getMessage(); 168 + e.getLineNumber() + " at position: " + e.getCharPositionInLine() + NEW_LINE + e.getMessage();
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
16 16
17 // Generated from GeneratedYang.g4 by ANTLR 4.5 17 // Generated from GeneratedYang.g4 by ANTLR 4.5
18 18
19 -
20 package org.onosproject.yangutils.parser.antlrgencode; 19 package org.onosproject.yangutils.parser.antlrgencode;
21 20
22 import org.antlr.v4.runtime.tree.ParseTreeListener; 21 import org.antlr.v4.runtime.tree.ParseTreeListener;
...@@ -1950,4 +1949,18 @@ public interface GeneratedYangListener extends ParseTreeListener { ...@@ -1950,4 +1949,18 @@ public interface GeneratedYangListener extends ParseTreeListener {
1950 */ 1949 */
1951 void exitAnnotationIdentifier(GeneratedYangParser.AnnotationIdentifierContext 1950 void exitAnnotationIdentifier(GeneratedYangParser.AnnotationIdentifierContext
1952 currentContext); 1951 currentContext);
1952 +
1953 + /**
1954 + * Enters a parse tree produced by GeneratedYangParser for grammar rule require instance.
1955 + *
1956 + * @param currentContext current context in the parsed tree
1957 + */
1958 + void enterRequireInstance(GeneratedYangParser.RequireInstanceContext currentContext);
1959 +
1960 + /**
1961 + * Exits a parse tree produced by GeneratedYangParser for grammar require instance.
1962 + *
1963 + * @param currentContext current context in the parsed tree
1964 + */
1965 + void exitRequireInstance(GeneratedYangParser.RequireInstanceContext currentContext);
1953 } 1966 }
......
...@@ -49,6 +49,7 @@ import org.onosproject.yangutils.parser.impl.listeners.InputListener; ...@@ -49,6 +49,7 @@ import org.onosproject.yangutils.parser.impl.listeners.InputListener;
49 import org.onosproject.yangutils.parser.impl.listeners.KeyListener; 49 import org.onosproject.yangutils.parser.impl.listeners.KeyListener;
50 import org.onosproject.yangutils.parser.impl.listeners.LeafListListener; 50 import org.onosproject.yangutils.parser.impl.listeners.LeafListListener;
51 import org.onosproject.yangutils.parser.impl.listeners.LeafListener; 51 import org.onosproject.yangutils.parser.impl.listeners.LeafListener;
52 +import org.onosproject.yangutils.parser.impl.listeners.LeafrefListener;
52 import org.onosproject.yangutils.parser.impl.listeners.LengthRestrictionListener; 53 import org.onosproject.yangutils.parser.impl.listeners.LengthRestrictionListener;
53 import org.onosproject.yangutils.parser.impl.listeners.ListListener; 54 import org.onosproject.yangutils.parser.impl.listeners.ListListener;
54 import org.onosproject.yangutils.parser.impl.listeners.MandatoryListener; 55 import org.onosproject.yangutils.parser.impl.listeners.MandatoryListener;
...@@ -56,16 +57,18 @@ import org.onosproject.yangutils.parser.impl.listeners.MaxElementsListener; ...@@ -56,16 +57,18 @@ import org.onosproject.yangutils.parser.impl.listeners.MaxElementsListener;
56 import org.onosproject.yangutils.parser.impl.listeners.MinElementsListener; 57 import org.onosproject.yangutils.parser.impl.listeners.MinElementsListener;
57 import org.onosproject.yangutils.parser.impl.listeners.ModuleListener; 58 import org.onosproject.yangutils.parser.impl.listeners.ModuleListener;
58 import org.onosproject.yangutils.parser.impl.listeners.MustListener; 59 import org.onosproject.yangutils.parser.impl.listeners.MustListener;
59 -import org.onosproject.yangutils.parser.impl.listeners.NotificationListener;
60 import org.onosproject.yangutils.parser.impl.listeners.NamespaceListener; 60 import org.onosproject.yangutils.parser.impl.listeners.NamespaceListener;
61 +import org.onosproject.yangutils.parser.impl.listeners.NotificationListener;
61 import org.onosproject.yangutils.parser.impl.listeners.OrganizationListener; 62 import org.onosproject.yangutils.parser.impl.listeners.OrganizationListener;
62 import org.onosproject.yangutils.parser.impl.listeners.OutputListener; 63 import org.onosproject.yangutils.parser.impl.listeners.OutputListener;
64 +import org.onosproject.yangutils.parser.impl.listeners.PathListener;
63 import org.onosproject.yangutils.parser.impl.listeners.PatternRestrictionListener; 65 import org.onosproject.yangutils.parser.impl.listeners.PatternRestrictionListener;
64 import org.onosproject.yangutils.parser.impl.listeners.PositionListener; 66 import org.onosproject.yangutils.parser.impl.listeners.PositionListener;
65 import org.onosproject.yangutils.parser.impl.listeners.PrefixListener; 67 import org.onosproject.yangutils.parser.impl.listeners.PrefixListener;
66 import org.onosproject.yangutils.parser.impl.listeners.PresenceListener; 68 import org.onosproject.yangutils.parser.impl.listeners.PresenceListener;
67 import org.onosproject.yangutils.parser.impl.listeners.RangeRestrictionListener; 69 import org.onosproject.yangutils.parser.impl.listeners.RangeRestrictionListener;
68 import org.onosproject.yangutils.parser.impl.listeners.ReferenceListener; 70 import org.onosproject.yangutils.parser.impl.listeners.ReferenceListener;
71 +import org.onosproject.yangutils.parser.impl.listeners.RequireInstanceListener;
69 import org.onosproject.yangutils.parser.impl.listeners.RevisionDateListener; 72 import org.onosproject.yangutils.parser.impl.listeners.RevisionDateListener;
70 import org.onosproject.yangutils.parser.impl.listeners.RevisionListener; 73 import org.onosproject.yangutils.parser.impl.listeners.RevisionListener;
71 import org.onosproject.yangutils.parser.impl.listeners.RpcListener; 74 import org.onosproject.yangutils.parser.impl.listeners.RpcListener;
...@@ -81,9 +84,9 @@ import org.onosproject.yangutils.parser.impl.listeners.ValueListener; ...@@ -81,9 +84,9 @@ import org.onosproject.yangutils.parser.impl.listeners.ValueListener;
81 import org.onosproject.yangutils.parser.impl.listeners.VersionListener; 84 import org.onosproject.yangutils.parser.impl.listeners.VersionListener;
82 import org.onosproject.yangutils.parser.impl.listeners.WhenListener; 85 import org.onosproject.yangutils.parser.impl.listeners.WhenListener;
83 86
84 -import static org.onosproject.yangutils.utils.UtilConstants.UNSUPPORTED_YANG_CONSTRUCT;
85 -import static org.onosproject.yangutils.utils.UtilConstants.CURRENTLY_UNSUPPORTED;
86 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.handleUnsupportedYangConstruct; 87 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.handleUnsupportedYangConstruct;
88 +import static org.onosproject.yangutils.utils.UtilConstants.CURRENTLY_UNSUPPORTED;
89 +import static org.onosproject.yangutils.utils.UtilConstants.UNSUPPORTED_YANG_CONSTRUCT;
87 90
88 /** 91 /**
89 * Represents ANTLR generates parse-tree. ANTLR generates a parse-tree listener interface that responds to events 92 * Represents ANTLR generates parse-tree. ANTLR generates a parse-tree listener interface that responds to events
...@@ -667,17 +670,17 @@ public class TreeWalkListener implements GeneratedYangListener { ...@@ -667,17 +670,17 @@ public class TreeWalkListener implements GeneratedYangListener {
667 670
668 @Override 671 @Override
669 public void enterLeafrefSpecification(GeneratedYangParser.LeafrefSpecificationContext ctx) { 672 public void enterLeafrefSpecification(GeneratedYangParser.LeafrefSpecificationContext ctx) {
670 - // do nothing. 673 + LeafrefListener.processLeafrefEntry(this, ctx);
671 } 674 }
672 675
673 @Override 676 @Override
674 public void exitLeafrefSpecification(GeneratedYangParser.LeafrefSpecificationContext ctx) { 677 public void exitLeafrefSpecification(GeneratedYangParser.LeafrefSpecificationContext ctx) {
675 - // do nothing. 678 + LeafrefListener.processLeafrefExit(this, ctx);
676 } 679 }
677 680
678 @Override 681 @Override
679 public void enterPathStatement(GeneratedYangParser.PathStatementContext ctx) { 682 public void enterPathStatement(GeneratedYangParser.PathStatementContext ctx) {
680 - handleUnsupportedYangConstruct(YangConstructType.PATH_DATA, ctx, CURRENTLY_UNSUPPORTED); 683 + PathListener.processPathEntry(this, ctx);
681 } 684 }
682 685
683 @Override 686 @Override
...@@ -687,7 +690,7 @@ public class TreeWalkListener implements GeneratedYangListener { ...@@ -687,7 +690,7 @@ public class TreeWalkListener implements GeneratedYangListener {
687 690
688 @Override 691 @Override
689 public void enterRequireInstanceStatement(GeneratedYangParser.RequireInstanceStatementContext ctx) { 692 public void enterRequireInstanceStatement(GeneratedYangParser.RequireInstanceStatementContext ctx) {
690 - handleUnsupportedYangConstruct(YangConstructType.REQUIRE_INSTANCE_DATA, ctx, UNSUPPORTED_YANG_CONSTRUCT); 693 + RequireInstanceListener.processRequireInstanceEntry(this, ctx);
691 } 694 }
692 695
693 @Override 696 @Override
...@@ -1489,6 +1492,16 @@ public class TreeWalkListener implements GeneratedYangListener { ...@@ -1489,6 +1492,16 @@ public class TreeWalkListener implements GeneratedYangListener {
1489 } 1492 }
1490 1493
1491 @Override 1494 @Override
1495 + public void enterRequireInstance(GeneratedYangParser.RequireInstanceContext ctx) {
1496 + // do nothing.
1497 + }
1498 +
1499 + @Override
1500 + public void exitRequireInstance(GeneratedYangParser.RequireInstanceContext ctx) {
1501 + // do nothing.
1502 + }
1503 +
1504 + @Override
1492 public void enterFraction(GeneratedYangParser.FractionContext ctx) { 1505 public void enterFraction(GeneratedYangParser.FractionContext ctx) {
1493 // TODO: implement the method. 1506 // TODO: implement the method.
1494 } 1507 }
......
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 +import org.onosproject.yangutils.datamodel.YangLeaf;
20 +import org.onosproject.yangutils.datamodel.YangLeafList;
21 +import org.onosproject.yangutils.datamodel.YangLeafRef;
22 +import org.onosproject.yangutils.datamodel.YangNode;
23 +import org.onosproject.yangutils.datamodel.YangType;
24 +import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
25 +import org.onosproject.yangutils.datamodel.utils.Parsable;
26 +import org.onosproject.yangutils.linker.impl.YangResolutionInfoImpl;
27 +import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
28 +import org.onosproject.yangutils.parser.exceptions.ParserException;
29 +import org.onosproject.yangutils.parser.impl.TreeWalkListener;
30 +
31 +import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.addResolutionInfo;
32 +import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.UNRESOLVED;
33 +import static org.onosproject.yangutils.datamodel.utils.YangConstructType.LEAFREF_DATA;
34 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
35 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
36 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
37 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
38 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
39 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
40 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
41 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
42 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
43 +
44 +/*
45 + * Reference: RFC6020 and YANG ANTLR Grammar
46 + *
47 + * ABNF grammar as per RFC6020
48 + * type-body-stmts = numerical-restrictions /
49 + * decimal64-specification /
50 + * string-restrictions /
51 + * enum-specification /
52 + * leafref-specification /
53 + * identityref-specification /
54 + * instance-identifier-specification /
55 + * bits-specification /
56 + * union-specification
57 + *
58 + * leafref-specification =
59 + * ;; these stmts can appear in any order
60 + * path-stmt stmtsep
61 + * [require-instance-stmt stmtsep]
62 + *
63 + * ANTLR grammar rule
64 + *
65 + * typeBodyStatements : numericalRestrictions | stringRestrictions | enumSpecification
66 + * | leafrefSpecification | identityrefSpecification | instanceIdentifierSpecification
67 + * | bitsSpecification | unionSpecification;
68 + *
69 + * leafrefSpecification : (pathStatement (requireInstanceStatement)?) | ((requireInstanceStatement)? pathStatement);
70 + */
71 +
72 +/**
73 + * Represents listener based call back function corresponding to the
74 + * "leafref" rule defined in ANTLR grammar file for corresponding ABNF rule
75 + * in RFC 6020.
76 + */
77 +public final class LeafrefListener {
78 +
79 + /**
80 + * Creates a new leafref listener.
81 + */
82 + private LeafrefListener() {
83 + }
84 +
85 + /**
86 + * It is called when parser receives an input matching the grammar rule
87 + * (leafref), perform validations and updates the data model tree.
88 + *
89 + * @param listener listener's object
90 + * @param ctx context object of the grammar rule
91 + */
92 + public static void processLeafrefEntry(TreeWalkListener listener,
93 + GeneratedYangParser.LeafrefSpecificationContext ctx) {
94 +
95 + // Check for stack to be non empty.
96 + checkStackIsNotEmpty(listener, MISSING_HOLDER, LEAFREF_DATA, "", ENTRY);
97 +
98 + int errorLine = ctx.getStart().getLine();
99 + int errorPosition = ctx.getStart().getCharPositionInLine();
100 +
101 + YangLeafRef<?> leafRef = new YangLeafRef<>();
102 +
103 + Parsable typeData = listener.getParsedDataStack().pop();
104 +
105 + if (!(typeData instanceof YangType)) {
106 + throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, LEAFREF_DATA,
107 + "", ENTRY));
108 + }
109 +
110 + YangType type = (YangType) typeData;
111 + type.setDataTypeExtendedInfo(leafRef);
112 +
113 + // Setting by default the value of require-instance as true.
114 + leafRef.setRequireInstance(true);
115 + Parsable tmpData = listener.getParsedDataStack().peek();
116 +
117 + switch (tmpData.getYangConstructType()) {
118 +
119 + case LEAF_DATA:
120 +
121 + // Parent YANG node of leaf to be added in resolution information.
122 + YangLeaf leaf = (YangLeaf) listener.getParsedDataStack().pop();
123 + Parsable parentNodeOfLeaf = listener.getParsedDataStack().peek();
124 + listener.getParsedDataStack().push(leaf);
125 +
126 + // Verify parent node of leaf.
127 + if (!(parentNodeOfLeaf instanceof YangNode)) {
128 + throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, LEAFREF_DATA,
129 + "", ENTRY));
130 + }
131 +
132 + leafRef.setResolvableStatus(UNRESOLVED);
133 +
134 + // Add resolution information to the list.
135 + YangResolutionInfoImpl resolutionInfo = new YangResolutionInfoImpl<YangLeafRef>(leafRef,
136 + (YangNode) parentNodeOfLeaf, errorLine, errorPosition);
137 + addToResolutionList(resolutionInfo);
138 + break;
139 +
140 + case LEAF_LIST_DATA:
141 +
142 + // Parent YANG node of leaf-list to be added in resolution information.
143 + YangLeafList leafList = (YangLeafList) listener.getParsedDataStack().pop();
144 + Parsable parentNodeOfLeafList = listener.getParsedDataStack().peek();
145 + listener.getParsedDataStack().push(leafList);
146 +
147 + // Verify parent node of leaf-list.
148 + if (!(parentNodeOfLeafList instanceof YangNode)) {
149 + throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, LEAFREF_DATA,
150 + "", ENTRY));
151 + }
152 +
153 + leafRef.setResolvableStatus(UNRESOLVED);
154 +
155 + // Add resolution information to the list.
156 + YangResolutionInfoImpl resolutionInfoImpl = new YangResolutionInfoImpl<YangLeafRef>(leafRef,
157 + (YangNode) parentNodeOfLeafList, errorLine, errorPosition);
158 + addToResolutionList(resolutionInfoImpl);
159 + break;
160 +
161 + case TYPEDEF_DATA:
162 + /*
163 + * Do not add the leaf ref to resolution list. It needs to be
164 + * added to resolution list, when leaf/leaf list references to
165 + * this typedef. At this time that leaf/leaf-list becomes the
166 + * parent for the leafref.
167 + */
168 + break;
169 +
170 + default:
171 + throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, LEAFREF_DATA,
172 + "", ENTRY));
173 + }
174 + listener.getParsedDataStack().push(typeData);
175 + listener.getParsedDataStack().push(leafRef);
176 + }
177 +
178 + /**
179 + * It is called when parser exits from grammar rule (leafref), it performs
180 + * validation and updates the data model tree.
181 + *
182 + * @param listener listener's object
183 + * @param ctx context object of the grammar rule
184 + */
185 + public static void processLeafrefExit(TreeWalkListener listener,
186 + GeneratedYangParser.LeafrefSpecificationContext ctx) {
187 +
188 + // Check for stack to be non empty.
189 + checkStackIsNotEmpty(listener, MISSING_CURRENT_HOLDER, LEAFREF_DATA, "", EXIT);
190 +
191 + Parsable parsableType = listener.getParsedDataStack().pop();
192 + if (!(parsableType instanceof YangLeafRef)) {
193 + throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, LEAFREF_DATA,
194 + "", EXIT));
195 + }
196 + }
197 +
198 + /**
199 + * Adds to resolution list.
200 + *
201 + * @param resolutionInfo resolution information
202 + */
203 + private static void addToResolutionList(YangResolutionInfoImpl resolutionInfo) {
204 +
205 + try {
206 + addResolutionInfo(resolutionInfo);
207 + } catch (DataModelException e) {
208 + throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
209 + LEAFREF_DATA, "", ENTRY, e.getMessage()));
210 + }
211 + }
212 +}
...@@ -128,6 +128,8 @@ public final class ModuleListener { ...@@ -128,6 +128,8 @@ public final class ModuleListener {
128 .peek()).resolveSelfFileLinking(ResolvableType.YANG_USES); 128 .peek()).resolveSelfFileLinking(ResolvableType.YANG_USES);
129 ((YangReferenceResolver) listener.getParsedDataStack() 129 ((YangReferenceResolver) listener.getParsedDataStack()
130 .peek()).resolveSelfFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE); 130 .peek()).resolveSelfFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE);
131 + ((YangReferenceResolver) listener.getParsedDataStack()
132 + .peek()).resolveSelfFileLinking(ResolvableType.YANG_LEAFREF);
131 } catch (DataModelException e) { 133 } catch (DataModelException e) {
132 LinkerException linkerException = new LinkerException(e.getMessage()); 134 LinkerException linkerException = new LinkerException(e.getMessage());
133 linkerException.setLine(e.getLineNumber()); 135 linkerException.setLine(e.getLineNumber());
......
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 +import org.onosproject.yangutils.datamodel.YangLeafRef;
20 +import org.onosproject.yangutils.datamodel.utils.Parsable;
21 +import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
22 +import org.onosproject.yangutils.parser.exceptions.ParserException;
23 +import org.onosproject.yangutils.parser.impl.TreeWalkListener;
24 +
25 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
26 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.validatePathArgument;
27 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
28 +import static org.onosproject.yangutils.datamodel.utils.YangConstructType.PATH_DATA;
29 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
30 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
31 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
32 +
33 +/*
34 + * Reference: RFC6020 and YANG ANTLR Grammar
35 + *
36 + * ABNF grammar as per RFC6020
37 + * leafref-specification =
38 + * ;; these stmts can appear in any order
39 + * path-stmt stmtsep
40 + * [require-instance-stmt stmtsep]
41 + *
42 + * path-stmt = path-keyword sep path-arg-str stmtend
43 + *
44 + * ANTLR grammar rule
45 + *
46 + * leafrefSpecification : (pathStatement (requireInstanceStatement)?) | ((requireInstanceStatement)? pathStatement);
47 + *
48 + * pathStatement : PATH_KEYWORD path STMTEND;
49 + */
50 +
51 +/**
52 + * Represents listener based call back function corresponding to the
53 + * "path" rule defined in ANTLR grammar file for corresponding ABNF rule
54 + * in RFC 6020.
55 + */
56 +public final class PathListener {
57 +
58 + /**
59 + * Creates a new path listener.
60 + */
61 + private PathListener() {
62 + }
63 +
64 + /**
65 + * It is called when parser receives an input matching the grammar rule
66 + * (path), performs validation and updates the data model tree.
67 + *
68 + * @param listener listener's object
69 + * @param ctx context object of the grammar rule
70 + */
71 + public static void processPathEntry(TreeWalkListener listener,
72 + GeneratedYangParser.PathStatementContext ctx) {
73 +
74 + // Check for stack to be non empty.
75 + checkStackIsNotEmpty(listener, MISSING_HOLDER, PATH_DATA, ctx.path().getText(), ENTRY);
76 +
77 + Parsable curData = listener.getParsedDataStack().peek();
78 +
79 + // Checks the holder of path as leafref, else throws error.
80 + if (curData instanceof YangLeafRef) {
81 +
82 + // Splitting the path argument and updating it in the datamodel tree.
83 + validatePathArgument(ctx.path().getText(), PATH_DATA, ctx, (YangLeafRef) curData);
84 + } else {
85 + throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, PATH_DATA,
86 + ctx.path().getText(), ENTRY));
87 + }
88 + }
89 +}
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 +import org.onosproject.yangutils.datamodel.YangLeafRef;
20 +import org.onosproject.yangutils.datamodel.YangType;
21 +import org.onosproject.yangutils.datamodel.utils.Parsable;
22 +import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
23 +import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
24 +import org.onosproject.yangutils.parser.exceptions.ParserException;
25 +import org.onosproject.yangutils.parser.impl.TreeWalkListener;
26 +
27 +import static org.onosproject.yangutils.datamodel.utils.YangConstructType.REQUIRE_INSTANCE_DATA;
28 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
29 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidBooleanValue;
30 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
31 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
32 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
33 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
34 +
35 +/*
36 + * Reference: RFC6020 and YANG ANTLR Grammar
37 + *
38 + * ABNF grammar as per RFC6020
39 + * require-instance-stmt = require-instance-keyword sep
40 + * require-instance-arg-str stmtend
41 + *
42 + * require-instance-arg-str = < a string that matches the rule
43 + * require-instance-arg >
44 + *
45 + * require-instance-arg = true-keyword / false-keyword
46 + *
47 + * ANTLR grammar rule
48 + *
49 + * requireInstanceStatement : REQUIRE_INSTANCE_KEYWORD requireInstance STMTEND;
50 + *
51 + * requireInstance : string;
52 + */
53 +
54 +/**
55 + * Represents listener based call back function corresponding to the
56 + * "require-instance" rule defined in ANTLR grammar file for corresponding ABNF rule
57 + * in RFC 6020.
58 + */
59 +public final class RequireInstanceListener {
60 +
61 + /**
62 + * Creates a new require instance listener.
63 + */
64 + private RequireInstanceListener() {
65 + }
66 +
67 + /**
68 + * It is called when parser receives an input matching the grammar rule
69 + * (require-instance), performs validation and updates the data model tree.
70 + *
71 + * @param listener listener's object
72 + * @param ctx context object of the grammar rule
73 + */
74 + public static void processRequireInstanceEntry(TreeWalkListener listener,
75 + GeneratedYangParser.RequireInstanceStatementContext ctx) {
76 +
77 + // Check for stack to be non empty.
78 + checkStackIsNotEmpty(listener, MISSING_HOLDER, REQUIRE_INSTANCE_DATA, "", ENTRY);
79 +
80 + Parsable curData = listener.getParsedDataStack().peek();
81 +
82 + // Gets the status of require instance
83 + boolean isRequireInstance = getValidBooleanValue(ctx.requireInstance().getText(), REQUIRE_INSTANCE_DATA, ctx);
84 +
85 + // Checks the holder of require-instance as leafref or type, else throws error.
86 + if (curData instanceof YangLeafRef) {
87 +
88 + // Sets the require-instance status to leafref.
89 + ((YangLeafRef) curData).setRequireInstance(isRequireInstance);
90 + } else if (curData instanceof YangType) {
91 +
92 + // Checks type should be instance-identifier, else throw error.
93 + if (((YangType) curData).getDataType() == YangDataTypes.INSTANCE_IDENTIFIER) {
94 +
95 + // Sets the require-instance status to instance-identifier type.
96 + ((YangType) curData).setDataTypeExtendedInfo(isRequireInstance);
97 + } else {
98 + throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, REQUIRE_INSTANCE_DATA,
99 + ctx.getText(), ENTRY));
100 + }
101 + } else {
102 + throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, REQUIRE_INSTANCE_DATA,
103 + ctx.getText(), ENTRY));
104 + }
105 + }
106 +}
...@@ -133,6 +133,8 @@ public final class SubModuleListener { ...@@ -133,6 +133,8 @@ public final class SubModuleListener {
133 .resolveSelfFileLinking(ResolvableType.YANG_USES); 133 .resolveSelfFileLinking(ResolvableType.YANG_USES);
134 ((YangReferenceResolver) listener.getParsedDataStack().peek()) 134 ((YangReferenceResolver) listener.getParsedDataStack().peek())
135 .resolveSelfFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE); 135 .resolveSelfFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE);
136 + ((YangReferenceResolver) listener.getParsedDataStack().peek())
137 + .resolveSelfFileLinking(ResolvableType.YANG_LEAFREF);
136 } catch (DataModelException e) { 138 } catch (DataModelException e) {
137 LinkerException linkerException = new LinkerException(e.getMessage()); 139 LinkerException linkerException = new LinkerException(e.getMessage());
138 linkerException.setLine(e.getLineNumber()); 140 linkerException.setLine(e.getLineNumber());
......
...@@ -101,6 +101,9 @@ public final class TypeListener { ...@@ -101,6 +101,9 @@ public final class TypeListener {
101 type.setNodeIdentifier(nodeIdentifier); 101 type.setNodeIdentifier(nodeIdentifier);
102 type.setDataType(yangDataTypes); 102 type.setDataType(yangDataTypes);
103 103
104 + // Set default require instance value as true for instance identifier.
105 + setDefaultRequireInstanceForInstanceIdentifier(type);
106 +
104 int errorLine = ctx.getStart().getLine(); 107 int errorLine = ctx.getStart().getLine();
105 int errorPosition = ctx.getStart().getCharPositionInLine(); 108 int errorPosition = ctx.getStart().getCharPositionInLine();
106 109
...@@ -233,6 +236,18 @@ public final class TypeListener { ...@@ -233,6 +236,18 @@ public final class TypeListener {
233 } 236 }
234 237
235 /** 238 /**
239 + * Sets the default require instance value as true when the type is instance identifier.
240 + *
241 + * @param type type to which the value has to be set
242 + */
243 + private static void setDefaultRequireInstanceForInstanceIdentifier(YangType<?> type) {
244 +
245 + if (type.getDataType() == YangDataTypes.INSTANCE_IDENTIFIER) {
246 + ((YangType<Boolean>) type).setDataTypeExtendedInfo(true);
247 + }
248 + }
249 +
250 + /**
236 * It is called when parser exits from grammar rule (type), it perform 251 * It is called when parser exits from grammar rule (type), it perform
237 * validations and update the data model tree. 252 * validations and update the data model tree.
238 * 253 *
...@@ -291,7 +306,11 @@ public final class TypeListener { ...@@ -291,7 +306,11 @@ public final class TypeListener {
291 parserException = new ParserException("YANG file error : a type bits" + 306 parserException = new ParserException("YANG file error : a type bits" +
292 " must have atleast one bit statement."); 307 " must have atleast one bit statement.");
293 break; 308 break;
294 - // TODO : decimal64, identity ref, leafref 309 + case LEAFREF:
310 + parserException = new ParserException("YANG file error : a type leafref" +
311 + " must have one path statement.");
312 + break;
313 + // TODO : decimal64, identity ref
295 default: 314 default:
296 return; 315 return;
297 } 316 }
......
...@@ -19,6 +19,8 @@ package org.onosproject.yangutils.translator.tojava; ...@@ -19,6 +19,8 @@ package org.onosproject.yangutils.translator.tojava;
19 import java.io.IOException; 19 import java.io.IOException;
20 20
21 import org.onosproject.yangutils.datamodel.YangNode; 21 import org.onosproject.yangutils.datamodel.YangNode;
22 +import org.onosproject.yangutils.datamodel.YangTypeDef;
23 +import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
22 import org.onosproject.yangutils.translator.exception.TranslatorException; 24 import org.onosproject.yangutils.translator.exception.TranslatorException;
23 import org.onosproject.yangutils.utils.io.impl.YangPluginConfig; 25 import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
24 26
...@@ -80,7 +82,20 @@ public final class JavaCodeGeneratorUtil { ...@@ -80,7 +82,20 @@ public final class JavaCodeGeneratorUtil {
80 if (!(codeGenNode instanceof JavaCodeGenerator)) { 82 if (!(codeGenNode instanceof JavaCodeGenerator)) {
81 throw new TranslatorException("Unsupported node to generate code"); 83 throw new TranslatorException("Unsupported node to generate code");
82 } 84 }
83 - 85 + if (codeGenNode instanceof YangTypeDef) {
86 + YangTypeDef typeDef = (YangTypeDef) codeGenNode;
87 + if (typeDef.getTypeDefBaseType().getDataType() == YangDataTypes.LEAFREF
88 + || typeDef.getTypeDefBaseType().getDataType() == YangDataTypes.IDENTITYREF) {
89 + if (codeGenNode.getNextSibling() != null) {
90 + curTraversal = SIBILING;
91 + codeGenNode = codeGenNode.getNextSibling();
92 + } else {
93 + curTraversal = PARENT;
94 + codeGenNode = codeGenNode.getParent();
95 + }
96 + continue;
97 + }
98 + }
84 setCurNode(codeGenNode); 99 setCurNode(codeGenNode);
85 try { 100 try {
86 generateCodeEntry(codeGenNode, yangPlugin); 101 generateCodeEntry(codeGenNode, yangPlugin);
......
...@@ -17,13 +17,15 @@ ...@@ -17,13 +17,15 @@
17 package org.onosproject.yangutils.translator.tojava.javamodel; 17 package org.onosproject.yangutils.translator.tojava.javamodel;
18 18
19 import java.util.Stack; 19 import java.util.Stack;
20 -import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes; 20 +
21 import org.onosproject.yangutils.datamodel.YangDerivedInfo; 21 import org.onosproject.yangutils.datamodel.YangDerivedInfo;
22 import org.onosproject.yangutils.datamodel.YangEnumeration; 22 import org.onosproject.yangutils.datamodel.YangEnumeration;
23 +import org.onosproject.yangutils.datamodel.YangLeafRef;
23 import org.onosproject.yangutils.datamodel.YangNode; 24 import org.onosproject.yangutils.datamodel.YangNode;
24 import org.onosproject.yangutils.datamodel.YangType; 25 import org.onosproject.yangutils.datamodel.YangType;
25 import org.onosproject.yangutils.datamodel.YangTypeDef; 26 import org.onosproject.yangutils.datamodel.YangTypeDef;
26 import org.onosproject.yangutils.datamodel.YangUnion; 27 import org.onosproject.yangutils.datamodel.YangUnion;
28 +import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
27 import org.onosproject.yangutils.translator.exception.TranslatorException; 29 import org.onosproject.yangutils.translator.exception.TranslatorException;
28 import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo; 30 import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
29 import org.onosproject.yangutils.translator.tojava.JavaFileInfo; 31 import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
...@@ -101,6 +103,10 @@ public final class AttributesJavaDataType { ...@@ -101,6 +103,10 @@ public final class AttributesJavaDataType {
101 return STRING_DATA_TYPE; 103 return STRING_DATA_TYPE;
102 case BOOLEAN: 104 case BOOLEAN:
103 return BOOLEAN_DATA_TYPE; 105 return BOOLEAN_DATA_TYPE;
106 + case INSTANCE_IDENTIFIER:
107 + return STRING_DATA_TYPE;
108 + case LEAFREF:
109 + return getJavaDataType(getReferredTypeFromLeafref(yangType));
104 default: 110 default:
105 throw new TranslatorException("given data type is not supported."); 111 throw new TranslatorException("given data type is not supported.");
106 } 112 }
...@@ -152,8 +158,8 @@ public final class AttributesJavaDataType { ...@@ -152,8 +158,8 @@ public final class AttributesJavaDataType {
152 case BINARY: 158 case BINARY:
153 return YANG_BINARY_CLASS; 159 return YANG_BINARY_CLASS;
154 case LEAFREF: 160 case LEAFREF:
155 - //TODO:LEAFREF 161 + YangType<?> referredType = getReferredTypeFromLeafref(yangType);
156 - break; 162 + return getJavaImportClass(referredType, isListAttr, pluginConfig);
157 case IDENTITYREF: 163 case IDENTITYREF:
158 //TODO:IDENTITYREF 164 //TODO:IDENTITYREF
159 break; 165 break;
...@@ -163,8 +169,7 @@ public final class AttributesJavaDataType { ...@@ -163,8 +169,7 @@ public final class AttributesJavaDataType {
163 return getCapitalCase(getCamelCase(((YangJavaUnion) yangType.getDataTypeExtendedInfo()).getName(), 169 return getCapitalCase(getCamelCase(((YangJavaUnion) yangType.getDataTypeExtendedInfo()).getName(),
164 pluginConfig)); 170 pluginConfig));
165 case INSTANCE_IDENTIFIER: 171 case INSTANCE_IDENTIFIER:
166 - //TODO:INSTANCE_IDENTIFIER 172 + return STRING_DATA_TYPE;
167 - break;
168 case DERIVED: 173 case DERIVED:
169 return getCapitalCase( 174 return getCapitalCase(
170 getCamelCase(yangType.getDataTypeName(), pluginConfig)); 175 getCamelCase(yangType.getDataTypeName(), pluginConfig));
...@@ -188,8 +193,8 @@ public final class AttributesJavaDataType { ...@@ -188,8 +193,8 @@ public final class AttributesJavaDataType {
188 case BINARY: 193 case BINARY:
189 return YANG_BINARY_CLASS; 194 return YANG_BINARY_CLASS;
190 case LEAFREF: 195 case LEAFREF:
191 - //TODO:LEAFREF 196 + YangType<?> referredType = getReferredTypeFromLeafref(yangType);
192 - break; 197 + return getJavaImportClass(referredType, isListAttr, pluginConfig);
193 case IDENTITYREF: 198 case IDENTITYREF:
194 //TODO:IDENTITYREF 199 //TODO:IDENTITYREF
195 break; 200 break;
...@@ -199,8 +204,7 @@ public final class AttributesJavaDataType { ...@@ -199,8 +204,7 @@ public final class AttributesJavaDataType {
199 return getCapitalCase(getCamelCase(((YangJavaUnion) yangType.getDataTypeExtendedInfo()).getName(), 204 return getCapitalCase(getCamelCase(((YangJavaUnion) yangType.getDataTypeExtendedInfo()).getName(),
200 pluginConfig)); 205 pluginConfig));
201 case INSTANCE_IDENTIFIER: 206 case INSTANCE_IDENTIFIER:
202 - //TODO:INSTANCE_IDENTIFIER 207 + return STRING_DATA_TYPE;
203 - break;
204 case DERIVED: 208 case DERIVED:
205 return getCapitalCase( 209 return getCapitalCase(
206 getCamelCase(yangType.getDataTypeName(), pluginConfig)); 210 getCamelCase(yangType.getDataTypeName(), pluginConfig));
...@@ -246,16 +250,15 @@ public final class AttributesJavaDataType { ...@@ -246,16 +250,15 @@ public final class AttributesJavaDataType {
246 case BINARY: 250 case BINARY:
247 return YANG_TYPES_PKG; 251 return YANG_TYPES_PKG;
248 case LEAFREF: 252 case LEAFREF:
249 - //TODO:LEAFREF 253 + YangType<?> referredType = getReferredTypeFromLeafref(yangType);
250 - break; 254 + return getJavaImportPackage(referredType, isListAttr, conflictResolver);
251 case IDENTITYREF: 255 case IDENTITYREF:
252 //TODO:IDENTITYREF 256 //TODO:IDENTITYREF
253 break; 257 break;
254 case UNION: 258 case UNION:
255 return getUnionPackage(yangType, conflictResolver); 259 return getUnionPackage(yangType, conflictResolver);
256 case INSTANCE_IDENTIFIER: 260 case INSTANCE_IDENTIFIER:
257 - //TODO:INSTANCE_IDENTIFIER 261 + return JAVA_LANG;
258 - break;
259 case DERIVED: 262 case DERIVED:
260 return getTypDefsPackage(yangType, conflictResolver); 263 return getTypDefsPackage(yangType, conflictResolver);
261 default: 264 default:
...@@ -274,8 +277,8 @@ public final class AttributesJavaDataType { ...@@ -274,8 +277,8 @@ public final class AttributesJavaDataType {
274 case BINARY: 277 case BINARY:
275 return YANG_TYPES_PKG; 278 return YANG_TYPES_PKG;
276 case LEAFREF: 279 case LEAFREF:
277 - //TODO:LEAFREF 280 + YangType<?> referredType = getReferredTypeFromLeafref(yangType);
278 - break; 281 + return getJavaImportPackage(referredType, isListAttr, conflictResolver);
279 case IDENTITYREF: 282 case IDENTITYREF:
280 //TODO:IDENTITYREF 283 //TODO:IDENTITYREF
281 break; 284 break;
...@@ -284,8 +287,7 @@ public final class AttributesJavaDataType { ...@@ -284,8 +287,7 @@ public final class AttributesJavaDataType {
284 case UNION: 287 case UNION:
285 return getUnionPackage(yangType, conflictResolver); 288 return getUnionPackage(yangType, conflictResolver);
286 case INSTANCE_IDENTIFIER: 289 case INSTANCE_IDENTIFIER:
287 - //TODO:INSTANCE_IDENTIFIER 290 + return JAVA_LANG;
288 - break;
289 case DERIVED: 291 case DERIVED:
290 return getTypDefsPackage(yangType, conflictResolver); 292 return getTypDefsPackage(yangType, conflictResolver);
291 default: 293 default:
...@@ -444,4 +446,15 @@ public final class AttributesJavaDataType { ...@@ -444,4 +446,15 @@ public final class AttributesJavaDataType {
444 .getPackage())); 446 .getPackage()));
445 } 447 }
446 } 448 }
449 +
450 + /**
451 + * Returns the referred type from leaf/leaf-list.
452 + *
453 + * @param type current type in leaf
454 + * @return type from the leafref
455 + */
456 + private static YangType<?> getReferredTypeFromLeafref(YangType type) {
457 + YangLeafRef<?> leafRefInfo = (YangLeafRef<?>) type.getDataTypeExtendedInfo();
458 + return leafRefInfo.getEffectiveDataType();
459 + }
447 } 460 }
......
...@@ -18,8 +18,9 @@ package org.onosproject.yangutils.translator.tojava.utils; ...@@ -18,8 +18,9 @@ package org.onosproject.yangutils.translator.tojava.utils;
18 18
19 import java.util.List; 19 import java.util.List;
20 import java.util.Map; 20 import java.util.Map;
21 -import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes; 21 +
22 import org.onosproject.yangutils.datamodel.YangType; 22 import org.onosproject.yangutils.datamodel.YangType;
23 +import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
23 import org.onosproject.yangutils.translator.exception.TranslatorException; 24 import org.onosproject.yangutils.translator.exception.TranslatorException;
24 import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo; 25 import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
25 import org.onosproject.yangutils.utils.io.impl.JavaDocGen; 26 import org.onosproject.yangutils.utils.io.impl.JavaDocGen;
...@@ -118,6 +119,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTA ...@@ -118,6 +119,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTA
118 import static org.onosproject.yangutils.utils.UtilConstants.VALUE; 119 import static org.onosproject.yangutils.utils.UtilConstants.VALUE;
119 import static org.onosproject.yangutils.utils.UtilConstants.VOID; 120 import static org.onosproject.yangutils.utils.UtilConstants.VOID;
120 import static org.onosproject.yangutils.utils.UtilConstants.YANG_UTILS_TODO; 121 import static org.onosproject.yangutils.utils.UtilConstants.YANG_UTILS_TODO;
122 +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
121 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILD_METHOD; 123 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILD_METHOD;
122 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.CONSTRUCTOR; 124 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.CONSTRUCTOR;
123 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.DEFAULT_CONSTRUCTOR; 125 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.DEFAULT_CONSTRUCTOR;
...@@ -127,7 +129,6 @@ import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.MAN ...@@ -127,7 +129,6 @@ import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.MAN
127 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.OF_METHOD; 129 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.OF_METHOD;
128 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.SETTER_METHOD; 130 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.SETTER_METHOD;
129 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR; 131 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR;
130 -import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
131 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase; 132 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
132 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase; 133 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
133 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase; 134 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase;
......
...@@ -282,6 +282,16 @@ public final class UtilConstants { ...@@ -282,6 +282,16 @@ public final class UtilConstants {
282 public static final String INPUT = "input"; 282 public static final String INPUT = "input";
283 283
284 /** 284 /**
285 + * Static attribute for output string.
286 + */
287 + public static final String OUTPUT = "output";
288 +
289 + /**
290 + * Static attribute for current string.
291 + */
292 + public static final String CURRENT = "current";
293 +
294 + /**
285 * Static attribute for leafref string. 295 * Static attribute for leafref string.
286 */ 296 */
287 public static final String LEAFREF = "leafref"; 297 public static final String LEAFREF = "leafref";
...@@ -342,6 +352,41 @@ public final class UtilConstants { ...@@ -342,6 +352,41 @@ public final class UtilConstants {
342 public static final String COMMA = ","; 352 public static final String COMMA = ",";
343 353
344 /** 354 /**
355 + * Static attribute for slash character.
356 + */
357 + public static final char CHAR_OF_SLASH = '/';
358 +
359 + /**
360 + * Static attribute for open square bracket character.
361 + */
362 + public static final char CHAR_OF_OPEN_SQUARE_BRACKET = '[';
363 +
364 + /**
365 + * Static attribute for close square bracket character.
366 + */
367 + public static final char CHAR_OF_CLOSE_SQUARE_BRACKET = ']';
368 +
369 + /**
370 + * Static attribute for slash string.
371 + */
372 + public static final String SLASH_FOR_STRING = "/";
373 +
374 + /**
375 + * Static attribute for open square bracket.
376 + */
377 + public static final String OPEN_SQUARE_BRACKET = "[";
378 +
379 + /**
380 + * Static attribute for ancestor accessor.
381 + */
382 + public static final String ANCESTOR_ACCESSOR = "..";
383 +
384 + /**
385 + * Static attribute for ancestor accessor along with path.
386 + */
387 + public static final String ANCESTOR_ACCESSOR_IN_PATH = "../";
388 +
389 + /**
345 * Static attribute for add syntax. 390 * Static attribute for add syntax.
346 */ 391 */
347 public static final String ADD_STRING = "add"; 392 public static final String ADD_STRING = "add";
...@@ -1110,7 +1155,6 @@ public final class UtilConstants { ...@@ -1110,7 +1155,6 @@ public final class UtilConstants {
1110 */ 1155 */
1111 public static final String YANG_DECIMAL64_CLASS = "YangDecimal64"; 1156 public static final String YANG_DECIMAL64_CLASS = "YangDecimal64";
1112 1157
1113 -
1114 /** 1158 /**
1115 * Static attribute for YANG file error. 1159 * Static attribute for YANG file error.
1116 */ 1160 */
...@@ -1140,12 +1184,18 @@ public final class UtilConstants { ...@@ -1140,12 +1184,18 @@ public final class UtilConstants {
1140 + "grouping for given uses"; 1184 + "grouping for given uses";
1141 1185
1142 /** 1186 /**
1143 - * Static attribute for grouping linker error information. 1187 + * Static attribute for if-feature linker error information.
1144 */ 1188 */
1145 public static final String FEATURE_LINKER_ERROR = "YANG file error: Unable to find feature " 1189 public static final String FEATURE_LINKER_ERROR = "YANG file error: Unable to find feature "
1146 + "for given if-feature"; 1190 + "for given if-feature";
1147 1191
1148 /** 1192 /**
1193 + * Static attribute for leafref linker error information.
1194 + */
1195 + public static final String LEAFREF_LINKER_ERROR = "YANG file error: Unable to find base "
1196 + + "leaf/leaf-list for given leafref";
1197 +
1198 + /**
1149 * Static attribute for reference. 1199 * Static attribute for reference.
1150 */ 1200 */
1151 public static final String REFERENCE = "Reference"; 1201 public static final String REFERENCE = "Reference";
......
...@@ -534,7 +534,7 @@ package org.onosproject.yangutils.parser.antlrgencode; ...@@ -534,7 +534,7 @@ package org.onosproject.yangutils.parser.antlrgencode;
534 * require-instance-arg > 534 * require-instance-arg >
535 * require-instance-arg = true-keyword / false-keyword 535 * require-instance-arg = true-keyword / false-keyword
536 */ 536 */
537 - requireInstanceStatement : REQUIRE_INSTANCE_KEYWORD (TRUE_KEYWORD | FALSE_KEYWORD) STMTEND; 537 + requireInstanceStatement : REQUIRE_INSTANCE_KEYWORD requireInstance STMTEND;
538 538
539 /** 539 /**
540 * instance-identifier-specification = 540 * instance-identifier-specification =
...@@ -1279,6 +1279,8 @@ package org.onosproject.yangutils.parser.antlrgencode; ...@@ -1279,6 +1279,8 @@ package org.onosproject.yangutils.parser.antlrgencode;
1279 1279
1280 refine : string; 1280 refine : string;
1281 1281
1282 + requireInstance : string;
1283 +
1282 augment : string; 1284 augment : string;
1283 1285
1284 deviation : string; 1286 deviation : string;
......
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 +import java.io.IOException;
20 +import java.util.ListIterator;
21 +
22 +import org.junit.Rule;
23 +import org.junit.Test;
24 +import org.junit.rules.ExpectedException;
25 +
26 +import org.onosproject.yangutils.datamodel.YangContainer;
27 +import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
28 +import org.onosproject.yangutils.datamodel.YangLeaf;
29 +import org.onosproject.yangutils.datamodel.YangLeafRef;
30 +import org.onosproject.yangutils.datamodel.YangModule;
31 +import org.onosproject.yangutils.datamodel.YangNode;
32 +import org.onosproject.yangutils.datamodel.YangNodeType;
33 +import org.onosproject.yangutils.datamodel.YangType;
34 +import org.onosproject.yangutils.parser.exceptions.ParserException;
35 +import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
36 +
37 +import static org.hamcrest.MatcherAssert.assertThat;
38 +import static org.hamcrest.core.Is.is;
39 +/**
40 + * Test cases for require-instance listener.
41 + */
42 +public class RequireInstanceListenerTest {
43 +
44 + @Rule
45 + public ExpectedException thrown = ExpectedException.none();
46 +
47 + private final YangUtilsParserManager manager = new YangUtilsParserManager();
48 +
49 + /**
50 + * Checks require-statement with true as status.
51 + */
52 + @Test
53 + public void processRequireInstanceTrue() throws IOException, ParserException {
54 +
55 + YangNode node = manager.getDataModel("src/test/resources/RequireInstanceTrue.yang");
56 +
57 + // Check whether the data model tree returned is of type module.
58 + assertThat((node instanceof YangModule), is(true));
59 +
60 + // Check whether the node type is set properly to module.
61 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
62 +
63 + // Check whether the module name is set correctly.
64 + YangModule yangNode = (YangModule) node;
65 + assertThat(yangNode.getName(), is("PathListener"));
66 +
67 + YangContainer container = (YangContainer) yangNode.getChild().getNextSibling();
68 + ListIterator<YangLeaf> leafIterator = container.getListOfLeaf().listIterator();
69 + YangLeaf leafInfo = leafIterator.next();
70 +
71 + // Check whether the require-instance value is set correctly in leafref.
72 + assertThat(leafInfo.getName(), is("ifname"));
73 + YangLeafRef yangLeafRef = (YangLeafRef) leafInfo.getDataType().getDataTypeExtendedInfo();
74 + assertThat(yangLeafRef.getRequireInstance(), is(true));
75 + }
76 +
77 + /**
78 + * Checks require-statement with false as status.
79 + */
80 + @Test
81 + public void processRequireInstanceFalse() throws IOException, ParserException {
82 +
83 + YangNode node = manager.getDataModel("src/test/resources/RequireInstanceFalse.yang");
84 +
85 + // Check whether the data model tree returned is of type module.
86 + assertThat((node instanceof YangModule), is(true));
87 +
88 + // Check whether the node type is set properly to module.
89 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
90 +
91 + // Check whether the module name is set correctly.
92 + YangModule yangNode = (YangModule) node;
93 + assertThat(yangNode.getName(), is("PathListener"));
94 +
95 + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
96 + YangLeaf leafInfo = leafIterator.next();
97 +
98 + // Check whether the require-instance value is set correctly in instance-identifier.
99 + assertThat(leafInfo.getName(), is("admin-status"));
100 +
101 + YangType type = leafInfo.getDataType();
102 +
103 + assertThat(type.getDataType(), is(YangDataTypes.INSTANCE_IDENTIFIER));
104 + boolean status = ((YangType<Boolean>) type).getDataTypeExtendedInfo();
105 +
106 + assertThat(status, is(false));
107 + }
108 +
109 + /**
110 + * Checks require-statement default value when its not there in YANG under instance-identifier.
111 + */
112 + @Test
113 + public void processRequireInstanceDefaultValueInInstanceIdentifier() throws IOException, ParserException {
114 +
115 + YangNode node = manager.getDataModel("src/test/resources/RequireInstanceDefaultValueInInstanceIdentifier.yang");
116 +
117 + // Check whether the data model tree returned is of type module.
118 + assertThat((node instanceof YangModule), is(true));
119 +
120 + // Check whether the node type is set properly to module.
121 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
122 +
123 + // Check whether the module name is set correctly.
124 + YangModule yangNode = (YangModule) node;
125 + assertThat(yangNode.getName(), is("PathListener"));
126 +
127 + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
128 + YangLeaf leafInfo = leafIterator.next();
129 +
130 + // Check whether the require-instance value is set correctly in instance-identifier.
131 + assertThat(leafInfo.getName(), is("admin-status"));
132 +
133 + YangType type = leafInfo.getDataType();
134 +
135 + assertThat(type.getDataType(), is(YangDataTypes.INSTANCE_IDENTIFIER));
136 +
137 + boolean status = ((YangType<Boolean>) type).getDataTypeExtendedInfo();
138 + assertThat(status, is(true));
139 + }
140 +
141 + /**
142 + * Checks require-statement default value when its not there in YANG under leafref.
143 + */
144 + @Test
145 + public void processRequireInstanceDefaultValueForLeafref() throws IOException, ParserException {
146 +
147 + YangNode node = manager.getDataModel("src/test/resources/RequireInstanceDefaultValueForLeafref.yang");
148 +
149 + // Check whether the data model tree returned is of type module.
150 + assertThat((node instanceof YangModule), is(true));
151 +
152 + // Check whether the node type is set properly to module.
153 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
154 +
155 + // Check whether the module name is set correctly.
156 + YangModule yangNode = (YangModule) node;
157 + assertThat(yangNode.getName(), is("PathListener"));
158 +
159 + YangContainer container = (YangContainer) yangNode.getChild().getNextSibling();
160 + ListIterator<YangLeaf> leafIterator = container.getListOfLeaf().listIterator();
161 + YangLeaf leafInfo = leafIterator.next();
162 +
163 + // Check whether the require-instance value is set correctly in leafref.
164 + assertThat(leafInfo.getName(), is("ifname"));
165 + YangLeafRef yangLeafRef = (YangLeafRef) leafInfo.getDataType().getDataTypeExtendedInfo();
166 + assertThat(yangLeafRef.getRequireInstance(), is(true));
167 + }
168 +}
...@@ -20,6 +20,7 @@ import java.util.ListIterator; ...@@ -20,6 +20,7 @@ import java.util.ListIterator;
20 import org.junit.Rule; 20 import org.junit.Rule;
21 import org.junit.Test; 21 import org.junit.Test;
22 import org.junit.rules.ExpectedException; 22 import org.junit.rules.ExpectedException;
23 +import org.onosproject.yangutils.datamodel.YangContainer;
23 import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes; 24 import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
24 import org.onosproject.yangutils.datamodel.YangLeaf; 25 import org.onosproject.yangutils.datamodel.YangLeaf;
25 import org.onosproject.yangutils.datamodel.YangLeafList; 26 import org.onosproject.yangutils.datamodel.YangLeafList;
...@@ -121,20 +122,6 @@ public class TypeListenerTest { ...@@ -121,20 +122,6 @@ public class TypeListenerTest {
121 } 122 }
122 123
123 /** 124 /**
124 - * Checks for unsupported type leafref.
125 - */
126 - @Test
127 - public void processLeafrefType() throws IOException, ParserException {
128 -
129 - thrown.expect(ParserException.class);
130 - thrown.expectMessage("YANG file error : \"leafref\" is not supported in current version,"
131 - + " please check wiki for YANG utils road map.");
132 -
133 - YangNode node = manager
134 - .getDataModel("src/test/resources/LeafrefInvalidIdentifier.yang");
135 - }
136 -
137 - /**
138 * Checks for unsupported type identityref. 125 * Checks for unsupported type identityref.
139 */ 126 */
140 @Test 127 @Test
...@@ -149,16 +136,29 @@ public class TypeListenerTest { ...@@ -149,16 +136,29 @@ public class TypeListenerTest {
149 } 136 }
150 137
151 /** 138 /**
152 - * Checks for unsupported type instance identifier. 139 + * Checks for type instance-identifier.
153 */ 140 */
154 @Test 141 @Test
155 public void processInstanceIdentifierType() throws IOException, ParserException { 142 public void processInstanceIdentifierType() throws IOException, ParserException {
156 143
157 - thrown.expect(ParserException.class);
158 - thrown.expectMessage("YANG file error : \"instance-identifier\" is not supported in current version,"
159 - + " please check wiki for YANG utils road map.");
160 -
161 YangNode node = manager 144 YangNode node = manager
162 - .getDataModel("src/test/resources/InstanceIdentifierInvalidIdentifier.yang"); 145 + .getDataModel("src/test/resources/InstanceIdentifierListener.yang");
146 +
147 + // Check whether the data model tree returned is of type module.
148 + assertThat((node instanceof YangModule), is(true));
149 +
150 + // Check whether the node type is set properly to module.
151 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
152 +
153 + // Check whether the module name is set correctly.
154 + YangModule yangNode = (YangModule) node;
155 + assertThat(yangNode.getName(), is("Test"));
156 + YangContainer container = (YangContainer) yangNode.getChild();
157 + ListIterator<YangLeaf> leafIterator = container.getListOfLeaf().listIterator();
158 + YangLeaf leafInfo = leafIterator.next();
159 +
160 + assertThat(leafInfo.getName(), is("invalid-interval"));
161 + assertThat(leafInfo.getDataType().getDataTypeName(), is("instance-identifier"));
162 + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.INSTANCE_IDENTIFIER));
163 } 163 }
164 } 164 }
......
...@@ -18,11 +18,15 @@ package org.onosproject.yangutils.plugin.manager; ...@@ -18,11 +18,15 @@ package org.onosproject.yangutils.plugin.manager;
18 18
19 import java.io.IOException; 19 import java.io.IOException;
20 import java.util.List; 20 import java.util.List;
21 +import java.util.ListIterator;
22 +
21 import org.junit.Test; 23 import org.junit.Test;
22 import org.onosproject.yangutils.datamodel.YangContainer; 24 import org.onosproject.yangutils.datamodel.YangContainer;
25 +import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
23 import org.onosproject.yangutils.datamodel.YangFeature; 26 import org.onosproject.yangutils.datamodel.YangFeature;
24 import org.onosproject.yangutils.datamodel.YangIfFeature; 27 import org.onosproject.yangutils.datamodel.YangIfFeature;
25 import org.onosproject.yangutils.datamodel.YangLeaf; 28 import org.onosproject.yangutils.datamodel.YangLeaf;
29 +import org.onosproject.yangutils.datamodel.YangLeafRef;
26 import org.onosproject.yangutils.datamodel.YangModule; 30 import org.onosproject.yangutils.datamodel.YangModule;
27 import org.onosproject.yangutils.datamodel.YangNode; 31 import org.onosproject.yangutils.datamodel.YangNode;
28 import org.onosproject.yangutils.datamodel.YangNodeType; 32 import org.onosproject.yangutils.datamodel.YangNodeType;
...@@ -217,4 +221,111 @@ public class IntraFileIfFeatureLinkingTest { ...@@ -217,4 +221,111 @@ public class IntraFileIfFeatureLinkingTest {
217 assertThat(ifFeature.getName().getName(), is("local-storage")); 221 assertThat(ifFeature.getName().getName(), is("local-storage"));
218 assertThat(ifFeature.getResolvableStatus(), is(ResolvableStatus.RESOLVED)); 222 assertThat(ifFeature.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
219 } 223 }
224 +
225 + /**
226 + * Checks addition of if-feature list to leafref.
227 + */
228 + @Test
229 + public void processSelfFileLinkingWithFeatureReferredByLeafref()
230 + throws IOException, ParserException {
231 +
232 + YangNode node = manager
233 + .getDataModel("src/test/resources/SelfFileLinkingWithFeatureReferredByLeafref.yang");
234 +
235 + // Check whether the data model tree returned is of type module.
236 + assertThat((node instanceof YangModule), is(true));
237 +
238 + // Check whether the node type is set properly to module.
239 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
240 +
241 + // Check whether the module name is set correctly.
242 + YangModule yangNode = (YangModule) node;
243 + assertThat(yangNode.getName(), is("syslog"));
244 +
245 + List<YangFeature> featureList = yangNode.getFeatureList();
246 + YangFeature feature = featureList.iterator().next();
247 + assertThat(feature.getName(), is("local-storage"));
248 +
249 + YangContainer container = (YangContainer) yangNode.getChild();
250 + assertThat(container.getName(), is("speed"));
251 +
252 + List<YangLeaf> listOfLeaf = container.getListOfLeaf();
253 + YangLeaf leaf = listOfLeaf.iterator().next();
254 + assertThat(leaf.getName(), is("local-storage-limit"));
255 +
256 + List<YangIfFeature> ifFeatureList = leaf.getIfFeatureList();
257 + YangIfFeature ifFeature = ifFeatureList.iterator().next();
258 + assertThat(ifFeature.getName().getName(), is("local-storage"));
259 + assertThat(ifFeature.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
260 +
261 + ListIterator<YangLeaf> listOfLeafInModule = yangNode.getListOfLeaf().listIterator();
262 + YangLeaf yangLeaf = listOfLeafInModule.next();
263 + assertThat(yangLeaf.getName(), is("storage-value"));
264 +
265 + YangLeafRef leafRef = (YangLeafRef) yangLeaf.getDataType().getDataTypeExtendedInfo();
266 +
267 + assertThat(leafRef.getEffectiveDataType().getDataType(), is(YangDataTypes.UINT64));
268 +
269 + List<YangIfFeature> ifFeatureListInLeafref = leafRef.getIfFeatureList();
270 + YangIfFeature ifFeatureInLeafref = ifFeatureListInLeafref.iterator().next();
271 + assertThat(ifFeatureInLeafref.getName().getName(), is("local-storage"));
272 + assertThat(ifFeatureInLeafref.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
273 + }
274 +
275 + /**
276 + * Checks addition of if-feature list to leafref when referred leaf is again having leafref in it.
277 + */
278 + @Test
279 + public void processSelfFileLinkingWithFeatureReferredByMultiLeafref()
280 + throws IOException, ParserException {
281 +
282 + YangNode node = manager
283 + .getDataModel("src/test/resources/SelfFileLinkingWithFeatureReferredByMultiLeafref.yang");
284 +
285 + // Check whether the data model tree returned is of type module.
286 + assertThat((node instanceof YangModule), is(true));
287 +
288 + // Check whether the node type is set properly to module.
289 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
290 +
291 + // Check whether the module name is set correctly.
292 + YangModule yangNode = (YangModule) node;
293 + assertThat(yangNode.getName(), is("syslog"));
294 +
295 + List<YangFeature> featureList = yangNode.getFeatureList();
296 + YangFeature feature = featureList.iterator().next();
297 + assertThat(feature.getName(), is("local-storage"));
298 +
299 + YangContainer container = (YangContainer) yangNode.getChild();
300 + assertThat(container.getName(), is("speed"));
301 +
302 + List<YangLeaf> listOfLeaf = container.getListOfLeaf();
303 + YangLeaf leaf = listOfLeaf.iterator().next();
304 + assertThat(leaf.getName(), is("local-storage-limit"));
305 +
306 + List<YangIfFeature> ifFeatureList = leaf.getIfFeatureList();
307 + YangIfFeature ifFeature = ifFeatureList.iterator().next();
308 + assertThat(ifFeature.getName().getName(), is("local-storage"));
309 + assertThat(ifFeature.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
310 +
311 + ListIterator<YangLeaf> listOfLeafInModule = yangNode.getListOfLeaf().listIterator();
312 + YangLeaf yangLeaf = listOfLeafInModule.next();
313 + assertThat(yangLeaf.getName(), is("storage-value"));
314 +
315 + YangLeafRef leafRef = (YangLeafRef) yangLeaf.getDataType().getDataTypeExtendedInfo();
316 +
317 + assertThat(leafRef.getEffectiveDataType().getDataType(), is(YangDataTypes.UINT64));
318 +
319 + List<YangIfFeature> ifFeatureListInLeafref = leafRef.getIfFeatureList();
320 + YangIfFeature ifFeatureInLeafref = ifFeatureListInLeafref.iterator().next();
321 +
322 + assertThat(ifFeatureInLeafref.getName().getName(), is("main-storage"));
323 + assertThat(ifFeatureInLeafref.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
324 +
325 + YangIfFeature ifFeatureInLeafref1 = ifFeatureListInLeafref.iterator().next();
326 +
327 + assertThat(ifFeatureInLeafref1.getName().getName(), is("main-storage"));
328 + assertThat(ifFeatureInLeafref1.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
329 +
330 + }
220 } 331 }
......
1 +module PathListener {
2 + namespace "test";
3 + prefix test;
4 + list interface {
5 + key "name";
6 + leaf name {
7 + type string;
8 + }
9 + leaf admin-status {
10 + type string;
11 + }
12 + list address {
13 + key "ip";
14 + leaf ip {
15 + type string;
16 + }
17 + }
18 + }
19 + container default-address {
20 + leaf ifname {
21 + type leafref {
22 + path "../../test:interface/test:name";
23 + }
24 + }
25 + leaf status {
26 + type leafref {
27 + path "/test:interface[name = current()/../ifname]/test:admin-status";
28 + }
29 + }
30 + }
31 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module PathListener {
2 + namespace "test";
3 + prefix test;
4 + list interface {
5 + key "name";
6 + leaf name {
7 + type string;
8 + }
9 + leaf admin-status {
10 + type string;
11 + }
12 + list address {
13 + key "ip";
14 + leaf ip {
15 + type string;
16 + }
17 + }
18 + }
19 + container default-address {
20 + leaf ifname {
21 + type leafref {
22 + path "../../test:interface/test:name";
23 + }
24 + }
25 + leaf status {
26 + type leafref {
27 + path "/test:interface[name = current()/../ifname]/test:admin-status";
28 + }
29 + }
30 + }
31 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module PathListener {
2 + namespace "test";
3 + prefix test;
4 + leaf admin-status {
5 + type instance-identifier;
6 + }
7 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module PathListener {
2 + namespace "test";
3 + prefix test;
4 + leaf admin-status {
5 + type instance-identifier {
6 + require-instance "false";
7 + }
8 + }
9 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module PathListener {
2 + namespace "test";
3 + prefix test;
4 + list interface {
5 + key "name";
6 + leaf name {
7 + type string;
8 + }
9 + leaf admin-status {
10 + type string;
11 + }
12 + list address {
13 + key "ip";
14 + leaf ip {
15 + type string;
16 + }
17 + }
18 + }
19 + container default-address {
20 + leaf ifname {
21 + type leafref {
22 + path "../../test:interface/test:name";
23 + require-instance true;
24 + }
25 + }
26 + leaf status {
27 + type leafref {
28 + path "/test:interface[name = current()/../ifname]/test:admin-status";
29 + }
30 + }
31 + }
32 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module syslog {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix "sys";
5 + feature local-storage {
6 + description
7 + "This feature means the device supports local
8 + storage (memory, flash or disk) that can be used to
9 + store syslog messages.";
10 + }
11 +
12 + container speed {
13 + leaf local-storage-limit {
14 + if-feature local-storage;
15 + type uint64;
16 + units "kilobyte";
17 + config false;
18 + description
19 + "The amount of local storage that can be
20 + used to hold syslog messages.";
21 + }
22 + }
23 + leaf storage-value {
24 + type leafref {
25 + path "/speed/local-storage-limit";
26 + }
27 + }
28 +}
1 +module syslog {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix "sys";
5 + feature local-storage {
6 + description
7 + "This feature means the device supports local
8 + storage (memory, flash or disk) that can be used to
9 + store syslog messages.";
10 + }
11 + feature main-storage {
12 + description
13 + "This feature means the device supports main
14 + storage that can be used to
15 + store syslog messages.";
16 + }
17 +
18 + container speed {
19 + leaf local-storage-limit {
20 + if-feature local-storage;
21 + type leafref {
22 + path "/value";
23 + }
24 + units "kilobyte";
25 + config false;
26 + description
27 + "The amount of local storage that can be
28 + used to hold syslog messages.";
29 + }
30 + }
31 + leaf storage-value {
32 + type leafref {
33 + path "/speed/local-storage-limit";
34 + }
35 + }
36 + leaf value {
37 + if-feature main-storage;
38 + type uint64;
39 + }
40 +}
1 +module ietf-network {
2 + yang-version 1;
3 + namespace "urn:ietf:params:xml:ns:yang:ietf-network";
4 + prefix nd;
5 + container networks {
6 + description
7 + "Serves as top-level container for a list of networks.";
8 + leaf network-id {
9 + type status;
10 + description
11 + "Identifies a network.";
12 + }
13 + }
14 + typedef status {
15 + type uint8;
16 + }
17 + leaf network-ref {
18 + type leafref {
19 + path "/networks";
20 + }
21 + }
22 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module ietf-network {
2 + yang-version 1;
3 + namespace "urn:ietf:params:xml:ns:yang:ietf-network";
4 + prefix nd;
5 + container networks {
6 + description
7 + "Serves as top-level container for a list of networks.";
8 + leaf network-id {
9 + type uint8;
10 + description
11 + "Identifies a network.";
12 + }
13 + }
14 + leaf-list network-ref {
15 + type leafref;
16 + }
17 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module ietf-network {
2 + yang-version 1;
3 + namespace "urn:ietf:params:xml:ns:yang:ietf-network";
4 + prefix nd;
5 + rpc networks {
6 + description
7 + "Serves as top-level container for a list of networks.";
8 + grouping input {
9 + leaf network-id {
10 + type string;
11 + description
12 + "Identifies a network.";
13 + }
14 + }
15 + input {
16 + leaf network-id {
17 + type uint8;
18 + description
19 + "Identifies a network.";
20 + }
21 + }
22 + output {
23 + }
24 + }
25 + leaf network-ref {
26 + type leafref {
27 + path "/networks/input/network-id";
28 + }
29 + }
30 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module ietf-network {
2 + yang-version 1;
3 + namespace "urn:ietf:params:xml:ns:yang:ietf-network";
4 + prefix nd;
5 + grouping networks {
6 + leaf network-id {
7 + type uint8;
8 + description
9 + "Identifies a network.";
10 + }
11 + }
12 + container current {
13 + leaf network-ref {
14 + type leafref {
15 + path "/networks/network-id";
16 + }
17 + }
18 + }
19 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module ietf-network {
2 + yang-version 1;
3 + namespace "urn:ietf:params:xml:ns:yang:ietf-network";
4 + prefix nd;
5 + rpc networks {
6 + description
7 + "Serves as top-level container for a list of networks.";
8 + grouping input {
9 + leaf network-id {
10 + type string;
11 + description
12 + "Identifies a network.";
13 + }
14 + }
15 + input {
16 + leaf network-id {
17 + type uint8;
18 + description
19 + "Identifies a network.";
20 + }
21 + }
22 + }
23 + leaf network-ref {
24 + type leafref {
25 + path "/networks/input/network-id";
26 + }
27 + }
28 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module ietf-network {
2 + yang-version 1;
3 + namespace "urn:ietf:params:xml:ns:yang:ietf-network";
4 + prefix nd;
5 + rpc networks {
6 + description
7 + "Serves as top-level container for a list of networks.";
8 + grouping input {
9 + leaf network-id {
10 + type string;
11 + description
12 + "Identifies a network.";
13 + }
14 + }
15 + input {
16 + leaf network-id {
17 + type uint8;
18 + description
19 + "Identifies a network.";
20 + }
21 + }
22 + }
23 + leaf network-ref {
24 + type leafref {
25 + path "../networks/input/network-id";
26 + }
27 + }
28 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module ietf-network {
2 + yang-version 1;
3 + namespace "urn:ietf:params:xml:ns:yang:ietf-network";
4 + prefix nd;
5 + container networks {
6 + description
7 + "Serves as top-level container for a list of networks.";
8 + leaf network-id {
9 + type uint8;
10 + description
11 + "Identifies a network.";
12 + }
13 + }
14 + leaf network-ref {
15 + type leafref {
16 + path "/define/network-id";
17 + }
18 + }
19 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module ietf-network {
2 + yang-version 1;
3 + namespace "urn:ietf:params:xml:ns:yang:ietf-network";
4 + prefix nd;
5 + container networks {
6 + description
7 + "Serves as top-level container for a list of networks.";
8 + leaf network-id {
9 + type uint8;
10 + description
11 + "Identifies a network.";
12 + }
13 + }
14 + leaf network-ref {
15 + type leafref {
16 + path "../define/network-id";
17 + }
18 + }
19 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module ietf-network {
2 + yang-version 1;
3 + namespace "urn:ietf:params:xml:ns:yang:ietf-network";
4 + prefix nd;
5 + container networks {
6 + description
7 + "Serves as top-level container for a list of networks.";
8 + leaf network-id {
9 + type uint8;
10 + description
11 + "Identifies a network.";
12 + }
13 + }
14 + leaf network-ref {
15 + type leafref {
16 + path "../../../define/network-id";
17 + }
18 + }
19 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module ietf-network {
2 + yang-version 1;
3 + namespace "urn:ietf:params:xml:ns:yang:ietf-network";
4 + prefix nd;
5 + rpc networks {
6 + description
7 + "Serves as top-level container for a list of networks.";
8 + input {
9 + leaf network-id {
10 + type uint8;
11 + description
12 + "Identifies a network.";
13 + }
14 + }
15 + output {
16 + }
17 + }
18 + leaf network-ref {
19 + type leafref {
20 + path "/networks/input/network-id";
21 + }
22 + }
23 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module ietf-network {
2 + yang-version 1;
3 + namespace "urn:ietf:params:xml:ns:yang:ietf-network";
4 + prefix nd;
5 + rpc networks {
6 + description
7 + "Serves as top-level container for a list of networks.";
8 + input {
9 + leaf-list network-id {
10 + type uint8;
11 + description
12 + "Identifies a network.";
13 + }
14 + }
15 + output {
16 + }
17 + }
18 + leaf-list network-ref {
19 + type leafref {
20 + path "/networks/input/network-id";
21 + }
22 + }
23 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + list valid {
6 + key "define";
7 + leaf define {
8 + type string;
9 + }
10 + container standard {
11 + typedef node {
12 + type leafref {
13 + path "/invalid-interval";
14 + }
15 + }
16 + container present {
17 + typedef name {
18 + type node;
19 + }
20 + leaf interval {
21 + type name;
22 + }
23 + }
24 + }
25 + }
26 + leaf-list invalid-interval {
27 + type enumeration {
28 + enum 10m;
29 + enum 100m;
30 + enum auto;
31 + }
32 + }
33 +}
1 +module ietf-network {
2 + yang-version 1;
3 + namespace "urn:ietf:params:xml:ns:yang:ietf-network";
4 + prefix nd;
5 + rpc networks {
6 + description
7 + "Serves as top-level container for a list of networks.";
8 + input {
9 + leaf-list network-id {
10 + type network-ref;
11 + description
12 + "Identifies a network.";
13 + }
14 + leaf id {
15 + type uint8;
16 + }
17 + }
18 + output {
19 + }
20 + }
21 + typedef network-ref {
22 + type leafref {
23 + path "/networks/input/id";
24 + }
25 + }
26 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module ietf-network {
2 + yang-version 1;
3 + namespace "urn:ietf:params:xml:ns:yang:ietf-network";
4 + prefix nd;
5 + container networks {
6 + description
7 + "Serves as top-level container for a list of networks.";
8 + leaf network-id {
9 + type network-ref;
10 + description
11 + "Identifies a network.";
12 + }
13 + leaf id {
14 + type uint8;
15 + }
16 + }
17 + typedef network-ref {
18 + type leafref {
19 + path "/networks/id";
20 + }
21 + }
22 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module ietf-network {
2 + yang-version 1;
3 + namespace "urn:ietf:params:xml:ns:yang:ietf-network";
4 + prefix nd;
5 + container networks {
6 + description
7 + "Serves as top-level container for a list of networks.";
8 + leaf network-id {
9 + type network-ref;
10 + description
11 + "Identifies a network.";
12 + }
13 + leaf id {
14 + type uint8;
15 + }
16 + }
17 + typedef network-ref {
18 + type leafref {
19 + path "../id";
20 + }
21 + }
22 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + list valid {
6 + key "define";
7 + leaf define {
8 + type string;
9 + }
10 + container standard {
11 + container present {
12 + leaf name {
13 + type leafref {
14 + path "/invalid-interval";
15 + }
16 + }
17 + }
18 + }
19 + }
20 + leaf invalid-interval {
21 + type union {
22 + type int32;
23 + type enumeration {
24 + enum "unbounded";
25 + }
26 + }
27 + }
28 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + list valid {
6 + key "define";
7 + leaf define {
8 + type string;
9 + }
10 + container standard {
11 + container present {
12 + leaf-list name {
13 + type leafref {
14 + path "/invalid-interval";
15 + }
16 + }
17 + }
18 + }
19 + }
20 + leaf-list invalid-interval {
21 + type enumeration {
22 + enum 10m;
23 + enum 100m;
24 + enum auto;
25 + }
26 + }
27 +}
1 +module ietf-network {
2 + yang-version 1;
3 + namespace "urn:ietf:params:xml:ns:yang:ietf-network";
4 + prefix nd;
5 + container networks {
6 + description
7 + "Serves as top-level container for a list of networks.";
8 + leaf network-id {
9 + type status;
10 + description
11 + "Identifies a network.";
12 + }
13 + }
14 + typedef status {
15 + type uint8;
16 + }
17 + leaf network-ref {
18 + type leafref {
19 + path "/networks/network-id";
20 + }
21 + }
22 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module ietf-network {
2 + yang-version 1;
3 + namespace "urn:ietf:params:xml:ns:yang:ietf-network";
4 + prefix nd;
5 + container networks {
6 + description
7 + "Serves as top-level container for a list of networks.";
8 + leaf network-id {
9 + type leafref {
10 + path "/status/current";
11 + }
12 + description
13 + "Identifies a network.";
14 + }
15 + }
16 + container status {
17 + leaf current {
18 + type uint8;
19 + }
20 + }
21 + leaf network-ref {
22 + type leafref {
23 + path "/networks/network-id";
24 + }
25 + }
26 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module ietf-network {
2 + yang-version 1;
3 + namespace "urn:ietf:params:xml:ns:yang:ietf-network";
4 + prefix nd;
5 + container networks {
6 + description
7 + "Serves as top-level container for a list of networks.";
8 + leaf network-id {
9 + type uint8;
10 + description
11 + "Identifies a network.";
12 + }
13 + }
14 + leaf network-ref {
15 + type leafref {
16 + path "/networks/network-id";
17 + }
18 + }
19 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module ietf-network {
2 + yang-version 1;
3 + namespace "urn:ietf:params:xml:ns:yang:ietf-network";
4 + prefix nd;
5 + container networks {
6 + description
7 + "Serves as top-level container for a list of networks.";
8 + leaf network-id {
9 + type uint8;
10 + description
11 + "Identifies a network.";
12 + }
13 + }
14 + leaf-list network-ref {
15 + type leafref {
16 + path "/networks/network-id";
17 + }
18 + }
19 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module ietf-network {
2 + yang-version 1;
3 + namespace "urn:ietf:params:xml:ns:yang:ietf-network";
4 + prefix nd;
5 + container networks {
6 + description
7 + "Serves as top-level container for a list of networks.";
8 + leaf network-id {
9 + type uint8;
10 + description
11 + "Identifies a network.";
12 + }
13 + }
14 + leaf network-ref {
15 + type leafref {
16 + path "../networks/network-id";
17 + }
18 + }
19 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + list valid {
6 + key "define";
7 + leaf define {
8 + type string;
9 + }
10 + container standard {
11 + container present {
12 + leaf-list name {
13 + type transmitter;
14 + }
15 + }
16 + }
17 + }
18 + container reference {
19 + list found {
20 + key "define";
21 + leaf define {
22 + type string;
23 + }
24 + container reciever {
25 + leaf remove {
26 + type leafref {
27 + path "/valid/standard/present/name";
28 + }
29 + }
30 + }
31 + }
32 + }
33 + typedef transmitter {
34 + type leafref {
35 + path "/invalid-interval";
36 + }
37 + }
38 + leaf invalid-interval {
39 + type enumeration {
40 + enum 10m;
41 + enum 100m;
42 + enum auto;
43 + }
44 + }
45 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + list valid {
6 + key "define";
7 + leaf define {
8 + type string;
9 + }
10 + container standard {
11 + container present {
12 + leaf-list name {
13 + type transmitter;
14 + }
15 + }
16 + }
17 + }
18 + container reference {
19 + list found {
20 + key "define";
21 + leaf define {
22 + type string;
23 + }
24 + container reciever {
25 + leaf remove {
26 + type leafref {
27 + path "../../../../valid/standard/present/name";
28 + }
29 + }
30 + }
31 + }
32 + }
33 + typedef transmitter {
34 + type leafref {
35 + path "../../../../invalid-interval";
36 + }
37 + }
38 + leaf invalid-interval {
39 + type enumeration {
40 + enum 10m;
41 + enum 100m;
42 + enum auto;
43 + }
44 + }
45 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + list valid {
6 + key "define";
7 + leaf define {
8 + type string;
9 + }
10 + container standard {
11 + container present {
12 + leaf-list name {
13 + type leafref {
14 + path "/transmitter/send";
15 + }
16 + }
17 + }
18 + }
19 + }
20 + container reference {
21 + list found {
22 + key "define";
23 + leaf define {
24 + type string;
25 + }
26 + container reciever {
27 + leaf remove {
28 + type leafref {
29 + path "/valid/standard/present/name";
30 + }
31 + }
32 + }
33 + }
34 + }
35 + list transmitter {
36 + key "send";
37 + leaf send {
38 + type leafref {
39 + path "/invalid-interval";
40 + }
41 + }
42 + }
43 + leaf-list invalid-interval {
44 + type enumeration {
45 + enum 10m;
46 + enum 100m;
47 + enum auto;
48 + }
49 + }
50 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + list valid {
6 + key "define";
7 + leaf define {
8 + type string;
9 + }
10 + container standard {
11 + container present {
12 + leaf-list name {
13 + type leafref {
14 + path "../../../../transmitter/send";
15 + }
16 + }
17 + }
18 + }
19 + }
20 + container reference {
21 + list found {
22 + key "define";
23 + leaf define {
24 + type string;
25 + }
26 + container reciever {
27 + leaf remove {
28 + type leafref {
29 + path "../../../../valid/standard/present/name";
30 + }
31 + }
32 + }
33 + }
34 + }
35 + list transmitter {
36 + key "send";
37 + leaf send {
38 + type leafref {
39 + path "../../invalid-interval";
40 + }
41 + }
42 + }
43 + leaf-list invalid-interval {
44 + type enumeration {
45 + enum 10m;
46 + enum 100m;
47 + enum auto;
48 + }
49 + }
50 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + list valid {
6 + key "define";
7 + leaf define {
8 + type string;
9 + }
10 + container standard {
11 + container present {
12 + leaf-list name {
13 + type transmitter;
14 + }
15 + }
16 + }
17 + }
18 + container reference {
19 + list found {
20 + key "define";
21 + leaf define {
22 + type string;
23 + }
24 + container reciever {
25 + leaf remove {
26 + type leafref {
27 + path "/valid/standard/present/name";
28 + }
29 + }
30 + }
31 + }
32 + }
33 + typedef transmitter {
34 + type invalid-interval;
35 + }
36 + typedef invalid-interval {
37 + type enumeration {
38 + enum 10m;
39 + enum 100m;
40 + enum auto;
41 + }
42 + }
43 +}
1 +module ietf-network {
2 + yang-version 1;
3 + namespace "urn:ietf:params:xml:ns:yang:ietf-network";
4 + prefix nd;
5 + container networks {
6 + description
7 + "Serves as top-level container for a list of networks.";
8 + leaf network-id {
9 + type uint8;
10 + description
11 + "Identifies a network.";
12 + }
13 + }
14 + leaf network-ref {
15 + type leafref {
16 + path "/define/network-id";
17 + }
18 + }
19 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module module1 {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + import module2 {
6 + prefix p;
7 + }
8 + leaf invalid-interval {
9 + type leafref {
10 + path "/p:hello";
11 + }
12 + }
13 + leaf hello {
14 + type string;
15 + }
16 +}
...\ No newline at end of file ...\ No newline at end of file
1 -module Test { 1 +module module2 {
2 yang-version 1; 2 yang-version 1;
3 namespace http://huawei.com; 3 namespace http://huawei.com;
4 - prefix Ant; 4 + prefix Ant2;
5 - leaf-list invalid-interval { 5 + leaf hello {
6 - type leafref; 6 + type string;
7 } 7 }
8 } 8 }
......
1 +module module1 {
2 + yang-version 1;
3 + namespace "urn:ietf:params:xml:ns:yang:ietf-te-topology";
4 + prefix "tet";
5 + import module2 {
6 + prefix "nt";
7 + }
8 + grouping te-node-tunnel-termination-capability {
9 + description
10 + "Termination capability of a tunnel termination point on a
11 + TE node.";
12 + list termination-capability {
13 + key "link-tp";
14 + description
15 + "The termination capabilities between
16 + tunnel-termination-point and link termination-point.
17 + The capability information can be used to compute
18 + the tunnel path.";
19 + leaf link-tp {
20 + type leafref {
21 + path "/nt:termination-point/nt:tp-id";
22 + }
23 + description
24 + "Link termination point.";
25 + }
26 + } // termination-capability
27 + } // te-node-tunnel-termination-capability
28 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module module2 {
2 + yang-version 1;
3 + namespace
4 + "urn:ietf:params:xml:ns:yang:ietf-inet-types";
5 + prefix inet;
6 + container termination-point {
7 + leaf tp-id {
8 + type string;
9 + }
10 + }
11 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module ietf-inet-types {
2 + yang-version 1;
3 + namespace
4 + "urn:ietf:params:xml:ns:yang:ietf-inet-types";
5 + prefix inet;
6 + typedef tp-ref {
7 + type leafref {
8 + path "/nwtp:value";
9 + }
10 + }
11 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module ietf-network-topology {
2 + yang-version 1;
3 + namespace "urn:ietf:params:xml:ns:yang:ietf-te-topology";
4 + prefix "tet";
5 + import ietf-network {
6 + prefix "nt";
7 + }
8 + grouping te-node-tunnel-termination-capability {
9 + description
10 + "Termination capability of a tunnel termination point on a
11 + TE node.";
12 + list termination-capability {
13 + key "link-tp";
14 + description
15 + "The termination capabilities between
16 + tunnel-termination-point and link termination-point.
17 + The capability information can be used to compute
18 + the tunnel path.";
19 + leaf link-tp {
20 + type leafref {
21 + path "/nt:termination-point/nt:tp-id";
22 + }
23 + description
24 + "Link termination point.";
25 + }
26 + } // termination-capability
27 + } // te-node-tunnel-termination-capability
28 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module ietf-network {
2 + yang-version 1;
3 + namespace
4 + "urn:ietf:params:xml:ns:yang:ietf-inet-types";
5 + prefix nw;
6 + import ietf-inet-types {
7 + prefix inet;
8 + }
9 + container termination-point {
10 + leaf tp-id {
11 + type string;
12 + }
13 + }
14 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module ietf-network {
2 + yang-version 1;
3 + namespace "urn:ietf:params:xml:ns:yang:ietf-network";
4 + prefix nd;
5 + container networks {
6 + description
7 + "Serves as top-level container for a list of networks.";
8 + leaf network-id {
9 + type status;
10 + description
11 + "Identifies a network.";
12 + }
13 + }
14 + typedef status {
15 + type uint8;
16 + }
17 + leaf network-ref {
18 + type leafref {
19 + path "/networks";
20 + }
21 + }
22 +}
...\ No newline at end of file ...\ No newline at end of file