Committed by
Patrick Liu
[ONOS-4842] Leafref implementation for augment and uses
Change-Id: I919553a64d683aff65a8f16e2de783702dd5a45f
Showing
89 changed files
with
3645 additions
and
1464 deletions
... | @@ -22,8 +22,10 @@ import org.onosproject.yangutils.datamodel.utils.ResolvableStatus; | ... | @@ -22,8 +22,10 @@ import org.onosproject.yangutils.datamodel.utils.ResolvableStatus; |
22 | /** | 22 | /** |
23 | * Abstraction of YANG resolvable information. Abstracted to obtain the | 23 | * Abstraction of YANG resolvable information. Abstracted to obtain the |
24 | * information required for linking resolution. | 24 | * information required for linking resolution. |
25 | + * | ||
26 | + * @param <T> YANG resolvable info | ||
25 | */ | 27 | */ |
26 | -public interface Resolvable { | 28 | +public interface Resolvable<T> { |
27 | 29 | ||
28 | /** | 30 | /** |
29 | * Returns the status of resolution. If completely resolved returns enum | 31 | * Returns the status of resolution. If completely resolved returns enum |
... | @@ -48,8 +50,9 @@ public interface Resolvable { | ... | @@ -48,8 +50,9 @@ public interface Resolvable { |
48 | /** | 50 | /** |
49 | * Resolves the linking. | 51 | * Resolves the linking. |
50 | * | 52 | * |
53 | + * @return list of entities to be added for resolution | ||
51 | * @throws DataModelException data model exception | 54 | * @throws DataModelException data model exception |
52 | */ | 55 | */ |
53 | - void resolve() | 56 | + T resolve() |
54 | throws DataModelException; | 57 | throws DataModelException; |
55 | } | 58 | } | ... | ... |
... | @@ -442,8 +442,9 @@ public class YangAugment | ... | @@ -442,8 +442,9 @@ public class YangAugment |
442 | } | 442 | } |
443 | 443 | ||
444 | @Override | 444 | @Override |
445 | - public void resolve() throws DataModelException { | 445 | + public Object resolve() throws DataModelException { |
446 | // Resolving of target node is being done in XPathLinker. | 446 | // Resolving of target node is being done in XPathLinker. |
447 | + return null; | ||
447 | } | 448 | } |
448 | 449 | ||
449 | /** | 450 | /** | ... | ... |
... | @@ -109,6 +109,7 @@ import java.io.Serializable; | ... | @@ -109,6 +109,7 @@ import java.io.Serializable; |
109 | } | 109 | } |
110 | 110 | ||
111 | @Override | 111 | @Override |
112 | - public void resolve() throws DataModelException { | 112 | + public Object resolve() throws DataModelException { |
113 | + return null; | ||
113 | } | 114 | } |
114 | } | 115 | } | ... | ... |
... | @@ -18,6 +18,7 @@ package org.onosproject.yangutils.datamodel; | ... | @@ -18,6 +18,7 @@ package org.onosproject.yangutils.datamodel; |
18 | import java.util.ArrayList; | 18 | import java.util.ArrayList; |
19 | import java.util.LinkedList; | 19 | import java.util.LinkedList; |
20 | import java.util.List; | 20 | import java.util.List; |
21 | + | ||
21 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | 22 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
22 | import org.onosproject.yangutils.datamodel.utils.Parsable; | 23 | import org.onosproject.yangutils.datamodel.utils.Parsable; |
23 | import org.onosproject.yangutils.datamodel.utils.YangConstructType; | 24 | import org.onosproject.yangutils.datamodel.utils.YangConstructType; | ... | ... |
... | @@ -13,34 +13,39 @@ | ... | @@ -13,34 +13,39 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.yangutils.linker.impl; | 16 | +package org.onosproject.yangutils.datamodel; |
17 | 17 | ||
18 | import java.io.Serializable; | 18 | import java.io.Serializable; |
19 | 19 | ||
20 | -import org.onosproject.yangutils.datamodel.YangEntityToResolveInfo; | ||
21 | -import org.onosproject.yangutils.datamodel.YangIfFeature; | ||
22 | -import org.onosproject.yangutils.datamodel.YangBase; | ||
23 | -import org.onosproject.yangutils.datamodel.YangIdentityRef; | ||
24 | -import org.onosproject.yangutils.datamodel.YangNode; | ||
25 | -import org.onosproject.yangutils.datamodel.YangType; | ||
26 | -import org.onosproject.yangutils.datamodel.YangUses; | ||
27 | -import org.onosproject.yangutils.linker.exceptions.LinkerException; | ||
28 | - | ||
29 | /** | 20 | /** |
30 | * Represents implementation of information about entity being resolved. | 21 | * Represents implementation of information about entity being resolved. |
31 | * | 22 | * |
32 | * @param <T> type of entity being resolved, uses / grouping | 23 | * @param <T> type of entity being resolved, uses / grouping |
33 | */ | 24 | */ |
34 | -public class YangEntityToResolveInfoImpl<T> implements YangEntityToResolveInfo<T>, Serializable { | 25 | +public class YangEntityToResolveInfoImpl<T> implements YangEntityToResolveInfo<T>, Serializable, LocationInfo { |
35 | 26 | ||
36 | private static final long serialVersionUID = 806201659L; | 27 | private static final long serialVersionUID = 806201659L; |
37 | 28 | ||
38 | - // Parsable node for which resolution is to be performed. | 29 | + /** |
30 | + * Parsable node for which resolution is to be performed. | ||
31 | + */ | ||
39 | private T entityToResolve; | 32 | private T entityToResolve; |
40 | 33 | ||
41 | - // Holder of the YANG construct for which resolution has to be carried out. | 34 | + /** |
35 | + * Holder of the YANG construct for which resolution has to be carried out. | ||
36 | + */ | ||
42 | private YangNode holderOfEntityToResolve; | 37 | private YangNode holderOfEntityToResolve; |
43 | 38 | ||
39 | + /** | ||
40 | + * Error line number. | ||
41 | + */ | ||
42 | + private transient int lineNumber; | ||
43 | + | ||
44 | + /** | ||
45 | + * Error character position in number. | ||
46 | + */ | ||
47 | + private transient int charPositionInLine; | ||
48 | + | ||
44 | @Override | 49 | @Override |
45 | public T getEntityToResolve() { | 50 | public T getEntityToResolve() { |
46 | return entityToResolve; | 51 | return entityToResolve; |
... | @@ -61,33 +66,23 @@ public class YangEntityToResolveInfoImpl<T> implements YangEntityToResolveInfo<T | ... | @@ -61,33 +66,23 @@ public class YangEntityToResolveInfoImpl<T> implements YangEntityToResolveInfo<T |
61 | this.holderOfEntityToResolve = holderOfEntityToResolve; | 66 | this.holderOfEntityToResolve = holderOfEntityToResolve; |
62 | } | 67 | } |
63 | 68 | ||
64 | - /** | 69 | + @Override |
65 | - * Retrieves the prefix of the entity. | 70 | + public int getLineNumber() { |
66 | - * | 71 | + return lineNumber; |
67 | - * @return entities prefix | 72 | + } |
68 | - * @throws LinkerException linker error | ||
69 | - */ | ||
70 | - public String getEntityPrefix() | ||
71 | - throws LinkerException { | ||
72 | - if (getEntityToResolve() == null) { | ||
73 | - return null; | ||
74 | - } | ||
75 | 73 | ||
76 | - String prefix; | 74 | + @Override |
77 | - T entityToBeResolved = getEntityToResolve(); | 75 | + public int getCharPosition() { |
78 | - if (entityToBeResolved instanceof YangType) { | 76 | + return charPositionInLine; |
79 | - prefix = ((YangType<?>) entityToBeResolved).getPrefix(); | 77 | + } |
80 | - } else if (entityToBeResolved instanceof YangUses) { | 78 | + |
81 | - prefix = ((YangUses) entityToBeResolved).getPrefix(); | 79 | + @Override |
82 | - } else if (entityToBeResolved instanceof YangIfFeature) { | 80 | + public void setLineNumber(int lineNumber) { |
83 | - prefix = ((YangIfFeature) entityToBeResolved).getPrefix(); | 81 | + this.lineNumber = lineNumber; |
84 | - } else if (entityToBeResolved instanceof YangBase) { | 82 | + } |
85 | - prefix = ((YangBase) entityToBeResolved).getBaseIdentifier().getPrefix(); | 83 | + |
86 | - } else if (entityToBeResolved instanceof YangIdentityRef) { | 84 | + @Override |
87 | - prefix = ((YangIdentityRef) entityToBeResolved).getBaseIdentity().getPrefix(); | 85 | + public void setCharPosition(int charPositionInLine) { |
88 | - } else { | 86 | + this.charPositionInLine = charPositionInLine; |
89 | - throw new LinkerException("Linker Exception: Entity to resolved is other than type/uses"); | ||
90 | - } | ||
91 | - return prefix; | ||
92 | } | 87 | } |
93 | } | 88 | } | ... | ... |
... | @@ -80,7 +80,7 @@ public class YangIdentityRef extends YangNode implements Parsable, Resolvable, S | ... | @@ -80,7 +80,7 @@ public class YangIdentityRef extends YangNode implements Parsable, Resolvable, S |
80 | } | 80 | } |
81 | 81 | ||
82 | @Override | 82 | @Override |
83 | - public void resolve() throws DataModelException { | 83 | + public Object resolve() throws DataModelException { |
84 | 84 | ||
85 | // Check if the derived info is present. | 85 | // Check if the derived info is present. |
86 | YangIdentity identity = getReferredIdentity(); | 86 | YangIdentity identity = getReferredIdentity(); |
... | @@ -92,10 +92,11 @@ public class YangIdentityRef extends YangNode implements Parsable, Resolvable, S | ... | @@ -92,10 +92,11 @@ public class YangIdentityRef extends YangNode implements Parsable, Resolvable, S |
92 | while (identity.getBaseNode() != null) { | 92 | while (identity.getBaseNode() != null) { |
93 | if (identity.getBaseNode().getResolvableStatus() != ResolvableStatus.RESOLVED) { | 93 | if (identity.getBaseNode().getResolvableStatus() != ResolvableStatus.RESOLVED) { |
94 | setResolvableStatus(ResolvableStatus.INTRA_FILE_RESOLVED); | 94 | setResolvableStatus(ResolvableStatus.INTRA_FILE_RESOLVED); |
95 | - return; | 95 | + return null; |
96 | } | 96 | } |
97 | identity = identity.getBaseNode().getReferredIdentity(); | 97 | identity = identity.getBaseNode().getReferredIdentity(); |
98 | } | 98 | } |
99 | + return null; | ||
99 | } | 100 | } |
100 | 101 | ||
101 | /** | 102 | /** | ... | ... |
... | @@ -170,7 +170,7 @@ public class YangIfFeature implements Parsable, Resolvable, Serializable { | ... | @@ -170,7 +170,7 @@ public class YangIfFeature implements Parsable, Resolvable, Serializable { |
170 | } | 170 | } |
171 | 171 | ||
172 | @Override | 172 | @Override |
173 | - public void resolve() throws DataModelException { | 173 | + public Object resolve() throws DataModelException { |
174 | YangFeature feature = getReferredFeature(); | 174 | YangFeature feature = getReferredFeature(); |
175 | 175 | ||
176 | // check whether feature has if-feature | 176 | // check whether feature has if-feature |
... | @@ -181,9 +181,10 @@ public class YangIfFeature implements Parsable, Resolvable, Serializable { | ... | @@ -181,9 +181,10 @@ public class YangIfFeature implements Parsable, Resolvable, Serializable { |
181 | YangIfFeature ifFeature = ifFeatureIterator.next(); | 181 | YangIfFeature ifFeature = ifFeatureIterator.next(); |
182 | if (ifFeature.getResolvableStatus() != ResolvableStatus.RESOLVED) { | 182 | if (ifFeature.getResolvableStatus() != ResolvableStatus.RESOLVED) { |
183 | setResolvableStatus(ResolvableStatus.INTRA_FILE_RESOLVED); | 183 | setResolvableStatus(ResolvableStatus.INTRA_FILE_RESOLVED); |
184 | - return; | 184 | + return null; |
185 | } | 185 | } |
186 | } | 186 | } |
187 | } | 187 | } |
188 | + return null; | ||
188 | } | 189 | } |
189 | } | 190 | } | ... | ... |
... | @@ -16,17 +16,18 @@ | ... | @@ -16,17 +16,18 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.datamodel; | 17 | package org.onosproject.yangutils.datamodel; |
18 | 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; | 19 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
25 | import org.onosproject.yangutils.datamodel.utils.Parsable; | 20 | import org.onosproject.yangutils.datamodel.utils.Parsable; |
26 | import org.onosproject.yangutils.datamodel.utils.ResolvableStatus; | 21 | import org.onosproject.yangutils.datamodel.utils.ResolvableStatus; |
27 | import org.onosproject.yangutils.datamodel.utils.YangConstructType; | 22 | import org.onosproject.yangutils.datamodel.utils.YangConstructType; |
28 | import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes; | 23 | import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes; |
29 | 24 | ||
25 | +import java.io.Serializable; | ||
26 | +import java.util.Iterator; | ||
27 | +import java.util.LinkedList; | ||
28 | +import java.util.List; | ||
29 | +import java.util.Map; | ||
30 | + | ||
30 | import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.INTRA_FILE_RESOLVED; | 31 | import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.INTRA_FILE_RESOLVED; |
31 | import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.RESOLVED; | 32 | import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.RESOLVED; |
32 | import static org.onosproject.yangutils.datamodel.utils.YangErrMsgConstants.DATA_MISSING_ERROR_TAG; | 33 | import static org.onosproject.yangutils.datamodel.utils.YangErrMsgConstants.DATA_MISSING_ERROR_TAG; |
... | @@ -47,7 +48,7 @@ import static org.onosproject.yangutils.datamodel.utils.YangErrMsgConstants.INST | ... | @@ -47,7 +48,7 @@ import static org.onosproject.yangutils.datamodel.utils.YangErrMsgConstants.INST |
47 | * @param <T> YANG leafref info | 48 | * @param <T> YANG leafref info |
48 | */ | 49 | */ |
49 | public class YangLeafRef<T> implements Parsable, Resolvable, Serializable, YangIfFeatureHolder, | 50 | public class YangLeafRef<T> implements Parsable, Resolvable, Serializable, YangIfFeatureHolder, |
50 | - YangXPathResolver, YangAppErrorHolder { | 51 | + YangXPathResolver, YangAppErrorHolder, LocationInfo { |
51 | 52 | ||
52 | private static final long serialVersionUID = 286201644L; | 53 | private static final long serialVersionUID = 286201644L; |
53 | 54 | ||
... | @@ -100,6 +101,61 @@ public class YangLeafRef<T> implements Parsable, Resolvable, Serializable, YangI | ... | @@ -100,6 +101,61 @@ public class YangLeafRef<T> implements Parsable, Resolvable, Serializable, YangI |
100 | private List<YangIfFeature> ifFeatureList; | 101 | private List<YangIfFeature> ifFeatureList; |
101 | 102 | ||
102 | /** | 103 | /** |
104 | + * Parent node of the leafref's leaf. | ||
105 | + */ | ||
106 | + private YangNode parentNodeOfLeafref; | ||
107 | + | ||
108 | + /** | ||
109 | + * Error line number. | ||
110 | + */ | ||
111 | + private transient int lineNumber; | ||
112 | + | ||
113 | + /** | ||
114 | + * Error character position in number. | ||
115 | + */ | ||
116 | + private transient int charPositionInLine; | ||
117 | + | ||
118 | + /** | ||
119 | + * Prefix in the nodes of the leafref path and its imported node name. | ||
120 | + */ | ||
121 | + private Map<String, String> prefixAndItsImportedModule; | ||
122 | + | ||
123 | + /** | ||
124 | + * Returns the prefix in the leafref path and its imported node name. | ||
125 | + * | ||
126 | + * @return the list of leafref prefix and imported node name | ||
127 | + */ | ||
128 | + public Map<String, String> getPrefixAndItsImportedModule() { | ||
129 | + return prefixAndItsImportedModule; | ||
130 | + } | ||
131 | + | ||
132 | + /** | ||
133 | + * Sets the prefix in the leafref path and its imported node name. | ||
134 | + * | ||
135 | + * @param prefixAndItsImportedModule the list of leafref prefix and imported node name | ||
136 | + */ | ||
137 | + public void setPrefixAndItsImportedModule(Map<String, String> prefixAndItsImportedModule) { | ||
138 | + this.prefixAndItsImportedModule = prefixAndItsImportedModule; | ||
139 | + } | ||
140 | + | ||
141 | + /** | ||
142 | + * Returns the parent node from the leafref's leaf. | ||
143 | + * | ||
144 | + * @return parent node of the leafref | ||
145 | + */ | ||
146 | + public YangNode getParentNodeOfLeafref() { | ||
147 | + return parentNodeOfLeafref; | ||
148 | + } | ||
149 | + | ||
150 | + /** | ||
151 | + * Sets the parent node from the leafref's leaf. | ||
152 | + * | ||
153 | + * @param parentNodeOfLeafref parent node of the leafref | ||
154 | + */ | ||
155 | + public void setParentNodeOfLeafref(YangNode parentNodeOfLeafref) { | ||
156 | + this.parentNodeOfLeafref = parentNodeOfLeafref; | ||
157 | + } | ||
158 | + /** | ||
103 | * YANG application error information. | 159 | * YANG application error information. |
104 | */ | 160 | */ |
105 | private YangAppErrorInfo yangAppErrorInfo; | 161 | private YangAppErrorInfo yangAppErrorInfo; |
... | @@ -294,7 +350,7 @@ public class YangLeafRef<T> implements Parsable, Resolvable, Serializable, YangI | ... | @@ -294,7 +350,7 @@ public class YangLeafRef<T> implements Parsable, Resolvable, Serializable, YangI |
294 | } | 350 | } |
295 | 351 | ||
296 | @Override | 352 | @Override |
297 | - public void resolve() throws DataModelException { | 353 | + public Object resolve() throws DataModelException { |
298 | 354 | ||
299 | if (getReferredLeafOrLeafList() == null) { | 355 | if (getReferredLeafOrLeafList() == null) { |
300 | throw new DataModelException("Linker Error: The leafref does not refer to any leaf/leaf-list."); | 356 | throw new DataModelException("Linker Error: The leafref does not refer to any leaf/leaf-list."); |
... | @@ -306,6 +362,7 @@ public class YangLeafRef<T> implements Parsable, Resolvable, Serializable, YangI | ... | @@ -306,6 +362,7 @@ public class YangLeafRef<T> implements Parsable, Resolvable, Serializable, YangI |
306 | } catch (DataModelException e) { | 362 | } catch (DataModelException e) { |
307 | throw new DataModelException(e.getMessage()); | 363 | throw new DataModelException(e.getMessage()); |
308 | } | 364 | } |
365 | + return null; | ||
309 | } | 366 | } |
310 | 367 | ||
311 | /** | 368 | /** |
... | @@ -443,4 +500,24 @@ public class YangLeafRef<T> implements Parsable, Resolvable, Serializable, YangI | ... | @@ -443,4 +500,24 @@ public class YangLeafRef<T> implements Parsable, Resolvable, Serializable, YangI |
443 | throw new DataModelException("Linker Error: The leafref must refer only to leaf/leaf-list."); | 500 | throw new DataModelException("Linker Error: The leafref must refer only to leaf/leaf-list."); |
444 | } | 501 | } |
445 | } | 502 | } |
503 | + | ||
504 | + @Override | ||
505 | + public int getLineNumber() { | ||
506 | + return lineNumber; | ||
507 | + } | ||
508 | + | ||
509 | + @Override | ||
510 | + public int getCharPosition() { | ||
511 | + return charPositionInLine; | ||
512 | + } | ||
513 | + | ||
514 | + @Override | ||
515 | + public void setLineNumber(int lineNumber) { | ||
516 | + this.lineNumber = lineNumber; | ||
517 | + } | ||
518 | + | ||
519 | + @Override | ||
520 | + public void setCharPosition(int charPositionInLine) { | ||
521 | + this.charPositionInLine = charPositionInLine; | ||
522 | + } | ||
446 | } | 523 | } | ... | ... |
... | @@ -16,15 +16,15 @@ | ... | @@ -16,15 +16,15 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.datamodel; | 17 | package org.onosproject.yangutils.datamodel; |
18 | 18 | ||
19 | -import java.util.ArrayList; | ||
20 | -import java.util.LinkedList; | ||
21 | -import java.util.List; | ||
22 | - | ||
23 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | 19 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
24 | import org.onosproject.yangutils.datamodel.utils.Parsable; | 20 | import org.onosproject.yangutils.datamodel.utils.Parsable; |
25 | import org.onosproject.yangutils.datamodel.utils.YangConstructType; | 21 | import org.onosproject.yangutils.datamodel.utils.YangConstructType; |
26 | import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes; | 22 | import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes; |
27 | 23 | ||
24 | +import java.util.ArrayList; | ||
25 | +import java.util.LinkedList; | ||
26 | +import java.util.List; | ||
27 | + | ||
28 | import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil; | 28 | import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil; |
29 | 29 | ||
30 | /* | 30 | /* |
... | @@ -119,6 +119,26 @@ public class YangList | ... | @@ -119,6 +119,26 @@ public class YangList |
119 | private List<String> keyList; | 119 | private List<String> keyList; |
120 | 120 | ||
121 | /** | 121 | /** |
122 | + * Reference RFC 6020. | ||
123 | + * | ||
124 | + * The "unique" statement is used to put constraints on valid list | ||
125 | + * entries. It takes as an argument a string that contains a space- | ||
126 | + * separated list of schema node identifiers, which MUST be given in the | ||
127 | + * descendant form. Each such schema node identifier MUST refer to a leaf. | ||
128 | + * | ||
129 | + * If one of the referenced leafs represents configuration data, then | ||
130 | + * all of the referenced leafs MUST represent configuration data. | ||
131 | + * | ||
132 | + * The "unique" constraint specifies that the combined values of all the | ||
133 | + * leaf instances specified in the argument string, including leafs with | ||
134 | + * default values, MUST be unique within all list entry instances in | ||
135 | + * which all referenced leafs exist. | ||
136 | + * | ||
137 | + * List of unique leaf/leaf-list names | ||
138 | + */ | ||
139 | + private List<String> uniqueList; | ||
140 | + | ||
141 | + /** | ||
122 | * List of leaves. | 142 | * List of leaves. |
123 | */ | 143 | */ |
124 | private List<YangLeaf> listOfLeaf; | 144 | private List<YangLeaf> listOfLeaf; |
... | @@ -271,6 +291,24 @@ public class YangList | ... | @@ -271,6 +291,24 @@ public class YangList |
271 | } | 291 | } |
272 | 292 | ||
273 | /** | 293 | /** |
294 | + * Returns the list of unique field names. | ||
295 | + * | ||
296 | + * @return the list of unique field names | ||
297 | + */ | ||
298 | + public List<String> getUniqueList() { | ||
299 | + return uniqueList; | ||
300 | + } | ||
301 | + | ||
302 | + /** | ||
303 | + * Sets the list of unique field names. | ||
304 | + * | ||
305 | + * @param uniqueList the list of unique field names | ||
306 | + */ | ||
307 | + private void setUniqueList(List<String> uniqueList) { | ||
308 | + this.uniqueList = uniqueList; | ||
309 | + } | ||
310 | + | ||
311 | + /** | ||
274 | * Returns the list of key field names. | 312 | * Returns the list of key field names. |
275 | * | 313 | * |
276 | * @return the list of key field names | 314 | * @return the list of key field names |
... | @@ -309,6 +347,24 @@ public class YangList | ... | @@ -309,6 +347,24 @@ public class YangList |
309 | } | 347 | } |
310 | 348 | ||
311 | /** | 349 | /** |
350 | + * Adds a unique field name. | ||
351 | + * | ||
352 | + * @param unique unique field name. | ||
353 | + * @throws DataModelException a violation of data model rules | ||
354 | + */ | ||
355 | + public void addUnique(String unique) | ||
356 | + throws DataModelException { | ||
357 | + if (getUniqueList() == null) { | ||
358 | + setUniqueList(new LinkedList<>()); | ||
359 | + } | ||
360 | + if (getUniqueList().contains(unique)) { | ||
361 | + throw new DataModelException("A leaf identifier must not appear more than once in the\n" + | ||
362 | + " unique"); | ||
363 | + } | ||
364 | + getUniqueList().add(unique); | ||
365 | + } | ||
366 | + | ||
367 | + /** | ||
312 | * Returns the list of leaves. | 368 | * Returns the list of leaves. |
313 | * | 369 | * |
314 | * @return the list of leaves | 370 | * @return the list of leaves |
... | @@ -489,11 +545,11 @@ public class YangList | ... | @@ -489,11 +545,11 @@ public class YangList |
489 | validateConfig(leaves, leafLists); | 545 | validateConfig(leaves, leafLists); |
490 | 546 | ||
491 | /* A list must have atleast one key leaf if config is true */ | 547 | /* A list must have atleast one key leaf if config is true */ |
492 | - if (isConfig && (keys == null || leaves == null && leafLists == null) && !isUsesPresentInList() | 548 | + if (isConfig && (keys == null || leaves == null) && !isUsesPresentInList() |
493 | && !isListPresentInGrouping()) { | 549 | && !isListPresentInGrouping()) { |
494 | throw new DataModelException("A list must have atleast one key leaf if config is true;"); | 550 | throw new DataModelException("A list must have atleast one key leaf if config is true;"); |
495 | } else if (keys != null) { | 551 | } else if (keys != null) { |
496 | - validateKey(leaves, leafLists, keys); | 552 | + validateKey(leaves, keys); |
497 | } | 553 | } |
498 | } | 554 | } |
499 | 555 | ||
... | @@ -501,7 +557,7 @@ public class YangList | ... | @@ -501,7 +557,7 @@ public class YangList |
501 | * Sets the config's value to all leaf if leaf's config statement is not | 557 | * Sets the config's value to all leaf if leaf's config statement is not |
502 | * specified. | 558 | * specified. |
503 | * | 559 | * |
504 | - * @param leaves list of leaf attributes of YANG list | 560 | + * @param leaves list of leaf attributes of YANG list |
505 | * @param leafLists list of leaf-list attributes of YANG list | 561 | * @param leafLists list of leaf-list attributes of YANG list |
506 | */ | 562 | */ |
507 | private void setDefaultConfigValueToChild(List<YangLeaf> leaves, List<YangLeafList> leafLists) { | 563 | private void setDefaultConfigValueToChild(List<YangLeaf> leaves, List<YangLeafList> leafLists) { |
... | @@ -534,7 +590,7 @@ public class YangList | ... | @@ -534,7 +590,7 @@ public class YangList |
534 | /** | 590 | /** |
535 | * Validates config statement of YANG list. | 591 | * Validates config statement of YANG list. |
536 | * | 592 | * |
537 | - * @param leaves list of leaf attributes of YANG list | 593 | + * @param leaves list of leaf attributes of YANG list |
538 | * @param leafLists list of leaf-list attributes of YANG list | 594 | * @param leafLists list of leaf-list attributes of YANG list |
539 | * @throws DataModelException a violation of data model rules | 595 | * @throws DataModelException a violation of data model rules |
540 | */ | 596 | */ |
... | @@ -567,16 +623,15 @@ public class YangList | ... | @@ -567,16 +623,15 @@ public class YangList |
567 | /** | 623 | /** |
568 | * Validates key statement of list. | 624 | * Validates key statement of list. |
569 | * | 625 | * |
570 | - * @param leaves list of leaf attributes of list | 626 | + * @param leaves list of leaf attributes of list |
571 | * @param leafLists list of leaf-list attributes of list | 627 | * @param leafLists list of leaf-list attributes of list |
572 | - * @param keys list of key attributes of list | 628 | + * @param keys list of key attributes of list |
573 | * @throws DataModelException a violation of data model rules | 629 | * @throws DataModelException a violation of data model rules |
574 | */ | 630 | */ |
575 | - private void validateKey(List<YangLeaf> leaves, List<YangLeafList> leafLists, List<String> keys) | 631 | + private void validateKey(List<YangLeaf> leaves, List<String> keys) |
576 | throws DataModelException { | 632 | throws DataModelException { |
577 | boolean leafFound = false; | 633 | boolean leafFound = false; |
578 | List<YangLeaf> keyLeaves = new LinkedList<>(); | 634 | List<YangLeaf> keyLeaves = new LinkedList<>(); |
579 | - List<YangLeafList> keyLeafLists = new LinkedList<>(); | ||
580 | 635 | ||
581 | /* | 636 | /* |
582 | * 1. Leaf identifier must refer to a child leaf of the list 2. A leaf | 637 | * 1. Leaf identifier must refer to a child leaf of the list 2. A leaf |
... | @@ -597,20 +652,6 @@ public class YangList | ... | @@ -597,20 +652,6 @@ public class YangList |
597 | } | 652 | } |
598 | } | 653 | } |
599 | 654 | ||
600 | - if (leafLists != null && !leafLists.isEmpty()) { | ||
601 | - for (YangLeafList leafList : leafLists) { | ||
602 | - if (key.equals(leafList.getName())) { | ||
603 | - if (leafList.getDataType().getDataType() == YangDataTypes.EMPTY) { | ||
604 | - throw new DataModelException(" A leaf-list that is part of the key" + | ||
605 | - " must not be the built-in type \"empty\"."); | ||
606 | - } | ||
607 | - leafFound = true; | ||
608 | - keyLeafLists.add(leafList); | ||
609 | - break; | ||
610 | - } | ||
611 | - } | ||
612 | - } | ||
613 | - | ||
614 | if (!leafFound && !isUsesPresentInList() && !isListPresentInGrouping()) { | 655 | if (!leafFound && !isUsesPresentInList() && !isListPresentInGrouping()) { |
615 | throw new DataModelException("An identifier, in key, must refer to a child leaf of the list"); | 656 | throw new DataModelException("An identifier, in key, must refer to a child leaf of the list"); |
616 | } | 657 | } |
... | @@ -627,17 +668,6 @@ public class YangList | ... | @@ -627,17 +668,6 @@ public class YangList |
627 | " \"config\" as the list itself."); | 668 | " \"config\" as the list itself."); |
628 | } | 669 | } |
629 | } | 670 | } |
630 | - | ||
631 | - /* | ||
632 | - * All key leafs in a list MUST have the same value for their "config" | ||
633 | - * as the list itself. | ||
634 | - */ | ||
635 | - for (YangLeafList keyLeafList : keyLeafLists) { | ||
636 | - if (isConfig() != keyLeafList.isConfig()) { | ||
637 | - throw new DataModelException("All key leaf-lists in a list must have the same value for their" + | ||
638 | - " \"config\" as the list itself."); | ||
639 | - } | ||
640 | - } | ||
641 | } | 671 | } |
642 | 672 | ||
643 | @Override | 673 | @Override | ... | ... |
... | @@ -272,12 +272,12 @@ public abstract class YangNode | ... | @@ -272,12 +272,12 @@ public abstract class YangNode |
272 | * @throws CloneNotSupportedException clone is not supported by the referred | 272 | * @throws CloneNotSupportedException clone is not supported by the referred |
273 | * node | 273 | * node |
274 | */ | 274 | */ |
275 | - public YangNode clone() | 275 | + public YangNode clone(YangUses yangUses) |
276 | throws CloneNotSupportedException { | 276 | throws CloneNotSupportedException { |
277 | YangNode clonedNode = (YangNode) super.clone(); | 277 | YangNode clonedNode = (YangNode) super.clone(); |
278 | if (clonedNode instanceof YangLeavesHolder) { | 278 | if (clonedNode instanceof YangLeavesHolder) { |
279 | try { | 279 | try { |
280 | - cloneLeaves((YangLeavesHolder) clonedNode); | 280 | + cloneLeaves((YangLeavesHolder) clonedNode, yangUses); |
281 | } catch (DataModelException e) { | 281 | } catch (DataModelException e) { |
282 | throw new CloneNotSupportedException(e.getMessage()); | 282 | throw new CloneNotSupportedException(e.getMessage()); |
283 | } | 283 | } |
... | @@ -299,7 +299,7 @@ public abstract class YangNode | ... | @@ -299,7 +299,7 @@ public abstract class YangNode |
299 | * @param dstRootNode destination node where the sub tree needs to be cloned | 299 | * @param dstRootNode destination node where the sub tree needs to be cloned |
300 | * @throws DataModelException data model error | 300 | * @throws DataModelException data model error |
301 | */ | 301 | */ |
302 | - public static void cloneSubTree(YangNode srcRootNode, YangNode dstRootNode) | 302 | + public static void cloneSubTree(YangNode srcRootNode, YangNode dstRootNode, YangUses yangUses) |
303 | throws DataModelException { | 303 | throws DataModelException { |
304 | 304 | ||
305 | YangNode nextNodeToClone = srcRootNode; | 305 | YangNode nextNodeToClone = srcRootNode; |
... | @@ -327,7 +327,7 @@ public abstract class YangNode | ... | @@ -327,7 +327,7 @@ public abstract class YangNode |
327 | throw new DataModelException("Internal error: Cloning failed, source tree null pointer reached"); | 327 | throw new DataModelException("Internal error: Cloning failed, source tree null pointer reached"); |
328 | } | 328 | } |
329 | if (curTraversal != PARENT) { | 329 | if (curTraversal != PARENT) { |
330 | - newNode = nextNodeToClone.clone(); | 330 | + newNode = nextNodeToClone.clone(yangUses); |
331 | detectCollisionWhileCloning(clonedTreeCurNode, newNode, curTraversal); | 331 | detectCollisionWhileCloning(clonedTreeCurNode, newNode, curTraversal); |
332 | } | 332 | } |
333 | 333 | ... | ... |
... | @@ -239,7 +239,7 @@ public class YangType<T> | ... | @@ -239,7 +239,7 @@ public class YangType<T> |
239 | } | 239 | } |
240 | 240 | ||
241 | @Override | 241 | @Override |
242 | - public void resolve() | 242 | + public Object resolve() |
243 | throws DataModelException { | 243 | throws DataModelException { |
244 | /* | 244 | /* |
245 | * Check whether the data type is derived. | 245 | * Check whether the data type is derived. |
... | @@ -260,6 +260,7 @@ public class YangType<T> | ... | @@ -260,6 +260,7 @@ public class YangType<T> |
260 | } catch (DataModelException e) { | 260 | } catch (DataModelException e) { |
261 | throw new DataModelException(e.getMessage()); | 261 | throw new DataModelException(e.getMessage()); |
262 | } | 262 | } |
263 | + return null; | ||
263 | } | 264 | } |
264 | 265 | ||
265 | /** | 266 | /** | ... | ... |
... | @@ -26,6 +26,8 @@ import org.onosproject.yangutils.datamodel.utils.YangConstructType; | ... | @@ -26,6 +26,8 @@ import org.onosproject.yangutils.datamodel.utils.YangConstructType; |
26 | import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil; | 26 | import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil; |
27 | import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParentNodeInGenCode; | 27 | import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParentNodeInGenCode; |
28 | import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.updateClonedLeavesUnionEnumRef; | 28 | import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.updateClonedLeavesUnionEnumRef; |
29 | +import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLeafrefUnderGroupingForLeaf; | ||
30 | +import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLeafrefUnderGroupingForLeafList; | ||
29 | 31 | ||
30 | /*- | 32 | /*- |
31 | * Reference RFC 6020. | 33 | * Reference RFC 6020. |
... | @@ -126,6 +128,16 @@ public class YangUses | ... | @@ -126,6 +128,16 @@ public class YangUses |
126 | private List<List<YangLeafList>> resolvedGroupingLeafLists; | 128 | private List<List<YangLeafList>> resolvedGroupingLeafLists; |
127 | 129 | ||
128 | /** | 130 | /** |
131 | + * Effective list of leaf lists of grouping that needs to replicated at YANG uses. | ||
132 | + */ | ||
133 | + private List<YangEntityToResolveInfoImpl> entityToResolveInfoList; | ||
134 | + | ||
135 | + /** | ||
136 | + * Current grouping depth for uses. | ||
137 | + */ | ||
138 | + private int currentGroupingDepth; | ||
139 | + | ||
140 | + /** | ||
129 | * Creates an YANG uses node. | 141 | * Creates an YANG uses node. |
130 | */ | 142 | */ |
131 | public YangUses() { | 143 | public YangUses() { |
... | @@ -138,6 +150,38 @@ public class YangUses | ... | @@ -138,6 +150,38 @@ public class YangUses |
138 | } | 150 | } |
139 | 151 | ||
140 | /** | 152 | /** |
153 | + * Returns the list of entity to resolve. | ||
154 | + * | ||
155 | + * @return the list of entity to resolve | ||
156 | + */ | ||
157 | + public List<YangEntityToResolveInfoImpl> getEntityToResolveInfoList() { | ||
158 | + return entityToResolveInfoList; | ||
159 | + } | ||
160 | + | ||
161 | + /** | ||
162 | + * Sets the list of entity to resolve. | ||
163 | + * | ||
164 | + * @param entityToResolveInfoList the list of entity to resolve | ||
165 | + */ | ||
166 | + public void setEntityToResolveInfoList(List<YangEntityToResolveInfoImpl> entityToResolveInfoList) { | ||
167 | + this.entityToResolveInfoList = entityToResolveInfoList; | ||
168 | + } | ||
169 | + | ||
170 | + /** | ||
171 | + * Adds an entity to resolve in list. | ||
172 | + * | ||
173 | + * @param entityToResolve entity to resolved | ||
174 | + * @throws DataModelException a violation of data model rules | ||
175 | + */ | ||
176 | + public void addEntityToResolve(YangEntityToResolveInfoImpl entityToResolve) | ||
177 | + throws DataModelException { | ||
178 | + if (getEntityToResolveInfoList() == null) { | ||
179 | + setEntityToResolveInfoList(new LinkedList<YangEntityToResolveInfoImpl>()); | ||
180 | + } | ||
181 | + getEntityToResolveInfoList().add(entityToResolve); | ||
182 | + } | ||
183 | + | ||
184 | + /** | ||
141 | * Returns the referred group. | 185 | * Returns the referred group. |
142 | * | 186 | * |
143 | * @return the referred group | 187 | * @return the referred group |
... | @@ -314,7 +358,7 @@ public class YangUses | ... | @@ -314,7 +358,7 @@ public class YangUses |
314 | } | 358 | } |
315 | 359 | ||
316 | @Override | 360 | @Override |
317 | - public void resolve() | 361 | + public Object resolve() |
318 | throws DataModelException { | 362 | throws DataModelException { |
319 | 363 | ||
320 | YangGrouping referredGrouping = getRefGroup(); | 364 | YangGrouping referredGrouping = getRefGroup(); |
... | @@ -337,7 +381,13 @@ public class YangUses | ... | @@ -337,7 +381,13 @@ public class YangUses |
337 | ((CollisionDetector) usesParentLeavesHolder).detectCollidingChild(leaf.getName(), | 381 | ((CollisionDetector) usesParentLeavesHolder).detectCollidingChild(leaf.getName(), |
338 | YangConstructType.LEAF_DATA); | 382 | YangConstructType.LEAF_DATA); |
339 | clonedLeaf = leaf.clone(); | 383 | clonedLeaf = leaf.clone(); |
340 | - | 384 | + if (getCurrentGroupingDepth() == 0) { |
385 | + YangEntityToResolveInfoImpl resolveInfo = resolveLeafrefUnderGroupingForLeaf(clonedLeaf, | ||
386 | + usesParentLeavesHolder, this); | ||
387 | + if (resolveInfo != null) { | ||
388 | + addEntityToResolve(resolveInfo); | ||
389 | + } | ||
390 | + } | ||
341 | } catch (CloneNotSupportedException | DataModelException e) { | 391 | } catch (CloneNotSupportedException | DataModelException e) { |
342 | throw new DataModelException(e.getMessage()); | 392 | throw new DataModelException(e.getMessage()); |
343 | } | 393 | } |
... | @@ -353,7 +403,13 @@ public class YangUses | ... | @@ -353,7 +403,13 @@ public class YangUses |
353 | ((CollisionDetector) usesParentLeavesHolder).detectCollidingChild(leafList.getName(), | 403 | ((CollisionDetector) usesParentLeavesHolder).detectCollidingChild(leafList.getName(), |
354 | YangConstructType.LEAF_LIST_DATA); | 404 | YangConstructType.LEAF_LIST_DATA); |
355 | clonedLeafList = leafList.clone(); | 405 | clonedLeafList = leafList.clone(); |
356 | - | 406 | + if (getCurrentGroupingDepth() == 0) { |
407 | + YangEntityToResolveInfoImpl resolveInfo = | ||
408 | + resolveLeafrefUnderGroupingForLeafList(clonedLeafList, usesParentLeavesHolder); | ||
409 | + if (resolveInfo != null) { | ||
410 | + addEntityToResolve(resolveInfo); | ||
411 | + } | ||
412 | + } | ||
357 | } catch (CloneNotSupportedException | DataModelException e) { | 413 | } catch (CloneNotSupportedException | DataModelException e) { |
358 | throw new DataModelException(e.getMessage()); | 414 | throw new DataModelException(e.getMessage()); |
359 | } | 415 | } |
... | @@ -364,11 +420,12 @@ public class YangUses | ... | @@ -364,11 +420,12 @@ public class YangUses |
364 | } | 420 | } |
365 | 421 | ||
366 | try { | 422 | try { |
367 | - YangNode.cloneSubTree(referredGrouping, usesParentNode); | 423 | + YangNode.cloneSubTree(referredGrouping, usesParentNode, this); |
368 | } catch (DataModelException e) { | 424 | } catch (DataModelException e) { |
369 | throw new DataModelException(e.getMessage()); | 425 | throw new DataModelException(e.getMessage()); |
370 | } | 426 | } |
371 | updateClonedLeavesUnionEnumRef(usesParentLeavesHolder); | 427 | updateClonedLeavesUnionEnumRef(usesParentLeavesHolder); |
428 | + return getEntityToResolveInfoList(); | ||
372 | } | 429 | } |
373 | 430 | ||
374 | /** | 431 | /** |
... | @@ -378,7 +435,7 @@ public class YangUses | ... | @@ -378,7 +435,7 @@ public class YangUses |
378 | * @param usesHolder holder of uses | 435 | * @param usesHolder holder of uses |
379 | */ | 436 | */ |
380 | private void addResolvedUsesInfoOfGrouping(YangUses usesInGrouping, | 437 | private void addResolvedUsesInfoOfGrouping(YangUses usesInGrouping, |
381 | - YangLeavesHolder usesHolder) throws DataModelException { | 438 | + YangLeavesHolder usesHolder) throws DataModelException { |
382 | for (YangNode usesResolvedNode : usesInGrouping.getUsesResolvedNodeList()) { | 439 | for (YangNode usesResolvedNode : usesInGrouping.getUsesResolvedNodeList()) { |
383 | addNodeOfGrouping(usesResolvedNode); | 440 | addNodeOfGrouping(usesResolvedNode); |
384 | } | 441 | } |
... | @@ -402,7 +459,7 @@ public class YangUses | ... | @@ -402,7 +459,7 @@ public class YangUses |
402 | * @throws DataModelException a violation in data model rule | 459 | * @throws DataModelException a violation in data model rule |
403 | */ | 460 | */ |
404 | private List<YangLeaf> cloneLeavesList(List<YangLeaf> listOfLeaves, | 461 | private List<YangLeaf> cloneLeavesList(List<YangLeaf> listOfLeaves, |
405 | - YangLeavesHolder usesParentNode) throws DataModelException { | 462 | + YangLeavesHolder usesParentNode) throws DataModelException { |
406 | if (listOfLeaves == null || listOfLeaves.size() == 0) { | 463 | if (listOfLeaves == null || listOfLeaves.size() == 0) { |
407 | throw new DataModelException("No leaves to clone"); | 464 | throw new DataModelException("No leaves to clone"); |
408 | } | 465 | } |
... | @@ -433,7 +490,7 @@ public class YangUses | ... | @@ -433,7 +490,7 @@ public class YangUses |
433 | * @return cloned list of leaf list | 490 | * @return cloned list of leaf list |
434 | */ | 491 | */ |
435 | private List<YangLeafList> cloneListOfLeafList(List<YangLeafList> listOfLeafList, | 492 | private List<YangLeafList> cloneListOfLeafList(List<YangLeafList> listOfLeafList, |
436 | - YangLeavesHolder usesParentNode) throws DataModelException { | 493 | + YangLeavesHolder usesParentNode) throws DataModelException { |
437 | if (listOfLeafList == null || listOfLeafList.size() == 0) { | 494 | if (listOfLeafList == null || listOfLeafList.size() == 0) { |
438 | throw new DataModelException("No leaf lists to clone"); | 495 | throw new DataModelException("No leaf lists to clone"); |
439 | } | 496 | } |
... | @@ -556,4 +613,13 @@ public class YangUses | ... | @@ -556,4 +613,13 @@ public class YangUses |
556 | public void setIfFeatureList(List<YangIfFeature> ifFeatureList) { | 613 | public void setIfFeatureList(List<YangIfFeature> ifFeatureList) { |
557 | this.ifFeatureList = ifFeatureList; | 614 | this.ifFeatureList = ifFeatureList; |
558 | } | 615 | } |
616 | + | ||
617 | + public void setCurrentGroupingDepth(int currentGroupingDepth) { | ||
618 | + this.currentGroupingDepth = currentGroupingDepth; | ||
619 | + } | ||
620 | + | ||
621 | + public int getCurrentGroupingDepth() { | ||
622 | + return currentGroupingDepth; | ||
623 | + } | ||
624 | + | ||
559 | } | 625 | } | ... | ... |
... | @@ -16,25 +16,21 @@ | ... | @@ -16,25 +16,21 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.datamodel.utils; | 17 | package org.onosproject.yangutils.datamodel.utils; |
18 | 18 | ||
19 | -import java.io.FileInputStream; | ||
20 | -import java.io.IOException; | ||
21 | -import java.io.ObjectInputStream; | ||
22 | -import java.util.ArrayList; | ||
23 | -import java.util.LinkedList; | ||
24 | -import java.util.List; | ||
25 | -import java.util.Set; | ||
26 | - | ||
27 | import org.onosproject.yangutils.datamodel.CollisionDetector; | 19 | import org.onosproject.yangutils.datamodel.CollisionDetector; |
28 | import org.onosproject.yangutils.datamodel.ResolvableType; | 20 | import org.onosproject.yangutils.datamodel.ResolvableType; |
29 | -import org.onosproject.yangutils.datamodel.YangIfFeature; | 21 | +import org.onosproject.yangutils.datamodel.YangAtomicPath; |
30 | import org.onosproject.yangutils.datamodel.YangAugment; | 22 | import org.onosproject.yangutils.datamodel.YangAugment; |
31 | import org.onosproject.yangutils.datamodel.YangBase; | 23 | import org.onosproject.yangutils.datamodel.YangBase; |
24 | +import org.onosproject.yangutils.datamodel.YangEntityToResolveInfoImpl; | ||
32 | import org.onosproject.yangutils.datamodel.YangEnumeration; | 25 | import org.onosproject.yangutils.datamodel.YangEnumeration; |
33 | import org.onosproject.yangutils.datamodel.YangIdentityRef; | 26 | import org.onosproject.yangutils.datamodel.YangIdentityRef; |
27 | +import org.onosproject.yangutils.datamodel.YangIfFeature; | ||
28 | +import org.onosproject.yangutils.datamodel.YangImport; | ||
34 | import org.onosproject.yangutils.datamodel.YangLeaf; | 29 | import org.onosproject.yangutils.datamodel.YangLeaf; |
35 | import org.onosproject.yangutils.datamodel.YangLeafList; | 30 | import org.onosproject.yangutils.datamodel.YangLeafList; |
36 | import org.onosproject.yangutils.datamodel.YangLeafRef; | 31 | import org.onosproject.yangutils.datamodel.YangLeafRef; |
37 | import org.onosproject.yangutils.datamodel.YangLeavesHolder; | 32 | import org.onosproject.yangutils.datamodel.YangLeavesHolder; |
33 | +import org.onosproject.yangutils.datamodel.YangModule; | ||
38 | import org.onosproject.yangutils.datamodel.YangNode; | 34 | import org.onosproject.yangutils.datamodel.YangNode; |
39 | import org.onosproject.yangutils.datamodel.YangReferenceResolver; | 35 | import org.onosproject.yangutils.datamodel.YangReferenceResolver; |
40 | import org.onosproject.yangutils.datamodel.YangResolutionInfo; | 36 | import org.onosproject.yangutils.datamodel.YangResolutionInfo; |
... | @@ -45,6 +41,16 @@ import org.onosproject.yangutils.datamodel.YangUses; | ... | @@ -45,6 +41,16 @@ import org.onosproject.yangutils.datamodel.YangUses; |
45 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | 41 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
46 | import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes; | 42 | import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes; |
47 | 43 | ||
44 | +import java.io.FileInputStream; | ||
45 | +import java.io.IOException; | ||
46 | +import java.io.ObjectInputStream; | ||
47 | +import java.util.ArrayList; | ||
48 | +import java.util.Iterator; | ||
49 | +import java.util.LinkedList; | ||
50 | +import java.util.List; | ||
51 | +import java.util.Map; | ||
52 | +import java.util.Set; | ||
53 | + | ||
48 | /** | 54 | /** |
49 | * Represents utilities for data model tree. | 55 | * Represents utilities for data model tree. |
50 | */ | 56 | */ |
... | @@ -206,7 +212,7 @@ public final class DataModelUtils { | ... | @@ -206,7 +212,7 @@ public final class DataModelUtils { |
206 | * @throws DataModelException a violation of data model rules | 212 | * @throws DataModelException a violation of data model rules |
207 | */ | 213 | */ |
208 | public static void resolveLinkingForResolutionList(List<YangResolutionInfo> resolutionList, | 214 | public static void resolveLinkingForResolutionList(List<YangResolutionInfo> resolutionList, |
209 | - YangReferenceResolver dataModelRootNode) | 215 | + YangReferenceResolver dataModelRootNode) |
210 | throws DataModelException { | 216 | throws DataModelException { |
211 | 217 | ||
212 | for (YangResolutionInfo resolutionInfo : resolutionList) { | 218 | for (YangResolutionInfo resolutionInfo : resolutionList) { |
... | @@ -222,7 +228,7 @@ public final class DataModelUtils { | ... | @@ -222,7 +228,7 @@ public final class DataModelUtils { |
222 | * @throws DataModelException a violation of data model rules | 228 | * @throws DataModelException a violation of data model rules |
223 | */ | 229 | */ |
224 | public static void linkInterFileReferences(List<YangResolutionInfo> resolutionList, | 230 | public static void linkInterFileReferences(List<YangResolutionInfo> resolutionList, |
225 | - YangReferenceResolver dataModelRootNode) | 231 | + YangReferenceResolver dataModelRootNode) |
226 | throws DataModelException { | 232 | throws DataModelException { |
227 | /* | 233 | /* |
228 | * Run through the resolution list, find type/uses referring to inter | 234 | * Run through the resolution list, find type/uses referring to inter |
... | @@ -316,16 +322,24 @@ public final class DataModelUtils { | ... | @@ -316,16 +322,24 @@ public final class DataModelUtils { |
316 | * Clones the list of leaves and list of leaf list in the leaves holder. | 322 | * Clones the list of leaves and list of leaf list in the leaves holder. |
317 | * | 323 | * |
318 | * @param leavesHolder YANG node potentially containing leaves or leaf lists | 324 | * @param leavesHolder YANG node potentially containing leaves or leaf lists |
325 | + * @param yangUses instance of YANG uses | ||
319 | * @throws CloneNotSupportedException clone is not supported | 326 | * @throws CloneNotSupportedException clone is not supported |
320 | * @throws DataModelException data model error | 327 | * @throws DataModelException data model error |
321 | */ | 328 | */ |
322 | - public static void cloneLeaves(YangLeavesHolder leavesHolder) | 329 | + public static void cloneLeaves(YangLeavesHolder leavesHolder, YangUses yangUses) |
323 | throws CloneNotSupportedException, DataModelException { | 330 | throws CloneNotSupportedException, DataModelException { |
324 | List<YangLeaf> currentListOfLeaves = leavesHolder.getListOfLeaf(); | 331 | List<YangLeaf> currentListOfLeaves = leavesHolder.getListOfLeaf(); |
325 | if (currentListOfLeaves != null) { | 332 | if (currentListOfLeaves != null) { |
326 | List<YangLeaf> clonedLeavesList = new LinkedList<YangLeaf>(); | 333 | List<YangLeaf> clonedLeavesList = new LinkedList<YangLeaf>(); |
327 | for (YangLeaf leaf : currentListOfLeaves) { | 334 | for (YangLeaf leaf : currentListOfLeaves) { |
328 | YangLeaf clonedLeaf = leaf.clone(); | 335 | YangLeaf clonedLeaf = leaf.clone(); |
336 | + if (yangUses.getCurrentGroupingDepth() == 0) { | ||
337 | + YangEntityToResolveInfoImpl resolveInfo = | ||
338 | + resolveLeafrefUnderGroupingForLeaf(clonedLeaf, leavesHolder, yangUses); | ||
339 | + if (resolveInfo != null) { | ||
340 | + yangUses.addEntityToResolve(resolveInfo); | ||
341 | + } | ||
342 | + } | ||
329 | clonedLeaf.setContainedIn(leavesHolder); | 343 | clonedLeaf.setContainedIn(leavesHolder); |
330 | clonedLeavesList.add(clonedLeaf); | 344 | clonedLeavesList.add(clonedLeaf); |
331 | } | 345 | } |
... | @@ -337,6 +351,13 @@ public final class DataModelUtils { | ... | @@ -337,6 +351,13 @@ public final class DataModelUtils { |
337 | List<YangLeafList> clonedListOfLeafList = new LinkedList<YangLeafList>(); | 351 | List<YangLeafList> clonedListOfLeafList = new LinkedList<YangLeafList>(); |
338 | for (YangLeafList leafList : currentListOfLeafList) { | 352 | for (YangLeafList leafList : currentListOfLeafList) { |
339 | YangLeafList clonedLeafList = leafList.clone(); | 353 | YangLeafList clonedLeafList = leafList.clone(); |
354 | + if (yangUses.getCurrentGroupingDepth() == 0) { | ||
355 | + YangEntityToResolveInfoImpl resolveInfo = | ||
356 | + resolveLeafrefUnderGroupingForLeafList(clonedLeafList, leavesHolder); | ||
357 | + if (resolveInfo != null) { | ||
358 | + yangUses.addEntityToResolve(resolveInfo); | ||
359 | + } | ||
360 | + } | ||
340 | clonedLeafList.setContainedIn(leavesHolder); | 361 | clonedLeafList.setContainedIn(leavesHolder); |
341 | clonedListOfLeafList.add(clonedLeafList); | 362 | clonedListOfLeafList.add(clonedLeafList); |
342 | } | 363 | } |
... | @@ -345,6 +366,112 @@ public final class DataModelUtils { | ... | @@ -345,6 +366,112 @@ public final class DataModelUtils { |
345 | } | 366 | } |
346 | 367 | ||
347 | /** | 368 | /** |
369 | + * Resolves leafref in leaf, which are under grouping by adding it to the resolution list. | ||
370 | + * | ||
371 | + * @param clonedLeaf cloned leaf in uses from grouping | ||
372 | + * @param leafParentHolder holder of the leaf from uses | ||
373 | + * @return entity of leafref which has to be resolved | ||
374 | + * @throws DataModelException data model error | ||
375 | + */ | ||
376 | + public static YangEntityToResolveInfoImpl resolveLeafrefUnderGroupingForLeaf(YangLeaf clonedLeaf, | ||
377 | + YangLeavesHolder leafParentHolder, | ||
378 | + YangUses yangUses) throws | ||
379 | + DataModelException { | ||
380 | + if (clonedLeaf.getDataType().getDataTypeExtendedInfo() instanceof YangLeafRef) { | ||
381 | + YangLeafRef leafrefForCloning = (YangLeafRef) clonedLeaf.getDataType().getDataTypeExtendedInfo(); | ||
382 | + // Conversion of prefixes in absolute path while cloning them. | ||
383 | + convertThePrefixesDuringChange(leafrefForCloning, yangUses); | ||
384 | + leafrefForCloning.setParentNodeOfLeafref((YangNode) leafParentHolder); | ||
385 | + YangEntityToResolveInfoImpl yangEntityToResolveInfo = new YangEntityToResolveInfoImpl(); | ||
386 | + yangEntityToResolveInfo.setEntityToResolve(leafrefForCloning); | ||
387 | + yangEntityToResolveInfo.setHolderOfEntityToResolve((YangNode) leafParentHolder); | ||
388 | + yangEntityToResolveInfo.setLineNumber(leafrefForCloning.getLineNumber()); | ||
389 | + yangEntityToResolveInfo.setCharPosition(leafrefForCloning.getCharPosition()); | ||
390 | + return yangEntityToResolveInfo; | ||
391 | + } | ||
392 | + return null; | ||
393 | + } | ||
394 | + | ||
395 | + /** | ||
396 | + * Converts the prefixes in all the nodes of the leafref with respect to the uses node. | ||
397 | + * | ||
398 | + * @param leafrefForCloning leafref that is to be cloned | ||
399 | + * @param yangUses instance of YANG uses where cloning is done | ||
400 | + * @throws DataModelException data model error | ||
401 | + */ | ||
402 | + private static void convertThePrefixesDuringChange(YangLeafRef leafrefForCloning, YangUses yangUses) throws | ||
403 | + DataModelException { | ||
404 | + List<YangAtomicPath> atomicPathList = leafrefForCloning.getAtomicPath(); | ||
405 | + if (atomicPathList != null && !atomicPathList.isEmpty()) { | ||
406 | + Iterator<YangAtomicPath> atomicPathIterator = atomicPathList.listIterator(); | ||
407 | + while (atomicPathIterator.hasNext()) { | ||
408 | + YangAtomicPath atomicPath = atomicPathIterator.next(); | ||
409 | + Map<String, String> prefixesAndItsImportNameNode = leafrefForCloning.getPrefixAndItsImportedModule(); | ||
410 | + if (!prefixesAndItsImportNameNode.isEmpty() || prefixesAndItsImportNameNode != null) { | ||
411 | + String prefixInPath = atomicPath.getNodeIdentifier().getPrefix(); | ||
412 | + String importedNodeName = prefixesAndItsImportNameNode.get(prefixInPath); | ||
413 | + assignCurrentLeafrefWithNewPrefixes(importedNodeName, atomicPath, yangUses); | ||
414 | + } | ||
415 | + } | ||
416 | + } | ||
417 | + } | ||
418 | + | ||
419 | + /** | ||
420 | + * Assigns leafref with new prefixes while cloning. | ||
421 | + * | ||
422 | + * @param importedNodeName imported node name from grouping | ||
423 | + * @param atomicPath atomic path in leafref | ||
424 | + * @param node instance of YANG uses where cloning is done | ||
425 | + * @throws DataModelException data model error | ||
426 | + */ | ||
427 | + private static void assignCurrentLeafrefWithNewPrefixes(String importedNodeName, YangAtomicPath atomicPath, | ||
428 | + YangNode node) throws DataModelException { | ||
429 | + while (!(node instanceof YangReferenceResolver)) { | ||
430 | + node = node.getParent(); | ||
431 | + if (node == null) { | ||
432 | + throw new DataModelException("Internal datamodel error: Datamodel tree is not correct"); | ||
433 | + } | ||
434 | + } | ||
435 | + if (node instanceof YangModule) { | ||
436 | + List<YangImport> importInUsesList = ((YangModule) node).getImportList(); | ||
437 | + if (importInUsesList != null && !importInUsesList.isEmpty()) { | ||
438 | + Iterator<YangImport> importInUsesListIterator = importInUsesList.listIterator(); | ||
439 | + while (importInUsesListIterator.hasNext()) { | ||
440 | + YangImport importInUsesNode = importInUsesListIterator.next(); | ||
441 | + if (importInUsesNode.getModuleName().equals(importedNodeName)) { | ||
442 | + atomicPath.getNodeIdentifier().setPrefix(importInUsesNode.getPrefixId()); | ||
443 | + } | ||
444 | + } | ||
445 | + } | ||
446 | + } | ||
447 | + } | ||
448 | + | ||
449 | + /** | ||
450 | + * Resolves leafref in leaf-list, which are under grouping by adding it to the resolution list. | ||
451 | + * | ||
452 | + * @param clonedLeafList cloned leaf-list in uses from grouping | ||
453 | + * @param leafListParentHolder holder of the leaf-list from uses | ||
454 | + * @return entity of leafref which has to be resolved | ||
455 | + * @throws DataModelException data model error | ||
456 | + */ | ||
457 | + public static YangEntityToResolveInfoImpl resolveLeafrefUnderGroupingForLeafList(YangLeafList clonedLeafList, | ||
458 | + YangLeavesHolder | ||
459 | + leafListParentHolder) | ||
460 | + throws DataModelException { | ||
461 | + if (clonedLeafList.getDataType().getDataTypeExtendedInfo() instanceof YangLeafRef) { | ||
462 | + YangLeafRef leafrefForCloning = (YangLeafRef) clonedLeafList.getDataType().getDataTypeExtendedInfo(); | ||
463 | + leafrefForCloning.setParentNodeOfLeafref((YangNode) leafListParentHolder); | ||
464 | + YangEntityToResolveInfoImpl yangEntityToResolveInfo = new YangEntityToResolveInfoImpl(); | ||
465 | + yangEntityToResolveInfo.setEntityToResolve(leafrefForCloning); | ||
466 | + yangEntityToResolveInfo.setHolderOfEntityToResolve((YangNode) leafListParentHolder); | ||
467 | + yangEntityToResolveInfo.setLineNumber(leafrefForCloning.getLineNumber()); | ||
468 | + yangEntityToResolveInfo.setCharPosition(leafrefForCloning.getCharPosition()); | ||
469 | + return yangEntityToResolveInfo; | ||
470 | + } | ||
471 | + return null; | ||
472 | + } | ||
473 | + | ||
474 | + /** | ||
348 | * Clones the union or enum leaves. If there is any cloned leaves whose type is union/enum then the corresponding | 475 | * Clones the union or enum leaves. If there is any cloned leaves whose type is union/enum then the corresponding |
349 | * type info needs to be updated to the cloned new type node. | 476 | * type info needs to be updated to the cloned new type node. |
350 | * | 477 | * | ... | ... |
... | @@ -177,11 +177,11 @@ public class YangLinkerManager | ... | @@ -177,11 +177,11 @@ public class YangLinkerManager |
177 | ((YangReferenceResolver) yangNode) | 177 | ((YangReferenceResolver) yangNode) |
178 | .resolveInterFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE); | 178 | .resolveInterFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE); |
179 | ((YangReferenceResolver) yangNode) | 179 | ((YangReferenceResolver) yangNode) |
180 | - .resolveInterFileLinking(ResolvableType.YANG_LEAFREF); | ||
181 | - ((YangReferenceResolver) yangNode) | ||
182 | .resolveInterFileLinking(ResolvableType.YANG_BASE); | 180 | .resolveInterFileLinking(ResolvableType.YANG_BASE); |
183 | ((YangReferenceResolver) yangNode) | 181 | ((YangReferenceResolver) yangNode) |
184 | .resolveInterFileLinking(ResolvableType.YANG_IDENTITYREF); | 182 | .resolveInterFileLinking(ResolvableType.YANG_IDENTITYREF); |
183 | + ((YangReferenceResolver) yangNode) | ||
184 | + .resolveInterFileLinking(ResolvableType.YANG_LEAFREF); | ||
185 | } catch (DataModelException e) { | 185 | } catch (DataModelException e) { |
186 | String errorInfo = "Error in file: " + yangNode.getName() + " at line: " | 186 | String errorInfo = "Error in file: " + yangNode.getName() + " at line: " |
187 | + e.getLineNumber() + " at position: " + e.getCharPositionInLine() + NEW_LINE + e.getMessage(); | 187 | + e.getLineNumber() + " at position: " + e.getCharPositionInLine() + NEW_LINE + e.getMessage(); | ... | ... |
... | @@ -16,18 +16,28 @@ | ... | @@ -16,18 +16,28 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.linker.impl; | 17 | package org.onosproject.yangutils.linker.impl; |
18 | 18 | ||
19 | -import java.util.List; | ||
20 | - | ||
21 | import org.onosproject.yangutils.datamodel.YangAugment; | 19 | import org.onosproject.yangutils.datamodel.YangAugment; |
22 | import org.onosproject.yangutils.datamodel.YangAugmentableNode; | 20 | import org.onosproject.yangutils.datamodel.YangAugmentableNode; |
23 | import org.onosproject.yangutils.datamodel.YangAugmentedInfo; | 21 | import org.onosproject.yangutils.datamodel.YangAugmentedInfo; |
22 | +import org.onosproject.yangutils.datamodel.YangCase; | ||
24 | import org.onosproject.yangutils.datamodel.YangChoice; | 23 | import org.onosproject.yangutils.datamodel.YangChoice; |
25 | import org.onosproject.yangutils.datamodel.YangLeaf; | 24 | import org.onosproject.yangutils.datamodel.YangLeaf; |
26 | import org.onosproject.yangutils.datamodel.YangLeafList; | 25 | import org.onosproject.yangutils.datamodel.YangLeafList; |
26 | +import org.onosproject.yangutils.datamodel.YangLeafRef; | ||
27 | import org.onosproject.yangutils.datamodel.YangLeavesHolder; | 27 | import org.onosproject.yangutils.datamodel.YangLeavesHolder; |
28 | import org.onosproject.yangutils.datamodel.YangNode; | 28 | import org.onosproject.yangutils.datamodel.YangNode; |
29 | +import org.onosproject.yangutils.datamodel.YangNodeIdentifier; | ||
30 | +import org.onosproject.yangutils.datamodel.utils.YangConstructType; | ||
29 | import org.onosproject.yangutils.linker.exceptions.LinkerException; | 31 | import org.onosproject.yangutils.linker.exceptions.LinkerException; |
30 | 32 | ||
33 | +import java.util.ArrayList; | ||
34 | +import java.util.List; | ||
35 | +import java.util.regex.Pattern; | ||
36 | + | ||
37 | +import static org.onosproject.yangutils.utils.UtilConstants.COLON; | ||
38 | +import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; | ||
39 | +import static org.onosproject.yangutils.utils.UtilConstants.SLASH_FOR_STRING; | ||
40 | + | ||
31 | /** | 41 | /** |
32 | * Represent utilities for YANG linker. | 42 | * Represent utilities for YANG linker. |
33 | */ | 43 | */ |
... | @@ -36,6 +46,10 @@ public final class YangLinkerUtils { | ... | @@ -36,6 +46,10 @@ public final class YangLinkerUtils { |
36 | private YangLinkerUtils() { | 46 | private YangLinkerUtils() { |
37 | } | 47 | } |
38 | 48 | ||
49 | + private static final int IDENTIFIER_LENGTH = 64; | ||
50 | + private static final Pattern IDENTIFIER_PATTERN = Pattern.compile("[a-zA-Z_][a-zA-Z0-9_.-]*"); | ||
51 | + private static final String XML = "xml"; | ||
52 | + | ||
39 | /** | 53 | /** |
40 | * Detects collision between target nodes leaf/leaf-list or child node with augmented leaf/leaf-list or child node. | 54 | * Detects collision between target nodes leaf/leaf-list or child node with augmented leaf/leaf-list or child node. |
41 | * | 55 | * |
... | @@ -119,4 +133,99 @@ public final class YangLinkerUtils { | ... | @@ -119,4 +133,99 @@ public final class YangLinkerUtils { |
119 | detectCollision((YangAugment) info, augment); | 133 | detectCollision((YangAugment) info, augment); |
120 | } | 134 | } |
121 | } | 135 | } |
136 | + | ||
137 | + /** | ||
138 | + * Returns list of path names that are needed from augment. | ||
139 | + * | ||
140 | + * @param augment instance of YANG augment | ||
141 | + * @param remainingAncestors ancestor count to move in augment path | ||
142 | + * @return list of path names needed in leafref | ||
143 | + */ | ||
144 | + public static List<String> getPathWithAugment(YangAugment augment, int remainingAncestors) { | ||
145 | + String augmentName = augment.getName(); | ||
146 | + List<String> listOfPathName = new ArrayList<>(); | ||
147 | + if (augmentName.contains(SLASH_FOR_STRING)) { | ||
148 | + String[] augmentNodeNames = augmentName.split(SLASH_FOR_STRING); | ||
149 | + for (String valueInAugment : augmentNodeNames) { | ||
150 | + if (valueInAugment != null && valueInAugment != EMPTY_STRING && !valueInAugment.isEmpty()) { | ||
151 | + listOfPathName.add(valueInAugment); | ||
152 | + } | ||
153 | + } | ||
154 | + } | ||
155 | + for (int countOfAncestor = 0; countOfAncestor < remainingAncestors; countOfAncestor++) { | ||
156 | + listOfPathName.remove(listOfPathName.size() - 1); | ||
157 | + } | ||
158 | + return listOfPathName; | ||
159 | + } | ||
160 | + | ||
161 | + /** | ||
162 | + * Skips the invalid nodes which cannot have data from YANG. | ||
163 | + * | ||
164 | + * @param currentParent current parent node reference | ||
165 | + * @param leafref instance of YANG leafref | ||
166 | + * @return parent node which can hold data | ||
167 | + * @throws LinkerException a violation of linker rules | ||
168 | + */ | ||
169 | + public static YangNode skipInvalidDataNodes(YangNode currentParent, YangLeafRef leafref) throws LinkerException { | ||
170 | + while (currentParent instanceof YangChoice || currentParent instanceof YangCase) { | ||
171 | + if (currentParent.getParent() == null) { | ||
172 | + throw new LinkerException("YANG file error: The target node, in the leafref path " + | ||
173 | + leafref.getPath() + ", is invalid."); | ||
174 | + } | ||
175 | + currentParent = currentParent.getParent(); | ||
176 | + } | ||
177 | + return currentParent; | ||
178 | + } | ||
179 | + | ||
180 | + /** | ||
181 | + * Checks and return valid node identifier. | ||
182 | + * | ||
183 | + * @param nodeIdentifierString string from yang file | ||
184 | + * @param yangConstruct yang construct for creating error message | ||
185 | + * @return valid node identifier | ||
186 | + */ | ||
187 | + public static YangNodeIdentifier getValidNodeIdentifier(String nodeIdentifierString, | ||
188 | + YangConstructType yangConstruct) { | ||
189 | + String[] tmpData = nodeIdentifierString.split(Pattern.quote(COLON)); | ||
190 | + if (tmpData.length == 1) { | ||
191 | + YangNodeIdentifier nodeIdentifier = new YangNodeIdentifier(); | ||
192 | + nodeIdentifier.setName(getValidIdentifier(tmpData[0], yangConstruct)); | ||
193 | + return nodeIdentifier; | ||
194 | + } else if (tmpData.length == 2) { | ||
195 | + YangNodeIdentifier nodeIdentifier = new YangNodeIdentifier(); | ||
196 | + nodeIdentifier.setPrefix(getValidIdentifier(tmpData[0], yangConstruct)); | ||
197 | + nodeIdentifier.setName(getValidIdentifier(tmpData[1], yangConstruct)); | ||
198 | + return nodeIdentifier; | ||
199 | + } else { | ||
200 | + throw new LinkerException("YANG file error : " + | ||
201 | + YangConstructType.getYangConstructType(yangConstruct) + " name " + nodeIdentifierString + | ||
202 | + " is not valid."); | ||
203 | + } | ||
204 | + } | ||
205 | + | ||
206 | + /** | ||
207 | + * Validates identifier and returns concatenated string if string contains plus symbol. | ||
208 | + * | ||
209 | + * @param identifier string from yang file | ||
210 | + * @param yangConstruct yang construct for creating error message= | ||
211 | + * @return concatenated string after removing double quotes | ||
212 | + */ | ||
213 | + public static String getValidIdentifier(String identifier, YangConstructType yangConstruct) { | ||
214 | + | ||
215 | + if (identifier.length() > IDENTIFIER_LENGTH) { | ||
216 | + throw new LinkerException("YANG file error : " + | ||
217 | + YangConstructType.getYangConstructType(yangConstruct) + " name " + identifier + " is " + | ||
218 | + "greater than 64 characters."); | ||
219 | + } else if (!IDENTIFIER_PATTERN.matcher(identifier).matches()) { | ||
220 | + throw new LinkerException("YANG file error : " + | ||
221 | + YangConstructType.getYangConstructType(yangConstruct) + " name " + identifier + " is not " + | ||
222 | + "valid."); | ||
223 | + } else if (identifier.toLowerCase().startsWith(XML)) { | ||
224 | + throw new LinkerException("YANG file error : " + | ||
225 | + YangConstructType.getYangConstructType(yangConstruct) + " identifier " + identifier + | ||
226 | + " must not start with (('X'|'x') ('M'|'m') ('L'|'l'))."); | ||
227 | + } else { | ||
228 | + return identifier; | ||
229 | + } | ||
230 | + } | ||
122 | } | 231 | } | ... | ... |
... | @@ -16,11 +16,6 @@ | ... | @@ -16,11 +16,6 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.linker.impl; | 17 | package org.onosproject.yangutils.linker.impl; |
18 | 18 | ||
19 | -import java.io.Serializable; | ||
20 | -import java.util.Iterator; | ||
21 | -import java.util.List; | ||
22 | -import java.util.Stack; | ||
23 | - | ||
24 | import org.onosproject.yangutils.datamodel.Resolvable; | 19 | import org.onosproject.yangutils.datamodel.Resolvable; |
25 | import org.onosproject.yangutils.datamodel.ResolvableType; | 20 | import org.onosproject.yangutils.datamodel.ResolvableType; |
26 | import org.onosproject.yangutils.datamodel.YangAtomicPath; | 21 | import org.onosproject.yangutils.datamodel.YangAtomicPath; |
... | @@ -29,6 +24,7 @@ import org.onosproject.yangutils.datamodel.YangAugmentableNode; | ... | @@ -29,6 +24,7 @@ import org.onosproject.yangutils.datamodel.YangAugmentableNode; |
29 | import org.onosproject.yangutils.datamodel.YangBase; | 24 | import org.onosproject.yangutils.datamodel.YangBase; |
30 | import org.onosproject.yangutils.datamodel.YangDerivedInfo; | 25 | import org.onosproject.yangutils.datamodel.YangDerivedInfo; |
31 | import org.onosproject.yangutils.datamodel.YangEntityToResolveInfo; | 26 | import org.onosproject.yangutils.datamodel.YangEntityToResolveInfo; |
27 | +import org.onosproject.yangutils.datamodel.YangEntityToResolveInfoImpl; | ||
32 | import org.onosproject.yangutils.datamodel.YangFeature; | 28 | import org.onosproject.yangutils.datamodel.YangFeature; |
33 | import org.onosproject.yangutils.datamodel.YangFeatureHolder; | 29 | import org.onosproject.yangutils.datamodel.YangFeatureHolder; |
34 | import org.onosproject.yangutils.datamodel.YangGrouping; | 30 | import org.onosproject.yangutils.datamodel.YangGrouping; |
... | @@ -41,14 +37,11 @@ import org.onosproject.yangutils.datamodel.YangInput; | ... | @@ -41,14 +37,11 @@ import org.onosproject.yangutils.datamodel.YangInput; |
41 | import org.onosproject.yangutils.datamodel.YangLeaf; | 37 | import org.onosproject.yangutils.datamodel.YangLeaf; |
42 | import org.onosproject.yangutils.datamodel.YangLeafList; | 38 | import org.onosproject.yangutils.datamodel.YangLeafList; |
43 | import org.onosproject.yangutils.datamodel.YangLeafRef; | 39 | import org.onosproject.yangutils.datamodel.YangLeafRef; |
44 | -import org.onosproject.yangutils.datamodel.YangLeavesHolder; | ||
45 | -import org.onosproject.yangutils.datamodel.YangList; | ||
46 | import org.onosproject.yangutils.datamodel.YangModule; | 40 | import org.onosproject.yangutils.datamodel.YangModule; |
47 | import org.onosproject.yangutils.datamodel.YangNode; | 41 | import org.onosproject.yangutils.datamodel.YangNode; |
48 | import org.onosproject.yangutils.datamodel.YangNodeIdentifier; | 42 | import org.onosproject.yangutils.datamodel.YangNodeIdentifier; |
49 | import org.onosproject.yangutils.datamodel.YangOutput; | 43 | import org.onosproject.yangutils.datamodel.YangOutput; |
50 | import org.onosproject.yangutils.datamodel.YangPathArgType; | 44 | import org.onosproject.yangutils.datamodel.YangPathArgType; |
51 | -import org.onosproject.yangutils.datamodel.YangPathPredicate; | ||
52 | import org.onosproject.yangutils.datamodel.YangReferenceResolver; | 45 | import org.onosproject.yangutils.datamodel.YangReferenceResolver; |
53 | import org.onosproject.yangutils.datamodel.YangRelativePath; | 46 | import org.onosproject.yangutils.datamodel.YangRelativePath; |
54 | import org.onosproject.yangutils.datamodel.YangResolutionInfo; | 47 | import org.onosproject.yangutils.datamodel.YangResolutionInfo; |
... | @@ -60,10 +53,18 @@ import org.onosproject.yangutils.datamodel.YangUses; | ... | @@ -60,10 +53,18 @@ import org.onosproject.yangutils.datamodel.YangUses; |
60 | import org.onosproject.yangutils.datamodel.YangXPathResolver; | 53 | import org.onosproject.yangutils.datamodel.YangXPathResolver; |
61 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | 54 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
62 | import org.onosproject.yangutils.datamodel.utils.ResolvableStatus; | 55 | import org.onosproject.yangutils.datamodel.utils.ResolvableStatus; |
56 | +import org.onosproject.yangutils.datamodel.utils.YangConstructType; | ||
63 | import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes; | 57 | import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes; |
64 | import org.onosproject.yangutils.linker.YangLinkingPhase; | 58 | import org.onosproject.yangutils.linker.YangLinkingPhase; |
65 | import org.onosproject.yangutils.linker.exceptions.LinkerException; | 59 | import org.onosproject.yangutils.linker.exceptions.LinkerException; |
66 | 60 | ||
61 | +import java.io.Serializable; | ||
62 | +import java.util.Iterator; | ||
63 | +import java.util.LinkedList; | ||
64 | +import java.util.List; | ||
65 | +import java.util.Stack; | ||
66 | + | ||
67 | +import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.addResolutionInfo; | ||
67 | import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.INTER_FILE_LINKED; | 68 | import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.INTER_FILE_LINKED; |
68 | import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.INTRA_FILE_RESOLVED; | 69 | import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.INTRA_FILE_RESOLVED; |
69 | import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.LINKED; | 70 | import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.LINKED; |
... | @@ -73,7 +74,11 @@ import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.UNRESOL | ... | @@ -73,7 +74,11 @@ import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.UNRESOL |
73 | import static org.onosproject.yangutils.linker.YangLinkingPhase.INTER_FILE; | 74 | import static org.onosproject.yangutils.linker.YangLinkingPhase.INTER_FILE; |
74 | import static org.onosproject.yangutils.linker.YangLinkingPhase.INTRA_FILE; | 75 | import static org.onosproject.yangutils.linker.YangLinkingPhase.INTRA_FILE; |
75 | import static org.onosproject.yangutils.linker.impl.YangLinkerUtils.detectCollisionForAugmentedNode; | 76 | import static org.onosproject.yangutils.linker.impl.YangLinkerUtils.detectCollisionForAugmentedNode; |
77 | +import static org.onosproject.yangutils.linker.impl.YangLinkerUtils.getPathWithAugment; | ||
78 | +import static org.onosproject.yangutils.linker.impl.YangLinkerUtils.getValidNodeIdentifier; | ||
79 | +import static org.onosproject.yangutils.linker.impl.YangLinkerUtils.skipInvalidDataNodes; | ||
76 | import static org.onosproject.yangutils.utils.UtilConstants.BASE_LINKER_ERROR; | 80 | import static org.onosproject.yangutils.utils.UtilConstants.BASE_LINKER_ERROR; |
81 | +import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; | ||
77 | import static org.onosproject.yangutils.utils.UtilConstants.FEATURE_LINKER_ERROR; | 82 | import static org.onosproject.yangutils.utils.UtilConstants.FEATURE_LINKER_ERROR; |
78 | import static org.onosproject.yangutils.utils.UtilConstants.GROUPING_LINKER_ERROR; | 83 | import static org.onosproject.yangutils.utils.UtilConstants.GROUPING_LINKER_ERROR; |
79 | import static org.onosproject.yangutils.utils.UtilConstants.IDENTITYREF; | 84 | import static org.onosproject.yangutils.utils.UtilConstants.IDENTITYREF; |
... | @@ -82,6 +87,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.INPUT; | ... | @@ -82,6 +87,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.INPUT; |
82 | import static org.onosproject.yangutils.utils.UtilConstants.LEAFREF; | 87 | import static org.onosproject.yangutils.utils.UtilConstants.LEAFREF; |
83 | import static org.onosproject.yangutils.utils.UtilConstants.LEAFREF_LINKER_ERROR; | 88 | import static org.onosproject.yangutils.utils.UtilConstants.LEAFREF_LINKER_ERROR; |
84 | import static org.onosproject.yangutils.utils.UtilConstants.OUTPUT; | 89 | import static org.onosproject.yangutils.utils.UtilConstants.OUTPUT; |
90 | +import static org.onosproject.yangutils.utils.UtilConstants.SLASH_FOR_STRING; | ||
85 | import static org.onosproject.yangutils.utils.UtilConstants.TYPEDEF_LINKER_ERROR; | 91 | import static org.onosproject.yangutils.utils.UtilConstants.TYPEDEF_LINKER_ERROR; |
86 | 92 | ||
87 | /** | 93 | /** |
... | @@ -328,13 +334,14 @@ public class YangResolutionInfoImpl<T> | ... | @@ -328,13 +334,14 @@ public class YangResolutionInfoImpl<T> |
328 | yangType.setDataTypeName(LEAFREF); | 334 | yangType.setDataTypeName(LEAFREF); |
329 | yangType.setDataTypeExtendedInfo(leafRefInTypeDef); | 335 | yangType.setDataTypeExtendedInfo(leafRefInTypeDef); |
330 | leafRefInTypeDef.setResolvableStatus(UNRESOLVED); | 336 | leafRefInTypeDef.setResolvableStatus(UNRESOLVED); |
337 | + leafRefInTypeDef.setParentNodeOfLeafref(potentialAncestorWithReferredNode); | ||
331 | 338 | ||
332 | // Add resolution information to the list. | 339 | // Add resolution information to the list. |
333 | YangResolutionInfoImpl resolutionInfoImpl = new YangResolutionInfoImpl<>(leafRefInTypeDef, | 340 | YangResolutionInfoImpl resolutionInfoImpl = new YangResolutionInfoImpl<>(leafRefInTypeDef, |
334 | - potentialAncestorWithReferredNode, | 341 | + potentialAncestorWithReferredNode, |
335 | - getLineNumber(), getCharPosition()); | 342 | + getLineNumber(), getCharPosition()); |
336 | getCurReferenceResolver().addToResolutionList(resolutionInfoImpl, | 343 | getCurReferenceResolver().addToResolutionList(resolutionInfoImpl, |
337 | - ResolvableType.YANG_LEAFREF); | 344 | + ResolvableType.YANG_LEAFREF); |
338 | getCurReferenceResolver().resolveSelfFileLinking(ResolvableType.YANG_LEAFREF); | 345 | getCurReferenceResolver().resolveSelfFileLinking(ResolvableType.YANG_LEAFREF); |
339 | 346 | ||
340 | } else if (derivedInfo.getEffectiveBuiltInType() == YangDataTypes.IDENTITYREF) { | 347 | } else if (derivedInfo.getEffectiveBuiltInType() == YangDataTypes.IDENTITYREF) { |
... | @@ -350,9 +357,9 @@ public class YangResolutionInfoImpl<T> | ... | @@ -350,9 +357,9 @@ public class YangResolutionInfoImpl<T> |
350 | 357 | ||
351 | // Add resolution information to the list. | 358 | // Add resolution information to the list. |
352 | YangResolutionInfoImpl resolutionInfoImpl = new YangResolutionInfoImpl<>(identityRefInTypeDef, | 359 | YangResolutionInfoImpl resolutionInfoImpl = new YangResolutionInfoImpl<>(identityRefInTypeDef, |
353 | - potentialAncestorWithReferredNode, getLineNumber(), getCharPosition()); | 360 | + potentialAncestorWithReferredNode, getLineNumber(), getCharPosition()); |
354 | getCurReferenceResolver().addToResolutionList(resolutionInfoImpl, | 361 | getCurReferenceResolver().addToResolutionList(resolutionInfoImpl, |
355 | - ResolvableType.YANG_IDENTITYREF); | 362 | + ResolvableType.YANG_IDENTITYREF); |
356 | getCurReferenceResolver().resolveSelfFileLinking(ResolvableType.YANG_IDENTITYREF); | 363 | getCurReferenceResolver().resolveSelfFileLinking(ResolvableType.YANG_IDENTITYREF); |
357 | } | 364 | } |
358 | } | 365 | } |
... | @@ -362,7 +369,13 @@ public class YangResolutionInfoImpl<T> | ... | @@ -362,7 +369,13 @@ public class YangResolutionInfoImpl<T> |
362 | */ | 369 | */ |
363 | private void resolveTopOfStack(YangLinkingPhase linkingPhase) | 370 | private void resolveTopOfStack(YangLinkingPhase linkingPhase) |
364 | throws DataModelException { | 371 | throws DataModelException { |
365 | - ((Resolvable) getCurrentEntityToResolveFromStack()).resolve(); | 372 | + List<T> entityToResolve = (List<T>) ((Resolvable) getCurrentEntityToResolveFromStack()).resolve(); |
373 | + if (entityToResolve != null && !entityToResolve.isEmpty()) { | ||
374 | + Iterator<T> entityToResolveIterator = entityToResolve.listIterator(); | ||
375 | + while (entityToResolveIterator.hasNext()) { | ||
376 | + addUnresolvedEntitiesToStack(entityToResolveIterator.next()); | ||
377 | + } | ||
378 | + } | ||
366 | if (((Resolvable) getCurrentEntityToResolveFromStack()).getResolvableStatus() != INTRA_FILE_RESOLVED | 379 | if (((Resolvable) getCurrentEntityToResolveFromStack()).getResolvableStatus() != INTRA_FILE_RESOLVED |
367 | && ((Resolvable) getCurrentEntityToResolveFromStack()).getResolvableStatus() != UNDEFINED) { | 380 | && ((Resolvable) getCurrentEntityToResolveFromStack()).getResolvableStatus() != UNDEFINED) { |
368 | // Sets the resolution status in inside the type/uses/if-feature/leafref. | 381 | // Sets the resolution status in inside the type/uses/if-feature/leafref. |
... | @@ -371,6 +384,31 @@ public class YangResolutionInfoImpl<T> | ... | @@ -371,6 +384,31 @@ public class YangResolutionInfoImpl<T> |
371 | } | 384 | } |
372 | 385 | ||
373 | /** | 386 | /** |
387 | + * Adds the unresolved entities to the resolution list. | ||
388 | + * | ||
389 | + * @param entityToResolve entity to resolve | ||
390 | + * @throws DataModelException a violation of data model rules | ||
391 | + */ | ||
392 | + private void addUnresolvedEntitiesToStack(T entityToResolve) throws DataModelException { | ||
393 | + if (entityToResolve instanceof YangEntityToResolveInfoImpl) { | ||
394 | + YangEntityToResolveInfoImpl entityToResolveInfo = (YangEntityToResolveInfoImpl) entityToResolve; | ||
395 | + if (entityToResolveInfo.getEntityToResolve() instanceof YangLeafRef) { | ||
396 | + YangLeafRef leafref = (YangLeafRef) entityToResolveInfo.getEntityToResolve(); | ||
397 | + YangNode parentNodeOfLeafref = entityToResolveInfo.getHolderOfEntityToResolve(); | ||
398 | + leafref.setParentNodeOfLeafref(parentNodeOfLeafref); | ||
399 | + if (leafref.getResolvableStatus() == UNRESOLVED) { | ||
400 | + leafref.setResolvableStatus(INTRA_FILE_RESOLVED); | ||
401 | + } | ||
402 | + // Add resolution information to the list. | ||
403 | + YangResolutionInfoImpl resolutionInfoImpl = new YangResolutionInfoImpl<YangLeafRef>(leafref, | ||
404 | + parentNodeOfLeafref, entityToResolveInfo.getLineNumber(), | ||
405 | + entityToResolveInfo.getCharPosition()); | ||
406 | + addResolutionInfo(resolutionInfoImpl); | ||
407 | + } | ||
408 | + } | ||
409 | + } | ||
410 | + | ||
411 | + /** | ||
374 | * Resolves linking for a node child and siblings. | 412 | * Resolves linking for a node child and siblings. |
375 | * | 413 | * |
376 | * @throws DataModelException data model error | 414 | * @throws DataModelException data model error |
... | @@ -378,6 +416,10 @@ public class YangResolutionInfoImpl<T> | ... | @@ -378,6 +416,10 @@ public class YangResolutionInfoImpl<T> |
378 | private void linkTopOfStackReferenceUpdateStack() | 416 | private void linkTopOfStackReferenceUpdateStack() |
379 | throws DataModelException { | 417 | throws DataModelException { |
380 | 418 | ||
419 | + if (getCurrentEntityToResolveFromStack() instanceof YangLeafRef) { | ||
420 | + ((Resolvable) getCurrentEntityToResolveFromStack()).setResolvableStatus(INTRA_FILE_RESOLVED); | ||
421 | + return; | ||
422 | + } | ||
381 | /* | 423 | /* |
382 | * Check if self file reference is there, this will not check for the | 424 | * Check if self file reference is there, this will not check for the |
383 | * scenario when prefix is not present and type/uses is present in | 425 | * scenario when prefix is not present and type/uses is present in |
... | @@ -398,9 +440,6 @@ public class YangResolutionInfoImpl<T> | ... | @@ -398,9 +440,6 @@ public class YangResolutionInfoImpl<T> |
398 | if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) { | 440 | if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) { |
399 | resolveSelfFileLinkingForIfFeature(potentialAncestorWithReferredNode); | 441 | resolveSelfFileLinkingForIfFeature(potentialAncestorWithReferredNode); |
400 | return; | 442 | return; |
401 | - } else if (getCurrentEntityToResolveFromStack() instanceof YangLeafRef) { | ||
402 | - resolveSelfFileLinkingForLeafref(potentialAncestorWithReferredNode); | ||
403 | - return; | ||
404 | } else if ((getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) || | 443 | } else if ((getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) || |
405 | (getCurrentEntityToResolveFromStack() instanceof YangBase)) { | 444 | (getCurrentEntityToResolveFromStack() instanceof YangBase)) { |
406 | resolveSelfFileLinkingForBaseAndIdentityref(); | 445 | resolveSelfFileLinkingForBaseAndIdentityref(); |
... | @@ -435,69 +474,6 @@ public class YangResolutionInfoImpl<T> | ... | @@ -435,69 +474,6 @@ public class YangResolutionInfoImpl<T> |
435 | } | 474 | } |
436 | 475 | ||
437 | /** | 476 | /** |
438 | - * Resolves self file linking for leafref. | ||
439 | - * | ||
440 | - * @param potentialAncestorWithReferredNode leafref holder node | ||
441 | - * @throws DataModelException a violation of data model rules | ||
442 | - */ | ||
443 | - private void resolveSelfFileLinkingForLeafref(YangNode potentialAncestorWithReferredNode) | ||
444 | - throws DataModelException { | ||
445 | - | ||
446 | - YangNode ancestorWithTheReferredNode = potentialAncestorWithReferredNode; | ||
447 | - YangLeafRef leafref = (YangLeafRef) getCurrentEntityToResolveFromStack(); | ||
448 | - boolean referredLeafFound = false; | ||
449 | - | ||
450 | - /* | ||
451 | - * Takes absolute path and takes the root node as module/sub-module, | ||
452 | - * then sends the list of nodes for finding the target leaf. | ||
453 | - */ | ||
454 | - if (leafref.getPathType() == YangPathArgType.ABSOLUTE_PATH) { | ||
455 | - List<YangAtomicPath> atomicPathList = leafref.getAtomicPath(); | ||
456 | - if (atomicPathList != null && !atomicPathList.isEmpty()) { | ||
457 | - Iterator<YangAtomicPath> listOfYangAtomicPath = atomicPathList.listIterator(); | ||
458 | - if (getCurReferenceResolver() instanceof YangModule) { | ||
459 | - YangModule rootNode = (YangModule) getCurReferenceResolver(); | ||
460 | - // Sends list of nodes for finding the target leaf. | ||
461 | - referredLeafFound = isLeafReferenceFound(listOfYangAtomicPath, rootNode, | ||
462 | - referredLeafFound, potentialAncestorWithReferredNode); | ||
463 | - } else if (getCurReferenceResolver() instanceof YangSubModule) { | ||
464 | - YangSubModule rootNode = (YangSubModule) getCurReferenceResolver(); | ||
465 | - // Sends list of nodes for finding the target leaf. | ||
466 | - referredLeafFound = isLeafReferenceFound(listOfYangAtomicPath, rootNode, | ||
467 | - referredLeafFound, potentialAncestorWithReferredNode); | ||
468 | - } | ||
469 | - } | ||
470 | - /* | ||
471 | - * Takes relative path, goes to the parent node by using the | ||
472 | - * ancestor count and sends the list of nodes for finding the target | ||
473 | - * leaf. | ||
474 | - */ | ||
475 | - } else if (leafref.getPathType() == YangPathArgType.RELATIVE_PATH) { | ||
476 | - YangRelativePath yangRelativePath = leafref.getRelativePath(); | ||
477 | - int parentNodes = yangRelativePath.getAncestorNodeCount(); | ||
478 | - List<YangAtomicPath> atomicPathList = yangRelativePath.getAtomicPathList(); | ||
479 | - if (atomicPathList != null && !atomicPathList.isEmpty()) { | ||
480 | - Iterator<YangAtomicPath> listOfAtomicPath = atomicPathList.listIterator(); | ||
481 | - // Gets the root node from ancestor count. | ||
482 | - YangNode rootparentNode = getRootNodeWithAncestorCount(parentNodes, ancestorWithTheReferredNode); | ||
483 | - // Sends list of nodes for finding the target leaf. | ||
484 | - referredLeafFound = isLeafReferenceFound(listOfAtomicPath, rootparentNode, | ||
485 | - referredLeafFound, potentialAncestorWithReferredNode); | ||
486 | - } | ||
487 | - } | ||
488 | - if (referredLeafFound) { | ||
489 | - return; | ||
490 | - } | ||
491 | - /* | ||
492 | - * In case prefix is not present it's a candidate for inter-file | ||
493 | - * resolution via include list. | ||
494 | - */ | ||
495 | - if (getRefPrefix() == null) { | ||
496 | - ((Resolvable) getCurrentEntityToResolveFromStack()).setResolvableStatus(INTRA_FILE_RESOLVED); | ||
497 | - } | ||
498 | - } | ||
499 | - | ||
500 | - /** | ||
501 | * Resolves self file linking for base/identityref. | 477 | * Resolves self file linking for base/identityref. |
502 | * | 478 | * |
503 | * @throws DataModelException a violation of data model rules | 479 | * @throws DataModelException a violation of data model rules |
... | @@ -509,7 +485,7 @@ public class YangResolutionInfoImpl<T> | ... | @@ -509,7 +485,7 @@ public class YangResolutionInfoImpl<T> |
509 | String nodeName = null; | 485 | String nodeName = null; |
510 | 486 | ||
511 | if (getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) { | 487 | if (getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) { |
512 | - nodeName = ((YangIdentityRef) getCurrentEntityToResolveFromStack()).getName(); | 488 | + nodeName = ((YangIdentityRef) getCurrentEntityToResolveFromStack()).getName(); |
513 | } | 489 | } |
514 | 490 | ||
515 | if (getCurrentEntityToResolveFromStack() instanceof YangBase) { | 491 | if (getCurrentEntityToResolveFromStack() instanceof YangBase) { |
... | @@ -595,61 +571,9 @@ public class YangResolutionInfoImpl<T> | ... | @@ -595,61 +571,9 @@ public class YangResolutionInfoImpl<T> |
595 | } | 571 | } |
596 | 572 | ||
597 | /** | 573 | /** |
598 | - * Returns the status of the referred leaf/leaf-list found for leafref. | ||
599 | - * | ||
600 | - * @param listOfYangAtomicPath list of atomic paths | ||
601 | - * @param ancestorWithTheReferredNode the parent node of leafref | ||
602 | - * @param referredLeafFound status of referred leaf/leaf-list | ||
603 | - * @param potentialAncestorWithReferredNode holder of the leafref leaf | ||
604 | - * @return status of referred leaf | ||
605 | - * @throws DataModelException a violation of data model rules | ||
606 | - */ | ||
607 | - private boolean isLeafReferenceFound(Iterator<YangAtomicPath> listOfYangAtomicPath, | ||
608 | - YangNode ancestorWithTheReferredNode, boolean referredLeafFound, YangNode potentialAncestorWithReferredNode) | ||
609 | - throws DataModelException { | ||
610 | - | ||
611 | - while (listOfYangAtomicPath.hasNext()) { | ||
612 | - YangAtomicPath atomicPath = listOfYangAtomicPath.next(); | ||
613 | - String nodeName = atomicPath.getNodeIdentifier().getName(); | ||
614 | - | ||
615 | - // When child is not present, only leaf/leaf-list is available in the node. | ||
616 | - if (ancestorWithTheReferredNode.getChild() == null) { | ||
617 | - referredLeafFound = isReferredLeafOrLeafListFound(ancestorWithTheReferredNode, nodeName, (T) LINKED); | ||
618 | - break; | ||
619 | - } | ||
620 | - ancestorWithTheReferredNode = ancestorWithTheReferredNode.getChild(); | ||
621 | - | ||
622 | - // Checks all the siblings under the node and returns the matched node. | ||
623 | - YangNode nodeFound = isReferredNodeInSiblingProcessedForLeafref(ancestorWithTheReferredNode, nodeName); | ||
624 | - | ||
625 | - // When node is not found in all the siblings, leaf-list may be the node we have to find. | ||
626 | - if (nodeFound == null) { | ||
627 | - referredLeafFound = isReferredLeafOrLeafListFound(ancestorWithTheReferredNode.getParent(), nodeName, | ||
628 | - (T) LINKED); | ||
629 | - } else { | ||
630 | - ancestorWithTheReferredNode = nodeFound; | ||
631 | - | ||
632 | - // For the node check if path predicate is present and fill its values. | ||
633 | - List<YangPathPredicate> pathPredicateList = atomicPath.getPathPredicatesList(); | ||
634 | - if (pathPredicateList != null && !pathPredicateList.isEmpty()) { | ||
635 | - Iterator<YangPathPredicate> listOfYangPathPredicate = pathPredicateList.listIterator(); | ||
636 | - fillPathPredicatesForTheNode(ancestorWithTheReferredNode, listOfYangPathPredicate, | ||
637 | - potentialAncestorWithReferredNode); | ||
638 | - } | ||
639 | - } | ||
640 | - | ||
641 | - // If leaf is also not found and node is also not found return the status as false. | ||
642 | - if (!referredLeafFound && nodeFound == null) { | ||
643 | - break; | ||
644 | - } | ||
645 | - } | ||
646 | - return referredLeafFound; | ||
647 | - } | ||
648 | - | ||
649 | - /** | ||
650 | * Returns the status of the referred identity found for base/identityref. | 574 | * Returns the status of the referred identity found for base/identityref. |
651 | * | 575 | * |
652 | - * @param nodeName the name of the base nodeidentifier/identityref nodeidentifier | 576 | + * @param nodeName the name of the base nodeidentifier/identityref nodeidentifier |
653 | * @param ancestorWithTheReferredNode the parent node of base/identityref | 577 | * @param ancestorWithTheReferredNode the parent node of base/identityref |
654 | * @return status of referred base/identityref | 578 | * @return status of referred base/identityref |
655 | * @throws DataModelException a violation of data model rules | 579 | * @throws DataModelException a violation of data model rules |
... | @@ -682,166 +606,9 @@ public class YangResolutionInfoImpl<T> | ... | @@ -682,166 +606,9 @@ public class YangResolutionInfoImpl<T> |
682 | } | 606 | } |
683 | 607 | ||
684 | /** | 608 | /** |
685 | - * Fills the referred leaf or leaf-list inside the path predicates. | ||
686 | - * | ||
687 | - * @param ancestorWithTheReferredNode the actual node where YANG list will be present | ||
688 | - * @param listOfYangPathPredicate the path predicates present for the node | ||
689 | - * @param potentialAncestorWithReferredNode the current leaf node parent | ||
690 | - * @throws DataModelException a violation of data model rules | ||
691 | - */ | ||
692 | - private void fillPathPredicatesForTheNode(YangNode ancestorWithTheReferredNode, | ||
693 | - Iterator<YangPathPredicate> listOfYangPathPredicate, YangNode potentialAncestorWithReferredNode) | ||
694 | - throws DataModelException { | ||
695 | - | ||
696 | - while (listOfYangPathPredicate.hasNext()) { | ||
697 | - if (!(ancestorWithTheReferredNode instanceof YangList)) { | ||
698 | - throw new DataModelException("YANG file error: The path predicates are applicable only for list"); | ||
699 | - } | ||
700 | - YangPathPredicate pathPredicate = listOfYangPathPredicate.next(); | ||
701 | - YangNodeIdentifier leftNode = pathPredicate.getNodeIdentifier(); | ||
702 | - YangRelativePath relativePath = pathPredicate.getRightRelativePath(); | ||
703 | - | ||
704 | - // Checks that the left axis is filled in the path predicate. | ||
705 | - boolean isLeftLeafOrLeafListSetForLeftAxis = getLeftLeafOrLeafListInPredicate( | ||
706 | - (YangList) ancestorWithTheReferredNode, pathPredicate, leftNode); | ||
707 | - if (!isLeftLeafOrLeafListSetForLeftAxis) { | ||
708 | - throw new DataModelException( | ||
709 | - "YANG file error: The path predicate is not referring to an existing leaf/leaflist"); | ||
710 | - } | ||
711 | - int parentNodes = relativePath.getAncestorNodeCount(); | ||
712 | - | ||
713 | - // Finds the root node for the right relative path. | ||
714 | - YangNode rootParentNode = getRootNodeWithAncestorCount(parentNodes, potentialAncestorWithReferredNode); | ||
715 | - | ||
716 | - // Finds the leaf/leaf-list from the right side relative path. | ||
717 | - resolveRightAxisNodeInPathPredicate(relativePath, rootParentNode, pathPredicate); | ||
718 | - } | ||
719 | - } | ||
720 | - | ||
721 | - /** | ||
722 | - * Resolves the right axis node in the path predicate. | ||
723 | - * | ||
724 | - * @param relativePath the relative path in the path predicate | ||
725 | - * @param rootParentNode parent node from where the node has to be found | ||
726 | - * @param pathPredicate data tree reference in YANG list | ||
727 | - * @throws DataModelException a violation of data model rules | ||
728 | - */ | ||
729 | - private void resolveRightAxisNodeInPathPredicate(YangRelativePath relativePath, YangNode rootParentNode, | ||
730 | - YangPathPredicate pathPredicate) throws DataModelException { | ||
731 | - | ||
732 | - List<YangAtomicPath> absolutePathList = relativePath.getAtomicPathList(); | ||
733 | - if (absolutePathList != null && !absolutePathList.isEmpty()) { | ||
734 | - Iterator<YangAtomicPath> listOfYangAtomicPathForRightRelative = absolutePathList.listIterator(); | ||
735 | - while (listOfYangAtomicPathForRightRelative.hasNext()) { | ||
736 | - boolean isRightAxisNodeFound = false; | ||
737 | - YangAtomicPath absolutePathInPredicate = listOfYangAtomicPathForRightRelative.next(); | ||
738 | - String nodeNameInAtomicPath = absolutePathInPredicate.getNodeIdentifier().getName(); | ||
739 | - | ||
740 | - // When child is not there check the leaf/leaf-list. | ||
741 | - if (rootParentNode.getChild() == null) { | ||
742 | - isRightAxisNodeFound = isReferredLeafOrLeafListFound(rootParentNode, | ||
743 | - nodeNameInAtomicPath, (T) pathPredicate); | ||
744 | - if (!isRightAxisNodeFound) { | ||
745 | - throw new DataModelException( | ||
746 | - "YANG file error: The path predicates is not referring to an existing leaf/leaflist"); | ||
747 | - } | ||
748 | - break; | ||
749 | - } | ||
750 | - rootParentNode = rootParentNode.getChild(); | ||
751 | - YangNode nodeFoundInTheRelativePath = isReferredNodeInSiblingProcessedForLeafref( | ||
752 | - rootParentNode, nodeNameInAtomicPath); | ||
753 | - | ||
754 | - if (nodeFoundInTheRelativePath == null) { | ||
755 | - | ||
756 | - // When node is not found check the leaf/leaf-list. | ||
757 | - isRightAxisNodeFound = isReferredLeafOrLeafListFound(rootParentNode.getParent(), | ||
758 | - nodeNameInAtomicPath, (T) pathPredicate); | ||
759 | - } else { | ||
760 | - rootParentNode = nodeFoundInTheRelativePath; | ||
761 | - } | ||
762 | - if (!isRightAxisNodeFound && nodeFoundInTheRelativePath == null) { | ||
763 | - throw new DataModelException( | ||
764 | - "YANG file error: The path predicates is not referring to an existing leaf/leaflist"); | ||
765 | - } | ||
766 | - } | ||
767 | - } | ||
768 | - } | ||
769 | - | ||
770 | - /** | ||
771 | - * Returns the status, if referred leaf/leaf-list is found. | ||
772 | - * | ||
773 | - * @param ancestorWithTheReferredNode the parent node of leaf/leaf-list | ||
774 | - * @param nodeName the name of the leaf/leaf-list | ||
775 | - * @param statusOrPathPredicate the status to be set for the leaf-ref or the path predicate | ||
776 | - * @return status of the target node is found | ||
777 | - * @throws DataModelException a violation of data model rules | ||
778 | - */ | ||
779 | - private boolean isReferredLeafOrLeafListFound(YangNode ancestorWithTheReferredNode, String nodeName, | ||
780 | - T statusOrPathPredicate) throws DataModelException { | ||
781 | - | ||
782 | - if (!(ancestorWithTheReferredNode instanceof YangLeavesHolder)) { | ||
783 | - throw new DataModelException("Yang file error: The target node of leafref is invalid."); | ||
784 | - } | ||
785 | - YangLeavesHolder leavesHolder = (YangLeavesHolder) ancestorWithTheReferredNode; | ||
786 | - if (leavesHolder.getListOfLeaf() != null) { | ||
787 | - Iterator<YangLeaf> yangLeavesList = leavesHolder.getListOfLeaf().listIterator(); | ||
788 | - while (yangLeavesList.hasNext()) { | ||
789 | - YangLeaf yangleaf = yangLeavesList.next(); | ||
790 | - if (yangleaf.getName().contentEquals(nodeName)) { | ||
791 | - if (statusOrPathPredicate instanceof ResolvableStatus) { | ||
792 | - ResolvableStatus status = (ResolvableStatus) statusOrPathPredicate; | ||
793 | - | ||
794 | - // Sets the referred leaf to YANG leafref. | ||
795 | - ((YangLeafRef) getCurrentEntityToResolveFromStack()).setReferredLeafOrLeafList(yangleaf); | ||
796 | - | ||
797 | - // Adds reference link of entity to the node under resolution. | ||
798 | - addReferredEntityLink(ancestorWithTheReferredNode, status); | ||
799 | - addUnResolvedLeafRefTypeToStack((T) yangleaf, ancestorWithTheReferredNode); | ||
800 | - return true; | ||
801 | - } else if (statusOrPathPredicate instanceof YangPathPredicate) { | ||
802 | - YangPathPredicate pathPredicate = (YangPathPredicate) statusOrPathPredicate; | ||
803 | - | ||
804 | - // Sets the right axis node. | ||
805 | - pathPredicate.setRightAxisNode(yangleaf); | ||
806 | - return true; | ||
807 | - } else { | ||
808 | - throw new DataModelException("YANG file error: The target node of leafref is invalid."); | ||
809 | - } | ||
810 | - } | ||
811 | - } | ||
812 | - } | ||
813 | - if (leavesHolder.getListOfLeafList() != null) { | ||
814 | - Iterator<YangLeafList> yangLeafListList = leavesHolder.getListOfLeafList().listIterator(); | ||
815 | - while (yangLeafListList.hasNext()) { | ||
816 | - YangLeafList yangLeaflist = yangLeafListList.next(); | ||
817 | - if (yangLeaflist.getName().contentEquals(nodeName)) { | ||
818 | - if (statusOrPathPredicate instanceof ResolvableStatus) { | ||
819 | - ResolvableStatus status = (ResolvableStatus) statusOrPathPredicate; | ||
820 | - | ||
821 | - // Sets the referred leaf-list to YANG leafref. | ||
822 | - ((YangLeafRef) getCurrentEntityToResolveFromStack()).setReferredLeafOrLeafList(yangLeaflist); | ||
823 | - | ||
824 | - // Adds reference link of entity to the node under resolution. | ||
825 | - addReferredEntityLink(ancestorWithTheReferredNode, status); | ||
826 | - addUnResolvedLeafRefTypeToStack((T) yangLeaflist, ancestorWithTheReferredNode); | ||
827 | - return true; | ||
828 | - } else if (statusOrPathPredicate instanceof YangPathPredicate) { | ||
829 | - YangPathPredicate pathPredicate = (YangPathPredicate) statusOrPathPredicate; | ||
830 | - pathPredicate.setRightAxisNode(yangLeaflist); | ||
831 | - return true; | ||
832 | - } else { | ||
833 | - throw new DataModelException("YANG file error: The target node of leafref is invalid."); | ||
834 | - } | ||
835 | - } | ||
836 | - } | ||
837 | - } | ||
838 | - return false; | ||
839 | - } | ||
840 | - | ||
841 | - /** | ||
842 | * Adds the unresolved constructs to stack which has to be resolved for leafref. | 609 | * Adds the unresolved constructs to stack which has to be resolved for leafref. |
843 | * | 610 | * |
844 | - * @param yangleafOrLeafList YANG leaf or leaf list which holds the type | 611 | + * @param yangleafOrLeafList YANG leaf or leaf list which holds the type |
845 | * @param ancestorWithTheReferredNode holder of the YANG leaf or leaf list | 612 | * @param ancestorWithTheReferredNode holder of the YANG leaf or leaf list |
846 | */ | 613 | */ |
847 | private void addUnResolvedLeafRefTypeToStack(T yangleafOrLeafList, YangNode ancestorWithTheReferredNode) { | 614 | private void addUnResolvedLeafRefTypeToStack(T yangleafOrLeafList, YangNode ancestorWithTheReferredNode) { |
... | @@ -880,40 +647,6 @@ public class YangResolutionInfoImpl<T> | ... | @@ -880,40 +647,6 @@ public class YangResolutionInfoImpl<T> |
880 | } | 647 | } |
881 | 648 | ||
882 | /** | 649 | /** |
883 | - * Returns true if referred leaf/leaf-list is found in a particular node. This is for path in path predicate. | ||
884 | - * | ||
885 | - * @param listForLeaf list node where referred leaf is found | ||
886 | - * @param pathPredicate path predicate instance where the value of nodes to be found are available | ||
887 | - * @param leftNode node identifier of the left side parameter in path predicate | ||
888 | - * @return status of the leaf/leaf-list found | ||
889 | - */ | ||
890 | - private boolean getLeftLeafOrLeafListInPredicate(YangList listForLeaf, YangPathPredicate pathPredicate, | ||
891 | - YangNodeIdentifier leftNode) { | ||
892 | - | ||
893 | - if (listForLeaf.getListOfLeaf() != null) { | ||
894 | - Iterator<YangLeaf> yangLeavesUnderList = listForLeaf.getListOfLeaf().listIterator(); | ||
895 | - while (yangLeavesUnderList.hasNext()) { | ||
896 | - YangLeaf yangleafUnderList = yangLeavesUnderList.next(); | ||
897 | - if (yangleafUnderList.getName().contentEquals(leftNode.getName())) { | ||
898 | - pathPredicate.setLeftAxisNode(yangleafUnderList); | ||
899 | - return true; | ||
900 | - } | ||
901 | - } | ||
902 | - } | ||
903 | - if (listForLeaf.getListOfLeafList() != null) { | ||
904 | - Iterator<YangLeafList> yangLeavesListUnderList = listForLeaf.getListOfLeafList().listIterator(); | ||
905 | - while (yangLeavesListUnderList.hasNext()) { | ||
906 | - YangLeafList yangleafListUnderList = yangLeavesListUnderList.next(); | ||
907 | - if (yangleafListUnderList.getName().contentEquals(leftNode.getName())) { | ||
908 | - pathPredicate.setLeftAxisNode(yangleafListUnderList); | ||
909 | - return true; | ||
910 | - } | ||
911 | - } | ||
912 | - } | ||
913 | - return false; | ||
914 | - } | ||
915 | - | ||
916 | - /** | ||
917 | * Returns feature holder(module/sub-module node) . | 650 | * Returns feature holder(module/sub-module node) . |
918 | * | 651 | * |
919 | * @param potentialAncestorWithReferredNode if-feature holder node | 652 | * @param potentialAncestorWithReferredNode if-feature holder node |
... | @@ -984,7 +717,7 @@ public class YangResolutionInfoImpl<T> | ... | @@ -984,7 +717,7 @@ public class YangResolutionInfoImpl<T> |
984 | * @throws DataModelException data model errors | 717 | * @throws DataModelException data model errors |
985 | */ | 718 | */ |
986 | private YangNode isReferredNodeInSiblingProcessedForIdentity(YangNode potentialReferredNode, | 719 | private YangNode isReferredNodeInSiblingProcessedForIdentity(YangNode potentialReferredNode, |
987 | - String referredNodeName) throws DataModelException { | 720 | + String referredNodeName) throws DataModelException { |
988 | 721 | ||
989 | while (potentialReferredNode != null) { | 722 | while (potentialReferredNode != null) { |
990 | if (potentialReferredNode instanceof YangIdentity) { | 723 | if (potentialReferredNode instanceof YangIdentity) { |
... | @@ -1002,7 +735,7 @@ public class YangResolutionInfoImpl<T> | ... | @@ -1002,7 +735,7 @@ public class YangResolutionInfoImpl<T> |
1002 | * Checks if the current reference node name and the name in the path are equal. | 735 | * Checks if the current reference node name and the name in the path are equal. |
1003 | * | 736 | * |
1004 | * @param currentReferredNode the node where the reference is pointed | 737 | * @param currentReferredNode the node where the reference is pointed |
1005 | - * @param nameOfNodeinPath name of the node in the path | 738 | + * @param nameOfNodeinPath name of the node in the path |
1006 | * @return status of the match between the name | 739 | * @return status of the match between the name |
1007 | * @throws DataModelException a violation of data model rules | 740 | * @throws DataModelException a violation of data model rules |
1008 | */ | 741 | */ |
... | @@ -1023,7 +756,7 @@ public class YangResolutionInfoImpl<T> | ... | @@ -1023,7 +756,7 @@ public class YangResolutionInfoImpl<T> |
1023 | /** | 756 | /** |
1024 | * Checks if the current reference node name and the name in the base/identityref base are equal. | 757 | * Checks if the current reference node name and the name in the base/identityref base are equal. |
1025 | * | 758 | * |
1026 | - * @param currentReferredNode the node where the reference is pointed | 759 | + * @param currentReferredNode the node where the reference is pointed |
1027 | * @param nameOfIdentityRefBase name of the base in the base/identityref base | 760 | * @param nameOfIdentityRefBase name of the base in the base/identityref base |
1028 | * @return status of the match between the name | 761 | * @return status of the match between the name |
1029 | * @throws DataModelException a violation of data model rules | 762 | * @throws DataModelException a violation of data model rules |
... | @@ -1122,7 +855,7 @@ public class YangResolutionInfoImpl<T> | ... | @@ -1122,7 +855,7 @@ public class YangResolutionInfoImpl<T> |
1122 | } | 855 | } |
1123 | } else { | 856 | } else { |
1124 | throw new DataModelException("Data Model Exception: Entity to resolved is other than type/" + | 857 | throw new DataModelException("Data Model Exception: Entity to resolved is other than type/" + |
1125 | - "uses/base/identityref"); | 858 | + "uses/base/identityref"); |
1126 | } | 859 | } |
1127 | return false; | 860 | return false; |
1128 | } | 861 | } |
... | @@ -1211,7 +944,7 @@ public class YangResolutionInfoImpl<T> | ... | @@ -1211,7 +944,7 @@ public class YangResolutionInfoImpl<T> |
1211 | ((YangIdentityRef) getCurrentEntityToResolveFromStack()).setReferredIdentity((YangIdentity) referredNode); | 944 | ((YangIdentityRef) getCurrentEntityToResolveFromStack()).setReferredIdentity((YangIdentity) referredNode); |
1212 | } else { | 945 | } else { |
1213 | throw new DataModelException("Data Model Exception: Entity to resolved is other than type" + | 946 | throw new DataModelException("Data Model Exception: Entity to resolved is other than type" + |
1214 | - "/uses/base/identityref"); | 947 | + "/uses/base/identityref"); |
1215 | } | 948 | } |
1216 | 949 | ||
1217 | // Sets the resolution status in inside the type/uses. | 950 | // Sets the resolution status in inside the type/uses. |
... | @@ -1260,7 +993,7 @@ public class YangResolutionInfoImpl<T> | ... | @@ -1260,7 +993,7 @@ public class YangResolutionInfoImpl<T> |
1260 | addUnResolvedBaseToStack(referredNode); | 993 | addUnResolvedBaseToStack(referredNode); |
1261 | } else { | 994 | } else { |
1262 | throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses/" + | 995 | throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses/" + |
1263 | - "base/identityref"); | 996 | + "base/identityref"); |
1264 | } | 997 | } |
1265 | } | 998 | } |
1266 | 999 | ||
... | @@ -1439,9 +1172,9 @@ public class YangResolutionInfoImpl<T> | ... | @@ -1439,9 +1172,9 @@ public class YangResolutionInfoImpl<T> |
1439 | throw new DataModelException("Data Model Exception: Entity to resolved is not Resolvable"); | 1172 | throw new DataModelException("Data Model Exception: Entity to resolved is not Resolvable"); |
1440 | } | 1173 | } |
1441 | 1174 | ||
1442 | - if (entityToResolve instanceof YangXPathResolver) { | 1175 | + if (entityToResolve instanceof YangXPathResolver && !(entityToResolve instanceof YangLeafRef)) { |
1443 | //Process x-path linking. | 1176 | //Process x-path linking. |
1444 | - processXPathLinking(getEntityToResolveInfo(), dataModelRootNode); | 1177 | + processXPathLinking(entityToResolve, dataModelRootNode); |
1445 | 1178 | ||
1446 | } else { | 1179 | } else { |
1447 | 1180 | ||
... | @@ -1458,13 +1191,14 @@ public class YangResolutionInfoImpl<T> | ... | @@ -1458,13 +1191,14 @@ public class YangResolutionInfoImpl<T> |
1458 | /** | 1191 | /** |
1459 | * Process x-path linking for augment and leaf-ref. | 1192 | * Process x-path linking for augment and leaf-ref. |
1460 | * | 1193 | * |
1461 | - * @param entityToResolveInfo entity to resolve | 1194 | + * @param entityToResolve entity to resolve |
1462 | - * @param root root node | 1195 | + * @param root root node |
1463 | */ | 1196 | */ |
1464 | - private void processXPathLinking(YangEntityToResolveInfoImpl<T> entityToResolveInfo, | 1197 | + private void processXPathLinking(T entityToResolve, |
1465 | YangReferenceResolver root) { | 1198 | YangReferenceResolver root) { |
1199 | + | ||
1466 | YangXpathLinker<T> xPathLinker = new YangXpathLinker<T>(); | 1200 | YangXpathLinker<T> xPathLinker = new YangXpathLinker<T>(); |
1467 | - T entityToResolve = entityToResolveInfo.getEntityToResolve(); | 1201 | + |
1468 | if (entityToResolve instanceof YangAugment) { | 1202 | if (entityToResolve instanceof YangAugment) { |
1469 | YangNode targetNode = null; | 1203 | YangNode targetNode = null; |
1470 | YangAugment augment = (YangAugment) entityToResolve; | 1204 | YangAugment augment = (YangAugment) entityToResolve; |
... | @@ -1488,23 +1222,29 @@ public class YangResolutionInfoImpl<T> | ... | @@ -1488,23 +1222,29 @@ public class YangResolutionInfoImpl<T> |
1488 | } else if (entityToResolve instanceof YangLeafRef) { | 1222 | } else if (entityToResolve instanceof YangLeafRef) { |
1489 | YangLeafRef leafRef = (YangLeafRef) entityToResolve; | 1223 | YangLeafRef leafRef = (YangLeafRef) entityToResolve; |
1490 | Object target = xPathLinker.processLeafRefXpathLinking(leafRef.getAtomicPath(), | 1224 | Object target = xPathLinker.processLeafRefXpathLinking(leafRef.getAtomicPath(), |
1491 | - (YangNode) root); | 1225 | + (YangNode) root, leafRef); |
1492 | if (target != null) { | 1226 | if (target != null) { |
1493 | YangLeaf leaf = null; | 1227 | YangLeaf leaf = null; |
1494 | YangLeafList leafList = null; | 1228 | YangLeafList leafList = null; |
1495 | leafRef.setReferredLeafOrLeafList(target); | 1229 | leafRef.setReferredLeafOrLeafList(target); |
1496 | if (target instanceof YangLeaf) { | 1230 | if (target instanceof YangLeaf) { |
1497 | leaf = (YangLeaf) target; | 1231 | leaf = (YangLeaf) target; |
1498 | - leafRef.setEffectiveDataType(leaf.getDataType()); | 1232 | + leafRef.setResolvableStatus(INTER_FILE_LINKED); |
1233 | + addUnResolvedLeafRefTypeToStack((T) leaf, getEntityToResolveInfo().getHolderOfEntityToResolve()); | ||
1499 | } else { | 1234 | } else { |
1500 | leafList = (YangLeafList) target; | 1235 | leafList = (YangLeafList) target; |
1501 | - leafRef.setEffectiveDataType(leafList.getDataType()); | 1236 | + leafRef.setResolvableStatus(INTER_FILE_LINKED); |
1237 | + addUnResolvedLeafRefTypeToStack((T) leafList, | ||
1238 | + getEntityToResolveInfo().getHolderOfEntityToResolve()); | ||
1502 | } | 1239 | } |
1503 | - leafRef.setResolvableStatus(RESOLVED); | ||
1504 | //TODO: add logic for leaf-ref for path predicates. | 1240 | //TODO: add logic for leaf-ref for path predicates. |
1505 | } else { | 1241 | } else { |
1506 | - throw new LinkerException("YANG file error: Unable to find base leaf/leaf-list for given leafref " | 1242 | + LinkerException linkerException = new LinkerException("YANG file error: Unable to find base " + |
1243 | + "leaf/leaf-list for given leafref path " | ||
1507 | + leafRef.getPath()); | 1244 | + leafRef.getPath()); |
1245 | + linkerException.setCharPosition(leafRef.getCharPosition()); | ||
1246 | + linkerException.setLine(leafRef.getLineNumber()); | ||
1247 | + throw linkerException; | ||
1508 | } | 1248 | } |
1509 | } | 1249 | } |
1510 | } | 1250 | } |
... | @@ -1524,36 +1264,13 @@ public class YangResolutionInfoImpl<T> | ... | @@ -1524,36 +1264,13 @@ public class YangResolutionInfoImpl<T> |
1524 | refPrefix = ((YangUses) getCurrentEntityToResolveFromStack()).getPrefix(); | 1264 | refPrefix = ((YangUses) getCurrentEntityToResolveFromStack()).getPrefix(); |
1525 | } else if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) { | 1265 | } else if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) { |
1526 | refPrefix = ((YangIfFeature) getCurrentEntityToResolveFromStack()).getPrefix(); | 1266 | refPrefix = ((YangIfFeature) getCurrentEntityToResolveFromStack()).getPrefix(); |
1527 | - } else if (getCurrentEntityToResolveFromStack() instanceof YangLeafRef) { | ||
1528 | - refPrefix = refPrefixForLeafRef(); | ||
1529 | } else if (getCurrentEntityToResolveFromStack() instanceof YangBase) { | 1267 | } else if (getCurrentEntityToResolveFromStack() instanceof YangBase) { |
1530 | refPrefix = ((YangBase) getCurrentEntityToResolveFromStack()).getBaseIdentifier().getPrefix(); | 1268 | refPrefix = ((YangBase) getCurrentEntityToResolveFromStack()).getBaseIdentifier().getPrefix(); |
1531 | } else if (getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) { | 1269 | } else if (getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) { |
1532 | refPrefix = ((YangIdentityRef) getCurrentEntityToResolveFromStack()).getPrefix(); | 1270 | refPrefix = ((YangIdentityRef) getCurrentEntityToResolveFromStack()).getPrefix(); |
1533 | } else { | 1271 | } else { |
1534 | throw new DataModelException("Data Model Exception: Entity to resolved is other than " + | 1272 | throw new DataModelException("Data Model Exception: Entity to resolved is other than " + |
1535 | - "type/uses/base/identityref"); | 1273 | + "type/uses/base/identityref"); |
1536 | - } | ||
1537 | - return refPrefix; | ||
1538 | - } | ||
1539 | - | ||
1540 | - /** | ||
1541 | - * Returns the referenced prefix for leafref under resolution. | ||
1542 | - * | ||
1543 | - * @return referenced prefix of leafref under resolution | ||
1544 | - */ | ||
1545 | - private String refPrefixForLeafRef() { | ||
1546 | - | ||
1547 | - String refPrefix; | ||
1548 | - if (((YangLeafRef) getCurrentEntityToResolveFromStack()).getPathType() == YangPathArgType.ABSOLUTE_PATH) { | ||
1549 | - List<YangAtomicPath> theList = ((YangLeafRef) getCurrentEntityToResolveFromStack()).getAtomicPath(); | ||
1550 | - YangAtomicPath absPath = theList.iterator().next(); | ||
1551 | - refPrefix = absPath.getNodeIdentifier().getPrefix(); | ||
1552 | - } else { | ||
1553 | - YangRelativePath relativePath = ((YangLeafRef) getCurrentEntityToResolveFromStack()).getRelativePath(); | ||
1554 | - List<YangAtomicPath> theList = relativePath.getAtomicPathList(); | ||
1555 | - YangAtomicPath absPath = theList.iterator().next(); | ||
1556 | - refPrefix = absPath.getNodeIdentifier().getPrefix(); | ||
1557 | } | 1274 | } |
1558 | return refPrefix; | 1275 | return refPrefix; |
1559 | } | 1276 | } |
... | @@ -1638,6 +1355,12 @@ public class YangResolutionInfoImpl<T> | ... | @@ -1638,6 +1355,12 @@ public class YangResolutionInfoImpl<T> |
1638 | private void linkInterFileTopOfStackRefUpdateStack() | 1355 | private void linkInterFileTopOfStackRefUpdateStack() |
1639 | throws DataModelException { | 1356 | throws DataModelException { |
1640 | 1357 | ||
1358 | + if (getCurrentEntityToResolveFromStack() instanceof YangLeafRef) { | ||
1359 | + // When leafref path comes with relative path, it will be converted to absolute path. | ||
1360 | + setAbsolutePathFromRelativePathInLeafref(getCurrentEntityToResolveFromStack()); | ||
1361 | + processXPathLinking(getCurrentEntityToResolveFromStack(), getCurReferenceResolver()); | ||
1362 | + return; | ||
1363 | + } | ||
1641 | /* | 1364 | /* |
1642 | * Obtain the referred node of top of stack entity under resolution | 1365 | * Obtain the referred node of top of stack entity under resolution |
1643 | */ | 1366 | */ |
... | @@ -1688,27 +1411,141 @@ public class YangResolutionInfoImpl<T> | ... | @@ -1688,27 +1411,141 @@ public class YangResolutionInfoImpl<T> |
1688 | dataModelException.setCharPosition(getCharPosition()); | 1411 | dataModelException.setCharPosition(getCharPosition()); |
1689 | throw dataModelException; | 1412 | throw dataModelException; |
1690 | } else { | 1413 | } else { |
1691 | - /* | 1414 | + ((Resolvable) getCurrentEntityToResolveFromStack()).setResolvableStatus(INTER_FILE_LINKED); |
1692 | - * If referred node is already linked, then just change the status | 1415 | + addUnresolvedRecursiveReferenceToStack((YangNode) referredNode); |
1693 | - * and push to the stack. | 1416 | + } |
1694 | - */ | 1417 | + } |
1695 | - if (getCurrentEntityToResolveFromStack() instanceof YangLeafRef) { | 1418 | + |
1696 | - ((Resolvable) getCurrentEntityToResolveFromStack()).setResolvableStatus(INTER_FILE_LINKED); | 1419 | + /** |
1697 | - if (referredNode instanceof YangLeaf) { | 1420 | + * Sets the leafref with absolute path from the relative path. |
1698 | - YangLeaf yangleaf = (YangLeaf) referredNode; | 1421 | + * |
1699 | - addUnResolvedLeafRefTypeToStack((T) yangleaf, (YangNode) yangleaf.getContainedIn()); | 1422 | + * @param resolutionInfo information about the YANG construct which has to be resolved |
1700 | - } else if (referredNode instanceof YangLeafList) { | 1423 | + * @throws DataModelException a violation of data model rules |
1701 | - YangLeafList yangLeafList = (YangLeafList) referredNode; | 1424 | + */ |
1702 | - addUnResolvedLeafRefTypeToStack((T) yangLeafList, (YangNode) yangLeafList.getContainedIn()); | 1425 | + public void setAbsolutePathFromRelativePathInLeafref(T resolutionInfo) throws DataModelException { |
1426 | + if (resolutionInfo instanceof YangLeafRef) { | ||
1427 | + | ||
1428 | + YangNode parentOfLeafref = ((YangLeafRef) resolutionInfo).getParentNodeOfLeafref(); | ||
1429 | + YangLeafRef leafref = (YangLeafRef) resolutionInfo; | ||
1430 | + | ||
1431 | + // Checks if the leafref has relative path in it. | ||
1432 | + if (leafref.getPathType() == YangPathArgType.RELATIVE_PATH) { | ||
1433 | + YangRelativePath relativePath = leafref.getRelativePath(); | ||
1434 | + List<YangAtomicPath> absoluteInRelative = relativePath.getAtomicPathList(); | ||
1435 | + int numberOfAncestors = relativePath.getAncestorNodeCount(); | ||
1436 | + | ||
1437 | + // Gets the root node from the ancestor count. | ||
1438 | + T nodeOrAugmentList = getRootNodeWithAncestorCountForLeafref(numberOfAncestors, parentOfLeafref, | ||
1439 | + leafref); | ||
1440 | + if (nodeOrAugmentList instanceof YangNode) { | ||
1441 | + String pathNameToBePrefixed = EMPTY_STRING; | ||
1442 | + YangNode rootNode = (YangNode) nodeOrAugmentList; | ||
1443 | + // Forms a new absolute path from the relative path | ||
1444 | + while (!(rootNode instanceof YangReferenceResolver)) { | ||
1445 | + pathNameToBePrefixed = rootNode.getName() + SLASH_FOR_STRING + pathNameToBePrefixed; | ||
1446 | + rootNode = rootNode.getParent(); | ||
1447 | + if (rootNode == null) { | ||
1448 | + throw new DataModelException("Internal datamodel error: Datamodel tree is not correct"); | ||
1449 | + } | ||
1450 | + } | ||
1451 | + fillAbsolutePathValuesInLeafref(leafref, pathNameToBePrefixed, absoluteInRelative); | ||
1452 | + } else { | ||
1453 | + List<String> listOfAugment = (List<String>) nodeOrAugmentList; | ||
1454 | + Iterator<String> listOfAugmentIterator = listOfAugment.listIterator(); | ||
1455 | + String augment = EMPTY_STRING; | ||
1456 | + while (listOfAugmentIterator.hasNext()) { | ||
1457 | + augment = augment + SLASH_FOR_STRING + listOfAugmentIterator.next(); | ||
1458 | + } | ||
1459 | + fillAbsolutePathValuesInLeafref(leafref, augment, absoluteInRelative); | ||
1703 | } | 1460 | } |
1704 | - } else { | ||
1705 | - ((Resolvable) getCurrentEntityToResolveFromStack()).setResolvableStatus(INTER_FILE_LINKED); | ||
1706 | - addUnresolvedRecursiveReferenceToStack((YangNode) referredNode); | ||
1707 | } | 1461 | } |
1708 | } | 1462 | } |
1709 | } | 1463 | } |
1710 | 1464 | ||
1711 | /** | 1465 | /** |
1466 | + * Fills the absolute path values in the leafref from relative path. | ||
1467 | + * | ||
1468 | + * @param leafref instance of YANG leafref | ||
1469 | + * @param pathNameToBePrefixed path name which has to be prefixed to relative path | ||
1470 | + * @param atomicPathsInRelative atomic paths in relative | ||
1471 | + * @throws DataModelException a violation of data model rules | ||
1472 | + */ | ||
1473 | + private void fillAbsolutePathValuesInLeafref(YangLeafRef leafref, String pathNameToBePrefixed, | ||
1474 | + List<YangAtomicPath> atomicPathsInRelative) throws DataModelException { | ||
1475 | + | ||
1476 | + leafref.setPathType(YangPathArgType.ABSOLUTE_PATH); | ||
1477 | + String[] pathName = new String[0]; | ||
1478 | + if (pathNameToBePrefixed != EMPTY_STRING && pathNameToBePrefixed != null) { | ||
1479 | + pathName = pathNameToBePrefixed.split(SLASH_FOR_STRING); | ||
1480 | + } | ||
1481 | + List<YangAtomicPath> finalListForAbsolute = new LinkedList<>(); | ||
1482 | + for (String value : pathName) { | ||
1483 | + if (value != null && !value.isEmpty() && value != EMPTY_STRING) { | ||
1484 | + YangNodeIdentifier nodeIdentifier = getValidNodeIdentifier(value, YangConstructType.PATH_DATA); | ||
1485 | + YangAtomicPath atomicPath = new YangAtomicPath(); | ||
1486 | + atomicPath.setNodeIdentifier(nodeIdentifier); | ||
1487 | + finalListForAbsolute.add(atomicPath); | ||
1488 | + } | ||
1489 | + } | ||
1490 | + if (atomicPathsInRelative != null && !atomicPathsInRelative.isEmpty()) { | ||
1491 | + Iterator<YangAtomicPath> atomicPathIterator = atomicPathsInRelative.listIterator(); | ||
1492 | + while (atomicPathIterator.hasNext()) { | ||
1493 | + YangAtomicPath yangAtomicPath = atomicPathIterator.next(); | ||
1494 | + finalListForAbsolute.add(yangAtomicPath); | ||
1495 | + } | ||
1496 | + leafref.setAtomicPath(finalListForAbsolute); | ||
1497 | + } else { | ||
1498 | + DataModelException dataModelException = new DataModelException("YANG file error: The target node, in the " + | ||
1499 | + "leafref path " + leafref.getPath() + ", is invalid."); | ||
1500 | + dataModelException.setCharPosition(leafref.getCharPosition()); | ||
1501 | + dataModelException.setLine(leafref.getLineNumber()); | ||
1502 | + throw dataModelException; | ||
1503 | + } | ||
1504 | + } | ||
1505 | + | ||
1506 | + /** | ||
1507 | + * Returns the root parent with respect to the ancestor count from leafref. | ||
1508 | + * | ||
1509 | + * @param ancestorCount count of node where parent node can be reached | ||
1510 | + * @param currentParent current parent node | ||
1511 | + * @param leafref instance of YANG leafref | ||
1512 | + * @return node where the ancestor count stops or augment path name list | ||
1513 | + * @throws DataModelException a violation of data model rules | ||
1514 | + */ | ||
1515 | + private T getRootNodeWithAncestorCountForLeafref(int ancestorCount, YangNode currentParent, YangLeafRef leafref) | ||
1516 | + throws DataModelException { | ||
1517 | + | ||
1518 | + int currentParentCount = 1; | ||
1519 | + currentParent = skipInvalidDataNodes(currentParent, leafref); | ||
1520 | + if (currentParent instanceof YangAugment) { | ||
1521 | + YangAugment augment = (YangAugment) currentParent; | ||
1522 | + List<String> valueInAugment = getPathWithAugment(augment, ancestorCount - currentParentCount); | ||
1523 | + return (T) valueInAugment; | ||
1524 | + } else { | ||
1525 | + while (currentParentCount < ancestorCount) { | ||
1526 | + YangNode currentSkippedParent = skipInvalidDataNodes(currentParent, leafref); | ||
1527 | + if (currentSkippedParent == currentParent) { | ||
1528 | + if (currentParent.getParent() == null) { | ||
1529 | + throw new DataModelException("YANG file error: The target node, in the leafref path " | ||
1530 | + + leafref.getPath() + ", is invalid."); | ||
1531 | + } | ||
1532 | + currentParent = currentParent.getParent(); | ||
1533 | + } else { | ||
1534 | + currentParent = currentSkippedParent; | ||
1535 | + continue; | ||
1536 | + } | ||
1537 | + currentParentCount = currentParentCount + 1; | ||
1538 | + if (currentParent instanceof YangAugment) { | ||
1539 | + YangAugment augment = (YangAugment) currentParent; | ||
1540 | + List<String> valueInAugment = getPathWithAugment(augment, ancestorCount - currentParentCount); | ||
1541 | + return (T) valueInAugment; | ||
1542 | + } | ||
1543 | + } | ||
1544 | + } | ||
1545 | + return (T) currentParent; | ||
1546 | + } | ||
1547 | + | ||
1548 | + /** | ||
1712 | * Finds and resolves with include list. | 1549 | * Finds and resolves with include list. |
1713 | * | 1550 | * |
1714 | * @return true if resolved, false otherwise | 1551 | * @return true if resolved, false otherwise |
... | @@ -1728,15 +1565,6 @@ public class YangResolutionInfoImpl<T> | ... | @@ -1728,15 +1565,6 @@ public class YangResolutionInfoImpl<T> |
1728 | linkedNode = findRefGrouping(yangInclude.getIncludedNode()); | 1565 | linkedNode = findRefGrouping(yangInclude.getIncludedNode()); |
1729 | } else if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) { | 1566 | } else if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) { |
1730 | linkedNode = findRefFeature(yangInclude.getIncludedNode()); | 1567 | linkedNode = findRefFeature(yangInclude.getIncludedNode()); |
1731 | - } else if (getCurrentEntityToResolveFromStack() instanceof YangLeafRef) { | ||
1732 | - boolean referredNode = findRefLeaf(yangInclude.getIncludedNode()); | ||
1733 | - /* | ||
1734 | - * Update the current reference resolver to external | ||
1735 | - * module/sub-module containing the referred typedef/grouping. | ||
1736 | - */ | ||
1737 | - setCurReferenceResolver((YangReferenceResolver) yangInclude.getIncludedNode()); | ||
1738 | - | ||
1739 | - return referredNode; | ||
1740 | } else if (getCurrentEntityToResolveFromStack() instanceof YangBase) { | 1568 | } else if (getCurrentEntityToResolveFromStack() instanceof YangBase) { |
1741 | linkedNode = findRefIdentity(yangInclude.getIncludedNode()); | 1569 | linkedNode = findRefIdentity(yangInclude.getIncludedNode()); |
1742 | } else if (getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) { | 1570 | } else if (getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) { |
... | @@ -1785,16 +1613,6 @@ public class YangResolutionInfoImpl<T> | ... | @@ -1785,16 +1613,6 @@ public class YangResolutionInfoImpl<T> |
1785 | linkedNode = findRefGrouping(yangImport.getImportedNode()); | 1613 | linkedNode = findRefGrouping(yangImport.getImportedNode()); |
1786 | } else if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) { | 1614 | } else if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) { |
1787 | linkedNode = findRefFeature(yangImport.getImportedNode()); | 1615 | linkedNode = findRefFeature(yangImport.getImportedNode()); |
1788 | - } else if (getCurrentEntityToResolveFromStack() instanceof YangLeafRef) { | ||
1789 | - boolean referredNode = findRefLeaf(yangImport.getImportedNode()); | ||
1790 | - /* | ||
1791 | - * Update the current reference resolver to external | ||
1792 | - * module/sub-module containing the referred | ||
1793 | - * typedef/grouping. | ||
1794 | - */ | ||
1795 | - setCurReferenceResolver((YangReferenceResolver) yangImport.getImportedNode()); | ||
1796 | - | ||
1797 | - return referredNode; | ||
1798 | } else if (getCurrentEntityToResolveFromStack() instanceof YangBase) { | 1616 | } else if (getCurrentEntityToResolveFromStack() instanceof YangBase) { |
1799 | linkedNode = findRefIdentity(yangImport.getImportedNode()); | 1617 | linkedNode = findRefIdentity(yangImport.getImportedNode()); |
1800 | } else if (getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) { | 1618 | } else if (getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) { |
... | @@ -1826,44 +1644,6 @@ public class YangResolutionInfoImpl<T> | ... | @@ -1826,44 +1644,6 @@ public class YangResolutionInfoImpl<T> |
1826 | } | 1644 | } |
1827 | 1645 | ||
1828 | /** | 1646 | /** |
1829 | - * Returns the status of referred leaf. | ||
1830 | - * | ||
1831 | - * @param importedNode the root node from a YANG file | ||
1832 | - * @return status of the referred leaf | ||
1833 | - * @throws DataModelException | ||
1834 | - */ | ||
1835 | - private boolean findRefLeaf(YangNode importedNode) throws DataModelException { | ||
1836 | - | ||
1837 | - boolean isReferredNodeFound = false; | ||
1838 | - List<YangAtomicPath> absolutePathList = ((YangLeafRef) getCurrentEntityToResolveFromStack()) | ||
1839 | - .getAtomicPath(); | ||
1840 | - if (absolutePathList != null && !absolutePathList.isEmpty()) { | ||
1841 | - Iterator<YangAtomicPath> listOfYangAtomicPath = absolutePathList.listIterator(); | ||
1842 | - | ||
1843 | - while (listOfYangAtomicPath.hasNext()) { | ||
1844 | - YangAtomicPath absolutePath = listOfYangAtomicPath.next(); | ||
1845 | - String nodeName = absolutePath.getNodeIdentifier().getName(); | ||
1846 | - | ||
1847 | - if (importedNode.getChild() == null) { | ||
1848 | - isReferredNodeFound = isReferredLeafOrLeafListFound(importedNode, nodeName, (T) INTER_FILE_LINKED); | ||
1849 | - break; | ||
1850 | - } | ||
1851 | - importedNode = importedNode.getChild(); | ||
1852 | - | ||
1853 | - YangNode nodeFound = isReferredNodeInSiblingProcessedForLeafref(importedNode, nodeName); | ||
1854 | - if (nodeFound == null) { | ||
1855 | - isReferredNodeFound = isReferredLeafOrLeafListFound(importedNode.getParent(), nodeName, | ||
1856 | - (T) INTER_FILE_LINKED); | ||
1857 | - } else { | ||
1858 | - importedNode = nodeFound; | ||
1859 | - } | ||
1860 | - } | ||
1861 | - } | ||
1862 | - // TODO: Path predicates filling for inter file has to be done. | ||
1863 | - return isReferredNodeFound; | ||
1864 | - } | ||
1865 | - | ||
1866 | - /** | ||
1867 | * Returns referred typedef/grouping node. | 1647 | * Returns referred typedef/grouping node. |
1868 | * | 1648 | * |
1869 | * @return referred typedef/grouping node | 1649 | * @return referred typedef/grouping node |
... | @@ -1887,7 +1667,7 @@ public class YangResolutionInfoImpl<T> | ... | @@ -1887,7 +1667,7 @@ public class YangResolutionInfoImpl<T> |
1887 | return (T) ((YangIdentityRef) getCurrentEntityToResolveFromStack()).getReferredIdentity(); | 1667 | return (T) ((YangIdentityRef) getCurrentEntityToResolveFromStack()).getReferredIdentity(); |
1888 | } else { | 1668 | } else { |
1889 | throw new DataModelException("Data Model Exception: Entity to resolved is other than type" + | 1669 | throw new DataModelException("Data Model Exception: Entity to resolved is other than type" + |
1890 | - "/uses/base/identityref"); | 1670 | + "/uses/base/identityref"); |
1891 | } | 1671 | } |
1892 | } | 1672 | } |
1893 | 1673 | ||
... | @@ -1986,7 +1766,7 @@ public class YangResolutionInfoImpl<T> | ... | @@ -1986,7 +1766,7 @@ public class YangResolutionInfoImpl<T> |
1986 | if (tmpNode instanceof YangIdentity) { | 1766 | if (tmpNode instanceof YangIdentity) { |
1987 | if (tmpNode.getName() | 1767 | if (tmpNode.getName() |
1988 | .equals(((YangIdentityRef) getCurrentEntityToResolveFromStack()) | 1768 | .equals(((YangIdentityRef) getCurrentEntityToResolveFromStack()) |
1989 | - .getBaseIdentity().getName())) { | 1769 | + .getBaseIdentity().getName())) { |
1990 | return tmpNode; | 1770 | return tmpNode; |
1991 | } | 1771 | } |
1992 | } | 1772 | } | ... | ... |
... | @@ -16,31 +16,41 @@ | ... | @@ -16,31 +16,41 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.linker.impl; | 17 | package org.onosproject.yangutils.linker.impl; |
18 | 18 | ||
19 | -import java.util.ArrayList; | ||
20 | -import java.util.HashMap; | ||
21 | -import java.util.Iterator; | ||
22 | -import java.util.List; | ||
23 | -import java.util.Map; | ||
24 | -import java.util.Stack; | ||
25 | - | ||
26 | import org.onosproject.yangutils.datamodel.YangAtomicPath; | 19 | import org.onosproject.yangutils.datamodel.YangAtomicPath; |
27 | import org.onosproject.yangutils.datamodel.YangAugment; | 20 | import org.onosproject.yangutils.datamodel.YangAugment; |
21 | +import org.onosproject.yangutils.datamodel.YangCase; | ||
22 | +import org.onosproject.yangutils.datamodel.YangChoice; | ||
23 | +import org.onosproject.yangutils.datamodel.YangGrouping; | ||
28 | import org.onosproject.yangutils.datamodel.YangImport; | 24 | import org.onosproject.yangutils.datamodel.YangImport; |
29 | import org.onosproject.yangutils.datamodel.YangInclude; | 25 | import org.onosproject.yangutils.datamodel.YangInclude; |
26 | +import org.onosproject.yangutils.datamodel.YangInput; | ||
30 | import org.onosproject.yangutils.datamodel.YangLeaf; | 27 | import org.onosproject.yangutils.datamodel.YangLeaf; |
31 | import org.onosproject.yangutils.datamodel.YangLeafList; | 28 | import org.onosproject.yangutils.datamodel.YangLeafList; |
29 | +import org.onosproject.yangutils.datamodel.YangLeafRef; | ||
32 | import org.onosproject.yangutils.datamodel.YangLeavesHolder; | 30 | import org.onosproject.yangutils.datamodel.YangLeavesHolder; |
33 | import org.onosproject.yangutils.datamodel.YangModule; | 31 | import org.onosproject.yangutils.datamodel.YangModule; |
34 | import org.onosproject.yangutils.datamodel.YangNode; | 32 | import org.onosproject.yangutils.datamodel.YangNode; |
35 | import org.onosproject.yangutils.datamodel.YangNodeIdentifier; | 33 | import org.onosproject.yangutils.datamodel.YangNodeIdentifier; |
34 | +import org.onosproject.yangutils.datamodel.YangOutput; | ||
36 | import org.onosproject.yangutils.datamodel.YangSubModule; | 35 | import org.onosproject.yangutils.datamodel.YangSubModule; |
36 | +import org.onosproject.yangutils.datamodel.YangTypeDef; | ||
37 | +import org.onosproject.yangutils.datamodel.YangUses; | ||
37 | import org.onosproject.yangutils.linker.exceptions.LinkerException; | 38 | import org.onosproject.yangutils.linker.exceptions.LinkerException; |
38 | 39 | ||
40 | +import java.util.ArrayList; | ||
41 | +import java.util.HashMap; | ||
42 | +import java.util.Iterator; | ||
43 | +import java.util.List; | ||
44 | +import java.util.Map; | ||
45 | +import java.util.Stack; | ||
46 | + | ||
39 | import static org.onosproject.yangutils.linker.impl.PrefixResolverType.INTER_TO_INTER; | 47 | import static org.onosproject.yangutils.linker.impl.PrefixResolverType.INTER_TO_INTER; |
40 | import static org.onosproject.yangutils.linker.impl.PrefixResolverType.INTER_TO_INTRA; | 48 | import static org.onosproject.yangutils.linker.impl.PrefixResolverType.INTER_TO_INTRA; |
41 | import static org.onosproject.yangutils.linker.impl.PrefixResolverType.INTRA_TO_INTER; | 49 | import static org.onosproject.yangutils.linker.impl.PrefixResolverType.INTRA_TO_INTER; |
42 | import static org.onosproject.yangutils.linker.impl.PrefixResolverType.NO_PREFIX_CHANGE_FOR_INTER; | 50 | import static org.onosproject.yangutils.linker.impl.PrefixResolverType.NO_PREFIX_CHANGE_FOR_INTER; |
43 | import static org.onosproject.yangutils.linker.impl.PrefixResolverType.NO_PREFIX_CHANGE_FOR_INTRA; | 51 | import static org.onosproject.yangutils.linker.impl.PrefixResolverType.NO_PREFIX_CHANGE_FOR_INTRA; |
52 | +import static org.onosproject.yangutils.utils.UtilConstants.INPUT; | ||
53 | +import static org.onosproject.yangutils.utils.UtilConstants.OUTPUT; | ||
44 | 54 | ||
45 | /** | 55 | /** |
46 | * Represents x-path linking. | 56 | * Represents x-path linking. |
... | @@ -194,31 +204,35 @@ public class YangXpathLinker<T> { | ... | @@ -194,31 +204,35 @@ public class YangXpathLinker<T> { |
194 | /** | 204 | /** |
195 | * Process absolute node path for target leaf. | 205 | * Process absolute node path for target leaf. |
196 | * | 206 | * |
197 | - * @param absPaths absolute path node list | 207 | + * @param atomicPaths atomic path node list |
198 | - * @param root root node | 208 | + * @param root root node |
209 | + * @param leafref instance of YANG leafref | ||
199 | * @return linked target node | 210 | * @return linked target node |
200 | */ | 211 | */ |
201 | - T processLeafRefXpathLinking(List<YangAtomicPath> absPaths, YangNode root) { | 212 | + public T processLeafRefXpathLinking(List<YangAtomicPath> atomicPaths, YangNode root, YangLeafRef leafref) { |
202 | 213 | ||
203 | YangNode targetNode = null; | 214 | YangNode targetNode = null; |
204 | setRootNode(root); | 215 | setRootNode(root); |
205 | setPrefixResolverTypes(new HashMap<>()); | 216 | setPrefixResolverTypes(new HashMap<>()); |
206 | - parsePrefixResolverList(absPaths); | 217 | + parsePrefixResolverList(atomicPaths); |
207 | - YangAtomicPath leafRefPath = absPaths.get(absPaths.size() - 1); | 218 | + YangAtomicPath leafRefPath = atomicPaths.get(atomicPaths.size() - 1); |
208 | 219 | ||
209 | // When leaf-ref path contains only one absolute path. | 220 | // When leaf-ref path contains only one absolute path. |
210 | - if (absPaths.size() == 1) { | 221 | + if (atomicPaths.size() == 1) { |
211 | - targetNode = getTargetNodewhenSizeIsOne(absPaths); | 222 | + targetNode = getTargetNodewhenSizeIsOne(atomicPaths); |
212 | } else { | 223 | } else { |
213 | - absPaths.remove(absPaths.size() - 1); | 224 | + atomicPaths.remove(atomicPaths.size() - 1); |
214 | 225 | ||
215 | - setAbsPaths(absPaths); | 226 | + setAbsPaths(atomicPaths); |
216 | targetNode = parseData(root); | 227 | targetNode = parseData(root); |
217 | } | 228 | } |
218 | if (targetNode == null) { | 229 | if (targetNode == null) { |
219 | targetNode = searchInSubModule(root); | 230 | targetNode = searchInSubModule(root); |
220 | } | 231 | } |
221 | 232 | ||
233 | + // Invalid path presence in the node list is checked. | ||
234 | + validateInvalidNodesInThePath(leafref); | ||
235 | + | ||
222 | if (targetNode != null) { | 236 | if (targetNode != null) { |
223 | YangLeaf targetLeaf = searchReferredLeaf(targetNode, leafRefPath.getNodeIdentifier().getName()); | 237 | YangLeaf targetLeaf = searchReferredLeaf(targetNode, leafRefPath.getNodeIdentifier().getName()); |
224 | if (targetLeaf == null) { | 238 | if (targetLeaf == null) { |
... | @@ -227,9 +241,12 @@ public class YangXpathLinker<T> { | ... | @@ -227,9 +241,12 @@ public class YangXpathLinker<T> { |
227 | if (targetLeafList != null) { | 241 | if (targetLeafList != null) { |
228 | return (T) targetLeafList; | 242 | return (T) targetLeafList; |
229 | } else { | 243 | } else { |
230 | - throw new LinkerException( | 244 | + LinkerException linkerException = new LinkerException("YANG file error: Unable to find base " + |
231 | - "YANG file error: Unable to find base leaf/leaf-list for given leafref " | 245 | + "leaf/leaf-list for given leafref path " |
232 | - + leafRefPath.getNodeIdentifier().getName()); | 246 | + + leafref.getPath()); |
247 | + linkerException.setCharPosition(leafref.getCharPosition()); | ||
248 | + linkerException.setLine(leafref.getLineNumber()); | ||
249 | + throw linkerException; | ||
233 | } | 250 | } |
234 | } | 251 | } |
235 | return (T) targetLeaf; | 252 | return (T) targetLeaf; |
... | @@ -238,6 +255,30 @@ public class YangXpathLinker<T> { | ... | @@ -238,6 +255,30 @@ public class YangXpathLinker<T> { |
238 | } | 255 | } |
239 | 256 | ||
240 | /** | 257 | /** |
258 | + * Validates the nodes in the path for any invalid node. | ||
259 | + * | ||
260 | + * @param leafref instance of YANG leafref | ||
261 | + */ | ||
262 | + private void validateInvalidNodesInThePath(YangLeafRef leafref) { | ||
263 | + Map<YangAtomicPath, YangNode> nodes = getResolvedNodes(); | ||
264 | + Iterator<Map.Entry<YangAtomicPath, YangNode>> nodesIterator = nodes.entrySet().iterator(); | ||
265 | + while (nodesIterator.hasNext()) { | ||
266 | + Map.Entry<YangAtomicPath, YangNode> nodeInList = nodesIterator.next(); | ||
267 | + YangNode nodeInPath = nodeInList.getValue(); | ||
268 | + | ||
269 | + if (nodeInPath instanceof YangGrouping || nodeInPath instanceof YangUses | ||
270 | + || nodeInPath instanceof YangTypeDef || nodeInPath instanceof YangCase | ||
271 | + || nodeInPath instanceof YangChoice) { | ||
272 | + LinkerException linkerException = new LinkerException("YANG file error: The target node, in the " + | ||
273 | + "leafref path " + leafref.getPath() + ", is invalid."); | ||
274 | + linkerException.setCharPosition(leafref.getCharPosition()); | ||
275 | + linkerException.setLine(leafref.getLineNumber()); | ||
276 | + throw linkerException; | ||
277 | + } | ||
278 | + } | ||
279 | + } | ||
280 | + | ||
281 | + /** | ||
241 | * Returns target node when leaf-ref has only one absolute path in list. | 282 | * Returns target node when leaf-ref has only one absolute path in list. |
242 | * | 283 | * |
243 | * @param absPaths absolute paths | 284 | * @param absPaths absolute paths |
... | @@ -289,9 +330,13 @@ public class YangXpathLinker<T> { | ... | @@ -289,9 +330,13 @@ public class YangXpathLinker<T> { |
289 | } | 330 | } |
290 | YangLeavesHolder holder = (YangLeavesHolder) targetNode; | 331 | YangLeavesHolder holder = (YangLeavesHolder) targetNode; |
291 | List<YangLeaf> leaves = holder.getListOfLeaf(); | 332 | List<YangLeaf> leaves = holder.getListOfLeaf(); |
292 | - for (YangLeaf leaf : leaves) { | 333 | + if (leaves != null && !leaves.isEmpty()) { |
293 | - if (leaf.getName().equals(leafName)) { | 334 | + Iterator<YangLeaf> leafIterator = leaves.listIterator(); |
294 | - return leaf; | 335 | + while (leafIterator.hasNext()) { |
336 | + YangLeaf leaf = leafIterator.next(); | ||
337 | + if (leaf.getName().equals(leafName)) { | ||
338 | + return leaf; | ||
339 | + } | ||
295 | } | 340 | } |
296 | } | 341 | } |
297 | return null; | 342 | return null; |
... | @@ -311,9 +356,13 @@ public class YangXpathLinker<T> { | ... | @@ -311,9 +356,13 @@ public class YangXpathLinker<T> { |
311 | } | 356 | } |
312 | YangLeavesHolder holder = (YangLeavesHolder) targetNode; | 357 | YangLeavesHolder holder = (YangLeavesHolder) targetNode; |
313 | List<YangLeafList> leavesList = holder.getListOfLeafList(); | 358 | List<YangLeafList> leavesList = holder.getListOfLeafList(); |
314 | - for (YangLeafList leafList : leavesList) { | 359 | + if (leavesList != null && !leavesList.isEmpty()) { |
315 | - if (leafList.getName().equals(leafListName)) { | 360 | + Iterator<YangLeafList> leafListIterator = leavesList.listIterator(); |
316 | - return leafList; | 361 | + while (leafListIterator.hasNext()) { |
362 | + YangLeafList leafList = leafListIterator.next(); | ||
363 | + if (leafList.getName().equals(leafListName)) { | ||
364 | + return leafList; | ||
365 | + } | ||
317 | } | 366 | } |
318 | } | 367 | } |
319 | return null; | 368 | return null; |
... | @@ -709,6 +758,15 @@ public class YangXpathLinker<T> { | ... | @@ -709,6 +758,15 @@ public class YangXpathLinker<T> { |
709 | } | 758 | } |
710 | 759 | ||
711 | while (node != null) { | 760 | while (node != null) { |
761 | + if (node instanceof YangInput) { | ||
762 | + if (curNodeId.getName().equalsIgnoreCase(INPUT)) { | ||
763 | + return node; | ||
764 | + } | ||
765 | + } else if (node instanceof YangOutput) { | ||
766 | + if (curNodeId.getName().equalsIgnoreCase(OUTPUT)) { | ||
767 | + return node; | ||
768 | + } | ||
769 | + } | ||
712 | if (node.getName().equals(curNodeId.getName())) { | 770 | if (node.getName().equals(curNodeId.getName())) { |
713 | return node; | 771 | return node; |
714 | } | 772 | } | ... | ... |
... | @@ -16,8 +16,6 @@ | ... | @@ -16,8 +16,6 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.parser.impl; | 17 | package org.onosproject.yangutils.parser.impl; |
18 | 18 | ||
19 | -import java.util.Stack; | ||
20 | - | ||
21 | import org.antlr.v4.runtime.ParserRuleContext; | 19 | import org.antlr.v4.runtime.ParserRuleContext; |
22 | import org.antlr.v4.runtime.tree.ErrorNode; | 20 | import org.antlr.v4.runtime.tree.ErrorNode; |
23 | import org.antlr.v4.runtime.tree.TerminalNode; | 21 | import org.antlr.v4.runtime.tree.TerminalNode; |
... | @@ -42,12 +40,14 @@ import org.onosproject.yangutils.parser.impl.listeners.DefaultListener; | ... | @@ -42,12 +40,14 @@ import org.onosproject.yangutils.parser.impl.listeners.DefaultListener; |
42 | import org.onosproject.yangutils.parser.impl.listeners.DescriptionListener; | 40 | import org.onosproject.yangutils.parser.impl.listeners.DescriptionListener; |
43 | import org.onosproject.yangutils.parser.impl.listeners.EnumListener; | 41 | import org.onosproject.yangutils.parser.impl.listeners.EnumListener; |
44 | import org.onosproject.yangutils.parser.impl.listeners.EnumerationListener; | 42 | import org.onosproject.yangutils.parser.impl.listeners.EnumerationListener; |
43 | +import org.onosproject.yangutils.parser.impl.listeners.ErrorAppTagListener; | ||
44 | +import org.onosproject.yangutils.parser.impl.listeners.ErrorMessageListener; | ||
45 | import org.onosproject.yangutils.parser.impl.listeners.FeatureListener; | 45 | import org.onosproject.yangutils.parser.impl.listeners.FeatureListener; |
46 | import org.onosproject.yangutils.parser.impl.listeners.FractionDigitsListener; | 46 | import org.onosproject.yangutils.parser.impl.listeners.FractionDigitsListener; |
47 | import org.onosproject.yangutils.parser.impl.listeners.GroupingListener; | 47 | import org.onosproject.yangutils.parser.impl.listeners.GroupingListener; |
48 | +import org.onosproject.yangutils.parser.impl.listeners.IdentityListener; | ||
48 | import org.onosproject.yangutils.parser.impl.listeners.IdentityrefListener; | 49 | import org.onosproject.yangutils.parser.impl.listeners.IdentityrefListener; |
49 | import org.onosproject.yangutils.parser.impl.listeners.IfFeatureListener; | 50 | import org.onosproject.yangutils.parser.impl.listeners.IfFeatureListener; |
50 | -import org.onosproject.yangutils.parser.impl.listeners.IdentityListener; | ||
51 | import org.onosproject.yangutils.parser.impl.listeners.ImportListener; | 51 | import org.onosproject.yangutils.parser.impl.listeners.ImportListener; |
52 | import org.onosproject.yangutils.parser.impl.listeners.IncludeListener; | 52 | import org.onosproject.yangutils.parser.impl.listeners.IncludeListener; |
53 | import org.onosproject.yangutils.parser.impl.listeners.InputListener; | 53 | import org.onosproject.yangutils.parser.impl.listeners.InputListener; |
... | @@ -83,13 +83,15 @@ import org.onosproject.yangutils.parser.impl.listeners.SubModuleListener; | ... | @@ -83,13 +83,15 @@ import org.onosproject.yangutils.parser.impl.listeners.SubModuleListener; |
83 | import org.onosproject.yangutils.parser.impl.listeners.TypeDefListener; | 83 | import org.onosproject.yangutils.parser.impl.listeners.TypeDefListener; |
84 | import org.onosproject.yangutils.parser.impl.listeners.TypeListener; | 84 | import org.onosproject.yangutils.parser.impl.listeners.TypeListener; |
85 | import org.onosproject.yangutils.parser.impl.listeners.UnionListener; | 85 | import org.onosproject.yangutils.parser.impl.listeners.UnionListener; |
86 | +import org.onosproject.yangutils.parser.impl.listeners.UniqueListener; | ||
86 | import org.onosproject.yangutils.parser.impl.listeners.UnitsListener; | 87 | import org.onosproject.yangutils.parser.impl.listeners.UnitsListener; |
87 | import org.onosproject.yangutils.parser.impl.listeners.UsesListener; | 88 | import org.onosproject.yangutils.parser.impl.listeners.UsesListener; |
88 | import org.onosproject.yangutils.parser.impl.listeners.ValueListener; | 89 | import org.onosproject.yangutils.parser.impl.listeners.ValueListener; |
89 | import org.onosproject.yangutils.parser.impl.listeners.VersionListener; | 90 | import org.onosproject.yangutils.parser.impl.listeners.VersionListener; |
90 | import org.onosproject.yangutils.parser.impl.listeners.WhenListener; | 91 | import org.onosproject.yangutils.parser.impl.listeners.WhenListener; |
91 | -import org.onosproject.yangutils.parser.impl.listeners.ErrorMessageListener; | 92 | + |
92 | -import org.onosproject.yangutils.parser.impl.listeners.ErrorAppTagListener; | 93 | +import java.util.Stack; |
94 | + | ||
93 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.handleUnsupportedYangConstruct; | 95 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.handleUnsupportedYangConstruct; |
94 | import static org.onosproject.yangutils.utils.UtilConstants.CURRENTLY_UNSUPPORTED; | 96 | import static org.onosproject.yangutils.utils.UtilConstants.CURRENTLY_UNSUPPORTED; |
95 | import static org.onosproject.yangutils.utils.UtilConstants.UNSUPPORTED_YANG_CONSTRUCT; | 97 | import static org.onosproject.yangutils.utils.UtilConstants.UNSUPPORTED_YANG_CONSTRUCT; |
... | @@ -109,6 +111,34 @@ public class TreeWalkListener implements GeneratedYangListener { | ... | @@ -109,6 +111,34 @@ public class TreeWalkListener implements GeneratedYangListener { |
109 | private YangNode rootNode; | 111 | private YangNode rootNode; |
110 | 112 | ||
111 | /** | 113 | /** |
114 | + * Parent depth of grouping count for any node. | ||
115 | + */ | ||
116 | + private int groupingDepth; | ||
117 | + | ||
118 | + /** | ||
119 | + * Returns number of grouping parents, by a node, at any level. | ||
120 | + * | ||
121 | + * @return depth of grouping | ||
122 | + */ | ||
123 | + public int getGroupingDepth() { | ||
124 | + return groupingDepth; | ||
125 | + } | ||
126 | + | ||
127 | + /** | ||
128 | + * Sets number of grouping parents by a node at any level. | ||
129 | + */ | ||
130 | + public void increaseGroupingDepth() { | ||
131 | + groupingDepth++; | ||
132 | + } | ||
133 | + | ||
134 | + /** | ||
135 | + * Sets number of grouping parents by a node at any level. | ||
136 | + */ | ||
137 | + public void decreaseGroupingDepth() { | ||
138 | + groupingDepth--; | ||
139 | + } | ||
140 | + | ||
141 | + /** | ||
112 | * Returns stack of parsable data. | 142 | * Returns stack of parsable data. |
113 | * | 143 | * |
114 | * @return stack of parsable data | 144 | * @return stack of parsable data |
... | @@ -956,7 +986,7 @@ public class TreeWalkListener implements GeneratedYangListener { | ... | @@ -956,7 +986,7 @@ public class TreeWalkListener implements GeneratedYangListener { |
956 | 986 | ||
957 | @Override | 987 | @Override |
958 | public void enterUniqueStatement(GeneratedYangParser.UniqueStatementContext ctx) { | 988 | public void enterUniqueStatement(GeneratedYangParser.UniqueStatementContext ctx) { |
959 | - handleUnsupportedYangConstruct(YangConstructType.UNIQUE_DATA, ctx, CURRENTLY_UNSUPPORTED); | 989 | + UniqueListener.processUniqueEntry(this, ctx); |
960 | } | 990 | } |
961 | 991 | ||
962 | @Override | 992 | @Override | ... | ... |
... | @@ -106,6 +106,8 @@ public final class GroupingListener { | ... | @@ -106,6 +106,8 @@ public final class GroupingListener { |
106 | // Validate sub statement cardinality. | 106 | // Validate sub statement cardinality. |
107 | validateSubStatementsCardinality(ctx); | 107 | validateSubStatementsCardinality(ctx); |
108 | 108 | ||
109 | + // Increase the grouping count by one. | ||
110 | + listener.increaseGroupingDepth(); | ||
109 | Parsable curData = listener.getParsedDataStack().peek(); | 111 | Parsable curData = listener.getParsedDataStack().peek(); |
110 | 112 | ||
111 | // Check for identifier collision | 113 | // Check for identifier collision |
... | @@ -149,6 +151,8 @@ public final class GroupingListener { | ... | @@ -149,6 +151,8 @@ public final class GroupingListener { |
149 | // Check for stack to be non empty. | 151 | // Check for stack to be non empty. |
150 | checkStackIsNotEmpty(listener, MISSING_HOLDER, GROUPING_DATA, ctx.identifier().getText(), EXIT); | 152 | checkStackIsNotEmpty(listener, MISSING_HOLDER, GROUPING_DATA, ctx.identifier().getText(), EXIT); |
151 | 153 | ||
154 | + // Decrease the grouping count by one. | ||
155 | + listener.decreaseGroupingDepth(); | ||
152 | if (listener.getParsedDataStack().peek() instanceof YangGrouping) { | 156 | if (listener.getParsedDataStack().peek() instanceof YangGrouping) { |
153 | listener.getParsedDataStack().pop(); | 157 | listener.getParsedDataStack().pop(); |
154 | } else { | 158 | } else { | ... | ... |
... | @@ -100,6 +100,8 @@ public final class LeafrefListener { | ... | @@ -100,6 +100,8 @@ public final class LeafrefListener { |
100 | 100 | ||
101 | YangLeafRef<?> leafRef = new YangLeafRef<>(); | 101 | YangLeafRef<?> leafRef = new YangLeafRef<>(); |
102 | 102 | ||
103 | + leafRef.setLineNumber(errorLine); | ||
104 | + leafRef.setCharPosition(errorPosition); | ||
103 | Parsable typeData = listener.getParsedDataStack().pop(); | 105 | Parsable typeData = listener.getParsedDataStack().pop(); |
104 | 106 | ||
105 | if (!(typeData instanceof YangType)) { | 107 | if (!(typeData instanceof YangType)) { |
... | @@ -130,11 +132,13 @@ public final class LeafrefListener { | ... | @@ -130,11 +132,13 @@ public final class LeafrefListener { |
130 | } | 132 | } |
131 | 133 | ||
132 | leafRef.setResolvableStatus(UNRESOLVED); | 134 | leafRef.setResolvableStatus(UNRESOLVED); |
133 | - | 135 | + leafRef.setParentNodeOfLeafref((YangNode) parentNodeOfLeaf); |
134 | - // Add resolution information to the list. | 136 | + if (listener.getGroupingDepth() == 0) { |
135 | - YangResolutionInfoImpl resolutionInfo = new YangResolutionInfoImpl<YangLeafRef>(leafRef, | 137 | + // Add resolution information to the list. |
136 | - (YangNode) parentNodeOfLeaf, errorLine, errorPosition); | 138 | + YangResolutionInfoImpl resolutionInfo = new YangResolutionInfoImpl<YangLeafRef>(leafRef, |
137 | - addToResolutionList(resolutionInfo); | 139 | + (YangNode) parentNodeOfLeaf, errorLine, errorPosition); |
140 | + addToResolutionList(resolutionInfo); | ||
141 | + } | ||
138 | break; | 142 | break; |
139 | 143 | ||
140 | case LEAF_LIST_DATA: | 144 | case LEAF_LIST_DATA: |
... | @@ -151,14 +155,19 @@ public final class LeafrefListener { | ... | @@ -151,14 +155,19 @@ public final class LeafrefListener { |
151 | } | 155 | } |
152 | 156 | ||
153 | leafRef.setResolvableStatus(UNRESOLVED); | 157 | leafRef.setResolvableStatus(UNRESOLVED); |
158 | + leafRef.setParentNodeOfLeafref((YangNode) parentNodeOfLeafList); | ||
154 | 159 | ||
155 | - // Add resolution information to the list. | 160 | + if (listener.getGroupingDepth() == 0) { |
156 | - YangResolutionInfoImpl resolutionInfoImpl = new YangResolutionInfoImpl<YangLeafRef>(leafRef, | 161 | + // Add resolution information to the list. |
157 | - (YangNode) parentNodeOfLeafList, errorLine, errorPosition); | 162 | + YangResolutionInfoImpl resolutionInfoImpl = new YangResolutionInfoImpl<YangLeafRef>(leafRef, |
158 | - addToResolutionList(resolutionInfoImpl); | 163 | + (YangNode) parentNodeOfLeafList, errorLine, errorPosition); |
164 | + addToResolutionList(resolutionInfoImpl); | ||
165 | + } | ||
159 | break; | 166 | break; |
160 | 167 | ||
161 | case TYPEDEF_DATA: | 168 | case TYPEDEF_DATA: |
169 | + Parsable parentNodeOfLeafref = listener.getParsedDataStack().peek(); | ||
170 | + leafRef.setParentNodeOfLeafref((YangNode) parentNodeOfLeafref); | ||
162 | /* | 171 | /* |
163 | * Do not add the leaf ref to resolution list. It needs to be | 172 | * Do not add the leaf ref to resolution list. It needs to be |
164 | * added to resolution list, when leaf/leaf list references to | 173 | * added to resolution list, when leaf/leaf list references to | ... | ... |
... | @@ -54,6 +54,7 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp | ... | @@ -54,6 +54,7 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp |
54 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; | 54 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; |
55 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA; | 55 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA; |
56 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; | 56 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; |
57 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.validateUniqueInList; | ||
57 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; | 58 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; |
58 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne; | 59 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne; |
59 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityNonZero; | 60 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityNonZero; |
... | @@ -174,6 +175,7 @@ public final class ListListener { | ... | @@ -174,6 +175,7 @@ public final class ListListener { |
174 | YangList yangList = (YangList) listener.getParsedDataStack().peek(); | 175 | YangList yangList = (YangList) listener.getParsedDataStack().peek(); |
175 | try { | 176 | try { |
176 | yangList.validateDataOnExit(); | 177 | yangList.validateDataOnExit(); |
178 | + validateUniqueInList(yangList, ctx); | ||
177 | } catch (DataModelException e) { | 179 | } catch (DataModelException e) { |
178 | throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA, | 180 | throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA, |
179 | LIST_DATA, ctx.identifier().getText(), EXIT, e.getMessage())); | 181 | LIST_DATA, ctx.identifier().getText(), EXIT, e.getMessage())); | ... | ... |
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.YangList; | ||
20 | +import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | ||
21 | +import org.onosproject.yangutils.datamodel.utils.Parsable; | ||
22 | +import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | ||
23 | +import org.onosproject.yangutils.parser.exceptions.ParserException; | ||
24 | +import org.onosproject.yangutils.parser.impl.TreeWalkListener; | ||
25 | + | ||
26 | +import static org.onosproject.yangutils.datamodel.utils.YangConstructType.UNIQUE_DATA; | ||
27 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; | ||
28 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction | ||
29 | + .constructExtendedListenerErrorMessage; | ||
30 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction | ||
31 | + .constructListenerErrorMessage; | ||
32 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; | ||
33 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; | ||
34 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA; | ||
35 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat; | ||
36 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; | ||
37 | + | ||
38 | +/* | ||
39 | + * Reference: RFC6020 and YANG ANTLR Grammar | ||
40 | + * | ||
41 | + * ABNF grammar as per RFC6020 | ||
42 | + * unique-stmt = unique-keyword sep unique-arg-str stmtend | ||
43 | + * | ||
44 | + * ANTLR grammar rule | ||
45 | + * uniqueStatement: UNIQUE_KEYWORD unique STMTEND; | ||
46 | + * unique : string; | ||
47 | + */ | ||
48 | + | ||
49 | +/** | ||
50 | + * Represesnts listener based call back function corresponding to the "unique" rule | ||
51 | + * defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020. | ||
52 | + */ | ||
53 | +public final class UniqueListener { | ||
54 | + | ||
55 | + /** | ||
56 | + * Creates a new unique listener. | ||
57 | + */ | ||
58 | + private UniqueListener() { | ||
59 | + } | ||
60 | + | ||
61 | + /** | ||
62 | + * It is called when parser receives an input matching the grammar rule | ||
63 | + * (unique), perform validations and updates the data model tree. | ||
64 | + * | ||
65 | + * @param listener listener's object | ||
66 | + * @param ctx context object of the grammar rule | ||
67 | + */ | ||
68 | + public static void processUniqueEntry(TreeWalkListener listener, | ||
69 | + GeneratedYangParser.UniqueStatementContext ctx) { | ||
70 | + | ||
71 | + // Check for stack to be non empty. | ||
72 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, UNIQUE_DATA, ctx.unique().getText(), ENTRY); | ||
73 | + | ||
74 | + Parsable tmpData = listener.getParsedDataStack().peek(); | ||
75 | + if (listener.getParsedDataStack().peek() instanceof YangList) { | ||
76 | + YangList yangList = (YangList) tmpData; | ||
77 | + String tmpUniqueValue = removeQuotesAndHandleConcat(ctx.unique().getText()); | ||
78 | + | ||
79 | + if (tmpUniqueValue.contains(" ")) { | ||
80 | + String[] uniqueValues = tmpUniqueValue.split(" "); | ||
81 | + for (String uniqueValue : uniqueValues) { | ||
82 | + try { | ||
83 | + yangList.addUnique(uniqueValue); | ||
84 | + } catch (DataModelException e) { | ||
85 | + throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA, | ||
86 | + UNIQUE_DATA, | ||
87 | + ctx.unique().getText(), ENTRY, e.getMessage())); | ||
88 | + } | ||
89 | + } | ||
90 | + } else { | ||
91 | + try { | ||
92 | + yangList.addUnique(tmpUniqueValue); | ||
93 | + } catch (DataModelException e) { | ||
94 | + throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA, UNIQUE_DATA, | ||
95 | + ctx.unique().getText(), ENTRY, e.getMessage())); | ||
96 | + } | ||
97 | + } | ||
98 | + } else { | ||
99 | + throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, UNIQUE_DATA, ctx.unique().getText(), | ||
100 | + ENTRY)); | ||
101 | + } | ||
102 | + } | ||
103 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
... | @@ -137,6 +137,7 @@ public final class UsesListener { | ... | @@ -137,6 +137,7 @@ public final class UsesListener { |
137 | YangUses usesNode = getYangUsesNode(JAVA_GENERATION); | 137 | YangUses usesNode = getYangUsesNode(JAVA_GENERATION); |
138 | YangNodeIdentifier nodeIdentifier = getValidNodeIdentifier(ctx.string().getText(), USES_DATA, ctx); | 138 | YangNodeIdentifier nodeIdentifier = getValidNodeIdentifier(ctx.string().getText(), USES_DATA, ctx); |
139 | usesNode.setNodeIdentifier(nodeIdentifier); | 139 | usesNode.setNodeIdentifier(nodeIdentifier); |
140 | + usesNode.setCurrentGroupingDepth(listener.getGroupingDepth()); | ||
140 | YangNode curNode = (YangNode) curData; | 141 | YangNode curNode = (YangNode) curData; |
141 | 142 | ||
142 | try { | 143 | try { | ... | ... |
... | @@ -16,25 +16,34 @@ | ... | @@ -16,25 +16,34 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.parser.impl.parserutils; | 17 | package org.onosproject.yangutils.parser.impl.parserutils; |
18 | 18 | ||
19 | -import java.text.ParseException; | ||
20 | -import java.text.SimpleDateFormat; | ||
21 | -import java.util.ArrayList; | ||
22 | -import java.util.Date; | ||
23 | -import java.util.Iterator; | ||
24 | -import java.util.LinkedList; | ||
25 | -import java.util.List; | ||
26 | -import java.util.regex.Pattern; | ||
27 | - | ||
28 | import org.antlr.v4.runtime.ParserRuleContext; | 19 | import org.antlr.v4.runtime.ParserRuleContext; |
29 | import org.onosproject.yangutils.datamodel.YangAtomicPath; | 20 | import org.onosproject.yangutils.datamodel.YangAtomicPath; |
21 | +import org.onosproject.yangutils.datamodel.YangImport; | ||
22 | +import org.onosproject.yangutils.datamodel.YangLeaf; | ||
30 | import org.onosproject.yangutils.datamodel.YangLeafRef; | 23 | import org.onosproject.yangutils.datamodel.YangLeafRef; |
24 | +import org.onosproject.yangutils.datamodel.YangLeavesHolder; | ||
25 | +import org.onosproject.yangutils.datamodel.YangList; | ||
26 | +import org.onosproject.yangutils.datamodel.YangModule; | ||
27 | +import org.onosproject.yangutils.datamodel.YangNode; | ||
31 | import org.onosproject.yangutils.datamodel.YangNodeIdentifier; | 28 | import org.onosproject.yangutils.datamodel.YangNodeIdentifier; |
32 | import org.onosproject.yangutils.datamodel.YangPathPredicate; | 29 | import org.onosproject.yangutils.datamodel.YangPathPredicate; |
30 | +import org.onosproject.yangutils.datamodel.YangReferenceResolver; | ||
33 | import org.onosproject.yangutils.datamodel.YangRelativePath; | 31 | import org.onosproject.yangutils.datamodel.YangRelativePath; |
32 | +import org.onosproject.yangutils.datamodel.YangSubModule; | ||
34 | import org.onosproject.yangutils.datamodel.utils.YangConstructType; | 33 | import org.onosproject.yangutils.datamodel.utils.YangConstructType; |
35 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | 34 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; |
36 | import org.onosproject.yangutils.parser.exceptions.ParserException; | 35 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
37 | 36 | ||
37 | +import java.text.ParseException; | ||
38 | +import java.text.SimpleDateFormat; | ||
39 | +import java.util.ArrayList; | ||
40 | +import java.util.Date; | ||
41 | +import java.util.HashMap; | ||
42 | +import java.util.Iterator; | ||
43 | +import java.util.LinkedList; | ||
44 | +import java.util.List; | ||
45 | +import java.util.regex.Pattern; | ||
46 | + | ||
38 | import static org.onosproject.yangutils.datamodel.YangPathArgType.ABSOLUTE_PATH; | 47 | import static org.onosproject.yangutils.datamodel.YangPathArgType.ABSOLUTE_PATH; |
39 | import static org.onosproject.yangutils.datamodel.YangPathArgType.RELATIVE_PATH; | 48 | import static org.onosproject.yangutils.datamodel.YangPathArgType.RELATIVE_PATH; |
40 | import static org.onosproject.yangutils.datamodel.YangPathOperator.EQUALTO; | 49 | import static org.onosproject.yangutils.datamodel.YangPathOperator.EQUALTO; |
... | @@ -98,9 +107,9 @@ public final class ListenerUtil { | ... | @@ -98,9 +107,9 @@ public final class ListenerUtil { |
98 | /** | 107 | /** |
99 | * Validates identifier and returns concatenated string if string contains plus symbol. | 108 | * Validates identifier and returns concatenated string if string contains plus symbol. |
100 | * | 109 | * |
101 | - * @param identifier string from yang file | 110 | + * @param identifier string from yang file |
102 | * @param yangConstruct yang construct for creating error message | 111 | * @param yangConstruct yang construct for creating error message |
103 | - * @param ctx yang construct's context to get the line number and character position | 112 | + * @param ctx yang construct's context to get the line number and character position |
104 | * @return concatenated string after removing double quotes | 113 | * @return concatenated string after removing double quotes |
105 | */ | 114 | */ |
106 | public static String getValidIdentifier(String identifier, YangConstructType yangConstruct, ParserRuleContext ctx) { | 115 | public static String getValidIdentifier(String identifier, YangConstructType yangConstruct, ParserRuleContext ctx) { |
... | @@ -132,14 +141,14 @@ public final class ListenerUtil { | ... | @@ -132,14 +141,14 @@ public final class ListenerUtil { |
132 | /** | 141 | /** |
133 | * Validates identifier and returns concatenated string if string contains plus symbol. | 142 | * Validates identifier and returns concatenated string if string contains plus symbol. |
134 | * | 143 | * |
135 | - * @param identifier string from yang file | 144 | + * @param identifier string from yang file |
136 | * @param yangConstruct yang construct for creating error message | 145 | * @param yangConstruct yang construct for creating error message |
137 | - * @param ctx yang construct's context to get the line number and character position | 146 | + * @param ctx yang construct's context to get the line number and character position |
138 | - * @param yangLeafRef instance of leafref where the path argument has to be set | 147 | + * @param yangLeafRef instance of leafref where the path argument has to be set |
139 | * @return concatenated string after removing double quotes | 148 | * @return concatenated string after removing double quotes |
140 | */ | 149 | */ |
141 | public static String getValidIdentifierForLeafref(String identifier, YangConstructType yangConstruct, | 150 | public static String getValidIdentifierForLeafref(String identifier, YangConstructType yangConstruct, |
142 | - ParserRuleContext ctx, YangLeafRef yangLeafRef) { | 151 | + ParserRuleContext ctx, YangLeafRef yangLeafRef) { |
143 | 152 | ||
144 | String identifierString = removeQuotesAndHandleConcat(identifier); | 153 | String identifierString = removeQuotesAndHandleConcat(identifier); |
145 | ParserException parserException; | 154 | ParserException parserException; |
... | @@ -211,13 +220,13 @@ public final class ListenerUtil { | ... | @@ -211,13 +220,13 @@ public final class ListenerUtil { |
211 | /** | 220 | /** |
212 | * Validates non negative integer value. | 221 | * Validates non negative integer value. |
213 | * | 222 | * |
214 | - * @param integerValue integer to be validated | 223 | + * @param integerValue integer to be validated |
215 | * @param yangConstruct yang construct for creating error message | 224 | * @param yangConstruct yang construct for creating error message |
216 | - * @param ctx context object of the grammar rule | 225 | + * @param ctx context object of the grammar rule |
217 | * @return valid non negative integer value | 226 | * @return valid non negative integer value |
218 | */ | 227 | */ |
219 | public static int getValidNonNegativeIntegerValue(String integerValue, YangConstructType yangConstruct, | 228 | public static int getValidNonNegativeIntegerValue(String integerValue, YangConstructType yangConstruct, |
220 | - ParserRuleContext ctx) { | 229 | + ParserRuleContext ctx) { |
221 | 230 | ||
222 | String value = removeQuotesAndHandleConcat(integerValue); | 231 | String value = removeQuotesAndHandleConcat(integerValue); |
223 | if (!value.matches(NON_NEGATIVE_INTEGER_PATTERN)) { | 232 | if (!value.matches(NON_NEGATIVE_INTEGER_PATTERN)) { |
... | @@ -246,13 +255,13 @@ public final class ListenerUtil { | ... | @@ -246,13 +255,13 @@ public final class ListenerUtil { |
246 | /** | 255 | /** |
247 | * Validates integer value. | 256 | * Validates integer value. |
248 | * | 257 | * |
249 | - * @param integerValue integer to be validated | 258 | + * @param integerValue integer to be validated |
250 | * @param yangConstruct yang construct for creating error message | 259 | * @param yangConstruct yang construct for creating error message |
251 | - * @param ctx context object of the grammar rule | 260 | + * @param ctx context object of the grammar rule |
252 | * @return valid integer value | 261 | * @return valid integer value |
253 | */ | 262 | */ |
254 | public static int getValidIntegerValue(String integerValue, YangConstructType yangConstruct, | 263 | public static int getValidIntegerValue(String integerValue, YangConstructType yangConstruct, |
255 | - ParserRuleContext ctx) { | 264 | + ParserRuleContext ctx) { |
256 | 265 | ||
257 | String value = removeQuotesAndHandleConcat(integerValue); | 266 | String value = removeQuotesAndHandleConcat(integerValue); |
258 | if (!INTEGER_PATTERN.matcher(value).matches()) { | 267 | if (!INTEGER_PATTERN.matcher(value).matches()) { |
... | @@ -281,13 +290,13 @@ public final class ListenerUtil { | ... | @@ -281,13 +290,13 @@ public final class ListenerUtil { |
281 | /** | 290 | /** |
282 | * Validates boolean value. | 291 | * Validates boolean value. |
283 | * | 292 | * |
284 | - * @param booleanValue value to be validated | 293 | + * @param booleanValue value to be validated |
285 | * @param yangConstruct yang construct for creating error message | 294 | * @param yangConstruct yang construct for creating error message |
286 | - * @param ctx context object of the grammar rule | 295 | + * @param ctx context object of the grammar rule |
287 | * @return boolean value either true or false | 296 | * @return boolean value either true or false |
288 | */ | 297 | */ |
289 | public static boolean getValidBooleanValue(String booleanValue, YangConstructType yangConstruct, | 298 | public static boolean getValidBooleanValue(String booleanValue, YangConstructType yangConstruct, |
290 | - ParserRuleContext ctx) { | 299 | + ParserRuleContext ctx) { |
291 | 300 | ||
292 | String value = removeQuotesAndHandleConcat(booleanValue); | 301 | String value = removeQuotesAndHandleConcat(booleanValue); |
293 | if (value.equals(TRUE)) { | 302 | if (value.equals(TRUE)) { |
... | @@ -329,12 +338,12 @@ public final class ListenerUtil { | ... | @@ -329,12 +338,12 @@ public final class ListenerUtil { |
329 | * Checks and return valid node identifier. | 338 | * Checks and return valid node identifier. |
330 | * | 339 | * |
331 | * @param nodeIdentifierString string from yang file | 340 | * @param nodeIdentifierString string from yang file |
332 | - * @param yangConstruct yang construct for creating error message | 341 | + * @param yangConstruct yang construct for creating error message |
333 | - * @param ctx yang construct's context to get the line number and character position | 342 | + * @param ctx yang construct's context to get the line number and character position |
334 | * @return valid node identifier | 343 | * @return valid node identifier |
335 | */ | 344 | */ |
336 | public static YangNodeIdentifier getValidNodeIdentifier(String nodeIdentifierString, | 345 | public static YangNodeIdentifier getValidNodeIdentifier(String nodeIdentifierString, |
337 | - YangConstructType yangConstruct, ParserRuleContext ctx) { | 346 | + YangConstructType yangConstruct, ParserRuleContext ctx) { |
338 | String tmpIdentifierString = removeQuotesAndHandleConcat(nodeIdentifierString); | 347 | String tmpIdentifierString = removeQuotesAndHandleConcat(nodeIdentifierString); |
339 | String[] tmpData = tmpIdentifierString.split(Pattern.quote(COLON)); | 348 | String[] tmpData = tmpIdentifierString.split(Pattern.quote(COLON)); |
340 | if (tmpData.length == 1) { | 349 | if (tmpData.length == 1) { |
... | @@ -360,13 +369,14 @@ public final class ListenerUtil { | ... | @@ -360,13 +369,14 @@ public final class ListenerUtil { |
360 | * Checks and return valid node identifier specific to nodes in leafref path. | 369 | * Checks and return valid node identifier specific to nodes in leafref path. |
361 | * | 370 | * |
362 | * @param nodeIdentifierString string from yang file | 371 | * @param nodeIdentifierString string from yang file |
363 | - * @param yangConstruct yang construct for creating error message | 372 | + * @param yangConstruct yang construct for creating error message |
364 | - * @param ctx yang construct's context to get the line number and character position | 373 | + * @param ctx yang construct's context to get the line number and character position |
365 | - * @param yangLeafRef instance of leafref where the path argument has to be set | 374 | + * @param yangLeafRef instance of leafref where the path argument has to be set |
366 | * @return valid node identifier | 375 | * @return valid node identifier |
367 | */ | 376 | */ |
368 | public static YangNodeIdentifier getValidNodeIdentifierForLeafref(String nodeIdentifierString, | 377 | public static YangNodeIdentifier getValidNodeIdentifierForLeafref(String nodeIdentifierString, |
369 | - YangConstructType yangConstruct, ParserRuleContext ctx, YangLeafRef yangLeafRef) { | 378 | + YangConstructType yangConstruct, |
379 | + ParserRuleContext ctx, YangLeafRef yangLeafRef) { | ||
370 | 380 | ||
371 | String tmpIdentifierString = removeQuotesAndHandleConcat(nodeIdentifierString); | 381 | String tmpIdentifierString = removeQuotesAndHandleConcat(nodeIdentifierString); |
372 | String[] tmpData = tmpIdentifierString.split(Pattern.quote(COLON)); | 382 | String[] tmpData = tmpIdentifierString.split(Pattern.quote(COLON)); |
... | @@ -392,13 +402,13 @@ public final class ListenerUtil { | ... | @@ -392,13 +402,13 @@ public final class ListenerUtil { |
392 | /** | 402 | /** |
393 | * Validates the path argument. It can be either absolute or relative path. | 403 | * Validates the path argument. It can be either absolute or relative path. |
394 | * | 404 | * |
395 | - * @param pathString the path string from the path type | 405 | + * @param pathString the path string from the path type |
396 | * @param yangConstruct yang construct for creating error message | 406 | * @param yangConstruct yang construct for creating error message |
397 | - * @param ctx yang construct's context to get the line number and character position | 407 | + * @param ctx yang construct's context to get the line number and character position |
398 | - * @param yangLeafRef instance of leafref where the path argument has to be set | 408 | + * @param yangLeafRef instance of leafref where the path argument has to be set |
399 | */ | 409 | */ |
400 | public static void validatePathArgument(String pathString, YangConstructType yangConstruct, | 410 | public static void validatePathArgument(String pathString, YangConstructType yangConstruct, |
401 | - ParserRuleContext ctx, YangLeafRef yangLeafRef) { | 411 | + ParserRuleContext ctx, YangLeafRef yangLeafRef) { |
402 | 412 | ||
403 | String completePathString = removeQuotesAndHandleConcat(pathString); | 413 | String completePathString = removeQuotesAndHandleConcat(pathString); |
404 | yangLeafRef.setPath(completePathString); | 414 | yangLeafRef.setPath(completePathString); |
... | @@ -406,6 +416,7 @@ public final class ListenerUtil { | ... | @@ -406,6 +416,7 @@ public final class ListenerUtil { |
406 | yangLeafRef.setPathType(ABSOLUTE_PATH); | 416 | yangLeafRef.setPathType(ABSOLUTE_PATH); |
407 | List<YangAtomicPath> yangAtomicPathListList = validateAbsolutePath(completePathString, yangConstruct, ctx, | 417 | List<YangAtomicPath> yangAtomicPathListList = validateAbsolutePath(completePathString, yangConstruct, ctx, |
408 | yangLeafRef); | 418 | yangLeafRef); |
419 | + validatePrefixAndYangNode(yangAtomicPathListList, yangLeafRef); | ||
409 | yangLeafRef.setAtomicPath(yangAtomicPathListList); | 420 | yangLeafRef.setAtomicPath(yangAtomicPathListList); |
410 | } else if (completePathString.startsWith(ANCESTOR_ACCESSOR)) { | 421 | } else if (completePathString.startsWith(ANCESTOR_ACCESSOR)) { |
411 | yangLeafRef.setPathType(RELATIVE_PATH); | 422 | yangLeafRef.setPathType(RELATIVE_PATH); |
... | @@ -421,15 +432,239 @@ public final class ListenerUtil { | ... | @@ -421,15 +432,239 @@ public final class ListenerUtil { |
421 | } | 432 | } |
422 | 433 | ||
423 | /** | 434 | /** |
435 | + * Validates the prefixes in the leafref and assigns them to the respective imported name in map. | ||
436 | + * | ||
437 | + * @param yangAtomicPathList list of atomic poth | ||
438 | + * @param yangLeafRef instance YANG leafref | ||
439 | + */ | ||
440 | + private static void validatePrefixAndYangNode(List<YangAtomicPath> yangAtomicPathList, YangLeafRef yangLeafRef) { | ||
441 | + Iterator<YangAtomicPath> yangAtomicPathIterator = yangAtomicPathList.listIterator(); | ||
442 | + while (yangAtomicPathIterator.hasNext()) { | ||
443 | + YangAtomicPath atomicPath = yangAtomicPathIterator.next(); | ||
444 | + String prefix = atomicPath.getNodeIdentifier().getPrefix(); | ||
445 | + YangNode parentNodeOfLeafref = yangLeafRef.getParentNodeOfLeafref(); | ||
446 | + YangNode moduleOrSubModule = getModuleOrSubmoduleInFileOfTheCurrentNode(parentNodeOfLeafref); | ||
447 | + YangModule moduleNode = null; | ||
448 | + if (moduleOrSubModule instanceof YangModule) { | ||
449 | + moduleNode = (YangModule) moduleOrSubModule; | ||
450 | + } | ||
451 | + if (moduleNode != null) { | ||
452 | + updatePrefixWithTheImportedList(moduleNode, prefix, yangLeafRef); | ||
453 | + } | ||
454 | + } | ||
455 | + } | ||
456 | + | ||
457 | + /** | ||
458 | + * Updates the prefix with the imported list in the module. | ||
459 | + * | ||
460 | + * @param moduleNode root node of the leafref | ||
461 | + * @param prefixInPath prefix in the path | ||
462 | + * @param yangLeafRef instance YANG leafref | ||
463 | + */ | ||
464 | + private static void updatePrefixWithTheImportedList(YangModule moduleNode, String prefixInPath, YangLeafRef | ||
465 | + yangLeafRef) { | ||
466 | + if (prefixInPath != null && prefixInPath != EMPTY_STRING && !prefixInPath.equals(moduleNode.getPrefix())) { | ||
467 | + List<YangImport> moduleImportList = moduleNode.getImportList(); | ||
468 | + if (moduleImportList != null && !moduleImportList.isEmpty()) { | ||
469 | + Iterator<YangImport> yangImportIterator = moduleImportList.listIterator(); | ||
470 | + while (yangImportIterator.hasNext()) { | ||
471 | + YangImport yangImport = yangImportIterator.next(); | ||
472 | + if (yangImport.getPrefixId().equals(prefixInPath)) { | ||
473 | + HashMap prefixMap = new HashMap(); | ||
474 | + prefixMap.put(prefixInPath, yangImport.getModuleName()); | ||
475 | + yangLeafRef.setPrefixAndItsImportedModule(prefixMap); | ||
476 | + } | ||
477 | + } | ||
478 | + } | ||
479 | + } else { | ||
480 | + HashMap prefixMap = new HashMap(); | ||
481 | + prefixMap.put(prefixInPath, moduleNode.getName()); | ||
482 | + yangLeafRef.setPrefixAndItsImportedModule(prefixMap); | ||
483 | + } | ||
484 | + } | ||
485 | + | ||
486 | + /** | ||
487 | + * Returns module or submodule node from the current node. | ||
488 | + * | ||
489 | + * @param node current node | ||
490 | + * @return root node | ||
491 | + */ | ||
492 | + private static YangNode getModuleOrSubmoduleInFileOfTheCurrentNode(YangNode node) { | ||
493 | + while (!(node instanceof YangModule) && !(node instanceof YangSubModule)) { | ||
494 | + if (node == null) { | ||
495 | + throw new ParserException("Internal datamodel error: Datamodel tree is not correct"); | ||
496 | + } | ||
497 | + node = node.getParent(); | ||
498 | + } | ||
499 | + return node; | ||
500 | + } | ||
501 | + | ||
502 | + /** | ||
503 | + * Validates the unique syntax from the reference path. | ||
504 | + * | ||
505 | + * @param uniquePath path of unique | ||
506 | + * @param prefixOfFile current file's prefix | ||
507 | + * @param ctx yang construct's context to get the line number and character position | ||
508 | + * @return list of absolute path | ||
509 | + */ | ||
510 | + private static List<YangAtomicPath> validateUniqueValues(String uniquePath, String prefixOfFile, | ||
511 | + ParserRuleContext ctx) { | ||
512 | + List<YangAtomicPath> atomicPath = new LinkedList<>(); | ||
513 | + String[] pathInUnique = uniquePath.split(SLASH_FOR_STRING); | ||
514 | + for (String uniqueValue : pathInUnique) { | ||
515 | + YangAtomicPath yangAtomicPathPath = new YangAtomicPath(); | ||
516 | + YangNodeIdentifier nodeIdentifier = getValidNodeIdentifier(uniqueValue, YangConstructType.UNIQUE_DATA, ctx); | ||
517 | + yangAtomicPathPath.setNodeIdentifier(nodeIdentifier); | ||
518 | + atomicPath.add(yangAtomicPathPath); | ||
519 | + if (nodeIdentifier.getPrefix() != null && nodeIdentifier.getPrefix() != prefixOfFile) { | ||
520 | + ParserException parserException = new ParserException("YANG file error : A leaf reference, in unique," + | ||
521 | + " must refer to a leaf in the list"); | ||
522 | + parserException.setLine(ctx.getStart().getLine()); | ||
523 | + parserException.setCharPosition(ctx.getStart().getCharPositionInLine()); | ||
524 | + throw parserException; | ||
525 | + } | ||
526 | + } | ||
527 | + return atomicPath; | ||
528 | + } | ||
529 | + | ||
530 | + /** | ||
531 | + * Validates unique field from the list. | ||
532 | + * | ||
533 | + * @param yangList instance of YANG list | ||
534 | + * @param ctx yang construct's context to get the line number and character position | ||
535 | + */ | ||
536 | + public static void validateUniqueInList(YangList yangList, ParserRuleContext ctx) { | ||
537 | + YangLeaf leaf; | ||
538 | + // Returns the prefix for the file where unique is present. | ||
539 | + String prefixOfTheFile = getPrefixInFileOfTheCurrentNode(yangList); | ||
540 | + List<String> uniques = yangList.getUniqueList(); | ||
541 | + if (uniques != null && !uniques.isEmpty()) { | ||
542 | + Iterator<String> uniqueList = uniques.listIterator(); | ||
543 | + while (uniqueList.hasNext()) { | ||
544 | + String pathInUnique = uniqueList.next(); | ||
545 | + List<YangAtomicPath> atomicPathInUnique = validateUniqueValues(pathInUnique, prefixOfTheFile, ctx); | ||
546 | + YangAtomicPath leafInPath = atomicPathInUnique.get(atomicPathInUnique.size() - 1); | ||
547 | + if (atomicPathInUnique.size() == 1) { | ||
548 | + leaf = getReferenceLeafFromUnique(yangList, leafInPath); | ||
549 | + } else { | ||
550 | + atomicPathInUnique.remove(atomicPathInUnique.size() - 1); | ||
551 | + YangNode holderOfLeaf = getNodeUnderListFromPath(atomicPathInUnique, yangList, ctx); | ||
552 | + leaf = getReferenceLeafFromUnique(holderOfLeaf, leafInPath); | ||
553 | + } | ||
554 | + if (leaf == null) { | ||
555 | + ParserException parserException = new ParserException("YANG file error : A leaf reference, in " + | ||
556 | + "unique," + | ||
557 | + " must refer to a leaf under the list"); | ||
558 | + parserException.setLine(ctx.getStart().getLine()); | ||
559 | + parserException.setCharPosition(ctx.getStart().getCharPositionInLine()); | ||
560 | + throw parserException; | ||
561 | + } | ||
562 | + } | ||
563 | + } | ||
564 | + } | ||
565 | + | ||
566 | + /** | ||
567 | + * Returns the last node under the unique path. | ||
568 | + * | ||
569 | + * @param uniquePath atomic path list | ||
570 | + * @param node root node from where it starts searching | ||
571 | + * @param ctx yang construct's context to get the line number and character position | ||
572 | + * @return last node in the list | ||
573 | + */ | ||
574 | + private static YangNode getNodeUnderListFromPath(List<YangAtomicPath> uniquePath, YangNode node, | ||
575 | + ParserRuleContext ctx) { | ||
576 | + Iterator<YangAtomicPath> nodesInReference = uniquePath.listIterator(); | ||
577 | + YangNode potentialReferredNode = node.getChild(); | ||
578 | + while (nodesInReference.hasNext()) { | ||
579 | + YangAtomicPath nodeInUnique = nodesInReference.next(); | ||
580 | + YangNode referredNode = getReferredNodeFromTheUniqueNodes(nodeInUnique.getNodeIdentifier(), | ||
581 | + potentialReferredNode); | ||
582 | + if (referredNode == null) { | ||
583 | + ParserException parserException = new ParserException("YANG file error : The target node in unique " + | ||
584 | + "reference path is invalid"); | ||
585 | + parserException.setLine(ctx.getStart().getLine()); | ||
586 | + parserException.setCharPosition(ctx.getStart().getCharPositionInLine()); | ||
587 | + throw parserException; | ||
588 | + } else { | ||
589 | + potentialReferredNode = referredNode.getChild(); | ||
590 | + } | ||
591 | + } | ||
592 | + return potentialReferredNode; | ||
593 | + } | ||
594 | + | ||
595 | + /** | ||
596 | + * Returns the node that matches with the name of the node in path. | ||
597 | + * | ||
598 | + * @param nodeInUnique node name in path | ||
599 | + * @param potentialReferredNode node under which it has to match | ||
600 | + * @return referred node | ||
601 | + */ | ||
602 | + private static YangNode getReferredNodeFromTheUniqueNodes(YangNodeIdentifier nodeInUnique, YangNode | ||
603 | + potentialReferredNode) { | ||
604 | + while (potentialReferredNode != null) { | ||
605 | + // Check if the potential referred node is the actual referred node | ||
606 | + if (potentialReferredNode.getName().equals(nodeInUnique.getName())) { | ||
607 | + return potentialReferredNode; | ||
608 | + } | ||
609 | + potentialReferredNode = potentialReferredNode.getNextSibling(); | ||
610 | + } | ||
611 | + return null; | ||
612 | + } | ||
613 | + | ||
614 | + /** | ||
615 | + * Returns the leaf which unique refers. | ||
616 | + * | ||
617 | + * @param nodeForLeaf last node where leaf is referred | ||
618 | + * @param leafInUnique leaf in unique path | ||
619 | + * @return YANG leaf | ||
620 | + */ | ||
621 | + private static YangLeaf getReferenceLeafFromUnique(YangNode nodeForLeaf, YangAtomicPath leafInUnique) { | ||
622 | + YangLeavesHolder leavesHolder = (YangLeavesHolder) nodeForLeaf; | ||
623 | + List<YangLeaf> leaves = leavesHolder.getListOfLeaf(); | ||
624 | + if (leaves != null && !leaves.isEmpty()) { | ||
625 | + for (YangLeaf leaf : leaves) { | ||
626 | + if (leafInUnique.getNodeIdentifier().getName().equals(leaf.getName())) { | ||
627 | + return leaf; | ||
628 | + } | ||
629 | + } | ||
630 | + } | ||
631 | + return null; | ||
632 | + } | ||
633 | + | ||
634 | + /** | ||
635 | + * Returns the prefix of the current file. | ||
636 | + * | ||
637 | + * @param node node where it needs to find the root node | ||
638 | + * @return prefix of root node | ||
639 | + */ | ||
640 | + public static String getPrefixInFileOfTheCurrentNode(YangNode node) { | ||
641 | + String prefixInFile; | ||
642 | + while (!(node instanceof YangReferenceResolver)) { | ||
643 | + node = node.getParent(); | ||
644 | + if (node == null) { | ||
645 | + throw new ParserException("Internal datamodel error: Datamodel tree is not correct"); | ||
646 | + } | ||
647 | + } | ||
648 | + if (node instanceof YangModule) { | ||
649 | + YangModule yangModule = (YangModule) node; | ||
650 | + prefixInFile = yangModule.getPrefix(); | ||
651 | + } else { | ||
652 | + YangSubModule yangSubModule = (YangSubModule) node; | ||
653 | + prefixInFile = yangSubModule.getPrefix(); | ||
654 | + } | ||
655 | + return prefixInFile; | ||
656 | + } | ||
657 | + | ||
658 | + /** | ||
424 | * Validates the relative path. | 659 | * Validates the relative path. |
425 | * | 660 | * |
426 | * @param completePathString the path string of relative path | 661 | * @param completePathString the path string of relative path |
427 | - * @param yangConstruct yang construct for creating error message | 662 | + * @param yangConstruct yang construct for creating error message |
428 | - * @param ctx yang construct's context to get the line number and character position | 663 | + * @param ctx yang construct's context to get the line number and character position |
429 | - * @param yangLeafRef instance of leafref where the path argument has to be set | 664 | + * @param yangLeafRef instance of leafref where the path argument has to be set |
430 | */ | 665 | */ |
431 | private static void validateRelativePath(String completePathString, YangConstructType yangConstruct, | 666 | private static void validateRelativePath(String completePathString, YangConstructType yangConstruct, |
432 | - ParserRuleContext ctx, YangLeafRef yangLeafRef) { | 667 | + ParserRuleContext ctx, YangLeafRef yangLeafRef) { |
433 | 668 | ||
434 | YangRelativePath relativePath = new YangRelativePath(); | 669 | YangRelativePath relativePath = new YangRelativePath(); |
435 | int numberOfAncestors = 0; | 670 | int numberOfAncestors = 0; |
... | @@ -449,6 +684,7 @@ public final class ListenerUtil { | ... | @@ -449,6 +684,7 @@ public final class ListenerUtil { |
449 | List<YangAtomicPath> atomicPath = validateAbsolutePath(SLASH_FOR_STRING + completePathString, | 684 | List<YangAtomicPath> atomicPath = validateAbsolutePath(SLASH_FOR_STRING + completePathString, |
450 | yangConstruct, | 685 | yangConstruct, |
451 | ctx, yangLeafRef); | 686 | ctx, yangLeafRef); |
687 | + validatePrefixAndYangNode(atomicPath, yangLeafRef); | ||
452 | relativePath.setAtomicPathList(atomicPath); | 688 | relativePath.setAtomicPathList(atomicPath); |
453 | yangLeafRef.setRelativePath(relativePath); | 689 | yangLeafRef.setRelativePath(relativePath); |
454 | } | 690 | } |
... | @@ -457,13 +693,14 @@ public final class ListenerUtil { | ... | @@ -457,13 +693,14 @@ public final class ListenerUtil { |
457 | * Validates the absolute path. | 693 | * Validates the absolute path. |
458 | * | 694 | * |
459 | * @param completePathString the path string of absolute path | 695 | * @param completePathString the path string of absolute path |
460 | - * @param yangConstruct yang construct for creating error message | 696 | + * @param yangConstruct yang construct for creating error message |
461 | - * @param ctx yang construct's context to get the line number and character position | 697 | + * @param ctx yang construct's context to get the line number and character position |
462 | - * @param yangLeafRef instance of leafref where the path argument has to be set | 698 | + * @param yangLeafRef instance of leafref where the path argument has to be set |
463 | * @return list of object of node in absolute path | 699 | * @return list of object of node in absolute path |
464 | */ | 700 | */ |
465 | private static List<YangAtomicPath> validateAbsolutePath(String completePathString, | 701 | private static List<YangAtomicPath> validateAbsolutePath(String completePathString, |
466 | - YangConstructType yangConstruct, ParserRuleContext ctx, YangLeafRef yangLeafRef) { | 702 | + YangConstructType yangConstruct, ParserRuleContext |
703 | + ctx, YangLeafRef yangLeafRef) { | ||
467 | 704 | ||
468 | List<YangAtomicPath> absolutePathList = new LinkedList<>(); | 705 | List<YangAtomicPath> absolutePathList = new LinkedList<>(); |
469 | YangPathPredicate yangPathPredicate = new YangPathPredicate(); | 706 | YangPathPredicate yangPathPredicate = new YangPathPredicate(); |
... | @@ -555,16 +792,17 @@ public final class ListenerUtil { | ... | @@ -555,16 +792,17 @@ public final class ListenerUtil { |
555 | /** | 792 | /** |
556 | * Validates path predicate in the absolute path's node. | 793 | * Validates path predicate in the absolute path's node. |
557 | * | 794 | * |
558 | - * @param pathPredicate list of path predicates in the node of absolute path | 795 | + * @param pathPredicate list of path predicates in the node of absolute path |
559 | - * @param yangConstruct yang construct for creating error message | 796 | + * @param yangConstruct yang construct for creating error message |
560 | - * @param ctx yang construct's context to get the line number and character position | 797 | + * @param ctx yang construct's context to get the line number and character position |
561 | * @param yangPathPredicate instance of path predicate where it has to be set | 798 | * @param yangPathPredicate instance of path predicate where it has to be set |
562 | - * @param yangLeafRef instance of leafref where the path argument has to be set | 799 | + * @param yangLeafRef instance of leafref where the path argument has to be set |
563 | * @return list of object of path predicates in absolute path's node | 800 | * @return list of object of path predicates in absolute path's node |
564 | */ | 801 | */ |
565 | private static List<YangPathPredicate> validatePathPredicate(List<String> pathPredicate, | 802 | private static List<YangPathPredicate> validatePathPredicate(List<String> pathPredicate, |
566 | - YangConstructType yangConstruct, ParserRuleContext ctx, YangPathPredicate yangPathPredicate, | 803 | + YangConstructType yangConstruct, ParserRuleContext |
567 | - YangLeafRef yangLeafRef) { | 804 | + ctx, YangPathPredicate yangPathPredicate, |
805 | + YangLeafRef yangLeafRef) { | ||
568 | 806 | ||
569 | Iterator<String> pathPredicateString = pathPredicate.iterator(); | 807 | Iterator<String> pathPredicateString = pathPredicate.iterator(); |
570 | List<String> pathEqualityExpression = new ArrayList<>(); | 808 | List<String> pathEqualityExpression = new ArrayList<>(); |
... | @@ -585,15 +823,17 @@ public final class ListenerUtil { | ... | @@ -585,15 +823,17 @@ public final class ListenerUtil { |
585 | * Validates the path equality expression. | 823 | * Validates the path equality expression. |
586 | * | 824 | * |
587 | * @param pathEqualityExpression list of path equality expression in the path predicates of the node | 825 | * @param pathEqualityExpression list of path equality expression in the path predicates of the node |
588 | - * @param yangConstruct yang construct for creating error message | 826 | + * @param yangConstruct yang construct for creating error message |
589 | - * @param ctx yang construct's context to get the line number and character position | 827 | + * @param ctx yang construct's context to get the line number and character position |
590 | - * @param yangPathPredicate instance of path predicate where it has to be set | 828 | + * @param yangPathPredicate instance of path predicate where it has to be set |
591 | - * @param yangLeafRef instance of leafref where the path argument has to be set | 829 | + * @param yangLeafRef instance of leafref where the path argument has to be set |
592 | * @return list of object of path predicates in absolute path's node | 830 | * @return list of object of path predicates in absolute path's node |
593 | */ | 831 | */ |
594 | private static List<YangPathPredicate> validatePathEqualityExpression(List<String> pathEqualityExpression, | 832 | private static List<YangPathPredicate> validatePathEqualityExpression(List<String> pathEqualityExpression, |
595 | - YangConstructType yangConstruct, ParserRuleContext ctx, YangPathPredicate yangPathPredicate, | 833 | + YangConstructType yangConstruct, |
596 | - YangLeafRef yangLeafRef) { | 834 | + ParserRuleContext ctx, YangPathPredicate |
835 | + yangPathPredicate, | ||
836 | + YangLeafRef yangLeafRef) { | ||
597 | 837 | ||
598 | Iterator<String> pathEqualityExpressionString = pathEqualityExpression.iterator(); | 838 | Iterator<String> pathEqualityExpressionString = pathEqualityExpression.iterator(); |
599 | List<YangPathPredicate> yangPathPredicateList = new ArrayList<>(); | 839 | List<YangPathPredicate> yangPathPredicateList = new ArrayList<>(); |
... | @@ -620,13 +860,14 @@ public final class ListenerUtil { | ... | @@ -620,13 +860,14 @@ public final class ListenerUtil { |
620 | * Validate the path key expression. | 860 | * Validate the path key expression. |
621 | * | 861 | * |
622 | * @param rightRelativePath relative path in the path predicate | 862 | * @param rightRelativePath relative path in the path predicate |
623 | - * @param yangConstruct yang construct for creating error message | 863 | + * @param yangConstruct yang construct for creating error message |
624 | - * @param ctx yang construct's context to get the line number and character position | 864 | + * @param ctx yang construct's context to get the line number and character position |
625 | - * @param yangLeafRef instance of leafref where the path argument has to be set | 865 | + * @param yangLeafRef instance of leafref where the path argument has to be set |
626 | * @return object of right relative path in path predicate | 866 | * @return object of right relative path in path predicate |
627 | */ | 867 | */ |
628 | private static YangRelativePath validatePathKeyExpression(String rightRelativePath, | 868 | private static YangRelativePath validatePathKeyExpression(String rightRelativePath, |
629 | - YangConstructType yangConstruct, ParserRuleContext ctx, YangLeafRef yangLeafRef) { | 869 | + YangConstructType yangConstruct, ParserRuleContext ctx, |
870 | + YangLeafRef yangLeafRef) { | ||
630 | 871 | ||
631 | YangRelativePath yangRelativePath = new YangRelativePath(); | 872 | YangRelativePath yangRelativePath = new YangRelativePath(); |
632 | String[] relativePath = rightRelativePath.split(SLASH_FOR_STRING); | 873 | String[] relativePath = rightRelativePath.split(SLASH_FOR_STRING); |
... | @@ -650,13 +891,15 @@ public final class ListenerUtil { | ... | @@ -650,13 +891,15 @@ public final class ListenerUtil { |
650 | * Validates the relative path key expression. | 891 | * Validates the relative path key expression. |
651 | * | 892 | * |
652 | * @param rightAbsolutePath absolute path nodes present in the relative path | 893 | * @param rightAbsolutePath absolute path nodes present in the relative path |
653 | - * @param yangConstruct yang construct for creating error message | 894 | + * @param yangConstruct yang construct for creating error message |
654 | - * @param ctx yang construct's context to get the line number and character position | 895 | + * @param ctx yang construct's context to get the line number and character position |
655 | - * @param yangLeafRef instance of leafref where the path argument has to be set | 896 | + * @param yangLeafRef instance of leafref where the path argument has to be set |
656 | * @return list of object of absolute path nodes present in the relative path | 897 | * @return list of object of absolute path nodes present in the relative path |
657 | */ | 898 | */ |
658 | private static List<YangAtomicPath> validateRelativePathKeyExpression(List<String> rightAbsolutePath, | 899 | private static List<YangAtomicPath> validateRelativePathKeyExpression(List<String> rightAbsolutePath, |
659 | - YangConstructType yangConstruct, ParserRuleContext ctx, YangLeafRef yangLeafRef) { | 900 | + YangConstructType yangConstruct, |
901 | + ParserRuleContext ctx, YangLeafRef | ||
902 | + yangLeafRef) { | ||
660 | 903 | ||
661 | List<YangAtomicPath> atomicPathList = new ArrayList<>(); | 904 | List<YangAtomicPath> atomicPathList = new ArrayList<>(); |
662 | YangNodeIdentifier yangNodeIdentifier; | 905 | YangNodeIdentifier yangNodeIdentifier; |
... | @@ -704,13 +947,14 @@ public final class ListenerUtil { | ... | @@ -704,13 +947,14 @@ public final class ListenerUtil { |
704 | /** | 947 | /** |
705 | * Checks and return valid absolute schema node id. | 948 | * Checks and return valid absolute schema node id. |
706 | * | 949 | * |
707 | - * @param argumentString string from yang file | 950 | + * @param argumentString string from yang file |
708 | * @param yangConstructType yang construct for creating error message | 951 | * @param yangConstructType yang construct for creating error message |
709 | - * @param ctx yang construct's context to get the line number and character position | 952 | + * @param ctx yang construct's context to get the line number and character position |
710 | * @return target nodes list of absolute schema node id | 953 | * @return target nodes list of absolute schema node id |
711 | */ | 954 | */ |
712 | public static List<YangAtomicPath> getValidAbsoluteSchemaNodeId(String argumentString, | 955 | public static List<YangAtomicPath> getValidAbsoluteSchemaNodeId(String argumentString, |
713 | - YangConstructType yangConstructType, ParserRuleContext ctx) { | 956 | + YangConstructType yangConstructType, |
957 | + ParserRuleContext ctx) { | ||
714 | 958 | ||
715 | List<YangAtomicPath> targetNodes = new ArrayList<>(); | 959 | List<YangAtomicPath> targetNodes = new ArrayList<>(); |
716 | YangNodeIdentifier yangNodeIdentifier; | 960 | YangNodeIdentifier yangNodeIdentifier; |
... | @@ -739,11 +983,11 @@ public final class ListenerUtil { | ... | @@ -739,11 +983,11 @@ public final class ListenerUtil { |
739 | * Throws parser exception for unsupported YANG constructs. | 983 | * Throws parser exception for unsupported YANG constructs. |
740 | * | 984 | * |
741 | * @param yangConstructType yang construct for creating error message | 985 | * @param yangConstructType yang construct for creating error message |
742 | - * @param ctx yang construct's context to get the line number and character position | 986 | + * @param ctx yang construct's context to get the line number and character position |
743 | - * @param errorInfo error information | 987 | + * @param errorInfo error information |
744 | */ | 988 | */ |
745 | public static void handleUnsupportedYangConstruct(YangConstructType yangConstructType, | 989 | public static void handleUnsupportedYangConstruct(YangConstructType yangConstructType, |
746 | - ParserRuleContext ctx, String errorInfo) { | 990 | + ParserRuleContext ctx, String errorInfo) { |
747 | ParserException parserException = new ParserException(YANG_FILE_ERROR | 991 | ParserException parserException = new ParserException(YANG_FILE_ERROR |
748 | + QUOTES + YangConstructType.getYangConstructType(yangConstructType) + QUOTES | 992 | + QUOTES + YangConstructType.getYangConstructType(yangConstructType) + QUOTES |
749 | + errorInfo); | 993 | + errorInfo); | ... | ... |
... | @@ -444,33 +444,6 @@ public class ConfigListenerTest { | ... | @@ -444,33 +444,6 @@ public class ConfigListenerTest { |
444 | * config statement's value. | 444 | * config statement's value. |
445 | */ | 445 | */ |
446 | @Test | 446 | @Test |
447 | - public void processNoConfigListSubStatementLeafList() throws IOException, ParserException { | ||
448 | - | ||
449 | - YangNode node = manager.getDataModel("src/test/resources/NoConfigListSubStatementLeafList.yang"); | ||
450 | - | ||
451 | - assertThat((node instanceof YangModule), is(true)); | ||
452 | - assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
453 | - YangModule yangNode = (YangModule) node; | ||
454 | - assertThat(yangNode.getName(), is("Test")); | ||
455 | - | ||
456 | - // Check whether the config value is set correctly. | ||
457 | - YangList list1 = (YangList) yangNode.getChild(); | ||
458 | - assertThat(list1.getName(), is("valid")); | ||
459 | - assertThat(list1.isConfig(), is(true)); | ||
460 | - | ||
461 | - ListIterator<YangLeafList> leafListIterator = list1.getListOfLeafList().listIterator(); | ||
462 | - YangLeafList leafListInfo = leafListIterator.next(); | ||
463 | - | ||
464 | - // Check whether config value is set correctly. | ||
465 | - assertThat(leafListInfo.getName(), is("invalid-interval")); | ||
466 | - assertThat(leafListInfo.isConfig(), is(true)); | ||
467 | - } | ||
468 | - | ||
469 | - /** | ||
470 | - * Checks when config is not specified, the default is same as the parent's schema node's | ||
471 | - * config statement's value. | ||
472 | - */ | ||
473 | - @Test | ||
474 | public void processNoConfigListSubStatementLeaf() throws IOException, ParserException { | 447 | public void processNoConfigListSubStatementLeaf() throws IOException, ParserException { |
475 | 448 | ||
476 | YangNode node = manager.getDataModel("src/test/resources/NoConfigListSubStatementLeaf.yang"); | 449 | YangNode node = manager.getDataModel("src/test/resources/NoConfigListSubStatementLeaf.yang"); | ... | ... |
... | @@ -143,26 +143,6 @@ public class KeyListenerTest { | ... | @@ -143,26 +143,6 @@ public class KeyListenerTest { |
143 | } | 143 | } |
144 | 144 | ||
145 | /** | 145 | /** |
146 | - * Checks key values are set correctly. | ||
147 | - */ | ||
148 | - @Test | ||
149 | - public void processConfigFalseValidKeyValidLeafList() throws IOException, ParserException { | ||
150 | - YangNode node = manager.getDataModel("src/test/resources/ConfigFalseValidKeyValidLeafList.yang"); | ||
151 | - | ||
152 | - assertThat((node instanceof YangModule), is(true)); | ||
153 | - assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
154 | - YangModule yangNode = (YangModule) node; | ||
155 | - assertThat(yangNode.getName(), is("Test")); | ||
156 | - | ||
157 | - // Check whether the list is child of module | ||
158 | - YangList yangList = (YangList) yangNode.getChild(); | ||
159 | - assertThat(yangList.getName(), is("valid")); | ||
160 | - | ||
161 | - ListIterator<String> keyList = yangList.getKeyList().listIterator(); | ||
162 | - assertThat(keyList.next(), is("invalid-interval")); | ||
163 | - } | ||
164 | - | ||
165 | - /** | ||
166 | * Checks whether exception is thrown when list's config is set to true and there is no key. | 146 | * Checks whether exception is thrown when list's config is set to true and there is no key. |
167 | */ | 147 | */ |
168 | @Test | 148 | @Test |
... | @@ -233,26 +213,6 @@ public class KeyListenerTest { | ... | @@ -233,26 +213,6 @@ public class KeyListenerTest { |
233 | } | 213 | } |
234 | 214 | ||
235 | /** | 215 | /** |
236 | - * Checks whether exception is thrown when key leaf-list identifier is not found in list. | ||
237 | - */ | ||
238 | - @Test | ||
239 | - public void processInvalidLeafListIdentifier() throws IOException, ParserException { | ||
240 | - thrown.expect(ParserException.class); | ||
241 | - thrown.expectMessage("An identifier, in key, must refer to a child leaf of the list"); | ||
242 | - YangNode node = manager.getDataModel("src/test/resources/InvalidLeafListIdentifier.yang"); | ||
243 | - } | ||
244 | - | ||
245 | - /** | ||
246 | - * Checks whether exception is thrown when key leaf-list is of type empty. | ||
247 | - */ | ||
248 | - @Test | ||
249 | - public void processKeyLeafListTypeEmpty() throws IOException, ParserException { | ||
250 | - thrown.expect(ParserException.class); | ||
251 | - thrown.expectMessage("A leaf-list that is part of the key must not be the built-in type \"empty\"."); | ||
252 | - YangNode node = manager.getDataModel("src/test/resources/KeyLeafListTypeEmpty.yang"); | ||
253 | - } | ||
254 | - | ||
255 | - /** | ||
256 | * Checks whether exception is thrown when key leaf is of type empty. | 216 | * Checks whether exception is thrown when key leaf is of type empty. |
257 | */ | 217 | */ |
258 | @Test | 218 | @Test | ... | ... |
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.junit.Rule; | ||
20 | +import org.junit.Test; | ||
21 | +import org.junit.rules.ExpectedException; | ||
22 | +import org.onosproject.yangutils.datamodel.YangList; | ||
23 | +import org.onosproject.yangutils.datamodel.YangModule; | ||
24 | +import org.onosproject.yangutils.datamodel.YangNode; | ||
25 | +import org.onosproject.yangutils.datamodel.YangNodeType; | ||
26 | +import org.onosproject.yangutils.parser.exceptions.ParserException; | ||
27 | +import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; | ||
28 | + | ||
29 | +import java.io.IOException; | ||
30 | +import java.util.ListIterator; | ||
31 | + | ||
32 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
33 | +import static org.hamcrest.core.Is.is; | ||
34 | + | ||
35 | +/** | ||
36 | + * Test cases for unique listener. | ||
37 | + */ | ||
38 | +public class UniqueListenerTest { | ||
39 | + | ||
40 | + @Rule | ||
41 | + public ExpectedException thrown = ExpectedException.none(); | ||
42 | + | ||
43 | + private final YangUtilsParserManager manager = new YangUtilsParserManager(); | ||
44 | + | ||
45 | + /** | ||
46 | + * Checks unique statement as sub-statement of list. | ||
47 | + */ | ||
48 | + @Test | ||
49 | + public void processListSubStatementUnique() throws IOException, ParserException { | ||
50 | + | ||
51 | + YangNode node = manager.getDataModel("src/test/resources/ListSubStatementUnique.yang"); | ||
52 | + | ||
53 | + assertThat((node instanceof YangModule), is(true)); | ||
54 | + | ||
55 | + // Check whether the node type is set properly to module. | ||
56 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
57 | + | ||
58 | + // Check whether the module name is set correctly. | ||
59 | + YangModule yangNode = (YangModule) node; | ||
60 | + assertThat(yangNode.getName(), is("Test")); | ||
61 | + | ||
62 | + // Check whether the list is child of module | ||
63 | + YangList yangList = (YangList) yangNode.getChild(); | ||
64 | + assertThat(yangList.getName(), is("valid")); | ||
65 | + assertThat(yangList.getUniqueList().listIterator().next(), is("invalid-interval")); | ||
66 | + } | ||
67 | + | ||
68 | + /** | ||
69 | + * Check multiple unique values. | ||
70 | + */ | ||
71 | + @Test | ||
72 | + public void processMultipleUniqueValues() throws IOException, ParserException { | ||
73 | + | ||
74 | + YangNode node = manager.getDataModel("src/test/resources/MultipleUniqueValues.yang"); | ||
75 | + | ||
76 | + assertThat((node instanceof YangModule), is(true)); | ||
77 | + | ||
78 | + // Check whether the node type is set properly to module. | ||
79 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
80 | + | ||
81 | + // Check whether the module name is set correctly. | ||
82 | + YangModule yangNode = (YangModule) node; | ||
83 | + assertThat(yangNode.getName(), is("Test")); | ||
84 | + | ||
85 | + // Check whether the list is child of module | ||
86 | + YangList yangList = (YangList) yangNode.getChild(); | ||
87 | + assertThat(yangList.getName(), is("valid")); | ||
88 | + ListIterator<String> listIterator; | ||
89 | + String list; | ||
90 | + listIterator = yangList.getUniqueList().listIterator(); | ||
91 | + list = listIterator.next(); | ||
92 | + assertThat(list, is("ospf")); | ||
93 | + list = listIterator.next(); | ||
94 | + assertThat(list, is("isis")); | ||
95 | + } | ||
96 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +/* | ||
2 | + * Copyright 2016-present Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.yangutils.plugin.manager; | ||
18 | + | ||
19 | +import org.apache.maven.plugin.MojoExecutionException; | ||
20 | +import org.junit.Rule; | ||
21 | +import org.junit.Test; | ||
22 | +import org.junit.rules.ExpectedException; | ||
23 | +import org.onosproject.yangutils.datamodel.YangContainer; | ||
24 | +import org.onosproject.yangutils.datamodel.YangLeaf; | ||
25 | +import org.onosproject.yangutils.datamodel.YangLeafRef; | ||
26 | +import org.onosproject.yangutils.datamodel.YangList; | ||
27 | +import org.onosproject.yangutils.datamodel.YangModule; | ||
28 | +import org.onosproject.yangutils.datamodel.YangNode; | ||
29 | +import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes; | ||
30 | +import org.onosproject.yangutils.linker.impl.YangLinkerManager; | ||
31 | +import org.onosproject.yangutils.parser.exceptions.ParserException; | ||
32 | +import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; | ||
33 | +import org.onosproject.yangutils.utils.io.impl.YangFileScanner; | ||
34 | + | ||
35 | +import java.io.IOException; | ||
36 | +import java.util.Iterator; | ||
37 | +import java.util.ListIterator; | ||
38 | + | ||
39 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
40 | +import static org.hamcrest.core.Is.is; | ||
41 | +import static org.onosproject.yangutils.datamodel.YangNodeType.MODULE_NODE; | ||
42 | +import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.RESOLVED; | ||
43 | +import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.LEAFREF; | ||
44 | + | ||
45 | +/** | ||
46 | + * Test cases for testing leafref inter file linking. | ||
47 | + */ | ||
48 | +public class InterFileLeafrefLinkingTest { | ||
49 | + | ||
50 | + @Rule | ||
51 | + public ExpectedException thrown = ExpectedException.none(); | ||
52 | + | ||
53 | + private final YangUtilManager utilManager = new YangUtilManager(); | ||
54 | + private final YangLinkerManager yangLinkerManager = new YangLinkerManager(); | ||
55 | + private final YangUtilsParserManager manager = new YangUtilsParserManager(); | ||
56 | + | ||
57 | + /** | ||
58 | + * Checks inter file leafref linking. | ||
59 | + */ | ||
60 | + @Test | ||
61 | + public void processInterFileLeafrefLinking() | ||
62 | + throws IOException, ParserException, MojoExecutionException { | ||
63 | + | ||
64 | + String searchDir = "src/test/resources/leafreflinker/interfile/interfileleafrefwithimport"; | ||
65 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); | ||
66 | + utilManager.parseYangFileInfoSet(); | ||
67 | + utilManager.createYangNodeSet(); | ||
68 | + YangNode refNode = null; | ||
69 | + YangNode selfNode = null; | ||
70 | + | ||
71 | + // Create YANG node set | ||
72 | + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); | ||
73 | + | ||
74 | + // Add references to import list. | ||
75 | + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); | ||
76 | + | ||
77 | + // Carry out inter-file linking. | ||
78 | + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); | ||
79 | + | ||
80 | + Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator(); | ||
81 | + | ||
82 | + YangNode rootNode = yangNodeIterator.next(); | ||
83 | + | ||
84 | + if (rootNode.getName().equals("module1")) { | ||
85 | + selfNode = rootNode; | ||
86 | + refNode = yangNodeIterator.next(); | ||
87 | + } else { | ||
88 | + refNode = rootNode; | ||
89 | + selfNode = yangNodeIterator.next(); | ||
90 | + } | ||
91 | + | ||
92 | + // Check whether the data model tree returned is of type module. | ||
93 | + assertThat(selfNode instanceof YangModule, is(true)); | ||
94 | + | ||
95 | + // Check whether the node type is set properly to module. | ||
96 | + assertThat(selfNode.getNodeType(), is(MODULE_NODE)); | ||
97 | + | ||
98 | + // Check whether the module name is set correctly. | ||
99 | + YangModule yangNode = (YangModule) selfNode; | ||
100 | + assertThat(yangNode.getName(), is("module1")); | ||
101 | + | ||
102 | + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); | ||
103 | + YangLeaf leafInfo = leafIterator.next(); | ||
104 | + | ||
105 | + assertThat(leafInfo.getName(), is("invalid-interval")); | ||
106 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("leafref")); | ||
107 | + assertThat(leafInfo.getDataType().getDataType(), is(LEAFREF)); | ||
108 | + | ||
109 | + // Check whether the data model tree returned is of type module. | ||
110 | + assertThat(refNode instanceof YangModule, is(true)); | ||
111 | + | ||
112 | + // Check whether the node type is set properly to module. | ||
113 | + assertThat(refNode.getNodeType(), is(MODULE_NODE)); | ||
114 | + | ||
115 | + // Check whether the module name is set correctly. | ||
116 | + YangModule yangNode1 = (YangModule) refNode; | ||
117 | + assertThat(yangNode1.getName(), is("module2")); | ||
118 | + YangLeaf leafInfo1 = yangNode1.getListOfLeaf().listIterator().next(); | ||
119 | + | ||
120 | + YangLeafRef leafref = (YangLeafRef) leafInfo.getDataType().getDataTypeExtendedInfo(); | ||
121 | + | ||
122 | + assertThat(leafref.getReferredLeafOrLeafList(), is(leafInfo1)); | ||
123 | + assertThat(leafref.getResolvableStatus(), is(RESOLVED)); | ||
124 | + | ||
125 | + assertThat(leafref.getEffectiveDataType().getDataType(), | ||
126 | + is(YangDataTypes.STRING)); | ||
127 | + } | ||
128 | + | ||
129 | + /** | ||
130 | + * Checks inter file resolution when leafref from grouping refers to other file. | ||
131 | + */ | ||
132 | + @Test | ||
133 | + public void processInterFileLeafrefFromGroupingRefersToOtherFile() | ||
134 | + throws IOException, ParserException { | ||
135 | + | ||
136 | + String searchDir = "src/test/resources/leafreflinker/interfile/interfileleafreffromgroupingreferstootherfile"; | ||
137 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); | ||
138 | + utilManager.parseYangFileInfoSet(); | ||
139 | + utilManager.createYangNodeSet(); | ||
140 | + YangNode selfNode = null; | ||
141 | + YangNode refNode = null; | ||
142 | + | ||
143 | + // Create YANG node set | ||
144 | + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); | ||
145 | + | ||
146 | + // Add references to import list. | ||
147 | + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); | ||
148 | + | ||
149 | + // Carry out inter-file linking. | ||
150 | + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); | ||
151 | + | ||
152 | + Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator(); | ||
153 | + | ||
154 | + YangNode rootNode = yangNodeIterator.next(); | ||
155 | + | ||
156 | + if (rootNode.getName().equals("module1")) { | ||
157 | + selfNode = rootNode; | ||
158 | + refNode = yangNodeIterator.next(); | ||
159 | + } else { | ||
160 | + refNode = rootNode; | ||
161 | + selfNode = yangNodeIterator.next(); | ||
162 | + } | ||
163 | + | ||
164 | + // Check whether the data model tree returned is of type module. | ||
165 | + assertThat(selfNode instanceof YangModule, is(true)); | ||
166 | + | ||
167 | + // Check whether the node type is set properly to module. | ||
168 | + assertThat(selfNode.getNodeType(), is(MODULE_NODE)); | ||
169 | + | ||
170 | + // Check whether the module name is set correctly. | ||
171 | + YangModule yangNode = (YangModule) selfNode; | ||
172 | + assertThat(yangNode.getName(), is("module1")); | ||
173 | + | ||
174 | + YangList list = (YangList) yangNode.getChild().getChild(); | ||
175 | + ListIterator<YangLeaf> leafIterator = list.getListOfLeaf().listIterator(); | ||
176 | + YangLeaf leafInfo = leafIterator.next(); | ||
177 | + | ||
178 | + assertThat(leafInfo.getName(), is("link-tp")); | ||
179 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("leafref")); | ||
180 | + assertThat(leafInfo.getDataType().getDataType(), is(LEAFREF)); | ||
181 | + | ||
182 | + YangLeafRef leafref = (YangLeafRef) leafInfo.getDataType().getDataTypeExtendedInfo(); | ||
183 | + | ||
184 | + YangLeaf leafInfo2 = (YangLeaf) leafref.getReferredLeafOrLeafList(); | ||
185 | + assertThat(leafref.getReferredLeafOrLeafList(), is(leafInfo2)); | ||
186 | + assertThat(leafref.getResolvableStatus(), is(RESOLVED)); | ||
187 | + | ||
188 | + assertThat(leafref.getEffectiveDataType().getDataType(), | ||
189 | + is(YangDataTypes.STRING)); | ||
190 | + } | ||
191 | + | ||
192 | + /** | ||
193 | + * Checks inter file resolution when leafref from grouping with prefix is changed properly during cloning. | ||
194 | + */ | ||
195 | + @Test | ||
196 | + public void processInterFileLeafrefFromGroupingWithPrefixIsCloned() | ||
197 | + throws IOException, ParserException { | ||
198 | + | ||
199 | + String searchDir = "src/test/resources/leafreflinker/interfile/leafrefInGroupingWithPrefix"; | ||
200 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); | ||
201 | + utilManager.parseYangFileInfoSet(); | ||
202 | + utilManager.createYangNodeSet(); | ||
203 | + YangNode selfNode = null; | ||
204 | + YangNode refNode = null; | ||
205 | + | ||
206 | + // Create YANG node set | ||
207 | + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); | ||
208 | + | ||
209 | + // Add references to import list. | ||
210 | + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); | ||
211 | + | ||
212 | + // Carry out inter-file linking. | ||
213 | + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); | ||
214 | + | ||
215 | + Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator(); | ||
216 | + | ||
217 | + YangNode rootNode = yangNodeIterator.next(); | ||
218 | + | ||
219 | + if (rootNode.getName().equals("LeafrefInGroupingOfModule1")) { | ||
220 | + selfNode = rootNode; | ||
221 | + refNode = yangNodeIterator.next(); | ||
222 | + } else { | ||
223 | + refNode = rootNode; | ||
224 | + selfNode = yangNodeIterator.next(); | ||
225 | + } | ||
226 | + | ||
227 | + // Check whether the data model tree returned is of type module. | ||
228 | + assertThat(selfNode instanceof YangModule, is(true)); | ||
229 | + | ||
230 | + // Check whether the node type is set properly to module. | ||
231 | + assertThat(selfNode.getNodeType(), is(MODULE_NODE)); | ||
232 | + | ||
233 | + // Check whether the module name is set correctly. | ||
234 | + YangModule yangNode = (YangModule) selfNode; | ||
235 | + assertThat(yangNode.getName(), is("LeafrefInGroupingOfModule1")); | ||
236 | + | ||
237 | + // Check whether the module name is set correctly. | ||
238 | + YangModule yangNode1 = (YangModule) refNode; | ||
239 | + assertThat(yangNode1.getName(), is("GroupingCopiedInModule2")); | ||
240 | + | ||
241 | + YangContainer yangContainer = (YangContainer) yangNode1.getChild(); | ||
242 | + | ||
243 | + ListIterator<YangLeaf> leafIterator = yangContainer.getListOfLeaf().listIterator(); | ||
244 | + YangLeaf leafInfo = leafIterator.next(); | ||
245 | + | ||
246 | + assertThat(leafInfo.getName(), is("network-ref")); | ||
247 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("leafref")); | ||
248 | + assertThat(leafInfo.getDataType().getDataType(), is(LEAFREF)); | ||
249 | + | ||
250 | + YangLeafRef leafref = (YangLeafRef) leafInfo.getDataType().getDataTypeExtendedInfo(); | ||
251 | + | ||
252 | + YangLeaf leafInfo2 = (YangLeaf) leafref.getReferredLeafOrLeafList(); | ||
253 | + assertThat(leafref.getReferredLeafOrLeafList(), is(leafInfo2)); | ||
254 | + assertThat(leafref.getResolvableStatus(), is(RESOLVED)); | ||
255 | + | ||
256 | + assertThat(leafref.getEffectiveDataType().getDataType(), | ||
257 | + is(YangDataTypes.STRING)); | ||
258 | + } | ||
259 | + | ||
260 | + /** | ||
261 | + * Checks inter file resolution when leafref from grouping with prefix is changed properly during cloning with | ||
262 | + * multi reference. | ||
263 | + */ | ||
264 | + @Test | ||
265 | + public void processInterFileLeafrefFromGroupingWithPrefixIsClonedMultiReference() | ||
266 | + throws IOException, ParserException { | ||
267 | + | ||
268 | + String searchDir = "src/test/resources/leafreflinker/interfile/leafrefInGroupingWithPrefixAndManyReference"; | ||
269 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); | ||
270 | + utilManager.parseYangFileInfoSet(); | ||
271 | + utilManager.createYangNodeSet(); | ||
272 | + YangNode selfNode = null; | ||
273 | + YangNode refNode = null; | ||
274 | + | ||
275 | + // Create YANG node set | ||
276 | + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); | ||
277 | + | ||
278 | + // Add references to import list. | ||
279 | + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); | ||
280 | + | ||
281 | + // Carry out inter-file linking. | ||
282 | + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); | ||
283 | + | ||
284 | + Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator(); | ||
285 | + | ||
286 | + YangNode rootNode = yangNodeIterator.next(); | ||
287 | + | ||
288 | + if (rootNode.getName().equals("ietf-network")) { | ||
289 | + selfNode = rootNode; | ||
290 | + refNode = yangNodeIterator.next(); | ||
291 | + } else { | ||
292 | + refNode = rootNode; | ||
293 | + selfNode = yangNodeIterator.next(); | ||
294 | + } | ||
295 | + | ||
296 | + // Check whether the data model tree returned is of type module. | ||
297 | + assertThat(selfNode instanceof YangModule, is(true)); | ||
298 | + | ||
299 | + // Check whether the node type is set properly to module. | ||
300 | + assertThat(selfNode.getNodeType(), is(MODULE_NODE)); | ||
301 | + | ||
302 | + // Check whether the module name is set correctly. | ||
303 | + YangModule yangNode = (YangModule) selfNode; | ||
304 | + assertThat(yangNode.getName(), is("ietf-network")); | ||
305 | + | ||
306 | + // Check whether the module name is set correctly. | ||
307 | + YangModule yangNode1 = (YangModule) refNode; | ||
308 | + assertThat(yangNode1.getName(), is("ietf-te-topology")); | ||
309 | + | ||
310 | + YangContainer yangContainer = (YangContainer) yangNode1.getChild().getNextSibling(); | ||
311 | + ListIterator<YangLeaf> leafIterator; | ||
312 | + YangLeaf leafInfo; | ||
313 | + | ||
314 | + leafIterator = yangContainer.getListOfLeaf().listIterator(); | ||
315 | + leafInfo = leafIterator.next(); | ||
316 | + leafInfo = leafIterator.next(); | ||
317 | + | ||
318 | + assertThat(leafInfo.getName(), is("node-ref")); | ||
319 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("leafref")); | ||
320 | + assertThat(leafInfo.getDataType().getDataType(), is(LEAFREF)); | ||
321 | + | ||
322 | + YangLeafRef leafref = (YangLeafRef) leafInfo.getDataType().getDataTypeExtendedInfo(); | ||
323 | + | ||
324 | + YangLeaf leafInfo2 = (YangLeaf) leafref.getReferredLeafOrLeafList(); | ||
325 | + assertThat(leafref.getReferredLeafOrLeafList(), is(leafInfo2)); | ||
326 | + assertThat(leafref.getResolvableStatus(), is(RESOLVED)); | ||
327 | + | ||
328 | + assertThat(leafref.getEffectiveDataType().getDataType(), | ||
329 | + is(YangDataTypes.DERIVED)); | ||
330 | + | ||
331 | + leafInfo = leafIterator.next(); | ||
332 | + | ||
333 | + assertThat(leafInfo.getName(), is("network-ref")); | ||
334 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("leafref")); | ||
335 | + assertThat(leafInfo.getDataType().getDataType(), is(LEAFREF)); | ||
336 | + | ||
337 | + YangLeafRef leafref1 = (YangLeafRef) leafInfo.getDataType().getDataTypeExtendedInfo(); | ||
338 | + | ||
339 | + YangLeaf leafInfo4 = (YangLeaf) leafref1.getReferredLeafOrLeafList(); | ||
340 | + assertThat(leafref1.getReferredLeafOrLeafList(), is(leafInfo4)); | ||
341 | + assertThat(leafref1.getResolvableStatus(), is(RESOLVED)); | ||
342 | + | ||
343 | + assertThat(leafref1.getEffectiveDataType().getDataType(), | ||
344 | + is(YangDataTypes.DERIVED)); | ||
345 | + } | ||
346 | +} |
... | @@ -16,41 +16,37 @@ | ... | @@ -16,41 +16,37 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.plugin.manager; | 17 | package org.onosproject.yangutils.plugin.manager; |
18 | 18 | ||
19 | -import java.io.IOException; | ||
20 | -import java.util.Iterator; | ||
21 | -import java.util.ListIterator; | ||
22 | - | ||
23 | import org.apache.maven.plugin.MojoExecutionException; | 19 | import org.apache.maven.plugin.MojoExecutionException; |
24 | import org.junit.Rule; | 20 | import org.junit.Rule; |
25 | import org.junit.Test; | 21 | import org.junit.Test; |
26 | import org.junit.rules.ExpectedException; | 22 | import org.junit.rules.ExpectedException; |
27 | -import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes; | ||
28 | import org.onosproject.yangutils.datamodel.YangDerivedInfo; | 23 | import org.onosproject.yangutils.datamodel.YangDerivedInfo; |
29 | import org.onosproject.yangutils.datamodel.YangGrouping; | 24 | import org.onosproject.yangutils.datamodel.YangGrouping; |
30 | import org.onosproject.yangutils.datamodel.YangLeaf; | 25 | import org.onosproject.yangutils.datamodel.YangLeaf; |
31 | -import org.onosproject.yangutils.datamodel.YangLeafRef; | ||
32 | -import org.onosproject.yangutils.datamodel.YangList; | ||
33 | import org.onosproject.yangutils.datamodel.YangModule; | 26 | import org.onosproject.yangutils.datamodel.YangModule; |
34 | import org.onosproject.yangutils.datamodel.YangNode; | 27 | import org.onosproject.yangutils.datamodel.YangNode; |
35 | import org.onosproject.yangutils.datamodel.YangNodeType; | 28 | import org.onosproject.yangutils.datamodel.YangNodeType; |
36 | import org.onosproject.yangutils.datamodel.YangTypeDef; | 29 | import org.onosproject.yangutils.datamodel.YangTypeDef; |
37 | import org.onosproject.yangutils.datamodel.YangUses; | 30 | import org.onosproject.yangutils.datamodel.YangUses; |
38 | import org.onosproject.yangutils.datamodel.utils.ResolvableStatus; | 31 | import org.onosproject.yangutils.datamodel.utils.ResolvableStatus; |
39 | -import org.onosproject.yangutils.linker.exceptions.LinkerException; | 32 | +import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes; |
40 | import org.onosproject.yangutils.linker.impl.YangLinkerManager; | 33 | import org.onosproject.yangutils.linker.impl.YangLinkerManager; |
41 | import org.onosproject.yangutils.parser.exceptions.ParserException; | 34 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
42 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; | 35 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; |
43 | import org.onosproject.yangutils.utils.io.impl.YangFileScanner; | 36 | import org.onosproject.yangutils.utils.io.impl.YangFileScanner; |
44 | import org.onosproject.yangutils.utils.io.impl.YangPluginConfig; | 37 | import org.onosproject.yangutils.utils.io.impl.YangPluginConfig; |
45 | 38 | ||
39 | +import java.io.IOException; | ||
40 | +import java.util.Iterator; | ||
41 | +import java.util.ListIterator; | ||
42 | + | ||
46 | import static org.hamcrest.CoreMatchers.nullValue; | 43 | import static org.hamcrest.CoreMatchers.nullValue; |
47 | import static org.hamcrest.MatcherAssert.assertThat; | 44 | import static org.hamcrest.MatcherAssert.assertThat; |
48 | import static org.hamcrest.core.Is.is; | 45 | import static org.hamcrest.core.Is.is; |
49 | -import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.STRING; | ||
50 | -import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DERIVED; | ||
51 | -import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.LEAFREF; | ||
52 | import static org.onosproject.yangutils.datamodel.YangNodeType.MODULE_NODE; | 46 | import static org.onosproject.yangutils.datamodel.YangNodeType.MODULE_NODE; |
53 | import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.RESOLVED; | 47 | import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.RESOLVED; |
48 | +import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DERIVED; | ||
49 | +import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.STRING; | ||
54 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory; | 50 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory; |
55 | 51 | ||
56 | /** | 52 | /** |
... | @@ -737,255 +733,6 @@ public class InterFileLinkingTest { | ... | @@ -737,255 +733,6 @@ public class InterFileLinkingTest { |
737 | } | 733 | } |
738 | 734 | ||
739 | /** | 735 | /** |
740 | - * Checks inter file leafref linking. | ||
741 | - */ | ||
742 | - @Test | ||
743 | - public void processInterFileLeafrefLinking() | ||
744 | - throws IOException, ParserException, MojoExecutionException { | ||
745 | - | ||
746 | - String searchDir = "src/test/resources/interfileleafref"; | ||
747 | - utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); | ||
748 | - utilManager.parseYangFileInfoSet(); | ||
749 | - utilManager.createYangNodeSet(); | ||
750 | - YangNode refNode = null; | ||
751 | - YangNode selfNode = null; | ||
752 | - | ||
753 | - // Create YANG node set | ||
754 | - yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); | ||
755 | - | ||
756 | - // Add references to import list. | ||
757 | - yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); | ||
758 | - | ||
759 | - // Carry out inter-file linking. | ||
760 | - yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); | ||
761 | - | ||
762 | - Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator(); | ||
763 | - | ||
764 | - YangNode rootNode = yangNodeIterator.next(); | ||
765 | - | ||
766 | - if (rootNode.getName().equals("module1")) { | ||
767 | - selfNode = rootNode; | ||
768 | - refNode = yangNodeIterator.next(); | ||
769 | - } else { | ||
770 | - refNode = rootNode; | ||
771 | - selfNode = yangNodeIterator.next(); | ||
772 | - } | ||
773 | - | ||
774 | - // Check whether the data model tree returned is of type module. | ||
775 | - assertThat(selfNode instanceof YangModule, is(true)); | ||
776 | - | ||
777 | - // Check whether the node type is set properly to module. | ||
778 | - assertThat(selfNode.getNodeType(), is(MODULE_NODE)); | ||
779 | - | ||
780 | - // Check whether the module name is set correctly. | ||
781 | - YangModule yangNode = (YangModule) selfNode; | ||
782 | - assertThat(yangNode.getName(), is("module1")); | ||
783 | - | ||
784 | - ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); | ||
785 | - YangLeaf leafInfo = leafIterator.next(); | ||
786 | - | ||
787 | - assertThat(leafInfo.getName(), is("invalid-interval")); | ||
788 | - assertThat(leafInfo.getDataType().getDataTypeName(), is("leafref")); | ||
789 | - assertThat(leafInfo.getDataType().getDataType(), is(LEAFREF)); | ||
790 | - | ||
791 | - // Check whether the data model tree returned is of type module. | ||
792 | - assertThat(refNode instanceof YangModule, is(true)); | ||
793 | - | ||
794 | - // Check whether the node type is set properly to module. | ||
795 | - assertThat(refNode.getNodeType(), is(MODULE_NODE)); | ||
796 | - | ||
797 | - // Check whether the module name is set correctly. | ||
798 | - YangModule yangNode1 = (YangModule) refNode; | ||
799 | - assertThat(yangNode1.getName(), is("module2")); | ||
800 | - YangLeaf leafInfo1 = yangNode1.getListOfLeaf().listIterator().next(); | ||
801 | - | ||
802 | - YangLeafRef leafref = (YangLeafRef) leafInfo.getDataType().getDataTypeExtendedInfo(); | ||
803 | - | ||
804 | - assertThat(leafref.getReferredLeafOrLeafList(), is(leafInfo1)); | ||
805 | - assertThat(leafref.getResolvableStatus(), is(RESOLVED)); | ||
806 | - | ||
807 | - assertThat(leafref.getEffectiveDataType().getDataType(), | ||
808 | - is(YangDataTypes.STRING)); | ||
809 | - } | ||
810 | - | ||
811 | - /** | ||
812 | - * Checks error scenerio where the node is invalid. | ||
813 | - */ | ||
814 | - @Test | ||
815 | - public void processSelfResolutionWhenLeafrefInModuleReferToInvalidNode() | ||
816 | - throws IOException, ParserException { | ||
817 | - | ||
818 | - thrown.expect(LinkerException.class); | ||
819 | - thrown.expectMessage( | ||
820 | - "YANG file error: Unable to find base leaf/leaf-list for given leafref"); | ||
821 | - String searchDir = "src/test/resources/interFileInvalidNode"; | ||
822 | - utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); | ||
823 | - utilManager.parseYangFileInfoSet(); | ||
824 | - utilManager.createYangNodeSet(); | ||
825 | - | ||
826 | - YangNode selfNode = null; | ||
827 | - | ||
828 | - // Create YANG node set | ||
829 | - yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); | ||
830 | - | ||
831 | - // Add references to import list. | ||
832 | - yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); | ||
833 | - | ||
834 | - // Carry out inter-file linking. | ||
835 | - yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); | ||
836 | - } | ||
837 | - | ||
838 | - /** | ||
839 | - * Checks the error scenerio when there is no referref leaf/leaf-list in any file. | ||
840 | - */ | ||
841 | - @Test | ||
842 | - public void processSelfResolutionWhenLeafrefDoesNotReferToLeafOrLeafList() | ||
843 | - throws IOException, ParserException { | ||
844 | - | ||
845 | - thrown.expect(LinkerException.class); | ||
846 | - thrown.expectMessage( | ||
847 | - "YANG file error: Unable to find base leaf/leaf-list for given leafref networks"); | ||
848 | - String searchDir = "src/test/resources/interfileleafrefwithinvaliddestinationnode"; | ||
849 | - utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); | ||
850 | - utilManager.parseYangFileInfoSet(); | ||
851 | - utilManager.createYangNodeSet(); | ||
852 | - YangNode selfNode = null; | ||
853 | - | ||
854 | - // Create YANG node set | ||
855 | - yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); | ||
856 | - | ||
857 | - // Add references to import list. | ||
858 | - yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); | ||
859 | - | ||
860 | - // Carry out inter-file linking. | ||
861 | - yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); | ||
862 | - } | ||
863 | - | ||
864 | - /** | ||
865 | - * Checks inter file resolution when leafref from grouping refers to other file. | ||
866 | - */ | ||
867 | - @Test | ||
868 | - public void processInterFileLeafrefFromGroupingRefersToOtherFile() | ||
869 | - throws IOException, ParserException { | ||
870 | - | ||
871 | - String searchDir = "src/test/resources/interfileleafreffromgroupingreferstootherfile"; | ||
872 | - utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); | ||
873 | - utilManager.parseYangFileInfoSet(); | ||
874 | - utilManager.createYangNodeSet(); | ||
875 | - YangNode selfNode = null; | ||
876 | - YangNode refNode = null; | ||
877 | - | ||
878 | - // Create YANG node set | ||
879 | - yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); | ||
880 | - | ||
881 | - // Add references to import list. | ||
882 | - yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); | ||
883 | - | ||
884 | - // Carry out inter-file linking. | ||
885 | - yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); | ||
886 | - | ||
887 | - Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator(); | ||
888 | - | ||
889 | - YangNode rootNode = yangNodeIterator.next(); | ||
890 | - | ||
891 | - if (rootNode.getName().equals("module1")) { | ||
892 | - selfNode = rootNode; | ||
893 | - refNode = yangNodeIterator.next(); | ||
894 | - } else { | ||
895 | - refNode = rootNode; | ||
896 | - selfNode = yangNodeIterator.next(); | ||
897 | - } | ||
898 | - | ||
899 | - // Check whether the data model tree returned is of type module. | ||
900 | - assertThat(selfNode instanceof YangModule, is(true)); | ||
901 | - | ||
902 | - // Check whether the node type is set properly to module. | ||
903 | - assertThat(selfNode.getNodeType(), is(MODULE_NODE)); | ||
904 | - | ||
905 | - // Check whether the module name is set correctly. | ||
906 | - YangModule yangNode = (YangModule) selfNode; | ||
907 | - assertThat(yangNode.getName(), is("module1")); | ||
908 | - | ||
909 | - YangList list = (YangList) yangNode.getChild().getChild(); | ||
910 | - ListIterator<YangLeaf> leafIterator = list.getListOfLeaf().listIterator(); | ||
911 | - YangLeaf leafInfo = leafIterator.next(); | ||
912 | - | ||
913 | - assertThat(leafInfo.getName(), is("link-tp")); | ||
914 | - assertThat(leafInfo.getDataType().getDataTypeName(), is("leafref")); | ||
915 | - assertThat(leafInfo.getDataType().getDataType(), is(LEAFREF)); | ||
916 | - | ||
917 | - YangLeafRef leafref = (YangLeafRef) leafInfo.getDataType().getDataTypeExtendedInfo(); | ||
918 | - | ||
919 | - YangLeaf leafInfo2 = (YangLeaf) leafref.getReferredLeafOrLeafList(); | ||
920 | - assertThat(leafref.getReferredLeafOrLeafList(), is(leafInfo2)); | ||
921 | - assertThat(leafref.getResolvableStatus(), is(RESOLVED)); | ||
922 | - | ||
923 | - assertThat(leafref.getEffectiveDataType().getDataType(), | ||
924 | - is(YangDataTypes.STRING)); | ||
925 | - } | ||
926 | - | ||
927 | - /** | ||
928 | - * Checks inter file resolution when leafref refers to multiple leafrefs through many files. | ||
929 | - */ | ||
930 | - @Test | ||
931 | - public void processInterFileLeafrefRefersToMultipleLeafrefInMultipleFiles() | ||
932 | - throws IOException, ParserException { | ||
933 | - | ||
934 | - String searchDir = "src/test/resources/interfileleafrefreferstomultipleleafrefinmultiplefiles"; | ||
935 | - utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); | ||
936 | - utilManager.parseYangFileInfoSet(); | ||
937 | - utilManager.createYangNodeSet(); | ||
938 | - YangNode refNode1 = null; | ||
939 | - YangNode refNode2 = null; | ||
940 | - YangNode selfNode = null; | ||
941 | - | ||
942 | - // Create YANG node set | ||
943 | - yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); | ||
944 | - | ||
945 | - // Add references to import list. | ||
946 | - yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); | ||
947 | - | ||
948 | - // Carry out inter-file linking. | ||
949 | - yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); | ||
950 | - | ||
951 | - for (YangNode rootNode : utilManager.getYangNodeSet()) { | ||
952 | - if (rootNode.getName().equals("ietf-network-topology")) { | ||
953 | - selfNode = rootNode; | ||
954 | - } else if (rootNode.getName().equals("ietf-network")) { | ||
955 | - refNode1 = rootNode; | ||
956 | - } else { | ||
957 | - refNode2 = rootNode; | ||
958 | - } | ||
959 | - } | ||
960 | - // Check whether the data model tree returned is of type module. | ||
961 | - assertThat(selfNode instanceof YangModule, is(true)); | ||
962 | - | ||
963 | - // Check whether the node type is set properly to module. | ||
964 | - assertThat(selfNode.getNodeType(), is(MODULE_NODE)); | ||
965 | - | ||
966 | - // Check whether the module name is set correctly. | ||
967 | - YangModule yangNode = (YangModule) selfNode; | ||
968 | - assertThat(yangNode.getName(), is("ietf-network-topology")); | ||
969 | - | ||
970 | - YangList list = (YangList) yangNode.getChild().getChild(); | ||
971 | - ListIterator<YangLeaf> leafIterator = list.getListOfLeaf().listIterator(); | ||
972 | - YangLeaf leafInfo = leafIterator.next(); | ||
973 | - | ||
974 | - assertThat(leafInfo.getName(), is("link-tp")); | ||
975 | - assertThat(leafInfo.getDataType().getDataTypeName(), is("leafref")); | ||
976 | - assertThat(leafInfo.getDataType().getDataType(), is(LEAFREF)); | ||
977 | - | ||
978 | - YangLeafRef leafref = (YangLeafRef) leafInfo.getDataType().getDataTypeExtendedInfo(); | ||
979 | - | ||
980 | - YangLeaf leafInfo2 = (YangLeaf) leafref.getReferredLeafOrLeafList(); | ||
981 | - assertThat(leafref.getReferredLeafOrLeafList(), is(leafInfo2)); | ||
982 | - assertThat(leafref.getResolvableStatus(), is(RESOLVED)); | ||
983 | - | ||
984 | - assertThat(leafref.getEffectiveDataType().getDataType(), | ||
985 | - is(YangDataTypes.STRING)); | ||
986 | - } | ||
987 | - | ||
988 | - /** | ||
989 | * Checks priority of the file. | 736 | * Checks priority of the file. |
990 | */ | 737 | */ |
991 | @Test | 738 | @Test | ... | ... |
... | @@ -16,17 +16,11 @@ | ... | @@ -16,17 +16,11 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.plugin.manager; | 17 | package org.onosproject.yangutils.plugin.manager; |
18 | 18 | ||
19 | -import java.io.IOException; | ||
20 | -import java.util.List; | ||
21 | -import java.util.ListIterator; | ||
22 | - | ||
23 | import org.junit.Test; | 19 | import org.junit.Test; |
24 | import org.onosproject.yangutils.datamodel.YangContainer; | 20 | import org.onosproject.yangutils.datamodel.YangContainer; |
25 | -import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes; | ||
26 | import org.onosproject.yangutils.datamodel.YangFeature; | 21 | import org.onosproject.yangutils.datamodel.YangFeature; |
27 | import org.onosproject.yangutils.datamodel.YangIfFeature; | 22 | import org.onosproject.yangutils.datamodel.YangIfFeature; |
28 | import org.onosproject.yangutils.datamodel.YangLeaf; | 23 | import org.onosproject.yangutils.datamodel.YangLeaf; |
29 | -import org.onosproject.yangutils.datamodel.YangLeafRef; | ||
30 | import org.onosproject.yangutils.datamodel.YangModule; | 24 | import org.onosproject.yangutils.datamodel.YangModule; |
31 | import org.onosproject.yangutils.datamodel.YangNode; | 25 | import org.onosproject.yangutils.datamodel.YangNode; |
32 | import org.onosproject.yangutils.datamodel.YangNodeType; | 26 | import org.onosproject.yangutils.datamodel.YangNodeType; |
... | @@ -35,6 +29,9 @@ import org.onosproject.yangutils.datamodel.utils.ResolvableStatus; | ... | @@ -35,6 +29,9 @@ import org.onosproject.yangutils.datamodel.utils.ResolvableStatus; |
35 | import org.onosproject.yangutils.parser.exceptions.ParserException; | 29 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
36 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; | 30 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; |
37 | 31 | ||
32 | +import java.io.IOException; | ||
33 | +import java.util.List; | ||
34 | + | ||
38 | import static org.hamcrest.MatcherAssert.assertThat; | 35 | import static org.hamcrest.MatcherAssert.assertThat; |
39 | import static org.hamcrest.core.Is.is; | 36 | import static org.hamcrest.core.Is.is; |
40 | 37 | ||
... | @@ -221,111 +218,4 @@ public class IntraFileIfFeatureLinkingTest { | ... | @@ -221,111 +218,4 @@ public class IntraFileIfFeatureLinkingTest { |
221 | assertThat(ifFeature.getName().getName(), is("local-storage")); | 218 | assertThat(ifFeature.getName().getName(), is("local-storage")); |
222 | assertThat(ifFeature.getResolvableStatus(), is(ResolvableStatus.RESOLVED)); | 219 | assertThat(ifFeature.getResolvableStatus(), is(ResolvableStatus.RESOLVED)); |
223 | } | 220 | } |
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 | - } | ||
331 | } | 221 | } | ... | ... |
... | @@ -16,17 +16,15 @@ | ... | @@ -16,17 +16,15 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.plugin.manager; | 17 | package org.onosproject.yangutils.plugin.manager; |
18 | 18 | ||
19 | -import java.io.IOException; | 19 | +import org.junit.Ignore; |
20 | -import java.util.Iterator; | ||
21 | -import java.util.List; | ||
22 | -import java.util.ListIterator; | ||
23 | - | ||
24 | import org.junit.Rule; | 20 | import org.junit.Rule; |
25 | import org.junit.Test; | 21 | import org.junit.Test; |
26 | import org.junit.rules.ExpectedException; | 22 | import org.junit.rules.ExpectedException; |
27 | import org.onosproject.yangutils.datamodel.YangAtomicPath; | 23 | import org.onosproject.yangutils.datamodel.YangAtomicPath; |
24 | +import org.onosproject.yangutils.datamodel.YangAugment; | ||
28 | import org.onosproject.yangutils.datamodel.YangContainer; | 25 | import org.onosproject.yangutils.datamodel.YangContainer; |
29 | -import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes; | 26 | +import org.onosproject.yangutils.datamodel.YangFeature; |
27 | +import org.onosproject.yangutils.datamodel.YangIfFeature; | ||
30 | import org.onosproject.yangutils.datamodel.YangInput; | 28 | import org.onosproject.yangutils.datamodel.YangInput; |
31 | import org.onosproject.yangutils.datamodel.YangLeaf; | 29 | import org.onosproject.yangutils.datamodel.YangLeaf; |
32 | import org.onosproject.yangutils.datamodel.YangLeafList; | 30 | import org.onosproject.yangutils.datamodel.YangLeafList; |
... | @@ -40,13 +38,24 @@ import org.onosproject.yangutils.datamodel.YangPathOperator; | ... | @@ -40,13 +38,24 @@ import org.onosproject.yangutils.datamodel.YangPathOperator; |
40 | import org.onosproject.yangutils.datamodel.YangPathPredicate; | 38 | import org.onosproject.yangutils.datamodel.YangPathPredicate; |
41 | import org.onosproject.yangutils.datamodel.YangRelativePath; | 39 | import org.onosproject.yangutils.datamodel.YangRelativePath; |
42 | import org.onosproject.yangutils.datamodel.utils.ResolvableStatus; | 40 | import org.onosproject.yangutils.datamodel.utils.ResolvableStatus; |
41 | +import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes; | ||
43 | import org.onosproject.yangutils.linker.exceptions.LinkerException; | 42 | import org.onosproject.yangutils.linker.exceptions.LinkerException; |
43 | +import org.onosproject.yangutils.linker.impl.YangLinkerManager; | ||
44 | import org.onosproject.yangutils.parser.exceptions.ParserException; | 44 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
45 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; | 45 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; |
46 | +import org.onosproject.yangutils.utils.io.impl.YangFileScanner; | ||
47 | + | ||
48 | +import java.io.IOException; | ||
49 | +import java.util.Iterator; | ||
50 | +import java.util.List; | ||
51 | +import java.util.ListIterator; | ||
46 | 52 | ||
47 | import static org.hamcrest.MatcherAssert.assertThat; | 53 | import static org.hamcrest.MatcherAssert.assertThat; |
48 | import static org.hamcrest.core.Is.is; | 54 | import static org.hamcrest.core.Is.is; |
49 | import static org.hamcrest.core.IsNull.nullValue; | 55 | import static org.hamcrest.core.IsNull.nullValue; |
56 | +import static org.onosproject.yangutils.datamodel.YangNodeType.MODULE_NODE; | ||
57 | +import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.RESOLVED; | ||
58 | +import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.LEAFREF; | ||
50 | 59 | ||
51 | /** | 60 | /** |
52 | * Test cases for testing leafref intra file linking. | 61 | * Test cases for testing leafref intra file linking. |
... | @@ -56,6 +65,8 @@ public class IntraFileLeafrefLinkingTest { | ... | @@ -56,6 +65,8 @@ public class IntraFileLeafrefLinkingTest { |
56 | @Rule | 65 | @Rule |
57 | public ExpectedException thrown = ExpectedException.none(); | 66 | public ExpectedException thrown = ExpectedException.none(); |
58 | 67 | ||
68 | + private final YangUtilManager utilManager = new YangUtilManager(); | ||
69 | + private final YangLinkerManager yangLinkerManager = new YangLinkerManager(); | ||
59 | private final YangUtilsParserManager manager = new YangUtilsParserManager(); | 70 | private final YangUtilsParserManager manager = new YangUtilsParserManager(); |
60 | 71 | ||
61 | /** | 72 | /** |
... | @@ -65,17 +76,38 @@ public class IntraFileLeafrefLinkingTest { | ... | @@ -65,17 +76,38 @@ public class IntraFileLeafrefLinkingTest { |
65 | public void processSelfResolutionWhenLeafrefReferToContainerLeaf() | 76 | public void processSelfResolutionWhenLeafrefReferToContainerLeaf() |
66 | throws IOException, ParserException { | 77 | throws IOException, ParserException { |
67 | 78 | ||
68 | - YangNode node = manager.getDataModel("src/test/resources/SelfResolutionWhenLeafrefReferToContainerLeaf.yang"); | 79 | + String searchDir = "src/test/resources/leafreflinker/intrafile/simpleleafref"; |
80 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); | ||
81 | + utilManager.parseYangFileInfoSet(); | ||
82 | + utilManager.createYangNodeSet(); | ||
83 | + YangNode selfNode = null; | ||
84 | + | ||
85 | + // Create YANG node set | ||
86 | + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); | ||
87 | + | ||
88 | + // Add references to import list. | ||
89 | + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); | ||
90 | + | ||
91 | + // Carry out inter-file linking. | ||
92 | + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); | ||
93 | + | ||
94 | + Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator(); | ||
95 | + | ||
96 | + YangNode rootNode = yangNodeIterator.next(); | ||
97 | + | ||
98 | + if (rootNode.getName().equals("SelfResolutionWhenLeafrefReferToContainerLeaf")) { | ||
99 | + selfNode = rootNode; | ||
100 | + } | ||
69 | 101 | ||
70 | // Check whether the data model tree returned is of type module. | 102 | // Check whether the data model tree returned is of type module. |
71 | - assertThat((node instanceof YangModule), is(true)); | 103 | + assertThat((selfNode instanceof YangModule), is(true)); |
72 | 104 | ||
73 | // Check whether the node type is set properly to module. | 105 | // Check whether the node type is set properly to module. |
74 | - assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | 106 | + assertThat(selfNode.getNodeType(), is(YangNodeType.MODULE_NODE)); |
75 | 107 | ||
76 | // Check whether the module name is set correctly. | 108 | // Check whether the module name is set correctly. |
77 | - YangModule yangNode = (YangModule) node; | 109 | + YangModule yangNode = (YangModule) selfNode; |
78 | - assertThat(yangNode.getName(), is("ietf-network")); | 110 | + assertThat(yangNode.getName(), is("SelfResolutionWhenLeafrefReferToContainerLeaf")); |
79 | 111 | ||
80 | ListIterator<YangLeaf> leafIterator; | 112 | ListIterator<YangLeaf> leafIterator; |
81 | YangLeaf leafInfo; | 113 | YangLeaf leafInfo; |
... | @@ -105,18 +137,38 @@ public class IntraFileLeafrefLinkingTest { | ... | @@ -105,18 +137,38 @@ public class IntraFileLeafrefLinkingTest { |
105 | public void processSelfResolutionWhenLeafrefInModuleReferToLeafInInputOfRpc() | 137 | public void processSelfResolutionWhenLeafrefInModuleReferToLeafInInputOfRpc() |
106 | throws IOException, ParserException { | 138 | throws IOException, ParserException { |
107 | 139 | ||
108 | - YangNode node = manager | 140 | + String searchDir = "src/test/resources/leafreflinker/intrafile/leafrefwithrpc"; |
109 | - .getDataModel("src/test/resources/SelfResolutionWhenLeafrefInModuleReferToLeafInInputOfRpc.yang"); | 141 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
142 | + utilManager.parseYangFileInfoSet(); | ||
143 | + utilManager.createYangNodeSet(); | ||
144 | + YangNode selfNode = null; | ||
145 | + | ||
146 | + // Create YANG node set | ||
147 | + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); | ||
148 | + | ||
149 | + // Add references to import list. | ||
150 | + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); | ||
151 | + | ||
152 | + // Carry out inter-file linking. | ||
153 | + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); | ||
154 | + | ||
155 | + Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator(); | ||
156 | + | ||
157 | + YangNode rootNode = yangNodeIterator.next(); | ||
158 | + | ||
159 | + if (rootNode.getName().equals("SelfResolutionWhenLeafrefInModuleReferToLeafInInputOfRpc")) { | ||
160 | + selfNode = rootNode; | ||
161 | + } | ||
110 | 162 | ||
111 | // Check whether the data model tree returned is of type module. | 163 | // Check whether the data model tree returned is of type module. |
112 | - assertThat((node instanceof YangModule), is(true)); | 164 | + assertThat((selfNode instanceof YangModule), is(true)); |
113 | 165 | ||
114 | // Check whether the node type is set properly to module. | 166 | // Check whether the node type is set properly to module. |
115 | - assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | 167 | + assertThat(selfNode.getNodeType(), is(YangNodeType.MODULE_NODE)); |
116 | 168 | ||
117 | // Check whether the module name is set correctly. | 169 | // Check whether the module name is set correctly. |
118 | - YangModule yangNode = (YangModule) node; | 170 | + YangModule yangNode = (YangModule) selfNode; |
119 | - assertThat(yangNode.getName(), is("ietf-network")); | 171 | + assertThat(yangNode.getName(), is("SelfResolutionWhenLeafrefInModuleReferToLeafInInputOfRpc")); |
120 | 172 | ||
121 | ListIterator<YangLeaf> leafIterator; | 173 | ListIterator<YangLeaf> leafIterator; |
122 | YangLeaf leafInfo; | 174 | YangLeaf leafInfo; |
... | @@ -142,23 +194,44 @@ public class IntraFileLeafrefLinkingTest { | ... | @@ -142,23 +194,44 @@ public class IntraFileLeafrefLinkingTest { |
142 | /** | 194 | /** |
143 | * Checks self resolution when leafref under module refers to grouping rpc with input as name. | 195 | * 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. | 196 | * Rpc has input child also. So here the node search must be done by taking input node. |
197 | + * TODO: When path has RPC's input but grouping & typedef with the same name occurs. | ||
145 | */ | 198 | */ |
146 | - @Test | 199 | + @Ignore |
147 | public void processSelfResolutionWhenLeafrefInModuleReferToGroupingWithInputInRpc() | 200 | public void processSelfResolutionWhenLeafrefInModuleReferToGroupingWithInputInRpc() |
148 | throws IOException, ParserException { | 201 | throws IOException, ParserException { |
149 | 202 | ||
150 | - YangNode node = manager | 203 | + String searchDir = "src/test/resources/leafreflinker/intrafile/leafrefwithrpcandgrouping"; |
151 | - .getDataModel("src/test/resources/SelfResolutionWhenLeafrefInModuleReferToGroupingWithInputInRpc.yang"); | 204 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
205 | + utilManager.parseYangFileInfoSet(); | ||
206 | + utilManager.createYangNodeSet(); | ||
207 | + YangNode selfNode = null; | ||
208 | + | ||
209 | + // Create YANG node set | ||
210 | + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); | ||
211 | + | ||
212 | + // Add references to import list. | ||
213 | + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); | ||
214 | + | ||
215 | + // Carry out inter-file linking. | ||
216 | + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); | ||
217 | + | ||
218 | + Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator(); | ||
219 | + | ||
220 | + YangNode rootNode = yangNodeIterator.next(); | ||
221 | + | ||
222 | + if (rootNode.getName().equals("SelfResolutionWhenLeafrefInModuleReferToGroupingWithInputInRpc")) { | ||
223 | + selfNode = rootNode; | ||
224 | + } | ||
152 | 225 | ||
153 | // Check whether the data model tree returned is of type module. | 226 | // Check whether the data model tree returned is of type module. |
154 | - assertThat((node instanceof YangModule), is(true)); | 227 | + assertThat((selfNode instanceof YangModule), is(true)); |
155 | 228 | ||
156 | // Check whether the node type is set properly to module. | 229 | // Check whether the node type is set properly to module. |
157 | - assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | 230 | + assertThat(selfNode.getNodeType(), is(YangNodeType.MODULE_NODE)); |
158 | 231 | ||
159 | // Check whether the module name is set correctly. | 232 | // Check whether the module name is set correctly. |
160 | - YangModule yangNode = (YangModule) node; | 233 | + YangModule yangNode = (YangModule) selfNode; |
161 | - assertThat(yangNode.getName(), is("ietf-network")); | 234 | + assertThat(yangNode.getName(), is("SelfResolutionWhenLeafrefInModuleReferToGroupingWithInputInRpc")); |
162 | 235 | ||
163 | ListIterator<YangLeaf> leafIterator; | 236 | ListIterator<YangLeaf> leafIterator; |
164 | YangLeaf leafInfo; | 237 | YangLeaf leafInfo; |
... | @@ -191,9 +264,21 @@ public class IntraFileLeafrefLinkingTest { | ... | @@ -191,9 +264,21 @@ public class IntraFileLeafrefLinkingTest { |
191 | 264 | ||
192 | thrown.expect(LinkerException.class); | 265 | thrown.expect(LinkerException.class); |
193 | thrown.expectMessage( | 266 | thrown.expectMessage( |
194 | - "YANG file error: The target node of leafref is invalid."); | 267 | + "YANG file error: The target node, in the leafref path /networks/network-id, is invalid."); |
195 | - YangNode node = manager | 268 | + |
196 | - .getDataModel("src/test/resources/SelfResolutionWhenLeafrefInModuleReferToGroupingInModule.yang"); | 269 | + String searchDir = "src/test/resources/leafreflinker/intrafile/invalidscenerioforgrouping"; |
270 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); | ||
271 | + utilManager.parseYangFileInfoSet(); | ||
272 | + utilManager.createYangNodeSet(); | ||
273 | + | ||
274 | + // Create YANG node set | ||
275 | + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); | ||
276 | + | ||
277 | + // Add references to import list. | ||
278 | + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); | ||
279 | + | ||
280 | + // Carry out inter-file linking. | ||
281 | + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); | ||
197 | } | 282 | } |
198 | 283 | ||
199 | /** | 284 | /** |
... | @@ -212,39 +297,27 @@ public class IntraFileLeafrefLinkingTest { | ... | @@ -212,39 +297,27 @@ public class IntraFileLeafrefLinkingTest { |
212 | 297 | ||
213 | /** | 298 | /** |
214 | * Checks self resolution when leafref under module refers to invalid node. | 299 | * 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 | */ | 300 | */ |
217 | @Test | 301 | @Test |
218 | public void processSelfResolutionWhenLeafrefInModuleReferToInvalidNode() | 302 | public void processSelfResolutionWhenLeafrefInModuleReferToInvalidNode() |
219 | throws IOException, ParserException { | 303 | throws IOException, ParserException { |
220 | 304 | ||
221 | - YangNode node = manager | 305 | + thrown.expect(LinkerException.class); |
222 | - .getDataModel("src/test/resources/SelfResolutionWhenLeafrefInModuleReferToInvalidNode.yang"); | 306 | + thrown.expectMessage( |
223 | - // Check whether the data model tree returned is of type module. | 307 | + "YANG file error: Unable to find base leaf/leaf-list for given leafref path /define/network-id"); |
224 | - assertThat((node instanceof YangModule), is(true)); | 308 | + String searchDir = "src/test/resources/leafreflinker/intrafile/invalidsceneriowithinvalidnode"; |
225 | - | 309 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
226 | - // Check whether the node type is set properly to module. | 310 | + utilManager.parseYangFileInfoSet(); |
227 | - assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | 311 | + utilManager.createYangNodeSet(); |
228 | - | ||
229 | - // Check whether the module name is set correctly. | ||
230 | - YangModule yangNode = (YangModule) node; | ||
231 | - assertThat(yangNode.getName(), is("ietf-network")); | ||
232 | 312 | ||
233 | - ListIterator<YangLeaf> leafIterator; | 313 | + // Create YANG node set |
234 | - YangLeaf leafInfo; | 314 | + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); |
235 | 315 | ||
236 | - leafIterator = yangNode.getListOfLeaf().listIterator(); | 316 | + // Add references to import list. |
237 | - leafInfo = leafIterator.next(); | 317 | + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); |
238 | 318 | ||
239 | - // Check whether the information in the leaf is correct. | 319 | + // Carry out inter-file linking. |
240 | - assertThat(leafInfo.getName(), is("network-ref")); | 320 | + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); |
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 | } | 321 | } |
249 | 322 | ||
250 | /** | 323 | /** |
... | @@ -255,16 +328,37 @@ public class IntraFileLeafrefLinkingTest { | ... | @@ -255,16 +328,37 @@ public class IntraFileLeafrefLinkingTest { |
255 | public void processSelfResolutionWhenLeafrefIsInDeepTreeAndLeafIsInModuleWithReferredTypeUnion() | 328 | public void processSelfResolutionWhenLeafrefIsInDeepTreeAndLeafIsInModuleWithReferredTypeUnion() |
256 | throws IOException, ParserException { | 329 | throws IOException, ParserException { |
257 | 330 | ||
258 | - YangNode node = manager.getDataModel( | 331 | + String searchDir = "src/test/resources/leafreflinker/intrafile/leafreflinking"; |
259 | - "src/test/resources/SelfResolutionWhenLeafrefIsInDeepTreeAndLeafIsInModuleWithReferredTypeUnion.yang"); | 332 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
333 | + utilManager.parseYangFileInfoSet(); | ||
334 | + utilManager.createYangNodeSet(); | ||
335 | + YangNode selfNode = null; | ||
336 | + | ||
337 | + // Create YANG node set | ||
338 | + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); | ||
339 | + | ||
340 | + // Add references to import list. | ||
341 | + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); | ||
342 | + | ||
343 | + // Carry out inter-file linking. | ||
344 | + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); | ||
345 | + | ||
346 | + Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator(); | ||
347 | + | ||
348 | + YangNode rootNode = yangNodeIterator.next(); | ||
349 | + | ||
350 | + if (rootNode.getName().equals("Test")) { | ||
351 | + selfNode = rootNode; | ||
352 | + } | ||
353 | + | ||
260 | // Check whether the data model tree returned is of type module. | 354 | // Check whether the data model tree returned is of type module. |
261 | - assertThat((node instanceof YangModule), is(true)); | 355 | + assertThat((selfNode instanceof YangModule), is(true)); |
262 | 356 | ||
263 | // Check whether the node type is set properly to module. | 357 | // Check whether the node type is set properly to module. |
264 | - assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | 358 | + assertThat(selfNode.getNodeType(), is(YangNodeType.MODULE_NODE)); |
265 | 359 | ||
266 | // Check whether the module name is set correctly. | 360 | // Check whether the module name is set correctly. |
267 | - YangModule yangNode = (YangModule) node; | 361 | + YangModule yangNode = (YangModule) selfNode; |
268 | assertThat(yangNode.getName(), is("Test")); | 362 | assertThat(yangNode.getName(), is("Test")); |
269 | 363 | ||
270 | YangContainer containerParent = (YangContainer) yangNode.getChild().getChild().getChild(); | 364 | YangContainer containerParent = (YangContainer) yangNode.getChild().getChild().getChild(); |
... | @@ -296,17 +390,37 @@ public class IntraFileLeafrefLinkingTest { | ... | @@ -296,17 +390,37 @@ public class IntraFileLeafrefLinkingTest { |
296 | public void processSelfResolutionWhenLeafrefReferToContainerLeafList() | 390 | public void processSelfResolutionWhenLeafrefReferToContainerLeafList() |
297 | throws IOException, ParserException { | 391 | throws IOException, ParserException { |
298 | 392 | ||
299 | - YangNode node = manager | 393 | + String searchDir = "src/test/resources/leafreflinker/intrafile/leafrefreferingtoleaflist"; |
300 | - .getDataModel("src/test/resources/SelfResolutionWhenLeafrefReferToContainerLeafList.yang"); | 394 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
395 | + utilManager.parseYangFileInfoSet(); | ||
396 | + utilManager.createYangNodeSet(); | ||
397 | + YangNode selfNode = null; | ||
398 | + | ||
399 | + // Create YANG node set | ||
400 | + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); | ||
401 | + | ||
402 | + // Add references to import list. | ||
403 | + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); | ||
404 | + | ||
405 | + // Carry out inter-file linking. | ||
406 | + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); | ||
407 | + | ||
408 | + Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator(); | ||
409 | + | ||
410 | + YangNode rootNode = yangNodeIterator.next(); | ||
411 | + | ||
412 | + if (rootNode.getName().equals("ietf-network")) { | ||
413 | + selfNode = rootNode; | ||
414 | + } | ||
301 | 415 | ||
302 | // Check whether the data model tree returned is of type module. | 416 | // Check whether the data model tree returned is of type module. |
303 | - assertThat((node instanceof YangModule), is(true)); | 417 | + assertThat((selfNode instanceof YangModule), is(true)); |
304 | 418 | ||
305 | // Check whether the node type is set properly to module. | 419 | // Check whether the node type is set properly to module. |
306 | - assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | 420 | + assertThat(selfNode.getNodeType(), is(YangNodeType.MODULE_NODE)); |
307 | 421 | ||
308 | // Check whether the module name is set correctly. | 422 | // Check whether the module name is set correctly. |
309 | - YangModule yangNode = (YangModule) node; | 423 | + YangModule yangNode = (YangModule) selfNode; |
310 | assertThat(yangNode.getName(), is("ietf-network")); | 424 | assertThat(yangNode.getName(), is("ietf-network")); |
311 | 425 | ||
312 | ListIterator<YangLeafList> leafListIterator; | 426 | ListIterator<YangLeafList> leafListIterator; |
... | @@ -337,17 +451,34 @@ public class IntraFileLeafrefLinkingTest { | ... | @@ -337,17 +451,34 @@ public class IntraFileLeafrefLinkingTest { |
337 | public void processSelfResolutionWhenLeafrefInModuleReferToLeafListInInputOfRpc() | 451 | public void processSelfResolutionWhenLeafrefInModuleReferToLeafListInInputOfRpc() |
338 | throws IOException, ParserException { | 452 | throws IOException, ParserException { |
339 | 453 | ||
340 | - YangNode node = manager | 454 | + String searchDir = "src/test/resources/leafreflinker/intrafile/leafreftoinputinrpc"; |
341 | - .getDataModel("src/test/resources/SelfResolutionWhenLeafrefInModuleReferToLeafListInInputOfRpc.yang"); | 455 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
456 | + utilManager.parseYangFileInfoSet(); | ||
457 | + utilManager.createYangNodeSet(); | ||
458 | + YangNode selfNode = null; | ||
342 | 459 | ||
343 | - // Check whether the data model tree returned is of type module. | 460 | + // Create YANG node set |
344 | - assertThat((node instanceof YangModule), is(true)); | 461 | + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); |
462 | + | ||
463 | + // Add references to import list. | ||
464 | + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); | ||
465 | + | ||
466 | + // Carry out inter-file linking. | ||
467 | + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); | ||
468 | + | ||
469 | + Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator(); | ||
470 | + | ||
471 | + YangNode rootNode = yangNodeIterator.next(); | ||
472 | + | ||
473 | + if (rootNode.getName().equals("ietf-network")) { | ||
474 | + selfNode = rootNode; | ||
475 | + } | ||
345 | 476 | ||
346 | // Check whether the node type is set properly to module. | 477 | // Check whether the node type is set properly to module. |
347 | - assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | 478 | + assertThat(selfNode.getNodeType(), is(YangNodeType.MODULE_NODE)); |
348 | 479 | ||
349 | // Check whether the module name is set correctly. | 480 | // Check whether the module name is set correctly. |
350 | - YangModule yangNode = (YangModule) node; | 481 | + YangModule yangNode = (YangModule) selfNode; |
351 | assertThat(yangNode.getName(), is("ietf-network")); | 482 | assertThat(yangNode.getName(), is("ietf-network")); |
352 | 483 | ||
353 | ListIterator<YangLeafList> leafListIterator; | 484 | ListIterator<YangLeafList> leafListIterator; |
... | @@ -379,17 +510,35 @@ public class IntraFileLeafrefLinkingTest { | ... | @@ -379,17 +510,35 @@ public class IntraFileLeafrefLinkingTest { |
379 | public void processSelfResolutionWhenLeafrefIsInDeepTreeAndLeafListIsInModuleWithReferredTypeEnumeration() | 510 | public void processSelfResolutionWhenLeafrefIsInDeepTreeAndLeafListIsInModuleWithReferredTypeEnumeration() |
380 | throws IOException, ParserException { | 511 | throws IOException, ParserException { |
381 | 512 | ||
382 | - YangNode node = manager.getDataModel( | 513 | + String searchDir = "src/test/resources/leafreflinker/intrafile/leafrefwithrefleafderived"; |
383 | - "src/test/resources/" + | 514 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
384 | - "SelfResolutionWhenLeafrefIsInDeepTreeAndLeafListIsInModuleWithReferredTypeEnumeration.yang"); | 515 | + utilManager.parseYangFileInfoSet(); |
385 | - // Check whether the data model tree returned is of type module. | 516 | + utilManager.createYangNodeSet(); |
386 | - assertThat((node instanceof YangModule), is(true)); | 517 | + YangNode selfNode = null; |
518 | + | ||
519 | + // Create YANG node set | ||
520 | + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); | ||
521 | + | ||
522 | + // Add references to import list. | ||
523 | + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); | ||
524 | + | ||
525 | + // Carry out inter-file linking. | ||
526 | + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); | ||
527 | + | ||
528 | + Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator(); | ||
529 | + | ||
530 | + YangNode rootNode = yangNodeIterator.next(); | ||
531 | + | ||
532 | + if (rootNode.getName().equals("Test")) { | ||
533 | + selfNode = rootNode; | ||
534 | + } | ||
387 | 535 | ||
388 | // Check whether the node type is set properly to module. | 536 | // Check whether the node type is set properly to module. |
389 | - assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | 537 | + assertThat(selfNode.getNodeType(), is(YangNodeType.MODULE_NODE)); |
390 | 538 | ||
391 | // Check whether the module name is set correctly. | 539 | // Check whether the module name is set correctly. |
392 | - YangModule yangNode = (YangModule) node; | 540 | + YangModule yangNode = (YangModule) selfNode; |
541 | + | ||
393 | assertThat(yangNode.getName(), is("Test")); | 542 | assertThat(yangNode.getName(), is("Test")); |
394 | 543 | ||
395 | YangContainer containerParent = (YangContainer) yangNode.getChild().getChild().getChild(); | 544 | YangContainer containerParent = (YangContainer) yangNode.getChild().getChild().getChild(); |
... | @@ -421,34 +570,22 @@ public class IntraFileLeafrefLinkingTest { | ... | @@ -421,34 +570,22 @@ public class IntraFileLeafrefLinkingTest { |
421 | public void processSelfResolutionWhenLeafrefDoesNotReferToLeafOrLeafList() | 570 | public void processSelfResolutionWhenLeafrefDoesNotReferToLeafOrLeafList() |
422 | throws IOException, ParserException { | 571 | throws IOException, ParserException { |
423 | 572 | ||
424 | - YangNode node = manager | 573 | + thrown.expect(LinkerException.class); |
425 | - .getDataModel("src/test/resources/SelfResolutionWhenLeafrefDoesNotReferToLeafOrLeafList.yang"); | 574 | + thrown.expectMessage( |
426 | - | 575 | + "YANG file error: Unable to find base leaf/leaf-list for given leafref path /networks"); |
427 | - // Check whether the data model tree returned is of type module. | 576 | + String searchDir = "src/test/resources/leafreflinker/intrafile/invalidsceneriowithnorefleaf"; |
428 | - assertThat((node instanceof YangModule), is(true)); | 577 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
429 | - | 578 | + utilManager.parseYangFileInfoSet(); |
430 | - // Check whether the node type is set properly to module. | 579 | + utilManager.createYangNodeSet(); |
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 | 580 | ||
440 | - //YangGrouping grouping = (YangGrouping) yangNode.getChild().getNextSibling(); | 581 | + // Create YANG node set |
441 | - leafIterator = yangNode.getListOfLeaf().listIterator(); | 582 | + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); |
442 | - leafInfo = leafIterator.next(); | ||
443 | 583 | ||
444 | - // Check whether the information in the leaf is correct under grouping. | 584 | + // Add references to import list. |
445 | - assertThat(leafInfo.getName(), is("network-ref")); | 585 | + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); |
446 | - assertThat(leafInfo.getDataType().getDataTypeName(), is("leafref")); | ||
447 | - assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.LEAFREF)); | ||
448 | - YangLeafRef leafref = (YangLeafRef) (leafInfo.getDataType().getDataTypeExtendedInfo()); | ||
449 | 586 | ||
450 | - assertThat(leafref.getResolvableStatus(), | 587 | + // Carry out inter-file linking. |
451 | - is(ResolvableStatus.INTRA_FILE_RESOLVED)); | 588 | + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); |
452 | } | 589 | } |
453 | 590 | ||
454 | /** | 591 | /** |
... | @@ -457,18 +594,35 @@ public class IntraFileLeafrefLinkingTest { | ... | @@ -457,18 +594,35 @@ public class IntraFileLeafrefLinkingTest { |
457 | @Test | 594 | @Test |
458 | public void processSelfResolutionWhenLeafrefInTypedefReferToContainer() | 595 | public void processSelfResolutionWhenLeafrefInTypedefReferToContainer() |
459 | throws IOException, ParserException { | 596 | throws IOException, ParserException { |
597 | + String searchDir = "src/test/resources/leafreflinker/intrafile/leafrefintypedef"; | ||
598 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); | ||
599 | + utilManager.parseYangFileInfoSet(); | ||
600 | + utilManager.createYangNodeSet(); | ||
601 | + YangNode selfNode = null; | ||
602 | + // Create YANG node set | ||
603 | + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); | ||
460 | 604 | ||
461 | - YangNode node = manager | 605 | + // Add references to import list. |
462 | - .getDataModel("src/test/resources/SelfResolutionWhenLeafrefInTypedefReferToContainer.yang"); | 606 | + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); |
607 | + | ||
608 | + // Carry out inter-file linking. | ||
609 | + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); | ||
610 | + | ||
611 | + Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator(); | ||
463 | 612 | ||
613 | + YangNode rootNode = yangNodeIterator.next(); | ||
614 | + | ||
615 | + if (rootNode.getName().equals("ietf-network")) { | ||
616 | + selfNode = rootNode; | ||
617 | + } | ||
464 | // Check whether the data model tree returned is of type module. | 618 | // Check whether the data model tree returned is of type module. |
465 | - assertThat((node instanceof YangModule), is(true)); | 619 | + assertThat((selfNode instanceof YangModule), is(true)); |
466 | 620 | ||
467 | // Check whether the node type is set properly to module. | 621 | // Check whether the node type is set properly to module. |
468 | - assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | 622 | + assertThat(selfNode.getNodeType(), is(YangNodeType.MODULE_NODE)); |
469 | 623 | ||
470 | // Check whether the module name is set correctly. | 624 | // Check whether the module name is set correctly. |
471 | - YangModule yangNode = (YangModule) node; | 625 | + YangModule yangNode = (YangModule) selfNode; |
472 | assertThat(yangNode.getName(), is("ietf-network")); | 626 | assertThat(yangNode.getName(), is("ietf-network")); |
473 | 627 | ||
474 | YangContainer yangContainer = (YangContainer) yangNode.getChild(); | 628 | YangContainer yangContainer = (YangContainer) yangNode.getChild(); |
... | @@ -499,17 +653,35 @@ public class IntraFileLeafrefLinkingTest { | ... | @@ -499,17 +653,35 @@ public class IntraFileLeafrefLinkingTest { |
499 | public void processSelfResolutionWhenLeafrefInTypedefModuleReferToLeafListInInputOfRpc() | 653 | public void processSelfResolutionWhenLeafrefInTypedefModuleReferToLeafListInInputOfRpc() |
500 | throws IOException, ParserException { | 654 | throws IOException, ParserException { |
501 | 655 | ||
502 | - YangNode node = manager.getDataModel( | 656 | + String searchDir = "src/test/resources/leafreflinker/intrafile/leafreftorpcinputleaflist"; |
503 | - "src/test/resources/SelfResolutionWhenLeafrefInTypedefModuleReferToLeafListInInputOfRpc.yang"); | 657 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
658 | + utilManager.parseYangFileInfoSet(); | ||
659 | + utilManager.createYangNodeSet(); | ||
660 | + YangNode selfNode = null; | ||
661 | + // Create YANG node set | ||
662 | + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); | ||
663 | + | ||
664 | + // Add references to import list. | ||
665 | + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); | ||
666 | + | ||
667 | + // Carry out inter-file linking. | ||
668 | + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); | ||
504 | 669 | ||
670 | + Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator(); | ||
671 | + | ||
672 | + YangNode rootNode = yangNodeIterator.next(); | ||
673 | + | ||
674 | + if (rootNode.getName().equals("ietf-network")) { | ||
675 | + selfNode = rootNode; | ||
676 | + } | ||
505 | // Check whether the data model tree returned is of type module. | 677 | // Check whether the data model tree returned is of type module. |
506 | - assertThat((node instanceof YangModule), is(true)); | 678 | + assertThat((selfNode instanceof YangModule), is(true)); |
507 | 679 | ||
508 | // Check whether the node type is set properly to module. | 680 | // Check whether the node type is set properly to module. |
509 | - assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | 681 | + assertThat(selfNode.getNodeType(), is(YangNodeType.MODULE_NODE)); |
510 | 682 | ||
511 | // Check whether the module name is set correctly. | 683 | // Check whether the module name is set correctly. |
512 | - YangModule yangNode = (YangModule) node; | 684 | + YangModule yangNode = (YangModule) selfNode; |
513 | assertThat(yangNode.getName(), is("ietf-network")); | 685 | assertThat(yangNode.getName(), is("ietf-network")); |
514 | 686 | ||
515 | YangInput yangInput = (YangInput) yangNode.getChild().getChild(); | 687 | YangInput yangInput = (YangInput) yangNode.getChild().getChild(); |
... | @@ -542,18 +714,35 @@ public class IntraFileLeafrefLinkingTest { | ... | @@ -542,18 +714,35 @@ public class IntraFileLeafrefLinkingTest { |
542 | public void processSelfResolutionWhenLeafrefInTypedefIsInDeepTreeAndLeafListIsInModuleWithReferredTypeEnumeration() | 714 | public void processSelfResolutionWhenLeafrefInTypedefIsInDeepTreeAndLeafListIsInModuleWithReferredTypeEnumeration() |
543 | throws IOException, ParserException { | 715 | throws IOException, ParserException { |
544 | 716 | ||
545 | - YangNode node = manager.getDataModel( | 717 | + String searchDir = "src/test/resources/leafreflinker/intrafile/leafreftoleafrefwithtypedef"; |
546 | - "src/test/resources/" + | 718 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
547 | - "SelfResolutionWhenLeafrefInTypedefIs" + | 719 | + utilManager.parseYangFileInfoSet(); |
548 | - "InDeepTreeAndLeafListIsInModuleWithReferredTypeEnumeration.yang"); | 720 | + utilManager.createYangNodeSet(); |
721 | + YangNode selfNode = null; | ||
722 | + // Create YANG node set | ||
723 | + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); | ||
724 | + | ||
725 | + // Add references to import list. | ||
726 | + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); | ||
727 | + | ||
728 | + // Carry out inter-file linking. | ||
729 | + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); | ||
730 | + | ||
731 | + Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator(); | ||
732 | + | ||
733 | + YangNode rootNode = yangNodeIterator.next(); | ||
734 | + | ||
735 | + if (rootNode.getName().equals("Test")) { | ||
736 | + selfNode = rootNode; | ||
737 | + } | ||
549 | // Check whether the data model tree returned is of type module. | 738 | // Check whether the data model tree returned is of type module. |
550 | - assertThat((node instanceof YangModule), is(true)); | 739 | + assertThat((selfNode instanceof YangModule), is(true)); |
551 | 740 | ||
552 | // Check whether the node type is set properly to module. | 741 | // Check whether the node type is set properly to module. |
553 | - assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | 742 | + assertThat(selfNode.getNodeType(), is(YangNodeType.MODULE_NODE)); |
554 | 743 | ||
555 | // Check whether the module name is set correctly. | 744 | // Check whether the module name is set correctly. |
556 | - YangModule yangNode = (YangModule) node; | 745 | + YangModule yangNode = (YangModule) selfNode; |
557 | assertThat(yangNode.getName(), is("Test")); | 746 | assertThat(yangNode.getName(), is("Test")); |
558 | 747 | ||
559 | YangContainer yangContainer = (YangContainer) yangNode.getChild().getChild().getChild().getNextSibling(); | 748 | YangContainer yangContainer = (YangContainer) yangNode.getChild().getChild().getChild().getNextSibling(); |
... | @@ -586,15 +775,35 @@ public class IntraFileLeafrefLinkingTest { | ... | @@ -586,15 +775,35 @@ public class IntraFileLeafrefLinkingTest { |
586 | public void processSelfResolutionWhenLeafrefRefersAnotherLeafref() | 775 | public void processSelfResolutionWhenLeafrefRefersAnotherLeafref() |
587 | throws IOException, ParserException { | 776 | throws IOException, ParserException { |
588 | 777 | ||
589 | - YangNode node = manager.getDataModel("src/test/resources/SelfResolutionWhenLeafrefReferToAnotherLeafref.yang"); | 778 | + String searchDir = "src/test/resources/leafreflinker/intrafile/leafreftoleafref"; |
779 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); | ||
780 | + utilManager.parseYangFileInfoSet(); | ||
781 | + utilManager.createYangNodeSet(); | ||
782 | + YangNode selfNode = null; | ||
783 | + // Create YANG node set | ||
784 | + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); | ||
785 | + | ||
786 | + // Add references to import list. | ||
787 | + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); | ||
788 | + | ||
789 | + // Carry out inter-file linking. | ||
790 | + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); | ||
791 | + | ||
792 | + Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator(); | ||
793 | + | ||
794 | + YangNode rootNode = yangNodeIterator.next(); | ||
795 | + | ||
796 | + if (rootNode.getName().equals("ietf-network")) { | ||
797 | + selfNode = rootNode; | ||
798 | + } | ||
590 | // Check whether the data model tree returned is of type module. | 799 | // Check whether the data model tree returned is of type module. |
591 | - assertThat((node instanceof YangModule), is(true)); | 800 | + assertThat((selfNode instanceof YangModule), is(true)); |
592 | 801 | ||
593 | // Check whether the node type is set properly to module. | 802 | // Check whether the node type is set properly to module. |
594 | - assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | 803 | + assertThat(selfNode.getNodeType(), is(YangNodeType.MODULE_NODE)); |
595 | 804 | ||
596 | // Check whether the module name is set correctly. | 805 | // Check whether the module name is set correctly. |
597 | - YangModule yangNode = (YangModule) node; | 806 | + YangModule yangNode = (YangModule) selfNode; |
598 | assertThat(yangNode.getName(), is("ietf-network")); | 807 | assertThat(yangNode.getName(), is("ietf-network")); |
599 | 808 | ||
600 | ListIterator<YangLeaf> leafIterator; | 809 | ListIterator<YangLeaf> leafIterator; |
... | @@ -624,15 +833,35 @@ public class IntraFileLeafrefLinkingTest { | ... | @@ -624,15 +833,35 @@ public class IntraFileLeafrefLinkingTest { |
624 | public void processSelfResolutionWhenLeafrefReferToMultipleLeafref() | 833 | public void processSelfResolutionWhenLeafrefReferToMultipleLeafref() |
625 | throws IOException, ParserException { | 834 | throws IOException, ParserException { |
626 | 835 | ||
627 | - YangNode node = manager.getDataModel("src/test/resources/SelfResolutionWhenLeafrefReferToMultipleLeafref.yang"); | 836 | + String searchDir = "src/test/resources/leafreflinker/intrafile/leafreftomultileafref"; |
837 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); | ||
838 | + utilManager.parseYangFileInfoSet(); | ||
839 | + utilManager.createYangNodeSet(); | ||
840 | + YangNode selfNode = null; | ||
841 | + // Create YANG node set | ||
842 | + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); | ||
843 | + | ||
844 | + // Add references to import list. | ||
845 | + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); | ||
846 | + | ||
847 | + // Carry out inter-file linking. | ||
848 | + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); | ||
849 | + | ||
850 | + Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator(); | ||
851 | + | ||
852 | + YangNode rootNode = yangNodeIterator.next(); | ||
853 | + | ||
854 | + if (rootNode.getName().equals("Test")) { | ||
855 | + selfNode = rootNode; | ||
856 | + } | ||
628 | // Check whether the data model tree returned is of type module. | 857 | // Check whether the data model tree returned is of type module. |
629 | - assertThat((node instanceof YangModule), is(true)); | 858 | + assertThat((selfNode instanceof YangModule), is(true)); |
630 | 859 | ||
631 | // Check whether the node type is set properly to module. | 860 | // Check whether the node type is set properly to module. |
632 | - assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | 861 | + assertThat(selfNode.getNodeType(), is(YangNodeType.MODULE_NODE)); |
633 | 862 | ||
634 | // Check whether the module name is set correctly. | 863 | // Check whether the module name is set correctly. |
635 | - YangModule yangNode = (YangModule) node; | 864 | + YangModule yangNode = (YangModule) selfNode; |
636 | assertThat(yangNode.getName(), is("Test")); | 865 | assertThat(yangNode.getName(), is("Test")); |
637 | 866 | ||
638 | YangContainer containerInModule = (YangContainer) yangNode.getChild().getNextSibling(); | 867 | YangContainer containerInModule = (YangContainer) yangNode.getChild().getNextSibling(); |
... | @@ -665,16 +894,35 @@ public class IntraFileLeafrefLinkingTest { | ... | @@ -665,16 +894,35 @@ public class IntraFileLeafrefLinkingTest { |
665 | public void processSelfResolutionWhenLeafrefRefersAnotherDerivedType() | 894 | public void processSelfResolutionWhenLeafrefRefersAnotherDerivedType() |
666 | throws IOException, ParserException { | 895 | throws IOException, ParserException { |
667 | 896 | ||
668 | - YangNode node = manager | 897 | + String searchDir = "src/test/resources/leafreflinker/intrafile/leafreftoderivedtype"; |
669 | - .getDataModel("src/test/resources/SelfResolutionWhenLeafrefReferToAnotherDerivedType.yang"); | 898 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
899 | + utilManager.parseYangFileInfoSet(); | ||
900 | + utilManager.createYangNodeSet(); | ||
901 | + YangNode selfNode = null; | ||
902 | + // Create YANG node set | ||
903 | + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); | ||
904 | + | ||
905 | + // Add references to import list. | ||
906 | + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); | ||
907 | + | ||
908 | + // Carry out inter-file linking. | ||
909 | + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); | ||
910 | + | ||
911 | + Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator(); | ||
912 | + | ||
913 | + YangNode rootNode = yangNodeIterator.next(); | ||
914 | + | ||
915 | + if (rootNode.getName().equals("ietf-network")) { | ||
916 | + selfNode = rootNode; | ||
917 | + } | ||
670 | // Check whether the data model tree returned is of type module. | 918 | // Check whether the data model tree returned is of type module. |
671 | - assertThat((node instanceof YangModule), is(true)); | 919 | + assertThat((selfNode instanceof YangModule), is(true)); |
672 | 920 | ||
673 | // Check whether the node type is set properly to module. | 921 | // Check whether the node type is set properly to module. |
674 | - assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | 922 | + assertThat(selfNode.getNodeType(), is(YangNodeType.MODULE_NODE)); |
675 | 923 | ||
676 | // Check whether the module name is set correctly. | 924 | // Check whether the module name is set correctly. |
677 | - YangModule yangNode = (YangModule) node; | 925 | + YangModule yangNode = (YangModule) selfNode; |
678 | assertThat(yangNode.getName(), is("ietf-network")); | 926 | assertThat(yangNode.getName(), is("ietf-network")); |
679 | 927 | ||
680 | ListIterator<YangLeaf> leafIterator; | 928 | ListIterator<YangLeaf> leafIterator; |
... | @@ -704,15 +952,35 @@ public class IntraFileLeafrefLinkingTest { | ... | @@ -704,15 +952,35 @@ public class IntraFileLeafrefLinkingTest { |
704 | public void processSelfResolutionWhenLeafrefReferToMultipleTypedef() | 952 | public void processSelfResolutionWhenLeafrefReferToMultipleTypedef() |
705 | throws IOException, ParserException { | 953 | throws IOException, ParserException { |
706 | 954 | ||
707 | - YangNode node = manager.getDataModel("src/test/resources/SelfResolutionWhenLeafrefReferToMultipleTypedef.yang"); | 955 | + String searchDir = "src/test/resources/leafreflinker/intrafile/leafreftomultitypedef"; |
956 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); | ||
957 | + utilManager.parseYangFileInfoSet(); | ||
958 | + utilManager.createYangNodeSet(); | ||
959 | + YangNode selfNode = null; | ||
960 | + // Create YANG node set | ||
961 | + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); | ||
962 | + | ||
963 | + // Add references to import list. | ||
964 | + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); | ||
965 | + | ||
966 | + // Carry out inter-file linking. | ||
967 | + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); | ||
968 | + | ||
969 | + Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator(); | ||
970 | + | ||
971 | + YangNode rootNode = yangNodeIterator.next(); | ||
972 | + | ||
973 | + if (rootNode.getName().equals("Test")) { | ||
974 | + selfNode = rootNode; | ||
975 | + } | ||
708 | // Check whether the data model tree returned is of type module. | 976 | // Check whether the data model tree returned is of type module. |
709 | - assertThat((node instanceof YangModule), is(true)); | 977 | + assertThat((selfNode instanceof YangModule), is(true)); |
710 | 978 | ||
711 | // Check whether the node type is set properly to module. | 979 | // Check whether the node type is set properly to module. |
712 | - assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | 980 | + assertThat(selfNode.getNodeType(), is(YangNodeType.MODULE_NODE)); |
713 | 981 | ||
714 | // Check whether the module name is set correctly. | 982 | // Check whether the module name is set correctly. |
715 | - YangModule yangNode = (YangModule) node; | 983 | + YangModule yangNode = (YangModule) selfNode; |
716 | assertThat(yangNode.getName(), is("Test")); | 984 | assertThat(yangNode.getName(), is("Test")); |
717 | 985 | ||
718 | YangContainer containerInModule = (YangContainer) yangNode.getChild().getNextSibling(); | 986 | YangContainer containerInModule = (YangContainer) yangNode.getChild().getNextSibling(); |
... | @@ -745,16 +1013,35 @@ public class IntraFileLeafrefLinkingTest { | ... | @@ -745,16 +1013,35 @@ public class IntraFileLeafrefLinkingTest { |
745 | public void processSelfResolutionWhenLeafrefReferToDerivedTypeReferringToLeafWithLeafref() | 1013 | public void processSelfResolutionWhenLeafrefReferToDerivedTypeReferringToLeafWithLeafref() |
746 | throws IOException, ParserException { | 1014 | throws IOException, ParserException { |
747 | 1015 | ||
748 | - YangNode node = manager.getDataModel( | 1016 | + String searchDir = "src/test/resources/leafreflinker/intrafile/leafreftotypedefwithleafref"; |
749 | - "src/test/resources/SelfResolutionWhenLeafrefReferToDerivedTypeReferringToLeafWithLeafref.yang"); | 1017 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
1018 | + utilManager.parseYangFileInfoSet(); | ||
1019 | + utilManager.createYangNodeSet(); | ||
1020 | + YangNode selfNode = null; | ||
1021 | + // Create YANG node set | ||
1022 | + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); | ||
1023 | + | ||
1024 | + // Add references to import list. | ||
1025 | + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); | ||
1026 | + | ||
1027 | + // Carry out inter-file linking. | ||
1028 | + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); | ||
1029 | + | ||
1030 | + Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator(); | ||
1031 | + | ||
1032 | + YangNode rootNode = yangNodeIterator.next(); | ||
1033 | + | ||
1034 | + if (rootNode.getName().equals("Test")) { | ||
1035 | + selfNode = rootNode; | ||
1036 | + } | ||
750 | // Check whether the data model tree returned is of type module. | 1037 | // Check whether the data model tree returned is of type module. |
751 | - assertThat((node instanceof YangModule), is(true)); | 1038 | + assertThat((selfNode instanceof YangModule), is(true)); |
752 | 1039 | ||
753 | // Check whether the node type is set properly to module. | 1040 | // Check whether the node type is set properly to module. |
754 | - assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | 1041 | + assertThat(selfNode.getNodeType(), is(YangNodeType.MODULE_NODE)); |
755 | 1042 | ||
756 | // Check whether the module name is set correctly. | 1043 | // Check whether the module name is set correctly. |
757 | - YangModule yangNode = (YangModule) node; | 1044 | + YangModule yangNode = (YangModule) selfNode; |
758 | assertThat(yangNode.getName(), is("Test")); | 1045 | assertThat(yangNode.getName(), is("Test")); |
759 | 1046 | ||
760 | YangContainer containerInModule = (YangContainer) yangNode.getChild().getNextSibling(); | 1047 | YangContainer containerInModule = (YangContainer) yangNode.getChild().getNextSibling(); |
... | @@ -786,17 +1073,35 @@ public class IntraFileLeafrefLinkingTest { | ... | @@ -786,17 +1073,35 @@ public class IntraFileLeafrefLinkingTest { |
786 | public void processSelfResolutionWhenLeafrefReferToContainerLeafRelPath() | 1073 | public void processSelfResolutionWhenLeafrefReferToContainerLeafRelPath() |
787 | throws IOException, ParserException { | 1074 | throws IOException, ParserException { |
788 | 1075 | ||
789 | - YangNode node = manager | 1076 | + String searchDir = "src/test/resources/leafreflinker/intrafile/relativepath/simpleleafref"; |
790 | - .getDataModel("src/test/resources/SelfResolutionWhenLeafrefReferToContainerLeafRelPath.yang"); | 1077 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
1078 | + utilManager.parseYangFileInfoSet(); | ||
1079 | + utilManager.createYangNodeSet(); | ||
1080 | + YangNode selfNode = null; | ||
1081 | + // Create YANG node set | ||
1082 | + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); | ||
791 | 1083 | ||
1084 | + // Add references to import list. | ||
1085 | + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); | ||
1086 | + | ||
1087 | + // Carry out inter-file linking. | ||
1088 | + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); | ||
1089 | + | ||
1090 | + Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator(); | ||
1091 | + | ||
1092 | + YangNode rootNode = yangNodeIterator.next(); | ||
1093 | + | ||
1094 | + if (rootNode.getName().equals("ietf-network")) { | ||
1095 | + selfNode = rootNode; | ||
1096 | + } | ||
792 | // Check whether the data model tree returned is of type module. | 1097 | // Check whether the data model tree returned is of type module. |
793 | - assertThat((node instanceof YangModule), is(true)); | 1098 | + assertThat((selfNode instanceof YangModule), is(true)); |
794 | 1099 | ||
795 | // Check whether the node type is set properly to module. | 1100 | // Check whether the node type is set properly to module. |
796 | - assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | 1101 | + assertThat(selfNode.getNodeType(), is(YangNodeType.MODULE_NODE)); |
797 | 1102 | ||
798 | // Check whether the module name is set correctly. | 1103 | // Check whether the module name is set correctly. |
799 | - YangModule yangNode = (YangModule) node; | 1104 | + YangModule yangNode = (YangModule) selfNode; |
800 | assertThat(yangNode.getName(), is("ietf-network")); | 1105 | assertThat(yangNode.getName(), is("ietf-network")); |
801 | 1106 | ||
802 | ListIterator<YangLeaf> leafIterator; | 1107 | ListIterator<YangLeaf> leafIterator; |
... | @@ -824,21 +1129,39 @@ public class IntraFileLeafrefLinkingTest { | ... | @@ -824,21 +1129,39 @@ public class IntraFileLeafrefLinkingTest { |
824 | * Checks self resolution when leafref under module refers to grouping rpc with input as name. | 1129 | * 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. | 1130 | * Rpc has input child also. So here the node search must be done by taking input node using relative path. |
826 | */ | 1131 | */ |
827 | - @Test | 1132 | + @Ignore |
828 | public void processSelfResolutionWhenLeafrefInModuleReferToGroupingWithInputInRpcRelPath() | 1133 | public void processSelfResolutionWhenLeafrefInModuleReferToGroupingWithInputInRpcRelPath() |
829 | throws IOException, ParserException { | 1134 | throws IOException, ParserException { |
830 | 1135 | ||
831 | - YangNode node = manager.getDataModel( | 1136 | + String searchDir = "src/test/resources/leafreflinker/intrafile/relativepath/leafreftoinputwithgroupinginrpc"; |
832 | - "src/test/resources/SelfResolutionWhenLeafrefInModuleReferToGroupingWithInputInRpcRelPath.yang"); | 1137 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
1138 | + utilManager.parseYangFileInfoSet(); | ||
1139 | + utilManager.createYangNodeSet(); | ||
1140 | + YangNode selfNode = null; | ||
1141 | + // Create YANG node set | ||
1142 | + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); | ||
833 | 1143 | ||
1144 | + // Add references to import list. | ||
1145 | + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); | ||
1146 | + | ||
1147 | + // Carry out inter-file linking. | ||
1148 | + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); | ||
1149 | + | ||
1150 | + Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator(); | ||
1151 | + | ||
1152 | + YangNode rootNode = yangNodeIterator.next(); | ||
1153 | + | ||
1154 | + if (rootNode.getName().equals("ietf-network")) { | ||
1155 | + selfNode = rootNode; | ||
1156 | + } | ||
834 | // Check whether the data model tree returned is of type module. | 1157 | // Check whether the data model tree returned is of type module. |
835 | - assertThat((node instanceof YangModule), is(true)); | 1158 | + assertThat((selfNode instanceof YangModule), is(true)); |
836 | 1159 | ||
837 | // Check whether the node type is set properly to module. | 1160 | // Check whether the node type is set properly to module. |
838 | - assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | 1161 | + assertThat(selfNode.getNodeType(), is(YangNodeType.MODULE_NODE)); |
839 | 1162 | ||
840 | // Check whether the module name is set correctly. | 1163 | // Check whether the module name is set correctly. |
841 | - YangModule yangNode = (YangModule) node; | 1164 | + YangModule yangNode = (YangModule) selfNode; |
842 | assertThat(yangNode.getName(), is("ietf-network")); | 1165 | assertThat(yangNode.getName(), is("ietf-network")); |
843 | 1166 | ||
844 | ListIterator<YangLeaf> leafIterator; | 1167 | ListIterator<YangLeaf> leafIterator; |
... | @@ -871,9 +1194,20 @@ public class IntraFileLeafrefLinkingTest { | ... | @@ -871,9 +1194,20 @@ public class IntraFileLeafrefLinkingTest { |
871 | 1194 | ||
872 | thrown.expect(LinkerException.class); | 1195 | thrown.expect(LinkerException.class); |
873 | thrown.expectMessage( | 1196 | thrown.expectMessage( |
874 | - "YANG file error: The target node of leafref is invalid."); | 1197 | + "YANG file error: The target node, in the leafref path ../../../define/network-id, is invalid."); |
875 | - YangNode node = manager | 1198 | + String searchDir = "src/test/resources/leafreflinker/intrafile/relativepath/invalidrelativeancestoraccess"; |
876 | - .getDataModel("src/test/resources/SelfResolutionWhenLeafrefInModuleReferToInvalidRootNodeRelPath.yang"); | 1199 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
1200 | + utilManager.parseYangFileInfoSet(); | ||
1201 | + utilManager.createYangNodeSet(); | ||
1202 | + | ||
1203 | + // Create YANG node set | ||
1204 | + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); | ||
1205 | + | ||
1206 | + // Add references to import list. | ||
1207 | + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); | ||
1208 | + | ||
1209 | + // Carry out inter-file linking. | ||
1210 | + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); | ||
877 | } | 1211 | } |
878 | 1212 | ||
879 | /** | 1213 | /** |
... | @@ -884,33 +1218,23 @@ public class IntraFileLeafrefLinkingTest { | ... | @@ -884,33 +1218,23 @@ public class IntraFileLeafrefLinkingTest { |
884 | public void processSelfResolutionWhenLeafrefInModuleReferToInvalidNodeRelPath() | 1218 | public void processSelfResolutionWhenLeafrefInModuleReferToInvalidNodeRelPath() |
885 | throws IOException, ParserException { | 1219 | throws IOException, ParserException { |
886 | 1220 | ||
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 | 1221 | ||
899 | - ListIterator<YangLeaf> leafIterator; | 1222 | + thrown.expect(LinkerException.class); |
900 | - YangLeaf leafInfo; | 1223 | + thrown.expectMessage( |
1224 | + "YANG file error: Unable to find base leaf/leaf-list for given leafref path ../define/network-id"); | ||
1225 | + String searchDir = "src/test/resources/leafreflinker/intrafile/relativepath/invalidnode"; | ||
1226 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); | ||
1227 | + utilManager.parseYangFileInfoSet(); | ||
1228 | + utilManager.createYangNodeSet(); | ||
901 | 1229 | ||
902 | - leafIterator = yangNode.getListOfLeaf().listIterator(); | 1230 | + // Create YANG node set |
903 | - leafInfo = leafIterator.next(); | 1231 | + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); |
904 | 1232 | ||
905 | - // Check whether the information in the leaf is correct. | 1233 | + // Add references to import list. |
906 | - assertThat(leafInfo.getName(), is("network-ref")); | 1234 | + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); |
907 | - assertThat(leafInfo.getDataType().getDataTypeName(), is("leafref")); | ||
908 | - assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.LEAFREF)); | ||
909 | - YangLeafRef leafref = (YangLeafRef) (leafInfo.getDataType().getDataTypeExtendedInfo()); | ||
910 | 1235 | ||
911 | - // Check whether leafref type got intra file resolved. | 1236 | + //Carry out inter-file linking. |
912 | - assertThat(leafref.getResolvableStatus(), | 1237 | + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); |
913 | - is(ResolvableStatus.INTRA_FILE_RESOLVED)); | ||
914 | } | 1238 | } |
915 | 1239 | ||
916 | /** | 1240 | /** |
... | @@ -920,17 +1244,35 @@ public class IntraFileLeafrefLinkingTest { | ... | @@ -920,17 +1244,35 @@ public class IntraFileLeafrefLinkingTest { |
920 | public void processSelfResolutionWhenLeafrefInTypedefReferToContainerRelPath() | 1244 | public void processSelfResolutionWhenLeafrefInTypedefReferToContainerRelPath() |
921 | throws IOException, ParserException { | 1245 | throws IOException, ParserException { |
922 | 1246 | ||
923 | - YangNode node = manager | 1247 | + String searchDir = "src/test/resources/leafreflinker/intrafile/relativepath/leafrefintypedef"; |
924 | - .getDataModel("src/test/resources/SelfResolutionWhenLeafrefInTypedefReferToContainerRelPath.yang"); | 1248 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
1249 | + utilManager.parseYangFileInfoSet(); | ||
1250 | + utilManager.createYangNodeSet(); | ||
1251 | + YangNode selfNode = null; | ||
1252 | + // Create YANG node set | ||
1253 | + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); | ||
925 | 1254 | ||
1255 | + // Add references to import list. | ||
1256 | + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); | ||
1257 | + | ||
1258 | + // Carry out inter-file linking. | ||
1259 | + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); | ||
1260 | + | ||
1261 | + Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator(); | ||
1262 | + | ||
1263 | + YangNode rootNode = yangNodeIterator.next(); | ||
1264 | + | ||
1265 | + if (rootNode.getName().equals("ietf-network")) { | ||
1266 | + selfNode = rootNode; | ||
1267 | + } | ||
926 | // Check whether the data model tree returned is of type module. | 1268 | // Check whether the data model tree returned is of type module. |
927 | - assertThat((node instanceof YangModule), is(true)); | 1269 | + assertThat((selfNode instanceof YangModule), is(true)); |
928 | 1270 | ||
929 | // Check whether the node type is set properly to module. | 1271 | // Check whether the node type is set properly to module. |
930 | - assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | 1272 | + assertThat(selfNode.getNodeType(), is(YangNodeType.MODULE_NODE)); |
931 | 1273 | ||
932 | // Check whether the module name is set correctly. | 1274 | // Check whether the module name is set correctly. |
933 | - YangModule yangNode = (YangModule) node; | 1275 | + YangModule yangNode = (YangModule) selfNode; |
934 | assertThat(yangNode.getName(), is("ietf-network")); | 1276 | assertThat(yangNode.getName(), is("ietf-network")); |
935 | ListIterator<YangLeaf> leafIterator; | 1277 | ListIterator<YangLeaf> leafIterator; |
936 | YangLeaf leafInfo; | 1278 | YangLeaf leafInfo; |
... | @@ -960,16 +1302,35 @@ public class IntraFileLeafrefLinkingTest { | ... | @@ -960,16 +1302,35 @@ public class IntraFileLeafrefLinkingTest { |
960 | public void processSelfResolutionWhenLeafrefReferToMultipleLeafrefRelPath() | 1302 | public void processSelfResolutionWhenLeafrefReferToMultipleLeafrefRelPath() |
961 | throws IOException, ParserException { | 1303 | throws IOException, ParserException { |
962 | 1304 | ||
963 | - YangNode node = manager | 1305 | + String searchDir = "src/test/resources/leafreflinker/intrafile/relativepath/leafreftomultileafref"; |
964 | - .getDataModel("src/test/resources/SelfResolutionWhenLeafrefReferToMultipleLeafrefRelPath.yang"); | 1306 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
1307 | + utilManager.parseYangFileInfoSet(); | ||
1308 | + utilManager.createYangNodeSet(); | ||
1309 | + YangNode selfNode = null; | ||
1310 | + // Create YANG node set | ||
1311 | + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); | ||
1312 | + | ||
1313 | + // Add references to import list. | ||
1314 | + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); | ||
1315 | + | ||
1316 | + // Carry out inter-file linking. | ||
1317 | + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); | ||
1318 | + | ||
1319 | + Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator(); | ||
1320 | + | ||
1321 | + YangNode rootNode = yangNodeIterator.next(); | ||
1322 | + | ||
1323 | + if (rootNode.getName().equals("Test")) { | ||
1324 | + selfNode = rootNode; | ||
1325 | + } | ||
965 | // Check whether the data model tree returned is of type module. | 1326 | // Check whether the data model tree returned is of type module. |
966 | - assertThat((node instanceof YangModule), is(true)); | 1327 | + assertThat((selfNode instanceof YangModule), is(true)); |
967 | 1328 | ||
968 | // Check whether the node type is set properly to module. | 1329 | // Check whether the node type is set properly to module. |
969 | - assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | 1330 | + assertThat(selfNode.getNodeType(), is(YangNodeType.MODULE_NODE)); |
970 | 1331 | ||
971 | // Check whether the module name is set correctly. | 1332 | // Check whether the module name is set correctly. |
972 | - YangModule yangNode = (YangModule) node; | 1333 | + YangModule yangNode = (YangModule) selfNode; |
973 | assertThat(yangNode.getName(), is("Test")); | 1334 | assertThat(yangNode.getName(), is("Test")); |
974 | 1335 | ||
975 | YangContainer containerInModule = (YangContainer) yangNode.getChild().getNextSibling(); | 1336 | YangContainer containerInModule = (YangContainer) yangNode.getChild().getNextSibling(); |
... | @@ -1002,16 +1363,35 @@ public class IntraFileLeafrefLinkingTest { | ... | @@ -1002,16 +1363,35 @@ public class IntraFileLeafrefLinkingTest { |
1002 | public void processSelfResolutionWhenLeafrefReferToDerivedTypeReferringToLeafWithLeafrefRelType() | 1363 | public void processSelfResolutionWhenLeafrefReferToDerivedTypeReferringToLeafWithLeafrefRelType() |
1003 | throws IOException, ParserException { | 1364 | throws IOException, ParserException { |
1004 | 1365 | ||
1005 | - YangNode node = manager.getDataModel( | 1366 | + String searchDir = "src/test/resources/leafreflinker/intrafile/relativepath/leafreftotypedef"; |
1006 | - "src/test/resources/SelfResolutionWhenLeafrefReferToDerivedTypeReferringToLeafWithLeafrefRelType.yang"); | 1367 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
1368 | + utilManager.parseYangFileInfoSet(); | ||
1369 | + utilManager.createYangNodeSet(); | ||
1370 | + YangNode selfNode = null; | ||
1371 | + // Create YANG node set | ||
1372 | + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); | ||
1373 | + | ||
1374 | + // Add references to import list. | ||
1375 | + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); | ||
1376 | + | ||
1377 | + // Carry out inter-file linking. | ||
1378 | + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); | ||
1379 | + | ||
1380 | + Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator(); | ||
1381 | + | ||
1382 | + YangNode rootNode = yangNodeIterator.next(); | ||
1383 | + | ||
1384 | + if (rootNode.getName().equals("Test")) { | ||
1385 | + selfNode = rootNode; | ||
1386 | + } | ||
1007 | // Check whether the data model tree returned is of type module. | 1387 | // Check whether the data model tree returned is of type module. |
1008 | - assertThat((node instanceof YangModule), is(true)); | 1388 | + assertThat((selfNode instanceof YangModule), is(true)); |
1009 | 1389 | ||
1010 | // Check whether the node type is set properly to module. | 1390 | // Check whether the node type is set properly to module. |
1011 | - assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | 1391 | + assertThat(selfNode.getNodeType(), is(YangNodeType.MODULE_NODE)); |
1012 | 1392 | ||
1013 | // Check whether the module name is set correctly. | 1393 | // Check whether the module name is set correctly. |
1014 | - YangModule yangNode = (YangModule) node; | 1394 | + YangModule yangNode = (YangModule) selfNode; |
1015 | assertThat(yangNode.getName(), is("Test")); | 1395 | assertThat(yangNode.getName(), is("Test")); |
1016 | 1396 | ||
1017 | YangContainer containerInModule = (YangContainer) yangNode.getChild().getNextSibling(); | 1397 | YangContainer containerInModule = (YangContainer) yangNode.getChild().getNextSibling(); |
... | @@ -1043,15 +1423,35 @@ public class IntraFileLeafrefLinkingTest { | ... | @@ -1043,15 +1423,35 @@ public class IntraFileLeafrefLinkingTest { |
1043 | public void processPathArgumentStatement() | 1423 | public void processPathArgumentStatement() |
1044 | throws IOException, ParserException { | 1424 | throws IOException, ParserException { |
1045 | 1425 | ||
1046 | - YangNode node = manager.getDataModel("src/test/resources/PathListener.yang"); | 1426 | + String searchDir = "src/test/resources/leafreflinker/intrafile/relativepath/pathlistener"; |
1427 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); | ||
1428 | + utilManager.parseYangFileInfoSet(); | ||
1429 | + utilManager.createYangNodeSet(); | ||
1430 | + YangNode selfNode = null; | ||
1431 | + // Create YANG node set | ||
1432 | + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); | ||
1433 | + | ||
1434 | + // Add references to import list. | ||
1435 | + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); | ||
1436 | + | ||
1437 | + // Carry out inter-file linking. | ||
1438 | + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); | ||
1439 | + | ||
1440 | + Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator(); | ||
1441 | + | ||
1442 | + YangNode rootNode = yangNodeIterator.next(); | ||
1443 | + | ||
1444 | + if (rootNode.getName().equals("PathListener")) { | ||
1445 | + selfNode = rootNode; | ||
1446 | + } | ||
1047 | // Check whether the data model tree returned is of type module. | 1447 | // Check whether the data model tree returned is of type module. |
1048 | - assertThat((node instanceof YangModule), is(true)); | 1448 | + assertThat((selfNode instanceof YangModule), is(true)); |
1049 | 1449 | ||
1050 | // Check whether the node type is set properly to module. | 1450 | // Check whether the node type is set properly to module. |
1051 | - assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | 1451 | + assertThat(selfNode.getNodeType(), is(YangNodeType.MODULE_NODE)); |
1052 | 1452 | ||
1053 | // Check whether the module name is set correctly. | 1453 | // Check whether the module name is set correctly. |
1054 | - YangModule yangNode = (YangModule) node; | 1454 | + YangModule yangNode = (YangModule) selfNode; |
1055 | assertThat(yangNode.getName(), is("PathListener")); | 1455 | assertThat(yangNode.getName(), is("PathListener")); |
1056 | YangList listInModule = (YangList) yangNode.getChild(); | 1456 | YangList listInModule = (YangList) yangNode.getChild(); |
1057 | 1457 | ||
... | @@ -1069,7 +1469,7 @@ public class IntraFileLeafrefLinkingTest { | ... | @@ -1069,7 +1469,7 @@ public class IntraFileLeafrefLinkingTest { |
1069 | assertThat(leafInfo.getDataType().getDataTypeName(), is("leafref")); | 1469 | assertThat(leafInfo.getDataType().getDataTypeName(), is("leafref")); |
1070 | assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.LEAFREF)); | 1470 | assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.LEAFREF)); |
1071 | YangLeafRef leafref = (YangLeafRef) leafInfo.getDataType().getDataTypeExtendedInfo(); | 1471 | YangLeafRef leafref = (YangLeafRef) leafInfo.getDataType().getDataTypeExtendedInfo(); |
1072 | - assertThat(leafref.getPathType(), is(YangPathArgType.RELATIVE_PATH)); | 1472 | + assertThat(leafref.getPathType(), is(YangPathArgType.ABSOLUTE_PATH)); |
1073 | 1473 | ||
1074 | YangRelativePath relativePathForName = leafref.getRelativePath(); | 1474 | YangRelativePath relativePathForName = leafref.getRelativePath(); |
1075 | assertThat(relativePathForName.getAncestorNodeCount(), is(2)); | 1475 | assertThat(relativePathForName.getAncestorNodeCount(), is(2)); |
... | @@ -1106,11 +1506,354 @@ public class IntraFileLeafrefLinkingTest { | ... | @@ -1106,11 +1506,354 @@ public class IntraFileLeafrefLinkingTest { |
1106 | assertThat(pathPredicate1.getPathOperator(), is(YangPathOperator.EQUALTO)); | 1506 | assertThat(pathPredicate1.getPathOperator(), is(YangPathOperator.EQUALTO)); |
1107 | assertThat(pathPredicate1.getRightRelativePath().getAtomicPathList().listIterator().next().getNodeIdentifier() | 1507 | assertThat(pathPredicate1.getRightRelativePath().getAtomicPathList().listIterator().next().getNodeIdentifier() |
1108 | .getName(), is("ifname")); | 1508 | .getName(), is("ifname")); |
1109 | - YangAtomicPath abspath2 = absPathIterator.next(); | 1509 | + //TODO : Fill the path predicates |
1110 | - assertThat(abspath2.getNodeIdentifier().getName(), is("admin-status")); | 1510 | +// assertThat(pathPredicate1.getLeftAxisNode(), is(leafNameInList)); |
1111 | - assertThat(abspath2.getNodeIdentifier().getPrefix(), is("test")); | 1511 | +// assertThat(pathPredicate1.getRightAxisNode(), is(leafInfo)); |
1512 | + } | ||
1513 | + | ||
1514 | + /** | ||
1515 | + * Checks inter file resolution when leafref refers to multiple leafrefs through many files. | ||
1516 | + */ | ||
1517 | + @Test | ||
1518 | + public void processInterFileLeafrefRefersToMultipleLeafrefInMultipleFiles() | ||
1519 | + throws IOException, ParserException { | ||
1520 | + | ||
1521 | + String searchDir = "src/test/resources/leafreflinker/interfile" + | ||
1522 | + "/interfileleafrefreferstomultipleleafrefinmultiplefiles"; | ||
1523 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); | ||
1524 | + utilManager.parseYangFileInfoSet(); | ||
1525 | + utilManager.createYangNodeSet(); | ||
1526 | + YangNode refNode1 = null; | ||
1527 | + YangNode refNode2 = null; | ||
1528 | + YangNode selfNode = null; | ||
1529 | + | ||
1530 | + // Create YANG node set | ||
1531 | + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); | ||
1532 | + | ||
1533 | + // Add references to import list. | ||
1534 | + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); | ||
1535 | + | ||
1536 | + // Carry out inter-file linking. | ||
1537 | + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); | ||
1538 | + | ||
1539 | + for (YangNode rootNode : utilManager.getYangNodeSet()) { | ||
1540 | + if (rootNode.getName().equals("ietf-network-topology")) { | ||
1541 | + selfNode = rootNode; | ||
1542 | + } else if (rootNode.getName().equals("ietf-network")) { | ||
1543 | + refNode1 = rootNode; | ||
1544 | + } else { | ||
1545 | + refNode2 = rootNode; | ||
1546 | + } | ||
1547 | + } | ||
1548 | + // Check whether the data model tree returned is of type module. | ||
1549 | + assertThat(selfNode instanceof YangModule, is(true)); | ||
1550 | + | ||
1551 | + // Check whether the node type is set properly to module. | ||
1552 | + assertThat(selfNode.getNodeType(), is(MODULE_NODE)); | ||
1553 | + | ||
1554 | + // Check whether the module name is set correctly. | ||
1555 | + YangModule yangNode = (YangModule) selfNode; | ||
1556 | + assertThat(yangNode.getName(), is("ietf-network-topology")); | ||
1557 | + | ||
1558 | + YangList list = (YangList) yangNode.getChild().getChild(); | ||
1559 | + ListIterator<YangLeaf> leafIterator = list.getListOfLeaf().listIterator(); | ||
1560 | + YangLeaf leafInfo = leafIterator.next(); | ||
1561 | + | ||
1562 | + assertThat(leafInfo.getName(), is("link-tp")); | ||
1563 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("leafref")); | ||
1564 | + assertThat(leafInfo.getDataType().getDataType(), is(LEAFREF)); | ||
1565 | + | ||
1566 | + YangLeafRef leafref = (YangLeafRef) leafInfo.getDataType().getDataTypeExtendedInfo(); | ||
1567 | + | ||
1568 | + YangLeaf leafInfo2 = (YangLeaf) leafref.getReferredLeafOrLeafList(); | ||
1569 | + assertThat(leafref.getReferredLeafOrLeafList(), is(leafInfo2)); | ||
1570 | + assertThat(leafref.getResolvableStatus(), is(RESOLVED)); | ||
1571 | + | ||
1572 | + assertThat(leafref.getEffectiveDataType().getDataType(), | ||
1573 | + is(YangDataTypes.STRING)); | ||
1574 | + } | ||
1575 | + | ||
1576 | + | ||
1577 | + /** | ||
1578 | + * Checks addition of if-feature list to leafref. | ||
1579 | + */ | ||
1580 | + @Test | ||
1581 | + public void processSelfFileLinkingWithFeatureReferredByLeafref() | ||
1582 | + throws IOException, ParserException { | ||
1583 | + | ||
1584 | + String searchDir = "src/test/resources/leafreflinker/iffeatuinleafref/simpleleafrefwithiffeature"; | ||
1585 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); | ||
1586 | + utilManager.parseYangFileInfoSet(); | ||
1587 | + utilManager.createYangNodeSet(); | ||
1588 | + YangNode selfNode = null; | ||
1589 | + // Create YANG node set | ||
1590 | + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); | ||
1591 | + | ||
1592 | + // Add references to import list. | ||
1593 | + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); | ||
1594 | + | ||
1595 | + // Carry out inter-file linking. | ||
1596 | + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); | ||
1597 | + | ||
1598 | + Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator(); | ||
1599 | + | ||
1600 | + YangNode rootNode = yangNodeIterator.next(); | ||
1601 | + | ||
1602 | + if (rootNode.getName().equals("syslog")) { | ||
1603 | + selfNode = rootNode; | ||
1604 | + } | ||
1605 | + // Check whether the data model tree returned is of type module. | ||
1606 | + assertThat((selfNode instanceof YangModule), is(true)); | ||
1607 | + | ||
1608 | + // Check whether the node type is set properly to module. | ||
1609 | + assertThat(selfNode.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
1610 | + | ||
1611 | + // Check whether the module name is set correctly. | ||
1612 | + YangModule yangNode = (YangModule) selfNode; | ||
1613 | + assertThat(yangNode.getName(), is("syslog")); | ||
1614 | + | ||
1615 | + List<YangFeature> featureList = yangNode.getFeatureList(); | ||
1616 | + YangFeature feature = featureList.iterator().next(); | ||
1617 | + assertThat(feature.getName(), is("local-storage")); | ||
1618 | + | ||
1619 | + YangContainer container = (YangContainer) yangNode.getChild(); | ||
1620 | + assertThat(container.getName(), is("speed")); | ||
1621 | + | ||
1622 | + List<YangLeaf> listOfLeaf = container.getListOfLeaf(); | ||
1623 | + YangLeaf leaf = listOfLeaf.iterator().next(); | ||
1624 | + assertThat(leaf.getName(), is("local-storage-limit")); | ||
1625 | + | ||
1626 | + List<YangIfFeature> ifFeatureList = leaf.getIfFeatureList(); | ||
1627 | + YangIfFeature ifFeature = ifFeatureList.iterator().next(); | ||
1628 | + assertThat(ifFeature.getName().getName(), is("local-storage")); | ||
1629 | + assertThat(ifFeature.getResolvableStatus(), is(ResolvableStatus.RESOLVED)); | ||
1630 | + | ||
1631 | + ListIterator<YangLeaf> listOfLeafInModule = yangNode.getListOfLeaf().listIterator(); | ||
1632 | + YangLeaf yangLeaf = listOfLeafInModule.next(); | ||
1633 | + assertThat(yangLeaf.getName(), is("storage-value")); | ||
1634 | + | ||
1635 | + YangLeafRef leafRef = (YangLeafRef) yangLeaf.getDataType().getDataTypeExtendedInfo(); | ||
1636 | + | ||
1637 | + assertThat(leafRef.getEffectiveDataType().getDataType(), is(YangDataTypes.UINT64)); | ||
1638 | + | ||
1639 | + List<YangIfFeature> ifFeatureListInLeafref = leafRef.getIfFeatureList(); | ||
1640 | + YangIfFeature ifFeatureInLeafref = ifFeatureListInLeafref.iterator().next(); | ||
1641 | + assertThat(ifFeatureInLeafref.getName().getName(), is("local-storage")); | ||
1642 | + assertThat(ifFeatureInLeafref.getResolvableStatus(), is(ResolvableStatus.RESOLVED)); | ||
1643 | + } | ||
1644 | + | ||
1645 | + /** | ||
1646 | + * Checks addition of if-feature list to leafref when referred leaf is again having leafref in it. | ||
1647 | + */ | ||
1648 | + @Test | ||
1649 | + public void processSelfFileLinkingWithFeatureReferredByMultiLeafref() | ||
1650 | + throws IOException, ParserException { | ||
1651 | + | ||
1652 | + String searchDir = "src/test/resources/leafreflinker/iffeatuinleafref/featurebymultileafref"; | ||
1653 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); | ||
1654 | + utilManager.parseYangFileInfoSet(); | ||
1655 | + utilManager.createYangNodeSet(); | ||
1656 | + YangNode selfNode = null; | ||
1657 | + // Create YANG node set | ||
1658 | + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); | ||
1659 | + | ||
1660 | + // Add references to import list. | ||
1661 | + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); | ||
1662 | + | ||
1663 | + // Carry out inter-file linking. | ||
1664 | + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); | ||
1665 | + | ||
1666 | + Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator(); | ||
1667 | + | ||
1668 | + YangNode rootNode = yangNodeIterator.next(); | ||
1669 | + | ||
1670 | + if (rootNode.getName().equals("syslog")) { | ||
1671 | + selfNode = rootNode; | ||
1672 | + } | ||
1673 | + // Check whether the data model tree returned is of type module. | ||
1674 | + assertThat((selfNode instanceof YangModule), is(true)); | ||
1675 | + | ||
1676 | + // Check whether the node type is set properly to module. | ||
1677 | + assertThat(selfNode.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
1678 | + | ||
1679 | + // Check whether the module name is set correctly. | ||
1680 | + YangModule yangNode = (YangModule) selfNode; | ||
1681 | + assertThat(yangNode.getName(), is("syslog")); | ||
1682 | + | ||
1683 | + List<YangFeature> featureList = yangNode.getFeatureList(); | ||
1684 | + YangFeature feature = featureList.iterator().next(); | ||
1685 | + assertThat(feature.getName(), is("local-storage")); | ||
1112 | 1686 | ||
1113 | - assertThat(pathPredicate1.getLeftAxisNode(), is(leafNameInList)); | 1687 | + YangContainer container = (YangContainer) yangNode.getChild(); |
1114 | - assertThat(pathPredicate1.getRightAxisNode(), is(leafInfo)); | 1688 | + assertThat(container.getName(), is("speed")); |
1689 | + | ||
1690 | + List<YangLeaf> listOfLeaf = container.getListOfLeaf(); | ||
1691 | + YangLeaf leaf = listOfLeaf.iterator().next(); | ||
1692 | + assertThat(leaf.getName(), is("local-storage-limit")); | ||
1693 | + | ||
1694 | + List<YangIfFeature> ifFeatureList = leaf.getIfFeatureList(); | ||
1695 | + YangIfFeature ifFeature = ifFeatureList.iterator().next(); | ||
1696 | + assertThat(ifFeature.getName().getName(), is("local-storage")); | ||
1697 | + assertThat(ifFeature.getResolvableStatus(), is(ResolvableStatus.RESOLVED)); | ||
1698 | + | ||
1699 | + ListIterator<YangLeaf> listOfLeafInModule = yangNode.getListOfLeaf().listIterator(); | ||
1700 | + YangLeaf yangLeaf = listOfLeafInModule.next(); | ||
1701 | + assertThat(yangLeaf.getName(), is("storage-value")); | ||
1702 | + | ||
1703 | + YangLeafRef leafRef = (YangLeafRef) yangLeaf.getDataType().getDataTypeExtendedInfo(); | ||
1704 | + | ||
1705 | + assertThat(leafRef.getEffectiveDataType().getDataType(), is(YangDataTypes.UINT64)); | ||
1706 | + | ||
1707 | + List<YangIfFeature> ifFeatureListInLeafref = leafRef.getIfFeatureList(); | ||
1708 | + YangIfFeature ifFeatureInLeafref = ifFeatureListInLeafref.iterator().next(); | ||
1709 | + | ||
1710 | + assertThat(ifFeatureInLeafref.getName().getName(), is("main-storage")); | ||
1711 | + assertThat(ifFeatureInLeafref.getResolvableStatus(), is(ResolvableStatus.RESOLVED)); | ||
1712 | + | ||
1713 | + YangIfFeature ifFeatureInLeafref1 = ifFeatureListInLeafref.iterator().next(); | ||
1714 | + | ||
1715 | + assertThat(ifFeatureInLeafref1.getName().getName(), is("main-storage")); | ||
1716 | + assertThat(ifFeatureInLeafref1.getResolvableStatus(), is(ResolvableStatus.RESOLVED)); | ||
1717 | + } | ||
1718 | + | ||
1719 | + /** | ||
1720 | + * Checks self resolution when leafref in grouping is copied to augment. | ||
1721 | + */ | ||
1722 | + @Test | ||
1723 | + public void processSelfResolutionWhenLeafrefInGroupingIsUnderAugment() | ||
1724 | + throws IOException, ParserException { | ||
1725 | + | ||
1726 | + String searchDir = "src/test/resources/leafreflinker/intrafile/leafrefInAugment"; | ||
1727 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); | ||
1728 | + utilManager.parseYangFileInfoSet(); | ||
1729 | + utilManager.createYangNodeSet(); | ||
1730 | + YangNode selfNode = null; | ||
1731 | + | ||
1732 | + // Create YANG node set | ||
1733 | + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); | ||
1734 | + | ||
1735 | + // Add references to import list. | ||
1736 | + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); | ||
1737 | + | ||
1738 | + // Carry out inter-file linking. | ||
1739 | + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); | ||
1740 | + | ||
1741 | + Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator(); | ||
1742 | + | ||
1743 | + YangNode rootNode = yangNodeIterator.next(); | ||
1744 | + | ||
1745 | + if (rootNode.getName().equals("topology")) { | ||
1746 | + selfNode = rootNode; | ||
1747 | + } | ||
1748 | + | ||
1749 | + // Check whether the data model tree returned is of type module. | ||
1750 | + assertThat((selfNode instanceof YangModule), is(true)); | ||
1751 | + | ||
1752 | + // Check whether the node type is set properly to module. | ||
1753 | + assertThat(selfNode.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
1754 | + | ||
1755 | + // Check whether the module name is set correctly. | ||
1756 | + YangModule yangNode = (YangModule) selfNode; | ||
1757 | + assertThat(yangNode.getName(), is("topology")); | ||
1758 | + | ||
1759 | + ListIterator<YangLeaf> leafIterator; | ||
1760 | + YangLeaf leafInfo; | ||
1761 | + | ||
1762 | + YangAugment augment = (YangAugment) yangNode.getChild().getNextSibling(); | ||
1763 | + | ||
1764 | + YangList list = (YangList) augment.getChild().getChild().getChild().getChild().getChild(); | ||
1765 | + | ||
1766 | + leafIterator = list.getListOfLeaf().listIterator(); | ||
1767 | + leafInfo = leafIterator.next(); | ||
1768 | + | ||
1769 | + // Check whether the information in the leaf is correct. | ||
1770 | + assertThat(leafInfo.getName(), is("src-tp-ref")); | ||
1771 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("leafref")); | ||
1772 | + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.LEAFREF)); | ||
1773 | + YangLeafRef leafref = (YangLeafRef) (leafInfo.getDataType().getDataTypeExtendedInfo()); | ||
1774 | + | ||
1775 | + // Check whether leafref type got resolved. | ||
1776 | + assertThat(leafref.getResolvableStatus(), | ||
1777 | + is(ResolvableStatus.RESOLVED)); | ||
1778 | + | ||
1779 | + // Check the effective type for the leaf. | ||
1780 | + assertThat(leafref.getEffectiveDataType().getDataType(), | ||
1781 | + is(YangDataTypes.UINT8)); | ||
1782 | + } | ||
1783 | + | ||
1784 | + /** | ||
1785 | + * Checks self resolution when leafref under grouping's uses. | ||
1786 | + */ | ||
1787 | + @Test | ||
1788 | + public void processSelfResolutionWhenLeafrefUnderGroupingUses() | ||
1789 | + throws IOException, ParserException { | ||
1790 | + | ||
1791 | + String searchDir = "src/test/resources/leafreflinker/intrafile/leafrefinusesundergrouping"; | ||
1792 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); | ||
1793 | + utilManager.parseYangFileInfoSet(); | ||
1794 | + utilManager.createYangNodeSet(); | ||
1795 | + YangNode selfNode = null; | ||
1796 | + YangNode refNode = null; | ||
1797 | + | ||
1798 | + // Create YANG node set | ||
1799 | + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); | ||
1800 | + | ||
1801 | + // Add references to import list. | ||
1802 | + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); | ||
1803 | + | ||
1804 | + // Carry out inter-file linking. | ||
1805 | + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); | ||
1806 | + | ||
1807 | + Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator(); | ||
1808 | + | ||
1809 | + YangNode rootNode = yangNodeIterator.next(); | ||
1810 | + | ||
1811 | + if (rootNode.getName().equals("ietf-network")) { | ||
1812 | + selfNode = rootNode; | ||
1813 | + refNode = yangNodeIterator.next(); | ||
1814 | + } else { | ||
1815 | + refNode = rootNode; | ||
1816 | + selfNode = yangNodeIterator.next(); | ||
1817 | + } | ||
1818 | + | ||
1819 | + // Check whether the data model tree returned is of type module. | ||
1820 | + assertThat(selfNode instanceof YangModule, is(true)); | ||
1821 | + | ||
1822 | + // Check whether the node type is set properly to module. | ||
1823 | + assertThat(selfNode.getNodeType(), is(MODULE_NODE)); | ||
1824 | + | ||
1825 | + // Check whether the module name is set correctly. | ||
1826 | + YangModule yangNode = (YangModule) selfNode; | ||
1827 | + assertThat(yangNode.getName(), is("ietf-network")); | ||
1828 | + | ||
1829 | + // Check whether the module name is set correctly. | ||
1830 | + YangModule yangNode1 = (YangModule) refNode; | ||
1831 | + assertThat(yangNode1.getName(), is("network")); | ||
1832 | + | ||
1833 | + YangContainer yangContainer = (YangContainer) yangNode.getChild().getNextSibling().getNextSibling(); | ||
1834 | + assertThat(yangContainer.getName(), is("fine")); | ||
1835 | + | ||
1836 | + YangContainer yangContainer1 = (YangContainer) yangContainer.getChild().getNextSibling(); | ||
1837 | + assertThat(yangContainer1.getName(), is("hi")); | ||
1838 | + | ||
1839 | + ListIterator<YangLeaf> leafIterator; | ||
1840 | + YangLeaf leafInfo; | ||
1841 | + | ||
1842 | + leafIterator = yangContainer1.getListOfLeaf().listIterator(); | ||
1843 | + leafInfo = leafIterator.next(); | ||
1844 | + | ||
1845 | + // Check whether the information in the leaf is correct. | ||
1846 | + assertThat(leafInfo.getName(), is("network-id-ref")); | ||
1847 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("leafref")); | ||
1848 | + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.LEAFREF)); | ||
1849 | + YangLeafRef leafref = (YangLeafRef) (leafInfo.getDataType().getDataTypeExtendedInfo()); | ||
1850 | + | ||
1851 | + // Check whether leafref type got resolved. | ||
1852 | + assertThat(leafref.getResolvableStatus(), | ||
1853 | + is(ResolvableStatus.RESOLVED)); | ||
1854 | + | ||
1855 | + // Check the effective type for the leaf. | ||
1856 | + assertThat(leafref.getEffectiveDataType().getDataType(), | ||
1857 | + is(YangDataTypes.DERIVED)); | ||
1115 | } | 1858 | } |
1116 | } | 1859 | } | ... | ... |
1 | -module Test { | ||
2 | - yang-version 1; | ||
3 | - namespace http://huawei.com; | ||
4 | - prefix Ant; | ||
5 | - list valid { | ||
6 | - key "invalid-interval"; | ||
7 | - leaf-list invalid { | ||
8 | - type "string"; | ||
9 | - units "seconds"; | ||
10 | - status current; | ||
11 | - reference "RFC 6020"; | ||
12 | - } | ||
13 | - } | ||
14 | -} | ||
... | \ 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 "invalid-interval"; | ||
7 | - leaf-list invalid-interval { | ||
8 | - type "empty"; | ||
9 | - units "seconds"; | ||
10 | - status current; | ||
11 | - reference "RFC 6020"; | ||
12 | - } | ||
13 | - } | ||
14 | -} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
... | @@ -4,7 +4,7 @@ module Test { | ... | @@ -4,7 +4,7 @@ module Test { |
4 | namespace http://huawei.com; | 4 | namespace http://huawei.com; |
5 | prefix Ant; | 5 | prefix Ant; |
6 | list valid { | 6 | list valid { |
7 | - key "invalid-interval"; | 7 | + key "invalid"; |
8 | leaf-list invalid-interval { | 8 | leaf-list invalid-interval { |
9 | type "uint16"; | 9 | type "uint16"; |
10 | units "seconds"; | 10 | units "seconds"; |
... | @@ -13,5 +13,8 @@ module Test { | ... | @@ -13,5 +13,8 @@ module Test { |
13 | status current; | 13 | status current; |
14 | reference "RFC 6020"; | 14 | reference "RFC 6020"; |
15 | } | 15 | } |
16 | + leaf invalid { | ||
17 | + type "uint16"; | ||
18 | + } | ||
16 | } | 19 | } |
17 | } | 20 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -3,12 +3,15 @@ module Test { | ... | @@ -3,12 +3,15 @@ module Test { |
3 | namespace http://huawei.com; | 3 | namespace http://huawei.com; |
4 | prefix Ant; | 4 | prefix Ant; |
5 | list valid { | 5 | list valid { |
6 | - key "invalid-interval"; | 6 | + key "invalid"; |
7 | max-elements 3; | 7 | max-elements 3; |
8 | leaf-list invalid-interval { | 8 | leaf-list invalid-interval { |
9 | type "uint16"; | 9 | type "uint16"; |
10 | units "seconds"; | 10 | units "seconds"; |
11 | description "Interval before a route is declared invalid"; | 11 | description "Interval before a route is declared invalid"; |
12 | } | 12 | } |
13 | + leaf invalid { | ||
14 | + type "uint16"; | ||
15 | + } | ||
13 | } | 16 | } |
14 | } | 17 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -3,12 +3,15 @@ module Test { | ... | @@ -3,12 +3,15 @@ module Test { |
3 | namespace http://huawei.com; | 3 | namespace http://huawei.com; |
4 | prefix Ant; | 4 | prefix Ant; |
5 | list valid { | 5 | list valid { |
6 | - key "invalid-interval"; | 6 | + key "invalid"; |
7 | min-elements 3; | 7 | min-elements 3; |
8 | leaf-list invalid-interval { | 8 | leaf-list invalid-interval { |
9 | type "uint16"; | 9 | type "uint16"; |
10 | units "seconds"; | 10 | units "seconds"; |
11 | description "Interval before a route is declared invalid"; | 11 | description "Interval before a route is declared invalid"; |
12 | } | 12 | } |
13 | + leaf invalid { | ||
14 | + type "uint16"; | ||
15 | + } | ||
13 | } | 16 | } |
14 | } | 17 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -3,12 +3,13 @@ module Test { | ... | @@ -3,12 +3,13 @@ module Test { |
3 | namespace http://huawei.com; | 3 | namespace http://huawei.com; |
4 | prefix Ant; | 4 | prefix Ant; |
5 | list valid { | 5 | list valid { |
6 | + unique "invalid-interval"; | ||
6 | key "invalid-interval"; | 7 | key "invalid-interval"; |
7 | - leaf-list invalid-interval { | 8 | + leaf invalid-interval { |
8 | type "uint16"; | 9 | type "uint16"; |
9 | units "seconds"; | 10 | units "seconds"; |
10 | status current; | 11 | status current; |
11 | reference "RFC 6020"; | 12 | reference "RFC 6020"; |
12 | } | 13 | } |
13 | } | 14 | } |
14 | -} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
15 | +} | ... | ... |
... | @@ -3,9 +3,16 @@ module Test { | ... | @@ -3,9 +3,16 @@ module Test { |
3 | namespace http://huawei.com; | 3 | namespace http://huawei.com; |
4 | prefix Ant; | 4 | prefix Ant; |
5 | list valid { | 5 | list valid { |
6 | - key "invalid-interval"; | 6 | + key "ospf"; |
7 | - leaf-list invalid-interval { | 7 | + unique "ospf isis"; |
8 | - type "string"; | 8 | + leaf ospf { |
9 | + type "uint16"; | ||
10 | + units "seconds"; | ||
11 | + status current; | ||
12 | + reference "RFC 6020"; | ||
13 | + } | ||
14 | + leaf isis { | ||
15 | + type "uint16"; | ||
9 | units "seconds"; | 16 | units "seconds"; |
10 | status current; | 17 | status current; |
11 | reference "RFC 6020"; | 18 | reference "RFC 6020"; | ... | ... |
... | @@ -3,7 +3,7 @@ module Test { | ... | @@ -3,7 +3,7 @@ module Test { |
3 | namespace http://huawei.com; | 3 | namespace http://huawei.com; |
4 | prefix Ant; | 4 | prefix Ant; |
5 | list valid { | 5 | list valid { |
6 | - key "invalid-interval"; | 6 | + key "invalid"; |
7 | leaf-list invalid-interval { | 7 | leaf-list invalid-interval { |
8 | type union { | 8 | type union { |
9 | type int32; | 9 | type int32; |
... | @@ -12,5 +12,8 @@ module Test { | ... | @@ -12,5 +12,8 @@ module Test { |
12 | } | 12 | } |
13 | } | 13 | } |
14 | } | 14 | } |
15 | + leaf invalid { | ||
16 | + type string; | ||
17 | + } | ||
15 | } | 18 | } |
16 | } | 19 | } | ... | ... |
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 |
... | @@ -103,7 +103,11 @@ | ... | @@ -103,7 +103,11 @@ |
103 | description | 103 | description |
104 | "References a link in a specific network."; | 104 | "References a link in a specific network."; |
105 | leaf link-ref { | 105 | leaf link-ref { |
106 | - type link-id; | 106 | + type leafref { |
107 | + path "/nd:networks/nd:network[nd:network-id=current()/../"+ | ||
108 | + "network-ref]/lnk:link/lnk:link-id"; | ||
109 | + require-instance false; | ||
110 | + } | ||
107 | description | 111 | description |
108 | "A type for an absolute reference a link instance. | 112 | "A type for an absolute reference a link instance. |
109 | (This type should not be used for relative references. | 113 | (This type should not be used for relative references. |
... | @@ -116,7 +120,12 @@ | ... | @@ -116,7 +120,12 @@ |
116 | description | 120 | description |
117 | "References a termination point in a specific node."; | 121 | "References a termination point in a specific node."; |
118 | leaf tp-ref { | 122 | leaf tp-ref { |
119 | - type tp-id; | 123 | + type leafref { |
124 | + path "/nd:networks/nd:network[nd:network-id=current()/../"+ | ||
125 | + "network-ref]/nd:node[nd:node-id=current()/../"+ | ||
126 | + "node-ref]/lnk:termination-point/lnk:tp-id"; | ||
127 | + require-instance false; | ||
128 | + } | ||
120 | description | 129 | description |
121 | "A type for an absolute reference to a termination point. | 130 | "A type for an absolute reference to a termination point. |
122 | (This type should not be used for relative references. | 131 | (This type should not be used for relative references. |
... | @@ -150,13 +159,18 @@ | ... | @@ -150,13 +159,18 @@ |
150 | "This container holds the logical source of a particular | 159 | "This container holds the logical source of a particular |
151 | link."; | 160 | link."; |
152 | leaf source-node { | 161 | leaf source-node { |
153 | - type nd:node-id; | 162 | + type leafref { |
163 | + path "../../../nd:node/nd:node-id"; | ||
164 | + } | ||
154 | mandatory true; | 165 | mandatory true; |
155 | description | 166 | description |
156 | "Source node identifier, must be in same topology."; | 167 | "Source node identifier, must be in same topology."; |
157 | } | 168 | } |
158 | leaf source-tp { | 169 | leaf source-tp { |
159 | - type tp-id; | 170 | + type leafref { |
171 | + path "../../../nd:node[nd:node-id=current()/../"+ | ||
172 | + "source-node]/termination-point/tp-id"; | ||
173 | + } | ||
160 | description | 174 | description |
161 | "Termination point within source node that terminates | 175 | "Termination point within source node that terminates |
162 | the link."; | 176 | the link."; |
... | @@ -167,14 +181,19 @@ | ... | @@ -167,14 +181,19 @@ |
167 | "This container holds the logical destination of a | 181 | "This container holds the logical destination of a |
168 | particular link."; | 182 | particular link."; |
169 | leaf dest-node { | 183 | leaf dest-node { |
170 | - type nd:node-id; | 184 | + type leafref { |
185 | + path "../../../nd:node/nd:node-id"; | ||
186 | + } | ||
171 | mandatory true; | 187 | mandatory true; |
172 | description | 188 | description |
173 | "Destination node identifier, must be in the same | 189 | "Destination node identifier, must be in the same |
174 | network."; | 190 | network."; |
175 | } | 191 | } |
176 | leaf dest-tp { | 192 | leaf dest-tp { |
177 | - type tp-id; | 193 | + type leafref { |
194 | + path "../../../nd:node[nd:node-id=current()/../"+ | ||
195 | + "dest-node]/termination-point/tp-id"; | ||
196 | + } | ||
178 | description | 197 | description |
179 | "Termination point within destination node that | 198 | "Termination point within destination node that |
180 | terminates the link."; | 199 | terminates the link."; |
... | @@ -192,13 +211,20 @@ | ... | @@ -192,13 +211,20 @@ |
192 | "Identifies the link, or links, that this link | 211 | "Identifies the link, or links, that this link |
193 | is dependent on."; | 212 | is dependent on."; |
194 | leaf network-ref { | 213 | leaf network-ref { |
195 | - type nd:network-id; | 214 | + type leafref { |
215 | + path "../../../nd:supporting-network/nd:network-ref"; | ||
216 | + require-instance false; | ||
217 | + } | ||
196 | description | 218 | description |
197 | "This leaf identifies in which underlay topology | 219 | "This leaf identifies in which underlay topology |
198 | supporting link is present."; | 220 | supporting link is present."; |
199 | } | 221 | } |
200 | leaf link-ref { | 222 | leaf link-ref { |
201 | - type link-id; | 223 | + type leafref { |
224 | + path "/nd:networks/nd:network[nd:network-id=current()/"+ | ||
225 | + "../network-ref]/link/link-id"; | ||
226 | + require-instance false; | ||
227 | + } | ||
202 | description | 228 | description |
203 | "This leaf identifies a link which is a part | 229 | "This leaf identifies a link which is a part |
204 | of this link's underlay. Reference loops, in which | 230 | of this link's underlay. Reference loops, in which |
... | @@ -237,19 +263,30 @@ | ... | @@ -237,19 +263,30 @@ |
237 | The corresponding information is simply provided by the | 263 | The corresponding information is simply provided by the |
238 | implementing system."; | 264 | implementing system."; |
239 | leaf network-ref { | 265 | leaf network-ref { |
240 | - type nd:network-id; | 266 | + type leafref { |
267 | + path "../../../nd:supporting-node/nd:network-ref"; | ||
268 | + require-instance false; | ||
269 | + } | ||
241 | description | 270 | description |
242 | "This leaf identifies in which topology the | 271 | "This leaf identifies in which topology the |
243 | supporting termination point is present."; | 272 | supporting termination point is present."; |
244 | } | 273 | } |
245 | leaf node-ref { | 274 | leaf node-ref { |
246 | - type nd:node-id; | 275 | + type leafref { |
276 | + path "../../../nd:supporting-node/nd:node-ref"; | ||
277 | + require-instance false; | ||
278 | + } | ||
247 | description | 279 | description |
248 | "This leaf identifies in which node the supporting | 280 | "This leaf identifies in which node the supporting |
249 | termination point is present."; | 281 | termination point is present."; |
250 | } | 282 | } |
251 | leaf tp-ref { | 283 | leaf tp-ref { |
252 | - type tp-id; | 284 | + type leafref { |
285 | + path "/nd:networks/nd:network[nd:network-id=current()/"+ | ||
286 | + "../network-ref]/nd:node[nd:node-id=current()/../"+ | ||
287 | + "node-ref]/termination-point/tp-id"; | ||
288 | + require-instance false; | ||
289 | + } | ||
253 | description | 290 | description |
254 | "Reference to the underlay node, must be in a | 291 | "Reference to the underlay node, must be in a |
255 | different topology"; | 292 | different topology"; | ... | ... |
... | @@ -87,7 +87,10 @@ | ... | @@ -87,7 +87,10 @@ |
87 | "Contains the information necessary to reference a network, | 87 | "Contains the information necessary to reference a network, |
88 | for example an underlay network."; | 88 | for example an underlay network."; |
89 | leaf network-ref { | 89 | leaf network-ref { |
90 | - type network-id; | 90 | + type leafref { |
91 | + path "/nd:networks/nd:network/nd:network-id"; | ||
92 | + require-instance false; | ||
93 | + } | ||
91 | description | 94 | description |
92 | "Used to reference a network, for example an underlay | 95 | "Used to reference a network, for example an underlay |
93 | network."; | 96 | network."; |
... | @@ -98,7 +101,11 @@ | ... | @@ -98,7 +101,11 @@ |
98 | description | 101 | description |
99 | "Contains the information necessary to reference a node."; | 102 | "Contains the information necessary to reference a node."; |
100 | leaf node-ref { | 103 | leaf node-ref { |
101 | - type node-id; | 104 | + type leafref { |
105 | + path "/nd:networks/nd:network[nd:network-id=current()/../"+ | ||
106 | + "network-ref]/nd:node/nd:node-id"; | ||
107 | + require-instance false; | ||
108 | + } | ||
102 | description | 109 | description |
103 | "Used to reference a node. | 110 | "Used to reference a node. |
104 | Nodes are identified relative to the network they are | 111 | Nodes are identified relative to the network they are |
... | @@ -135,7 +142,10 @@ | ... | @@ -135,7 +142,10 @@ |
135 | "An underlay network, used to represent layered network | 142 | "An underlay network, used to represent layered network |
136 | topologies."; | 143 | topologies."; |
137 | leaf network-ref { | 144 | leaf network-ref { |
138 | - type network-id; | 145 | + type leafref { |
146 | + path "/networks/network/network-id"; | ||
147 | + require-instance false; | ||
148 | + } | ||
139 | description | 149 | description |
140 | "References the underlay network."; | 150 | "References the underlay network."; |
141 | } | 151 | } |
... | @@ -157,13 +167,19 @@ | ... | @@ -157,13 +167,19 @@ |
157 | this node is supported by. Used to represent layering | 167 | this node is supported by. Used to represent layering |
158 | structure."; | 168 | structure."; |
159 | leaf network-ref { | 169 | leaf network-ref { |
160 | - type network-id; | 170 | + type leafref { |
171 | + path "../../../supporting-network/network-ref"; | ||
172 | + require-instance false; | ||
173 | + } | ||
161 | description | 174 | description |
162 | "References the underlay network that the | 175 | "References the underlay network that the |
163 | underlay node is part of."; | 176 | underlay node is part of."; |
164 | } | 177 | } |
165 | leaf node-ref { | 178 | leaf node-ref { |
166 | - type node-id; | 179 | + type leafref { |
180 | + path "/networks/network/node/node-id"; | ||
181 | + require-instance false; | ||
182 | + } | ||
167 | description | 183 | description |
168 | "References the underlay node itself."; | 184 | "References the underlay node itself."; |
169 | } | 185 | } | ... | ... |
... | @@ -515,14 +515,14 @@ | ... | @@ -515,14 +515,14 @@ |
515 | "A container controlling performance metric throttle."; | 515 | "A container controlling performance metric throttle."; |
516 | container performance-metric-throttle { | 516 | container performance-metric-throttle { |
517 | if-feature te-performance-metric; | 517 | if-feature te-performance-metric; |
518 | - /*must "suppression-interval >= measure-interval" { | 518 | + must "suppression-interval >= measure-interval" { |
519 | error-message | 519 | error-message |
520 | "suppression-interval cannot be less then | 520 | "suppression-interval cannot be less then |
521 | measure-interval."; | 521 | measure-interval."; |
522 | description | 522 | description |
523 | "Constraint on suppression-interval and | 523 | "Constraint on suppression-interval and |
524 | measure-interval."; | 524 | measure-interval."; |
525 | - }*/ | 525 | + } |
526 | description | 526 | description |
527 | "Link performance information in real time."; | 527 | "Link performance information in real time."; |
528 | reference | 528 | reference |
... | @@ -549,7 +549,7 @@ | ... | @@ -549,7 +549,7 @@ |
549 | } | 549 | } |
550 | leaf suppression-interval { | 550 | leaf suppression-interval { |
551 | type uint32 { | 551 | type uint32 { |
552 | - range "1..max"; | 552 | + range "1 .. max"; |
553 | } | 553 | } |
554 | default 120; | 554 | default 120; |
555 | description | 555 | description |
... | @@ -633,13 +633,25 @@ | ... | @@ -633,13 +633,25 @@ |
633 | "Identify the sequence in the bundle."; | 633 | "Identify the sequence in the bundle."; |
634 | } | 634 | } |
635 | leaf src-tp-ref { | 635 | leaf src-tp-ref { |
636 | - type nt:tp-id; | 636 | + type leafref { |
637 | + path "../../../../../../nw:node[nw:node-id = " | ||
638 | + + "current()/../../../../../nt:source/" | ||
639 | + + "nt:source-node]/" | ||
640 | + + "nt:termination-point/nt:tp-id"; | ||
641 | + require-instance true; | ||
642 | + } | ||
637 | description | 643 | description |
638 | "Reference to another TE termination point on the | 644 | "Reference to another TE termination point on the |
639 | same souruce node."; | 645 | same souruce node."; |
640 | } | 646 | } |
641 | leaf des-tp-ref { | 647 | leaf des-tp-ref { |
642 | - type nt:tp-id; | 648 | + type leafref { |
649 | + path "../../../../../../nw:node[nw:node-id = " | ||
650 | + + "current()/../../../../../nt:destination/" | ||
651 | + + "nt:dest-node]/" | ||
652 | + + "nt:termination-point/nt:tp-id"; | ||
653 | + require-instance true; | ||
654 | + } | ||
643 | description | 655 | description |
644 | "Reference to another TE termination point on the | 656 | "Reference to another TE termination point on the |
645 | same destination node."; | 657 | same destination node."; |
... | @@ -682,7 +694,9 @@ | ... | @@ -682,7 +694,9 @@ |
682 | 694 | ||
683 | leaf-list te-link-template { | 695 | leaf-list te-link-template { |
684 | if-feature template; | 696 | if-feature template; |
685 | - type te-template-name; | 697 | + type leafref { |
698 | + path "../../../../../te/templates/link-template/name"; | ||
699 | + } | ||
686 | description | 700 | description |
687 | "The reference to a TE link template."; | 701 | "The reference to a TE link template."; |
688 | } | 702 | } |
... | @@ -862,12 +876,16 @@ | ... | @@ -862,12 +876,16 @@ |
862 | RFC4203: OSPF Extensions in Support of Generalized | 876 | RFC4203: OSPF Extensions in Support of Generalized |
863 | Multi-Protocol Label Switching (GMPLS)."; | 877 | Multi-Protocol Label Switching (GMPLS)."; |
864 | leaf switching-capability { | 878 | leaf switching-capability { |
865 | - type string; | 879 | + type identityref { |
880 | + base te-types:switching-capabilities; | ||
881 | + } | ||
866 | description | 882 | description |
867 | "Switching Capability for this interface."; | 883 | "Switching Capability for this interface."; |
868 | } | 884 | } |
869 | leaf encoding { | 885 | leaf encoding { |
870 | - type string; | 886 | + type identityref { |
887 | + base te-types:lsp-encoding-types; | ||
888 | + } | ||
871 | description | 889 | description |
872 | "Encoding supported by this interface."; | 890 | "Encoding supported by this interface."; |
873 | } | 891 | } |
... | @@ -929,12 +947,16 @@ | ... | @@ -929,12 +947,16 @@ |
929 | "RFC6001: Generalized MPLS (GMPLS) Protocol Extensions | 947 | "RFC6001: Generalized MPLS (GMPLS) Protocol Extensions |
930 | for Multi-Layer and Multi-Region Networks (MLN/MRN)."; | 948 | for Multi-Layer and Multi-Region Networks (MLN/MRN)."; |
931 | leaf upper-sc { | 949 | leaf upper-sc { |
932 | - type string; | 950 | + type identityref { |
951 | + base te-types:switching-capabilities; | ||
952 | + } | ||
933 | description | 953 | description |
934 | "Switching Capability for this interface."; | 954 | "Switching Capability for this interface."; |
935 | } | 955 | } |
936 | leaf upper-encoding { | 956 | leaf upper-encoding { |
937 | - type string; | 957 | + type identityref { |
958 | + base te-types:lsp-encoding-types; | ||
959 | + } | ||
938 | description | 960 | description |
939 | "Encoding supported by this interface."; | 961 | "Encoding supported by this interface."; |
940 | } | 962 | } |
... | @@ -1140,13 +1162,17 @@ | ... | @@ -1140,13 +1162,17 @@ |
1140 | 1162 | ||
1141 | uses te-node-tunnel-termination-capability; | 1163 | uses te-node-tunnel-termination-capability; |
1142 | leaf switching-capability { | 1164 | leaf switching-capability { |
1143 | - type string; | 1165 | + type identityref { |
1166 | + base te-types:switching-capabilities; | ||
1167 | + } | ||
1144 | mandatory true; | 1168 | mandatory true; |
1145 | description | 1169 | description |
1146 | "Switching Capability."; | 1170 | "Switching Capability."; |
1147 | } | 1171 | } |
1148 | leaf encoding { | 1172 | leaf encoding { |
1149 | - type string; | 1173 | + type identityref { |
1174 | + base te-types:lsp-encoding-types; | ||
1175 | + } | ||
1150 | mandatory true; | 1176 | mandatory true; |
1151 | description | 1177 | description |
1152 | "Encoding type."; | 1178 | "Encoding type."; |
... | @@ -1162,7 +1188,9 @@ | ... | @@ -1162,7 +1188,9 @@ |
1162 | 1188 | ||
1163 | leaf-list te-node-template { | 1189 | leaf-list te-node-template { |
1164 | if-feature template; | 1190 | if-feature template; |
1165 | - type te-template-name; | 1191 | + type leafref { |
1192 | + path "../../../../../te/templates/node-template/name"; | ||
1193 | + } | ||
1166 | description | 1194 | description |
1167 | "The reference to a TE node template."; | 1195 | "The reference to a TE node template."; |
1168 | } | 1196 | } |
... | @@ -1231,7 +1259,9 @@ | ... | @@ -1231,7 +1259,9 @@ |
1231 | } | 1259 | } |
1232 | container from { | 1260 | container from { |
1233 | leaf tp-ref { | 1261 | leaf tp-ref { |
1234 | - type nt:tp-id; | 1262 | + type leafref { |
1263 | + path "../../../../../../nt:termination-point/nt:tp-id"; | ||
1264 | + } | ||
1235 | description | 1265 | description |
1236 | "Relative reference to source termination point."; | 1266 | "Relative reference to source termination point."; |
1237 | } | 1267 | } |
... | @@ -1240,7 +1270,9 @@ | ... | @@ -1240,7 +1270,9 @@ |
1240 | } | 1270 | } |
1241 | container to { | 1271 | container to { |
1242 | leaf tp-ref { | 1272 | leaf tp-ref { |
1243 | - type nt:tp-id; | 1273 | + type leafref { |
1274 | + path "../../../../../../nt:termination-point/nt:tp-id"; | ||
1275 | + } | ||
1244 | description | 1276 | description |
1245 | "Relative reference to destination termination point."; | 1277 | "Relative reference to destination termination point."; |
1246 | } | 1278 | } |
... | @@ -1402,7 +1434,9 @@ | ... | @@ -1402,7 +1434,9 @@ |
1402 | The capability information can be used to compute | 1434 | The capability information can be used to compute |
1403 | the tunnel path."; | 1435 | the tunnel path."; |
1404 | leaf link-tp { | 1436 | leaf link-tp { |
1405 | - type nt:tp-id; | 1437 | + type leafref { |
1438 | + path "../../../../../nt:termination-point/nt:tp-id"; | ||
1439 | + } | ||
1406 | description | 1440 | description |
1407 | "Link termination point."; | 1441 | "Link termination point."; |
1408 | } | 1442 | } |
... | @@ -1562,22 +1596,37 @@ | ... | @@ -1562,22 +1596,37 @@ |
1562 | description | 1596 | description |
1563 | "References a TE topology."; | 1597 | "References a TE topology."; |
1564 | leaf provider-id-ref { | 1598 | leaf provider-id-ref { |
1565 | - type te-global-id; | 1599 | + type leafref { |
1600 | + path "/nw:networks/nw:network[nw:network-id = " | ||
1601 | + + "current()/../network-id-ref]/tet:te/tet:provider-id"; | ||
1602 | + require-instance false; | ||
1603 | + } | ||
1566 | description | 1604 | description |
1567 | "A reference to a provider-id."; | 1605 | "A reference to a provider-id."; |
1568 | } | 1606 | } |
1569 | leaf client-id-ref { | 1607 | leaf client-id-ref { |
1570 | - type te-global-id; | 1608 | + type leafref { |
1609 | + path "/nw:networks/nw:network[nw:network-id = " | ||
1610 | + + "current()/../network-id-ref]/tet:te/tet:client-id"; | ||
1611 | + require-instance false; | ||
1612 | + } | ||
1571 | description | 1613 | description |
1572 | "A reference to a client-id."; | 1614 | "A reference to a client-id."; |
1573 | } | 1615 | } |
1574 | leaf te-topology-id-ref { | 1616 | leaf te-topology-id-ref { |
1575 | - type tet:te-topology-id; | 1617 | + type leafref { |
1618 | + path "/nw:networks/nw:network[nw:network-id = " | ||
1619 | + + "current()/../network-id-ref]/tet:te/tet:te-topology-id"; | ||
1620 | + require-instance false; | ||
1621 | + } | ||
1576 | description | 1622 | description |
1577 | "A reference to a te-topology-id."; | 1623 | "A reference to a te-topology-id."; |
1578 | } | 1624 | } |
1579 | leaf network-id-ref { | 1625 | leaf network-id-ref { |
1580 | - type nw:network-id; | 1626 | + type leafref { |
1627 | + path "/nw:networks/nw:network/nw:network-id"; | ||
1628 | + require-instance false; | ||
1629 | + } | ||
1581 | description | 1630 | description |
1582 | "A reference to a network-id in base ietf-network module."; | 1631 | "A reference to a network-id in base ietf-network module."; |
1583 | } | 1632 | } | ... | ... |
... | @@ -580,7 +580,7 @@ | ... | @@ -580,7 +580,7 @@ |
580 | 580 | ||
581 | typedef admin-group { | 581 | typedef admin-group { |
582 | type binary { | 582 | type binary { |
583 | - length 32; | 583 | + length 32; |
584 | } | 584 | } |
585 | description | 585 | description |
586 | "Administrative group/Resource class/Color."; | 586 | "Administrative group/Resource class/Color."; |
... | @@ -680,12 +680,18 @@ | ... | @@ -680,12 +680,18 @@ |
680 | "The tunnel path hop limit."; | 680 | "The tunnel path hop limit."; |
681 | } | 681 | } |
682 | leaf metric-type { | 682 | leaf metric-type { |
683 | - type string; | 683 | + type identityref { |
684 | + base path-metric-type; | ||
685 | + } | ||
686 | + default path-metric-te; | ||
684 | description | 687 | description |
685 | "The tunnel path metric type."; | 688 | "The tunnel path metric type."; |
686 | } | 689 | } |
687 | leaf tiebreaker-type { | 690 | leaf tiebreaker-type { |
688 | - type string; | 691 | + type identityref { |
692 | + base path-tiebreaker-type; | ||
693 | + } | ||
694 | + default path-tiebreaker-maxfill; | ||
689 | description | 695 | description |
690 | "The tunnel path computation tie breakers."; | 696 | "The tunnel path computation tie breakers."; |
691 | } | 697 | } |
... | @@ -729,7 +735,9 @@ | ... | @@ -729,7 +735,9 @@ |
729 | list constraints { | 735 | list constraints { |
730 | key "usage"; | 736 | key "usage"; |
731 | leaf usage { | 737 | leaf usage { |
732 | - type string; | 738 | + type identityref { |
739 | + base resource-affinities-type; | ||
740 | + } | ||
733 | description "Affinities usage"; | 741 | description "Affinities usage"; |
734 | } | 742 | } |
735 | container constraint { | 743 | container constraint { |
... | @@ -765,7 +773,9 @@ | ... | @@ -765,7 +773,9 @@ |
765 | "Type of SRLG representation"; | 773 | "Type of SRLG representation"; |
766 | case values { | 774 | case values { |
767 | leaf usage { | 775 | leaf usage { |
768 | - type string; | 776 | + type identityref { |
777 | + base route-exclude-srlg; | ||
778 | + } | ||
769 | description "SRLG usage"; | 779 | description "SRLG usage"; |
770 | } | 780 | } |
771 | leaf-list values { | 781 | leaf-list values { |
... | @@ -777,7 +787,9 @@ | ... | @@ -777,7 +787,9 @@ |
777 | list constraints { | 787 | list constraints { |
778 | key "usage"; | 788 | key "usage"; |
779 | leaf usage { | 789 | leaf usage { |
780 | - type string; | 790 | + type identityref { |
791 | + base route-exclude-srlg; | ||
792 | + } | ||
781 | description "SRLG usage"; | 793 | description "SRLG usage"; |
782 | } | 794 | } |
783 | container constraint { | 795 | container constraint { |
... | @@ -829,12 +841,17 @@ | ... | @@ -829,12 +841,17 @@ |
829 | source."; | 841 | source."; |
830 | } | 842 | } |
831 | leaf type { | 843 | leaf type { |
832 | - type string; | 844 | + type identityref { |
845 | + base bidir-association-type; | ||
846 | + } | ||
847 | + default bidir-assoc-non-corouted; | ||
833 | description | 848 | description |
834 | "The TE tunnel association type."; | 849 | "The TE tunnel association type."; |
835 | } | 850 | } |
836 | leaf provisioing { | 851 | leaf provisioing { |
837 | - type string; | 852 | + type identityref { |
853 | + base bidir-provisioning-mode; | ||
854 | + } | ||
838 | description | 855 | description |
839 | "Describes the provisioning model of the | 856 | "Describes the provisioning model of the |
840 | associated bidirectional LSP"; | 857 | associated bidirectional LSP"; | ... | ... |
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 |
... | @@ -5,7 +5,7 @@ module module1 { | ... | @@ -5,7 +5,7 @@ module module1 { |
5 | import module2 { | 5 | import module2 { |
6 | prefix "nt"; | 6 | prefix "nt"; |
7 | } | 7 | } |
8 | - grouping te-node-tunnel-termination-capability { | 8 | + container te-node-tunnel-termination-capability { |
9 | description | 9 | description |
10 | "Termination capability of a tunnel termination point on a | 10 | "Termination capability of a tunnel termination point on a |
11 | TE node."; | 11 | TE node."; |
... | @@ -25,4 +25,4 @@ module module1 { | ... | @@ -25,4 +25,4 @@ module module1 { |
25 | } | 25 | } |
26 | } // termination-capability | 26 | } // termination-capability |
27 | } // te-node-tunnel-termination-capability | 27 | } // te-node-tunnel-termination-capability |
28 | -} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
28 | +} | ... | ... |
... | @@ -5,7 +5,7 @@ module ietf-network-topology { | ... | @@ -5,7 +5,7 @@ module ietf-network-topology { |
5 | import ietf-network { | 5 | import ietf-network { |
6 | prefix "nt"; | 6 | prefix "nt"; |
7 | } | 7 | } |
8 | - grouping te-node-tunnel-termination-capability { | 8 | + container te-node-tunnel-termination-capability { |
9 | description | 9 | description |
10 | "Termination capability of a tunnel termination point on a | 10 | "Termination capability of a tunnel termination point on a |
11 | TE node."; | 11 | TE node."; |
... | @@ -25,4 +25,4 @@ module ietf-network-topology { | ... | @@ -25,4 +25,4 @@ module ietf-network-topology { |
25 | } | 25 | } |
26 | } // termination-capability | 26 | } // termination-capability |
27 | } // te-node-tunnel-termination-capability | 27 | } // te-node-tunnel-termination-capability |
28 | -} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
28 | +} | ... | ... |
1 | +module GroupingCopiedInModule2 { | ||
2 | + yang-version 1; | ||
3 | + namespace "onos-yang-19:level1:newlevel"; | ||
4 | + prefix test; | ||
5 | + import LeafrefInGroupingOfModule1 { | ||
6 | + prefix module1; | ||
7 | + } | ||
8 | + description "leaf scenario"; | ||
9 | + container value { | ||
10 | + uses "module1:network-ref"; | ||
11 | + } | ||
12 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | -module ietf-network { | 1 | +module LeafrefInGroupingOfModule1 { |
2 | yang-version 1; | 2 | yang-version 1; |
3 | - namespace "urn:ietf:params:xml:ns:yang:ietf-network"; | 3 | + namespace "onos-yang-19:level1:newlevel"; |
4 | - prefix nd; | 4 | + prefix test2; |
5 | - rpc networks { | 5 | + description "leaf scenario"; |
6 | - description | 6 | + container networks { |
7 | - "Serves as top-level container for a list of networks."; | 7 | + list network { |
8 | - grouping input { | 8 | + key "network-id"; |
9 | - leaf network-id { | 9 | + description |
10 | - type string; | 10 | + "Describes a network. |
11 | + A network typically contains an inventory of nodes, | ||
12 | + topological information (augmented through | ||
13 | + network-topology model), as well as layering | ||
14 | + information."; | ||
15 | + container network-types { | ||
11 | description | 16 | description |
12 | - "Identifies a network."; | 17 | + "Serves as an augmentation target. |
18 | + The network type is indicated through corresponding | ||
19 | + presence containers augmented into this container."; | ||
13 | } | 20 | } |
14 | - } | ||
15 | - input { | ||
16 | leaf network-id { | 21 | leaf network-id { |
17 | - type uint8; | 22 | + type string; |
18 | description | 23 | description |
19 | "Identifies a network."; | 24 | "Identifies a network."; |
20 | } | 25 | } |
21 | } | 26 | } |
22 | - output { | 27 | + leaf network-ip { |
28 | + type uint8; | ||
29 | + description | ||
30 | + "Identifies a network."; | ||
23 | } | 31 | } |
24 | } | 32 | } |
25 | - leaf network-ref { | 33 | + grouping network-ref { |
26 | - type leafref { | 34 | + leaf network-ref { |
27 | - path "/networks/input/network-id"; | 35 | + type leafref { |
36 | + path "/test2:networks/test2:network/test2:network-id"; | ||
37 | + } | ||
28 | } | 38 | } |
29 | } | 39 | } |
30 | } | 40 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
1 | +module ietf-te-topology { | ||
2 | + yang-version 1; | ||
3 | + namespace "onos-yang-19:level1:newlevel"; | ||
4 | + prefix test; | ||
5 | + import ietf-network { | ||
6 | + prefix "nw"; | ||
7 | + } | ||
8 | + description "leaf scenario"; | ||
9 | + typedef te-topology-event-type { | ||
10 | + type enumeration { | ||
11 | + enum "add" { | ||
12 | + value 0; | ||
13 | + description | ||
14 | + "A TE node or te-link has been added."; | ||
15 | + } | ||
16 | + enum "remove" { | ||
17 | + value 1; | ||
18 | + description | ||
19 | + "A TE node or te-link has been removed."; | ||
20 | + } | ||
21 | + enum "update" { | ||
22 | + value 2; | ||
23 | + description | ||
24 | + "A TE node or te-link has been updated."; | ||
25 | + } | ||
26 | + } | ||
27 | + description "TE Event type for notifications"; | ||
28 | + } // te-topology-event-type | ||
29 | + container te-node-event { | ||
30 | + leaf event-type { | ||
31 | + type te-topology-event-type; | ||
32 | + description "Event type."; | ||
33 | + } | ||
34 | + description "Notification event for TE node."; | ||
35 | + uses nw:node-ref; | ||
36 | + } | ||
37 | +} |
1 | + module ietf-network { | ||
2 | + yang-version 1; | ||
3 | + namespace "urn:ietf:params:xml:ns:yang:ietf-network"; | ||
4 | + prefix nd; | ||
5 | + | ||
6 | + organization | ||
7 | + "IETF I2RS (Interface to the Routing System) Working Group"; | ||
8 | + | ||
9 | + contact | ||
10 | + "WG Web: <http://tools.ietf.org/wg/i2rs/> | ||
11 | + WG List: <mailto:i2rs@ietf.org> | ||
12 | + | ||
13 | + WG Chair: Susan Hares | ||
14 | + <mailto:shares@ndzh.com> | ||
15 | + | ||
16 | + WG Chair: Jeffrey Haas | ||
17 | + <mailto:jhaas@pfrc.org> | ||
18 | + | ||
19 | + Editor: Alexander Clemm | ||
20 | + <mailto:alex@cisco.com> | ||
21 | + | ||
22 | + Editor: Jan Medved | ||
23 | + <mailto:jmedved@cisco.com> | ||
24 | + | ||
25 | + Editor: Robert Varga | ||
26 | + <mailto:rovarga@cisco.com> | ||
27 | + | ||
28 | + Editor: Tony Tkacik | ||
29 | + <mailto:ttkacik@cisco.com> | ||
30 | + | ||
31 | + Editor: Nitin Bahadur | ||
32 | + <mailto:nitin_bahadur@yahoo.com> | ||
33 | + | ||
34 | + Editor: Hariharan Ananthakrishnan | ||
35 | + <mailto:hari@packetdesign.com>"; | ||
36 | + | ||
37 | + description | ||
38 | + "This module defines a common base model for a collection | ||
39 | + of nodes in a network. Node definitions are further used | ||
40 | + in network topologies and inventories. | ||
41 | + | ||
42 | + Copyright (c) 2015 IETF Trust and the persons identified as | ||
43 | + authors of the code. All rights reserved. | ||
44 | + | ||
45 | + Redistribution and use in source and binary forms, with or | ||
46 | + without modification, is permitted pursuant to, and subject | ||
47 | + to the license terms contained in, the Simplified BSD License | ||
48 | + set forth in Section 4.c of the IETF Trust's Legal Provisions | ||
49 | + Relating to IETF Documents | ||
50 | + (http://trustee.ietf.org/license-info). | ||
51 | + | ||
52 | + This version of this YANG module is part of | ||
53 | + draft-ietf-i2rs-yang-network-topo-02; | ||
54 | + see the RFC itself for full legal notices. | ||
55 | + | ||
56 | + NOTE TO RFC EDITOR: Please replace above reference to | ||
57 | + draft-ietf-i2rs-yang-network-topo-02 with RFC | ||
58 | + number when published (i.e. RFC xxxx)."; | ||
59 | + | ||
60 | + revision 2015-12-08 { | ||
61 | + description | ||
62 | + "Initial revision. | ||
63 | + NOTE TO RFC EDITOR: Please replace the following reference | ||
64 | + to draft-ietf-i2rs-yang-network-topo-02 with | ||
65 | + RFC number when published (i.e. RFC xxxx)."; | ||
66 | + reference | ||
67 | + "draft-ietf-i2rs-yang-network-topo-02"; | ||
68 | + } | ||
69 | + | ||
70 | + typedef node-id { | ||
71 | + type string; | ||
72 | + description | ||
73 | + "Identifier for a node."; | ||
74 | + } | ||
75 | + | ||
76 | + typedef network-id { | ||
77 | + type string; | ||
78 | + description | ||
79 | + "Identifier for a network."; | ||
80 | + } | ||
81 | + grouping network-ref { | ||
82 | + description | ||
83 | + "Contains the information necessary to reference a network, | ||
84 | + for example an underlay network."; | ||
85 | + leaf network-ref { | ||
86 | + type leafref { | ||
87 | + path "/nd:networks/nd:network/nd:network-id"; | ||
88 | + require-instance false; | ||
89 | + } | ||
90 | + description | ||
91 | + "Used to reference a network, for example an underlay | ||
92 | + network."; | ||
93 | + } | ||
94 | + } | ||
95 | + | ||
96 | + grouping node-ref { | ||
97 | + description | ||
98 | + "Contains the information necessary to reference a node."; | ||
99 | + leaf node-ref { | ||
100 | + type leafref { | ||
101 | + path "/nd:networks/nd:network[nd:network-id=current()/../"+ | ||
102 | + "network-ref]/nd:node/nd:node-id"; | ||
103 | + require-instance false; | ||
104 | + } | ||
105 | + description | ||
106 | + "Used to reference a node. | ||
107 | + Nodes are identified relative to the network they are | ||
108 | + contained in."; | ||
109 | + } | ||
110 | + uses network-ref; | ||
111 | + } | ||
112 | + | ||
113 | + container networks { | ||
114 | + description | ||
115 | + "Serves as top-level container for a list of networks."; | ||
116 | + list network { | ||
117 | + key "network-id"; | ||
118 | + description | ||
119 | + "Describes a network. | ||
120 | + A network typically contains an inventory of nodes, | ||
121 | + topological information (augmented through | ||
122 | + network-topology model), as well as layering | ||
123 | + information."; | ||
124 | + container network-types { | ||
125 | + description | ||
126 | + "Serves as an augmentation target. | ||
127 | + The network type is indicated through corresponding | ||
128 | + presence containers augmented into this container."; | ||
129 | + } | ||
130 | + leaf network-id { | ||
131 | + type network-id; | ||
132 | + description | ||
133 | + "Identifies a network."; | ||
134 | + } | ||
135 | + list supporting-network { | ||
136 | + key "network-ref"; | ||
137 | + description | ||
138 | + "An underlay network, used to represent layered network | ||
139 | + topologies."; | ||
140 | + leaf network-ref { | ||
141 | + type leafref { | ||
142 | + path "/networks/network/network-id"; | ||
143 | + require-instance false; | ||
144 | + } | ||
145 | + description | ||
146 | + "References the underlay network."; | ||
147 | + } | ||
148 | + } | ||
149 | + list node { | ||
150 | + key "node-id"; | ||
151 | + description | ||
152 | + "The inventory of nodes of this network."; | ||
153 | + leaf node-id { | ||
154 | + type node-id; | ||
155 | + description | ||
156 | + "Identifies a node uniquely within the containing | ||
157 | + network."; | ||
158 | + } | ||
159 | + list supporting-node { | ||
160 | + key "network-ref node-ref"; | ||
161 | + description | ||
162 | + "Represents another node, in an underlay network, that | ||
163 | + this node is supported by. Used to represent layering | ||
164 | + structure."; | ||
165 | + leaf network-ref { | ||
166 | + type leafref { | ||
167 | + path "../../../supporting-network/network-ref"; | ||
168 | + require-instance false; | ||
169 | + } | ||
170 | + description | ||
171 | + "References the underlay network that the | ||
172 | + underlay node is part of."; | ||
173 | + } | ||
174 | + leaf node-ref { | ||
175 | + type leafref { | ||
176 | + path "/networks/network/node/node-id"; | ||
177 | + require-instance false; | ||
178 | + } | ||
179 | + description | ||
180 | + "References the underlay node itself."; | ||
181 | + } | ||
182 | + } | ||
183 | + } | ||
184 | + } | ||
185 | + } | ||
186 | + container networks-state { | ||
187 | + config false; | ||
188 | + description | ||
189 | + "Serves as top-level container for a list of state information | ||
190 | + for networks"; | ||
191 | + list network { | ||
192 | + key "network-ref"; | ||
193 | + description | ||
194 | + "Data nodes representing operational data and state of | ||
195 | + networks. | ||
196 | + An instance is automatically created for every network | ||
197 | + in the corresponding list under the networks container."; | ||
198 | + uses network-ref; | ||
199 | + leaf server-provided { | ||
200 | + type boolean; | ||
201 | + description | ||
202 | + "Indicates whether the information concerning this | ||
203 | + particular network is populated by the server | ||
204 | + (server-provided true, the general case for network | ||
205 | + information discovered from the server), | ||
206 | + or whether it is configured by a client | ||
207 | + (server-provided true, possible e.g. for | ||
208 | + service overlays managed through a controller)."; | ||
209 | + } | ||
210 | + } | ||
211 | + } | ||
212 | + } |
1 | -module ietf-network { | 1 | +module SelfResolutionWhenLeafrefInModuleReferToGroupingInModule { |
2 | yang-version 1; | 2 | yang-version 1; |
3 | namespace "urn:ietf:params:xml:ns:yang:ietf-network"; | 3 | namespace "urn:ietf:params:xml:ns:yang:ietf-network"; |
4 | prefix nd; | 4 | prefix nd; |
... | @@ -16,4 +16,4 @@ module ietf-network { | ... | @@ -16,4 +16,4 @@ module ietf-network { |
16 | } | 16 | } |
17 | } | 17 | } |
18 | } | 18 | } |
19 | -} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
19 | +} | ... | ... |
1 | -module ietf-network { | 1 | +module SelfResolutionWhenLeafrefInModuleReferToInvalidNode { |
2 | yang-version 1; | 2 | yang-version 1; |
3 | namespace "urn:ietf:params:xml:ns:yang:ietf-network"; | 3 | namespace "urn:ietf:params:xml:ns:yang:ietf-network"; |
4 | prefix nd; | 4 | prefix nd; |
... | @@ -16,4 +16,4 @@ module ietf-network { | ... | @@ -16,4 +16,4 @@ module ietf-network { |
16 | path "/define/network-id"; | 16 | path "/define/network-id"; |
17 | } | 17 | } |
18 | } | 18 | } |
19 | -} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
19 | +} | ... | ... |
1 | +module topology { | ||
2 | + yang-version 1; | ||
3 | + namespace "onos-yang-19:level1:newlevel"; | ||
4 | + prefix test; | ||
5 | + organization "huawei"; | ||
6 | + contact "adarsh.m@huawei.com"; | ||
7 | + description "leaf scenario"; | ||
8 | + container networks { | ||
9 | + list network { | ||
10 | + key "network-id"; | ||
11 | + description | ||
12 | + "Describes a network. | ||
13 | + A network typically contains an inventory of nodes, | ||
14 | + topological information (augmented through | ||
15 | + network-topology model), as well as layering | ||
16 | + information."; | ||
17 | + container network-types { | ||
18 | + description | ||
19 | + "Serves as an augmentation target. | ||
20 | + The network type is indicated through corresponding | ||
21 | + presence containers augmented into this container."; | ||
22 | + } | ||
23 | + leaf network-id { | ||
24 | + type string; | ||
25 | + description | ||
26 | + "Identifies a network."; | ||
27 | + } | ||
28 | + } | ||
29 | + leaf network-ip { | ||
30 | + type uint8; | ||
31 | + description | ||
32 | + "Identifies a network."; | ||
33 | + } | ||
34 | + } | ||
35 | + augment "/networks/network" { | ||
36 | + container config { | ||
37 | + description | ||
38 | + "Configuration data."; | ||
39 | + choice bundle-stack-level { | ||
40 | + description | ||
41 | + "The TE link can be partitioned into bundled | ||
42 | + links, or component links."; | ||
43 | + case bundle { | ||
44 | + container bundled-links { | ||
45 | + description | ||
46 | + "A set of bundled links."; | ||
47 | + reference | ||
48 | + "RFC4201: Link Bundling in MPLS Traffic Engineering | ||
49 | + (TE)."; | ||
50 | + list bundled-link { | ||
51 | + key "src-tp-ref"; | ||
52 | + leaf src-tp-ref { | ||
53 | + type leafref { | ||
54 | + path "../../../../../network-ip"; | ||
55 | + require-instance true; | ||
56 | + } | ||
57 | + } | ||
58 | + } | ||
59 | + } | ||
60 | + } | ||
61 | + } | ||
62 | + } | ||
63 | + } | ||
64 | +} | ||
... | \ 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 | + | ||
6 | + import ietf-inet-types { | ||
7 | + prefix inet; | ||
8 | + } | ||
9 | + typedef node-id { | ||
10 | + type inet:uri; | ||
11 | + description | ||
12 | + "Identifier for a node."; | ||
13 | + } | ||
14 | + | ||
15 | + leaf xyz { | ||
16 | + type string; | ||
17 | + } | ||
18 | + typedef network-id { | ||
19 | + type inet:uri; | ||
20 | + description | ||
21 | + "Identifier for a network."; | ||
22 | + } | ||
23 | + grouping network-ref { | ||
24 | + description | ||
25 | + "Contains the information necessary to reference a network, | ||
26 | + for example an underlay network."; | ||
27 | + leaf network-ref { | ||
28 | + type leafref { | ||
29 | + path "/nd:xyz"; | ||
30 | + require-instance false; | ||
31 | + } | ||
32 | + description | ||
33 | + "Used to reference a network, for example an underlay | ||
34 | + network."; | ||
35 | + } | ||
36 | + } | ||
37 | + } |
1 | +module ietf-network { | ||
2 | + yang-version 1; | ||
3 | + namespace "urn:ietf:params:xml:ns:yang:ietf-network"; | ||
4 | + prefix nd; | ||
5 | + import network { | ||
6 | + prefix "nw"; | ||
7 | + } | ||
8 | + grouping xyz { | ||
9 | + leaf network-id-ref { | ||
10 | + type leafref { | ||
11 | + path "/nw:networks/nw:network/nw:network-id"; | ||
12 | + require-instance false; | ||
13 | + } | ||
14 | + description | ||
15 | + "A reference to a network-id in base ietf-network module."; | ||
16 | + } | ||
17 | + } | ||
18 | + grouping yzx { | ||
19 | + container hi { | ||
20 | + uses xyz; | ||
21 | + } | ||
22 | + } | ||
23 | + container fine { | ||
24 | + uses yzx; | ||
25 | + } | ||
26 | + container networks { | ||
27 | + leaf network { | ||
28 | + type string; | ||
29 | + } | ||
30 | + } | ||
31 | +} | ||
32 | + | ||
33 | + |
1 | + module network { | ||
2 | + yang-version 1; | ||
3 | + namespace "urn:ietf:params:xml:ns:yang:ietf-network"; | ||
4 | + prefix nd; | ||
5 | + | ||
6 | + organization | ||
7 | + "IETF I2RS (Interface to the Routing System) Working Group"; | ||
8 | + | ||
9 | + contact | ||
10 | + "WG Web: <http://tools.ietf.org/wg/i2rs/> | ||
11 | + WG List: <mailto:i2rs@ietf.org> | ||
12 | + | ||
13 | + WG Chair: Susan Hares | ||
14 | + <mailto:shares@ndzh.com> | ||
15 | + | ||
16 | + WG Chair: Jeffrey Haas | ||
17 | + <mailto:jhaas@pfrc.org> | ||
18 | + | ||
19 | + Editor: Alexander Clemm | ||
20 | + <mailto:alex@cisco.com> | ||
21 | + | ||
22 | + Editor: Jan Medved | ||
23 | + <mailto:jmedved@cisco.com> | ||
24 | + | ||
25 | + Editor: Robert Varga | ||
26 | + <mailto:rovarga@cisco.com> | ||
27 | + | ||
28 | + Editor: Tony Tkacik | ||
29 | + <mailto:ttkacik@cisco.com> | ||
30 | + | ||
31 | + Editor: Nitin Bahadur | ||
32 | + <mailto:nitin_bahadur@yahoo.com> | ||
33 | + | ||
34 | + Editor: Hariharan Ananthakrishnan | ||
35 | + <mailto:hari@packetdesign.com>"; | ||
36 | + | ||
37 | + description | ||
38 | + "This module defines a common base model for a collection | ||
39 | + of nodes in a network. Node definitions are further used | ||
40 | + in network topologies and inventories. | ||
41 | + | ||
42 | + Copyright (c) 2015 IETF Trust and the persons identified as | ||
43 | + authors of the code. All rights reserved. | ||
44 | + | ||
45 | + Redistribution and use in source and binary forms, with or | ||
46 | + without modification, is permitted pursuant to, and subject | ||
47 | + to the license terms contained in, the Simplified BSD License | ||
48 | + set forth in Section 4.c of the IETF Trust's Legal Provisions | ||
49 | + Relating to IETF Documents | ||
50 | + (http://trustee.ietf.org/license-info). | ||
51 | + | ||
52 | + This version of this YANG module is part of | ||
53 | + draft-ietf-i2rs-yang-network-topo-02; | ||
54 | + see the RFC itself for full legal notices. | ||
55 | + | ||
56 | + NOTE TO RFC EDITOR: Please replace above reference to | ||
57 | + draft-ietf-i2rs-yang-network-topo-02 with RFC | ||
58 | + number when published (i.e. RFC xxxx)."; | ||
59 | + | ||
60 | + revision 2015-12-08 { | ||
61 | + description | ||
62 | + "Initial revision. | ||
63 | + NOTE TO RFC EDITOR: Please replace the following reference | ||
64 | + to draft-ietf-i2rs-yang-network-topo-02 with | ||
65 | + RFC number when published (i.e. RFC xxxx)."; | ||
66 | + reference | ||
67 | + "draft-ietf-i2rs-yang-network-topo-02"; | ||
68 | + } | ||
69 | + | ||
70 | + typedef node-id { | ||
71 | + type string; | ||
72 | + description | ||
73 | + "Identifier for a node."; | ||
74 | + } | ||
75 | + | ||
76 | + typedef network-id { | ||
77 | + type string; | ||
78 | + description | ||
79 | + "Identifier for a network."; | ||
80 | + } | ||
81 | + grouping network-ref { | ||
82 | + description | ||
83 | + "Contains the information necessary to reference a network, | ||
84 | + for example an underlay network."; | ||
85 | + leaf network-ref { | ||
86 | + type leafref { | ||
87 | + path "/nd:networks/nd:network/nd:network-id"; | ||
88 | + require-instance false; | ||
89 | + } | ||
90 | + description | ||
91 | + "Used to reference a network, for example an underlay | ||
92 | + network."; | ||
93 | + } | ||
94 | + } | ||
95 | + | ||
96 | + grouping node-ref { | ||
97 | + description | ||
98 | + "Contains the information necessary to reference a node."; | ||
99 | + leaf node-ref { | ||
100 | + type leafref { | ||
101 | + path "/nd:networks/nd:network[nd:network-id=current()/../"+ | ||
102 | + "network-ref]/nd:node/nd:node-id"; | ||
103 | + require-instance false; | ||
104 | + } | ||
105 | + description | ||
106 | + "Used to reference a node. | ||
107 | + Nodes are identified relative to the network they are | ||
108 | + contained in."; | ||
109 | + } | ||
110 | + uses network-ref; | ||
111 | + } | ||
112 | + | ||
113 | + container networks { | ||
114 | + description | ||
115 | + "Serves as top-level container for a list of networks."; | ||
116 | + list network { | ||
117 | + key "network-id"; | ||
118 | + description | ||
119 | + "Describes a network. | ||
120 | + A network typically contains an inventory of nodes, | ||
121 | + topological information (augmented through | ||
122 | + network-topology model), as well as layering | ||
123 | + information."; | ||
124 | + container network-types { | ||
125 | + description | ||
126 | + "Serves as an augmentation target. | ||
127 | + The network type is indicated through corresponding | ||
128 | + presence containers augmented into this container."; | ||
129 | + } | ||
130 | + leaf network-id { | ||
131 | + type network-id; | ||
132 | + description | ||
133 | + "Identifies a network."; | ||
134 | + } | ||
135 | + list supporting-network { | ||
136 | + key "network-ref"; | ||
137 | + description | ||
138 | + "An underlay network, used to represent layered network | ||
139 | + topologies."; | ||
140 | + leaf network-ref { | ||
141 | + type leafref { | ||
142 | + path "/networks/network/network-id"; | ||
143 | + require-instance false; | ||
144 | + } | ||
145 | + description | ||
146 | + "References the underlay network."; | ||
147 | + } | ||
148 | + } | ||
149 | + list node { | ||
150 | + key "node-id"; | ||
151 | + description | ||
152 | + "The inventory of nodes of this network."; | ||
153 | + leaf node-id { | ||
154 | + type node-id; | ||
155 | + description | ||
156 | + "Identifies a node uniquely within the containing | ||
157 | + network."; | ||
158 | + } | ||
159 | + list supporting-node { | ||
160 | + key "network-ref node-ref"; | ||
161 | + description | ||
162 | + "Represents another node, in an underlay network, that | ||
163 | + this node is supported by. Used to represent layering | ||
164 | + structure."; | ||
165 | + leaf network-ref { | ||
166 | + type leafref { | ||
167 | + path "../../../supporting-network/network-ref"; | ||
168 | + require-instance false; | ||
169 | + } | ||
170 | + description | ||
171 | + "References the underlay network that the | ||
172 | + underlay node is part of."; | ||
173 | + } | ||
174 | + leaf node-ref { | ||
175 | + type leafref { | ||
176 | + path "/networks/network/node/node-id"; | ||
177 | + require-instance false; | ||
178 | + } | ||
179 | + description | ||
180 | + "References the underlay node itself."; | ||
181 | + } | ||
182 | + } | ||
183 | + } | ||
184 | + } | ||
185 | + } | ||
186 | + container networks-state { | ||
187 | + config false; | ||
188 | + description | ||
189 | + "Serves as top-level container for a list of state information | ||
190 | + for networks"; | ||
191 | + list network { | ||
192 | + key "network-ref"; | ||
193 | + description | ||
194 | + "Data nodes representing operational data and state of | ||
195 | + networks. | ||
196 | + An instance is automatically created for every network | ||
197 | + in the corresponding list under the networks container."; | ||
198 | + uses network-ref; | ||
199 | + leaf server-provided { | ||
200 | + type boolean; | ||
201 | + description | ||
202 | + "Indicates whether the information concerning this | ||
203 | + particular network is populated by the server | ||
204 | + (server-provided true, the general case for network | ||
205 | + information discovered from the server), | ||
206 | + or whether it is configured by a client | ||
207 | + (server-provided true, possible e.g. for | ||
208 | + service overlays managed through a controller)."; | ||
209 | + } | ||
210 | + } | ||
211 | + } | ||
212 | + } | ||
... | \ 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 | + | ||
6 | + organization | ||
7 | + "IETF I2RS (Interface to the Routing System) Working Group"; | ||
8 | + grouping node-ref { | ||
9 | + description | ||
10 | + "Contains the information necessary to reference a node."; | ||
11 | + container node-from-grouping { | ||
12 | + leaf node-ref { | ||
13 | + type leafref { | ||
14 | + path "/networks/network/node/node-id"; | ||
15 | + require-instance false; | ||
16 | + } | ||
17 | + } | ||
18 | + } | ||
19 | + } | ||
20 | + container networks { | ||
21 | + description | ||
22 | + "Serves as top-level container for a list of networks."; | ||
23 | + list network { | ||
24 | + key "network-id"; | ||
25 | + description | ||
26 | + "Describes a network. | ||
27 | + A network typically contains an inventory of nodes, | ||
28 | + topological information (augmented through | ||
29 | + network-topology model), as well as layering | ||
30 | + information."; | ||
31 | + container network-types { | ||
32 | + description | ||
33 | + "Serves as an augmentation target. | ||
34 | + The network type is indicated through corresponding | ||
35 | + presence containers augmented into this container."; | ||
36 | + } | ||
37 | + leaf network-id { | ||
38 | + type string; | ||
39 | + description | ||
40 | + "Identifies a network."; | ||
41 | + } | ||
42 | + list supporting-network { | ||
43 | + key "network-ref"; | ||
44 | + description | ||
45 | + "An underlay network, used to represent layered network | ||
46 | + topologies."; | ||
47 | + leaf network-ref { | ||
48 | + type leafref { | ||
49 | + path "/networks/network/network-id"; | ||
50 | + require-instance false; | ||
51 | + } | ||
52 | + description | ||
53 | + "References the underlay network."; | ||
54 | + } | ||
55 | + } | ||
56 | + list node { | ||
57 | + key "node-id"; | ||
58 | + description | ||
59 | + "The inventory of nodes of this network."; | ||
60 | + leaf node-id { | ||
61 | + type uint8; | ||
62 | + description | ||
63 | + "Identifies a node uniquely within the containing | ||
64 | + network."; | ||
65 | + } | ||
66 | + list supporting-node { | ||
67 | + key "network-ref node-ref"; | ||
68 | + description | ||
69 | + "Represents another node, in an underlay network, that | ||
70 | + this node is supported by. Used to represent layering | ||
71 | + structure."; | ||
72 | + leaf network-ref { | ||
73 | + type leafref { | ||
74 | + path "../../../supporting-network/network-ref"; | ||
75 | + require-instance false; | ||
76 | + } | ||
77 | + description | ||
78 | + "References the underlay network that the | ||
79 | + underlay node is part of."; | ||
80 | + } | ||
81 | + leaf node-ref { | ||
82 | + type leafref { | ||
83 | + path "/networks/network/node/node-id"; | ||
84 | + require-instance false; | ||
85 | + } | ||
86 | + description | ||
87 | + "References the underlay node itself."; | ||
88 | + } | ||
89 | + } | ||
90 | + } | ||
91 | + } | ||
92 | + uses node-ref; | ||
93 | + } | ||
94 | + | ||
95 | +} |
1 | -module ietf-network { | 1 | +module SelfResolutionWhenLeafrefInModuleReferToLeafInInputOfRpc { |
2 | yang-version 1; | 2 | yang-version 1; |
3 | namespace "urn:ietf:params:xml:ns:yang:ietf-network"; | 3 | namespace "urn:ietf:params:xml:ns:yang:ietf-network"; |
4 | prefix nd; | 4 | prefix nd; |
... | @@ -20,4 +20,4 @@ module ietf-network { | ... | @@ -20,4 +20,4 @@ module ietf-network { |
20 | path "/networks/input/network-id"; | 20 | path "/networks/input/network-id"; |
21 | } | 21 | } |
22 | } | 22 | } |
23 | -} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
23 | +} | ... | ... |
1 | -module ietf-network { | 1 | +module SelfResolutionWhenLeafrefInModuleReferToGroupingWithInputInRpc { |
2 | yang-version 1; | 2 | yang-version 1; |
3 | namespace "urn:ietf:params:xml:ns:yang:ietf-network"; | 3 | namespace "urn:ietf:params:xml:ns:yang:ietf-network"; |
4 | prefix nd; | 4 | prefix nd; |
... | @@ -25,4 +25,4 @@ module ietf-network { | ... | @@ -25,4 +25,4 @@ module ietf-network { |
25 | path "/networks/input/network-id"; | 25 | path "/networks/input/network-id"; |
26 | } | 26 | } |
27 | } | 27 | } |
28 | -} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
28 | +} | ... | ... |
1 | -module ietf-network { | 1 | +module SelfResolutionWhenLeafrefReferToContainerLeaf { |
2 | yang-version 1; | 2 | yang-version 1; |
3 | namespace "urn:ietf:params:xml:ns:yang:ietf-network"; | 3 | namespace "urn:ietf:params:xml:ns:yang:ietf-network"; |
4 | prefix nd; | 4 | prefix nd; |
... | @@ -16,4 +16,4 @@ module ietf-network { | ... | @@ -16,4 +16,4 @@ module ietf-network { |
16 | path "/networks/network-id"; | 16 | path "/networks/network-id"; |
17 | } | 17 | } |
18 | } | 18 | } |
19 | -} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
19 | +} | ... | ... |
-
Please register or login to post a comment