Shankara-Huawei
Committed by Gerrit Code Review

[ONOS-4753] Identity/identityref implementation and UT

Change-Id: I40148fa228465555be3bdf410cc294ffc0f34c18
Showing 56 changed files with 2985 additions and 90 deletions
...@@ -39,5 +39,15 @@ public enum ResolvableType { ...@@ -39,5 +39,15 @@ public enum ResolvableType {
39 /** 39 /**
40 * Identifies the leafref. 40 * Identifies the leafref.
41 */ 41 */
42 - YANG_LEAFREF 42 + YANG_LEAFREF,
43 +
44 + /**
45 + * Identifies the base.
46 + */
47 + YANG_BASE,
48 +
49 + /**
50 + * Identifies the identityref.
51 + */
52 + YANG_IDENTITYREF
43 } 53 }
......
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 +package org.onosproject.yangutils.datamodel;
17 +
18 +import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
19 +import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
20 +
21 +import java.io.Serializable;
22 +
23 +/**
24 + * Reference RFC 6020.
25 + *
26 + * Represents data model node to maintain information defined in YANG base.
27 + * The "base" statement, which is optional, takes as an argument a
28 + * string that is the name of an existing identity, from which the new
29 + * identity is derived. If no "base" statement is present, the identity
30 + * is defined from scratch.
31 + *
32 + * If a prefix is present on the base name, it refers to an identity
33 + * defined in the module that was imported with that prefix, or the
34 + * local module if the prefix matches the local module's prefix.
35 + * Otherwise, an identity with the matching name MUST be defined in the
36 + * current module or an included submodule.
37 + */
38 +
39 +/**
40 + * Represents data model node to maintain information defined in YANG base.
41 + */
42 + public class YangBase implements Resolvable, Serializable {
43 +
44 + private static final long serialVersionUID = 806201693L;
45 +
46 + // YANG node identifier.
47 + private YangNodeIdentifier baseIdentifier;
48 +
49 + // Referred identity parent information.
50 + private YangIdentity referredIdentity;
51 +
52 + /**
53 + * Status of resolution. If completely resolved enum value is "RESOLVED",
54 + * if not enum value is "UNRESOLVED", in case reference of grouping/typedef/base/identityref
55 + * is added to uses/type/base/identityref but it's not resolved value of enum should be
56 + * "INTRA_FILE_RESOLVED".
57 + */
58 + private ResolvableStatus resolvableStatus;
59 +
60 + // Creates a base type of node.
61 + public YangBase() {
62 + resolvableStatus = ResolvableStatus.UNRESOLVED;
63 + }
64 +
65 + /**
66 + * Returns the YANG node identifier.
67 + *
68 + * @return the YANG node identifier
69 + */
70 + public YangNodeIdentifier getBaseIdentifier() {
71 + return baseIdentifier;
72 + }
73 +
74 + /**
75 + * Sets the YANG node identifier.
76 + *
77 + * @param baseIdentifier the YANG node identifier to set
78 + */
79 + public void setBaseIdentifier(YangNodeIdentifier baseIdentifier) {
80 + this.baseIdentifier = baseIdentifier;
81 + }
82 +
83 + /**
84 + * Returns the parent identity node.
85 + *
86 + * @return the parent identity node
87 + */
88 + public YangIdentity getReferredIdentity() {
89 + return referredIdentity;
90 + }
91 +
92 + /**
93 + * Sets the parent identity node.
94 + *
95 + * @param referredIdentity the parent identity node to set
96 + */
97 + public void setReferredIdentity(YangIdentity referredIdentity) {
98 + this.referredIdentity = referredIdentity;
99 + }
100 +
101 + @Override
102 + public ResolvableStatus getResolvableStatus() {
103 + return resolvableStatus;
104 + }
105 +
106 + @Override
107 + public void setResolvableStatus(ResolvableStatus resolvableStatus) {
108 + this.resolvableStatus = resolvableStatus;
109 + }
110 +
111 + @Override
112 + public void resolve() throws DataModelException {
113 + }
114 +}
...@@ -334,7 +334,7 @@ public class YangDerivedInfo<T> ...@@ -334,7 +334,7 @@ public class YangDerivedInfo<T>
334 return RESOLVED; 334 return RESOLVED;
335 } 335 }
336 } 336 }
337 - } else if (baseType.getDataType() == LEAFREF) { 337 + } else if ((baseType.getDataType() == LEAFREF) || (baseType.getDataType() == IDENTITYREF)) {
338 setEffectiveBuiltInType(baseType.getDataType()); 338 setEffectiveBuiltInType(baseType.getDataType());
339 return RESOLVED; 339 return RESOLVED;
340 } else { 340 } else {
......
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 +package org.onosproject.yangutils.datamodel;
17 +
18 +import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
19 +import org.onosproject.yangutils.datamodel.utils.Parsable;
20 +import org.onosproject.yangutils.datamodel.utils.YangConstructType;
21 +
22 +import java.io.Serializable;
23 +
24 +/*-
25 + * Reference RFC 6020.
26 + *
27 + * The "identity" statement is used to define a new globally unique,
28 + * abstract, and untyped identity. Its only purpose is to denote its
29 + * name, semantics, and existence. An identity can either be defined
30 + * from scratch or derived from a base identity. The identity's
31 + * argument is an identifier that is the name of the identity. It is
32 + * followed by a block of substatements that holds detailed identity
33 + * information.
34 + *
35 + * The identity's Substatements
36 + *
37 + * +--------------+---------+-------------+-----------------------+
38 + * | substatement | section | cardinality | data model mapping |
39 + * +--------------+---------+-------------+-----------------------+
40 + * | base | 7.16.2 | 0..1 | -YangNodeIdentifier |
41 + * | description | 7.19.3 | 0..1 | -string |
42 + * | reference | 7.19.4 | 0..1 | -string |
43 + * | status | 7.19.2 | 0..1 | -YangStatus |
44 + * +--------------+---------+-------------+-----------------------+
45 + */
46 +
47 +/**
48 + * Represents data model node to maintain information defined in YANG identity.
49 + */
50 +public class YangIdentity extends YangNode implements YangCommonInfo, Parsable, Serializable {
51 +
52 + private static final long serialVersionUID = 806201691L;
53 +
54 + //Name of the identity.
55 + private String name;
56 +
57 + //Base node of identity.
58 + private YangBase baseNode;
59 +
60 + //Status of YANG identity.
61 + private YangStatusType status;
62 +
63 + //Description of YANG identity.
64 + private String description;
65 +
66 + //YANG reference of the identity.
67 + private String reference;
68 +
69 + //Creates a identity type of node.
70 + public YangIdentity() {
71 + super(YangNodeType.IDENTITY_NODE);
72 + }
73 +
74 + /**
75 + * Returns the name of identity.
76 + *
77 + * @return the identity name
78 + */
79 + public String getName() {
80 + return name;
81 + }
82 +
83 + /**
84 + * Sets the name of identity.
85 + *
86 + * @param name the identity name to set
87 + */
88 + public void setName(String name) {
89 + this.name = name;
90 + }
91 +
92 + @Override
93 + public YangStatusType getStatus() {
94 + return status;
95 + }
96 +
97 + @Override
98 + public void setStatus(YangStatusType status) {
99 + this.status = status;
100 + }
101 +
102 + @Override
103 + public String getDescription() {
104 + return description;
105 + }
106 +
107 + @Override
108 + public void setDescription(String description) {
109 + this.description = description;
110 + }
111 +
112 + @Override
113 + public String getReference() {
114 + return reference;
115 + }
116 +
117 + @Override
118 + public void setReference(String reference) {
119 + this.reference = reference;
120 + }
121 +
122 + @Override
123 + public YangConstructType getYangConstructType() {
124 + return YangConstructType.IDENTITY_DATA;
125 + }
126 +
127 + @Override
128 + public void validateDataOnEntry() throws DataModelException {
129 + }
130 +
131 + @Override
132 + public void validateDataOnExit() throws DataModelException {
133 + }
134 +
135 + /**
136 + * Returns base node of identity.
137 + *
138 + * @return the base node of identity
139 + */
140 + public YangBase getBaseNode() {
141 + return baseNode;
142 + }
143 +
144 + /**
145 + * Sets the base node.
146 + *
147 + * @param baseNode the base node to set
148 + */
149 + public void setBaseNode(YangBase baseNode) {
150 + this.baseNode = baseNode;
151 + }
152 +}
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 +package org.onosproject.yangutils.datamodel;
17 +
18 +import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
19 +import org.onosproject.yangutils.datamodel.utils.Parsable;
20 +import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
21 +import org.onosproject.yangutils.datamodel.utils.YangConstructType;
22 +
23 +import java.io.Serializable;
24 +
25 +/*-
26 + * Reference RFC 6020.
27 + *
28 + * The identityref type is used to reference an existing identity.
29 + *
30 + * The identityref's base Statement :
31 + * The "base" statement, which is a substatement to the "type"
32 + * statement, MUST be present if the type is "identityref". The
33 + * argument is the name of an identity, as defined by an "identity"
34 + * statement. If a prefix is present on the identity name, it refers to
35 + * an identity defined in the module that was imported with that prefix.
36 + * Otherwise, an identity with the matching name MUST be defined in the
37 + * current module or an included submodule.
38 + * Valid values for an identityref are any identities derived from the
39 + * identityref's base identity. On a particular server, the valid
40 + * values are further restricted to the set of identities defined in the
41 + * modules supported by the server.
42 + */
43 +
44 +/**
45 + * Represents data model node to maintain information defined in YANG identityref.
46 + */
47 +public class YangIdentityRef extends YangNode implements Parsable, Resolvable, Serializable {
48 +
49 + private static final long serialVersionUID = 806201692L;
50 +
51 + // Get referred identity parent information.
52 + private YangIdentity referredIdentity;
53 +
54 + // YANG node identifier.
55 + private YangNodeIdentifier baseIdentity;
56 +
57 + /**
58 + * Status of resolution. If completely resolved enum value is "RESOLVED",
59 + * if not enum value is "UNRESOLVED", in case reference of grouping/typedef/identityref/base
60 + * is added to uses/type/identityref/base but it's not resolved value of enum should be
61 + * "INTRA_FILE_RESOLVED".
62 + */
63 + private ResolvableStatus resolvableStatus;
64 +
65 + // Creates a specific identityref of node.
66 + public YangIdentityRef() {
67 + super(YangNodeType.IDENTITYREF_NODE);
68 + baseIdentity = new YangNodeIdentifier();
69 + resolvableStatus = ResolvableStatus.UNRESOLVED;
70 + }
71 +
72 + @Override
73 + public ResolvableStatus getResolvableStatus() {
74 + return resolvableStatus;
75 + }
76 +
77 + @Override
78 + public void setResolvableStatus(ResolvableStatus resolvableStatus) {
79 + this.resolvableStatus = resolvableStatus;
80 + }
81 +
82 + @Override
83 + public void resolve() throws DataModelException {
84 +
85 + // Check if the derived info is present.
86 + YangIdentity identity = getReferredIdentity();
87 +
88 + if (identity == null) {
89 + throw new DataModelException("Linker Error: Identity information is missing.");
90 + }
91 +
92 + while (identity.getBaseNode() != null) {
93 + if (identity.getBaseNode().getResolvableStatus() != ResolvableStatus.RESOLVED) {
94 + setResolvableStatus(ResolvableStatus.INTRA_FILE_RESOLVED);
95 + return;
96 + }
97 + identity = identity.getBaseNode().getReferredIdentity();
98 + }
99 + }
100 +
101 + /**
102 + * Returns the YANG base node identifier.
103 + *
104 + * @return the YANG base node identifier
105 + */
106 + public YangNodeIdentifier getBaseIdentity() {
107 + return baseIdentity;
108 + }
109 +
110 + /**
111 + * Sets the YANG node identifier.
112 + *
113 + * @param baseIdentity the YANG node identifier to set
114 + */
115 + public void setBaseIdentity(YangNodeIdentifier baseIdentity) {
116 + this.baseIdentity = baseIdentity;
117 + }
118 +
119 + /**
120 + * Returns the name of identity.
121 + *
122 + * @return the identity name
123 + */
124 + @Override
125 + public String getName() {
126 + return baseIdentity.getName();
127 + }
128 +
129 + /**
130 + * Sets the name of identity.
131 + *
132 + * @param name the identity name to set
133 + */
134 + @Override
135 + public void setName(String name) {
136 + baseIdentity.setName(name);
137 + }
138 +
139 + /**
140 + * Sets node identifier.
141 + *
142 + * @param nodeIdentifier the node identifier
143 + */
144 + public void setNodeIdentifier(YangNodeIdentifier nodeIdentifier) {
145 + this.baseIdentity = nodeIdentifier;
146 + }
147 +
148 + /**
149 + * Returns prefix associated with base.
150 + *
151 + * @return prefix associated with base
152 + */
153 + public String getPrefix() {
154 + return baseIdentity.getPrefix();
155 + }
156 +
157 + /**
158 + * Sets prefix associated with base.
159 + *
160 + * @param prefix prefix associated with base
161 + */
162 + public void setPrefix(String prefix) {
163 + baseIdentity.setPrefix(prefix);
164 + }
165 +
166 + @Override
167 + public YangConstructType getYangConstructType() {
168 + return YangConstructType.IDENTITYREF_DATA;
169 + }
170 +
171 + @Override
172 + public void validateDataOnEntry() throws DataModelException {
173 + }
174 +
175 + @Override
176 + public void validateDataOnExit() throws DataModelException {
177 + }
178 +
179 + /**
180 + * Returns the parent identity node.
181 + *
182 + * @return the parent identity node
183 + */
184 + public YangIdentity getReferredIdentity() {
185 + return referredIdentity;
186 + }
187 +
188 + /**
189 + * Sets the parent identity node.
190 + *
191 + * @param referredIdentity the parent identity node to set
192 + */
193 + public void setReferredIdentity(YangIdentity referredIdentity) {
194 + this.referredIdentity = referredIdentity;
195 + }
196 +}
...@@ -216,6 +216,17 @@ public class YangModule ...@@ -216,6 +216,17 @@ public class YangModule
216 private List<YangResolutionInfo> leafrefResolutionList; 216 private List<YangResolutionInfo> leafrefResolutionList;
217 217
218 /** 218 /**
219 + * base resolution list.
220 + */
221 + private List<YangResolutionInfo> baseResolutionList;
222 +
223 + /**
224 + * identityref resolution list.
225 + */
226 + private List<YangResolutionInfo> identityrefResolutionList;
227 +
228 +
229 + /**
219 * Creates a YANG node of module type. 230 * Creates a YANG node of module type.
220 */ 231 */
221 public YangModule() { 232 public YangModule() {
...@@ -225,6 +236,8 @@ public class YangModule ...@@ -225,6 +236,8 @@ public class YangModule
225 usesResolutionList = new LinkedList<>(); 236 usesResolutionList = new LinkedList<>();
226 ifFeatureResolutionList = new LinkedList<>(); 237 ifFeatureResolutionList = new LinkedList<>();
227 leafrefResolutionList = new LinkedList<>(); 238 leafrefResolutionList = new LinkedList<>();
239 + baseResolutionList = new LinkedList<>();
240 + identityrefResolutionList = new LinkedList<>();
228 importList = new LinkedList<YangImport>(); 241 importList = new LinkedList<YangImport>();
229 includeList = new LinkedList<YangInclude>(); 242 includeList = new LinkedList<YangInclude>();
230 listOfLeaf = new LinkedList<YangLeaf>(); 243 listOfLeaf = new LinkedList<YangLeaf>();
...@@ -597,8 +610,12 @@ public class YangModule ...@@ -597,8 +610,12 @@ public class YangModule
597 return usesResolutionList; 610 return usesResolutionList;
598 } else if (type == ResolvableType.YANG_IF_FEATURE) { 611 } else if (type == ResolvableType.YANG_IF_FEATURE) {
599 return ifFeatureResolutionList; 612 return ifFeatureResolutionList;
600 - } else { 613 + } else if (type == ResolvableType.YANG_LEAFREF) {
601 return leafrefResolutionList; 614 return leafrefResolutionList;
615 + } else if (type == ResolvableType.YANG_BASE) {
616 + return baseResolutionList;
617 + } else {
618 + return identityrefResolutionList;
602 } 619 }
603 } 620 }
604 621
...@@ -611,8 +628,12 @@ public class YangModule ...@@ -611,8 +628,12 @@ public class YangModule
611 usesResolutionList.add(resolutionInfo); 628 usesResolutionList.add(resolutionInfo);
612 } else if (type == ResolvableType.YANG_IF_FEATURE) { 629 } else if (type == ResolvableType.YANG_IF_FEATURE) {
613 ifFeatureResolutionList.add(resolutionInfo); 630 ifFeatureResolutionList.add(resolutionInfo);
614 - } else { 631 + } else if (type == ResolvableType.YANG_LEAFREF) {
615 leafrefResolutionList.add(resolutionInfo); 632 leafrefResolutionList.add(resolutionInfo);
633 + } else if (type == ResolvableType.YANG_BASE) {
634 + baseResolutionList.add(resolutionInfo);
635 + } else if (type == ResolvableType.YANG_IDENTITYREF) {
636 + identityrefResolutionList.add(resolutionInfo);
616 } 637 }
617 } 638 }
618 639
...@@ -627,6 +648,10 @@ public class YangModule ...@@ -627,6 +648,10 @@ public class YangModule
627 ifFeatureResolutionList.add((YangResolutionInfo) resolutionList); 648 ifFeatureResolutionList.add((YangResolutionInfo) resolutionList);
628 } else if (type == ResolvableType.YANG_LEAFREF) { 649 } else if (type == ResolvableType.YANG_LEAFREF) {
629 leafrefResolutionList = resolutionList; 650 leafrefResolutionList = resolutionList;
651 + } else if (type == ResolvableType.YANG_BASE) {
652 + baseResolutionList = resolutionList;
653 + } else if (type == ResolvableType.YANG_IDENTITYREF) {
654 + identityrefResolutionList = resolutionList;
630 } 655 }
631 656
632 } 657 }
...@@ -650,11 +675,8 @@ public class YangModule ...@@ -650,11 +675,8 @@ public class YangModule
650 while (includeInfoIterator.hasNext()) { 675 while (includeInfoIterator.hasNext()) {
651 YangInclude yangInclude = includeInfoIterator.next(); 676 YangInclude yangInclude = includeInfoIterator.next();
652 YangSubModule subModule = null; 677 YangSubModule subModule = null;
653 - try {
654 subModule = yangInclude.addReferenceToInclude(yangNodeSet); 678 subModule = yangInclude.addReferenceToInclude(yangNodeSet);
655 - } catch (DataModelException e) { 679 +
656 - throw e;
657 - }
658 // Check if the referred sub-modules parent is self 680 // Check if the referred sub-modules parent is self
659 if (!(subModule.getBelongsTo().getModuleNode() == this)) { 681 if (!(subModule.getBelongsTo().getModuleNode() == this)) {
660 yangInclude.reportIncludeError(); 682 yangInclude.reportIncludeError();
......
...@@ -102,5 +102,15 @@ public enum YangNodeType { ...@@ -102,5 +102,15 @@ public enum YangNodeType {
102 /** 102 /**
103 * Node contains "YANG's list" information. 103 * Node contains "YANG's list" information.
104 */ 104 */
105 - LIST_NODE 105 + LIST_NODE,
106 +
107 + /**
108 + * Identity node.
109 + */
110 + IDENTITY_NODE,
111 +
112 + /**
113 + * Identityref node.
114 + */
115 + IDENTITYREF_NODE
106 } 116 }
......
...@@ -214,6 +214,16 @@ public class YangSubModule ...@@ -214,6 +214,16 @@ public class YangSubModule
214 private List<YangResolutionInfo> leafrefResolutionList; 214 private List<YangResolutionInfo> leafrefResolutionList;
215 215
216 /** 216 /**
217 + * base resolution list.
218 + */
219 + private List<YangResolutionInfo> baseResolutionList;
220 +
221 + /**
222 + * identityref resolution list.
223 + */
224 + private List<YangResolutionInfo> identityrefResolutionList;
225 +
226 + /**
217 * Creates a sub module node. 227 * Creates a sub module node.
218 */ 228 */
219 public YangSubModule() { 229 public YangSubModule() {
...@@ -222,6 +232,8 @@ public class YangSubModule ...@@ -222,6 +232,8 @@ public class YangSubModule
222 usesResolutionList = new LinkedList<>(); 232 usesResolutionList = new LinkedList<>();
223 ifFeatureResolutionList = new LinkedList<>(); 233 ifFeatureResolutionList = new LinkedList<>();
224 leafrefResolutionList = new LinkedList<>(); 234 leafrefResolutionList = new LinkedList<>();
235 + baseResolutionList = new LinkedList<>();
236 + identityrefResolutionList = new LinkedList<>();
225 importList = new LinkedList<YangImport>(); 237 importList = new LinkedList<YangImport>();
226 includeList = new LinkedList<YangInclude>(); 238 includeList = new LinkedList<YangInclude>();
227 listOfLeaf = new LinkedList<YangLeaf>(); 239 listOfLeaf = new LinkedList<YangLeaf>();
...@@ -559,8 +571,12 @@ public class YangSubModule ...@@ -559,8 +571,12 @@ public class YangSubModule
559 return usesResolutionList; 571 return usesResolutionList;
560 } else if (type == ResolvableType.YANG_IF_FEATURE) { 572 } else if (type == ResolvableType.YANG_IF_FEATURE) {
561 return ifFeatureResolutionList; 573 return ifFeatureResolutionList;
562 - } else { 574 + } else if (type == ResolvableType.YANG_LEAFREF) {
563 return leafrefResolutionList; 575 return leafrefResolutionList;
576 + } else if (type == ResolvableType.YANG_BASE) {
577 + return baseResolutionList;
578 + } else {
579 + return identityrefResolutionList;
564 } 580 }
565 } 581 }
566 582
...@@ -573,8 +589,12 @@ public class YangSubModule ...@@ -573,8 +589,12 @@ public class YangSubModule
573 usesResolutionList.add(resolutionInfo); 589 usesResolutionList.add(resolutionInfo);
574 } else if (type == ResolvableType.YANG_IF_FEATURE) { 590 } else if (type == ResolvableType.YANG_IF_FEATURE) {
575 ifFeatureResolutionList.add(resolutionInfo); 591 ifFeatureResolutionList.add(resolutionInfo);
576 - } else { 592 + } else if (type == ResolvableType.YANG_LEAFREF) {
577 leafrefResolutionList.add(resolutionInfo); 593 leafrefResolutionList.add(resolutionInfo);
594 + } else if (type == ResolvableType.YANG_BASE) {
595 + baseResolutionList.add(resolutionInfo);
596 + } else if (type == ResolvableType.YANG_IDENTITYREF) {
597 + identityrefResolutionList.add(resolutionInfo);
578 } 598 }
579 } 599 }
580 600
...@@ -589,6 +609,10 @@ public class YangSubModule ...@@ -589,6 +609,10 @@ public class YangSubModule
589 ifFeatureResolutionList.add((YangResolutionInfo) resolutionList); 609 ifFeatureResolutionList.add((YangResolutionInfo) resolutionList);
590 } else if (type == ResolvableType.YANG_LEAFREF) { 610 } else if (type == ResolvableType.YANG_LEAFREF) {
591 leafrefResolutionList = resolutionList; 611 leafrefResolutionList = resolutionList;
612 + } else if (type == ResolvableType.YANG_BASE) {
613 + baseResolutionList = resolutionList;
614 + } else if (type == ResolvableType.YANG_IDENTITYREF) {
615 + identityrefResolutionList = resolutionList;
592 } 616 }
593 617
594 } 618 }
......
...@@ -22,6 +22,8 @@ import java.util.Set; ...@@ -22,6 +22,8 @@ import java.util.Set;
22 import org.onosproject.yangutils.datamodel.CollisionDetector; 22 import org.onosproject.yangutils.datamodel.CollisionDetector;
23 import org.onosproject.yangutils.datamodel.ResolvableType; 23 import org.onosproject.yangutils.datamodel.ResolvableType;
24 import org.onosproject.yangutils.datamodel.YangIfFeature; 24 import org.onosproject.yangutils.datamodel.YangIfFeature;
25 +import org.onosproject.yangutils.datamodel.YangBase;
26 +import org.onosproject.yangutils.datamodel.YangIdentityRef;
25 import org.onosproject.yangutils.datamodel.YangLeaf; 27 import org.onosproject.yangutils.datamodel.YangLeaf;
26 import org.onosproject.yangutils.datamodel.YangLeafList; 28 import org.onosproject.yangutils.datamodel.YangLeafList;
27 import org.onosproject.yangutils.datamodel.YangLeafRef; 29 import org.onosproject.yangutils.datamodel.YangLeafRef;
...@@ -176,6 +178,10 @@ public final class DataModelUtils { ...@@ -176,6 +178,10 @@ public final class DataModelUtils {
176 .getEntityToResolve() instanceof YangLeafRef) { 178 .getEntityToResolve() instanceof YangLeafRef) {
177 resolutionNode.addToResolutionList(resolutionInfo, 179 resolutionNode.addToResolutionList(resolutionInfo,
178 ResolvableType.YANG_LEAFREF); 180 ResolvableType.YANG_LEAFREF);
181 + } else if (resolutionInfo.getEntityToResolveInfo().getEntityToResolve() instanceof YangBase) {
182 + resolutionNode.addToResolutionList(resolutionInfo, ResolvableType.YANG_BASE);
183 + } else if (resolutionInfo.getEntityToResolveInfo().getEntityToResolve() instanceof YangIdentityRef) {
184 + resolutionNode.addToResolutionList(resolutionInfo, ResolvableType.YANG_IDENTITYREF);
179 } 185 }
180 } 186 }
181 187
......
...@@ -19,6 +19,8 @@ import java.io.Serializable; ...@@ -19,6 +19,8 @@ import java.io.Serializable;
19 19
20 import org.onosproject.yangutils.datamodel.YangEntityToResolveInfo; 20 import org.onosproject.yangutils.datamodel.YangEntityToResolveInfo;
21 import org.onosproject.yangutils.datamodel.YangIfFeature; 21 import org.onosproject.yangutils.datamodel.YangIfFeature;
22 +import org.onosproject.yangutils.datamodel.YangBase;
23 +import org.onosproject.yangutils.datamodel.YangIdentityRef;
22 import org.onosproject.yangutils.datamodel.YangNode; 24 import org.onosproject.yangutils.datamodel.YangNode;
23 import org.onosproject.yangutils.datamodel.YangType; 25 import org.onosproject.yangutils.datamodel.YangType;
24 import org.onosproject.yangutils.datamodel.YangUses; 26 import org.onosproject.yangutils.datamodel.YangUses;
...@@ -79,6 +81,10 @@ public class YangEntityToResolveInfoImpl<T> implements YangEntityToResolveInfo<T ...@@ -79,6 +81,10 @@ public class YangEntityToResolveInfoImpl<T> implements YangEntityToResolveInfo<T
79 prefix = ((YangUses) entityToBeResolved).getPrefix(); 81 prefix = ((YangUses) entityToBeResolved).getPrefix();
80 } else if (entityToBeResolved instanceof YangIfFeature) { 82 } else if (entityToBeResolved instanceof YangIfFeature) {
81 prefix = ((YangIfFeature) entityToBeResolved).getPrefix(); 83 prefix = ((YangIfFeature) entityToBeResolved).getPrefix();
84 + } else if (entityToBeResolved instanceof YangBase) {
85 + prefix = ((YangBase) entityToBeResolved).getBaseIdentifier().getPrefix();
86 + } else if (entityToBeResolved instanceof YangIdentityRef) {
87 + prefix = ((YangIdentityRef) entityToBeResolved).getBaseIdentity().getPrefix();
82 } else { 88 } else {
83 throw new LinkerException("Linker Exception: Entity to resolved is other than type/uses"); 89 throw new LinkerException("Linker Exception: Entity to resolved is other than type/uses");
84 } 90 }
......
...@@ -158,11 +158,16 @@ public class YangLinkerManager ...@@ -158,11 +158,16 @@ public class YangLinkerManager
158 try { 158 try {
159 ((YangReferenceResolver) yangNode) 159 ((YangReferenceResolver) yangNode)
160 .resolveInterFileLinking(ResolvableType.YANG_IF_FEATURE); 160 .resolveInterFileLinking(ResolvableType.YANG_IF_FEATURE);
161 - ((YangReferenceResolver) yangNode).resolveInterFileLinking(ResolvableType.YANG_USES); 161 + ((YangReferenceResolver) yangNode)
162 + .resolveInterFileLinking(ResolvableType.YANG_USES);
162 ((YangReferenceResolver) yangNode) 163 ((YangReferenceResolver) yangNode)
163 .resolveInterFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE); 164 .resolveInterFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE);
164 ((YangReferenceResolver) yangNode) 165 ((YangReferenceResolver) yangNode)
165 .resolveInterFileLinking(ResolvableType.YANG_LEAFREF); 166 .resolveInterFileLinking(ResolvableType.YANG_LEAFREF);
167 + ((YangReferenceResolver) yangNode)
168 + .resolveInterFileLinking(ResolvableType.YANG_BASE);
169 + ((YangReferenceResolver) yangNode)
170 + .resolveInterFileLinking(ResolvableType.YANG_IDENTITYREF);
166 } catch (DataModelException e) { 171 } catch (DataModelException e) {
167 String errorInfo = "Error in file: " + yangNode.getName() + " at line: " 172 String errorInfo = "Error in file: " + yangNode.getName() + " at line: "
168 + e.getLineNumber() + " at position: " + e.getCharPositionInLine() + NEW_LINE + e.getMessage(); 173 + e.getLineNumber() + " at position: " + e.getCharPositionInLine() + NEW_LINE + e.getMessage();
......
...@@ -24,12 +24,15 @@ import java.util.Stack; ...@@ -24,12 +24,15 @@ import java.util.Stack;
24 import org.onosproject.yangutils.datamodel.Resolvable; 24 import org.onosproject.yangutils.datamodel.Resolvable;
25 import org.onosproject.yangutils.datamodel.ResolvableType; 25 import org.onosproject.yangutils.datamodel.ResolvableType;
26 import org.onosproject.yangutils.datamodel.YangAtomicPath; 26 import org.onosproject.yangutils.datamodel.YangAtomicPath;
27 +import org.onosproject.yangutils.datamodel.YangBase;
27 import org.onosproject.yangutils.datamodel.YangDerivedInfo; 28 import org.onosproject.yangutils.datamodel.YangDerivedInfo;
28 import org.onosproject.yangutils.datamodel.YangEntityToResolveInfo; 29 import org.onosproject.yangutils.datamodel.YangEntityToResolveInfo;
29 import org.onosproject.yangutils.datamodel.YangFeature; 30 import org.onosproject.yangutils.datamodel.YangFeature;
30 import org.onosproject.yangutils.datamodel.YangFeatureHolder; 31 import org.onosproject.yangutils.datamodel.YangFeatureHolder;
31 import org.onosproject.yangutils.datamodel.YangGrouping; 32 import org.onosproject.yangutils.datamodel.YangGrouping;
32 import org.onosproject.yangutils.datamodel.YangIfFeature; 33 import org.onosproject.yangutils.datamodel.YangIfFeature;
34 +import org.onosproject.yangutils.datamodel.YangIdentity;
35 +import org.onosproject.yangutils.datamodel.YangIdentityRef;
33 import org.onosproject.yangutils.datamodel.YangImport; 36 import org.onosproject.yangutils.datamodel.YangImport;
34 import org.onosproject.yangutils.datamodel.YangInclude; 37 import org.onosproject.yangutils.datamodel.YangInclude;
35 import org.onosproject.yangutils.datamodel.YangInput; 38 import org.onosproject.yangutils.datamodel.YangInput;
...@@ -69,9 +72,12 @@ import static org.onosproject.yangutils.utils.UtilConstants.FEATURE_LINKER_ERROR ...@@ -69,9 +72,12 @@ import static org.onosproject.yangutils.utils.UtilConstants.FEATURE_LINKER_ERROR
69 import static org.onosproject.yangutils.utils.UtilConstants.GROUPING_LINKER_ERROR; 72 import static org.onosproject.yangutils.utils.UtilConstants.GROUPING_LINKER_ERROR;
70 import static org.onosproject.yangutils.utils.UtilConstants.INPUT; 73 import static org.onosproject.yangutils.utils.UtilConstants.INPUT;
71 import static org.onosproject.yangutils.utils.UtilConstants.LEAFREF; 74 import static org.onosproject.yangutils.utils.UtilConstants.LEAFREF;
75 +import static org.onosproject.yangutils.utils.UtilConstants.IDENTITYREF;
72 import static org.onosproject.yangutils.utils.UtilConstants.LEAFREF_LINKER_ERROR; 76 import static org.onosproject.yangutils.utils.UtilConstants.LEAFREF_LINKER_ERROR;
73 import static org.onosproject.yangutils.utils.UtilConstants.OUTPUT; 77 import static org.onosproject.yangutils.utils.UtilConstants.OUTPUT;
74 import static org.onosproject.yangutils.utils.UtilConstants.TYPEDEF_LINKER_ERROR; 78 import static org.onosproject.yangutils.utils.UtilConstants.TYPEDEF_LINKER_ERROR;
79 +import static org.onosproject.yangutils.utils.UtilConstants.IDENTITYREF_LINKER_ERROR;
80 +import static org.onosproject.yangutils.utils.UtilConstants.BASE_LINKER_ERROR;
75 81
76 /** 82 /**
77 * Represents implementation of resolution object which will be resolved by 83 * Represents implementation of resolution object which will be resolved by
...@@ -143,7 +149,10 @@ public class YangResolutionInfoImpl<T> ...@@ -143,7 +149,10 @@ public class YangResolutionInfoImpl<T>
143 149
144 setCurReferenceResolver(dataModelRootNode); 150 setCurReferenceResolver(dataModelRootNode);
145 151
146 - // Current node to resolve, it can be a YANG type, YANG uses or YANG if-feature or YANG leafref. 152 + /**
153 + * Current node to resolve, it can be a YANG type, YANG uses or YANG if-feature or
154 + * YANG leafref or YANG base or YANG identityref.
155 + */
147 T entityToResolve = getEntityToResolveInfo().getEntityToResolve(); 156 T entityToResolve = getEntityToResolveInfo().getEntityToResolve();
148 157
149 // Check if linking is already done 158 // Check if linking is already done
...@@ -157,7 +166,7 @@ public class YangResolutionInfoImpl<T> ...@@ -157,7 +166,7 @@ public class YangResolutionInfoImpl<T>
157 } 166 }
158 } else { 167 } else {
159 throw new DataModelException("Data Model Exception: Entity to resolved is other than " + 168 throw new DataModelException("Data Model Exception: Entity to resolved is other than " +
160 - "type/uses/if-feature/leafref"); 169 + "type/uses/if-feature/leafref/base/identityref");
161 } 170 }
162 171
163 // Push the initial entity to resolve in stack. 172 // Push the initial entity to resolve in stack.
...@@ -178,7 +187,10 @@ public class YangResolutionInfoImpl<T> ...@@ -178,7 +187,10 @@ public class YangResolutionInfoImpl<T>
178 187
179 while (getPartialResolvedStack().size() != 0) { 188 while (getPartialResolvedStack().size() != 0) {
180 189
181 - // Current node to resolve, it can be a YANG type or YANG uses. 190 + /**
191 + * Current node to resolve, it can be a YANG type or YANG uses or
192 + * YANG if-feature or YANG leafref or YANG base or YANG identityref.
193 + */
182 T entityToResolve = getCurrentEntityToResolveFromStack(); 194 T entityToResolve = getCurrentEntityToResolveFromStack();
183 // Check if linking is already done 195 // Check if linking is already done
184 if (entityToResolve instanceof Resolvable) { 196 if (entityToResolve instanceof Resolvable) {
...@@ -227,6 +239,10 @@ public class YangResolutionInfoImpl<T> ...@@ -227,6 +239,10 @@ public class YangResolutionInfoImpl<T>
227 errorInfo = GROUPING_LINKER_ERROR; 239 errorInfo = GROUPING_LINKER_ERROR;
228 } else if (resolvable instanceof YangIfFeature) { 240 } else if (resolvable instanceof YangIfFeature) {
229 errorInfo = FEATURE_LINKER_ERROR; 241 errorInfo = FEATURE_LINKER_ERROR;
242 + } else if (resolvable instanceof YangBase) {
243 + errorInfo = BASE_LINKER_ERROR;
244 + } else if (resolvable instanceof YangIdentityRef) {
245 + errorInfo = IDENTITYREF_LINKER_ERROR;
230 } else { 246 } else {
231 errorInfo = LEAFREF_LINKER_ERROR; 247 errorInfo = LEAFREF_LINKER_ERROR;
232 } 248 }
...@@ -246,14 +262,16 @@ public class YangResolutionInfoImpl<T> ...@@ -246,14 +262,16 @@ public class YangResolutionInfoImpl<T>
246 262
247 } else { 263 } else {
248 throw new DataModelException( 264 throw new DataModelException(
249 - "Data Model Exception: Entity to resolved is other than type/uses/if-feature/leafref"); 265 + "Data Model Exception: Entity to resolved is other than type/uses/if-feature" +
266 + "/leafref/base/identityref");
250 } 267 }
251 } 268 }
252 269
253 } 270 }
254 271
255 /** 272 /**
256 - * Adds the leafref type to the type, which has derived type referring to typedef with leafref type. 273 + * Adds the leafref/identityref type to the type, which has derived type referring to
274 + * typedef with leafref/identityref type.
257 */ 275 */
258 private void addDerivedRefTypeToRefTypeResolutionList() throws DataModelException { 276 private void addDerivedRefTypeToRefTypeResolutionList() throws DataModelException {
259 277
...@@ -279,9 +297,10 @@ public class YangResolutionInfoImpl<T> ...@@ -279,9 +297,10 @@ public class YangResolutionInfoImpl<T>
279 YangDerivedInfo derivedInfo = (YangDerivedInfo) yangType.getDataTypeExtendedInfo(); 297 YangDerivedInfo derivedInfo = (YangDerivedInfo) yangType.getDataTypeExtendedInfo();
280 298
281 /* 299 /*
282 - * If the derived types referred type is not leaf ref return 300 + * If the derived types referred type is not leafref/identityref return
283 */ 301 */
284 - if (derivedInfo.getEffectiveBuiltInType() != YangDataTypes.LEAFREF) { 302 + if ((derivedInfo.getEffectiveBuiltInType() != YangDataTypes.LEAFREF) &&
303 + (derivedInfo.getEffectiveBuiltInType() != YangDataTypes.IDENTITYREF)) {
285 return; 304 return;
286 } 305 }
287 306
...@@ -292,13 +311,14 @@ public class YangResolutionInfoImpl<T> ...@@ -292,13 +311,14 @@ public class YangResolutionInfoImpl<T>
292 extendedInfo = (T) derivedInfoFromTypedef.getReferredTypeDef().getTypeDefBaseType() 311 extendedInfo = (T) derivedInfoFromTypedef.getReferredTypeDef().getTypeDefBaseType()
293 .getDataTypeExtendedInfo(); 312 .getDataTypeExtendedInfo();
294 } 313 }
314 +
295 /* 315 /*
296 - * Backup the derived types leaf ref info, delete all the info in 316 + * Backup the derived types leafref/identityref info, delete all the info in current type,
297 - * current type, but for resolution status as resolved. Copy the backed 317 + * but for resolution status as resolved. Copy the backed up leafref/identityref to types extended info,
298 - * up leaf ref to types extended info, create a leaf ref resolution info 318 + * create a leafref/identityref resolution info using the current resolution info and
299 - * using the current resolution info and add to leaf ref resolution 319 + * add to leafref/identityref resolution list.
300 - * list.
301 */ 320 */
321 + if (derivedInfo.getEffectiveBuiltInType() == YangDataTypes.LEAFREF) {
302 YangLeafRef leafRefInTypeDef = (YangLeafRef) extendedInfo; 322 YangLeafRef leafRefInTypeDef = (YangLeafRef) extendedInfo;
303 yangType.resetYangType(); 323 yangType.resetYangType();
304 324
...@@ -310,10 +330,30 @@ public class YangResolutionInfoImpl<T> ...@@ -310,10 +330,30 @@ public class YangResolutionInfoImpl<T>
310 330
311 // Add resolution information to the list. 331 // Add resolution information to the list.
312 YangResolutionInfoImpl resolutionInfoImpl = new YangResolutionInfoImpl<>(leafRefInTypeDef, 332 YangResolutionInfoImpl resolutionInfoImpl = new YangResolutionInfoImpl<>(leafRefInTypeDef,
313 - potentialAncestorWithReferredNode, getLineNumber(), getCharPosition()); 333 + potentialAncestorWithReferredNode,
334 + getLineNumber(), getCharPosition());
314 getCurReferenceResolver().addToResolutionList(resolutionInfoImpl, 335 getCurReferenceResolver().addToResolutionList(resolutionInfoImpl,
315 ResolvableType.YANG_LEAFREF); 336 ResolvableType.YANG_LEAFREF);
316 getCurReferenceResolver().resolveSelfFileLinking(ResolvableType.YANG_LEAFREF); 337 getCurReferenceResolver().resolveSelfFileLinking(ResolvableType.YANG_LEAFREF);
338 +
339 + } else if (derivedInfo.getEffectiveBuiltInType() == YangDataTypes.IDENTITYREF) {
340 +
341 + YangIdentityRef identityRefInTypeDef = (YangIdentityRef) extendedInfo;
342 + yangType.resetYangType();
343 +
344 + yangType.setResolvableStatus(RESOLVED);
345 + yangType.setDataType(YangDataTypes.IDENTITYREF);
346 + yangType.setDataTypeName(IDENTITYREF);
347 + yangType.setDataTypeExtendedInfo(identityRefInTypeDef);
348 + identityRefInTypeDef.setResolvableStatus(UNRESOLVED);
349 +
350 + // Add resolution information to the list.
351 + YangResolutionInfoImpl resolutionInfoImpl = new YangResolutionInfoImpl<>(identityRefInTypeDef,
352 + potentialAncestorWithReferredNode, getLineNumber(), getCharPosition());
353 + getCurReferenceResolver().addToResolutionList(resolutionInfoImpl,
354 + ResolvableType.YANG_IDENTITYREF);
355 + getCurReferenceResolver().resolveSelfFileLinking(ResolvableType.YANG_IDENTITYREF);
356 + }
317 } 357 }
318 358
319 /** 359 /**
...@@ -360,6 +400,10 @@ public class YangResolutionInfoImpl<T> ...@@ -360,6 +400,10 @@ public class YangResolutionInfoImpl<T>
360 } else if (getCurrentEntityToResolveFromStack() instanceof YangLeafRef) { 400 } else if (getCurrentEntityToResolveFromStack() instanceof YangLeafRef) {
361 resolveSelfFileLinkingForLeafref(potentialAncestorWithReferredNode); 401 resolveSelfFileLinkingForLeafref(potentialAncestorWithReferredNode);
362 return; 402 return;
403 + } else if ((getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) ||
404 + (getCurrentEntityToResolveFromStack() instanceof YangBase)) {
405 + resolveSelfFileLinkingForBaseAndIdentityref();
406 + return;
363 } else { 407 } else {
364 408
365 /** 409 /**
...@@ -453,6 +497,47 @@ public class YangResolutionInfoImpl<T> ...@@ -453,6 +497,47 @@ public class YangResolutionInfoImpl<T>
453 } 497 }
454 498
455 /** 499 /**
500 + * Resolves self file linking for base/identityref.
501 + *
502 + * @throws DataModelException a violation of data model rules
503 + */
504 + private void resolveSelfFileLinkingForBaseAndIdentityref()
505 + throws DataModelException {
506 +
507 + boolean referredIdentityFound = false;
508 + String nodeName = null;
509 +
510 + if (getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) {
511 + nodeName = ((YangIdentityRef) getCurrentEntityToResolveFromStack()).getName();
512 + }
513 +
514 + if (getCurrentEntityToResolveFromStack() instanceof YangBase) {
515 + nodeName = ((YangBase) getCurrentEntityToResolveFromStack()).getBaseIdentifier().getName();
516 + }
517 +
518 + if (getCurReferenceResolver() instanceof YangModule) {
519 + YangModule rootNode = (YangModule) getCurReferenceResolver();
520 + // Sends list of nodes for finding the target identity.
521 + referredIdentityFound = isIdentityReferenceFound(nodeName, rootNode);
522 + } else if (getCurReferenceResolver() instanceof YangSubModule) {
523 + YangSubModule rootNode = (YangSubModule) getCurReferenceResolver();
524 + // Sends list of nodes for finding the target identity.
525 + referredIdentityFound = isIdentityReferenceFound(nodeName, rootNode);
526 + }
527 +
528 + if (referredIdentityFound) {
529 + return;
530 + }
531 +
532 + /*
533 + * In case prefix is not present it's a candidate for inter-file resolution via include list.
534 + */
535 + if (getRefPrefix() == null) {
536 + ((Resolvable) getCurrentEntityToResolveFromStack()).setResolvableStatus(INTRA_FILE_RESOLVED);
537 + }
538 + }
539 +
540 + /**
456 * Returns the root parent with respect to the ancestor count from leafref. 541 * Returns the root parent with respect to the ancestor count from leafref.
457 * 542 *
458 * @param ancestorCount count of node where parent node can be reached 543 * @param ancestorCount count of node where parent node can be reached
...@@ -561,6 +646,41 @@ public class YangResolutionInfoImpl<T> ...@@ -561,6 +646,41 @@ public class YangResolutionInfoImpl<T>
561 } 646 }
562 647
563 /** 648 /**
649 + * Returns the status of the referred identity found for base/identityref.
650 + *
651 + * @param nodeName the name of the base nodeidentifier/identityref nodeidentifier
652 + * @param ancestorWithTheReferredNode the parent node of base/identityref
653 + * @return status of referred base/identityref
654 + * @throws DataModelException a violation of data model rules
655 + */
656 + private boolean isIdentityReferenceFound(String nodeName, YangNode ancestorWithTheReferredNode)
657 + throws DataModelException {
658 +
659 + // When child is not present return.
660 + if (ancestorWithTheReferredNode.getChild() == null) {
661 + return false;
662 + }
663 +
664 + ancestorWithTheReferredNode = ancestorWithTheReferredNode.getChild();
665 +
666 + // Checks all the siblings under the node and returns the matched node.
667 + YangNode nodeFound = isReferredNodeInSiblingProcessedForIdentity(ancestorWithTheReferredNode, nodeName);
668 +
669 + if (nodeFound != null) {
670 + // Adds reference link of entity to the node under resolution.
671 + addReferredEntityLink(nodeFound, LINKED);
672 +
673 + /**
674 + * resolve the reference and update the partial resolution stack with any further recursive references
675 + */
676 + addUnresolvedRecursiveReferenceToStack(nodeFound);
677 + return true;
678 + }
679 +
680 + return false;
681 + }
682 +
683 + /**
564 * Fills the referred leaf or leaf-list inside the path predicates. 684 * Fills the referred leaf or leaf-list inside the path predicates.
565 * 685 *
566 * @param ancestorWithTheReferredNode the actual node where YANG list will be present 686 * @param ancestorWithTheReferredNode the actual node where YANG list will be present
...@@ -856,6 +976,28 @@ public class YangResolutionInfoImpl<T> ...@@ -856,6 +976,28 @@ public class YangResolutionInfoImpl<T>
856 } 976 }
857 977
858 /** 978 /**
979 + * Checks for the referred parent node for the base/identity.
980 + *
981 + * @param potentialReferredNode potential referred node
982 + * @return the reffered parent node of base/identity.
983 + * @throws DataModelException data model errors
984 + */
985 + private YangNode isReferredNodeInSiblingProcessedForIdentity(YangNode potentialReferredNode,
986 + String referredNodeName) throws DataModelException {
987 +
988 + while (potentialReferredNode != null) {
989 + if (potentialReferredNode instanceof YangIdentity) {
990 + // Check if the potential referred node is the actual referred node
991 + if (isReferredNodeForIdentity(potentialReferredNode, referredNodeName)) {
992 + return potentialReferredNode;
993 + }
994 + }
995 + potentialReferredNode = potentialReferredNode.getNextSibling();
996 + }
997 + return null;
998 + }
999 +
1000 + /**
859 * Checks if the current reference node name and the name in the path are equal. 1001 * Checks if the current reference node name and the name in the path are equal.
860 * 1002 *
861 * @param currentReferredNode the node where the reference is pointed 1003 * @param currentReferredNode the node where the reference is pointed
...@@ -878,6 +1020,28 @@ public class YangResolutionInfoImpl<T> ...@@ -878,6 +1020,28 @@ public class YangResolutionInfoImpl<T>
878 } 1020 }
879 1021
880 /** 1022 /**
1023 + * Checks if the current reference node name and the name in the base/identityref base are equal.
1024 + *
1025 + * @param currentReferredNode the node where the reference is pointed
1026 + * @param nameOfIdentityRefBase name of the base in the base/identityref base
1027 + * @return status of the match between the name
1028 + * @throws DataModelException a violation of data model rules
1029 + */
1030 + private boolean isReferredNodeForIdentity(YangNode currentReferredNode, String nameOfIdentityRefBase)
1031 + throws DataModelException {
1032 +
1033 + if ((getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) ||
1034 + (getCurrentEntityToResolveFromStack() instanceof YangBase)) {
1035 + /*
1036 + * Check if name of node name matches with the current reference node.
1037 + */
1038 + return currentReferredNode.getName().contentEquals(nameOfIdentityRefBase);
1039 + } else {
1040 + throw new DataModelException("Data Model Exception: Entity to resolved is other than identityref");
1041 + }
1042 + }
1043 +
1044 + /**
881 * Checks for the referred node defined in a ancestor scope. 1045 * Checks for the referred node defined in a ancestor scope.
882 * 1046 *
883 * @param potentialReferredNode potential referred node 1047 * @param potentialReferredNode potential referred node
...@@ -946,8 +1110,18 @@ public class YangResolutionInfoImpl<T> ...@@ -946,8 +1110,18 @@ public class YangResolutionInfoImpl<T>
946 */ 1110 */
947 return isNodeNameSameAsResolutionInfoName(potentialReferredNode); 1111 return isNodeNameSameAsResolutionInfoName(potentialReferredNode);
948 } 1112 }
1113 + } else if ((getCurrentEntityToResolveFromStack() instanceof YangBase) ||
1114 + (getCurrentEntityToResolveFromStack() instanceof YangIdentityRef)) {
1115 + if (potentialReferredNode instanceof YangIdentity) {
1116 + /*
1117 + * Check if name of node name matches with the entity being
1118 + * resolved
1119 + */
1120 + return isNodeNameSameAsResolutionInfoName(potentialReferredNode);
1121 + }
949 } else { 1122 } else {
950 - throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses"); 1123 + throw new DataModelException("Data Model Exception: Entity to resolved is other than type/" +
1124 + "uses/base/identityref");
951 } 1125 }
952 return false; 1126 return false;
953 } 1127 }
...@@ -977,6 +1151,16 @@ public class YangResolutionInfoImpl<T> ...@@ -977,6 +1151,16 @@ public class YangResolutionInfoImpl<T>
977 } 1151 }
978 } else if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) { 1152 } else if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) {
979 return isFeatureDefinedInNode(node); 1153 return isFeatureDefinedInNode(node);
1154 + } else if (getCurrentEntityToResolveFromStack() instanceof YangBase) {
1155 + if (node.getName().contentEquals(
1156 + ((YangBase) getCurrentEntityToResolveFromStack()).getBaseIdentifier().getName())) {
1157 + return true;
1158 + }
1159 + } else if (getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) {
1160 + if (node.getName().contentEquals(
1161 + ((YangIdentityRef) getCurrentEntityToResolveFromStack()).getName())) {
1162 + return true;
1163 + }
980 } else { 1164 } else {
981 throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses"); 1165 throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
982 } 1166 }
...@@ -1020,8 +1204,13 @@ public class YangResolutionInfoImpl<T> ...@@ -1020,8 +1204,13 @@ public class YangResolutionInfoImpl<T>
1020 // do nothing , referred node is already set 1204 // do nothing , referred node is already set
1021 } else if (getCurrentEntityToResolveFromStack() instanceof YangLeafRef) { 1205 } else if (getCurrentEntityToResolveFromStack() instanceof YangLeafRef) {
1022 // do nothing , referred node is already set 1206 // do nothing , referred node is already set
1207 + } else if (getCurrentEntityToResolveFromStack() instanceof YangBase) {
1208 + ((YangBase) getCurrentEntityToResolveFromStack()).setReferredIdentity((YangIdentity) referredNode);
1209 + } else if (getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) {
1210 + ((YangIdentityRef) getCurrentEntityToResolveFromStack()).setReferredIdentity((YangIdentity) referredNode);
1023 } else { 1211 } else {
1024 - throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses"); 1212 + throw new DataModelException("Data Model Exception: Entity to resolved is other than type" +
1213 + "/uses/base/identityref");
1025 } 1214 }
1026 1215
1027 // Sets the resolution status in inside the type/uses. 1216 // Sets the resolution status in inside the type/uses.
...@@ -1062,6 +1251,15 @@ public class YangResolutionInfoImpl<T> ...@@ -1062,6 +1251,15 @@ public class YangResolutionInfoImpl<T>
1062 } else if (getCurrentEntityToResolveFromStack() instanceof YangLeafRef) { 1251 } else if (getCurrentEntityToResolveFromStack() instanceof YangLeafRef) {
1063 // do nothing , referred node is already set 1252 // do nothing , referred node is already set
1064 throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses"); 1253 throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
1254 + } else if ((getCurrentEntityToResolveFromStack() instanceof YangBase) ||
1255 + (getCurrentEntityToResolveFromStack() instanceof YangIdentityRef)) {
1256 + /*
1257 + * Search if the identity has any un resolved base, if so return true, else return false.
1258 + */
1259 + addUnResolvedBaseToStack(referredNode);
1260 + } else {
1261 + throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses/" +
1262 + "base/identityref");
1065 } 1263 }
1066 } 1264 }
1067 1265
...@@ -1109,6 +1307,26 @@ public class YangResolutionInfoImpl<T> ...@@ -1109,6 +1307,26 @@ public class YangResolutionInfoImpl<T>
1109 } 1307 }
1110 1308
1111 /** 1309 /**
1310 + * Returns if there is any unresolved base in identity.
1311 + *
1312 + * @param node module/submodule node
1313 + */
1314 + private void addUnResolvedBaseToStack(YangNode node) {
1315 +
1316 + YangIdentity curNode = (YangIdentity) node;
1317 + if (curNode.getBaseNode() != null) {
1318 + if (curNode.getBaseNode().getResolvableStatus() != RESOLVED) {
1319 + YangEntityToResolveInfoImpl<YangBase> unResolvedEntityInfo = new YangEntityToResolveInfoImpl<>();
1320 + unResolvedEntityInfo.setEntityToResolve(curNode.getBaseNode());
1321 + unResolvedEntityInfo.setHolderOfEntityToResolve(node);
1322 + addInPartialResolvedStack((YangEntityToResolveInfoImpl<T>) unResolvedEntityInfo);
1323 +
1324 + }
1325 + }
1326 + }
1327 +
1328 +
1329 + /**
1112 * Returns stack of YANG type with partially resolved YANG construct 1330 * Returns stack of YANG type with partially resolved YANG construct
1113 * hierarchy. 1331 * hierarchy.
1114 * 1332 *
...@@ -1247,8 +1465,13 @@ public class YangResolutionInfoImpl<T> ...@@ -1247,8 +1465,13 @@ public class YangResolutionInfoImpl<T>
1247 refPrefix = ((YangIfFeature) getCurrentEntityToResolveFromStack()).getPrefix(); 1465 refPrefix = ((YangIfFeature) getCurrentEntityToResolveFromStack()).getPrefix();
1248 } else if (getCurrentEntityToResolveFromStack() instanceof YangLeafRef) { 1466 } else if (getCurrentEntityToResolveFromStack() instanceof YangLeafRef) {
1249 refPrefix = refPrefixForLeafRef(); 1467 refPrefix = refPrefixForLeafRef();
1468 + } else if (getCurrentEntityToResolveFromStack() instanceof YangBase) {
1469 + refPrefix = ((YangBase) getCurrentEntityToResolveFromStack()).getBaseIdentifier().getPrefix();
1470 + } else if (getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) {
1471 + refPrefix = ((YangIdentityRef) getCurrentEntityToResolveFromStack()).getPrefix();
1250 } else { 1472 } else {
1251 - throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses"); 1473 + throw new DataModelException("Data Model Exception: Entity to resolved is other than " +
1474 + "type/uses/base/identityref");
1252 } 1475 }
1253 return refPrefix; 1476 return refPrefix;
1254 } 1477 }
...@@ -1392,6 +1615,10 @@ public class YangResolutionInfoImpl<T> ...@@ -1392,6 +1615,10 @@ public class YangResolutionInfoImpl<T>
1392 errorInfo = GROUPING_LINKER_ERROR; 1615 errorInfo = GROUPING_LINKER_ERROR;
1393 } else if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) { 1616 } else if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) {
1394 errorInfo = FEATURE_LINKER_ERROR; 1617 errorInfo = FEATURE_LINKER_ERROR;
1618 + } else if (getCurrentEntityToResolveFromStack() instanceof YangBase) {
1619 + errorInfo = BASE_LINKER_ERROR;
1620 + } else if (getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) {
1621 + errorInfo = IDENTITYREF_LINKER_ERROR;
1395 } else { 1622 } else {
1396 errorInfo = LEAFREF_LINKER_ERROR; 1623 errorInfo = LEAFREF_LINKER_ERROR;
1397 } 1624 }
...@@ -1449,7 +1676,12 @@ public class YangResolutionInfoImpl<T> ...@@ -1449,7 +1676,12 @@ public class YangResolutionInfoImpl<T>
1449 setCurReferenceResolver((YangReferenceResolver) yangInclude.getIncludedNode()); 1676 setCurReferenceResolver((YangReferenceResolver) yangInclude.getIncludedNode());
1450 1677
1451 return referredNode; 1678 return referredNode;
1679 + } else if (getCurrentEntityToResolveFromStack() instanceof YangBase) {
1680 + linkedNode = findRefIdentity(yangInclude.getIncludedNode());
1681 + } else if (getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) {
1682 + linkedNode = findRefIdentityRef(yangInclude.getIncludedNode());
1452 } 1683 }
1684 +
1453 if (linkedNode != null) { 1685 if (linkedNode != null) {
1454 // Add the link to external entity. 1686 // Add the link to external entity.
1455 addReferredEntityLink(linkedNode, INTER_FILE_LINKED); 1687 addReferredEntityLink(linkedNode, INTER_FILE_LINKED);
...@@ -1502,6 +1734,10 @@ public class YangResolutionInfoImpl<T> ...@@ -1502,6 +1734,10 @@ public class YangResolutionInfoImpl<T>
1502 setCurReferenceResolver((YangReferenceResolver) yangImport.getImportedNode()); 1734 setCurReferenceResolver((YangReferenceResolver) yangImport.getImportedNode());
1503 1735
1504 return referredNode; 1736 return referredNode;
1737 + } else if (getCurrentEntityToResolveFromStack() instanceof YangBase) {
1738 + linkedNode = findRefIdentity(yangImport.getImportedNode());
1739 + } else if (getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) {
1740 + linkedNode = findRefIdentityRef(yangImport.getImportedNode());
1505 } 1741 }
1506 if (linkedNode != null) { 1742 if (linkedNode != null) {
1507 // Add the link to external entity. 1743 // Add the link to external entity.
...@@ -1584,8 +1820,13 @@ public class YangResolutionInfoImpl<T> ...@@ -1584,8 +1820,13 @@ public class YangResolutionInfoImpl<T>
1584 return (T) ((YangIfFeature) getCurrentEntityToResolveFromStack()).getReferredFeatureHolder(); 1820 return (T) ((YangIfFeature) getCurrentEntityToResolveFromStack()).getReferredFeatureHolder();
1585 } else if (getCurrentEntityToResolveFromStack() instanceof YangLeafRef) { 1821 } else if (getCurrentEntityToResolveFromStack() instanceof YangLeafRef) {
1586 return (T) ((YangLeafRef) getCurrentEntityToResolveFromStack()).getReferredLeafOrLeafList(); 1822 return (T) ((YangLeafRef) getCurrentEntityToResolveFromStack()).getReferredLeafOrLeafList();
1823 + } else if (getCurrentEntityToResolveFromStack() instanceof YangBase) {
1824 + return (T) ((YangBase) getCurrentEntityToResolveFromStack()).getReferredIdentity();
1825 + } else if (getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) {
1826 + return (T) ((YangIdentityRef) getCurrentEntityToResolveFromStack()).getReferredIdentity();
1587 } else { 1827 } else {
1588 - throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses"); 1828 + throw new DataModelException("Data Model Exception: Entity to resolved is other than type" +
1829 + "/uses/base/identityref");
1589 } 1830 }
1590 } 1831 }
1591 1832
...@@ -1651,4 +1892,45 @@ public class YangResolutionInfoImpl<T> ...@@ -1651,4 +1892,45 @@ public class YangResolutionInfoImpl<T>
1651 } 1892 }
1652 return null; 1893 return null;
1653 } 1894 }
1895 +
1896 + /**
1897 + * Finds the referred identity node at the root level of imported/included node.
1898 + *
1899 + * @param refNode module/sub-module node
1900 + * @return referred identity
1901 + */
1902 + private YangNode findRefIdentity(YangNode refNode) {
1903 + YangNode tmpNode = refNode.getChild();
1904 + while (tmpNode != null) {
1905 + if (tmpNode instanceof YangIdentity) {
1906 + if (tmpNode.getName()
1907 + .equals(((YangBase) getCurrentEntityToResolveFromStack()).getBaseIdentifier().getName())) {
1908 + return tmpNode;
1909 + }
1910 + }
1911 + tmpNode = tmpNode.getNextSibling();
1912 + }
1913 + return null;
1914 + }
1915 +
1916 + /**
1917 + * Finds the referred identity node at the root level of imported/included node.
1918 + *
1919 + * @param refNode module/sub-module node
1920 + * @return referred identity
1921 + */
1922 + private YangNode findRefIdentityRef(YangNode refNode) {
1923 + YangNode tmpNode = refNode.getChild();
1924 + while (tmpNode != null) {
1925 + if (tmpNode instanceof YangIdentity) {
1926 + if (tmpNode.getName()
1927 + .equals(((YangIdentityRef) getCurrentEntityToResolveFromStack())
1928 + .getBaseIdentity().getName())) {
1929 + return tmpNode;
1930 + }
1931 + }
1932 + tmpNode = tmpNode.getNextSibling();
1933 + }
1934 + return null;
1935 + }
1654 } 1936 }
......
...@@ -28,6 +28,7 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangListener; ...@@ -28,6 +28,7 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangListener;
28 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; 28 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
29 import org.onosproject.yangutils.parser.impl.listeners.AugmentListener; 29 import org.onosproject.yangutils.parser.impl.listeners.AugmentListener;
30 import org.onosproject.yangutils.parser.impl.listeners.BaseFileListener; 30 import org.onosproject.yangutils.parser.impl.listeners.BaseFileListener;
31 +import org.onosproject.yangutils.parser.impl.listeners.BaseListener;
31 import org.onosproject.yangutils.parser.impl.listeners.BelongsToListener; 32 import org.onosproject.yangutils.parser.impl.listeners.BelongsToListener;
32 import org.onosproject.yangutils.parser.impl.listeners.BitListener; 33 import org.onosproject.yangutils.parser.impl.listeners.BitListener;
33 import org.onosproject.yangutils.parser.impl.listeners.BitsListener; 34 import org.onosproject.yangutils.parser.impl.listeners.BitsListener;
...@@ -42,7 +43,9 @@ import org.onosproject.yangutils.parser.impl.listeners.EnumListener; ...@@ -42,7 +43,9 @@ import org.onosproject.yangutils.parser.impl.listeners.EnumListener;
42 import org.onosproject.yangutils.parser.impl.listeners.EnumerationListener; 43 import org.onosproject.yangutils.parser.impl.listeners.EnumerationListener;
43 import org.onosproject.yangutils.parser.impl.listeners.FeatureListener; 44 import org.onosproject.yangutils.parser.impl.listeners.FeatureListener;
44 import org.onosproject.yangutils.parser.impl.listeners.GroupingListener; 45 import org.onosproject.yangutils.parser.impl.listeners.GroupingListener;
46 +import org.onosproject.yangutils.parser.impl.listeners.IdentityrefListener;
45 import org.onosproject.yangutils.parser.impl.listeners.IfFeatureListener; 47 import org.onosproject.yangutils.parser.impl.listeners.IfFeatureListener;
48 +import org.onosproject.yangutils.parser.impl.listeners.IdentityListener;
46 import org.onosproject.yangutils.parser.impl.listeners.ImportListener; 49 import org.onosproject.yangutils.parser.impl.listeners.ImportListener;
47 import org.onosproject.yangutils.parser.impl.listeners.IncludeListener; 50 import org.onosproject.yangutils.parser.impl.listeners.IncludeListener;
48 import org.onosproject.yangutils.parser.impl.listeners.InputListener; 51 import org.onosproject.yangutils.parser.impl.listeners.InputListener;
...@@ -450,12 +453,12 @@ public class TreeWalkListener implements GeneratedYangListener { ...@@ -450,12 +453,12 @@ public class TreeWalkListener implements GeneratedYangListener {
450 453
451 @Override 454 @Override
452 public void enterIdentityStatement(GeneratedYangParser.IdentityStatementContext ctx) { 455 public void enterIdentityStatement(GeneratedYangParser.IdentityStatementContext ctx) {
453 - handleUnsupportedYangConstruct(YangConstructType.IDENTITY_DATA, ctx, CURRENTLY_UNSUPPORTED); 456 + IdentityListener.processIdentityEntry(this, ctx);
454 } 457 }
455 458
456 @Override 459 @Override
457 public void exitIdentityStatement(GeneratedYangParser.IdentityStatementContext ctx) { 460 public void exitIdentityStatement(GeneratedYangParser.IdentityStatementContext ctx) {
458 - // do nothing. 461 + IdentityListener.processIdentityExit(this, ctx);
459 } 462 }
460 463
461 @Override 464 @Override
...@@ -470,7 +473,7 @@ public class TreeWalkListener implements GeneratedYangListener { ...@@ -470,7 +473,7 @@ public class TreeWalkListener implements GeneratedYangListener {
470 473
471 @Override 474 @Override
472 public void enterBaseStatement(GeneratedYangParser.BaseStatementContext ctx) { 475 public void enterBaseStatement(GeneratedYangParser.BaseStatementContext ctx) {
473 - handleUnsupportedYangConstruct(YangConstructType.BASE_DATA, ctx, CURRENTLY_UNSUPPORTED); 476 + BaseListener.processBaseEntry(this, ctx);
474 } 477 }
475 478
476 @Override 479 @Override
...@@ -710,12 +713,12 @@ public class TreeWalkListener implements GeneratedYangListener { ...@@ -710,12 +713,12 @@ public class TreeWalkListener implements GeneratedYangListener {
710 713
711 @Override 714 @Override
712 public void enterIdentityrefSpecification(GeneratedYangParser.IdentityrefSpecificationContext ctx) { 715 public void enterIdentityrefSpecification(GeneratedYangParser.IdentityrefSpecificationContext ctx) {
713 - // do nothing. 716 + IdentityrefListener.processIdentityrefEntry(this, ctx);
714 } 717 }
715 718
716 @Override 719 @Override
717 public void exitIdentityrefSpecification(GeneratedYangParser.IdentityrefSpecificationContext ctx) { 720 public void exitIdentityrefSpecification(GeneratedYangParser.IdentityrefSpecificationContext ctx) {
718 - // do nothing. 721 + IdentityrefListener.processIdentityrefExit(this, ctx);
719 } 722 }
720 723
721 @Override 724 @Override
......
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 +package org.onosproject.yangutils.parser.impl.listeners;
17 +
18 +import org.onosproject.yangutils.datamodel.YangBase;
19 +import org.onosproject.yangutils.datamodel.YangIdentity;
20 +import org.onosproject.yangutils.datamodel.YangIdentityRef;
21 +import org.onosproject.yangutils.datamodel.YangNode;
22 +import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
23 +import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
24 +import org.onosproject.yangutils.linker.impl.YangResolutionInfoImpl;
25 +import org.onosproject.yangutils.datamodel.utils.Parsable;
26 +import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
27 +import org.onosproject.yangutils.parser.exceptions.ParserException;
28 +import org.onosproject.yangutils.parser.impl.TreeWalkListener;
29 +
30 +import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.addResolutionInfo;
31 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
32 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
33 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
34 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
35 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.*;
36 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidNodeIdentifier;
37 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
38 +import static org.onosproject.yangutils.datamodel.utils.YangConstructType.BASE_DATA;
39 +
40 +/**
41 + * base-stmt = base-keyword sep identifier-ref-arg-str
42 + * optsep stmtend*
43 + * identifier-ref-arg = [prefix ":"] identifier
44 + */
45 +
46 +/**
47 + * Represents listener based call back function corresponding to the "base"
48 + * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
49 + */
50 +public final class BaseListener {
51 +
52 + //Creates a new base listener.
53 + private BaseListener() {
54 + }
55 +
56 + /**
57 + * Performs validation and updates the data model tree when parser receives an
58 + * input matching the grammar rule (base).
59 + *
60 + * @param listener listener's object
61 + * @param ctx context object of the grammar rule
62 + */
63 + public static void processBaseEntry(TreeWalkListener listener,
64 + GeneratedYangParser.BaseStatementContext ctx) {
65 +
66 + // Check for stack to be non empty.
67 + checkStackIsNotEmpty(listener, MISSING_HOLDER, BASE_DATA, ctx.string().getText(), ENTRY);
68 +
69 + YangNodeIdentifier nodeIdentifier = getValidNodeIdentifier(ctx.string().getText(), BASE_DATA, ctx);
70 +
71 + Parsable tmpData = listener.getParsedDataStack().peek();
72 +
73 + /**
74 + * For identityref base node identifier is copied in identity listener itself, so no need to process
75 + * base statement for indentityref
76 + */
77 + if (tmpData instanceof YangIdentityRef) {
78 + return;
79 + }
80 +
81 + if (!(tmpData instanceof YangIdentity)) {
82 + throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, BASE_DATA,
83 + ctx.string().getText(), ENTRY));
84 + }
85 +
86 + YangBase yangBase = new YangBase();
87 + yangBase.setBaseIdentifier(nodeIdentifier);
88 + ((YangIdentity) tmpData).setBaseNode(yangBase);
89 +
90 + int errorLine = ctx.getStart().getLine();
91 + int errorPosition = ctx.getStart().getCharPositionInLine();
92 +
93 + // Add resolution information to the list
94 + YangResolutionInfoImpl resolutionInfo =
95 + new YangResolutionInfoImpl<YangBase>(yangBase, (YangNode) tmpData, errorLine, errorPosition);
96 + addToResolutionList(resolutionInfo, ctx);
97 + }
98 +
99 + /**
100 + * Add to resolution list.
101 + *
102 + * @param resolutionInfo resolution information
103 + * @param ctx context object of the grammar rule
104 + */
105 + private static void addToResolutionList(YangResolutionInfoImpl<YangBase> resolutionInfo,
106 + GeneratedYangParser.BaseStatementContext ctx) {
107 +
108 + try {
109 + addResolutionInfo(resolutionInfo);
110 + } catch (DataModelException e) {
111 + throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
112 + BASE_DATA, ctx.string().getText(), EXIT, e.getMessage()));
113 + }
114 + }
115 +
116 +}
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 +package org.onosproject.yangutils.parser.impl.listeners;
17 +
18 +import org.onosproject.yangutils.datamodel.YangIdentity;
19 +import org.onosproject.yangutils.datamodel.YangModule;
20 +import org.onosproject.yangutils.datamodel.YangNode;
21 +import org.onosproject.yangutils.datamodel.YangSubModule;
22 +import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
23 +import org.onosproject.yangutils.datamodel.utils.Parsable;
24 +import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
25 +import org.onosproject.yangutils.parser.exceptions.ParserException;
26 +import org.onosproject.yangutils.parser.impl.TreeWalkListener;
27 +
28 +import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
29 +import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangIdentityNode;
30 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
31 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
32 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
33 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
34 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
35 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
36 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
37 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
38 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
39 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
40 +import static org.onosproject.yangutils.datamodel.utils.YangConstructType.IDENTITY_DATA;
41 +
42 +/**
43 + * Reference: RFC6020 and YANG ANTLR Grammar.
44 + *
45 + * ABNF grammar as per RFC6020
46 + * identity-stmt = identity-keyword sep identifier-arg-str optsep
47 + * (";" /
48 + * "{" stmtsep
49 + * ;; these stmts can appear in any order
50 + * [base-stmt stmtsep]
51 + * [status-stmt stmtsep]
52 + * [description-stmt stmtsep]
53 + * [reference-stmt stmtsep]
54 + * "}")
55 + */
56 +
57 +/**
58 + * Represents listener based call back function corresponding to the "identity"
59 + * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
60 + */
61 +public final class IdentityListener {
62 +
63 + //Creates a identity listener.
64 + private IdentityListener() {
65 + }
66 +
67 + /**
68 + * Performs validations and update the data model tree when parser receives an input
69 + * matching the grammar rule (identity).
70 + *
71 + * @param listener Listener's object
72 + * @param ctx context object of the grammar rule
73 + */
74 + public static void processIdentityEntry(TreeWalkListener listener,
75 + GeneratedYangParser.IdentityStatementContext ctx) {
76 +
77 + // Check for stack to be non empty.
78 + checkStackIsNotEmpty(listener, MISSING_HOLDER, IDENTITY_DATA, ctx.identifier().getText(), ENTRY);
79 +
80 + String identifier = getValidIdentifier(ctx.identifier().getText(), IDENTITY_DATA, ctx);
81 +
82 + YangIdentity identity = getYangIdentityNode(JAVA_GENERATION);
83 + identity.setName(identifier);
84 +
85 + Parsable curData = listener.getParsedDataStack().peek();
86 + if (curData instanceof YangModule || curData instanceof YangSubModule) {
87 + YangNode curNode = (YangNode) curData;
88 + try {
89 + curNode.addChild(identity);
90 + } catch (DataModelException e) {
91 + throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
92 + IDENTITY_DATA, ctx.identifier().getText(), ENTRY, e.getMessage()));
93 + }
94 + // Push identity node to the stack.
95 + listener.getParsedDataStack().push(identity);
96 + } else {
97 + throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, IDENTITY_DATA,
98 + ctx.identifier().getText(), ENTRY));
99 + }
100 +
101 + }
102 +
103 + /**
104 + * Performs validations and update the data model tree when parser exits from grammar
105 + * rule (identity).
106 + *
107 + * @param listener Listener's object
108 + * @param ctx context object of the grammar rule
109 + */
110 + public static void processIdentityExit(TreeWalkListener listener,
111 + GeneratedYangParser.IdentityStatementContext ctx) {
112 +
113 + // Check for stack to be non empty.
114 + checkStackIsNotEmpty(listener, MISSING_CURRENT_HOLDER, IDENTITY_DATA, ctx.identifier().getText(), EXIT);
115 +
116 + Parsable parsableType = listener.getParsedDataStack().pop();
117 + if (!(parsableType instanceof YangIdentity)) {
118 + throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, IDENTITY_DATA,
119 + ctx.identifier().getText(), EXIT));
120 + }
121 + }
122 +
123 +}
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 +package org.onosproject.yangutils.parser.impl.listeners;
17 +
18 +import org.onosproject.yangutils.datamodel.YangIdentityRef;
19 +import org.onosproject.yangutils.datamodel.YangNode;
20 +import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
21 +import org.onosproject.yangutils.datamodel.YangType;
22 +import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
23 +import org.onosproject.yangutils.datamodel.utils.Parsable;
24 +import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
25 +import org.onosproject.yangutils.linker.impl.YangResolutionInfoImpl;
26 +import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
27 +import org.onosproject.yangutils.parser.exceptions.ParserException;
28 +import org.onosproject.yangutils.parser.impl.TreeWalkListener;
29 +
30 +import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.addResolutionInfo;
31 +import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.UNRESOLVED;
32 +import static org.onosproject.yangutils.datamodel.utils.YangConstructType.BASE_DATA;
33 +import static org.onosproject.yangutils.datamodel.utils.YangConstructType.IDENTITYREF_DATA;
34 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
35 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
36 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
37 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
38 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
39 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
40 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
41 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
42 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidNodeIdentifier;
43 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
44 +
45 +/**
46 + * Reference: RFC6020 and YANG ANTLR Grammar
47 + *
48 + * ABNF grammar as per RFC6020
49 + * identityref-specification =
50 + * base-stmt stmtsep
51 + * base-stmt = base-keyword sep identifier-ref-arg-str
52 + * optsep stmtend*
53 + * identifier-ref-arg = [prefix ":"] identifier
54 + */
55 +
56 +/**
57 + * Represents listener based call back function corresponding to the "identityref"
58 + * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
59 + */
60 +public final class IdentityrefListener {
61 +
62 + //Creates a new type listener.
63 + private IdentityrefListener() {
64 + }
65 +
66 + /**
67 + * Performs validation and updates the data model tree when parser receives an input
68 + * matching the grammar rule (identityref).
69 + *
70 + * @param listener listener's object
71 + * @param ctx context object of the grammar rule
72 + */
73 + public static void processIdentityrefEntry(TreeWalkListener listener,
74 + GeneratedYangParser.IdentityrefSpecificationContext ctx) {
75 +
76 + // Check for stack to be non empty.
77 + checkStackIsNotEmpty(listener, MISSING_HOLDER, IDENTITYREF_DATA, "", ENTRY);
78 +
79 + if (listener.getParsedDataStack().peek() instanceof YangType) {
80 +
81 + YangIdentityRef identityRef = new YangIdentityRef();
82 + Parsable typeData = listener.getParsedDataStack().pop();
83 + YangDataTypes yangDataTypes = ((YangType) typeData).getDataType();
84 + YangResolutionInfoImpl resolutionInfo;
85 +
86 + // Validate node identifier.
87 + YangNodeIdentifier nodeIdentifier = getValidNodeIdentifier(ctx.baseStatement().string().getText(),
88 + BASE_DATA, ctx);
89 + identityRef.setBaseIdentity(nodeIdentifier);
90 + ((YangType) typeData).setDataTypeExtendedInfo(identityRef);
91 +
92 + int errorLine = ctx.getStart().getLine();
93 + int errorPosition = ctx.getStart().getCharPositionInLine();
94 +
95 + Parsable tmpData = listener.getParsedDataStack().peek();
96 + switch (tmpData.getYangConstructType()) {
97 + case LEAF_DATA:
98 +
99 + // Pop the stack entry to obtain the parent YANG node.
100 + Parsable leaf = listener.getParsedDataStack().pop();
101 + Parsable parentNodeOfLeaf = listener.getParsedDataStack().peek();
102 +
103 + // Push the popped entry back to the stack.
104 + listener.getParsedDataStack().push(leaf);
105 +
106 + // Verify parent node of leaf
107 + if (!(parentNodeOfLeaf instanceof YangNode)) {
108 + throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER,
109 + IDENTITYREF_DATA, ctx.getText(), EXIT));
110 + }
111 +
112 + identityRef.setResolvableStatus(UNRESOLVED);
113 +
114 + // Add resolution information to the list
115 + resolutionInfo = new YangResolutionInfoImpl<YangIdentityRef>(identityRef,
116 + (YangNode) parentNodeOfLeaf, errorLine, errorPosition);
117 + addToResolutionList(resolutionInfo, ctx);
118 +
119 + break;
120 + case LEAF_LIST_DATA:
121 +
122 + // Pop the stack entry to obtain the parent YANG node.
123 + Parsable leafList = listener.getParsedDataStack().pop();
124 + Parsable parentNodeOfLeafList = listener.getParsedDataStack().peek();
125 +
126 + // Push the popped entry back to the stack.
127 + listener.getParsedDataStack().push(leafList);
128 +
129 + // Verify parent node of leaf
130 + if (!(parentNodeOfLeafList instanceof YangNode)) {
131 + throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER,
132 + IDENTITYREF_DATA, ctx.getText(), EXIT));
133 + }
134 +
135 + identityRef.setResolvableStatus(UNRESOLVED);
136 +
137 + // Add resolution information to the list
138 + resolutionInfo = new YangResolutionInfoImpl<YangIdentityRef>(identityRef,
139 + (YangNode) parentNodeOfLeafList, errorLine, errorPosition);
140 + addToResolutionList(resolutionInfo, ctx);
141 + break;
142 + case UNION_DATA:
143 +
144 + Parsable parentNodeOfUnionNode = listener.getParsedDataStack().peek();
145 +
146 + // Verify parent node of leaf
147 + if (!(parentNodeOfUnionNode instanceof YangNode)) {
148 + throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER,
149 + IDENTITYREF_DATA, ctx.getText(), EXIT));
150 + }
151 +
152 + identityRef.setResolvableStatus(UNRESOLVED);
153 +
154 + // Add resolution information to the list
155 + resolutionInfo = new YangResolutionInfoImpl<YangIdentityRef>(identityRef,
156 + (YangNode) parentNodeOfUnionNode, errorLine, errorPosition);
157 + addToResolutionList(resolutionInfo, ctx);
158 +
159 + break;
160 + case TYPEDEF_DATA:
161 + /**
162 + * Do not add the identity ref to resolution list. It needs to be
163 + * added to resolution list, when leaf/leaf list references to
164 + * this typedef. At this time that leaf/leaf-list becomes the
165 + * parent for the identityref.
166 + */
167 + break;
168 + default:
169 + throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, IDENTITYREF_DATA,
170 + ctx.getText(), EXIT));
171 + }
172 + listener.getParsedDataStack().push(typeData);
173 + listener.getParsedDataStack().push(identityRef);
174 + } else {
175 + throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, IDENTITYREF_DATA, "", ENTRY));
176 + }
177 + }
178 +
179 + /**
180 + * Performs validations and update the data model tree when parser exits from grammar
181 + * rule (identityref).
182 + *
183 + * @param listener Listener's object
184 + * @param ctx context object of the grammar rule
185 + */
186 + public static void processIdentityrefExit(TreeWalkListener listener,
187 + GeneratedYangParser.IdentityrefSpecificationContext ctx) {
188 +
189 + // Check for stack to be non empty.
190 + checkStackIsNotEmpty(listener, MISSING_CURRENT_HOLDER, IDENTITYREF_DATA, ctx.getText(), EXIT);
191 +
192 + Parsable parsableType = listener.getParsedDataStack().pop();
193 + if (!(parsableType instanceof YangIdentityRef)) {
194 + throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, IDENTITYREF_DATA,
195 + ctx.getText(), EXIT));
196 + }
197 + }
198 +
199 + /**
200 + * Adds to resolution list.
201 + *
202 + * @param resolutionInfo resolution information
203 + * @param ctx context object of the grammar rule
204 + */
205 + private static void addToResolutionList(YangResolutionInfoImpl<YangIdentityRef> resolutionInfo,
206 + GeneratedYangParser.IdentityrefSpecificationContext ctx) {
207 + try {
208 + addResolutionInfo(resolutionInfo);
209 + } catch (DataModelException e) {
210 + throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
211 + IDENTITYREF_DATA, ctx.getText(), ENTRY, e.getMessage()));
212 + }
213 + }
214 +}
...@@ -130,6 +130,10 @@ public final class ModuleListener { ...@@ -130,6 +130,10 @@ public final class ModuleListener {
130 .peek()).resolveSelfFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE); 130 .peek()).resolveSelfFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE);
131 ((YangReferenceResolver) listener.getParsedDataStack() 131 ((YangReferenceResolver) listener.getParsedDataStack()
132 .peek()).resolveSelfFileLinking(ResolvableType.YANG_LEAFREF); 132 .peek()).resolveSelfFileLinking(ResolvableType.YANG_LEAFREF);
133 + ((YangReferenceResolver) listener.getParsedDataStack()
134 + .peek()).resolveSelfFileLinking(ResolvableType.YANG_BASE);
135 + ((YangReferenceResolver) listener.getParsedDataStack()
136 + .peek()).resolveSelfFileLinking(ResolvableType.YANG_IDENTITYREF);
133 } catch (DataModelException e) { 137 } catch (DataModelException e) {
134 LinkerException linkerException = new LinkerException(e.getMessage()); 138 LinkerException linkerException = new LinkerException(e.getMessage());
135 linkerException.setLine(e.getLineNumber()); 139 linkerException.setLine(e.getLineNumber());
......
...@@ -135,6 +135,10 @@ public final class SubModuleListener { ...@@ -135,6 +135,10 @@ public final class SubModuleListener {
135 .resolveSelfFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE); 135 .resolveSelfFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE);
136 ((YangReferenceResolver) listener.getParsedDataStack().peek()) 136 ((YangReferenceResolver) listener.getParsedDataStack().peek())
137 .resolveSelfFileLinking(ResolvableType.YANG_LEAFREF); 137 .resolveSelfFileLinking(ResolvableType.YANG_LEAFREF);
138 + ((YangReferenceResolver) listener.getParsedDataStack().peek())
139 + .resolveSelfFileLinking(ResolvableType.YANG_BASE);
140 + ((YangReferenceResolver) listener.getParsedDataStack().peek())
141 + .resolveSelfFileLinking(ResolvableType.YANG_IDENTITYREF);
138 } catch (DataModelException e) { 142 } catch (DataModelException e) {
139 LinkerException linkerException = new LinkerException(e.getMessage()); 143 LinkerException linkerException = new LinkerException(e.getMessage());
140 linkerException.setLine(e.getLineNumber()); 144 linkerException.setLine(e.getLineNumber());
......
...@@ -310,7 +310,11 @@ public final class TypeListener { ...@@ -310,7 +310,11 @@ public final class TypeListener {
310 parserException = new ParserException("YANG file error : a type leafref" + 310 parserException = new ParserException("YANG file error : a type leafref" +
311 " must have one path statement."); 311 " must have one path statement.");
312 break; 312 break;
313 - // TODO : decimal64, identity ref 313 + case IDENTITYREF:
314 + parserException = new ParserException("YANG file error : a type identityref" +
315 + " must have base statement.");
316 + break;
317 + // TODO : decimal64,
314 default: 318 default:
315 return; 319 return;
316 } 320 }
......
...@@ -48,10 +48,8 @@ import static org.onosproject.yangutils.utils.UtilConstants.CHAR_OF_SLASH; ...@@ -48,10 +48,8 @@ import static org.onosproject.yangutils.utils.UtilConstants.CHAR_OF_SLASH;
48 import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS; 48 import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
49 import static org.onosproject.yangutils.utils.UtilConstants.COLON; 49 import static org.onosproject.yangutils.utils.UtilConstants.COLON;
50 import static org.onosproject.yangutils.utils.UtilConstants.CURRENT; 50 import static org.onosproject.yangutils.utils.UtilConstants.CURRENT;
51 -import static org.onosproject.yangutils.utils.UtilConstants.CURRENTLY_UNSUPPORTED;
52 import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; 51 import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
53 import static org.onosproject.yangutils.utils.UtilConstants.FALSE; 52 import static org.onosproject.yangutils.utils.UtilConstants.FALSE;
54 -import static org.onosproject.yangutils.utils.UtilConstants.IDENTITYREF;
55 import static org.onosproject.yangutils.utils.UtilConstants.OPEN_SQUARE_BRACKET; 53 import static org.onosproject.yangutils.utils.UtilConstants.OPEN_SQUARE_BRACKET;
56 import static org.onosproject.yangutils.utils.UtilConstants.QUOTES; 54 import static org.onosproject.yangutils.utils.UtilConstants.QUOTES;
57 import static org.onosproject.yangutils.utils.UtilConstants.SLASH; 55 import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
...@@ -341,7 +339,6 @@ public final class ListenerUtil { ...@@ -341,7 +339,6 @@ public final class ListenerUtil {
341 String[] tmpData = tmpIdentifierString.split(Pattern.quote(COLON)); 339 String[] tmpData = tmpIdentifierString.split(Pattern.quote(COLON));
342 if (tmpData.length == 1) { 340 if (tmpData.length == 1) {
343 YangNodeIdentifier nodeIdentifier = new YangNodeIdentifier(); 341 YangNodeIdentifier nodeIdentifier = new YangNodeIdentifier();
344 - checkForUnsupportedTypes(tmpData[0], yangConstruct, ctx);
345 nodeIdentifier.setName(getValidIdentifier(tmpData[0], yangConstruct, ctx)); 342 nodeIdentifier.setName(getValidIdentifier(tmpData[0], yangConstruct, ctx));
346 return nodeIdentifier; 343 return nodeIdentifier;
347 } else if (tmpData.length == 2) { 344 } else if (tmpData.length == 2) {
...@@ -375,7 +372,6 @@ public final class ListenerUtil { ...@@ -375,7 +372,6 @@ public final class ListenerUtil {
375 String[] tmpData = tmpIdentifierString.split(Pattern.quote(COLON)); 372 String[] tmpData = tmpIdentifierString.split(Pattern.quote(COLON));
376 if (tmpData.length == 1) { 373 if (tmpData.length == 1) {
377 YangNodeIdentifier nodeIdentifier = new YangNodeIdentifier(); 374 YangNodeIdentifier nodeIdentifier = new YangNodeIdentifier();
378 - checkForUnsupportedTypes(tmpData[0], yangConstruct, ctx);
379 nodeIdentifier.setName(getValidIdentifierForLeafref(tmpData[0], yangConstruct, ctx, yangLeafRef)); 375 nodeIdentifier.setName(getValidIdentifierForLeafref(tmpData[0], yangConstruct, ctx, yangLeafRef));
380 return nodeIdentifier; 376 return nodeIdentifier;
381 } else if (tmpData.length == 2) { 377 } else if (tmpData.length == 2) {
...@@ -706,24 +702,6 @@ public final class ListenerUtil { ...@@ -706,24 +702,6 @@ public final class ListenerUtil {
706 } 702 }
707 703
708 /** 704 /**
709 - * Checks whether the type is an unsupported type.
710 - *
711 - * @param typeName name of the type
712 - * @param yangConstruct yang construct to check if it is type
713 - * @param ctx yang construct's context to get the line number and character position
714 - */
715 - private static void checkForUnsupportedTypes(String typeName,
716 - YangConstructType yangConstruct, ParserRuleContext ctx) {
717 -
718 - if (yangConstruct == YangConstructType.TYPE_DATA) {
719 - if (typeName.equalsIgnoreCase(IDENTITYREF)) {
720 - handleUnsupportedYangConstruct(YangConstructType.IDENTITYREF_DATA,
721 - ctx, CURRENTLY_UNSUPPORTED);
722 - }
723 - }
724 - }
725 -
726 - /**
727 * Checks and return valid absolute schema node id. 705 * Checks and return valid absolute schema node id.
728 * 706 *
729 * @param argumentString string from yang file 707 * @param argumentString string from yang file
......
...@@ -89,6 +89,11 @@ public final class GeneratedJavaFileType { ...@@ -89,6 +89,11 @@ public final class GeneratedJavaFileType {
89 public static final int GENERATE_EVENT_SUBJECT_CLASS = 1024; 89 public static final int GENERATE_EVENT_SUBJECT_CLASS = 1024;
90 90
91 /** 91 /**
92 + * Identity listener class.
93 + */
94 + public static final int GENERATE_IDENTITY_CLASS = 2048;
95 +
96 + /**
92 * Creates an instance of generate java file type. 97 * Creates an instance of generate java file type.
93 */ 98 */
94 private GeneratedJavaFileType() { 99 private GeneratedJavaFileType() {
......
...@@ -20,6 +20,7 @@ import org.onosproject.yangutils.datamodel.YangCase; ...@@ -20,6 +20,7 @@ import org.onosproject.yangutils.datamodel.YangCase;
20 import org.onosproject.yangutils.datamodel.YangChoice; 20 import org.onosproject.yangutils.datamodel.YangChoice;
21 import org.onosproject.yangutils.datamodel.YangContainer; 21 import org.onosproject.yangutils.datamodel.YangContainer;
22 import org.onosproject.yangutils.datamodel.YangGrouping; 22 import org.onosproject.yangutils.datamodel.YangGrouping;
23 +import org.onosproject.yangutils.datamodel.YangIdentity;
23 import org.onosproject.yangutils.datamodel.YangInput; 24 import org.onosproject.yangutils.datamodel.YangInput;
24 import org.onosproject.yangutils.datamodel.YangLeaf; 25 import org.onosproject.yangutils.datamodel.YangLeaf;
25 import org.onosproject.yangutils.datamodel.YangLeafList; 26 import org.onosproject.yangutils.datamodel.YangLeafList;
...@@ -41,6 +42,7 @@ import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaChoice; ...@@ -41,6 +42,7 @@ import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaChoice;
41 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaContainer; 42 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaContainer;
42 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaEnumeration; 43 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaEnumeration;
43 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaGrouping; 44 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaGrouping;
45 +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaIdentity;
44 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaInput; 46 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaInput;
45 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaLeaf; 47 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaLeaf;
46 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaLeafList; 48 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaLeafList;
...@@ -163,6 +165,24 @@ public final class YangDataModelFactory { ...@@ -163,6 +165,24 @@ public final class YangDataModelFactory {
163 * generated 165 * generated
164 * @return the corresponding inherited node based on the target language 166 * @return the corresponding inherited node based on the target language
165 */ 167 */
168 + public static YangIdentity getYangIdentityNode(GeneratedLanguage targetLanguage) {
169 + switch (targetLanguage) {
170 + case JAVA_GENERATION: {
171 + return new YangJavaIdentity();
172 + }
173 + default: {
174 + throw new TranslatorException("Only YANG to Java is supported.");
175 + }
176 + }
177 + }
178 +
179 + /**
180 + * Returns based on the target language generate the inherited data model node.
181 + *
182 + * @param targetLanguage target language in which YANG mapping needs to be
183 + * generated
184 + * @return the corresponding inherited node based on the target language
185 + */
166 public static YangGrouping getYangGroupingNode(GeneratedLanguage targetLanguage) { 186 public static YangGrouping getYangGroupingNode(GeneratedLanguage targetLanguage) {
167 switch (targetLanguage) { 187 switch (targetLanguage) {
168 case JAVA_GENERATION: { 188 case JAVA_GENERATION: {
......
...@@ -20,7 +20,9 @@ import java.util.Stack; ...@@ -20,7 +20,9 @@ import java.util.Stack;
20 20
21 import org.onosproject.yangutils.datamodel.YangDerivedInfo; 21 import org.onosproject.yangutils.datamodel.YangDerivedInfo;
22 import org.onosproject.yangutils.datamodel.YangEnumeration; 22 import org.onosproject.yangutils.datamodel.YangEnumeration;
23 +import org.onosproject.yangutils.datamodel.YangIdentity;
23 import org.onosproject.yangutils.datamodel.YangLeafRef; 24 import org.onosproject.yangutils.datamodel.YangLeafRef;
25 +import org.onosproject.yangutils.datamodel.YangIdentityRef;
24 import org.onosproject.yangutils.datamodel.YangNode; 26 import org.onosproject.yangutils.datamodel.YangNode;
25 import org.onosproject.yangutils.datamodel.YangType; 27 import org.onosproject.yangutils.datamodel.YangType;
26 import org.onosproject.yangutils.datamodel.YangTypeDef; 28 import org.onosproject.yangutils.datamodel.YangTypeDef;
...@@ -161,8 +163,10 @@ public final class AttributesJavaDataType { ...@@ -161,8 +163,10 @@ public final class AttributesJavaDataType {
161 YangType<?> referredType = getReferredTypeFromLeafref(yangType); 163 YangType<?> referredType = getReferredTypeFromLeafref(yangType);
162 return getJavaImportClass(referredType, isListAttr, pluginConfig); 164 return getJavaImportClass(referredType, isListAttr, pluginConfig);
163 case IDENTITYREF: 165 case IDENTITYREF:
164 - //TODO:IDENTITYREF 166 + YangIdentityRef identityRef = (YangIdentityRef) yangType.getDataTypeExtendedInfo();
165 - break; 167 + YangIdentity identity = identityRef.getReferredIdentity();
168 + return getCapitalCase(getCamelCase(((YangJavaIdentity) identity).
169 + getName(), pluginConfig));
166 case EMPTY: 170 case EMPTY:
167 return BOOLEAN_WRAPPER; 171 return BOOLEAN_WRAPPER;
168 case UNION: 172 case UNION:
...@@ -196,8 +200,9 @@ public final class AttributesJavaDataType { ...@@ -196,8 +200,9 @@ public final class AttributesJavaDataType {
196 YangType<?> referredType = getReferredTypeFromLeafref(yangType); 200 YangType<?> referredType = getReferredTypeFromLeafref(yangType);
197 return getJavaImportClass(referredType, isListAttr, pluginConfig); 201 return getJavaImportClass(referredType, isListAttr, pluginConfig);
198 case IDENTITYREF: 202 case IDENTITYREF:
199 - //TODO:IDENTITYREF 203 + YangIdentityRef identityRef = (YangIdentityRef) yangType.getDataTypeExtendedInfo();
200 - break; 204 + YangIdentity identity = identityRef.getReferredIdentity();
205 + return getCapitalCase(getCamelCase(((YangJavaIdentity) identity).getName(), pluginConfig));
201 case EMPTY: 206 case EMPTY:
202 return BOOLEAN_DATA_TYPE; 207 return BOOLEAN_DATA_TYPE;
203 case UNION: 208 case UNION:
...@@ -212,7 +217,6 @@ public final class AttributesJavaDataType { ...@@ -212,7 +217,6 @@ public final class AttributesJavaDataType {
212 return null; 217 return null;
213 } 218 }
214 } 219 }
215 - return null;
216 } 220 }
217 221
218 /** 222 /**
...@@ -253,8 +257,7 @@ public final class AttributesJavaDataType { ...@@ -253,8 +257,7 @@ public final class AttributesJavaDataType {
253 YangType<?> referredType = getReferredTypeFromLeafref(yangType); 257 YangType<?> referredType = getReferredTypeFromLeafref(yangType);
254 return getJavaImportPackage(referredType, isListAttr, conflictResolver); 258 return getJavaImportPackage(referredType, isListAttr, conflictResolver);
255 case IDENTITYREF: 259 case IDENTITYREF:
256 - //TODO:IDENTITYREF 260 + return getIdentityRefPackage(yangType, conflictResolver);
257 - break;
258 case UNION: 261 case UNION:
259 return getUnionPackage(yangType, conflictResolver); 262 return getUnionPackage(yangType, conflictResolver);
260 case INSTANCE_IDENTIFIER: 263 case INSTANCE_IDENTIFIER:
...@@ -280,8 +283,7 @@ public final class AttributesJavaDataType { ...@@ -280,8 +283,7 @@ public final class AttributesJavaDataType {
280 YangType<?> referredType = getReferredTypeFromLeafref(yangType); 283 YangType<?> referredType = getReferredTypeFromLeafref(yangType);
281 return getJavaImportPackage(referredType, isListAttr, conflictResolver); 284 return getJavaImportPackage(referredType, isListAttr, conflictResolver);
282 case IDENTITYREF: 285 case IDENTITYREF:
283 - //TODO:IDENTITYREF 286 + return getIdentityRefPackage(yangType, conflictResolver);
284 - break;
285 case EMPTY: 287 case EMPTY:
286 return JAVA_LANG; 288 return JAVA_LANG;
287 case UNION: 289 case UNION:
...@@ -294,7 +296,6 @@ public final class AttributesJavaDataType { ...@@ -294,7 +296,6 @@ public final class AttributesJavaDataType {
294 return null; 296 return null;
295 } 297 }
296 } 298 }
297 - return null;
298 } 299 }
299 300
300 /** 301 /**
...@@ -361,6 +362,25 @@ public final class AttributesJavaDataType { ...@@ -361,6 +362,25 @@ public final class AttributesJavaDataType {
361 } 362 }
362 363
363 /** 364 /**
365 + * Returns YANG identity's java package.
366 + *
367 + * @param type YANG type
368 + * @param conflictResolver object of YANG to java naming conflict util
369 + * @return YANG identity's java package
370 + */
371 + private static String getIdentityRefPackage(YangType<?> type, YangToJavaNamingConflictUtil conflictResolver) {
372 +
373 + if (!(type.getDataTypeExtendedInfo() instanceof YangIdentityRef)) {
374 + throw new TranslatorException("type should have been identityref.");
375 + }
376 + YangIdentityRef identityRef = (YangIdentityRef) type.getDataTypeExtendedInfo();
377 + YangJavaIdentity identity = (YangJavaIdentity) (identityRef.getReferredIdentity());
378 + if (identity.getJavaFileInfo().getPackage() == null) {
379 + return getPackageFromParent(identity.getParent(), conflictResolver);
380 + }
381 + return identity.getJavaFileInfo().getPackage();
382 + }
383 + /**
364 * Returns package from parent node. 384 * Returns package from parent node.
365 * 385 *
366 * @param parent parent YANG node 386 * @param parent parent YANG node
......
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 +package org.onosproject.yangutils.translator.tojava.javamodel;
17 +
18 +import org.onosproject.yangutils.datamodel.YangIdentity;
19 +import org.onosproject.yangutils.translator.exception.TranslatorException;
20 +import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
21 +import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
22 +import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
23 +import org.onosproject.yangutils.translator.tojava.JavaImportData;
24 +import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
25 +import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
26 +import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
27 +
28 +import java.io.File;
29 +import java.io.IOException;
30 +import java.util.List;
31 +
32 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
33 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_IDENTITY_CLASS;
34 +import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.updatePackageInfo;
35 +import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject;
36 +import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.initiateJavaFileGeneration;
37 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
38 +import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
39 +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
40 +
41 +/**
42 + * Represents input information extended to support java code generation.
43 + */
44 +public class YangJavaIdentity extends YangIdentity
45 + implements JavaCodeGeneratorInfo, JavaCodeGenerator {
46 +
47 + //File type extension for java classes.
48 + private static final String JAVA_FILE_EXTENSION = ".java";
49 +
50 +
51 + //Contains the information of the java file being generated.
52 + private JavaFileInfo javaFileInfo;
53 +
54 + //Contains the information of the importd.
55 + private transient JavaImportData importData;
56 +
57 + /**
58 + * File handle to maintain temporary java code fragments as per the code
59 + * snippet types.
60 + */
61 + private TempJavaCodeFragmentFiles tempFileHandle;
62 +
63 + /**
64 + * Creates YANG java container object.
65 + */
66 + public YangJavaIdentity() {
67 + setJavaFileInfo(new JavaFileInfo());
68 + getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
69 + importData = new JavaImportData();
70 + }
71 +
72 + /**
73 + * Returns the generated java file information.
74 + *
75 + * @return generated java file information
76 + */
77 + @Override
78 + public JavaFileInfo getJavaFileInfo() {
79 + if (javaFileInfo == null) {
80 + throw new TranslatorException("Missing java info in java datamodel node");
81 + }
82 + return javaFileInfo;
83 + }
84 +
85 + /**
86 + * Sets the java file info object.
87 + *
88 + * @param javaInfo java file info object
89 + */
90 + @Override
91 + public void setJavaFileInfo(JavaFileInfo javaInfo) {
92 + javaFileInfo = javaInfo;
93 + }
94 +
95 + /**
96 + * Returns the temporary file handle.
97 + *
98 + * @return temporary file handle
99 + */
100 + @Override
101 + public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
102 + return tempFileHandle;
103 + }
104 +
105 + /**
106 + * Sets temporary file handle.
107 + *
108 + * @param fileHandle temporary file handle
109 + */
110 + @Override
111 + public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
112 + tempFileHandle = fileHandle;
113 + }
114 +
115 + /**
116 + * Prepare the information for java code generation corresponding to YANG
117 + * container info.
118 + *
119 + * @param yangPlugin YANG plugin config
120 + * @throws TranslatorException translator operation fail
121 + */
122 + @Override
123 + public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
124 + try {
125 + updatePackageInfo(this, yangPlugin);
126 + JavaQualifiedTypeInfo basePkgInfo = new JavaQualifiedTypeInfo();
127 + String className = getCapitalCase(getJavaFileInfo().getJavaName());
128 + String path = getJavaFileInfo().getPackageFilePath();
129 + createPackage(this);
130 + List<String> imports = null;
131 + boolean isQualified = false;
132 +
133 + if (getBaseNode() != null && getBaseNode().getReferredIdentity() != null) {
134 + if (!(getBaseNode().getReferredIdentity() instanceof YangJavaIdentity)) {
135 + throw new TranslatorException("Failed to prepare generate code entry for base node");
136 + }
137 + YangJavaIdentity baseIdentity = (YangJavaIdentity) getBaseNode().getReferredIdentity();
138 + String baseClassName = getCapitalCase(baseIdentity.getJavaFileInfo().getJavaName());
139 + String basePkg = baseIdentity.getJavaFileInfo().getPackage();
140 + basePkgInfo.setClassInfo(baseClassName);
141 + basePkgInfo.setPkgInfo(basePkg);
142 + isQualified = importData.addImportInfo(basePkgInfo, className, getJavaFileInfo().getPackage());
143 + if (!isQualified) {
144 + imports = importData.getImports();
145 + }
146 + }
147 +
148 + File file = getFileObject(path, className, JAVA_FILE_EXTENSION, getJavaFileInfo());
149 +
150 + initiateJavaFileGeneration(file, GENERATE_IDENTITY_CLASS, imports, this, className);
151 + closeFile(file, false);
152 + } catch (IOException e) {
153 + throw new TranslatorException(
154 + "Failed to prepare generate code entry for identity node " + this.getName());
155 + }
156 + }
157 +
158 + /**
159 + * Create a java file using the YANG container info.
160 + *
161 + * @throws TranslatorException translator operation fail
162 + */
163 + @Override
164 + public void generateCodeExit() throws TranslatorException {
165 + /* Do nothing, file is already generated in entry*/
166 + }
167 +}
168 +
...@@ -16,10 +16,13 @@ ...@@ -16,10 +16,13 @@
16 16
17 package org.onosproject.yangutils.translator.tojava.utils; 17 package org.onosproject.yangutils.translator.tojava.utils;
18 18
19 +import org.onosproject.yangutils.datamodel.YangIdentity;
19 import org.onosproject.yangutils.datamodel.YangNode; 20 import org.onosproject.yangutils.datamodel.YangNode;
20 import org.onosproject.yangutils.datamodel.YangNotification; 21 import org.onosproject.yangutils.datamodel.YangNotification;
22 +import org.onosproject.yangutils.translator.exception.TranslatorException;
21 import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; 23 import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
22 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer; 24 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
25 +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaIdentity;
23 26
24 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; 27 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
25 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK; 28 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
...@@ -27,6 +30,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType. ...@@ -27,6 +30,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.
27 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS; 30 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
28 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE; 31 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
29 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS; 32 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
33 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_IDENTITY_CLASS;
30 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; 34 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
31 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; 35 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
32 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS; 36 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
...@@ -57,6 +61,8 @@ import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_ANY_STRING ...@@ -57,6 +61,8 @@ import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_ANY_STRING
57 import static org.onosproject.yangutils.utils.UtilConstants.SERVICE; 61 import static org.onosproject.yangutils.utils.UtilConstants.SERVICE;
58 import static org.onosproject.yangutils.utils.UtilConstants.SPACE; 62 import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
59 import static org.onosproject.yangutils.utils.UtilConstants.SUBJECT; 63 import static org.onosproject.yangutils.utils.UtilConstants.SUBJECT;
64 +import static org.onosproject.yangutils.utils.UtilConstants.ABSTRACT;
65 +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
60 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast; 66 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
61 67
62 /** 68 /**
...@@ -128,6 +134,8 @@ public final class ClassDefinitionGenerator { ...@@ -128,6 +134,8 @@ public final class ClassDefinitionGenerator {
128 return getEventListenerDefinition(yangName); 134 return getEventListenerDefinition(yangName);
129 case GENERATE_EVENT_SUBJECT_CLASS: 135 case GENERATE_EVENT_SUBJECT_CLASS:
130 return getClassDefinition(yangName); 136 return getClassDefinition(yangName);
137 + case GENERATE_IDENTITY_CLASS:
138 + return getIdentityClassDefinition(yangName, curNode);
131 default: 139 default:
132 return null; 140 return null;
133 } 141 }
...@@ -214,6 +222,32 @@ public final class ClassDefinitionGenerator { ...@@ -214,6 +222,32 @@ public final class ClassDefinitionGenerator {
214 } 222 }
215 223
216 /** 224 /**
225 + * Returns implementation file identity class definition.
226 + *
227 + * @param yangName file name
228 + * @return identity class definition
229 + */
230 + private static String getIdentityClassDefinition(String yangName, YangNode curNode) {
231 + if (!(curNode instanceof YangJavaIdentity)) {
232 + throw new TranslatorException("Expected java identity instance node");
233 + }
234 + YangJavaIdentity identity = (YangJavaIdentity) curNode;
235 + if (identity.getBaseNode() != null) {
236 + YangIdentity baseIdentity = identity.getBaseNode().getReferredIdentity();
237 + if (!(baseIdentity instanceof YangJavaIdentity)) {
238 + throw new TranslatorException("Expected java identity instance node");
239 + }
240 +
241 + YangJavaIdentity baseJavaIdentity = (YangJavaIdentity) baseIdentity;
242 + return PUBLIC + SPACE + ABSTRACT + SPACE + CLASS + SPACE + yangName + SPACE + EXTEND + SPACE
243 + + getCapitalCase(baseJavaIdentity.getJavaFileInfo().getJavaName()) + SPACE +
244 + OPEN_CURLY_BRACKET + NEW_LINE;
245 + }
246 +
247 + return PUBLIC + SPACE + ABSTRACT + SPACE + CLASS + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
248 + }
249 +
250 + /**
217 * Returns type file class definition. 251 * Returns type file class definition.
218 * 252 *
219 * @param yangName file name 253 * @param yangName file name
......
...@@ -42,6 +42,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType. ...@@ -42,6 +42,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.
42 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; 42 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
43 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; 43 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
44 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS; 44 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
45 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_IDENTITY_CLASS;
45 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; 46 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
46 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; 47 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
47 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK; 48 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK;
...@@ -68,6 +69,7 @@ import static org.onosproject.yangutils.translator.tojava.utils.ClassDefinitionG ...@@ -68,6 +69,7 @@ import static org.onosproject.yangutils.translator.tojava.utils.ClassDefinitionG
68 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getJavaPackageFromPackagePath; 69 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getJavaPackageFromPackagePath;
69 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase; 70 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase;
70 import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS; 71 import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
72 +import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
71 import static org.onosproject.yangutils.utils.UtilConstants.COMPONENT_ANNOTATION; 73 import static org.onosproject.yangutils.utils.UtilConstants.COMPONENT_ANNOTATION;
72 import static org.onosproject.yangutils.utils.UtilConstants.EQUAL; 74 import static org.onosproject.yangutils.utils.UtilConstants.EQUAL;
73 import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; 75 import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
...@@ -294,6 +296,7 @@ public final class JavaFileGeneratorUtils { ...@@ -294,6 +296,7 @@ public final class JavaFileGeneratorUtils {
294 } 296 }
295 297
296 file.createNewFile(); 298 file.createNewFile();
299 +
297 appendContents(file, genType, imports, curNode, className); 300 appendContents(file, genType, imports, curNode, className);
298 } catch (IOException e) { 301 } catch (IOException e) {
299 throw new IOException("Failed to create " + file.getName() + " class file."); 302 throw new IOException("Failed to create " + file.getName() + " class file.");
...@@ -348,6 +351,11 @@ public final class JavaFileGeneratorUtils { ...@@ -348,6 +351,11 @@ public final class JavaFileGeneratorUtils {
348 appendHeaderContents(file, pkgString, importsList); 351 appendHeaderContents(file, pkgString, importsList);
349 write(file, genType, EVENT_SUBJECT_CLASS, curNode, className); 352 write(file, genType, EVENT_SUBJECT_CLASS, curNode, className);
350 break; 353 break;
354 + case GENERATE_IDENTITY_CLASS:
355 + appendHeaderContents(file, pkgString, importsList);
356 + write(file, genType, EVENT_SUBJECT_CLASS, curNode, className);
357 + insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET);
358 + break;
351 default: 359 default:
352 break; 360 break;
353 } 361 }
......
...@@ -647,6 +647,11 @@ public final class UtilConstants { ...@@ -647,6 +647,11 @@ public final class UtilConstants {
647 public static final String PUBLIC = "public"; 647 public static final String PUBLIC = "public";
648 648
649 /** 649 /**
650 + * Static attribute for abstract modifier.
651 + */
652 + public static final String ABSTRACT = "abstract";
653 +
654 + /**
650 * Static attribute for protected modifier. 655 * Static attribute for protected modifier.
651 */ 656 */
652 public static final String PROTECTED = "protected"; 657 public static final String PROTECTED = "protected";
...@@ -1196,6 +1201,18 @@ public final class UtilConstants { ...@@ -1196,6 +1201,18 @@ public final class UtilConstants {
1196 + "leaf/leaf-list for given leafref"; 1201 + "leaf/leaf-list for given leafref";
1197 1202
1198 /** 1203 /**
1204 + * Static attribute for base linker error information.
1205 + */
1206 + public static final String BASE_LINKER_ERROR = "YANG file error: Unable to find base "
1207 + + "identity for given base";
1208 +
1209 + /**
1210 + * Static attribute for identityref linker error information.
1211 + */
1212 + public static final String IDENTITYREF_LINKER_ERROR = "YANG file error: Unable to find base "
1213 + + "identity for given base";
1214 +
1215 + /**
1199 * Static attribute for reference. 1216 * Static attribute for reference.
1200 */ 1217 */
1201 public static final String REFERENCE = "Reference"; 1218 public static final String REFERENCE = "Reference";
......
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 +package org.onosproject.yangutils.parser.impl.listeners;
17 +
18 +import org.junit.Rule;
19 +import org.junit.Test;
20 +import org.junit.rules.ExpectedException;
21 +import org.onosproject.yangutils.datamodel.YangIdentity;
22 +import org.onosproject.yangutils.datamodel.YangIdentityRef;
23 +import org.onosproject.yangutils.datamodel.YangLeaf;
24 +import org.onosproject.yangutils.datamodel.YangLeafList;
25 +import org.onosproject.yangutils.datamodel.YangModule;
26 +import org.onosproject.yangutils.datamodel.YangNode;
27 +import org.onosproject.yangutils.datamodel.YangNodeType;
28 +import org.onosproject.yangutils.datamodel.YangType;
29 +import org.onosproject.yangutils.datamodel.YangTypeDef;
30 +import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
31 +import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
32 +import org.onosproject.yangutils.parser.exceptions.ParserException;
33 +import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
34 +
35 +import java.io.IOException;
36 +import java.util.ListIterator;
37 +
38 +import static org.hamcrest.MatcherAssert.assertThat;
39 +import static org.hamcrest.core.Is.is;
40 +
41 +/**
42 + * Test case for identity listener.
43 + */
44 +public class IdentityListenerTest {
45 + @Rule
46 + public ExpectedException thrown = ExpectedException.none();
47 +
48 + private final YangUtilsParserManager manager = new YangUtilsParserManager();
49 +
50 + /**
51 + * Checks for updating datamodel for identity/identityref.
52 + */
53 + @Test
54 + public void processIdentityrefType() throws IOException, ParserException {
55 +
56 + YangNode node = manager
57 + .getDataModel("src/test/resources/IdentityListener.yang");
58 +
59 + // Check whether the data model tree returned is of type module.
60 + assertThat((node instanceof YangModule), is(true));
61 +
62 + // Check whether the node type is set properly to module.
63 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
64 +
65 + // Check whether the module name is set correctly.
66 + YangModule yangNode = (YangModule) node;
67 + assertThat(yangNode.getName(), is("IdentityListener"));
68 +
69 + YangIdentity yangIdentity = (YangIdentity) yangNode.getChild();
70 + assertThat(yangIdentity.getName(), is("tunnel"));
71 +
72 + yangIdentity = (YangIdentity) yangNode.getChild().getNextSibling();
73 + assertThat(yangIdentity.getName(), is("tunnel-type"));
74 +
75 + yangIdentity = (YangIdentity) yangNode.getChild().getNextSibling().getNextSibling();
76 + assertThat(yangIdentity.getName(), is("ref-address-family"));
77 +
78 + yangIdentity = (YangIdentity) yangNode.getChild().getNextSibling().getNextSibling()
79 + .getNextSibling();
80 + assertThat(yangIdentity.getName(), is("ipv4-address-family"));
81 + assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family"));
82 + assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family"));
83 +
84 + yangIdentity = (YangIdentity) yangNode.getChild().getNextSibling().getNextSibling()
85 + .getNextSibling().getNextSibling();
86 + assertThat(yangIdentity.getName(), is("ipv6-address-family"));
87 + assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family"));
88 + assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family"));
89 + assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED));
90 +
91 + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
92 + YangLeaf leafInfo = leafIterator.next();
93 +
94 + assertThat(leafInfo.getName(), is("tunnel"));
95 + assertThat(leafInfo.getDataType().getDataTypeName(), is("identityref"));
96 + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF));
97 + YangIdentityRef yangIdentityRef = (YangIdentityRef) leafInfo.getDataType().getDataTypeExtendedInfo();
98 + assertThat(yangIdentityRef.getName(), is("ref-address-family"));
99 + assertThat(yangIdentityRef.getBaseIdentity().getName(), is("ref-address-family"));
100 + assertThat(yangIdentityRef.getReferredIdentity().getName(), is("ref-address-family"));
101 + assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
102 +
103 + ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator();
104 + YangLeafList leafListInfo = leafListIterator.next();
105 +
106 + // Check whether the information in the leaf is correct.
107 + assertThat(leafListInfo.getName(), is("network-ref"));
108 + assertThat(leafListInfo.getDataType().getDataTypeName(), is("identityref"));
109 + assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF));
110 + yangIdentityRef = (YangIdentityRef) (leafListInfo.getDataType().getDataTypeExtendedInfo());
111 +
112 + // Check whether identityref type got resolved.
113 + assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
114 + }
115 +
116 + /**
117 + * Checks for updating datamodel for intrafile resolution identity/identityref.
118 + */
119 + @Test
120 + public void processIntraIdentityrefType() throws IOException, ParserException {
121 +
122 + YangNode node = manager
123 + .getDataModel("src/test/resources/IdentityIntraFile.yang");
124 +
125 + // Check whether the data model tree returned is of type module.
126 + assertThat((node instanceof YangModule), is(true));
127 +
128 + // Check whether the node type is set properly to module.
129 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
130 +
131 + // Check whether the module name is set correctly.
132 + YangModule yangNode = (YangModule) node;
133 + assertThat(yangNode.getName(), is("IdentityIntraFile"));
134 +
135 + YangIdentity yangIdentity = (YangIdentity) yangNode.getChild();
136 + assertThat(yangIdentity.getName(), is("ipv4-address-family"));
137 + assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family"));
138 + assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.INTRA_FILE_RESOLVED));
139 + }
140 +
141 + /**
142 + * Checks for updating datamodel for identityref used in tydedef.
143 + */
144 + @Test
145 + public void processIdentityTypedefStatement() throws IOException, ParserException {
146 +
147 + YangNode node = manager.getDataModel("src/test/resources/IdentityTypedef.yang");
148 +
149 + // Check whether the data model tree returned is of type module.
150 + assertThat((node instanceof YangModule), is(true));
151 +
152 + // Check whether the node type is set properly to module.
153 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
154 +
155 + // Check whether the module name is set correctly.
156 + YangModule yangNode = (YangModule) node;
157 + assertThat(yangNode.getName(), is("Test"));
158 +
159 + YangIdentity yangIdentity = (YangIdentity) yangNode.getChild();
160 + assertThat(yangIdentity.getName(), is("tunnel"));
161 +
162 + YangTypeDef typedef = (YangTypeDef) yangNode.getChild().getNextSibling();
163 + assertThat(typedef.getName(), is("type15"));
164 +
165 + YangType type = typedef.getTypeList().iterator().next();
166 + assertThat(type.getDataType(), is(YangDataTypes.IDENTITYREF));
167 + assertThat(type.getDataTypeName(), is("identityref"));
168 +
169 + YangIdentityRef identityRef = (YangIdentityRef) type.getDataTypeExtendedInfo();
170 + assertThat(identityRef.getName(), is("tunnel"));
171 + assertThat(identityRef.getBaseIdentity().getName(), is("tunnel"));
172 +
173 + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
174 + YangLeaf leafInfo = leafIterator.next();
175 +
176 + assertThat(leafInfo.getName(), is("tunnel-value"));
177 + assertThat(leafInfo.getDataType().getDataTypeName(), is("identityref"));
178 + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF));
179 + YangIdentityRef yangIdentityRef = (YangIdentityRef) leafInfo.getDataType().getDataTypeExtendedInfo();
180 + assertThat(yangIdentityRef.getName(), is("tunnel"));
181 + assertThat(yangIdentityRef.getBaseIdentity().getName(), is("tunnel"));
182 + assertThat(yangIdentityRef.getReferredIdentity().getName(), is("tunnel"));
183 + assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
184 + }
185 +
186 + /**
187 + * Checks for updating datamodel for unresolved status of identityref used in tydedef.
188 + */
189 + @Test
190 + public void processIdentityUnresolvedTypedefStatement() throws IOException, ParserException {
191 +
192 + YangNode node = manager.getDataModel("src/test/resources/IdentityTypedefUnresolved.yang");
193 +
194 + // Check whether the data model tree returned is of type module.
195 + assertThat((node instanceof YangModule), is(true));
196 +
197 + // Check whether the node type is set properly to module.
198 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
199 +
200 + // Check whether the module name is set correctly.
201 + YangModule yangNode = (YangModule) node;
202 + assertThat(yangNode.getName(), is("Test"));
203 +
204 + YangIdentity yangIdentity = (YangIdentity) yangNode.getChild();
205 + assertThat(yangIdentity.getName(), is("tunnel"));
206 +
207 + YangTypeDef typedef = (YangTypeDef) yangNode.getChild().getNextSibling();
208 + assertThat(typedef.getName(), is("type15"));
209 +
210 + YangType type = typedef.getTypeList().iterator().next();
211 + assertThat(type.getDataType(), is(YangDataTypes.IDENTITYREF));
212 + assertThat(type.getDataTypeName(), is("identityref"));
213 +
214 + YangIdentityRef identityRef = (YangIdentityRef) type.getDataTypeExtendedInfo();
215 + assertThat(identityRef.getName(), is("tunnel"));
216 + assertThat(identityRef.getBaseIdentity().getName(), is("tunnel"));
217 + assertThat(identityRef.getResolvableStatus(), is(ResolvableStatus.UNRESOLVED));
218 +
219 + }
220 +}
...@@ -122,20 +122,6 @@ public class TypeListenerTest { ...@@ -122,20 +122,6 @@ public class TypeListenerTest {
122 } 122 }
123 123
124 /** 124 /**
125 - * Checks for unsupported type identityref.
126 - */
127 - @Test
128 - public void processIdentityrefType() throws IOException, ParserException {
129 -
130 - thrown.expect(ParserException.class);
131 - thrown.expectMessage("YANG file error : \"identityref\" is not supported in current version,"
132 - + " please check wiki for YANG utils road map.");
133 -
134 - YangNode node = manager
135 - .getDataModel("src/test/resources/IdentityrefInvalidIdentifier.yang");
136 - }
137 -
138 - /**
139 * Checks for type instance-identifier. 125 * Checks for type instance-identifier.
140 */ 126 */
141 @Test 127 @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 +package org.onosproject.yangutils.plugin.manager;
17 +
18 +import org.apache.maven.plugin.MojoExecutionException;
19 +import org.junit.Rule;
20 +import org.junit.Test;
21 +import org.junit.rules.ExpectedException;
22 +import org.onosproject.yangutils.datamodel.YangIdentity;
23 +import org.onosproject.yangutils.datamodel.YangIdentityRef;
24 +import org.onosproject.yangutils.datamodel.YangLeaf;
25 +import org.onosproject.yangutils.datamodel.YangLeafList;
26 +import org.onosproject.yangutils.datamodel.YangModule;
27 +import org.onosproject.yangutils.datamodel.YangNode;
28 +import org.onosproject.yangutils.datamodel.YangType;
29 +import org.onosproject.yangutils.datamodel.YangTypeDef;
30 +import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
31 +import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
32 +import org.onosproject.yangutils.linker.exceptions.LinkerException;
33 +import org.onosproject.yangutils.linker.impl.YangLinkerManager;
34 +import org.onosproject.yangutils.parser.exceptions.ParserException;
35 +import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
36 +
37 +import java.io.IOException;
38 +import java.util.ListIterator;
39 +
40 +import static org.hamcrest.MatcherAssert.assertThat;
41 +import static org.hamcrest.core.Is.is;
42 +import static org.onosproject.yangutils.datamodel.YangNodeType.MODULE_NODE;
43 +
44 +/**
45 + * Test cases for testing inter file linking for identity.
46 + */
47 +public class InterFileIdentityLinkingTest {
48 + @Rule
49 + public ExpectedException thrown = ExpectedException.none();
50 +
51 + private final YangUtilManager utilManager = new YangUtilManager();
52 + private final YangLinkerManager yangLinkerManager = new YangLinkerManager();
53 +
54 + /**
55 + * Checks inter file feature linking with imported file.
56 + */
57 + @Test
58 + public void processIdentityInImportedFile()
59 + throws IOException, ParserException, MojoExecutionException {
60 +
61 + String searchDir = "src/test/resources/interfileidentityimport";
62 + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
63 + utilManager.parseYangFileInfoSet();
64 + utilManager.createYangNodeSet();
65 +
66 + YangNode selfNode = null;
67 + YangNode refNode1 = null;
68 + YangNode refNode2 = null;
69 +
70 + // Create YANG node set
71 + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet());
72 +
73 + // Add references to import list.
74 + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
75 +
76 + // Carry out inter-file linking.
77 + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
78 +
79 + for (YangNode rootNode : utilManager.getYangNodeSet()) {
80 + if (rootNode.getName().equals("IdentityIntraFile")) {
81 + selfNode = rootNode;
82 + } else if (rootNode.getName().equals("IdentityInModule")) {
83 + refNode1 = rootNode;
84 + } else {
85 + refNode2 = rootNode;
86 + }
87 + }
88 +
89 + // Check whether the data model tree returned is of type module.
90 + assertThat(selfNode instanceof YangModule, is(true));
91 +
92 + // Check whether the node type is set properly to module.
93 + assertThat(selfNode.getNodeType(), is(MODULE_NODE));
94 +
95 + // Check whether the module name is set correctly.
96 + YangModule yangNode = (YangModule) selfNode;
97 + assertThat(yangNode.getName(), is("IdentityIntraFile"));
98 +
99 + YangIdentity yangIdentity = (YangIdentity) yangNode.getChild();
100 + assertThat(yangIdentity.getName(), is("ipv4-address-family"));
101 + assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family"));
102 + assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family"));
103 + assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED));
104 +
105 + yangIdentity = (YangIdentity) yangNode.getChild().getNextSibling();
106 + assertThat(yangIdentity.getName(), is("ipv6-address-family"));
107 + assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family"));
108 + assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family"));
109 + assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED));
110 +
111 + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
112 + YangLeaf leafInfo = leafIterator.next();
113 +
114 + assertThat(leafInfo.getName(), is("tunnel"));
115 + assertThat(leafInfo.getDataType().getDataTypeName(), is("identityref"));
116 + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF));
117 + YangIdentityRef yangIdentityRef = (YangIdentityRef) leafInfo.getDataType().getDataTypeExtendedInfo();
118 + assertThat(yangIdentityRef.getName(), is("ref-address-family"));
119 + assertThat(yangIdentityRef.getBaseIdentity().getName(), is("ref-address-family"));
120 + assertThat(yangIdentityRef.getReferredIdentity().getName(), is("ref-address-family"));
121 + assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
122 +
123 + ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator();
124 + YangLeafList leafListInfo = leafListIterator.next();
125 +
126 + // Check whether the information in the leaf is correct.
127 + assertThat(leafListInfo.getName(), is("network-ref"));
128 + assertThat(leafListInfo.getDataType().getDataTypeName(), is("identityref"));
129 + assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF));
130 + yangIdentityRef = (YangIdentityRef) (leafListInfo.getDataType().getDataTypeExtendedInfo());
131 + assertThat(yangIdentityRef.getBaseIdentity().getName(), is("ref-address-family"));
132 + assertThat(yangIdentityRef.getReferredIdentity().getName(), is("ref-address-family"));
133 + assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
134 +
135 + }
136 +
137 + /**
138 + * Checks inter file feature linking with included file.
139 + */
140 + @Test
141 + public void processIdentityInIncludedFile()
142 + throws IOException, ParserException, MojoExecutionException {
143 +
144 + String searchDir = "src/test/resources/interfileidentityinlude";
145 + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
146 + utilManager.parseYangFileInfoSet();
147 + utilManager.createYangNodeSet();
148 +
149 + YangNode selfNode = null;
150 + YangNode refNode1 = null;
151 + YangNode refNode2 = null;
152 +
153 + // Create YANG node set
154 + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet());
155 +
156 + // Carry out linking of sub module with module.
157 + yangLinkerManager.linkSubModulesToParentModule(utilManager.getYangNodeSet());
158 +
159 + // Add references to import list.
160 + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
161 +
162 + // Add references to include list.
163 + yangLinkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet());
164 +
165 + // Carry out inter-file linking.
166 + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
167 +
168 + for (YangNode rootNode : utilManager.getYangNodeSet()) {
169 + if (rootNode.getName().equals("syslog3")) {
170 + selfNode = rootNode;
171 + } else if (rootNode.getName().equals("syslog4")) {
172 + refNode1 = rootNode;
173 + } else {
174 + refNode2 = rootNode;
175 + }
176 + }
177 +
178 + // Check whether the data model tree returned is of type module.
179 + assertThat(selfNode instanceof YangModule, is(true));
180 +
181 + // Check whether the node type is set properly to module.
182 + assertThat(selfNode.getNodeType(), is(MODULE_NODE));
183 +
184 + // Check whether the module name is set correctly.
185 + YangModule yangNode = (YangModule) selfNode;
186 + assertThat(yangNode.getName(), is("syslog3"));
187 +
188 + YangIdentity yangIdentity = (YangIdentity) yangNode.getChild();
189 + assertThat(yangIdentity.getName(), is("ipv4-address-family"));
190 + assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family"));
191 + assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family"));
192 + assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED));
193 +
194 + yangIdentity = (YangIdentity) yangNode.getChild().getNextSibling();
195 + assertThat(yangIdentity.getName(), is("ipv6-address-family"));
196 + assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family"));
197 + assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family"));
198 + assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED));
199 +
200 + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
201 + YangLeaf leafInfo = leafIterator.next();
202 +
203 + assertThat(leafInfo.getName(), is("tunnel"));
204 + assertThat(leafInfo.getDataType().getDataTypeName(), is("identityref"));
205 + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF));
206 + YangIdentityRef yangIdentityRef = (YangIdentityRef) leafInfo.getDataType().getDataTypeExtendedInfo();
207 + assertThat(yangIdentityRef.getName(), is("ref-address-family"));
208 + assertThat(yangIdentityRef.getBaseIdentity().getName(), is("ref-address-family"));
209 + assertThat(yangIdentityRef.getReferredIdentity().getName(), is("ref-address-family"));
210 + assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
211 +
212 + ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator();
213 + YangLeafList leafListInfo = leafListIterator.next();
214 +
215 + // Check whether the information in the leaf is correct.
216 + assertThat(leafListInfo.getName(), is("network-ref"));
217 + assertThat(leafListInfo.getDataType().getDataTypeName(), is("identityref"));
218 + assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF));
219 + yangIdentityRef = (YangIdentityRef) (leafListInfo.getDataType().getDataTypeExtendedInfo());
220 + assertThat(yangIdentityRef.getBaseIdentity().getName(), is("ref-address-family"));
221 + assertThat(yangIdentityRef.getReferredIdentity().getName(), is("ref-address-family"));
222 + assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
223 + }
224 +
225 + /**
226 + * Checks inter file feature linking with imported file with dependency.
227 + */
228 + @Test
229 + public void processIdentityInImportedFileWithDependency()
230 + throws IOException, ParserException, MojoExecutionException {
231 +
232 + String searchDir = "src/test/resources/interfileidentityimportdependency";
233 + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
234 + utilManager.parseYangFileInfoSet();
235 + utilManager.createYangNodeSet();
236 +
237 + YangNode selfNode = null;
238 + YangNode refNode1 = null;
239 + YangNode refNode2 = null;
240 +
241 + // Create YANG node set
242 + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet());
243 +
244 + // Add references to import list.
245 + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
246 +
247 + // Carry out inter-file linking.
248 + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
249 +
250 + for (YangNode rootNode : utilManager.getYangNodeSet()) {
251 + if (rootNode.getName().equals("syslog1")) {
252 + selfNode = rootNode;
253 + } else if (rootNode.getName().equals("syslog2")) {
254 + refNode1 = rootNode;
255 + } else {
256 + refNode2 = rootNode;
257 + }
258 + }
259 +
260 + // Check whether the data model tree returned is of type module.
261 + assertThat(selfNode instanceof YangModule, is(true));
262 +
263 + // Check whether the node type is set properly to module.
264 + assertThat(selfNode.getNodeType(), is(MODULE_NODE));
265 +
266 + // Check whether the module name is set correctly.
267 + YangModule yangNode = (YangModule) selfNode;
268 + assertThat(yangNode.getName(), is("syslog1"));
269 +
270 + YangIdentity yangIdentity = (YangIdentity) yangNode.getChild();
271 + assertThat(yangIdentity.getName(), is("ipv4-address-family"));
272 + assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family"));
273 + assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family"));
274 + assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED));
275 +
276 + yangIdentity = (YangIdentity) yangNode.getChild().getNextSibling();
277 + assertThat(yangIdentity.getName(), is("ipv6-address-family"));
278 + assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family"));
279 + assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family"));
280 + assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED));
281 +
282 + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
283 + YangLeaf leafInfo = leafIterator.next();
284 +
285 + assertThat(leafInfo.getName(), is("tunnel"));
286 + assertThat(leafInfo.getDataType().getDataTypeName(), is("identityref"));
287 + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF));
288 + YangIdentityRef yangIdentityRef = (YangIdentityRef) leafInfo.getDataType().getDataTypeExtendedInfo();
289 + assertThat(yangIdentityRef.getName(), is("ref-address-family"));
290 + assertThat(yangIdentityRef.getBaseIdentity().getName(), is("ref-address-family"));
291 + assertThat(yangIdentityRef.getReferredIdentity().getName(), is("ref-address-family"));
292 + assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
293 +
294 + ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator();
295 + YangLeafList leafListInfo = leafListIterator.next();
296 +
297 + // Check whether the information in the leaf is correct.
298 + assertThat(leafListInfo.getName(), is("network-ref"));
299 + assertThat(leafListInfo.getDataType().getDataTypeName(), is("identityref"));
300 + assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF));
301 + yangIdentityRef = (YangIdentityRef) (leafListInfo.getDataType().getDataTypeExtendedInfo());
302 + assertThat(yangIdentityRef.getBaseIdentity().getName(), is("ref-address-family"));
303 + assertThat(yangIdentityRef.getReferredIdentity().getName(), is("ref-address-family"));
304 + assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
305 + }
306 +
307 + /**
308 + * Checks inter file feature linking with included file with dependency.
309 + */
310 + @Test
311 + public void processIdentityInIncludedFileWithDependency()
312 + throws IOException, ParserException, MojoExecutionException {
313 +
314 + String searchDir = "src/test/resources/interfileidentityincludedependency";
315 + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
316 + utilManager.parseYangFileInfoSet();
317 + utilManager.createYangNodeSet();
318 +
319 + YangNode selfNode = null;
320 + YangNode refNode1 = null;
321 + YangNode refNode2 = null;
322 +
323 + // Create YANG node set
324 + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet());
325 +
326 + // Carry out linking of sub module with module.
327 + yangLinkerManager.linkSubModulesToParentModule(utilManager.getYangNodeSet());
328 +
329 + // Add references to include list.
330 + yangLinkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet());
331 +
332 + // Add references to import list.
333 + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
334 +
335 + // Carry out inter-file linking.
336 + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
337 +
338 + for (YangNode rootNode : utilManager.getYangNodeSet()) {
339 + if (rootNode.getName().equals("syslog1")) {
340 + selfNode = rootNode;
341 + } else if (rootNode.getName().equals("syslog2")) {
342 + refNode1 = rootNode;
343 + } else {
344 + refNode2 = rootNode;
345 + }
346 + }
347 +
348 + // Check whether the data model tree returned is of type module.
349 + assertThat(selfNode instanceof YangModule, is(true));
350 +
351 + // Check whether the node type is set properly to module.
352 + assertThat(selfNode.getNodeType(), is(MODULE_NODE));
353 +
354 + // Check whether the module name is set correctly.
355 + YangModule yangNode = (YangModule) selfNode;
356 + assertThat(yangNode.getName(), is("syslog1"));
357 +
358 + YangIdentity yangIdentity = (YangIdentity) yangNode.getChild();
359 + assertThat(yangIdentity.getName(), is("ipv4-address-family"));
360 + assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family"));
361 + assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family"));
362 + assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED));
363 +
364 + yangIdentity = (YangIdentity) yangNode.getChild().getNextSibling();
365 + assertThat(yangIdentity.getName(), is("ipv6-address-family"));
366 + assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family"));
367 + assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family"));
368 + assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED));
369 +
370 + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
371 + YangLeaf leafInfo = leafIterator.next();
372 +
373 + assertThat(leafInfo.getName(), is("tunnel"));
374 + assertThat(leafInfo.getDataType().getDataTypeName(), is("identityref"));
375 + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF));
376 + YangIdentityRef yangIdentityRef = (YangIdentityRef) leafInfo.getDataType().getDataTypeExtendedInfo();
377 + assertThat(yangIdentityRef.getName(), is("ref-address-family"));
378 + assertThat(yangIdentityRef.getBaseIdentity().getName(), is("ref-address-family"));
379 + assertThat(yangIdentityRef.getReferredIdentity().getName(), is("ref-address-family"));
380 + assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
381 +
382 + ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator();
383 + YangLeafList leafListInfo = leafListIterator.next();
384 +
385 + // Check whether the information in the leaf is correct.
386 + assertThat(leafListInfo.getName(), is("network-ref"));
387 + assertThat(leafListInfo.getDataType().getDataTypeName(), is("identityref"));
388 + assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF));
389 + yangIdentityRef = (YangIdentityRef) (leafListInfo.getDataType().getDataTypeExtendedInfo());
390 + assertThat(yangIdentityRef.getBaseIdentity().getName(), is("ref-address-family"));
391 + assertThat(yangIdentityRef.getReferredIdentity().getName(), is("ref-address-family"));
392 + assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
393 + }
394 +
395 + /**
396 + * Checks inter file feature linking with imported file with dependency
397 + * feature undefined.
398 + */
399 + @Test
400 + public void processIdentityInImportedFileWithDependencyUndefined()
401 + throws IOException, LinkerException, MojoExecutionException {
402 + thrown.expect(LinkerException.class);
403 + thrown.expectMessage("YANG file error: Unable to find base identity for given base");
404 +
405 + String searchDir = "src/test/resources/interfileidentityimportdependencyUndefined";
406 + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
407 + utilManager.parseYangFileInfoSet();
408 + utilManager.createYangNodeSet();
409 +
410 + YangNode selfNode = null;
411 + YangNode refNode1 = null;
412 + YangNode refNode2 = null;
413 +
414 + // Create YANG node set
415 + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet());
416 +
417 + // Add references to import list.
418 + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
419 +
420 + // Carry out inter-file linking.
421 + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
422 + }
423 +
424 + /**
425 + * Checks inter file feature linking with included file with dependency
426 + * feature undefined.
427 + */
428 + @Test
429 + public void processIdentityInIncludedFileWithDependencyUndefined()
430 + throws IOException, LinkerException, MojoExecutionException {
431 + thrown.expect(LinkerException.class);
432 + thrown.expectMessage("YANG file error: Unable to find base identity for given base");
433 +
434 + String searchDir = "src/test/resources/interfileidentityincludedependencyUndefined";
435 + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
436 + utilManager.parseYangFileInfoSet();
437 + utilManager.createYangNodeSet();
438 +
439 + YangNode selfNode = null;
440 + YangNode refNode1 = null;
441 + YangNode refNode2 = null;
442 +
443 + // Create YANG node set
444 + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet());
445 +
446 + // Carry out linking of sub module with module.
447 + yangLinkerManager.linkSubModulesToParentModule(utilManager.getYangNodeSet());
448 +
449 + // Add references to import list.
450 + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
451 +
452 + // Add references to include list.
453 + yangLinkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet());
454 +
455 + // Carry out inter-file linking.
456 + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
457 + }
458 +
459 + /**
460 + * Checks inter file feature linking with imported file.
461 + */
462 + @Test
463 + public void processIdentityTypedefUnresolvedInImportedFile()
464 + throws IOException, ParserException, MojoExecutionException {
465 +
466 + String searchDir = "src/test/resources/interfileidentitytypedef";
467 + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
468 + utilManager.parseYangFileInfoSet();
469 + utilManager.createYangNodeSet();
470 +
471 + YangNode selfNode = null;
472 + YangNode refNode1 = null;
473 + YangNode refNode2 = null;
474 +
475 + // Create YANG node set
476 + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet());
477 +
478 + // Add references to import list.
479 + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
480 +
481 + // Carry out inter-file linking.
482 + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
483 +
484 + for (YangNode rootNode : utilManager.getYangNodeSet()) {
485 + if (rootNode.getName().equals("IdentityIntraFile")) {
486 + selfNode = rootNode;
487 + } else if (rootNode.getName().equals("IdentityInModule")) {
488 + refNode1 = rootNode;
489 + } else {
490 + refNode2 = rootNode;
491 + }
492 + }
493 + // Check whether the data model tree returned is of type module.
494 + assertThat(selfNode instanceof YangModule, is(true));
495 +
496 + // Check whether the node type is set properly to module.
497 + assertThat(selfNode.getNodeType(), is(MODULE_NODE));
498 +
499 + // Check whether the module name is set correctly.
500 + YangModule yangNode = (YangModule) selfNode;
501 + assertThat(yangNode.getName(), is("IdentityIntraFile"));
502 +
503 + YangIdentity yangIdentity = (YangIdentity) yangNode.getChild();
504 + assertThat(yangIdentity.getName(), is("ipv4-address-family"));
505 + assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family"));
506 + assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family"));
507 + assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED));
508 +
509 + yangIdentity = (YangIdentity) yangNode.getChild().getNextSibling();
510 + assertThat(yangIdentity.getName(), is("ipv6-address-family"));
511 + assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family"));
512 + assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family"));
513 + assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED));
514 +
515 + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
516 + YangLeaf leafInfo = leafIterator.next();
517 +
518 + assertThat(leafInfo.getName(), is("tunnel"));
519 + assertThat(leafInfo.getDataType().getDataTypeName(), is("identityref"));
520 + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF));
521 + YangIdentityRef yangIdentityRef = (YangIdentityRef) leafInfo.getDataType().getDataTypeExtendedInfo();
522 + assertThat(yangIdentityRef.getName(), is("ref-address-family"));
523 + assertThat(yangIdentityRef.getBaseIdentity().getName(), is("ref-address-family"));
524 + assertThat(yangIdentityRef.getReferredIdentity().getName(), is("ref-address-family"));
525 + assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
526 +
527 + ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator();
528 + YangLeafList leafListInfo = leafListIterator.next();
529 +
530 + // Check whether the information in the leaf is correct.
531 + assertThat(leafListInfo.getName(), is("network-ref"));
532 + assertThat(leafListInfo.getDataType().getDataTypeName(), is("identityref"));
533 + assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF));
534 + yangIdentityRef = (YangIdentityRef) (leafListInfo.getDataType().getDataTypeExtendedInfo());
535 + // Check whether leafref type got resolved.
536 + assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
537 +
538 + YangTypeDef typedef = (YangTypeDef) yangNode.getChild().getNextSibling().getNextSibling();
539 + assertThat(typedef.getName(), is("type15"));
540 +
541 + YangType type = typedef.getTypeList().iterator().next();
542 + assertThat(type.getDataType(), is(YangDataTypes.IDENTITYREF));
543 + assertThat(type.getDataTypeName(), is("identityref"));
544 +
545 + YangIdentityRef identityRef = (YangIdentityRef) type.getDataTypeExtendedInfo();
546 + assertThat(identityRef.getName(), is("ref-address-family"));
547 + assertThat(identityRef.getBaseIdentity().getName(), is("ref-address-family"));
548 + assertThat(identityRef.getResolvableStatus(), is(ResolvableStatus.UNRESOLVED));
549 + }
550 +
551 + /**
552 + * Checks inter file feature linking with imported file.
553 + */
554 + @Test
555 + public void processIdentityTypedefInImportedFile()
556 + throws IOException, ParserException, MojoExecutionException {
557 +
558 + String searchDir = "src/test/resources/interfileidentitytypedef";
559 + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
560 + utilManager.parseYangFileInfoSet();
561 + utilManager.createYangNodeSet();
562 +
563 + YangNode selfNode = null;
564 + YangNode refNode1 = null;
565 + YangNode refNode2 = null;
566 +
567 + // Create YANG node set
568 + yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet());
569 +
570 + // Add references to import list.
571 + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
572 +
573 + // Carry out inter-file linking.
574 + yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
575 +
576 + for (YangNode rootNode : utilManager.getYangNodeSet()) {
577 + if (rootNode.getName().equals("IdentityTypedef")) {
578 + selfNode = rootNode;
579 + } else if (rootNode.getName().equals("IdentityInModule")) {
580 + refNode1 = rootNode;
581 + } else {
582 + refNode2 = rootNode;
583 + }
584 + }
585 +
586 + // Check whether the data model tree returned is of type module.
587 + assertThat(selfNode instanceof YangModule, is(true));
588 +
589 + // Check whether the node type is set properly to module.
590 + assertThat(selfNode.getNodeType(), is(MODULE_NODE));
591 +
592 + // Check whether the module name is set correctly.
593 + YangModule yangNode = (YangModule) selfNode;
594 + assertThat(yangNode.getName(), is("IdentityTypedef"));
595 +
596 + YangIdentity yangIdentity = (YangIdentity) yangNode.getChild();
597 + assertThat(yangIdentity.getName(), is("ipv4-address-family"));
598 + assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family"));
599 + assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family"));
600 + assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED));
601 +
602 + yangIdentity = (YangIdentity) yangNode.getChild().getNextSibling();
603 + assertThat(yangIdentity.getName(), is("ipv6-address-family"));
604 + assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family"));
605 + assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family"));
606 + assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED));
607 +
608 + YangTypeDef typedef = (YangTypeDef) yangNode.getChild().getNextSibling().getNextSibling();
609 + assertThat(typedef.getName(), is("type15"));
610 +
611 + YangType type = typedef.getTypeList().iterator().next();
612 + assertThat(type.getDataType(), is(YangDataTypes.IDENTITYREF));
613 + assertThat(type.getDataTypeName(), is("identityref"));
614 +
615 + YangIdentityRef identityRef = (YangIdentityRef) type.getDataTypeExtendedInfo();
616 + assertThat(identityRef.getName(), is("ref-address-family"));
617 + assertThat(identityRef.getBaseIdentity().getName(), is("ref-address-family"));
618 +
619 + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
620 + YangLeaf leafInfo = leafIterator.next();
621 +
622 + assertThat(leafInfo.getName(), is("tunnel"));
623 + assertThat(leafInfo.getDataType().getDataTypeName(), is("identityref"));
624 + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF));
625 + YangIdentityRef yangIdentityRef = (YangIdentityRef) leafInfo.getDataType().getDataTypeExtendedInfo();
626 + assertThat(yangIdentityRef.getName(), is("ref-address-family"));
627 + assertThat(yangIdentityRef.getBaseIdentity().getName(), is("ref-address-family"));
628 + assertThat(yangIdentityRef.getReferredIdentity().getName(), is("ref-address-family"));
629 + assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
630 +
631 + ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator();
632 + YangLeafList leafListInfo = leafListIterator.next();
633 +
634 + // Check whether the information in the leaf is correct.
635 + assertThat(leafListInfo.getName(), is("network-ref"));
636 + assertThat(leafListInfo.getDataType().getDataTypeName(), is("identityref"));
637 + assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF));
638 + yangIdentityRef = (YangIdentityRef) (leafListInfo.getDataType().getDataTypeExtendedInfo());
639 + // Check whether leafref type got resolved.
640 + assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
641 + }
642 +}
1 +module IdentityInModule{
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix IdentityInModule;
5 +
6 + identity tunnel-type {
7 + description
8 + "Base identity from which specific tunnel types are derived.";
9 + }
10 +
11 + identity ref-address-family {
12 + reference "http://www.iana.org/assignments/address-family-numbers/address-family-numbers.xhtml#address-family-numbers-2";
13 + }
14 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module IdentityIntraFile {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix IdentityIntraFile;
5 +
6 + import "IdentityInModule" {
7 + prefix "IdentityInModule";
8 + }
9 +
10 + identity ipv4-address-family {
11 + base IdentityInModule:ref-address-family;
12 + }
13 +
14 + identity ipv6-address-family {
15 + base IdentityInModule:ref-address-family;
16 + }
17 +
18 + leaf tunnel {
19 + type identityref {
20 + base IdentityInModule:ref-address-family;
21 + }
22 + }
23 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module IdentityListener{
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix IdentityListener;
5 +
6 + identity tunnel {
7 + description
8 + "Base identity from which specific tunnel types are derived.";
9 + }
10 +
11 + identity tunnel-type {
12 + description
13 + "Base identity from which specific tunnel types are derived.";
14 + }
15 +
16 + identity ref-address-family {
17 + reference "http://www.iana.org/assignments/address-family-numbers/address-family-numbers.xhtml#address-family-numbers-2";
18 + }
19 +
20 + identity ipv4-address-family {
21 + base ref-address-family;
22 + }
23 +
24 + identity ipv6-address-family {
25 + base ref-address-family;
26 + }
27 +
28 + leaf tunnel {
29 + type identityref {
30 + base ref-address-family;
31 + }
32 + }
33 +
34 + leaf-list network-ref {
35 + type identityref {
36 + base ref-address-family;
37 + }
38 + }
39 +}
...\ 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 +
6 + identity tunnel {
7 + description
8 + "Base identity from which specific tunnel types are derived.";
9 + }
10 +
11 + leaf tunnel-value {
12 + type type15;
13 + }
14 +
15 + typedef type15 {
16 + type identityref {
17 + base tunnel;
18 + }
19 + }
20 +}
...@@ -2,10 +2,15 @@ module Test { ...@@ -2,10 +2,15 @@ module Test {
2 yang-version 1; 2 yang-version 1;
3 namespace http://huawei.com; 3 namespace http://huawei.com;
4 prefix Ant; 4 prefix Ant;
5 - grouping currentcheck { 5 +
6 - leaf invalid-interval { 6 + identity tunnel {
7 - type identityref { 7 + description
8 + "Base identity from which specific tunnel types are derived.";
8 } 9 }
10 +
11 + typedef type15 {
12 + type identityref {
13 + base tunnel;
9 } 14 }
10 } 15 }
11 } 16 }
......
1 +module IdentityTest{
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix IdentityTest;
5 +
6 + identity ref-address-family {
7 + description "ref-address-family";
8 + }
9 +
10 + identity ipv4-address-family {
11 + base ref-address-family;
12 + }
13 +
14 + leaf tunnel {
15 + type identityref {
16 + base ref-address-family;
17 + }
18 + }
19 +}
...\ No newline at end of file ...\ No newline at end of file
1 +
2 +module IdentityInModule{
3 + yang-version 1;
4 + namespace http://huawei.com;
5 + prefix IdentityInModule;
6 +
7 + identity tunnel-type {
8 + description
9 + "Base identity from which specific tunnel types are derived.";
10 + }
11 +
12 + identity ref-address-family {
13 + reference "http://www.iana.org/assignments/address-family-numbers/address-family-numbers.xhtml#address-family-numbers-2";
14 + }
15 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module IdentityIntraFile {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix IdentityIntraFile;
5 +
6 + import "IdentityInModule" {
7 + prefix "IdentityInModule";
8 + }
9 +
10 + identity ipv4-address-family {
11 + base IdentityInModule:ref-address-family;
12 + }
13 +
14 + identity ipv6-address-family {
15 + base IdentityInModule:ref-address-family;
16 + }
17 +
18 + leaf tunnel {
19 + type identityref {
20 + base IdentityInModule:ref-address-family;
21 + }
22 + }
23 +
24 + leaf-list network-ref {
25 + type identityref {
26 + base IdentityInModule:ref-address-family;
27 + }
28 + }
29 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module syslog1 {
2 + yang-version 1;
3 + namespace "http://huawei1.com";
4 + prefix "sys1";
5 +
6 + import "syslog2" {
7 + prefix "sys2";
8 + }
9 +
10 + identity ipv4-address-family {
11 + base sys2:ref-address-family;
12 + }
13 +
14 + identity ipv6-address-family {
15 + base sys2:ref-address-family;
16 + }
17 +
18 + leaf tunnel {
19 + type identityref {
20 + base sys2:ref-address-family;
21 + }
22 + }
23 +
24 + leaf-list network-ref {
25 + type identityref {
26 + base sys2:ref-address-family;
27 + }
28 + }
29 +
30 +}
1 +module syslog2 {
2 + yang-version 1;
3 + namespace "http://huawei2.com";
4 + prefix "sys2";
5 +
6 + import "syslog3" {
7 + prefix "sys3";
8 + }
9 +
10 + identity tunnel-type {
11 + base sys3:final-address-family;
12 + }
13 +
14 + identity ref-address-family {
15 + base sys3:final-address-family;
16 + }
17 +}
1 +module syslog3 {
2 + yang-version 1;
3 + namespace "http://huawei3.com";
4 + prefix "sys3";
5 +
6 + identity final-address-family {
7 + description
8 + "Base identity from which specific tunnel types are derived.";
9 + }
10 +}
1 +module syslog1 {
2 + yang-version 1;
3 + namespace "http://huawei1.com";
4 + prefix "sys1";
5 +
6 + import "syslog2" {
7 + prefix "sys2";
8 + }
9 +
10 + identity ipv4-address-family {
11 + base sys2:ref-address-family;
12 + }
13 +
14 + identity ipv6-address-family {
15 + base sys2:ref-address-family;
16 + }
17 +
18 + leaf tunnel {
19 + type identityref {
20 + base sys2:ref-address-family;
21 + }
22 + }
23 +
24 + leaf-list network-ref {
25 + type identityref {
26 + base sys2:ref-address-family;
27 + }
28 + }
29 +}
1 +module syslog2 {
2 + yang-version 1;
3 + namespace "http://huawei2.com";
4 + prefix "sys2";
5 +
6 + import "syslog3" {
7 + prefix "sys3";
8 + }
9 +
10 + identity tunnel-type {
11 + base sys3:final-address-family;
12 + }
13 +
14 + identity ref-address-family {
15 + base sys3:final-address-family;
16 + }
17 +}
18 +
1 +module syslog3 {
2 + yang-version 1;
3 + namespace "http://huawei3.com";
4 + prefix "sys3";
5 +}
1 +module syslog1 {
2 + yang-version 1;
3 + namespace "http://huawei3.com";
4 + prefix "sys1";
5 +
6 + include "syslog2";
7 +
8 + identity ipv4-address-family {
9 + base ref-address-family;
10 + }
11 +
12 + identity ipv6-address-family {
13 + base ref-address-family;
14 + }
15 +
16 + leaf tunnel {
17 + type identityref {
18 + base ref-address-family;
19 + }
20 + }
21 +
22 + leaf-list network-ref {
23 + type identityref {
24 + base ref-address-family;
25 + }
26 + }
27 +}
1 +submodule syslog2 {
2 + yang-version 1;
3 + belongs-to "syslog1" {
4 + prefix "sys1";
5 + }
6 +
7 + import "syslog3" {
8 + prefix "sys3";
9 + }
10 +
11 + identity tunnel-type {
12 + base sys3:final-address-family;
13 + }
14 +
15 + identity ref-address-family {
16 + base sys3:final-address-family;
17 + }
18 +}
19 +
1 +module syslog3 {
2 + yang-version 1;
3 + namespace "http://huawei3.com";
4 + prefix "sys3";
5 +
6 + identity final-address-family {
7 + description
8 + "Base identity from which specific tunnel types are derived.";
9 + }
10 +}
1 +module syslog1 {
2 + yang-version 1;
3 + namespace "http://huawei3.com";
4 + prefix "sys1";
5 +
6 + include "syslog2";
7 +
8 + identity ipv4-address-family {
9 + base sys2:ref-address-family;
10 + }
11 +
12 + identity ipv6-address-family {
13 + base sys2:ref-address-family;
14 + }
15 +
16 + leaf tunnel {
17 + type identityref {
18 + base sys2:ref-address-family;
19 + }
20 + }
21 +
22 + leaf-list network-ref {
23 + type identityref {
24 + base sys2:ref-address-family;
25 + }
26 + }
27 +}
1 +submodule syslog2 {
2 + yang-version 1;
3 + belongs-to "syslog1" {
4 + prefix "sys1";
5 + }
6 +
7 + import "syslog3" {
8 + prefix "sys3";
9 + }
10 +
11 + identity tunnel-type {
12 + base sys3:final-address-family;
13 + }
14 +
15 + identity ref-address-family {
16 + base sys3:final-address-family;
17 + }
18 +}
19 +
1 +module syslog3 {
2 + yang-version 1;
3 + namespace "http://huawei3.com";
4 + prefix "sys3";
5 +}
1 +module syslog3 {
2 + yang-version 1;
3 + namespace "http://huawei3.com";
4 + prefix "sys3";
5 +
6 + include "syslog4";
7 +
8 + identity ipv4-address-family {
9 + base ref-address-family;
10 + }
11 +
12 + identity ipv6-address-family {
13 + base ref-address-family;
14 + }
15 +
16 + leaf tunnel {
17 + type identityref {
18 + base ref-address-family;
19 + }
20 + }
21 +
22 + leaf-list network-ref {
23 + type identityref {
24 + base ref-address-family;
25 + }
26 + }
27 +}
1 +submodule syslog4 {
2 + yang-version 1;
3 + belongs-to "syslog3" {
4 + prefix "sys3";
5 + }
6 +
7 + identity tunnel-type {
8 + description
9 + "Base identity from which specific tunnel types are derived.";
10 + }
11 +
12 + identity ref-address-family {
13 + reference "http://www.iana.org/assignments/address-family-numbers/address-family-numbers.xhtml#address-family-numbers-2";
14 + }
15 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module IdentityInModule{
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix IdentityInModule;
5 +
6 + identity tunnel-type {
7 + description
8 + "Base identity from which specific tunnel types are derived.";
9 + }
10 +
11 + identity ref-address-family {
12 + reference "http://www.iana.org/assignments/address-family-numbers/address-family-numbers.xhtml#address-family-numbers-2";
13 + }
14 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module IdentityIntraFile {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix IdentityIntraFile;
5 +
6 + import "IdentityInModule" {
7 + prefix "IdentityInModule";
8 + }
9 +
10 + identity ipv4-address-family {
11 + base IdentityInModule:ref-address-family;
12 + }
13 +
14 + identity ipv6-address-family {
15 + base IdentityInModule:ref-address-family;
16 + }
17 +
18 + leaf tunnel {
19 + type identityref {
20 + base IdentityInModule:ref-address-family;
21 + }
22 + }
23 +
24 + leaf-list network-ref {
25 + type identityref {
26 + base IdentityInModule:ref-address-family;
27 + }
28 + }
29 +
30 + typedef type15 {
31 + type identityref {
32 + base IdentityInModule:ref-address-family;
33 + }
34 + }
35 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module IdentityTypedef {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix IdentityTypedef;
5 +
6 + import "IdentityInModule" {
7 + prefix "IdentityInModule";
8 + }
9 +
10 + identity ipv4-address-family {
11 + base IdentityInModule:ref-address-family;
12 + }
13 +
14 + identity ipv6-address-family {
15 + base IdentityInModule:ref-address-family;
16 + }
17 +
18 + leaf tunnel {
19 + type type15;
20 + }
21 +
22 + leaf-list network-ref {
23 + type type15;
24 + }
25 +
26 + typedef type15 {
27 + type identityref {
28 + base IdentityInModule:ref-address-family;
29 + }
30 + }
31 +}
...\ No newline at end of file ...\ No newline at end of file
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
56 reference "RFC3209"; 56 reference "RFC3209";
57 } 57 }
58 58
59 - /*identity tunnel-type { 59 + identity tunnel-type {
60 description 60 description
61 "Base identity from which specific tunnel types are 61 "Base identity from which specific tunnel types are
62 derived."; 62 derived.";
...@@ -254,7 +254,7 @@ ...@@ -254,7 +254,7 @@
254 base lsp-encoding-types; 254 base lsp-encoding-types;
255 description 255 description
256 "Line (e.g., 8B/10B) LSP encoding"; 256 "Line (e.g., 8B/10B) LSP encoding";
257 - }*/ 257 + }
258 258
259 /* TE basic features */ 259 /* TE basic features */
260 feature p2mp-te { 260 feature p2mp-te {
...@@ -452,7 +452,7 @@ ...@@ -452,7 +452,7 @@
452 } 452 }
453 } 453 }
454 454
455 - /*identity route-usage-type { 455 + identity route-usage-type {
456 description 456 description
457 "Base identity for route usage"; 457 "Base identity for route usage";
458 } 458 }
...@@ -576,7 +576,7 @@ ...@@ -576,7 +576,7 @@
576 description 576 description
577 "The set of attribute filters associated with a 577 "The set of attribute filters associated with a
578 tunnel any of which renders a link unacceptable"; 578 tunnel any of which renders a link unacceptable";
579 - }*/ 579 + }
580 580
581 typedef admin-group { 581 typedef admin-group {
582 type binary { 582 type binary {
...@@ -605,7 +605,7 @@ ...@@ -605,7 +605,7 @@
605 description "SRLG type"; 605 description "SRLG type";
606 } 606 }
607 607
608 - /*identity path-computation-srlg-type { 608 + identity path-computation-srlg-type {
609 description 609 description
610 "Base identity for SRLG path computation"; 610 "Base identity for SRLG path computation";
611 } 611 }
...@@ -632,7 +632,7 @@ ...@@ -632,7 +632,7 @@
632 base path-computation-srlg-type; 632 base path-computation-srlg-type;
633 description 633 description
634 "Include weighted SRLG check in path computation"; 634 "Include weighted SRLG check in path computation";
635 - }*/ 635 + }
636 636
637 typedef te-metric { 637 typedef te-metric {
638 type uint32; 638 type uint32;
......