Committed by
Patrick Liu
[ONOS-4744] Leafref implementation and UT
Change-Id: I151797185e0bb1695c0640b667ae76ef87c4d4b0
Showing
73 changed files
with
4869 additions
and
133 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 | } | ... | ... |
utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangLeafRef.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2016-present Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.yangutils.datamodel; | ||
18 | + | ||
19 | +import java.io.Serializable; | ||
20 | +import java.util.Iterator; | ||
21 | +import java.util.LinkedList; | ||
22 | +import java.util.List; | ||
23 | + | ||
24 | +import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | ||
25 | +import org.onosproject.yangutils.datamodel.utils.Parsable; | ||
26 | +import org.onosproject.yangutils.datamodel.utils.ResolvableStatus; | ||
27 | +import org.onosproject.yangutils.datamodel.utils.YangConstructType; | ||
28 | +import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes; | ||
29 | + | ||
30 | +import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.INTRA_FILE_RESOLVED; | ||
31 | +import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.RESOLVED; | ||
32 | + | ||
33 | +/* | ||
34 | + * Reference:RFC 6020. | ||
35 | + * The leafref type is used to reference a particular leaf instance in | ||
36 | + * the data tree. The "path" substatement (Section 9.9.2) selects a set | ||
37 | + * of leaf instances, and the leafref value space is the set of values | ||
38 | + * of these leaf instances. | ||
39 | + */ | ||
40 | + | ||
41 | +/** | ||
42 | + * Represents the leafref information. | ||
43 | + * | ||
44 | + * @param <T> YANG leafref info | ||
45 | + */ | ||
46 | +public class YangLeafRef<T> implements Parsable, Resolvable, Serializable, YangIfFeatureHolder { | ||
47 | + | ||
48 | + private static final long serialVersionUID = 286201644L; | ||
49 | + | ||
50 | + /** | ||
51 | + * YANG data type. | ||
52 | + */ | ||
53 | + private YangType effectiveDataType; | ||
54 | + | ||
55 | + /** | ||
56 | + * Referred leaf/leaf-list for the path specified in the leafref type. | ||
57 | + */ | ||
58 | + private T referredLeafOrLeafList; | ||
59 | + | ||
60 | + /** | ||
61 | + * Path of the leafref. | ||
62 | + */ | ||
63 | + private String path; | ||
64 | + | ||
65 | + /** | ||
66 | + * Leafref path type. Either absolute or relative path. | ||
67 | + */ | ||
68 | + private YangPathArgType pathType; | ||
69 | + | ||
70 | + /** | ||
71 | + * List of atomic paths in absolute Path. | ||
72 | + */ | ||
73 | + private List<YangAtomicPath> atomicPath; | ||
74 | + | ||
75 | + /** | ||
76 | + * YANG relative path. | ||
77 | + */ | ||
78 | + private YangRelativePath relativePath; | ||
79 | + | ||
80 | + /** | ||
81 | + * Status of resolution. If completely resolved enum value is "RESOLVED", | ||
82 | + * if not enum value is "UNRESOLVED", in case reference of grouping/typedef/leafref | ||
83 | + * is added to uses/type/leafref but it's not resolved value of enum should be | ||
84 | + * "INTRA_FILE_RESOLVED". | ||
85 | + */ | ||
86 | + private ResolvableStatus resolvableStatus; | ||
87 | + | ||
88 | + /** | ||
89 | + * Require instance status in leafref type. | ||
90 | + */ | ||
91 | + private boolean requireInstance; | ||
92 | + | ||
93 | + /** | ||
94 | + * List of if-feature. | ||
95 | + */ | ||
96 | + private List<YangIfFeature> ifFeatureList; | ||
97 | + | ||
98 | + /** | ||
99 | + * Returns the status of the require instance in leafref. | ||
100 | + * | ||
101 | + * @return status of the require instance | ||
102 | + */ | ||
103 | + public boolean getRequireInstance() { | ||
104 | + return requireInstance; | ||
105 | + } | ||
106 | + | ||
107 | + /** | ||
108 | + * Sets the status of the require instance in leafref. | ||
109 | + * | ||
110 | + * @param requireInstance status of the require instance | ||
111 | + */ | ||
112 | + public void setRequireInstance(boolean requireInstance) { | ||
113 | + this.requireInstance = requireInstance; | ||
114 | + } | ||
115 | + | ||
116 | + /** | ||
117 | + * Returns the type of data. | ||
118 | + * | ||
119 | + * @return the data type | ||
120 | + */ | ||
121 | + public YangType getEffectiveDataType() { | ||
122 | + return effectiveDataType; | ||
123 | + } | ||
124 | + | ||
125 | + /** | ||
126 | + * Sets the type of data. | ||
127 | + * | ||
128 | + * @param effectiveDataType data type | ||
129 | + */ | ||
130 | + public void setEffectiveDataType(YangType effectiveDataType) { | ||
131 | + this.effectiveDataType = effectiveDataType; | ||
132 | + } | ||
133 | + | ||
134 | + /** | ||
135 | + * Returns the path of the leafref. | ||
136 | + * | ||
137 | + * @return path of the leafref | ||
138 | + */ | ||
139 | + public String getPath() { | ||
140 | + return path; | ||
141 | + } | ||
142 | + | ||
143 | + /** | ||
144 | + * Sets the path of the leafref. | ||
145 | + * | ||
146 | + * @param path leafref path | ||
147 | + */ | ||
148 | + public void setPath(String path) { | ||
149 | + this.path = path; | ||
150 | + } | ||
151 | + | ||
152 | + /** | ||
153 | + * Returns the type of path in the leafref. | ||
154 | + * | ||
155 | + * @return type of path | ||
156 | + */ | ||
157 | + public YangPathArgType getPathType() { | ||
158 | + return pathType; | ||
159 | + } | ||
160 | + | ||
161 | + /** | ||
162 | + * Sets the type of path in the leafref. It can be either absolute or relative type. | ||
163 | + * | ||
164 | + * @param pathType type of path | ||
165 | + */ | ||
166 | + public void setPathType(YangPathArgType pathType) { | ||
167 | + this.pathType = pathType; | ||
168 | + } | ||
169 | + | ||
170 | + /** | ||
171 | + * Returns the list of atomic path. | ||
172 | + * | ||
173 | + * @return list of atomic path | ||
174 | + */ | ||
175 | + public List<YangAtomicPath> getAtomicPath() { | ||
176 | + return atomicPath; | ||
177 | + } | ||
178 | + | ||
179 | + /** | ||
180 | + * Sets the list of atomic path. | ||
181 | + * | ||
182 | + * @param atomicPath list of atomic path. | ||
183 | + */ | ||
184 | + public void setAtomicPath(List<YangAtomicPath> atomicPath) { | ||
185 | + this.atomicPath = atomicPath; | ||
186 | + } | ||
187 | + | ||
188 | + /** | ||
189 | + * Returns the object of relative path. | ||
190 | + * | ||
191 | + * @return object of relative path | ||
192 | + */ | ||
193 | + public YangRelativePath getRelativePath() { | ||
194 | + return relativePath; | ||
195 | + } | ||
196 | + | ||
197 | + /** | ||
198 | + * Sets the object of relative path. | ||
199 | + * | ||
200 | + * @param relativePath object of relative path. | ||
201 | + */ | ||
202 | + public void setRelativePath(YangRelativePath relativePath) { | ||
203 | + this.relativePath = relativePath; | ||
204 | + } | ||
205 | + | ||
206 | + /** | ||
207 | + * Returns the object of referred leaf/leaf-list. | ||
208 | + * | ||
209 | + * @return object of referred leaf/leaf-list | ||
210 | + */ | ||
211 | + public T getReferredLeafOrLeafList() { | ||
212 | + return referredLeafOrLeafList; | ||
213 | + } | ||
214 | + | ||
215 | + /** | ||
216 | + * Sets the object of referred leaf/leaf-list. | ||
217 | + * | ||
218 | + * @param targetExtendedInfo object of referred leaf/leaf-list | ||
219 | + */ | ||
220 | + public void setReferredLeafOrLeafList(T targetExtendedInfo) { | ||
221 | + this.referredLeafOrLeafList = targetExtendedInfo; | ||
222 | + } | ||
223 | + | ||
224 | + @Override | ||
225 | + public List<YangIfFeature> getIfFeatureList() { | ||
226 | + return ifFeatureList; | ||
227 | + } | ||
228 | + | ||
229 | + @Override | ||
230 | + public void addIfFeatureList(YangIfFeature ifFeature) { | ||
231 | + if (getIfFeatureList() == null) { | ||
232 | + setIfFeatureList(new LinkedList<>()); | ||
233 | + } | ||
234 | + getIfFeatureList().add(ifFeature); | ||
235 | + } | ||
236 | + | ||
237 | + @Override | ||
238 | + public void setIfFeatureList(List<YangIfFeature> ifFeatureList) { | ||
239 | + this.ifFeatureList = ifFeatureList; | ||
240 | + } | ||
241 | + | ||
242 | + @Override | ||
243 | + public YangConstructType getYangConstructType() { | ||
244 | + return YangConstructType.LEAFREF_DATA; | ||
245 | + } | ||
246 | + | ||
247 | + @Override | ||
248 | + public void validateDataOnEntry() throws DataModelException { | ||
249 | + // TODO auto-generated method stub, to be implemented by parser | ||
250 | + } | ||
251 | + | ||
252 | + @Override | ||
253 | + public void validateDataOnExit() throws DataModelException { | ||
254 | + // TODO auto-generated method stub, to be implemented by parser | ||
255 | + } | ||
256 | + | ||
257 | + @Override | ||
258 | + public ResolvableStatus getResolvableStatus() { | ||
259 | + return resolvableStatus; | ||
260 | + } | ||
261 | + | ||
262 | + @Override | ||
263 | + public void setResolvableStatus(ResolvableStatus resolvableStatus) { | ||
264 | + this.resolvableStatus = resolvableStatus; | ||
265 | + } | ||
266 | + | ||
267 | + @Override | ||
268 | + public void resolve() throws DataModelException { | ||
269 | + | ||
270 | + if (getReferredLeafOrLeafList() == null) { | ||
271 | + throw new DataModelException("Linker Error: The leafref does not refer to any leaf/leaf-list."); | ||
272 | + } | ||
273 | + | ||
274 | + // Initiate the resolution | ||
275 | + try { | ||
276 | + setResolvableStatus(getResolution()); | ||
277 | + } catch (DataModelException e) { | ||
278 | + throw new DataModelException(e.getMessage()); | ||
279 | + } | ||
280 | + } | ||
281 | + | ||
282 | + /** | ||
283 | + * Returns the resolution status by getting the effective built-in type. | ||
284 | + * | ||
285 | + * @return status of resolution | ||
286 | + * @throws DataModelException a violation of data model rules | ||
287 | + */ | ||
288 | + private ResolvableStatus getResolution() throws DataModelException { | ||
289 | + | ||
290 | + if (getReferredLeafOrLeafList() instanceof YangLeaf) { | ||
291 | + YangLeaf yangLeaf = ((YangLeaf) getReferredLeafOrLeafList()); | ||
292 | + YangType baseType = yangLeaf.getDataType(); | ||
293 | + | ||
294 | + if (baseType.getDataType() == YangDataTypes.LEAFREF) { | ||
295 | + YangLeafRef referredLeafRefInfo = (YangLeafRef) (yangLeaf.getDataType().getDataTypeExtendedInfo()); | ||
296 | + /* | ||
297 | + * Check whether the referred typedef is resolved. | ||
298 | + */ | ||
299 | + if (referredLeafRefInfo.getResolvableStatus() != INTRA_FILE_RESOLVED | ||
300 | + && referredLeafRefInfo.getResolvableStatus() != RESOLVED) { | ||
301 | + throw new DataModelException("Linker Error: Referred typedef is not resolved for type."); | ||
302 | + } | ||
303 | + | ||
304 | + /* | ||
305 | + * Check if the referred typedef is intra file resolved, if yes | ||
306 | + * sets current status also to intra file resolved . | ||
307 | + */ | ||
308 | + if ((referredLeafRefInfo.getResolvableStatus() == INTRA_FILE_RESOLVED)) { | ||
309 | + return INTRA_FILE_RESOLVED; | ||
310 | + } | ||
311 | + | ||
312 | + // Add the if-feature list from referred leafref to current leafref. | ||
313 | + List<YangIfFeature> referredLeafIfFeatureListFromLeafref = referredLeafRefInfo.getIfFeatureList(); | ||
314 | + if (referredLeafIfFeatureListFromLeafref != null && !referredLeafIfFeatureListFromLeafref.isEmpty()) { | ||
315 | + Iterator<YangIfFeature> referredLeafIfFeature = referredLeafIfFeatureListFromLeafref.iterator(); | ||
316 | + while (referredLeafIfFeature.hasNext()) { | ||
317 | + YangIfFeature ifFeature = referredLeafIfFeature.next(); | ||
318 | + addIfFeatureList(ifFeature); | ||
319 | + } | ||
320 | + } | ||
321 | + setEffectiveDataType(referredLeafRefInfo.getEffectiveDataType()); | ||
322 | + } else if (baseType.getDataType() == YangDataTypes.DERIVED) { | ||
323 | + /* | ||
324 | + * Check whether the referred typedef is resolved. | ||
325 | + */ | ||
326 | + if (baseType.getResolvableStatus() != INTRA_FILE_RESOLVED | ||
327 | + && baseType.getResolvableStatus() != RESOLVED) { | ||
328 | + throw new DataModelException("Linker Error: Referred typedef is not resolved for type."); | ||
329 | + } | ||
330 | + /* | ||
331 | + * Check if the referred typedef is intra file resolved, if yes | ||
332 | + * sets current status also to intra file resolved . | ||
333 | + */ | ||
334 | + if ((baseType.getResolvableStatus() == INTRA_FILE_RESOLVED)) { | ||
335 | + return INTRA_FILE_RESOLVED; | ||
336 | + } | ||
337 | + setEffectiveDataType(baseType); | ||
338 | + } else { | ||
339 | + setEffectiveDataType(baseType); | ||
340 | + } | ||
341 | + | ||
342 | + // Add the if-feature list from referred leaf to current leafref. | ||
343 | + List<YangIfFeature> referredLeafIfFeatureList = yangLeaf.getIfFeatureList(); | ||
344 | + if (referredLeafIfFeatureList != null && !referredLeafIfFeatureList.isEmpty()) { | ||
345 | + Iterator<YangIfFeature> referredLeafIfFeature = referredLeafIfFeatureList.iterator(); | ||
346 | + while (referredLeafIfFeature.hasNext()) { | ||
347 | + YangIfFeature ifFeature = referredLeafIfFeature.next(); | ||
348 | + addIfFeatureList(ifFeature); | ||
349 | + } | ||
350 | + } | ||
351 | + return RESOLVED; | ||
352 | + } else if (getReferredLeafOrLeafList() instanceof YangLeafList) { | ||
353 | + YangLeafList yangLeafList = ((YangLeafList) getReferredLeafOrLeafList()); | ||
354 | + YangType baseType = yangLeafList.getDataType(); | ||
355 | + | ||
356 | + if (baseType.getDataType() == YangDataTypes.LEAFREF) { | ||
357 | + YangLeafRef referredLeafRefInfo = (YangLeafRef) yangLeafList.getDataType().getDataTypeExtendedInfo(); | ||
358 | + /* | ||
359 | + * Check whether the referred typedef is resolved. | ||
360 | + */ | ||
361 | + if (referredLeafRefInfo.getResolvableStatus() != INTRA_FILE_RESOLVED | ||
362 | + && referredLeafRefInfo.getResolvableStatus() != RESOLVED) { | ||
363 | + throw new DataModelException("Linker Error: Referred typedef is not resolved for type."); | ||
364 | + } | ||
365 | + /* | ||
366 | + * Check if the referred typedef is intra file resolved, if yes | ||
367 | + * sets current status also to intra file resolved . | ||
368 | + */ | ||
369 | + if ((referredLeafRefInfo.getResolvableStatus() == INTRA_FILE_RESOLVED)) { | ||
370 | + return INTRA_FILE_RESOLVED; | ||
371 | + } | ||
372 | + // Add the if-feature list from referred leafref to current leafref. | ||
373 | + List<YangIfFeature> referredLeafListIfFeatureListFromLeafref = referredLeafRefInfo.getIfFeatureList(); | ||
374 | + if (referredLeafListIfFeatureListFromLeafref != null | ||
375 | + && !referredLeafListIfFeatureListFromLeafref.isEmpty()) { | ||
376 | + Iterator<YangIfFeature> referredLeafListIfFeature = referredLeafListIfFeatureListFromLeafref | ||
377 | + .iterator(); | ||
378 | + while (referredLeafListIfFeature.hasNext()) { | ||
379 | + YangIfFeature ifFeature = referredLeafListIfFeature.next(); | ||
380 | + addIfFeatureList(ifFeature); | ||
381 | + } | ||
382 | + } | ||
383 | + setEffectiveDataType(referredLeafRefInfo.getEffectiveDataType()); | ||
384 | + } else if (baseType.getDataType() == YangDataTypes.DERIVED) { | ||
385 | + /* | ||
386 | + * Check whether the referred typedef is resolved. | ||
387 | + */ | ||
388 | + if (baseType.getResolvableStatus() != INTRA_FILE_RESOLVED | ||
389 | + && baseType.getResolvableStatus() != RESOLVED) { | ||
390 | + throw new DataModelException("Linker Error: Referred typedef is not resolved for type."); | ||
391 | + } | ||
392 | + /* | ||
393 | + * Check if the referred typedef is intra file resolved, if yes | ||
394 | + * sets current status also to intra file resolved . | ||
395 | + */ | ||
396 | + if ((baseType.getResolvableStatus() == INTRA_FILE_RESOLVED)) { | ||
397 | + return INTRA_FILE_RESOLVED; | ||
398 | + } | ||
399 | + setEffectiveDataType(baseType); | ||
400 | + } else { | ||
401 | + setEffectiveDataType(baseType); | ||
402 | + } | ||
403 | + // Add the if-feature list from referred leaf-list to current leafref. | ||
404 | + List<YangIfFeature> referredLeafListIfFeatureList = yangLeafList.getIfFeatureList(); | ||
405 | + if (referredLeafListIfFeatureList != null && !referredLeafListIfFeatureList.isEmpty()) { | ||
406 | + Iterator<YangIfFeature> referredLeafListIfFeature = referredLeafListIfFeatureList.iterator(); | ||
407 | + while (referredLeafListIfFeature.hasNext()) { | ||
408 | + YangIfFeature ifFeature = referredLeafListIfFeature.next(); | ||
409 | + addIfFeatureList(ifFeature); | ||
410 | + } | ||
411 | + } | ||
412 | + return RESOLVED; | ||
413 | + } else { | ||
414 | + throw new DataModelException("Linker Error: The leafref must refer only to leaf/leaf-list."); | ||
415 | + } | ||
416 | + } | ||
417 | +} |
... | @@ -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(); | ... | ... |
... | @@ -22,7 +22,8 @@ import java.util.List; | ... | @@ -22,7 +22,8 @@ import java.util.List; |
22 | import java.util.Stack; | 22 | import java.util.Stack; |
23 | 23 | ||
24 | import org.onosproject.yangutils.datamodel.Resolvable; | 24 | import org.onosproject.yangutils.datamodel.Resolvable; |
25 | -import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes; | 25 | +import org.onosproject.yangutils.datamodel.ResolvableType; |
26 | +import org.onosproject.yangutils.datamodel.YangAtomicPath; | ||
26 | import org.onosproject.yangutils.datamodel.YangDerivedInfo; | 27 | import org.onosproject.yangutils.datamodel.YangDerivedInfo; |
27 | import org.onosproject.yangutils.datamodel.YangEntityToResolveInfo; | 28 | import org.onosproject.yangutils.datamodel.YangEntityToResolveInfo; |
28 | import org.onosproject.yangutils.datamodel.YangFeature; | 29 | import org.onosproject.yangutils.datamodel.YangFeature; |
... | @@ -31,15 +32,29 @@ import org.onosproject.yangutils.datamodel.YangGrouping; | ... | @@ -31,15 +32,29 @@ import org.onosproject.yangutils.datamodel.YangGrouping; |
31 | import org.onosproject.yangutils.datamodel.YangIfFeature; | 32 | import org.onosproject.yangutils.datamodel.YangIfFeature; |
32 | import org.onosproject.yangutils.datamodel.YangImport; | 33 | import org.onosproject.yangutils.datamodel.YangImport; |
33 | import org.onosproject.yangutils.datamodel.YangInclude; | 34 | import org.onosproject.yangutils.datamodel.YangInclude; |
35 | +import org.onosproject.yangutils.datamodel.YangInput; | ||
36 | +import org.onosproject.yangutils.datamodel.YangLeaf; | ||
37 | +import org.onosproject.yangutils.datamodel.YangLeafList; | ||
38 | +import org.onosproject.yangutils.datamodel.YangLeafRef; | ||
39 | +import org.onosproject.yangutils.datamodel.YangLeavesHolder; | ||
40 | +import org.onosproject.yangutils.datamodel.YangList; | ||
41 | +import org.onosproject.yangutils.datamodel.YangModule; | ||
34 | import org.onosproject.yangutils.datamodel.YangNode; | 42 | import org.onosproject.yangutils.datamodel.YangNode; |
35 | import org.onosproject.yangutils.datamodel.YangNodeIdentifier; | 43 | import org.onosproject.yangutils.datamodel.YangNodeIdentifier; |
44 | +import org.onosproject.yangutils.datamodel.YangOutput; | ||
45 | +import org.onosproject.yangutils.datamodel.YangPathArgType; | ||
46 | +import org.onosproject.yangutils.datamodel.YangPathPredicate; | ||
36 | import org.onosproject.yangutils.datamodel.YangReferenceResolver; | 47 | import org.onosproject.yangutils.datamodel.YangReferenceResolver; |
48 | +import org.onosproject.yangutils.datamodel.YangRelativePath; | ||
37 | import org.onosproject.yangutils.datamodel.YangResolutionInfo; | 49 | import org.onosproject.yangutils.datamodel.YangResolutionInfo; |
50 | +import org.onosproject.yangutils.datamodel.YangRpc; | ||
51 | +import org.onosproject.yangutils.datamodel.YangSubModule; | ||
38 | import org.onosproject.yangutils.datamodel.YangType; | 52 | import org.onosproject.yangutils.datamodel.YangType; |
39 | import org.onosproject.yangutils.datamodel.YangTypeDef; | 53 | import org.onosproject.yangutils.datamodel.YangTypeDef; |
40 | import org.onosproject.yangutils.datamodel.YangUses; | 54 | import org.onosproject.yangutils.datamodel.YangUses; |
41 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | 55 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
42 | import org.onosproject.yangutils.datamodel.utils.ResolvableStatus; | 56 | import org.onosproject.yangutils.datamodel.utils.ResolvableStatus; |
57 | +import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes; | ||
43 | import org.onosproject.yangutils.linker.YangLinkingPhase; | 58 | import org.onosproject.yangutils.linker.YangLinkingPhase; |
44 | 59 | ||
45 | import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.INTER_FILE_LINKED; | 60 | import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.INTER_FILE_LINKED; |
... | @@ -52,6 +67,10 @@ import static org.onosproject.yangutils.linker.YangLinkingPhase.INTER_FILE; | ... | @@ -52,6 +67,10 @@ import static org.onosproject.yangutils.linker.YangLinkingPhase.INTER_FILE; |
52 | import static org.onosproject.yangutils.linker.YangLinkingPhase.INTRA_FILE; | 67 | import static org.onosproject.yangutils.linker.YangLinkingPhase.INTRA_FILE; |
53 | import static org.onosproject.yangutils.utils.UtilConstants.FEATURE_LINKER_ERROR; | 68 | import static org.onosproject.yangutils.utils.UtilConstants.FEATURE_LINKER_ERROR; |
54 | import static org.onosproject.yangutils.utils.UtilConstants.GROUPING_LINKER_ERROR; | 69 | import static org.onosproject.yangutils.utils.UtilConstants.GROUPING_LINKER_ERROR; |
70 | +import static org.onosproject.yangutils.utils.UtilConstants.INPUT; | ||
71 | +import static org.onosproject.yangutils.utils.UtilConstants.LEAFREF; | ||
72 | +import static org.onosproject.yangutils.utils.UtilConstants.LEAFREF_LINKER_ERROR; | ||
73 | +import static org.onosproject.yangutils.utils.UtilConstants.OUTPUT; | ||
55 | import static org.onosproject.yangutils.utils.UtilConstants.TYPEDEF_LINKER_ERROR; | 74 | import static org.onosproject.yangutils.utils.UtilConstants.TYPEDEF_LINKER_ERROR; |
56 | 75 | ||
57 | /** | 76 | /** |
... | @@ -124,7 +143,7 @@ public class YangResolutionInfoImpl<T> | ... | @@ -124,7 +143,7 @@ public class YangResolutionInfoImpl<T> |
124 | 143 | ||
125 | setCurReferenceResolver(dataModelRootNode); | 144 | setCurReferenceResolver(dataModelRootNode); |
126 | 145 | ||
127 | - // Current node to resolve, it can be a YANG type, YANG uses or YANG if-feature. | 146 | + // Current node to resolve, it can be a YANG type, YANG uses or YANG if-feature or YANG leafref. |
128 | T entityToResolve = getEntityToResolveInfo().getEntityToResolve(); | 147 | T entityToResolve = getEntityToResolveInfo().getEntityToResolve(); |
129 | 148 | ||
130 | // Check if linking is already done | 149 | // Check if linking is already done |
... | @@ -138,13 +157,15 @@ public class YangResolutionInfoImpl<T> | ... | @@ -138,13 +157,15 @@ public class YangResolutionInfoImpl<T> |
138 | } | 157 | } |
139 | } else { | 158 | } else { |
140 | throw new DataModelException("Data Model Exception: Entity to resolved is other than " + | 159 | throw new DataModelException("Data Model Exception: Entity to resolved is other than " + |
141 | - "type/uses/if-feature"); | 160 | + "type/uses/if-feature/leafref"); |
142 | } | 161 | } |
143 | 162 | ||
144 | // Push the initial entity to resolve in stack. | 163 | // Push the initial entity to resolve in stack. |
145 | addInPartialResolvedStack(getEntityToResolveInfo()); | 164 | addInPartialResolvedStack(getEntityToResolveInfo()); |
146 | 165 | ||
147 | linkAndResolvePartialResolvedStack(); | 166 | linkAndResolvePartialResolvedStack(); |
167 | + | ||
168 | + addDerivedRefTypeToRefTypeResolutionList(); | ||
148 | } | 169 | } |
149 | 170 | ||
150 | /** | 171 | /** |
... | @@ -204,8 +225,10 @@ public class YangResolutionInfoImpl<T> | ... | @@ -204,8 +225,10 @@ public class YangResolutionInfoImpl<T> |
204 | errorInfo = TYPEDEF_LINKER_ERROR; | 225 | errorInfo = TYPEDEF_LINKER_ERROR; |
205 | } else if (resolvable instanceof YangUses) { | 226 | } else if (resolvable instanceof YangUses) { |
206 | errorInfo = GROUPING_LINKER_ERROR; | 227 | errorInfo = GROUPING_LINKER_ERROR; |
207 | - } else { | 228 | + } else if (resolvable instanceof YangIfFeature) { |
208 | errorInfo = FEATURE_LINKER_ERROR; | 229 | errorInfo = FEATURE_LINKER_ERROR; |
230 | + } else { | ||
231 | + errorInfo = LEAFREF_LINKER_ERROR; | ||
209 | } | 232 | } |
210 | DataModelException dataModelException = | 233 | DataModelException dataModelException = |
211 | new DataModelException(errorInfo); | 234 | new DataModelException(errorInfo); |
... | @@ -222,11 +245,75 @@ public class YangResolutionInfoImpl<T> | ... | @@ -222,11 +245,75 @@ public class YangResolutionInfoImpl<T> |
222 | } | 245 | } |
223 | 246 | ||
224 | } else { | 247 | } else { |
225 | - throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses"); | 248 | + throw new DataModelException( |
249 | + "Data Model Exception: Entity to resolved is other than type/uses/if-feature/leafref"); | ||
250 | + } | ||
251 | + } | ||
252 | + | ||
253 | + } | ||
254 | + | ||
255 | + /** | ||
256 | + * Adds the leafref type to the type, which has derived type referring to typedef with leafref type. | ||
257 | + */ | ||
258 | + private void addDerivedRefTypeToRefTypeResolutionList() throws DataModelException { | ||
259 | + | ||
260 | + YangNode potentialAncestorWithReferredNode = getEntityToResolveInfo().getHolderOfEntityToResolve(); | ||
261 | + | ||
262 | + // If holder is typedef return. | ||
263 | + if (potentialAncestorWithReferredNode instanceof YangTypeDef) { | ||
264 | + return; | ||
265 | + } | ||
266 | + | ||
267 | + // If entity is not type return. | ||
268 | + if (!(getEntityToResolveInfo().getEntityToResolve() instanceof YangType)) { | ||
269 | + return; | ||
226 | } | 270 | } |
227 | 271 | ||
272 | + YangType yangType = (YangType) getEntityToResolveInfo().getEntityToResolve(); | ||
273 | + | ||
274 | + // If type is not resolved return. | ||
275 | + if (yangType.getResolvableStatus() != RESOLVED) { | ||
276 | + return; | ||
228 | } | 277 | } |
229 | 278 | ||
279 | + YangDerivedInfo derivedInfo = (YangDerivedInfo) yangType.getDataTypeExtendedInfo(); | ||
280 | + | ||
281 | + /* | ||
282 | + * If the derived types referred type is not leaf ref return | ||
283 | + */ | ||
284 | + if (derivedInfo.getEffectiveBuiltInType() != YangDataTypes.LEAFREF) { | ||
285 | + return; | ||
286 | + } | ||
287 | + | ||
288 | + T extendedInfo = (T) derivedInfo.getReferredTypeDef().getTypeDefBaseType().getDataTypeExtendedInfo(); | ||
289 | + | ||
290 | + while (extendedInfo instanceof YangDerivedInfo) { | ||
291 | + YangDerivedInfo derivedInfoFromTypedef = (YangDerivedInfo) extendedInfo; | ||
292 | + extendedInfo = (T) derivedInfoFromTypedef.getReferredTypeDef().getTypeDefBaseType() | ||
293 | + .getDataTypeExtendedInfo(); | ||
294 | + } | ||
295 | + /* | ||
296 | + * Backup the derived types leaf ref info, delete all the info in | ||
297 | + * current type, but for resolution status as resolved. Copy the backed | ||
298 | + * up leaf ref to types extended info, create a leaf ref resolution info | ||
299 | + * using the current resolution info and add to leaf ref resolution | ||
300 | + * list. | ||
301 | + */ | ||
302 | + YangLeafRef leafRefInTypeDef = (YangLeafRef) extendedInfo; | ||
303 | + yangType.resetYangType(); | ||
304 | + | ||
305 | + yangType.setResolvableStatus(RESOLVED); | ||
306 | + yangType.setDataType(YangDataTypes.LEAFREF); | ||
307 | + yangType.setDataTypeName(LEAFREF); | ||
308 | + yangType.setDataTypeExtendedInfo(leafRefInTypeDef); | ||
309 | + leafRefInTypeDef.setResolvableStatus(UNRESOLVED); | ||
310 | + | ||
311 | + // Add resolution information to the list. | ||
312 | + YangResolutionInfoImpl resolutionInfoImpl = new YangResolutionInfoImpl<>(leafRefInTypeDef, | ||
313 | + potentialAncestorWithReferredNode, getLineNumber(), getCharPosition()); | ||
314 | + getCurReferenceResolver().addToResolutionList(resolutionInfoImpl, | ||
315 | + ResolvableType.YANG_LEAFREF); | ||
316 | + getCurReferenceResolver().resolveSelfFileLinking(ResolvableType.YANG_LEAFREF); | ||
230 | } | 317 | } |
231 | 318 | ||
232 | /** | 319 | /** |
... | @@ -237,7 +324,7 @@ public class YangResolutionInfoImpl<T> | ... | @@ -237,7 +324,7 @@ public class YangResolutionInfoImpl<T> |
237 | ((Resolvable) getCurrentEntityToResolveFromStack()).resolve(); | 324 | ((Resolvable) getCurrentEntityToResolveFromStack()).resolve(); |
238 | if (((Resolvable) getCurrentEntityToResolveFromStack()).getResolvableStatus() != INTRA_FILE_RESOLVED | 325 | if (((Resolvable) getCurrentEntityToResolveFromStack()).getResolvableStatus() != INTRA_FILE_RESOLVED |
239 | && ((Resolvable) getCurrentEntityToResolveFromStack()).getResolvableStatus() != UNDEFINED) { | 326 | && ((Resolvable) getCurrentEntityToResolveFromStack()).getResolvableStatus() != UNDEFINED) { |
240 | - // Sets the resolution status in inside the type/uses/if-feature. | 327 | + // Sets the resolution status in inside the type/uses/if-feature/leafref. |
241 | ((Resolvable) getCurrentEntityToResolveFromStack()).setResolvableStatus(RESOLVED); | 328 | ((Resolvable) getCurrentEntityToResolveFromStack()).setResolvableStatus(RESOLVED); |
242 | } | 329 | } |
243 | } | 330 | } |
... | @@ -270,6 +357,9 @@ public class YangResolutionInfoImpl<T> | ... | @@ -270,6 +357,9 @@ public class YangResolutionInfoImpl<T> |
270 | if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) { | 357 | if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) { |
271 | resolveSelfFileLinkingForIfFeature(potentialAncestorWithReferredNode); | 358 | resolveSelfFileLinkingForIfFeature(potentialAncestorWithReferredNode); |
272 | return; | 359 | return; |
360 | + } else if (getCurrentEntityToResolveFromStack() instanceof YangLeafRef) { | ||
361 | + resolveSelfFileLinkingForLeafref(potentialAncestorWithReferredNode); | ||
362 | + return; | ||
273 | } else { | 363 | } else { |
274 | 364 | ||
275 | /** | 365 | /** |
... | @@ -300,6 +390,91 @@ public class YangResolutionInfoImpl<T> | ... | @@ -300,6 +390,91 @@ public class YangResolutionInfoImpl<T> |
300 | } | 390 | } |
301 | 391 | ||
302 | /** | 392 | /** |
393 | + * Resolves self file linking for leafref. | ||
394 | + * | ||
395 | + * @param potentialAncestorWithReferredNode leafref holder node | ||
396 | + * @throws DataModelException a violation of data model rules | ||
397 | + */ | ||
398 | + private void resolveSelfFileLinkingForLeafref(YangNode potentialAncestorWithReferredNode) | ||
399 | + throws DataModelException { | ||
400 | + | ||
401 | + YangNode ancestorWithTheReferredNode = potentialAncestorWithReferredNode; | ||
402 | + YangLeafRef leafref = (YangLeafRef) getCurrentEntityToResolveFromStack(); | ||
403 | + boolean referredLeafFound = false; | ||
404 | + | ||
405 | + /* | ||
406 | + * Takes absolute path and takes the root node as module/sub-module, | ||
407 | + * then sends the list of nodes for finding the target leaf. | ||
408 | + */ | ||
409 | + if (leafref.getPathType() == YangPathArgType.ABSOLUTE_PATH) { | ||
410 | + List<YangAtomicPath> atomicPathList = leafref.getAtomicPath(); | ||
411 | + if (atomicPathList != null && !atomicPathList.isEmpty()) { | ||
412 | + Iterator<YangAtomicPath> listOfYangAtomicPath = atomicPathList.listIterator(); | ||
413 | + if (getCurReferenceResolver() instanceof YangModule) { | ||
414 | + YangModule rootNode = (YangModule) getCurReferenceResolver(); | ||
415 | + // Sends list of nodes for finding the target leaf. | ||
416 | + referredLeafFound = isLeafReferenceFound(listOfYangAtomicPath, rootNode, | ||
417 | + referredLeafFound, potentialAncestorWithReferredNode); | ||
418 | + } else if (getCurReferenceResolver() instanceof YangSubModule) { | ||
419 | + YangSubModule rootNode = (YangSubModule) getCurReferenceResolver(); | ||
420 | + // Sends list of nodes for finding the target leaf. | ||
421 | + referredLeafFound = isLeafReferenceFound(listOfYangAtomicPath, rootNode, | ||
422 | + referredLeafFound, potentialAncestorWithReferredNode); | ||
423 | + } | ||
424 | + } | ||
425 | + /* | ||
426 | + * Takes relative path, goes to the parent node by using the | ||
427 | + * ancestor count and sends the list of nodes for finding the target | ||
428 | + * leaf. | ||
429 | + */ | ||
430 | + } else if (leafref.getPathType() == YangPathArgType.RELATIVE_PATH) { | ||
431 | + YangRelativePath yangRelativePath = leafref.getRelativePath(); | ||
432 | + int parentNodes = yangRelativePath.getAncestorNodeCount(); | ||
433 | + List<YangAtomicPath> atomicPathList = yangRelativePath.getAtomicPathList(); | ||
434 | + if (atomicPathList != null && !atomicPathList.isEmpty()) { | ||
435 | + Iterator<YangAtomicPath> listOfAtomicPath = atomicPathList.listIterator(); | ||
436 | + // Gets the root node from ancestor count. | ||
437 | + YangNode rootparentNode = getRootNodeWithAncestorCount(parentNodes, ancestorWithTheReferredNode); | ||
438 | + // Sends list of nodes for finding the target leaf. | ||
439 | + referredLeafFound = isLeafReferenceFound(listOfAtomicPath, rootparentNode, | ||
440 | + referredLeafFound, potentialAncestorWithReferredNode); | ||
441 | + } | ||
442 | + } | ||
443 | + if (referredLeafFound) { | ||
444 | + return; | ||
445 | + } | ||
446 | + /* | ||
447 | + * In case prefix is not present it's a candidate for inter-file | ||
448 | + * resolution via include list. | ||
449 | + */ | ||
450 | + if (getRefPrefix() == null) { | ||
451 | + ((Resolvable) getCurrentEntityToResolveFromStack()).setResolvableStatus(INTRA_FILE_RESOLVED); | ||
452 | + } | ||
453 | + } | ||
454 | + | ||
455 | + /** | ||
456 | + * Returns the root parent with respect to the ancestor count from leafref. | ||
457 | + * | ||
458 | + * @param ancestorCount count of node where parent node can be reached | ||
459 | + * @param currentParent current parent node | ||
460 | + * @return root node | ||
461 | + * @throws DataModelException a violation of data model rules | ||
462 | + */ | ||
463 | + private YangNode getRootNodeWithAncestorCount(int ancestorCount, YangNode currentParent) | ||
464 | + throws DataModelException { | ||
465 | + | ||
466 | + int currentParentCount = 1; | ||
467 | + while (currentParentCount < ancestorCount) { | ||
468 | + if (currentParent.getParent() == null) { | ||
469 | + throw new DataModelException("YANG file error: The target node of leafref is invalid."); | ||
470 | + } | ||
471 | + currentParent = currentParent.getParent(); | ||
472 | + currentParentCount = currentParentCount + 1; | ||
473 | + } | ||
474 | + return currentParent; | ||
475 | + } | ||
476 | + | ||
477 | + /** | ||
303 | * Resolves self file linking for if-feature. | 478 | * Resolves self file linking for if-feature. |
304 | * | 479 | * |
305 | * @param potentialAncestorWithReferredNode if-feature holder node | 480 | * @param potentialAncestorWithReferredNode if-feature holder node |
... | @@ -333,6 +508,289 @@ public class YangResolutionInfoImpl<T> | ... | @@ -333,6 +508,289 @@ public class YangResolutionInfoImpl<T> |
333 | } | 508 | } |
334 | } | 509 | } |
335 | 510 | ||
511 | + /** | ||
512 | + * Returns the status of the referred leaf/leaf-list found for leafref. | ||
513 | + * | ||
514 | + * @param listOfYangAtomicPath list of atomic paths | ||
515 | + * @param ancestorWithTheReferredNode the parent node of leafref | ||
516 | + * @param referredLeafFound status of referred leaf/leaf-list | ||
517 | + * @param potentialAncestorWithReferredNode holder of the leafref leaf | ||
518 | + * @return status of referred leaf | ||
519 | + * @throws DataModelException a violation of data model rules | ||
520 | + */ | ||
521 | + private boolean isLeafReferenceFound(Iterator<YangAtomicPath> listOfYangAtomicPath, | ||
522 | + YangNode ancestorWithTheReferredNode, boolean referredLeafFound, YangNode potentialAncestorWithReferredNode) | ||
523 | + throws DataModelException { | ||
524 | + | ||
525 | + while (listOfYangAtomicPath.hasNext()) { | ||
526 | + YangAtomicPath atomicPath = listOfYangAtomicPath.next(); | ||
527 | + String nodeName = atomicPath.getNodeIdentifier().getName(); | ||
528 | + | ||
529 | + // When child is not present, only leaf/leaf-list is available in the node. | ||
530 | + if (ancestorWithTheReferredNode.getChild() == null) { | ||
531 | + referredLeafFound = isReferredLeafOrLeafListFound(ancestorWithTheReferredNode, nodeName, (T) LINKED); | ||
532 | + break; | ||
533 | + } | ||
534 | + ancestorWithTheReferredNode = ancestorWithTheReferredNode.getChild(); | ||
535 | + | ||
536 | + // Checks all the siblings under the node and returns the matched node. | ||
537 | + YangNode nodeFound = isReferredNodeInSiblingProcessedForLeafref(ancestorWithTheReferredNode, nodeName); | ||
538 | + | ||
539 | + // When node is not found in all the siblings, leaf-list may be the node we have to find. | ||
540 | + if (nodeFound == null) { | ||
541 | + referredLeafFound = isReferredLeafOrLeafListFound(ancestorWithTheReferredNode.getParent(), nodeName, | ||
542 | + (T) LINKED); | ||
543 | + } else { | ||
544 | + ancestorWithTheReferredNode = nodeFound; | ||
545 | + | ||
546 | + // For the node check if path predicate is present and fill its values. | ||
547 | + List<YangPathPredicate> pathPredicateList = atomicPath.getPathPredicatesList(); | ||
548 | + if (pathPredicateList != null && !pathPredicateList.isEmpty()) { | ||
549 | + Iterator<YangPathPredicate> listOfYangPathPredicate = pathPredicateList.listIterator(); | ||
550 | + fillPathPredicatesForTheNode(ancestorWithTheReferredNode, listOfYangPathPredicate, | ||
551 | + potentialAncestorWithReferredNode); | ||
552 | + } | ||
553 | + } | ||
554 | + | ||
555 | + // If leaf is also not found and node is also not found return the status as false. | ||
556 | + if (!referredLeafFound && nodeFound == null) { | ||
557 | + break; | ||
558 | + } | ||
559 | + } | ||
560 | + return referredLeafFound; | ||
561 | + } | ||
562 | + | ||
563 | + /** | ||
564 | + * Fills the referred leaf or leaf-list inside the path predicates. | ||
565 | + * | ||
566 | + * @param ancestorWithTheReferredNode the actual node where YANG list will be present | ||
567 | + * @param listOfYangPathPredicate the path predicates present for the node | ||
568 | + * @param potentialAncestorWithReferredNode the current leaf node parent | ||
569 | + * @throws DataModelException a violation of data model rules | ||
570 | + */ | ||
571 | + private void fillPathPredicatesForTheNode(YangNode ancestorWithTheReferredNode, | ||
572 | + Iterator<YangPathPredicate> listOfYangPathPredicate, YangNode potentialAncestorWithReferredNode) | ||
573 | + throws DataModelException { | ||
574 | + | ||
575 | + while (listOfYangPathPredicate.hasNext()) { | ||
576 | + if (!(ancestorWithTheReferredNode instanceof YangList)) { | ||
577 | + throw new DataModelException("YANG file error: The path predicates are applicable only for list"); | ||
578 | + } | ||
579 | + YangPathPredicate pathPredicate = listOfYangPathPredicate.next(); | ||
580 | + YangNodeIdentifier leftNode = pathPredicate.getNodeIdentifier(); | ||
581 | + YangRelativePath relativePath = pathPredicate.getRightRelativePath(); | ||
582 | + | ||
583 | + // Checks that the left axis is filled in the path predicate. | ||
584 | + boolean isLeftLeafOrLeafListSetForLeftAxis = getLeftLeafOrLeafListInPredicate( | ||
585 | + (YangList) ancestorWithTheReferredNode, pathPredicate, leftNode); | ||
586 | + if (!isLeftLeafOrLeafListSetForLeftAxis) { | ||
587 | + throw new DataModelException( | ||
588 | + "YANG file error: The path predicate is not referring to an existing leaf/leaflist"); | ||
589 | + } | ||
590 | + int parentNodes = relativePath.getAncestorNodeCount(); | ||
591 | + | ||
592 | + // Finds the root node for the right relative path. | ||
593 | + YangNode rootParentNode = getRootNodeWithAncestorCount(parentNodes, potentialAncestorWithReferredNode); | ||
594 | + | ||
595 | + // Finds the leaf/leaf-list from the right side relative path. | ||
596 | + resolveRightAxisNodeInPathPredicate(relativePath, rootParentNode, pathPredicate); | ||
597 | + } | ||
598 | + } | ||
599 | + | ||
600 | + /** | ||
601 | + * Resolves the right axis node in the path predicate. | ||
602 | + * | ||
603 | + * @param relativePath the relative path in the path predicate | ||
604 | + * @param rootParentNode parent node from where the node has to be found | ||
605 | + * @param pathPredicate data tree reference in YANG list | ||
606 | + * @throws DataModelException a violation of data model rules | ||
607 | + */ | ||
608 | + private void resolveRightAxisNodeInPathPredicate(YangRelativePath relativePath, YangNode rootParentNode, | ||
609 | + YangPathPredicate pathPredicate) throws DataModelException { | ||
610 | + | ||
611 | + List<YangAtomicPath> absolutePathList = relativePath.getAtomicPathList(); | ||
612 | + if (absolutePathList != null && !absolutePathList.isEmpty()) { | ||
613 | + Iterator<YangAtomicPath> listOfYangAtomicPathForRightRelative = absolutePathList.listIterator(); | ||
614 | + while (listOfYangAtomicPathForRightRelative.hasNext()) { | ||
615 | + boolean isRightAxisNodeFound = false; | ||
616 | + YangAtomicPath absolutePathInPredicate = listOfYangAtomicPathForRightRelative.next(); | ||
617 | + String nodeNameInAtomicPath = absolutePathInPredicate.getNodeIdentifier().getName(); | ||
618 | + | ||
619 | + // When child is not there check the leaf/leaf-list. | ||
620 | + if (rootParentNode.getChild() == null) { | ||
621 | + isRightAxisNodeFound = isReferredLeafOrLeafListFound(rootParentNode, | ||
622 | + nodeNameInAtomicPath, (T) pathPredicate); | ||
623 | + if (!isRightAxisNodeFound) { | ||
624 | + throw new DataModelException( | ||
625 | + "YANG file error: The path predicates is not referring to an existing leaf/leaflist"); | ||
626 | + } | ||
627 | + break; | ||
628 | + } | ||
629 | + rootParentNode = rootParentNode.getChild(); | ||
630 | + YangNode nodeFoundInTheRelativePath = isReferredNodeInSiblingProcessedForLeafref( | ||
631 | + rootParentNode, nodeNameInAtomicPath); | ||
632 | + | ||
633 | + if (nodeFoundInTheRelativePath == null) { | ||
634 | + | ||
635 | + // When node is not found check the leaf/leaf-list. | ||
636 | + isRightAxisNodeFound = isReferredLeafOrLeafListFound(rootParentNode.getParent(), | ||
637 | + nodeNameInAtomicPath, (T) pathPredicate); | ||
638 | + } else { | ||
639 | + rootParentNode = nodeFoundInTheRelativePath; | ||
640 | + } | ||
641 | + if (!isRightAxisNodeFound && nodeFoundInTheRelativePath == null) { | ||
642 | + throw new DataModelException( | ||
643 | + "YANG file error: The path predicates is not referring to an existing leaf/leaflist"); | ||
644 | + } | ||
645 | + } | ||
646 | + } | ||
647 | + } | ||
648 | + | ||
649 | + /** | ||
650 | + * Returns the status, if referred leaf/leaf-list is found. | ||
651 | + * | ||
652 | + * @param ancestorWithTheReferredNode the parent node of leaf/leaf-list | ||
653 | + * @param nodeName the name of the leaf/leaf-list | ||
654 | + * @param statusOrPathPredicate the status to be set for the leaf-ref or the path predicate | ||
655 | + * @return status of the target node is found | ||
656 | + * @throws DataModelException a violation of data model rules | ||
657 | + */ | ||
658 | + private boolean isReferredLeafOrLeafListFound(YangNode ancestorWithTheReferredNode, String nodeName, | ||
659 | + T statusOrPathPredicate) throws DataModelException { | ||
660 | + | ||
661 | + if (!(ancestorWithTheReferredNode instanceof YangLeavesHolder)) { | ||
662 | + throw new DataModelException("Yang file error: The target node of leafref is invalid."); | ||
663 | + } | ||
664 | + YangLeavesHolder leavesHolder = (YangLeavesHolder) ancestorWithTheReferredNode; | ||
665 | + if (leavesHolder.getListOfLeaf() != null) { | ||
666 | + Iterator<YangLeaf> yangLeavesList = leavesHolder.getListOfLeaf().listIterator(); | ||
667 | + while (yangLeavesList.hasNext()) { | ||
668 | + YangLeaf yangleaf = yangLeavesList.next(); | ||
669 | + if (yangleaf.getName().contentEquals(nodeName)) { | ||
670 | + if (statusOrPathPredicate instanceof ResolvableStatus) { | ||
671 | + ResolvableStatus status = (ResolvableStatus) statusOrPathPredicate; | ||
672 | + | ||
673 | + // Sets the referred leaf to YANG leafref. | ||
674 | + ((YangLeafRef) getCurrentEntityToResolveFromStack()).setReferredLeafOrLeafList(yangleaf); | ||
675 | + | ||
676 | + // Adds reference link of entity to the node under resolution. | ||
677 | + addReferredEntityLink(ancestorWithTheReferredNode, status); | ||
678 | + addUnResolvedLeafRefTypeToStack((T) yangleaf, ancestorWithTheReferredNode); | ||
679 | + return true; | ||
680 | + } else if (statusOrPathPredicate instanceof YangPathPredicate) { | ||
681 | + YangPathPredicate pathPredicate = (YangPathPredicate) statusOrPathPredicate; | ||
682 | + | ||
683 | + // Sets the right axis node. | ||
684 | + pathPredicate.setRightAxisNode(yangleaf); | ||
685 | + return true; | ||
686 | + } else { | ||
687 | + throw new DataModelException("YANG file error: The target node of leafref is invalid."); | ||
688 | + } | ||
689 | + } | ||
690 | + } | ||
691 | + } | ||
692 | + if (leavesHolder.getListOfLeafList() != null) { | ||
693 | + Iterator<YangLeafList> yangLeafListList = leavesHolder.getListOfLeafList().listIterator(); | ||
694 | + while (yangLeafListList.hasNext()) { | ||
695 | + YangLeafList yangLeaflist = yangLeafListList.next(); | ||
696 | + if (yangLeaflist.getName().contentEquals(nodeName)) { | ||
697 | + if (statusOrPathPredicate instanceof ResolvableStatus) { | ||
698 | + ResolvableStatus status = (ResolvableStatus) statusOrPathPredicate; | ||
699 | + | ||
700 | + // Sets the referred leaf-list to YANG leafref. | ||
701 | + ((YangLeafRef) getCurrentEntityToResolveFromStack()).setReferredLeafOrLeafList(yangLeaflist); | ||
702 | + | ||
703 | + // Adds reference link of entity to the node under resolution. | ||
704 | + addReferredEntityLink(ancestorWithTheReferredNode, status); | ||
705 | + addUnResolvedLeafRefTypeToStack((T) yangLeaflist, ancestorWithTheReferredNode); | ||
706 | + return true; | ||
707 | + } else if (statusOrPathPredicate instanceof YangPathPredicate) { | ||
708 | + YangPathPredicate pathPredicate = (YangPathPredicate) statusOrPathPredicate; | ||
709 | + pathPredicate.setRightAxisNode(yangLeaflist); | ||
710 | + return true; | ||
711 | + } else { | ||
712 | + throw new DataModelException("YANG file error: The target node of leafref is invalid."); | ||
713 | + } | ||
714 | + } | ||
715 | + } | ||
716 | + } | ||
717 | + return false; | ||
718 | + } | ||
719 | + | ||
720 | + /** | ||
721 | + * Adds the unresolved constructs to stack which has to be resolved for leafref. | ||
722 | + * | ||
723 | + * @param yangleafOrLeafList YANG leaf or leaf list which holds the type | ||
724 | + * @param ancestorWithTheReferredNode holder of the YANG leaf or leaf list | ||
725 | + */ | ||
726 | + private void addUnResolvedLeafRefTypeToStack(T yangleafOrLeafList, YangNode ancestorWithTheReferredNode) { | ||
727 | + | ||
728 | + YangType referredTypeInLeafOrLeafList; | ||
729 | + if (yangleafOrLeafList instanceof YangLeaf) { | ||
730 | + YangLeaf leaf = (YangLeaf) yangleafOrLeafList; | ||
731 | + referredTypeInLeafOrLeafList = leaf.getDataType(); | ||
732 | + if (referredTypeInLeafOrLeafList.getDataType() == YangDataTypes.LEAFREF) { | ||
733 | + YangEntityToResolveInfoImpl<YangLeafRef<?>> unResolvedEntityInfo = new YangEntityToResolveInfoImpl<>(); | ||
734 | + unResolvedEntityInfo.setEntityToResolve((YangLeafRef<?>) leaf.getDataType().getDataTypeExtendedInfo()); | ||
735 | + unResolvedEntityInfo.setHolderOfEntityToResolve(ancestorWithTheReferredNode); | ||
736 | + addInPartialResolvedStack((YangEntityToResolveInfoImpl<T>) unResolvedEntityInfo); | ||
737 | + } else if (referredTypeInLeafOrLeafList.getDataType() == YangDataTypes.DERIVED) { | ||
738 | + YangEntityToResolveInfoImpl<YangType<?>> unResolvedEntityInfo = new YangEntityToResolveInfoImpl<>(); | ||
739 | + unResolvedEntityInfo.setEntityToResolve(referredTypeInLeafOrLeafList); | ||
740 | + unResolvedEntityInfo.setHolderOfEntityToResolve(ancestorWithTheReferredNode); | ||
741 | + addInPartialResolvedStack((YangEntityToResolveInfoImpl<T>) unResolvedEntityInfo); | ||
742 | + } | ||
743 | + } else { | ||
744 | + YangLeafList leafList = (YangLeafList) yangleafOrLeafList; | ||
745 | + referredTypeInLeafOrLeafList = leafList.getDataType(); | ||
746 | + if (referredTypeInLeafOrLeafList.getDataType() == YangDataTypes.LEAFREF) { | ||
747 | + YangEntityToResolveInfoImpl<YangLeafRef<?>> unResolvedEntityInfo = new YangEntityToResolveInfoImpl<>(); | ||
748 | + unResolvedEntityInfo | ||
749 | + .setEntityToResolve((YangLeafRef<?>) leafList.getDataType().getDataTypeExtendedInfo()); | ||
750 | + unResolvedEntityInfo.setHolderOfEntityToResolve(ancestorWithTheReferredNode); | ||
751 | + addInPartialResolvedStack((YangEntityToResolveInfoImpl<T>) unResolvedEntityInfo); | ||
752 | + } else if (referredTypeInLeafOrLeafList.getDataType() == YangDataTypes.DERIVED) { | ||
753 | + YangEntityToResolveInfoImpl<YangType<?>> unResolvedEntityInfo = new YangEntityToResolveInfoImpl<>(); | ||
754 | + unResolvedEntityInfo.setEntityToResolve(referredTypeInLeafOrLeafList); | ||
755 | + unResolvedEntityInfo.setHolderOfEntityToResolve(ancestorWithTheReferredNode); | ||
756 | + addInPartialResolvedStack((YangEntityToResolveInfoImpl<T>) unResolvedEntityInfo); | ||
757 | + } | ||
758 | + } | ||
759 | + } | ||
760 | + | ||
761 | + /** | ||
762 | + * Returns true if referred leaf/leaf-list is found in a particular node. This is for path in path predicate. | ||
763 | + * | ||
764 | + * @param listForLeaf list node where referred leaf is found | ||
765 | + * @param pathPredicate path predicate instance where the value of nodes to be found are available | ||
766 | + * @param leftNode node identifier of the left side parameter in path predicate | ||
767 | + * @return status of the leaf/leaf-list found | ||
768 | + */ | ||
769 | + private boolean getLeftLeafOrLeafListInPredicate(YangList listForLeaf, YangPathPredicate pathPredicate, | ||
770 | + YangNodeIdentifier leftNode) { | ||
771 | + | ||
772 | + if (listForLeaf.getListOfLeaf() != null) { | ||
773 | + Iterator<YangLeaf> yangLeavesUnderList = listForLeaf.getListOfLeaf().listIterator(); | ||
774 | + while (yangLeavesUnderList.hasNext()) { | ||
775 | + YangLeaf yangleafUnderList = yangLeavesUnderList.next(); | ||
776 | + if (yangleafUnderList.getName().contentEquals(leftNode.getName())) { | ||
777 | + pathPredicate.setLeftAxisNode(yangleafUnderList); | ||
778 | + return true; | ||
779 | + } | ||
780 | + } | ||
781 | + } | ||
782 | + if (listForLeaf.getListOfLeafList() != null) { | ||
783 | + Iterator<YangLeafList> yangLeavesListUnderList = listForLeaf.getListOfLeafList().listIterator(); | ||
784 | + while (yangLeavesListUnderList.hasNext()) { | ||
785 | + YangLeafList yangleafListUnderList = yangLeavesListUnderList.next(); | ||
786 | + if (yangleafListUnderList.getName().contentEquals(leftNode.getName())) { | ||
787 | + pathPredicate.setLeftAxisNode(yangleafListUnderList); | ||
788 | + return true; | ||
789 | + } | ||
790 | + } | ||
791 | + } | ||
792 | + return false; | ||
793 | + } | ||
336 | 794 | ||
337 | /** | 795 | /** |
338 | * Returns feature holder(module/sub-module node) . | 796 | * Returns feature holder(module/sub-module node) . |
... | @@ -362,12 +820,70 @@ public class YangResolutionInfoImpl<T> | ... | @@ -362,12 +820,70 @@ public class YangResolutionInfoImpl<T> |
362 | } | 820 | } |
363 | 821 | ||
364 | /** | 822 | /** |
823 | + * Checks for the referred parent node for the leafref path. | ||
824 | + * | ||
825 | + * @param potentialReferredNode potential referred node | ||
826 | + * @return the reffered parent node of leaf/leaf-list | ||
827 | + * @throws DataModelException data model errors | ||
828 | + */ | ||
829 | + private YangNode isReferredNodeInSiblingProcessedForLeafref(YangNode potentialReferredNode, String referredNodeName) | ||
830 | + throws DataModelException { | ||
831 | + | ||
832 | + while (potentialReferredNode != null) { | ||
833 | + if (potentialReferredNode instanceof YangInput) { | ||
834 | + if (referredNodeName.equalsIgnoreCase(INPUT)) { | ||
835 | + return potentialReferredNode; | ||
836 | + } | ||
837 | + } else if (potentialReferredNode instanceof YangOutput) { | ||
838 | + if (referredNodeName.equalsIgnoreCase(OUTPUT)) { | ||
839 | + return potentialReferredNode; | ||
840 | + } | ||
841 | + } | ||
842 | + // Check if the potential referred node is the actual referred node | ||
843 | + if (isReferredNodeForLeafref(potentialReferredNode, referredNodeName)) { | ||
844 | + if (potentialReferredNode instanceof YangGrouping || potentialReferredNode instanceof YangTypeDef) { | ||
845 | + if (potentialReferredNode.getParent() instanceof YangRpc) { | ||
846 | + potentialReferredNode = potentialReferredNode.getNextSibling(); | ||
847 | + } else { | ||
848 | + throw new DataModelException("YANG file error: The target node of leafref is invalid."); | ||
849 | + } | ||
850 | + } | ||
851 | + return potentialReferredNode; | ||
852 | + } | ||
853 | + potentialReferredNode = potentialReferredNode.getNextSibling(); | ||
854 | + } | ||
855 | + return null; | ||
856 | + } | ||
857 | + | ||
858 | + /** | ||
859 | + * Checks if the current reference node name and the name in the path are equal. | ||
860 | + * | ||
861 | + * @param currentReferredNode the node where the reference is pointed | ||
862 | + * @param nameOfNodeinPath name of the node in the path | ||
863 | + * @return status of the match between the name | ||
864 | + * @throws DataModelException a violation of data model rules | ||
865 | + */ | ||
866 | + private boolean isReferredNodeForLeafref(YangNode currentReferredNode, String nameOfNodeinPath) | ||
867 | + throws DataModelException { | ||
868 | + | ||
869 | + if (getCurrentEntityToResolveFromStack() instanceof YangLeafRef) { | ||
870 | + /* | ||
871 | + * Check if name of node name matches with the current reference | ||
872 | + * node. | ||
873 | + */ | ||
874 | + return currentReferredNode.getName().contentEquals(nameOfNodeinPath); | ||
875 | + } else { | ||
876 | + throw new DataModelException("Data Model Exception: Entity to resolved is other than leafref"); | ||
877 | + } | ||
878 | + } | ||
879 | + | ||
880 | + /** | ||
365 | * Checks for the referred node defined in a ancestor scope. | 881 | * Checks for the referred node defined in a ancestor scope. |
366 | * | 882 | * |
367 | * @param potentialReferredNode potential referred node | 883 | * @param potentialReferredNode potential referred node |
368 | * @return status of resolution and updating the partial resolved stack with | 884 | * @return status of resolution and updating the partial resolved stack with |
369 | * the any recursive references | 885 | * the any recursive references |
370 | - * @throws DataModelException data model errors | 886 | + * @throws DataModelException a violation of data model rules |
371 | */ | 887 | */ |
372 | private boolean isReferredNodeInSiblingListProcessed(YangNode potentialReferredNode) | 888 | private boolean isReferredNodeInSiblingListProcessed(YangNode potentialReferredNode) |
373 | throws DataModelException { | 889 | throws DataModelException { |
... | @@ -502,6 +1018,8 @@ public class YangResolutionInfoImpl<T> | ... | @@ -502,6 +1018,8 @@ public class YangResolutionInfoImpl<T> |
502 | .setRefGroup((YangGrouping) referredNode); | 1018 | .setRefGroup((YangGrouping) referredNode); |
503 | } else if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) { | 1019 | } else if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) { |
504 | // do nothing , referred node is already set | 1020 | // do nothing , referred node is already set |
1021 | + } else if (getCurrentEntityToResolveFromStack() instanceof YangLeafRef) { | ||
1022 | + // do nothing , referred node is already set | ||
505 | } else { | 1023 | } else { |
506 | throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses"); | 1024 | throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses"); |
507 | } | 1025 | } |
... | @@ -541,7 +1059,8 @@ public class YangResolutionInfoImpl<T> | ... | @@ -541,7 +1059,8 @@ public class YangResolutionInfoImpl<T> |
541 | addUnResolvedUsesToStack(referredNode); | 1059 | addUnResolvedUsesToStack(referredNode); |
542 | } else if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) { | 1060 | } else if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) { |
543 | addUnResolvedIfFeatureToStack(referredNode); | 1061 | addUnResolvedIfFeatureToStack(referredNode); |
544 | - } else { | 1062 | + } else if (getCurrentEntityToResolveFromStack() instanceof YangLeafRef) { |
1063 | + // do nothing , referred node is already set | ||
545 | throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses"); | 1064 | throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses"); |
546 | } | 1065 | } |
547 | } | 1066 | } |
... | @@ -706,6 +1225,9 @@ public class YangResolutionInfoImpl<T> | ... | @@ -706,6 +1225,9 @@ public class YangResolutionInfoImpl<T> |
706 | 1225 | ||
707 | // Inter file linking and resolution. | 1226 | // Inter file linking and resolution. |
708 | linkInterFileAndResolve(); | 1227 | linkInterFileAndResolve(); |
1228 | + | ||
1229 | + // Resolve the derived types having leafref. | ||
1230 | + addDerivedRefTypeToRefTypeResolutionList(); | ||
709 | } | 1231 | } |
710 | 1232 | ||
711 | /** | 1233 | /** |
... | @@ -723,6 +1245,8 @@ public class YangResolutionInfoImpl<T> | ... | @@ -723,6 +1245,8 @@ public class YangResolutionInfoImpl<T> |
723 | refPrefix = ((YangUses) getCurrentEntityToResolveFromStack()).getPrefix(); | 1245 | refPrefix = ((YangUses) getCurrentEntityToResolveFromStack()).getPrefix(); |
724 | } else if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) { | 1246 | } else if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) { |
725 | refPrefix = ((YangIfFeature) getCurrentEntityToResolveFromStack()).getPrefix(); | 1247 | refPrefix = ((YangIfFeature) getCurrentEntityToResolveFromStack()).getPrefix(); |
1248 | + } else if (getCurrentEntityToResolveFromStack() instanceof YangLeafRef) { | ||
1249 | + refPrefix = refPrefixForLeafRef(); | ||
726 | } else { | 1250 | } else { |
727 | throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses"); | 1251 | throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses"); |
728 | } | 1252 | } |
... | @@ -730,6 +1254,27 @@ public class YangResolutionInfoImpl<T> | ... | @@ -730,6 +1254,27 @@ public class YangResolutionInfoImpl<T> |
730 | } | 1254 | } |
731 | 1255 | ||
732 | /** | 1256 | /** |
1257 | + * Returns the referenced prefix for leafref under resolution. | ||
1258 | + * | ||
1259 | + * @return referenced prefix of leafref under resolution | ||
1260 | + */ | ||
1261 | + private String refPrefixForLeafRef() { | ||
1262 | + | ||
1263 | + String refPrefix; | ||
1264 | + if (((YangLeafRef) getCurrentEntityToResolveFromStack()).getPathType() == YangPathArgType.ABSOLUTE_PATH) { | ||
1265 | + List<YangAtomicPath> theList = ((YangLeafRef) getCurrentEntityToResolveFromStack()).getAtomicPath(); | ||
1266 | + YangAtomicPath absPath = theList.iterator().next(); | ||
1267 | + refPrefix = absPath.getNodeIdentifier().getPrefix(); | ||
1268 | + } else { | ||
1269 | + YangRelativePath relativePath = ((YangLeafRef) getCurrentEntityToResolveFromStack()).getRelativePath(); | ||
1270 | + List<YangAtomicPath> theList = relativePath.getAtomicPathList(); | ||
1271 | + YangAtomicPath absPath = theList.iterator().next(); | ||
1272 | + refPrefix = absPath.getNodeIdentifier().getPrefix(); | ||
1273 | + } | ||
1274 | + return refPrefix; | ||
1275 | + } | ||
1276 | + | ||
1277 | + /** | ||
733 | * Performs inter file linking and resolution. | 1278 | * Performs inter file linking and resolution. |
734 | * | 1279 | * |
735 | * @throws DataModelException a violation in data model rule | 1280 | * @throws DataModelException a violation in data model rule |
... | @@ -838,9 +1383,19 @@ public class YangResolutionInfoImpl<T> | ... | @@ -838,9 +1383,19 @@ public class YangResolutionInfoImpl<T> |
838 | ((YangIfFeature) getCurrentEntityToResolveFromStack()).setResolvableStatus(UNDEFINED); | 1383 | ((YangIfFeature) getCurrentEntityToResolveFromStack()).setResolvableStatus(UNDEFINED); |
839 | return; | 1384 | return; |
840 | } | 1385 | } |
841 | - // Exception when referred typedef/grouping is not found. | 1386 | + // If current entity is still not resolved, then |
842 | - DataModelException dataModelException = new DataModelException("YANG file error: Referred " + | 1387 | + // linking/resolution has failed. |
843 | - "typedef/grouping for a given type/uses can't be found."); | 1388 | + String errorInfo; |
1389 | + if (getCurrentEntityToResolveFromStack() instanceof YangType) { | ||
1390 | + errorInfo = TYPEDEF_LINKER_ERROR; | ||
1391 | + } else if (getCurrentEntityToResolveFromStack() instanceof YangUses) { | ||
1392 | + errorInfo = GROUPING_LINKER_ERROR; | ||
1393 | + } else if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) { | ||
1394 | + errorInfo = FEATURE_LINKER_ERROR; | ||
1395 | + } else { | ||
1396 | + errorInfo = LEAFREF_LINKER_ERROR; | ||
1397 | + } | ||
1398 | + DataModelException dataModelException = new DataModelException(errorInfo); | ||
844 | dataModelException.setLine(getLineNumber()); | 1399 | dataModelException.setLine(getLineNumber()); |
845 | dataModelException.setCharPosition(getCharPosition()); | 1400 | dataModelException.setCharPosition(getCharPosition()); |
846 | throw dataModelException; | 1401 | throw dataModelException; |
... | @@ -849,10 +1404,21 @@ public class YangResolutionInfoImpl<T> | ... | @@ -849,10 +1404,21 @@ public class YangResolutionInfoImpl<T> |
849 | * If referred node is already linked, then just change the status | 1404 | * If referred node is already linked, then just change the status |
850 | * and push to the stack. | 1405 | * and push to the stack. |
851 | */ | 1406 | */ |
1407 | + if (getCurrentEntityToResolveFromStack() instanceof YangLeafRef) { | ||
1408 | + ((Resolvable) getCurrentEntityToResolveFromStack()).setResolvableStatus(INTER_FILE_LINKED); | ||
1409 | + if (referredNode instanceof YangLeaf) { | ||
1410 | + YangLeaf yangleaf = (YangLeaf) referredNode; | ||
1411 | + addUnResolvedLeafRefTypeToStack((T) yangleaf, (YangNode) yangleaf.getContainedIn()); | ||
1412 | + } else if (referredNode instanceof YangLeafList) { | ||
1413 | + YangLeafList yangLeafList = (YangLeafList) referredNode; | ||
1414 | + addUnResolvedLeafRefTypeToStack((T) yangLeafList, (YangNode) yangLeafList.getContainedIn()); | ||
1415 | + } | ||
1416 | + } else { | ||
852 | ((Resolvable) getCurrentEntityToResolveFromStack()).setResolvableStatus(INTER_FILE_LINKED); | 1417 | ((Resolvable) getCurrentEntityToResolveFromStack()).setResolvableStatus(INTER_FILE_LINKED); |
853 | addUnresolvedRecursiveReferenceToStack((YangNode) referredNode); | 1418 | addUnresolvedRecursiveReferenceToStack((YangNode) referredNode); |
854 | } | 1419 | } |
855 | } | 1420 | } |
1421 | + } | ||
856 | 1422 | ||
857 | /** | 1423 | /** |
858 | * Finds and resolves with include list. | 1424 | * Finds and resolves with include list. |
... | @@ -874,6 +1440,15 @@ public class YangResolutionInfoImpl<T> | ... | @@ -874,6 +1440,15 @@ public class YangResolutionInfoImpl<T> |
874 | linkedNode = findRefGrouping(yangInclude.getIncludedNode()); | 1440 | linkedNode = findRefGrouping(yangInclude.getIncludedNode()); |
875 | } else if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) { | 1441 | } else if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) { |
876 | linkedNode = findRefFeature(yangInclude.getIncludedNode()); | 1442 | linkedNode = findRefFeature(yangInclude.getIncludedNode()); |
1443 | + } else if (getCurrentEntityToResolveFromStack() instanceof YangLeafRef) { | ||
1444 | + boolean referredNode = findRefLeaf(yangInclude.getIncludedNode()); | ||
1445 | + /* | ||
1446 | + * Update the current reference resolver to external | ||
1447 | + * module/sub-module containing the referred typedef/grouping. | ||
1448 | + */ | ||
1449 | + setCurReferenceResolver((YangReferenceResolver) yangInclude.getIncludedNode()); | ||
1450 | + | ||
1451 | + return referredNode; | ||
877 | } | 1452 | } |
878 | if (linkedNode != null) { | 1453 | if (linkedNode != null) { |
879 | // Add the link to external entity. | 1454 | // Add the link to external entity. |
... | @@ -917,6 +1492,16 @@ public class YangResolutionInfoImpl<T> | ... | @@ -917,6 +1492,16 @@ public class YangResolutionInfoImpl<T> |
917 | linkedNode = findRefGrouping(yangImport.getImportedNode()); | 1492 | linkedNode = findRefGrouping(yangImport.getImportedNode()); |
918 | } else if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) { | 1493 | } else if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) { |
919 | linkedNode = findRefFeature(yangImport.getImportedNode()); | 1494 | linkedNode = findRefFeature(yangImport.getImportedNode()); |
1495 | + } else if (getCurrentEntityToResolveFromStack() instanceof YangLeafRef) { | ||
1496 | + boolean referredNode = findRefLeaf(yangImport.getImportedNode()); | ||
1497 | + /* | ||
1498 | + * Update the current reference resolver to external | ||
1499 | + * module/sub-module containing the referred | ||
1500 | + * typedef/grouping. | ||
1501 | + */ | ||
1502 | + setCurReferenceResolver((YangReferenceResolver) yangImport.getImportedNode()); | ||
1503 | + | ||
1504 | + return referredNode; | ||
920 | } | 1505 | } |
921 | if (linkedNode != null) { | 1506 | if (linkedNode != null) { |
922 | // Add the link to external entity. | 1507 | // Add the link to external entity. |
... | @@ -944,6 +1529,44 @@ public class YangResolutionInfoImpl<T> | ... | @@ -944,6 +1529,44 @@ public class YangResolutionInfoImpl<T> |
944 | } | 1529 | } |
945 | 1530 | ||
946 | /** | 1531 | /** |
1532 | + * Returns the status of referred leaf. | ||
1533 | + * | ||
1534 | + * @param importedNode the root node from a YANG file | ||
1535 | + * @return status of the referred leaf | ||
1536 | + * @throws DataModelException | ||
1537 | + */ | ||
1538 | + private boolean findRefLeaf(YangNode importedNode) throws DataModelException { | ||
1539 | + | ||
1540 | + boolean isReferredNodeFound = false; | ||
1541 | + List<YangAtomicPath> absolutePathList = ((YangLeafRef) getCurrentEntityToResolveFromStack()) | ||
1542 | + .getAtomicPath(); | ||
1543 | + if (absolutePathList != null && !absolutePathList.isEmpty()) { | ||
1544 | + Iterator<YangAtomicPath> listOfYangAtomicPath = absolutePathList.listIterator(); | ||
1545 | + | ||
1546 | + while (listOfYangAtomicPath.hasNext()) { | ||
1547 | + YangAtomicPath absolutePath = listOfYangAtomicPath.next(); | ||
1548 | + String nodeName = absolutePath.getNodeIdentifier().getName(); | ||
1549 | + | ||
1550 | + if (importedNode.getChild() == null) { | ||
1551 | + isReferredNodeFound = isReferredLeafOrLeafListFound(importedNode, nodeName, (T) INTER_FILE_LINKED); | ||
1552 | + break; | ||
1553 | + } | ||
1554 | + importedNode = importedNode.getChild(); | ||
1555 | + | ||
1556 | + YangNode nodeFound = isReferredNodeInSiblingProcessedForLeafref(importedNode, nodeName); | ||
1557 | + if (nodeFound == null) { | ||
1558 | + isReferredNodeFound = isReferredLeafOrLeafListFound(importedNode.getParent(), nodeName, | ||
1559 | + (T) INTER_FILE_LINKED); | ||
1560 | + } else { | ||
1561 | + importedNode = nodeFound; | ||
1562 | + } | ||
1563 | + } | ||
1564 | + } | ||
1565 | + // TODO: Path predicates filling for inter file has to be done. | ||
1566 | + return isReferredNodeFound; | ||
1567 | + } | ||
1568 | + | ||
1569 | + /** | ||
947 | * Returns referred typedef/grouping node. | 1570 | * Returns referred typedef/grouping node. |
948 | * | 1571 | * |
949 | * @return referred typedef/grouping node | 1572 | * @return referred typedef/grouping node |
... | @@ -959,6 +1582,8 @@ public class YangResolutionInfoImpl<T> | ... | @@ -959,6 +1582,8 @@ public class YangResolutionInfoImpl<T> |
959 | return (T) ((YangUses) getCurrentEntityToResolveFromStack()).getRefGroup(); | 1582 | return (T) ((YangUses) getCurrentEntityToResolveFromStack()).getRefGroup(); |
960 | } else if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) { | 1583 | } else if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) { |
961 | return (T) ((YangIfFeature) getCurrentEntityToResolveFromStack()).getReferredFeatureHolder(); | 1584 | return (T) ((YangIfFeature) getCurrentEntityToResolveFromStack()).getReferredFeatureHolder(); |
1585 | + } else if (getCurrentEntityToResolveFromStack() instanceof YangLeafRef) { | ||
1586 | + return (T) ((YangLeafRef) getCurrentEntityToResolveFromStack()).getReferredLeafOrLeafList(); | ||
962 | } else { | 1587 | } else { |
963 | throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses"); | 1588 | throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses"); |
964 | } | 1589 | } | ... | ... |
... | @@ -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 | } | ... | ... |
... | @@ -18,28 +18,44 @@ package org.onosproject.yangutils.parser.impl.parserutils; | ... | @@ -18,28 +18,44 @@ package org.onosproject.yangutils.parser.impl.parserutils; |
18 | 18 | ||
19 | import java.text.ParseException; | 19 | import java.text.ParseException; |
20 | import java.text.SimpleDateFormat; | 20 | import java.text.SimpleDateFormat; |
21 | +import java.util.ArrayList; | ||
21 | import java.util.Date; | 22 | import java.util.Date; |
23 | +import java.util.Iterator; | ||
22 | import java.util.LinkedList; | 24 | import java.util.LinkedList; |
23 | import java.util.List; | 25 | import java.util.List; |
24 | import java.util.regex.Pattern; | 26 | import java.util.regex.Pattern; |
25 | 27 | ||
26 | import org.antlr.v4.runtime.ParserRuleContext; | 28 | import org.antlr.v4.runtime.ParserRuleContext; |
29 | +import org.onosproject.yangutils.datamodel.YangAtomicPath; | ||
30 | +import org.onosproject.yangutils.datamodel.YangLeafRef; | ||
27 | import org.onosproject.yangutils.datamodel.YangNodeIdentifier; | 31 | import org.onosproject.yangutils.datamodel.YangNodeIdentifier; |
32 | +import org.onosproject.yangutils.datamodel.YangPathPredicate; | ||
33 | +import org.onosproject.yangutils.datamodel.YangRelativePath; | ||
28 | import org.onosproject.yangutils.datamodel.utils.YangConstructType; | 34 | import org.onosproject.yangutils.datamodel.utils.YangConstructType; |
29 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | 35 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; |
30 | import org.onosproject.yangutils.parser.exceptions.ParserException; | 36 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
31 | 37 | ||
38 | +import static org.onosproject.yangutils.datamodel.YangPathArgType.ABSOLUTE_PATH; | ||
39 | +import static org.onosproject.yangutils.datamodel.YangPathArgType.RELATIVE_PATH; | ||
40 | +import static org.onosproject.yangutils.datamodel.YangPathOperator.EQUALTO; | ||
32 | import static org.onosproject.yangutils.utils.UtilConstants.ADD; | 41 | import static org.onosproject.yangutils.utils.UtilConstants.ADD; |
42 | +import static org.onosproject.yangutils.utils.UtilConstants.ANCESTOR_ACCESSOR; | ||
43 | +import static org.onosproject.yangutils.utils.UtilConstants.ANCESTOR_ACCESSOR_IN_PATH; | ||
33 | import static org.onosproject.yangutils.utils.UtilConstants.CARET; | 44 | import static org.onosproject.yangutils.utils.UtilConstants.CARET; |
45 | +import static org.onosproject.yangutils.utils.UtilConstants.CHAR_OF_CLOSE_SQUARE_BRACKET; | ||
46 | +import static org.onosproject.yangutils.utils.UtilConstants.CHAR_OF_OPEN_SQUARE_BRACKET; | ||
47 | +import static org.onosproject.yangutils.utils.UtilConstants.CHAR_OF_SLASH; | ||
48 | +import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS; | ||
34 | import static org.onosproject.yangutils.utils.UtilConstants.COLON; | 49 | import static org.onosproject.yangutils.utils.UtilConstants.COLON; |
50 | +import static org.onosproject.yangutils.utils.UtilConstants.CURRENT; | ||
35 | import static org.onosproject.yangutils.utils.UtilConstants.CURRENTLY_UNSUPPORTED; | 51 | import static org.onosproject.yangutils.utils.UtilConstants.CURRENTLY_UNSUPPORTED; |
36 | import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; | 52 | import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; |
37 | import static org.onosproject.yangutils.utils.UtilConstants.FALSE; | 53 | import static org.onosproject.yangutils.utils.UtilConstants.FALSE; |
38 | import static org.onosproject.yangutils.utils.UtilConstants.IDENTITYREF; | 54 | import static org.onosproject.yangutils.utils.UtilConstants.IDENTITYREF; |
39 | -import static org.onosproject.yangutils.utils.UtilConstants.INSTANCE_IDENTIFIER; | 55 | +import static org.onosproject.yangutils.utils.UtilConstants.OPEN_SQUARE_BRACKET; |
40 | -import static org.onosproject.yangutils.utils.UtilConstants.LEAFREF; | ||
41 | import static org.onosproject.yangutils.utils.UtilConstants.QUOTES; | 56 | import static org.onosproject.yangutils.utils.UtilConstants.QUOTES; |
42 | import static org.onosproject.yangutils.utils.UtilConstants.SLASH; | 57 | import static org.onosproject.yangutils.utils.UtilConstants.SLASH; |
58 | +import static org.onosproject.yangutils.utils.UtilConstants.SLASH_FOR_STRING; | ||
43 | import static org.onosproject.yangutils.utils.UtilConstants.TRUE; | 59 | import static org.onosproject.yangutils.utils.UtilConstants.TRUE; |
44 | import static org.onosproject.yangutils.utils.UtilConstants.YANG_FILE_ERROR; | 60 | import static org.onosproject.yangutils.utils.UtilConstants.YANG_FILE_ERROR; |
45 | 61 | ||
... | @@ -52,6 +68,7 @@ public final class ListenerUtil { | ... | @@ -52,6 +68,7 @@ public final class ListenerUtil { |
52 | private static final String DATE_PATTERN = "[0-9]{4}-([0-9]{2}|[0-9])-([0-9]{2}|[0-9])"; | 68 | private static final String DATE_PATTERN = "[0-9]{4}-([0-9]{2}|[0-9])-([0-9]{2}|[0-9])"; |
53 | private static final String NON_NEGATIVE_INTEGER_PATTERN = "[0-9]+"; | 69 | private static final String NON_NEGATIVE_INTEGER_PATTERN = "[0-9]+"; |
54 | private static final Pattern INTEGER_PATTERN = Pattern.compile("[-][0-9]+|[0-9]+"); | 70 | private static final Pattern INTEGER_PATTERN = Pattern.compile("[-][0-9]+|[0-9]+"); |
71 | + private static final Pattern PATH_PREDICATE_PATTERN = Pattern.compile("\\[(.*?)\\]"); | ||
55 | private static final String XML = "xml"; | 72 | private static final String XML = "xml"; |
56 | private static final String ONE = "1"; | 73 | private static final String ONE = "1"; |
57 | private static final int IDENTIFIER_LENGTH = 64; | 74 | private static final int IDENTIFIER_LENGTH = 64; |
... | @@ -115,6 +132,42 @@ public final class ListenerUtil { | ... | @@ -115,6 +132,42 @@ public final class ListenerUtil { |
115 | } | 132 | } |
116 | 133 | ||
117 | /** | 134 | /** |
135 | + * Validates identifier and returns concatenated string if string contains plus symbol. | ||
136 | + * | ||
137 | + * @param identifier string from yang file | ||
138 | + * @param yangConstruct yang construct for creating error message | ||
139 | + * @param ctx yang construct's context to get the line number and character position | ||
140 | + * @param yangLeafRef instance of leafref where the path argument has to be set | ||
141 | + * @return concatenated string after removing double quotes | ||
142 | + */ | ||
143 | + public static String getValidIdentifierForLeafref(String identifier, YangConstructType yangConstruct, | ||
144 | + ParserRuleContext ctx, YangLeafRef yangLeafRef) { | ||
145 | + | ||
146 | + String identifierString = removeQuotesAndHandleConcat(identifier); | ||
147 | + ParserException parserException; | ||
148 | + | ||
149 | + if (identifierString.length() > IDENTIFIER_LENGTH) { | ||
150 | + parserException = new ParserException("YANG file error : " + " identifier " + identifierString + " in " + | ||
151 | + YangConstructType.getYangConstructType(yangConstruct) + " " + yangLeafRef.getPath() + " is " + | ||
152 | + "greater than 64 characters."); | ||
153 | + } else if (!IDENTIFIER_PATTERN.matcher(identifierString).matches()) { | ||
154 | + parserException = new ParserException("YANG file error : " + " identifier " + identifierString + " in " + | ||
155 | + YangConstructType.getYangConstructType(yangConstruct) + " " + yangLeafRef.getPath() + " is not " + | ||
156 | + "valid."); | ||
157 | + } else if (identifierString.toLowerCase().startsWith(XML)) { | ||
158 | + parserException = new ParserException("YANG file error : " + " identifier " + identifierString + " in " + | ||
159 | + YangConstructType.getYangConstructType(yangConstruct) + " " + yangLeafRef.getPath() + | ||
160 | + " must not start with (('X'|'x') ('M'|'m') ('L'|'l'))."); | ||
161 | + } else { | ||
162 | + return identifierString; | ||
163 | + } | ||
164 | + | ||
165 | + parserException.setLine(ctx.getStart().getLine()); | ||
166 | + parserException.setCharPosition(ctx.getStart().getCharPositionInLine()); | ||
167 | + throw parserException; | ||
168 | + } | ||
169 | + | ||
170 | + /** | ||
118 | * Validates the revision date. | 171 | * Validates the revision date. |
119 | * | 172 | * |
120 | * @param dateToValidate input revision date | 173 | * @param dateToValidate input revision date |
... | @@ -307,6 +360,352 @@ public final class ListenerUtil { | ... | @@ -307,6 +360,352 @@ public final class ListenerUtil { |
307 | } | 360 | } |
308 | 361 | ||
309 | /** | 362 | /** |
363 | + * Checks and return valid node identifier specific to nodes in leafref path. | ||
364 | + * | ||
365 | + * @param nodeIdentifierString string from yang file | ||
366 | + * @param yangConstruct yang construct for creating error message | ||
367 | + * @param ctx yang construct's context to get the line number and character position | ||
368 | + * @param yangLeafRef instance of leafref where the path argument has to be set | ||
369 | + * @return valid node identifier | ||
370 | + */ | ||
371 | + public static YangNodeIdentifier getValidNodeIdentifierForLeafref(String nodeIdentifierString, | ||
372 | + YangConstructType yangConstruct, ParserRuleContext ctx, YangLeafRef yangLeafRef) { | ||
373 | + | ||
374 | + String tmpIdentifierString = removeQuotesAndHandleConcat(nodeIdentifierString); | ||
375 | + String[] tmpData = tmpIdentifierString.split(Pattern.quote(COLON)); | ||
376 | + if (tmpData.length == 1) { | ||
377 | + YangNodeIdentifier nodeIdentifier = new YangNodeIdentifier(); | ||
378 | + checkForUnsupportedTypes(tmpData[0], yangConstruct, ctx); | ||
379 | + nodeIdentifier.setName(getValidIdentifierForLeafref(tmpData[0], yangConstruct, ctx, yangLeafRef)); | ||
380 | + return nodeIdentifier; | ||
381 | + } else if (tmpData.length == 2) { | ||
382 | + YangNodeIdentifier nodeIdentifier = new YangNodeIdentifier(); | ||
383 | + nodeIdentifier.setPrefix(getValidIdentifierForLeafref(tmpData[0], yangConstruct, ctx, yangLeafRef)); | ||
384 | + nodeIdentifier.setName(getValidIdentifierForLeafref(tmpData[1], yangConstruct, ctx, yangLeafRef)); | ||
385 | + return nodeIdentifier; | ||
386 | + } else { | ||
387 | + ParserException parserException = new ParserException("YANG file error : " + | ||
388 | + YangConstructType.getYangConstructType(yangConstruct) + yangLeafRef.getPath() + | ||
389 | + " is not valid."); | ||
390 | + parserException.setLine(ctx.getStart().getLine()); | ||
391 | + parserException.setCharPosition(ctx.getStart().getCharPositionInLine()); | ||
392 | + throw parserException; | ||
393 | + } | ||
394 | + } | ||
395 | + | ||
396 | + /** | ||
397 | + * Validates the path argument. It can be either absolute or relative path. | ||
398 | + * | ||
399 | + * @param pathString the path string from the path type | ||
400 | + * @param yangConstruct yang construct for creating error message | ||
401 | + * @param ctx yang construct's context to get the line number and character position | ||
402 | + * @param yangLeafRef instance of leafref where the path argument has to be set | ||
403 | + */ | ||
404 | + public static void validatePathArgument(String pathString, YangConstructType yangConstruct, | ||
405 | + ParserRuleContext ctx, YangLeafRef yangLeafRef) { | ||
406 | + | ||
407 | + String completePathString = removeQuotesAndHandleConcat(pathString); | ||
408 | + yangLeafRef.setPath(completePathString); | ||
409 | + if (completePathString.startsWith(SLASH)) { | ||
410 | + yangLeafRef.setPathType(ABSOLUTE_PATH); | ||
411 | + List<YangAtomicPath> yangAtomicPathListList = validateAbsolutePath(completePathString, yangConstruct, ctx, | ||
412 | + yangLeafRef); | ||
413 | + yangLeafRef.setAtomicPath(yangAtomicPathListList); | ||
414 | + } else if (completePathString.startsWith(ANCESTOR_ACCESSOR)) { | ||
415 | + yangLeafRef.setPathType(RELATIVE_PATH); | ||
416 | + validateRelativePath(completePathString, yangConstruct, ctx, yangLeafRef); | ||
417 | + } else { | ||
418 | + ParserException parserException = new ParserException("YANG file error : " + | ||
419 | + YangConstructType.getYangConstructType(yangConstruct) + yangLeafRef.getPath() + | ||
420 | + " does not follow valid path syntax"); | ||
421 | + parserException.setLine(ctx.getStart().getLine()); | ||
422 | + parserException.setCharPosition(ctx.getStart().getCharPositionInLine()); | ||
423 | + throw parserException; | ||
424 | + } | ||
425 | + } | ||
426 | + | ||
427 | + /** | ||
428 | + * Validates the relative path. | ||
429 | + * | ||
430 | + * @param completePathString the path string of relative path | ||
431 | + * @param yangConstruct yang construct for creating error message | ||
432 | + * @param ctx yang construct's context to get the line number and character position | ||
433 | + * @param yangLeafRef instance of leafref where the path argument has to be set | ||
434 | + */ | ||
435 | + private static void validateRelativePath(String completePathString, YangConstructType yangConstruct, | ||
436 | + ParserRuleContext ctx, YangLeafRef yangLeafRef) { | ||
437 | + | ||
438 | + YangRelativePath relativePath = new YangRelativePath(); | ||
439 | + int numberOfAncestors = 0; | ||
440 | + while (completePathString.startsWith(ANCESTOR_ACCESSOR_IN_PATH)) { | ||
441 | + completePathString = completePathString.replaceFirst(ANCESTOR_ACCESSOR_IN_PATH, EMPTY_STRING); | ||
442 | + numberOfAncestors = numberOfAncestors + 1; | ||
443 | + } | ||
444 | + if (completePathString == null || completePathString.length() == 0) { | ||
445 | + ParserException parserException = new ParserException("YANG file error : " | ||
446 | + + YangConstructType.getYangConstructType(yangConstruct) + yangLeafRef.getPath() + | ||
447 | + " does not follow valid path syntax"); | ||
448 | + parserException.setLine(ctx.getStart().getLine()); | ||
449 | + parserException.setCharPosition(ctx.getStart().getCharPositionInLine()); | ||
450 | + throw parserException; | ||
451 | + } | ||
452 | + relativePath.setAncestorNodeCount(numberOfAncestors); | ||
453 | + List<YangAtomicPath> atomicPath = validateAbsolutePath(SLASH_FOR_STRING + completePathString, | ||
454 | + yangConstruct, | ||
455 | + ctx, yangLeafRef); | ||
456 | + relativePath.setAtomicPathList(atomicPath); | ||
457 | + yangLeafRef.setRelativePath(relativePath); | ||
458 | + } | ||
459 | + | ||
460 | + /** | ||
461 | + * Validates the absolute path. | ||
462 | + * | ||
463 | + * @param completePathString the path string of absolute path | ||
464 | + * @param yangConstruct yang construct for creating error message | ||
465 | + * @param ctx yang construct's context to get the line number and character position | ||
466 | + * @param yangLeafRef instance of leafref where the path argument has to be set | ||
467 | + * @return list of object of node in absolute path | ||
468 | + */ | ||
469 | + private static List<YangAtomicPath> validateAbsolutePath(String completePathString, | ||
470 | + YangConstructType yangConstruct, ParserRuleContext ctx, YangLeafRef yangLeafRef) { | ||
471 | + | ||
472 | + List<YangAtomicPath> absolutePathList = new LinkedList<>(); | ||
473 | + YangPathPredicate yangPathPredicate = new YangPathPredicate(); | ||
474 | + YangNodeIdentifier yangNodeIdentifier; | ||
475 | + | ||
476 | + while (completePathString != null) { | ||
477 | + String path = completePathString.replaceFirst(SLASH_FOR_STRING, EMPTY_STRING); | ||
478 | + if (path == null || path.length() == 0) { | ||
479 | + ParserException parserException = new ParserException("YANG file error : " | ||
480 | + + YangConstructType.getYangConstructType(yangConstruct) + " " + yangLeafRef.getPath() + | ||
481 | + " does not follow valid path syntax"); | ||
482 | + parserException.setLine(ctx.getStart().getLine()); | ||
483 | + parserException.setCharPosition(ctx.getStart().getCharPositionInLine()); | ||
484 | + throw parserException; | ||
485 | + } | ||
486 | + String matchedPathPredicate; | ||
487 | + String nodeIdentifier; | ||
488 | + String[] differentiate = new String[2]; | ||
489 | + int forNodeIdentifier = path.indexOf(CHAR_OF_SLASH); | ||
490 | + int forPathPredicate = path.indexOf(CHAR_OF_OPEN_SQUARE_BRACKET); | ||
491 | + | ||
492 | + // Checks if path predicate is present for the node. | ||
493 | + if ((forPathPredicate < forNodeIdentifier) && (forPathPredicate != -1)) { | ||
494 | + List<String> pathPredicate = new ArrayList<>(); | ||
495 | + matchedPathPredicate = matchForPathPredicate(path); | ||
496 | + | ||
497 | + if (matchedPathPredicate == null || matchedPathPredicate.length() == 0) { | ||
498 | + ParserException parserException = new ParserException("YANG file error : " | ||
499 | + + YangConstructType.getYangConstructType(yangConstruct) + " " + yangLeafRef.getPath() + | ||
500 | + " does not follow valid path syntax"); | ||
501 | + parserException.setLine(ctx.getStart().getLine()); | ||
502 | + parserException.setCharPosition(ctx.getStart().getCharPositionInLine()); | ||
503 | + throw parserException; | ||
504 | + } | ||
505 | + int indexOfMatchedFirstOpenBrace = path.indexOf(CHAR_OF_OPEN_SQUARE_BRACKET); | ||
506 | + differentiate[0] = path.substring(0, indexOfMatchedFirstOpenBrace); | ||
507 | + differentiate[1] = path.substring(indexOfMatchedFirstOpenBrace); | ||
508 | + pathPredicate.add(matchedPathPredicate); | ||
509 | + nodeIdentifier = differentiate[0]; | ||
510 | + // Starts adding all path predicates of a node into the list. | ||
511 | + if (!differentiate[1].isEmpty()) { | ||
512 | + while (differentiate[1].startsWith(OPEN_SQUARE_BRACKET)) { | ||
513 | + matchedPathPredicate = matchForPathPredicate(differentiate[1]); | ||
514 | + if (matchedPathPredicate == null || matchedPathPredicate.length() == 0) { | ||
515 | + ParserException parserException = new ParserException( | ||
516 | + "YANG file error : " + YangConstructType.getYangConstructType(yangConstruct) + " " | ||
517 | + + yangLeafRef.getPath() + | ||
518 | + " does not follow valid path syntax"); | ||
519 | + parserException.setLine(ctx.getStart().getLine()); | ||
520 | + parserException.setCharPosition(ctx.getStart().getCharPositionInLine()); | ||
521 | + throw parserException; | ||
522 | + } | ||
523 | + pathPredicate.add(matchedPathPredicate); | ||
524 | + differentiate[1] = differentiate[1].substring(matchedPathPredicate.length()); | ||
525 | + } | ||
526 | + } | ||
527 | + | ||
528 | + List<YangPathPredicate> pathPredicateList = validatePathPredicate(pathPredicate, yangConstruct, ctx, | ||
529 | + yangPathPredicate, yangLeafRef); | ||
530 | + YangAtomicPath atomicPath = new YangAtomicPath(); | ||
531 | + yangNodeIdentifier = getValidNodeIdentifierForLeafref(nodeIdentifier, yangConstruct, ctx, yangLeafRef); | ||
532 | + atomicPath.setNodeIdentifier(yangNodeIdentifier); | ||
533 | + atomicPath.setPathPredicatesList(pathPredicateList); | ||
534 | + absolutePathList.add(atomicPath); | ||
535 | + } else { | ||
536 | + if (path.contains(SLASH_FOR_STRING)) { | ||
537 | + nodeIdentifier = path.substring(0, path.indexOf(CHAR_OF_SLASH)); | ||
538 | + differentiate[1] = path.substring(path.indexOf(CHAR_OF_SLASH)); | ||
539 | + } else { | ||
540 | + nodeIdentifier = path; | ||
541 | + differentiate[1] = null; | ||
542 | + } | ||
543 | + yangNodeIdentifier = getValidNodeIdentifierForLeafref(nodeIdentifier, yangConstruct, ctx, yangLeafRef); | ||
544 | + | ||
545 | + YangAtomicPath atomicPath = new YangAtomicPath(); | ||
546 | + atomicPath.setNodeIdentifier(yangNodeIdentifier); | ||
547 | + atomicPath.setPathPredicatesList(null); | ||
548 | + absolutePathList.add(atomicPath); | ||
549 | + } | ||
550 | + if (differentiate[1] == null || differentiate[1].length() == 0) { | ||
551 | + completePathString = null; | ||
552 | + } else { | ||
553 | + completePathString = differentiate[1]; | ||
554 | + } | ||
555 | + } | ||
556 | + return absolutePathList; | ||
557 | + } | ||
558 | + | ||
559 | + /** | ||
560 | + * Validates path predicate in the absolute path's node. | ||
561 | + * | ||
562 | + * @param pathPredicate list of path predicates in the node of absolute path | ||
563 | + * @param yangConstruct yang construct for creating error message | ||
564 | + * @param ctx yang construct's context to get the line number and character position | ||
565 | + * @param yangPathPredicate instance of path predicate where it has to be set | ||
566 | + * @param yangLeafRef instance of leafref where the path argument has to be set | ||
567 | + * @return list of object of path predicates in absolute path's node | ||
568 | + */ | ||
569 | + private static List<YangPathPredicate> validatePathPredicate(List<String> pathPredicate, | ||
570 | + YangConstructType yangConstruct, ParserRuleContext ctx, YangPathPredicate yangPathPredicate, | ||
571 | + YangLeafRef yangLeafRef) { | ||
572 | + | ||
573 | + Iterator<String> pathPredicateString = pathPredicate.iterator(); | ||
574 | + List<String> pathEqualityExpression = new ArrayList<>(); | ||
575 | + | ||
576 | + while (pathPredicateString.hasNext()) { | ||
577 | + String pathPredicateForNode = pathPredicateString.next(); | ||
578 | + pathPredicateForNode = (pathPredicateForNode.substring(1)).trim(); | ||
579 | + pathPredicateForNode = pathPredicateForNode.substring(0, | ||
580 | + pathPredicateForNode.indexOf(CHAR_OF_CLOSE_SQUARE_BRACKET)); | ||
581 | + pathEqualityExpression.add(pathPredicateForNode); | ||
582 | + } | ||
583 | + List<YangPathPredicate> validatedPathPredicateList = validatePathEqualityExpression(pathEqualityExpression, | ||
584 | + yangConstruct, ctx, yangPathPredicate, yangLeafRef); | ||
585 | + return validatedPathPredicateList; | ||
586 | + } | ||
587 | + | ||
588 | + /** | ||
589 | + * Validates the path equality expression. | ||
590 | + * | ||
591 | + * @param pathEqualityExpression list of path equality expression in the path predicates of the node | ||
592 | + * @param yangConstruct yang construct for creating error message | ||
593 | + * @param ctx yang construct's context to get the line number and character position | ||
594 | + * @param yangPathPredicate instance of path predicate where it has to be set | ||
595 | + * @param yangLeafRef instance of leafref where the path argument has to be set | ||
596 | + * @return list of object of path predicates in absolute path's node | ||
597 | + */ | ||
598 | + private static List<YangPathPredicate> validatePathEqualityExpression(List<String> pathEqualityExpression, | ||
599 | + YangConstructType yangConstruct, ParserRuleContext ctx, YangPathPredicate yangPathPredicate, | ||
600 | + YangLeafRef yangLeafRef) { | ||
601 | + | ||
602 | + Iterator<String> pathEqualityExpressionString = pathEqualityExpression.iterator(); | ||
603 | + List<YangPathPredicate> yangPathPredicateList = new ArrayList<>(); | ||
604 | + | ||
605 | + while (pathEqualityExpressionString.hasNext()) { | ||
606 | + String pathEqualityExpressionForNode = pathEqualityExpressionString.next(); | ||
607 | + String[] pathEqualityExpressionArray = pathEqualityExpressionForNode.split("[=]"); | ||
608 | + | ||
609 | + YangNodeIdentifier yangNodeIdentifierForPredicate; | ||
610 | + YangRelativePath yangRelativePath; | ||
611 | + yangNodeIdentifierForPredicate = getValidNodeIdentifierForLeafref(pathEqualityExpressionArray[0].trim(), | ||
612 | + yangConstruct, ctx, yangLeafRef); | ||
613 | + yangRelativePath = validatePathKeyExpression(pathEqualityExpressionArray[1].trim(), yangConstruct, ctx, | ||
614 | + yangLeafRef); | ||
615 | + yangPathPredicate.setNodeIdentifier(yangNodeIdentifierForPredicate); | ||
616 | + yangPathPredicate.setPathOperator(EQUALTO); | ||
617 | + yangPathPredicate.setRightRelativePath(yangRelativePath); | ||
618 | + yangPathPredicateList.add(yangPathPredicate); | ||
619 | + } | ||
620 | + return yangPathPredicateList; | ||
621 | + } | ||
622 | + | ||
623 | + /** | ||
624 | + * Validate the path key expression. | ||
625 | + * | ||
626 | + * @param rightRelativePath relative path in the path predicate | ||
627 | + * @param yangConstruct yang construct for creating error message | ||
628 | + * @param ctx yang construct's context to get the line number and character position | ||
629 | + * @param yangLeafRef instance of leafref where the path argument has to be set | ||
630 | + * @return object of right relative path in path predicate | ||
631 | + */ | ||
632 | + private static YangRelativePath validatePathKeyExpression(String rightRelativePath, | ||
633 | + YangConstructType yangConstruct, ParserRuleContext ctx, YangLeafRef yangLeafRef) { | ||
634 | + | ||
635 | + YangRelativePath yangRelativePath = new YangRelativePath(); | ||
636 | + String[] relativePath = rightRelativePath.split(SLASH_FOR_STRING); | ||
637 | + List<String> rightAbsolutePath = new ArrayList<>(); | ||
638 | + int accessAncestor = 0; | ||
639 | + for (String path : relativePath) { | ||
640 | + if (path.trim().equals(ANCESTOR_ACCESSOR)) { | ||
641 | + accessAncestor = accessAncestor + 1; | ||
642 | + } else { | ||
643 | + rightAbsolutePath.add(path); | ||
644 | + } | ||
645 | + } | ||
646 | + List<YangAtomicPath> atomicPathInRelativePath = validateRelativePathKeyExpression(rightAbsolutePath, | ||
647 | + yangConstruct, ctx, yangLeafRef); | ||
648 | + yangRelativePath.setAtomicPathList(atomicPathInRelativePath); | ||
649 | + yangRelativePath.setAncestorNodeCount(accessAncestor); | ||
650 | + return yangRelativePath; | ||
651 | + } | ||
652 | + | ||
653 | + /** | ||
654 | + * Validates the relative path key expression. | ||
655 | + * | ||
656 | + * @param rightAbsolutePath absolute path nodes present in the relative path | ||
657 | + * @param yangConstruct yang construct for creating error message | ||
658 | + * @param ctx yang construct's context to get the line number and character position | ||
659 | + * @param yangLeafRef instance of leafref where the path argument has to be set | ||
660 | + * @return list of object of absolute path nodes present in the relative path | ||
661 | + */ | ||
662 | + private static List<YangAtomicPath> validateRelativePathKeyExpression(List<String> rightAbsolutePath, | ||
663 | + YangConstructType yangConstruct, ParserRuleContext ctx, YangLeafRef yangLeafRef) { | ||
664 | + | ||
665 | + List<YangAtomicPath> atomicPathList = new ArrayList<>(); | ||
666 | + YangNodeIdentifier yangNodeIdentifier; | ||
667 | + | ||
668 | + Iterator<String> nodes = rightAbsolutePath.iterator(); | ||
669 | + String currentInvocationFunction = nodes.next(); | ||
670 | + currentInvocationFunction = currentInvocationFunction.trim(); | ||
671 | + String[] currentFunction = currentInvocationFunction.split("[(]"); | ||
672 | + | ||
673 | + if (!(currentFunction[0].trim().equals(CURRENT)) || !(currentFunction[1].trim().equals(CLOSE_PARENTHESIS))) { | ||
674 | + ParserException parserException = new ParserException("YANG file error : " | ||
675 | + + YangConstructType.getYangConstructType(yangConstruct) + " " + yangLeafRef.getPath() + | ||
676 | + " does not follow valid path syntax"); | ||
677 | + parserException.setLine(ctx.getStart().getLine()); | ||
678 | + parserException.setCharPosition(ctx.getStart().getCharPositionInLine()); | ||
679 | + throw parserException; | ||
680 | + } | ||
681 | + | ||
682 | + while (nodes.hasNext()) { | ||
683 | + YangAtomicPath atomicPath = new YangAtomicPath(); | ||
684 | + String node = nodes.next(); | ||
685 | + yangNodeIdentifier = getValidNodeIdentifierForLeafref(node.trim(), yangConstruct, ctx, yangLeafRef); | ||
686 | + atomicPath.setNodeIdentifier(yangNodeIdentifier); | ||
687 | + atomicPathList.add(atomicPath); | ||
688 | + } | ||
689 | + return atomicPathList; | ||
690 | + } | ||
691 | + | ||
692 | + /** | ||
693 | + * Validates the match for first path predicate in a given string. | ||
694 | + * | ||
695 | + * @param matchRequiredString string for which match has to be done | ||
696 | + * @return the matched string | ||
697 | + */ | ||
698 | + private static String matchForPathPredicate(String matchRequiredString) { | ||
699 | + | ||
700 | + String matchedString = null; | ||
701 | + java.util.regex.Matcher matcher = PATH_PREDICATE_PATTERN.matcher(matchRequiredString); | ||
702 | + if (matcher.find()) { | ||
703 | + matchedString = matcher.group(0); | ||
704 | + } | ||
705 | + return matchedString; | ||
706 | + } | ||
707 | + | ||
708 | + /** | ||
310 | * Checks whether the type is an unsupported type. | 709 | * Checks whether the type is an unsupported type. |
311 | * | 710 | * |
312 | * @param typeName name of the type | 711 | * @param typeName name of the type |
... | @@ -317,15 +716,9 @@ public final class ListenerUtil { | ... | @@ -317,15 +716,9 @@ public final class ListenerUtil { |
317 | YangConstructType yangConstruct, ParserRuleContext ctx) { | 716 | YangConstructType yangConstruct, ParserRuleContext ctx) { |
318 | 717 | ||
319 | if (yangConstruct == YangConstructType.TYPE_DATA) { | 718 | if (yangConstruct == YangConstructType.TYPE_DATA) { |
320 | - if (typeName.equalsIgnoreCase(LEAFREF)) { | 719 | + if (typeName.equalsIgnoreCase(IDENTITYREF)) { |
321 | - handleUnsupportedYangConstruct(YangConstructType.LEAFREF_DATA, | ||
322 | - ctx, CURRENTLY_UNSUPPORTED); | ||
323 | - } else if (typeName.equalsIgnoreCase(IDENTITYREF)) { | ||
324 | handleUnsupportedYangConstruct(YangConstructType.IDENTITYREF_DATA, | 720 | handleUnsupportedYangConstruct(YangConstructType.IDENTITYREF_DATA, |
325 | ctx, CURRENTLY_UNSUPPORTED); | 721 | ctx, CURRENTLY_UNSUPPORTED); |
326 | - } else if (typeName.equalsIgnoreCase(INSTANCE_IDENTIFIER)) { | ||
327 | - handleUnsupportedYangConstruct(YangConstructType.INSTANCE_IDENTIFIER_DATA, | ||
328 | - ctx, CURRENTLY_UNSUPPORTED); | ||
329 | } | 722 | } |
330 | } | 723 | } |
331 | } | 724 | } | ... | ... |
... | @@ -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 | } | ... | ... |
... | @@ -20,27 +20,34 @@ import java.io.IOException; | ... | @@ -20,27 +20,34 @@ import java.io.IOException; |
20 | import java.util.Iterator; | 20 | import java.util.Iterator; |
21 | import java.util.ListIterator; | 21 | import java.util.ListIterator; |
22 | import org.apache.maven.plugin.MojoExecutionException; | 22 | import org.apache.maven.plugin.MojoExecutionException; |
23 | +import org.junit.Rule; | ||
23 | import org.junit.Test; | 24 | import org.junit.Test; |
25 | +import org.junit.rules.ExpectedException; | ||
24 | import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes; | 26 | import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes; |
25 | import org.onosproject.yangutils.datamodel.YangDerivedInfo; | 27 | import org.onosproject.yangutils.datamodel.YangDerivedInfo; |
26 | import org.onosproject.yangutils.datamodel.YangGrouping; | 28 | import org.onosproject.yangutils.datamodel.YangGrouping; |
27 | import org.onosproject.yangutils.datamodel.YangLeaf; | 29 | import org.onosproject.yangutils.datamodel.YangLeaf; |
30 | +import org.onosproject.yangutils.datamodel.YangLeafRef; | ||
31 | +import org.onosproject.yangutils.datamodel.YangList; | ||
28 | import org.onosproject.yangutils.datamodel.YangModule; | 32 | import org.onosproject.yangutils.datamodel.YangModule; |
29 | import org.onosproject.yangutils.datamodel.YangNode; | 33 | import org.onosproject.yangutils.datamodel.YangNode; |
30 | import org.onosproject.yangutils.datamodel.YangNodeType; | 34 | import org.onosproject.yangutils.datamodel.YangNodeType; |
31 | import org.onosproject.yangutils.datamodel.YangTypeDef; | 35 | import org.onosproject.yangutils.datamodel.YangTypeDef; |
32 | import org.onosproject.yangutils.datamodel.YangUses; | 36 | import org.onosproject.yangutils.datamodel.YangUses; |
33 | import org.onosproject.yangutils.datamodel.utils.ResolvableStatus; | 37 | import org.onosproject.yangutils.datamodel.utils.ResolvableStatus; |
38 | +import org.onosproject.yangutils.linker.exceptions.LinkerException; | ||
34 | import org.onosproject.yangutils.linker.impl.YangLinkerManager; | 39 | import org.onosproject.yangutils.linker.impl.YangLinkerManager; |
35 | import org.onosproject.yangutils.parser.exceptions.ParserException; | 40 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
41 | +import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; | ||
36 | import org.onosproject.yangutils.utils.io.impl.YangFileScanner; | 42 | import org.onosproject.yangutils.utils.io.impl.YangFileScanner; |
37 | import org.onosproject.yangutils.utils.io.impl.YangPluginConfig; | 43 | import org.onosproject.yangutils.utils.io.impl.YangPluginConfig; |
38 | 44 | ||
39 | import static org.hamcrest.CoreMatchers.nullValue; | 45 | import static org.hamcrest.CoreMatchers.nullValue; |
40 | import static org.hamcrest.MatcherAssert.assertThat; | 46 | import static org.hamcrest.MatcherAssert.assertThat; |
41 | import static org.hamcrest.core.Is.is; | 47 | import static org.hamcrest.core.Is.is; |
42 | -import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DERIVED; | ||
43 | import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.STRING; | 48 | import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.STRING; |
49 | +import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DERIVED; | ||
50 | +import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.LEAFREF; | ||
44 | import static org.onosproject.yangutils.datamodel.YangNodeType.MODULE_NODE; | 51 | import static org.onosproject.yangutils.datamodel.YangNodeType.MODULE_NODE; |
45 | import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.RESOLVED; | 52 | import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.RESOLVED; |
46 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory; | 53 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory; |
... | @@ -50,6 +57,10 @@ import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirector | ... | @@ -50,6 +57,10 @@ import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirector |
50 | */ | 57 | */ |
51 | public class InterFileLinkingTest { | 58 | public class InterFileLinkingTest { |
52 | 59 | ||
60 | + @Rule | ||
61 | + public ExpectedException thrown = ExpectedException.none(); | ||
62 | + | ||
63 | + private final YangUtilsParserManager manager = new YangUtilsParserManager(); | ||
53 | private final YangUtilManager utilManager = new YangUtilManager(); | 64 | private final YangUtilManager utilManager = new YangUtilManager(); |
54 | private final YangLinkerManager yangLinkerManager = new YangLinkerManager(); | 65 | private final YangLinkerManager yangLinkerManager = new YangLinkerManager(); |
55 | 66 | ||
... | @@ -726,4 +737,253 @@ public class InterFileLinkingTest { | ... | @@ -726,4 +737,253 @@ public class InterFileLinkingTest { |
726 | deleteDirectory(userDir + "/target/groupingNodeSameAsModule/"); | 737 | deleteDirectory(userDir + "/target/groupingNodeSameAsModule/"); |
727 | 738 | ||
728 | } | 739 | } |
740 | + | ||
741 | + /** | ||
742 | + * Checks inter file leafref linking. | ||
743 | + */ | ||
744 | + @Test | ||
745 | + public void processInterFileLeafrefLinking() | ||
746 | + throws IOException, ParserException, MojoExecutionException { | ||
747 | + | ||
748 | + String searchDir = "src/test/resources/interfileleafref"; | ||
749 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); | ||
750 | + utilManager.parseYangFileInfoSet(); | ||
751 | + utilManager.createYangNodeSet(); | ||
752 | + YangNode refNode = null; | ||
753 | + YangNode selfNode = null; | ||
754 | + | ||
755 | + // Create YANG node set | ||
756 | + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); | ||
757 | + | ||
758 | + // Add references to import list. | ||
759 | + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); | ||
760 | + | ||
761 | + // Carry out inter-file linking. | ||
762 | + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); | ||
763 | + | ||
764 | + Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator(); | ||
765 | + | ||
766 | + YangNode rootNode = yangNodeIterator.next(); | ||
767 | + | ||
768 | + if (rootNode.getName().equals("module1")) { | ||
769 | + selfNode = rootNode; | ||
770 | + refNode = yangNodeIterator.next(); | ||
771 | + } else { | ||
772 | + refNode = rootNode; | ||
773 | + selfNode = yangNodeIterator.next(); | ||
774 | + } | ||
775 | + | ||
776 | + // Check whether the data model tree returned is of type module. | ||
777 | + assertThat(selfNode instanceof YangModule, is(true)); | ||
778 | + | ||
779 | + // Check whether the node type is set properly to module. | ||
780 | + assertThat(selfNode.getNodeType(), is(MODULE_NODE)); | ||
781 | + | ||
782 | + // Check whether the module name is set correctly. | ||
783 | + YangModule yangNode = (YangModule) selfNode; | ||
784 | + assertThat(yangNode.getName(), is("module1")); | ||
785 | + | ||
786 | + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); | ||
787 | + YangLeaf leafInfo = leafIterator.next(); | ||
788 | + | ||
789 | + assertThat(leafInfo.getName(), is("invalid-interval")); | ||
790 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("leafref")); | ||
791 | + assertThat(leafInfo.getDataType().getDataType(), is(LEAFREF)); | ||
792 | + | ||
793 | + // Check whether the data model tree returned is of type module. | ||
794 | + assertThat(refNode instanceof YangModule, is(true)); | ||
795 | + | ||
796 | + // Check whether the node type is set properly to module. | ||
797 | + assertThat(refNode.getNodeType(), is(MODULE_NODE)); | ||
798 | + | ||
799 | + // Check whether the module name is set correctly. | ||
800 | + YangModule yangNode1 = (YangModule) refNode; | ||
801 | + assertThat(yangNode1.getName(), is("module2")); | ||
802 | + YangLeaf leafInfo1 = yangNode1.getListOfLeaf().listIterator().next(); | ||
803 | + | ||
804 | + YangLeafRef leafref = (YangLeafRef) leafInfo.getDataType().getDataTypeExtendedInfo(); | ||
805 | + | ||
806 | + assertThat(leafref.getReferredLeafOrLeafList(), is(leafInfo1)); | ||
807 | + assertThat(leafref.getResolvableStatus(), is(RESOLVED)); | ||
808 | + | ||
809 | + assertThat(leafref.getEffectiveDataType().getDataType(), | ||
810 | + is(YangDataTypes.STRING)); | ||
811 | + } | ||
812 | + | ||
813 | + /** | ||
814 | + * Checks error scenerio where the node is invalid. | ||
815 | + */ | ||
816 | + @Test | ||
817 | + public void processSelfResolutionWhenLeafrefInModuleReferToInvalidNode() | ||
818 | + throws IOException, ParserException { | ||
819 | + | ||
820 | + thrown.expect(LinkerException.class); | ||
821 | + thrown.expectMessage( | ||
822 | + "YANG file error: Unable to find base leaf/leaf-list for given leafref"); | ||
823 | + String searchDir = "src/test/resources/interFileInvalidNode"; | ||
824 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); | ||
825 | + utilManager.parseYangFileInfoSet(); | ||
826 | + utilManager.createYangNodeSet(); | ||
827 | + | ||
828 | + YangNode selfNode = null; | ||
829 | + | ||
830 | + // Create YANG node set | ||
831 | + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); | ||
832 | + | ||
833 | + // Add references to import list. | ||
834 | + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); | ||
835 | + | ||
836 | + // Carry out inter-file linking. | ||
837 | + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); | ||
838 | + } | ||
839 | + | ||
840 | + /** | ||
841 | + * Checks the error scenerio when there is no referref leaf/leaf-list in any file. | ||
842 | + */ | ||
843 | + @Test | ||
844 | + public void processSelfResolutionWhenLeafrefDoesNotReferToLeafOrLeafList() | ||
845 | + throws IOException, ParserException { | ||
846 | + | ||
847 | + thrown.expect(LinkerException.class); | ||
848 | + thrown.expectMessage( | ||
849 | + "YANG file error: Unable to find base leaf/leaf-list for given leafref"); | ||
850 | + String searchDir = "src/test/resources/interfileleafrefwithinvaliddestinationnode"; | ||
851 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); | ||
852 | + utilManager.parseYangFileInfoSet(); | ||
853 | + utilManager.createYangNodeSet(); | ||
854 | + YangNode selfNode = null; | ||
855 | + | ||
856 | + // Create YANG node set | ||
857 | + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); | ||
858 | + | ||
859 | + // Add references to import list. | ||
860 | + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); | ||
861 | + | ||
862 | + // Carry out inter-file linking. | ||
863 | + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); | ||
864 | + } | ||
865 | + | ||
866 | + /** | ||
867 | + * Checks inter file resolution when leafref from grouping refers to other file. | ||
868 | + */ | ||
869 | + @Test | ||
870 | + public void processInterFileLeafrefFromGroupingRefersToOtherFile() | ||
871 | + throws IOException, ParserException { | ||
872 | + | ||
873 | + String searchDir = "src/test/resources/interfileleafreffromgroupingreferstootherfile"; | ||
874 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); | ||
875 | + utilManager.parseYangFileInfoSet(); | ||
876 | + utilManager.createYangNodeSet(); | ||
877 | + YangNode selfNode = null; | ||
878 | + YangNode refNode = null; | ||
879 | + | ||
880 | + // Create YANG node set | ||
881 | + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); | ||
882 | + | ||
883 | + // Add references to import list. | ||
884 | + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); | ||
885 | + | ||
886 | + // Carry out inter-file linking. | ||
887 | + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); | ||
888 | + | ||
889 | + Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator(); | ||
890 | + | ||
891 | + YangNode rootNode = yangNodeIterator.next(); | ||
892 | + | ||
893 | + if (rootNode.getName().equals("module1")) { | ||
894 | + selfNode = rootNode; | ||
895 | + refNode = yangNodeIterator.next(); | ||
896 | + } else { | ||
897 | + refNode = rootNode; | ||
898 | + selfNode = yangNodeIterator.next(); | ||
899 | + } | ||
900 | + | ||
901 | + // Check whether the data model tree returned is of type module. | ||
902 | + assertThat(selfNode instanceof YangModule, is(true)); | ||
903 | + | ||
904 | + // Check whether the node type is set properly to module. | ||
905 | + assertThat(selfNode.getNodeType(), is(MODULE_NODE)); | ||
906 | + | ||
907 | + // Check whether the module name is set correctly. | ||
908 | + YangModule yangNode = (YangModule) selfNode; | ||
909 | + assertThat(yangNode.getName(), is("module1")); | ||
910 | + | ||
911 | + YangList list = (YangList) yangNode.getChild().getChild(); | ||
912 | + ListIterator<YangLeaf> leafIterator = list.getListOfLeaf().listIterator(); | ||
913 | + YangLeaf leafInfo = leafIterator.next(); | ||
914 | + | ||
915 | + assertThat(leafInfo.getName(), is("link-tp")); | ||
916 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("leafref")); | ||
917 | + assertThat(leafInfo.getDataType().getDataType(), is(LEAFREF)); | ||
918 | + | ||
919 | + YangLeafRef leafref = (YangLeafRef) leafInfo.getDataType().getDataTypeExtendedInfo(); | ||
920 | + | ||
921 | + YangLeaf leafInfo2 = (YangLeaf) leafref.getReferredLeafOrLeafList(); | ||
922 | + assertThat(leafref.getReferredLeafOrLeafList(), is(leafInfo2)); | ||
923 | + assertThat(leafref.getResolvableStatus(), is(RESOLVED)); | ||
924 | + | ||
925 | + assertThat(leafref.getEffectiveDataType().getDataType(), | ||
926 | + is(YangDataTypes.STRING)); | ||
927 | + } | ||
928 | + | ||
929 | + /** | ||
930 | + * Checks inter file resolution when leafref refers to multiple leafrefs through many files. | ||
931 | + */ | ||
932 | + @Test | ||
933 | + public void processInterFileLeafrefRefersToMultipleLeafrefInMultipleFiles() | ||
934 | + throws IOException, ParserException { | ||
935 | + | ||
936 | + String searchDir = "src/test/resources/interfileleafrefreferstomultipleleafrefinmultiplefiles"; | ||
937 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); | ||
938 | + utilManager.parseYangFileInfoSet(); | ||
939 | + utilManager.createYangNodeSet(); | ||
940 | + YangNode refNode1 = null; | ||
941 | + YangNode refNode2 = null; | ||
942 | + YangNode selfNode = null; | ||
943 | + | ||
944 | + // Create YANG node set | ||
945 | + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); | ||
946 | + | ||
947 | + // Add references to import list. | ||
948 | + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); | ||
949 | + | ||
950 | + // Carry out inter-file linking. | ||
951 | + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); | ||
952 | + | ||
953 | + for (YangNode rootNode : utilManager.getYangNodeSet()) { | ||
954 | + if (rootNode.getName().equals("ietf-network-topology")) { | ||
955 | + selfNode = rootNode; | ||
956 | + } else if (rootNode.getName().equals("ietf-network")) { | ||
957 | + refNode1 = rootNode; | ||
958 | + } else { | ||
959 | + refNode2 = rootNode; | ||
960 | + } | ||
961 | + } | ||
962 | + // Check whether the data model tree returned is of type module. | ||
963 | + assertThat(selfNode instanceof YangModule, is(true)); | ||
964 | + | ||
965 | + // Check whether the node type is set properly to module. | ||
966 | + assertThat(selfNode.getNodeType(), is(MODULE_NODE)); | ||
967 | + | ||
968 | + // Check whether the module name is set correctly. | ||
969 | + YangModule yangNode = (YangModule) selfNode; | ||
970 | + assertThat(yangNode.getName(), is("ietf-network-topology")); | ||
971 | + | ||
972 | + YangList list = (YangList) yangNode.getChild().getChild(); | ||
973 | + ListIterator<YangLeaf> leafIterator = list.getListOfLeaf().listIterator(); | ||
974 | + YangLeaf leafInfo = leafIterator.next(); | ||
975 | + | ||
976 | + assertThat(leafInfo.getName(), is("link-tp")); | ||
977 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("leafref")); | ||
978 | + assertThat(leafInfo.getDataType().getDataType(), is(LEAFREF)); | ||
979 | + | ||
980 | + YangLeafRef leafref = (YangLeafRef) leafInfo.getDataType().getDataTypeExtendedInfo(); | ||
981 | + | ||
982 | + YangLeaf leafInfo2 = (YangLeaf) leafref.getReferredLeafOrLeafList(); | ||
983 | + assertThat(leafref.getReferredLeafOrLeafList(), is(leafInfo2)); | ||
984 | + assertThat(leafref.getResolvableStatus(), is(RESOLVED)); | ||
985 | + | ||
986 | + assertThat(leafref.getEffectiveDataType().getDataType(), | ||
987 | + is(YangDataTypes.STRING)); | ||
988 | + } | ||
729 | } | 989 | } | ... | ... |
... | @@ -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 | +/* | ||
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.plugin.manager; | ||
18 | + | ||
19 | +import org.junit.Rule; | ||
20 | +import org.junit.Test; | ||
21 | +import org.junit.rules.ExpectedException; | ||
22 | +import org.onosproject.yangutils.datamodel.YangAtomicPath; | ||
23 | +import org.onosproject.yangutils.datamodel.YangContainer; | ||
24 | +import org.onosproject.yangutils.datamodel.YangInput; | ||
25 | +import org.onosproject.yangutils.datamodel.YangLeaf; | ||
26 | +import org.onosproject.yangutils.datamodel.YangLeafList; | ||
27 | +import org.onosproject.yangutils.datamodel.YangLeafRef; | ||
28 | +import org.onosproject.yangutils.datamodel.YangList; | ||
29 | +import org.onosproject.yangutils.datamodel.YangModule; | ||
30 | +import org.onosproject.yangutils.datamodel.YangNode; | ||
31 | +import org.onosproject.yangutils.datamodel.YangNodeType; | ||
32 | +import org.onosproject.yangutils.datamodel.YangPathArgType; | ||
33 | +import org.onosproject.yangutils.datamodel.YangPathOperator; | ||
34 | +import org.onosproject.yangutils.datamodel.YangPathPredicate; | ||
35 | +import org.onosproject.yangutils.datamodel.YangRelativePath; | ||
36 | +import org.onosproject.yangutils.datamodel.utils.ResolvableStatus; | ||
37 | +import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes; | ||
38 | +import org.onosproject.yangutils.linker.exceptions.LinkerException; | ||
39 | +import org.onosproject.yangutils.parser.exceptions.ParserException; | ||
40 | +import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; | ||
41 | + | ||
42 | +import java.io.IOException; | ||
43 | +import java.util.Iterator; | ||
44 | +import java.util.List; | ||
45 | +import java.util.ListIterator; | ||
46 | + | ||
47 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
48 | +import static org.hamcrest.core.Is.is; | ||
49 | +import static org.hamcrest.core.IsNull.nullValue; | ||
50 | + | ||
51 | +/** | ||
52 | + * Test cases for testing leafref intra file linking. | ||
53 | + */ | ||
54 | +public class IntraFileLeafrefLinkingTest { | ||
55 | + | ||
56 | + @Rule | ||
57 | + public ExpectedException thrown = ExpectedException.none(); | ||
58 | + | ||
59 | + private final YangUtilsParserManager manager = new YangUtilsParserManager(); | ||
60 | + | ||
61 | + /** | ||
62 | + * Checks self resolution when leafref under module refers to leaf in container. | ||
63 | + */ | ||
64 | + @Test | ||
65 | + public void processSelfResolutionWhenLeafrefReferToContainerLeaf() | ||
66 | + throws IOException, ParserException { | ||
67 | + | ||
68 | + YangNode node = manager.getDataModel("src/test/resources/SelfResolutionWhenLeafrefReferToContainerLeaf.yang"); | ||
69 | + | ||
70 | + // Check whether the data model tree returned is of type module. | ||
71 | + assertThat((node instanceof YangModule), is(true)); | ||
72 | + | ||
73 | + // Check whether the node type is set properly to module. | ||
74 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
75 | + | ||
76 | + // Check whether the module name is set correctly. | ||
77 | + YangModule yangNode = (YangModule) node; | ||
78 | + assertThat(yangNode.getName(), is("ietf-network")); | ||
79 | + | ||
80 | + ListIterator<YangLeaf> leafIterator; | ||
81 | + YangLeaf leafInfo; | ||
82 | + | ||
83 | + leafIterator = yangNode.getListOfLeaf().listIterator(); | ||
84 | + leafInfo = leafIterator.next(); | ||
85 | + | ||
86 | + // Check whether the information in the leaf is correct. | ||
87 | + assertThat(leafInfo.getName(), is("network-ref")); | ||
88 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("leafref")); | ||
89 | + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.LEAFREF)); | ||
90 | + YangLeafRef leafref = (YangLeafRef) (leafInfo.getDataType().getDataTypeExtendedInfo()); | ||
91 | + | ||
92 | + // Check whether leafref type got resolved. | ||
93 | + assertThat(leafref.getResolvableStatus(), | ||
94 | + is(ResolvableStatus.RESOLVED)); | ||
95 | + | ||
96 | + // Check the effective type for the leaf. | ||
97 | + assertThat(leafref.getEffectiveDataType().getDataType(), | ||
98 | + is(YangDataTypes.UINT8)); | ||
99 | + } | ||
100 | + | ||
101 | + /** | ||
102 | + * Checks self resolution when leafref under module refers to leaf in input of rpc. | ||
103 | + */ | ||
104 | + @Test | ||
105 | + public void processSelfResolutionWhenLeafrefInModuleReferToLeafInInputOfRpc() | ||
106 | + throws IOException, ParserException { | ||
107 | + | ||
108 | + YangNode node = manager | ||
109 | + .getDataModel("src/test/resources/SelfResolutionWhenLeafrefInModuleReferToLeafInInputOfRpc.yang"); | ||
110 | + | ||
111 | + // Check whether the data model tree returned is of type module. | ||
112 | + assertThat((node instanceof YangModule), is(true)); | ||
113 | + | ||
114 | + // Check whether the node type is set properly to module. | ||
115 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
116 | + | ||
117 | + // Check whether the module name is set correctly. | ||
118 | + YangModule yangNode = (YangModule) node; | ||
119 | + assertThat(yangNode.getName(), is("ietf-network")); | ||
120 | + | ||
121 | + ListIterator<YangLeaf> leafIterator; | ||
122 | + YangLeaf leafInfo; | ||
123 | + | ||
124 | + leafIterator = yangNode.getListOfLeaf().listIterator(); | ||
125 | + leafInfo = leafIterator.next(); | ||
126 | + | ||
127 | + // Check whether the information in the leaf is correct. | ||
128 | + assertThat(leafInfo.getName(), is("network-ref")); | ||
129 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("leafref")); | ||
130 | + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.LEAFREF)); | ||
131 | + YangLeafRef leafref = (YangLeafRef) (leafInfo.getDataType().getDataTypeExtendedInfo()); | ||
132 | + | ||
133 | + // Check whether leafref type got resolved. | ||
134 | + assertThat(leafref.getResolvableStatus(), | ||
135 | + is(ResolvableStatus.RESOLVED)); | ||
136 | + | ||
137 | + // Check the effective type for the leaf. | ||
138 | + assertThat(leafref.getEffectiveDataType().getDataType(), | ||
139 | + is(YangDataTypes.UINT8)); | ||
140 | + } | ||
141 | + | ||
142 | + /** | ||
143 | + * Checks self resolution when leafref under module refers to grouping rpc with input as name. | ||
144 | + * Rpc has input child also. So here the node search must be done by taking input node. | ||
145 | + */ | ||
146 | + @Test | ||
147 | + public void processSelfResolutionWhenLeafrefInModuleReferToGroupingWithInputInRpc() | ||
148 | + throws IOException, ParserException { | ||
149 | + | ||
150 | + YangNode node = manager | ||
151 | + .getDataModel("src/test/resources/SelfResolutionWhenLeafrefInModuleReferToGroupingWithInputInRpc.yang"); | ||
152 | + | ||
153 | + // Check whether the data model tree returned is of type module. | ||
154 | + assertThat((node instanceof YangModule), is(true)); | ||
155 | + | ||
156 | + // Check whether the node type is set properly to module. | ||
157 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
158 | + | ||
159 | + // Check whether the module name is set correctly. | ||
160 | + YangModule yangNode = (YangModule) node; | ||
161 | + assertThat(yangNode.getName(), is("ietf-network")); | ||
162 | + | ||
163 | + ListIterator<YangLeaf> leafIterator; | ||
164 | + YangLeaf leafInfo; | ||
165 | + | ||
166 | + leafIterator = yangNode.getListOfLeaf().listIterator(); | ||
167 | + leafInfo = leafIterator.next(); | ||
168 | + | ||
169 | + // Check whether the information in the leaf is correct. | ||
170 | + assertThat(leafInfo.getName(), is("network-ref")); | ||
171 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("leafref")); | ||
172 | + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.LEAFREF)); | ||
173 | + YangLeafRef leafref = (YangLeafRef) (leafInfo.getDataType().getDataTypeExtendedInfo()); | ||
174 | + | ||
175 | + // Check whether leafref type got resolved. | ||
176 | + assertThat(leafref.getResolvableStatus(), | ||
177 | + is(ResolvableStatus.RESOLVED)); | ||
178 | + | ||
179 | + // Check the effective type for the leaf. | ||
180 | + assertThat(leafref.getEffectiveDataType().getDataType(), | ||
181 | + is(YangDataTypes.UINT8)); | ||
182 | + } | ||
183 | + | ||
184 | + /** | ||
185 | + * Checks self resolution when leafref under module refers to grouping under module. | ||
186 | + * Grouping/typedef cannot be referred. | ||
187 | + */ | ||
188 | + @Test | ||
189 | + public void processSelfResolutionWhenLeafrefInModuleReferToGrouping() | ||
190 | + throws IOException, ParserException { | ||
191 | + | ||
192 | + thrown.expect(LinkerException.class); | ||
193 | + thrown.expectMessage( | ||
194 | + "YANG file error: The target node of leafref is invalid."); | ||
195 | + YangNode node = manager | ||
196 | + .getDataModel("src/test/resources/SelfResolutionWhenLeafrefInModuleReferToGroupingInModule.yang"); | ||
197 | + } | ||
198 | + | ||
199 | + /** | ||
200 | + * Checks self resolution error scenerio where leafref is without path. | ||
201 | + */ | ||
202 | + @Test | ||
203 | + public void processSelfResolutionWhenLeafrefDoesntHavePath() | ||
204 | + throws IOException, ParserException { | ||
205 | + | ||
206 | + thrown.expect(ParserException.class); | ||
207 | + thrown.expectMessage( | ||
208 | + "YANG file error : a type leafref must have one path statement."); | ||
209 | + YangNode node = manager | ||
210 | + .getDataModel("src/test/resources/SelfResolutionWhenLeafrefDoesntHavePath.yang"); | ||
211 | + } | ||
212 | + | ||
213 | + /** | ||
214 | + * Checks self resolution when leafref under module refers to invalid node. | ||
215 | + * Inter file linking also has to be done to know the error message. | ||
216 | + */ | ||
217 | + @Test | ||
218 | + public void processSelfResolutionWhenLeafrefInModuleReferToInvalidNode() | ||
219 | + throws IOException, ParserException { | ||
220 | + | ||
221 | + YangNode node = manager | ||
222 | + .getDataModel("src/test/resources/SelfResolutionWhenLeafrefInModuleReferToInvalidNode.yang"); | ||
223 | + // Check whether the data model tree returned is of type module. | ||
224 | + assertThat((node instanceof YangModule), is(true)); | ||
225 | + | ||
226 | + // Check whether the node type is set properly to module. | ||
227 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
228 | + | ||
229 | + // Check whether the module name is set correctly. | ||
230 | + YangModule yangNode = (YangModule) node; | ||
231 | + assertThat(yangNode.getName(), is("ietf-network")); | ||
232 | + | ||
233 | + ListIterator<YangLeaf> leafIterator; | ||
234 | + YangLeaf leafInfo; | ||
235 | + | ||
236 | + leafIterator = yangNode.getListOfLeaf().listIterator(); | ||
237 | + leafInfo = leafIterator.next(); | ||
238 | + | ||
239 | + // Check whether the information in the leaf is correct. | ||
240 | + assertThat(leafInfo.getName(), is("network-ref")); | ||
241 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("leafref")); | ||
242 | + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.LEAFREF)); | ||
243 | + YangLeafRef leafref = (YangLeafRef) (leafInfo.getDataType().getDataTypeExtendedInfo()); | ||
244 | + | ||
245 | + // Check whether leafref type got intra file resolved. | ||
246 | + assertThat(leafref.getResolvableStatus(), | ||
247 | + is(ResolvableStatus.INTRA_FILE_RESOLVED)); | ||
248 | + } | ||
249 | + | ||
250 | + /** | ||
251 | + * Checks self resolution when leafref under module refers to invalid node. | ||
252 | + * Inter file linking also has to be done to know the error message. | ||
253 | + */ | ||
254 | + @Test | ||
255 | + public void processSelfResolutionWhenLeafrefIsInDeepTreeAndLeafIsInModuleWithReferredTypeUnion() | ||
256 | + throws IOException, ParserException { | ||
257 | + | ||
258 | + YangNode node = manager.getDataModel( | ||
259 | + "src/test/resources/SelfResolutionWhenLeafrefIsInDeepTreeAndLeafIsInModuleWithReferredTypeUnion.yang"); | ||
260 | + // Check whether the data model tree returned is of type module. | ||
261 | + assertThat((node instanceof YangModule), is(true)); | ||
262 | + | ||
263 | + // Check whether the node type is set properly to module. | ||
264 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
265 | + | ||
266 | + // Check whether the module name is set correctly. | ||
267 | + YangModule yangNode = (YangModule) node; | ||
268 | + assertThat(yangNode.getName(), is("Test")); | ||
269 | + | ||
270 | + YangContainer containerParent = (YangContainer) yangNode.getChild().getChild().getChild(); | ||
271 | + ListIterator<YangLeaf> leafIterator; | ||
272 | + YangLeaf leafInfo; | ||
273 | + | ||
274 | + leafIterator = containerParent.getListOfLeaf().listIterator(); | ||
275 | + leafInfo = leafIterator.next(); | ||
276 | + | ||
277 | + // Check whether the information in the leaf is correct. | ||
278 | + assertThat(leafInfo.getName(), is("name")); | ||
279 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("leafref")); | ||
280 | + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.LEAFREF)); | ||
281 | + YangLeafRef leafref = (YangLeafRef) (leafInfo.getDataType().getDataTypeExtendedInfo()); | ||
282 | + | ||
283 | + // Check whether leafref type got resolved. | ||
284 | + assertThat(leafref.getResolvableStatus(), | ||
285 | + is(ResolvableStatus.RESOLVED)); | ||
286 | + | ||
287 | + // Check the effective type for the leaf. | ||
288 | + assertThat(leafref.getEffectiveDataType().getDataType(), | ||
289 | + is(YangDataTypes.UNION)); | ||
290 | + } | ||
291 | + | ||
292 | + /** | ||
293 | + * Checks self resolution when leafref of leaf-list under module refers to leaf in container. | ||
294 | + */ | ||
295 | + @Test | ||
296 | + public void processSelfResolutionWhenLeafrefReferToContainerLeafList() | ||
297 | + throws IOException, ParserException { | ||
298 | + | ||
299 | + YangNode node = manager | ||
300 | + .getDataModel("src/test/resources/SelfResolutionWhenLeafrefReferToContainerLeafList.yang"); | ||
301 | + | ||
302 | + // Check whether the data model tree returned is of type module. | ||
303 | + assertThat((node instanceof YangModule), is(true)); | ||
304 | + | ||
305 | + // Check whether the node type is set properly to module. | ||
306 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
307 | + | ||
308 | + // Check whether the module name is set correctly. | ||
309 | + YangModule yangNode = (YangModule) node; | ||
310 | + assertThat(yangNode.getName(), is("ietf-network")); | ||
311 | + | ||
312 | + ListIterator<YangLeafList> leafListIterator; | ||
313 | + YangLeafList leafListInfo; | ||
314 | + | ||
315 | + leafListIterator = yangNode.getListOfLeafList().listIterator(); | ||
316 | + leafListInfo = leafListIterator.next(); | ||
317 | + | ||
318 | + // Check whether the information in the leaf is correct. | ||
319 | + assertThat(leafListInfo.getName(), is("network-ref")); | ||
320 | + assertThat(leafListInfo.getDataType().getDataTypeName(), is("leafref")); | ||
321 | + assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.LEAFREF)); | ||
322 | + YangLeafRef leafref = (YangLeafRef) (leafListInfo.getDataType().getDataTypeExtendedInfo()); | ||
323 | + | ||
324 | + // Check whether leafref type got resolved. | ||
325 | + assertThat(leafref.getResolvableStatus(), | ||
326 | + is(ResolvableStatus.RESOLVED)); | ||
327 | + | ||
328 | + // Check the effective type for the leaf. | ||
329 | + assertThat(leafref.getEffectiveDataType().getDataType(), | ||
330 | + is(YangDataTypes.UINT8)); | ||
331 | + } | ||
332 | + | ||
333 | + /** | ||
334 | + * Checks self resolution when leafref of leaf-list under module refers to leaf-list in input of rpc. | ||
335 | + */ | ||
336 | + @Test | ||
337 | + public void processSelfResolutionWhenLeafrefInModuleReferToLeafListInInputOfRpc() | ||
338 | + throws IOException, ParserException { | ||
339 | + | ||
340 | + YangNode node = manager | ||
341 | + .getDataModel("src/test/resources/SelfResolutionWhenLeafrefInModuleReferToLeafListInInputOfRpc.yang"); | ||
342 | + | ||
343 | + // Check whether the data model tree returned is of type module. | ||
344 | + assertThat((node instanceof YangModule), is(true)); | ||
345 | + | ||
346 | + // Check whether the node type is set properly to module. | ||
347 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
348 | + | ||
349 | + // Check whether the module name is set correctly. | ||
350 | + YangModule yangNode = (YangModule) node; | ||
351 | + assertThat(yangNode.getName(), is("ietf-network")); | ||
352 | + | ||
353 | + ListIterator<YangLeafList> leafListIterator; | ||
354 | + YangLeafList leafListInfo; | ||
355 | + | ||
356 | + leafListIterator = yangNode.getListOfLeafList().listIterator(); | ||
357 | + leafListInfo = leafListIterator.next(); | ||
358 | + | ||
359 | + // Check whether the information in the leaf is correct. | ||
360 | + assertThat(leafListInfo.getName(), is("network-ref")); | ||
361 | + assertThat(leafListInfo.getDataType().getDataTypeName(), is("leafref")); | ||
362 | + assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.LEAFREF)); | ||
363 | + YangLeafRef leafref = (YangLeafRef) (leafListInfo.getDataType().getDataTypeExtendedInfo()); | ||
364 | + | ||
365 | + // Check whether leafref type got resolved. | ||
366 | + assertThat(leafref.getResolvableStatus(), | ||
367 | + is(ResolvableStatus.RESOLVED)); | ||
368 | + | ||
369 | + // Check the effective type for the leaf. | ||
370 | + assertThat(leafref.getEffectiveDataType().getDataType(), | ||
371 | + is(YangDataTypes.UINT8)); | ||
372 | + } | ||
373 | + | ||
374 | + /** | ||
375 | + * Checks self resolution when leafref of leaf-list under module refers to invalid node. | ||
376 | + * Inter file linking also has to be done to know the error message. | ||
377 | + */ | ||
378 | + @Test | ||
379 | + public void processSelfResolutionWhenLeafrefIsInDeepTreeAndLeafListIsInModuleWithReferredTypeEnumeration() | ||
380 | + throws IOException, ParserException { | ||
381 | + | ||
382 | + YangNode node = manager.getDataModel( | ||
383 | + "src/test/resources/" + | ||
384 | + "SelfResolutionWhenLeafrefIsInDeepTreeAndLeafListIsInModuleWithReferredTypeEnumeration.yang"); | ||
385 | + // Check whether the data model tree returned is of type module. | ||
386 | + assertThat((node instanceof YangModule), is(true)); | ||
387 | + | ||
388 | + // Check whether the node type is set properly to module. | ||
389 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
390 | + | ||
391 | + // Check whether the module name is set correctly. | ||
392 | + YangModule yangNode = (YangModule) node; | ||
393 | + assertThat(yangNode.getName(), is("Test")); | ||
394 | + | ||
395 | + YangContainer containerParent = (YangContainer) yangNode.getChild().getChild().getChild(); | ||
396 | + ListIterator<YangLeafList> leafListListIterator; | ||
397 | + YangLeafList leafListInfo; | ||
398 | + | ||
399 | + leafListListIterator = containerParent.getListOfLeafList().listIterator(); | ||
400 | + leafListInfo = leafListListIterator.next(); | ||
401 | + | ||
402 | + // Check whether the information in the leaf is correct. | ||
403 | + assertThat(leafListInfo.getName(), is("name")); | ||
404 | + assertThat(leafListInfo.getDataType().getDataTypeName(), is("leafref")); | ||
405 | + assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.LEAFREF)); | ||
406 | + YangLeafRef leafref = (YangLeafRef) (leafListInfo.getDataType().getDataTypeExtendedInfo()); | ||
407 | + | ||
408 | + // Check whether leafref type got resolved. | ||
409 | + assertThat(leafref.getResolvableStatus(), | ||
410 | + is(ResolvableStatus.RESOLVED)); | ||
411 | + | ||
412 | + // Check the effective type for the leaf. | ||
413 | + assertThat(leafref.getEffectiveDataType().getDataType(), | ||
414 | + is(YangDataTypes.ENUMERATION)); | ||
415 | + } | ||
416 | + | ||
417 | + /** | ||
418 | + * Checks the error scenerio when the referred node is not a leaf or leaf-list. | ||
419 | + */ | ||
420 | + @Test | ||
421 | + public void processSelfResolutionWhenLeafrefDoesNotReferToLeafOrLeafList() | ||
422 | + throws IOException, ParserException { | ||
423 | + | ||
424 | + YangNode node = manager | ||
425 | + .getDataModel("src/test/resources/SelfResolutionWhenLeafrefDoesNotReferToLeafOrLeafList.yang"); | ||
426 | + | ||
427 | + // Check whether the data model tree returned is of type module. | ||
428 | + assertThat((node instanceof YangModule), is(true)); | ||
429 | + | ||
430 | + // Check whether the node type is set properly to module. | ||
431 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
432 | + | ||
433 | + // Check whether the module name is set correctly. | ||
434 | + YangModule yangNode = (YangModule) node; | ||
435 | + assertThat(yangNode.getName(), is("ietf-network")); | ||
436 | + | ||
437 | + ListIterator<YangLeaf> leafIterator; | ||
438 | + YangLeaf leafInfo; | ||
439 | + | ||
440 | + //YangGrouping grouping = (YangGrouping) yangNode.getChild().getNextSibling(); | ||
441 | + leafIterator = yangNode.getListOfLeaf().listIterator(); | ||
442 | + leafInfo = leafIterator.next(); | ||
443 | + | ||
444 | + // Check whether the information in the leaf is correct under grouping. | ||
445 | + assertThat(leafInfo.getName(), is("network-ref")); | ||
446 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("leafref")); | ||
447 | + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.LEAFREF)); | ||
448 | + YangLeafRef leafref = (YangLeafRef) (leafInfo.getDataType().getDataTypeExtendedInfo()); | ||
449 | + | ||
450 | + assertThat(leafref.getResolvableStatus(), | ||
451 | + is(ResolvableStatus.INTRA_FILE_RESOLVED)); | ||
452 | + } | ||
453 | + | ||
454 | + /** | ||
455 | + * Checks self resolution when leafref of leaf-list under module refers to leaf in container. | ||
456 | + */ | ||
457 | + @Test | ||
458 | + public void processSelfResolutionWhenLeafrefInTypedefReferToContainer() | ||
459 | + throws IOException, ParserException { | ||
460 | + | ||
461 | + YangNode node = manager | ||
462 | + .getDataModel("src/test/resources/SelfResolutionWhenLeafrefInTypedefReferToContainer.yang"); | ||
463 | + | ||
464 | + // Check whether the data model tree returned is of type module. | ||
465 | + assertThat((node instanceof YangModule), is(true)); | ||
466 | + | ||
467 | + // Check whether the node type is set properly to module. | ||
468 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
469 | + | ||
470 | + // Check whether the module name is set correctly. | ||
471 | + YangModule yangNode = (YangModule) node; | ||
472 | + assertThat(yangNode.getName(), is("ietf-network")); | ||
473 | + | ||
474 | + YangContainer yangContainer = (YangContainer) yangNode.getChild(); | ||
475 | + ListIterator<YangLeaf> leafIterator; | ||
476 | + YangLeaf leafInfo; | ||
477 | + leafIterator = yangContainer.getListOfLeaf().listIterator(); | ||
478 | + leafInfo = leafIterator.next(); | ||
479 | + | ||
480 | + // Check whether the information in the leaf is correct under grouping. | ||
481 | + assertThat(leafInfo.getName(), is("network-id")); | ||
482 | + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.LEAFREF)); | ||
483 | + | ||
484 | + YangLeafRef leafref = (YangLeafRef) (leafInfo.getDataType().getDataTypeExtendedInfo()); | ||
485 | + | ||
486 | + // Check whether leafref type got resolved. | ||
487 | + assertThat(leafref.getResolvableStatus(), | ||
488 | + is(ResolvableStatus.RESOLVED)); | ||
489 | + | ||
490 | + // Check the effective type for the leaf. | ||
491 | + assertThat(leafref.getEffectiveDataType().getDataType(), | ||
492 | + is(YangDataTypes.UINT8)); | ||
493 | + } | ||
494 | + | ||
495 | + /** | ||
496 | + * Checks self resolution when leafref of leaf-list under module refers to leaf-list in input of rpc. | ||
497 | + */ | ||
498 | + @Test | ||
499 | + public void processSelfResolutionWhenLeafrefInTypedefModuleReferToLeafListInInputOfRpc() | ||
500 | + throws IOException, ParserException { | ||
501 | + | ||
502 | + YangNode node = manager.getDataModel( | ||
503 | + "src/test/resources/SelfResolutionWhenLeafrefInTypedefModuleReferToLeafListInInputOfRpc.yang"); | ||
504 | + | ||
505 | + // Check whether the data model tree returned is of type module. | ||
506 | + assertThat((node instanceof YangModule), is(true)); | ||
507 | + | ||
508 | + // Check whether the node type is set properly to module. | ||
509 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
510 | + | ||
511 | + // Check whether the module name is set correctly. | ||
512 | + YangModule yangNode = (YangModule) node; | ||
513 | + assertThat(yangNode.getName(), is("ietf-network")); | ||
514 | + | ||
515 | + YangInput yangInput = (YangInput) yangNode.getChild().getChild(); | ||
516 | + | ||
517 | + ListIterator<YangLeafList> leafListIterator; | ||
518 | + YangLeafList yangLeafListInfo; | ||
519 | + leafListIterator = yangInput.getListOfLeafList().listIterator(); | ||
520 | + yangLeafListInfo = leafListIterator.next(); | ||
521 | + | ||
522 | + // Check whether the information in the leaf is correct under grouping. | ||
523 | + assertThat(yangLeafListInfo.getName(), is("network-id")); | ||
524 | + assertThat(yangLeafListInfo.getDataType().getDataType(), is(YangDataTypes.LEAFREF)); | ||
525 | + | ||
526 | + YangLeafRef leafref = (YangLeafRef) (yangLeafListInfo.getDataType().getDataTypeExtendedInfo()); | ||
527 | + | ||
528 | + // Check whether leafref type got resolved. | ||
529 | + assertThat(leafref.getResolvableStatus(), | ||
530 | + is(ResolvableStatus.RESOLVED)); | ||
531 | + | ||
532 | + // Check the effective type for the leaf. | ||
533 | + assertThat(leafref.getEffectiveDataType().getDataType(), | ||
534 | + is(YangDataTypes.UINT8)); | ||
535 | + } | ||
536 | + | ||
537 | + /** | ||
538 | + * Checks self resolution when leafref of leaf-list under module refers to invalid node. | ||
539 | + * Inter file linking also has to be done to know the error message. | ||
540 | + */ | ||
541 | + @Test | ||
542 | + public void processSelfResolutionWhenLeafrefInTypedefIsInDeepTreeAndLeafListIsInModuleWithReferredTypeEnumeration() | ||
543 | + throws IOException, ParserException { | ||
544 | + | ||
545 | + YangNode node = manager.getDataModel( | ||
546 | + "src/test/resources/" + | ||
547 | + "SelfResolutionWhenLeafrefInTypedefIs" + | ||
548 | + "InDeepTreeAndLeafListIsInModuleWithReferredTypeEnumeration.yang"); | ||
549 | + // Check whether the data model tree returned is of type module. | ||
550 | + assertThat((node instanceof YangModule), is(true)); | ||
551 | + | ||
552 | + // Check whether the node type is set properly to module. | ||
553 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
554 | + | ||
555 | + // Check whether the module name is set correctly. | ||
556 | + YangModule yangNode = (YangModule) node; | ||
557 | + assertThat(yangNode.getName(), is("Test")); | ||
558 | + | ||
559 | + YangContainer yangContainer = (YangContainer) yangNode.getChild().getChild().getChild().getNextSibling(); | ||
560 | + | ||
561 | + ListIterator<YangLeaf> leafIterator; | ||
562 | + YangLeaf yangLeafInfo; | ||
563 | + leafIterator = yangContainer.getListOfLeaf().listIterator(); | ||
564 | + yangLeafInfo = leafIterator.next(); | ||
565 | + | ||
566 | + // Check whether the information in the leaf is correct under grouping. | ||
567 | + assertThat(yangLeafInfo.getName(), is("interval")); | ||
568 | + assertThat(yangLeafInfo.getDataType().getDataType(), is(YangDataTypes.LEAFREF)); | ||
569 | + | ||
570 | + YangLeafRef leafref = (YangLeafRef) (yangLeafInfo.getDataType().getDataTypeExtendedInfo()); | ||
571 | + | ||
572 | + // Check whether leafref type got resolved. | ||
573 | + assertThat(leafref.getResolvableStatus(), | ||
574 | + is(ResolvableStatus.RESOLVED)); | ||
575 | + | ||
576 | + // Check the effective type for the leaf. | ||
577 | + assertThat(leafref.getEffectiveDataType().getDataType(), | ||
578 | + is(YangDataTypes.ENUMERATION)); | ||
579 | + } | ||
580 | + | ||
581 | + /** | ||
582 | + * Checks self resolution when grouping and uses are siblings. | ||
583 | + * Grouping followed by uses. | ||
584 | + */ | ||
585 | + @Test | ||
586 | + public void processSelfResolutionWhenLeafrefRefersAnotherLeafref() | ||
587 | + throws IOException, ParserException { | ||
588 | + | ||
589 | + YangNode node = manager.getDataModel("src/test/resources/SelfResolutionWhenLeafrefReferToAnotherLeafref.yang"); | ||
590 | + // Check whether the data model tree returned is of type module. | ||
591 | + assertThat((node instanceof YangModule), is(true)); | ||
592 | + | ||
593 | + // Check whether the node type is set properly to module. | ||
594 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
595 | + | ||
596 | + // Check whether the module name is set correctly. | ||
597 | + YangModule yangNode = (YangModule) node; | ||
598 | + assertThat(yangNode.getName(), is("ietf-network")); | ||
599 | + | ||
600 | + ListIterator<YangLeaf> leafIterator; | ||
601 | + YangLeaf leafInfo; | ||
602 | + | ||
603 | + //YangGrouping grouping = (YangGrouping) yangNode.getChild().getNextSibling(); | ||
604 | + leafIterator = yangNode.getListOfLeaf().listIterator(); | ||
605 | + leafInfo = leafIterator.next(); | ||
606 | + | ||
607 | + // Check whether the information in the leaf is correct under grouping. | ||
608 | + assertThat(leafInfo.getName(), is("network-ref")); | ||
609 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("leafref")); | ||
610 | + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.LEAFREF)); | ||
611 | + YangLeafRef leafref = (YangLeafRef) (leafInfo.getDataType().getDataTypeExtendedInfo()); | ||
612 | + | ||
613 | + assertThat(leafref.getResolvableStatus(), | ||
614 | + is(ResolvableStatus.RESOLVED)); | ||
615 | + | ||
616 | + assertThat(leafref.getEffectiveDataType().getDataType(), | ||
617 | + is(YangDataTypes.UINT8)); | ||
618 | + } | ||
619 | + | ||
620 | + /** | ||
621 | + * Checks self resolution when leafref refers to many other leafref. | ||
622 | + */ | ||
623 | + @Test | ||
624 | + public void processSelfResolutionWhenLeafrefReferToMultipleLeafref() | ||
625 | + throws IOException, ParserException { | ||
626 | + | ||
627 | + YangNode node = manager.getDataModel("src/test/resources/SelfResolutionWhenLeafrefReferToMultipleLeafref.yang"); | ||
628 | + // Check whether the data model tree returned is of type module. | ||
629 | + assertThat((node instanceof YangModule), is(true)); | ||
630 | + | ||
631 | + // Check whether the node type is set properly to module. | ||
632 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
633 | + | ||
634 | + // Check whether the module name is set correctly. | ||
635 | + YangModule yangNode = (YangModule) node; | ||
636 | + assertThat(yangNode.getName(), is("Test")); | ||
637 | + | ||
638 | + YangContainer containerInModule = (YangContainer) yangNode.getChild().getNextSibling(); | ||
639 | + YangContainer containerInList = (YangContainer) containerInModule.getChild().getChild(); | ||
640 | + | ||
641 | + ListIterator<YangLeaf> leafIterator; | ||
642 | + YangLeaf leafInfo; | ||
643 | + | ||
644 | + leafIterator = containerInList.getListOfLeaf().listIterator(); | ||
645 | + leafInfo = leafIterator.next(); | ||
646 | + | ||
647 | + // Check whether the information in the leaf is correct under grouping. | ||
648 | + assertThat(leafInfo.getName(), is("remove")); | ||
649 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("leafref")); | ||
650 | + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.LEAFREF)); | ||
651 | + YangLeafRef leafref = (YangLeafRef) (leafInfo.getDataType().getDataTypeExtendedInfo()); | ||
652 | + | ||
653 | + assertThat(leafref.getResolvableStatus(), | ||
654 | + is(ResolvableStatus.RESOLVED)); | ||
655 | + | ||
656 | + assertThat(leafref.getEffectiveDataType().getDataType(), | ||
657 | + is(YangDataTypes.ENUMERATION)); | ||
658 | + } | ||
659 | + | ||
660 | + /** | ||
661 | + * Checks self resolution when grouping and uses are siblings. | ||
662 | + * Grouping followed by uses. | ||
663 | + */ | ||
664 | + @Test | ||
665 | + public void processSelfResolutionWhenLeafrefRefersAnotherDerivedType() | ||
666 | + throws IOException, ParserException { | ||
667 | + | ||
668 | + YangNode node = manager | ||
669 | + .getDataModel("src/test/resources/SelfResolutionWhenLeafrefReferToAnotherDerivedType.yang"); | ||
670 | + // Check whether the data model tree returned is of type module. | ||
671 | + assertThat((node instanceof YangModule), is(true)); | ||
672 | + | ||
673 | + // Check whether the node type is set properly to module. | ||
674 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
675 | + | ||
676 | + // Check whether the module name is set correctly. | ||
677 | + YangModule yangNode = (YangModule) node; | ||
678 | + assertThat(yangNode.getName(), is("ietf-network")); | ||
679 | + | ||
680 | + ListIterator<YangLeaf> leafIterator; | ||
681 | + YangLeaf leafInfo; | ||
682 | + | ||
683 | + //YangGrouping grouping = (YangGrouping) yangNode.getChild().getNextSibling(); | ||
684 | + leafIterator = yangNode.getListOfLeaf().listIterator(); | ||
685 | + leafInfo = leafIterator.next(); | ||
686 | + | ||
687 | + // Check whether the information in the leaf is correct under grouping. | ||
688 | + assertThat(leafInfo.getName(), is("network-ref")); | ||
689 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("leafref")); | ||
690 | + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.LEAFREF)); | ||
691 | + YangLeafRef leafref = (YangLeafRef) (leafInfo.getDataType().getDataTypeExtendedInfo()); | ||
692 | + | ||
693 | + assertThat(leafref.getResolvableStatus(), | ||
694 | + is(ResolvableStatus.RESOLVED)); | ||
695 | + | ||
696 | + assertThat(leafref.getEffectiveDataType().getDataType(), | ||
697 | + is(YangDataTypes.DERIVED)); | ||
698 | + } | ||
699 | + | ||
700 | + /** | ||
701 | + * Checks self resolution when leafref refers to many other leafref. | ||
702 | + */ | ||
703 | + @Test | ||
704 | + public void processSelfResolutionWhenLeafrefReferToMultipleTypedef() | ||
705 | + throws IOException, ParserException { | ||
706 | + | ||
707 | + YangNode node = manager.getDataModel("src/test/resources/SelfResolutionWhenLeafrefReferToMultipleTypedef.yang"); | ||
708 | + // Check whether the data model tree returned is of type module. | ||
709 | + assertThat((node instanceof YangModule), is(true)); | ||
710 | + | ||
711 | + // Check whether the node type is set properly to module. | ||
712 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
713 | + | ||
714 | + // Check whether the module name is set correctly. | ||
715 | + YangModule yangNode = (YangModule) node; | ||
716 | + assertThat(yangNode.getName(), is("Test")); | ||
717 | + | ||
718 | + YangContainer containerInModule = (YangContainer) yangNode.getChild().getNextSibling(); | ||
719 | + YangContainer containerInList = (YangContainer) containerInModule.getChild().getChild(); | ||
720 | + | ||
721 | + ListIterator<YangLeaf> leafIterator; | ||
722 | + YangLeaf leafInfo; | ||
723 | + | ||
724 | + leafIterator = containerInList.getListOfLeaf().listIterator(); | ||
725 | + leafInfo = leafIterator.next(); | ||
726 | + | ||
727 | + // Check whether the information in the leaf is correct under grouping. | ||
728 | + assertThat(leafInfo.getName(), is("remove")); | ||
729 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("leafref")); | ||
730 | + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.LEAFREF)); | ||
731 | + YangLeafRef leafref = (YangLeafRef) (leafInfo.getDataType().getDataTypeExtendedInfo()); | ||
732 | + | ||
733 | + assertThat(leafref.getResolvableStatus(), | ||
734 | + is(ResolvableStatus.RESOLVED)); | ||
735 | + | ||
736 | + assertThat(leafref.getEffectiveDataType().getDataType(), | ||
737 | + is(YangDataTypes.DERIVED)); | ||
738 | + } | ||
739 | + | ||
740 | + /** | ||
741 | + * Checks self resolution when leafref refers to many other leaf with derived type | ||
742 | + * which in turn referring to another leaf. | ||
743 | + */ | ||
744 | + @Test | ||
745 | + public void processSelfResolutionWhenLeafrefReferToDerivedTypeReferringToLeafWithLeafref() | ||
746 | + throws IOException, ParserException { | ||
747 | + | ||
748 | + YangNode node = manager.getDataModel( | ||
749 | + "src/test/resources/SelfResolutionWhenLeafrefReferToDerivedTypeReferringToLeafWithLeafref.yang"); | ||
750 | + // Check whether the data model tree returned is of type module. | ||
751 | + assertThat((node instanceof YangModule), is(true)); | ||
752 | + | ||
753 | + // Check whether the node type is set properly to module. | ||
754 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
755 | + | ||
756 | + // Check whether the module name is set correctly. | ||
757 | + YangModule yangNode = (YangModule) node; | ||
758 | + assertThat(yangNode.getName(), is("Test")); | ||
759 | + | ||
760 | + YangContainer containerInModule = (YangContainer) yangNode.getChild().getNextSibling(); | ||
761 | + YangContainer containerInList = (YangContainer) containerInModule.getChild().getChild(); | ||
762 | + | ||
763 | + ListIterator<YangLeaf> leafIterator; | ||
764 | + YangLeaf leafInfo; | ||
765 | + | ||
766 | + leafIterator = containerInList.getListOfLeaf().listIterator(); | ||
767 | + leafInfo = leafIterator.next(); | ||
768 | + | ||
769 | + // Check whether the information in the leaf is correct under grouping. | ||
770 | + assertThat(leafInfo.getName(), is("remove")); | ||
771 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("leafref")); | ||
772 | + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.LEAFREF)); | ||
773 | + YangLeafRef leafref = (YangLeafRef) leafInfo.getDataType().getDataTypeExtendedInfo(); | ||
774 | + | ||
775 | + assertThat(leafref.getResolvableStatus(), | ||
776 | + is(ResolvableStatus.RESOLVED)); | ||
777 | + | ||
778 | + assertThat(leafref.getEffectiveDataType().getDataType(), | ||
779 | + is(YangDataTypes.ENUMERATION)); | ||
780 | + } | ||
781 | + | ||
782 | + /** | ||
783 | + * Checks self resolution when leafref under module refers to leaf in container with relative path. | ||
784 | + */ | ||
785 | + @Test | ||
786 | + public void processSelfResolutionWhenLeafrefReferToContainerLeafRelPath() | ||
787 | + throws IOException, ParserException { | ||
788 | + | ||
789 | + YangNode node = manager | ||
790 | + .getDataModel("src/test/resources/SelfResolutionWhenLeafrefReferToContainerLeafRelPath.yang"); | ||
791 | + | ||
792 | + // Check whether the data model tree returned is of type module. | ||
793 | + assertThat((node instanceof YangModule), is(true)); | ||
794 | + | ||
795 | + // Check whether the node type is set properly to module. | ||
796 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
797 | + | ||
798 | + // Check whether the module name is set correctly. | ||
799 | + YangModule yangNode = (YangModule) node; | ||
800 | + assertThat(yangNode.getName(), is("ietf-network")); | ||
801 | + | ||
802 | + ListIterator<YangLeaf> leafIterator; | ||
803 | + YangLeaf leafInfo; | ||
804 | + | ||
805 | + leafIterator = yangNode.getListOfLeaf().listIterator(); | ||
806 | + leafInfo = leafIterator.next(); | ||
807 | + | ||
808 | + // Check whether the information in the leaf is correct. | ||
809 | + assertThat(leafInfo.getName(), is("network-ref")); | ||
810 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("leafref")); | ||
811 | + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.LEAFREF)); | ||
812 | + YangLeafRef leafref = (YangLeafRef) (leafInfo.getDataType().getDataTypeExtendedInfo()); | ||
813 | + | ||
814 | + // Check whether leafref type got resolved. | ||
815 | + assertThat(leafref.getResolvableStatus(), | ||
816 | + is(ResolvableStatus.RESOLVED)); | ||
817 | + | ||
818 | + // Check the effective type for the leaf. | ||
819 | + assertThat(leafref.getEffectiveDataType().getDataType(), | ||
820 | + is(YangDataTypes.UINT8)); | ||
821 | + } | ||
822 | + | ||
823 | + /** | ||
824 | + * Checks self resolution when leafref under module refers to grouping rpc with input as name. | ||
825 | + * Rpc has input child also. So here the node search must be done by taking input node using relative path. | ||
826 | + */ | ||
827 | + @Test | ||
828 | + public void processSelfResolutionWhenLeafrefInModuleReferToGroupingWithInputInRpcRelPath() | ||
829 | + throws IOException, ParserException { | ||
830 | + | ||
831 | + YangNode node = manager.getDataModel( | ||
832 | + "src/test/resources/SelfResolutionWhenLeafrefInModuleReferToGroupingWithInputInRpcRelPath.yang"); | ||
833 | + | ||
834 | + // Check whether the data model tree returned is of type module. | ||
835 | + assertThat((node instanceof YangModule), is(true)); | ||
836 | + | ||
837 | + // Check whether the node type is set properly to module. | ||
838 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
839 | + | ||
840 | + // Check whether the module name is set correctly. | ||
841 | + YangModule yangNode = (YangModule) node; | ||
842 | + assertThat(yangNode.getName(), is("ietf-network")); | ||
843 | + | ||
844 | + ListIterator<YangLeaf> leafIterator; | ||
845 | + YangLeaf leafInfo; | ||
846 | + | ||
847 | + leafIterator = yangNode.getListOfLeaf().listIterator(); | ||
848 | + leafInfo = leafIterator.next(); | ||
849 | + | ||
850 | + // Check whether the information in the leaf is correct. | ||
851 | + assertThat(leafInfo.getName(), is("network-ref")); | ||
852 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("leafref")); | ||
853 | + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.LEAFREF)); | ||
854 | + YangLeafRef leafref = (YangLeafRef) (leafInfo.getDataType().getDataTypeExtendedInfo()); | ||
855 | + | ||
856 | + // Check whether leafref type got resolved. | ||
857 | + assertThat(leafref.getResolvableStatus(), | ||
858 | + is(ResolvableStatus.RESOLVED)); | ||
859 | + | ||
860 | + // Check the effective type for the leaf. | ||
861 | + assertThat(leafref.getEffectiveDataType().getDataType(), | ||
862 | + is(YangDataTypes.UINT8)); | ||
863 | + } | ||
864 | + | ||
865 | + /** | ||
866 | + * Checks self resolution when leafref under module refers to invalid root node with relative path. | ||
867 | + */ | ||
868 | + @Test | ||
869 | + public void processSelfResolutionWhenLeafrefInModuleReferToInvalidRootNodeRelPath() | ||
870 | + throws IOException, ParserException { | ||
871 | + | ||
872 | + thrown.expect(LinkerException.class); | ||
873 | + thrown.expectMessage( | ||
874 | + "YANG file error: The target node of leafref is invalid."); | ||
875 | + YangNode node = manager | ||
876 | + .getDataModel("src/test/resources/SelfResolutionWhenLeafrefInModuleReferToInvalidRootNodeRelPath.yang"); | ||
877 | + } | ||
878 | + | ||
879 | + /** | ||
880 | + * Checks self resolution when leafref under module refers to invalid node. | ||
881 | + * Inter file linking also has to be done to know the error message with relative path. | ||
882 | + */ | ||
883 | + @Test | ||
884 | + public void processSelfResolutionWhenLeafrefInModuleReferToInvalidNodeRelPath() | ||
885 | + throws IOException, ParserException { | ||
886 | + | ||
887 | + YangNode node = manager | ||
888 | + .getDataModel("src/test/resources/SelfResolutionWhenLeafrefInModuleReferToInvalidNodeRelPath.yang"); | ||
889 | + // Check whether the data model tree returned is of type module. | ||
890 | + assertThat((node instanceof YangModule), is(true)); | ||
891 | + | ||
892 | + // Check whether the node type is set properly to module. | ||
893 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
894 | + | ||
895 | + // Check whether the module name is set correctly. | ||
896 | + YangModule yangNode = (YangModule) node; | ||
897 | + assertThat(yangNode.getName(), is("ietf-network")); | ||
898 | + | ||
899 | + ListIterator<YangLeaf> leafIterator; | ||
900 | + YangLeaf leafInfo; | ||
901 | + | ||
902 | + leafIterator = yangNode.getListOfLeaf().listIterator(); | ||
903 | + leafInfo = leafIterator.next(); | ||
904 | + | ||
905 | + // Check whether the information in the leaf is correct. | ||
906 | + assertThat(leafInfo.getName(), is("network-ref")); | ||
907 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("leafref")); | ||
908 | + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.LEAFREF)); | ||
909 | + YangLeafRef leafref = (YangLeafRef) (leafInfo.getDataType().getDataTypeExtendedInfo()); | ||
910 | + | ||
911 | + // Check whether leafref type got intra file resolved. | ||
912 | + assertThat(leafref.getResolvableStatus(), | ||
913 | + is(ResolvableStatus.INTRA_FILE_RESOLVED)); | ||
914 | + } | ||
915 | + | ||
916 | + /** | ||
917 | + * Checks self resolution when leafref of leaf-list under module refers to leaf in container with relative path. | ||
918 | + */ | ||
919 | + @Test | ||
920 | + public void processSelfResolutionWhenLeafrefInTypedefReferToContainerRelPath() | ||
921 | + throws IOException, ParserException { | ||
922 | + | ||
923 | + YangNode node = manager | ||
924 | + .getDataModel("src/test/resources/SelfResolutionWhenLeafrefInTypedefReferToContainerRelPath.yang"); | ||
925 | + | ||
926 | + // Check whether the data model tree returned is of type module. | ||
927 | + assertThat((node instanceof YangModule), is(true)); | ||
928 | + | ||
929 | + // Check whether the node type is set properly to module. | ||
930 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
931 | + | ||
932 | + // Check whether the module name is set correctly. | ||
933 | + YangModule yangNode = (YangModule) node; | ||
934 | + assertThat(yangNode.getName(), is("ietf-network")); | ||
935 | + ListIterator<YangLeaf> leafIterator; | ||
936 | + YangLeaf leafInfo; | ||
937 | + YangContainer yangContainer = (YangContainer) yangNode.getChild(); | ||
938 | + leafIterator = yangContainer.getListOfLeaf().listIterator(); | ||
939 | + leafInfo = leafIterator.next(); | ||
940 | + | ||
941 | + // Check whether the information in the leaf is correct under grouping. | ||
942 | + assertThat(leafInfo.getName(), is("network-id")); | ||
943 | + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.LEAFREF)); | ||
944 | + | ||
945 | + YangLeafRef leafref = (YangLeafRef) (leafInfo.getDataType().getDataTypeExtendedInfo()); | ||
946 | + | ||
947 | + // Check whether leafref type got resolved. | ||
948 | + assertThat(leafref.getResolvableStatus(), | ||
949 | + is(ResolvableStatus.RESOLVED)); | ||
950 | + | ||
951 | + // Check the effective type for the leaf. | ||
952 | + assertThat(leafref.getEffectiveDataType().getDataType(), | ||
953 | + is(YangDataTypes.UINT8)); | ||
954 | + } | ||
955 | + | ||
956 | + /** | ||
957 | + * Checks self resolution when leafref refers to many other leafref with relative path. | ||
958 | + */ | ||
959 | + @Test | ||
960 | + public void processSelfResolutionWhenLeafrefReferToMultipleLeafrefRelPath() | ||
961 | + throws IOException, ParserException { | ||
962 | + | ||
963 | + YangNode node = manager | ||
964 | + .getDataModel("src/test/resources/SelfResolutionWhenLeafrefReferToMultipleLeafrefRelPath.yang"); | ||
965 | + // Check whether the data model tree returned is of type module. | ||
966 | + assertThat((node instanceof YangModule), is(true)); | ||
967 | + | ||
968 | + // Check whether the node type is set properly to module. | ||
969 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
970 | + | ||
971 | + // Check whether the module name is set correctly. | ||
972 | + YangModule yangNode = (YangModule) node; | ||
973 | + assertThat(yangNode.getName(), is("Test")); | ||
974 | + | ||
975 | + YangContainer containerInModule = (YangContainer) yangNode.getChild().getNextSibling(); | ||
976 | + YangContainer containerInList = (YangContainer) containerInModule.getChild().getChild(); | ||
977 | + | ||
978 | + ListIterator<YangLeaf> leafIterator; | ||
979 | + YangLeaf leafInfo; | ||
980 | + | ||
981 | + leafIterator = containerInList.getListOfLeaf().listIterator(); | ||
982 | + leafInfo = leafIterator.next(); | ||
983 | + | ||
984 | + // Check whether the information in the leaf is correct under grouping. | ||
985 | + assertThat(leafInfo.getName(), is("remove")); | ||
986 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("leafref")); | ||
987 | + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.LEAFREF)); | ||
988 | + YangLeafRef leafref = (YangLeafRef) (leafInfo.getDataType().getDataTypeExtendedInfo()); | ||
989 | + | ||
990 | + assertThat(leafref.getResolvableStatus(), | ||
991 | + is(ResolvableStatus.RESOLVED)); | ||
992 | + | ||
993 | + assertThat(leafref.getEffectiveDataType().getDataType(), | ||
994 | + is(YangDataTypes.ENUMERATION)); | ||
995 | + } | ||
996 | + | ||
997 | + /** | ||
998 | + * Checks self resolution when leafref refers to many other leaf with derived type | ||
999 | + * which in turn referring to another leaf with relative type. | ||
1000 | + */ | ||
1001 | + @Test | ||
1002 | + public void processSelfResolutionWhenLeafrefReferToDerivedTypeReferringToLeafWithLeafrefRelType() | ||
1003 | + throws IOException, ParserException { | ||
1004 | + | ||
1005 | + YangNode node = manager.getDataModel( | ||
1006 | + "src/test/resources/SelfResolutionWhenLeafrefReferToDerivedTypeReferringToLeafWithLeafrefRelType.yang"); | ||
1007 | + // Check whether the data model tree returned is of type module. | ||
1008 | + assertThat((node instanceof YangModule), is(true)); | ||
1009 | + | ||
1010 | + // Check whether the node type is set properly to module. | ||
1011 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
1012 | + | ||
1013 | + // Check whether the module name is set correctly. | ||
1014 | + YangModule yangNode = (YangModule) node; | ||
1015 | + assertThat(yangNode.getName(), is("Test")); | ||
1016 | + | ||
1017 | + YangContainer containerInModule = (YangContainer) yangNode.getChild().getNextSibling(); | ||
1018 | + YangContainer containerInList = (YangContainer) containerInModule.getChild().getChild(); | ||
1019 | + | ||
1020 | + ListIterator<YangLeaf> leafIterator; | ||
1021 | + YangLeaf leafInfo; | ||
1022 | + | ||
1023 | + leafIterator = containerInList.getListOfLeaf().listIterator(); | ||
1024 | + leafInfo = leafIterator.next(); | ||
1025 | + | ||
1026 | + // Check whether the information in the leaf is correct under grouping. | ||
1027 | + assertThat(leafInfo.getName(), is("remove")); | ||
1028 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("leafref")); | ||
1029 | + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.LEAFREF)); | ||
1030 | + YangLeafRef leafref = (YangLeafRef) leafInfo.getDataType().getDataTypeExtendedInfo(); | ||
1031 | + | ||
1032 | + assertThat(leafref.getResolvableStatus(), | ||
1033 | + is(ResolvableStatus.RESOLVED)); | ||
1034 | + | ||
1035 | + assertThat(leafref.getEffectiveDataType().getDataType(), | ||
1036 | + is(YangDataTypes.ENUMERATION)); | ||
1037 | + } | ||
1038 | + | ||
1039 | + /** | ||
1040 | + * Checks the valid scenerios of path argument having proper setters. | ||
1041 | + */ | ||
1042 | + @Test | ||
1043 | + public void processPathArgumentStatement() | ||
1044 | + throws IOException, ParserException { | ||
1045 | + | ||
1046 | + YangNode node = manager.getDataModel("src/test/resources/PathListener.yang"); | ||
1047 | + // Check whether the data model tree returned is of type module. | ||
1048 | + assertThat((node instanceof YangModule), is(true)); | ||
1049 | + | ||
1050 | + // Check whether the node type is set properly to module. | ||
1051 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
1052 | + | ||
1053 | + // Check whether the module name is set correctly. | ||
1054 | + YangModule yangNode = (YangModule) node; | ||
1055 | + assertThat(yangNode.getName(), is("PathListener")); | ||
1056 | + YangList listInModule = (YangList) yangNode.getChild(); | ||
1057 | + | ||
1058 | + YangContainer containerInModule = (YangContainer) yangNode.getChild().getNextSibling(); | ||
1059 | + ListIterator<YangLeaf> leafIterator; | ||
1060 | + YangLeaf leafInfo; | ||
1061 | + | ||
1062 | + YangLeaf leafNameInList = listInModule.getListOfLeaf().listIterator().next(); | ||
1063 | + | ||
1064 | + leafIterator = containerInModule.getListOfLeaf().listIterator(); | ||
1065 | + leafInfo = leafIterator.next(); | ||
1066 | + | ||
1067 | + // Check whether the information in the leaf is correct under grouping. | ||
1068 | + assertThat(leafInfo.getName(), is("ifname")); | ||
1069 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("leafref")); | ||
1070 | + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.LEAFREF)); | ||
1071 | + YangLeafRef leafref = (YangLeafRef) leafInfo.getDataType().getDataTypeExtendedInfo(); | ||
1072 | + assertThat(leafref.getPathType(), is(YangPathArgType.RELATIVE_PATH)); | ||
1073 | + | ||
1074 | + YangRelativePath relativePathForName = leafref.getRelativePath(); | ||
1075 | + assertThat(relativePathForName.getAncestorNodeCount(), is(2)); | ||
1076 | + List<YangAtomicPath> absPathForName = relativePathForName.getAtomicPathList(); | ||
1077 | + Iterator<YangAtomicPath> absPathIteratorForName = absPathForName.listIterator(); | ||
1078 | + YangAtomicPath abspathForName = absPathIteratorForName.next(); | ||
1079 | + assertThat(abspathForName.getNodeIdentifier().getName(), is("interface")); | ||
1080 | + assertThat(abspathForName.getNodeIdentifier().getPrefix(), is("test")); | ||
1081 | + YangAtomicPath abspath1 = absPathIteratorForName.next(); | ||
1082 | + assertThat(abspath1.getNodeIdentifier().getName(), is("name")); | ||
1083 | + assertThat(abspath1.getNodeIdentifier().getPrefix(), is("test")); | ||
1084 | + | ||
1085 | + YangLeaf leafInfo1 = leafIterator.next(); | ||
1086 | + // Check whether the information in the leaf is correct under grouping. | ||
1087 | + assertThat(leafInfo1.getName(), is("status")); | ||
1088 | + assertThat(leafInfo1.getDataType().getDataTypeName(), is("leafref")); | ||
1089 | + assertThat(leafInfo1.getDataType().getDataType(), is(YangDataTypes.LEAFREF)); | ||
1090 | + | ||
1091 | + YangLeafRef leafref1 = (YangLeafRef) leafInfo1.getDataType().getDataTypeExtendedInfo(); | ||
1092 | + assertThat(leafref1.getPathType(), is(YangPathArgType.ABSOLUTE_PATH)); | ||
1093 | + | ||
1094 | + List<YangAtomicPath> absolutePathList = leafref1.getAtomicPath(); | ||
1095 | + Iterator<YangAtomicPath> absPathIterator = absolutePathList.listIterator(); | ||
1096 | + YangAtomicPath abspath = absPathIterator.next(); | ||
1097 | + assertThat(abspath.getNodeIdentifier().getName(), is("interface")); | ||
1098 | + assertThat(abspath.getNodeIdentifier().getPrefix(), is("test")); | ||
1099 | + | ||
1100 | + List<YangPathPredicate> pathPredicateList = abspath.getPathPredicatesList(); | ||
1101 | + Iterator<YangPathPredicate> pathPredicate = pathPredicateList.listIterator(); | ||
1102 | + YangPathPredicate pathPredicate1 = pathPredicate.next(); | ||
1103 | + assertThat(pathPredicate1.getNodeIdentifier().getName(), is("name")); | ||
1104 | + assertThat(pathPredicate1.getNodeIdentifier().getPrefix(), nullValue()); | ||
1105 | + assertThat(pathPredicate1.getRightRelativePath().getAncestorNodeCount(), is(1)); | ||
1106 | + assertThat(pathPredicate1.getPathOperator(), is(YangPathOperator.EQUALTO)); | ||
1107 | + assertThat(pathPredicate1.getRightRelativePath().getAtomicPathList().listIterator().next().getNodeIdentifier() | ||
1108 | + .getName(), is("ifname")); | ||
1109 | + YangAtomicPath abspath2 = absPathIterator.next(); | ||
1110 | + assertThat(abspath2.getNodeIdentifier().getName(), is("admin-status")); | ||
1111 | + assertThat(abspath2.getNodeIdentifier().getPrefix(), is("test")); | ||
1112 | + | ||
1113 | + assertThat(pathPredicate1.getLeftAxisNode(), is(leafNameInList)); | ||
1114 | + assertThat(pathPredicate1.getRightAxisNode(), is(leafInfo)); | ||
1115 | + } | ||
1116 | +} |
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 | + 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 |
utils/yangutils/plugin/src/test/resources/SelfFileLinkingWithFeatureReferredByLeafref.yang
0 → 100644
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 | +} |
utils/yangutils/plugin/src/test/resources/SelfFileLinkingWithFeatureReferredByMultiLeafref.yang
0 → 100644
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 | +} |
utils/yangutils/plugin/src/test/resources/SelfResolutionWhenLeafrefDoesNotReferToLeafOrLeafList.yang
0 → 100644
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 |
utils/yangutils/plugin/src/test/resources/SelfResolutionWhenLeafrefInModuleReferToGrouping.yang
0 → 100644
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 |
utils/yangutils/plugin/src/test/resources/SelfResolutionWhenLeafrefInModuleReferToInvalidNode.yang
0 → 100644
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 |
utils/yangutils/plugin/src/test/resources/SelfResolutionWhenLeafrefInTypedefReferToContainer.yang
0 → 100644
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 | +} |
utils/yangutils/plugin/src/test/resources/SelfResolutionWhenLeafrefReferToAnotherDerivedType.yang
0 → 100644
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 |
utils/yangutils/plugin/src/test/resources/SelfResolutionWhenLeafrefReferToAnotherLeafref.yang
0 → 100644
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 |
utils/yangutils/plugin/src/test/resources/SelfResolutionWhenLeafrefReferToContainerLeaf.yang
0 → 100644
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 |
utils/yangutils/plugin/src/test/resources/SelfResolutionWhenLeafrefReferToContainerLeafList.yang
0 → 100644
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 |
utils/yangutils/plugin/src/test/resources/SelfResolutionWhenLeafrefReferToContainerLeafRelPath.yang
0 → 100644
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 | +} |
utils/yangutils/plugin/src/test/resources/SelfResolutionWhenLeafrefReferToMultipleLeafref.yang
0 → 100644
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 | +} |
utils/yangutils/plugin/src/test/resources/SelfResolutionWhenLeafrefReferToMultipleTypedef.yang
0 → 100644
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 |
utils/yangutils/plugin/src/test/resources/interfileleafreffromgroupingreferstootherfile/module1.yang
0 → 100644
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 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 |
-
Please register or login to post a comment