Committed by
Vidyashree-Huawei
[ONOS-4894][ONOS-4890][ONOS-4887][ONOS-4923]extension and argument
datamodel and listener + defect fix Change-Id: Icefe046d9848935bb6c40a6d7688feb084edd65d
Showing
25 changed files
with
915 additions
and
66 deletions
| ... | @@ -354,7 +354,7 @@ public class YangCase | ... | @@ -354,7 +354,7 @@ public class YangCase |
| 354 | @Override | 354 | @Override |
| 355 | public void detectCollidingChild(String identifierName, YangConstructType dataType) | 355 | public void detectCollidingChild(String identifierName, YangConstructType dataType) |
| 356 | throws DataModelException { | 356 | throws DataModelException { |
| 357 | - if (!(getParent() instanceof YangChoice)) { | 357 | + if (!(getParent() instanceof YangChoice || getParent() instanceof YangAugment)) { |
| 358 | throw new DataModelException("Internal Data Model Tree Error: Invalid/Missing holder in case " + | 358 | throw new DataModelException("Internal Data Model Tree Error: Invalid/Missing holder in case " + |
| 359 | getName()); | 359 | getName()); |
| 360 | } | 360 | } | ... | ... |
utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangExtension.java
0 → 100644
| 1 | +/* | ||
| 2 | + * Copyright 2016-present Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | + | ||
| 17 | +package org.onosproject.yangutils.datamodel; | ||
| 18 | + | ||
| 19 | +import java.io.Serializable; | ||
| 20 | +import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | ||
| 21 | +import org.onosproject.yangutils.datamodel.utils.Parsable; | ||
| 22 | +import org.onosproject.yangutils.datamodel.utils.YangConstructType; | ||
| 23 | + | ||
| 24 | +/*- | ||
| 25 | + * Reference RFC 6020. | ||
| 26 | + * | ||
| 27 | + * The "extension" statement allows the definition of new statements | ||
| 28 | + * within the YANG language. This new statement definition can be | ||
| 29 | + * imported and used by other modules. | ||
| 30 | + * | ||
| 31 | + * The statement's argument is an identifier that is the new keyword for | ||
| 32 | + * the extension and must be followed by a block of sub-statements that | ||
| 33 | + * holds detailed extension information. The purpose of the "extension" | ||
| 34 | + * statement is to define a keyword, so that it can be imported and used | ||
| 35 | + * by other modules. | ||
| 36 | + * | ||
| 37 | + * The extension can be used like a normal YANG statement, with the | ||
| 38 | + * statement name followed by an argument if one is defined by the | ||
| 39 | + * extension, and an optional block of sub-statements. The statement's | ||
| 40 | + * name is created by combining the prefix of the module in which the | ||
| 41 | + * extension was defined, a colon (":"), and the extension's keyword, | ||
| 42 | + * with no interleaving whitespace. The sub-statements of an extension | ||
| 43 | + * are defined by the extension, using some mechanism outside the scope | ||
| 44 | + * of this specification. Syntactically, the sub-statements MUST be YANG | ||
| 45 | + * statements, or also defined using "extension" statements. | ||
| 46 | + * | ||
| 47 | + * The extension's Sub-statements | ||
| 48 | + * | ||
| 49 | + * +--------------+---------+-------------+------------------+ | ||
| 50 | + * | substatement | section | cardinality |data model mapping| | ||
| 51 | + * +--------------+---------+-------------+------------------+ | ||
| 52 | + * | description | 7.19.3 | 0..1 | -string | | ||
| 53 | + * | reference | 7.19.4 | 0..1 | -string | | ||
| 54 | + * | status | 7.19.2 | 0..1 | -YangStatus | | ||
| 55 | + * | argument | 7.17.2 | 0..1 | -string | | ||
| 56 | + * +--------------+---------+-------------+------------------+ | ||
| 57 | + */ | ||
| 58 | + | ||
| 59 | +/** | ||
| 60 | + * Represents data model node to maintain information defined in YANG extension. | ||
| 61 | + */ | ||
| 62 | +public class YangExtension | ||
| 63 | + implements YangCommonInfo, Serializable, Parsable { | ||
| 64 | + | ||
| 65 | + private static final long serialVersionUID = 806201605L; | ||
| 66 | + | ||
| 67 | + /** | ||
| 68 | + * Name of the extension. | ||
| 69 | + */ | ||
| 70 | + private String name; | ||
| 71 | + | ||
| 72 | + /** | ||
| 73 | + * Name of the argument. | ||
| 74 | + */ | ||
| 75 | + private String argumentName; | ||
| 76 | + | ||
| 77 | + /** | ||
| 78 | + * Description of extension. | ||
| 79 | + */ | ||
| 80 | + private String description; | ||
| 81 | + | ||
| 82 | + /** | ||
| 83 | + * Reference of the extension. | ||
| 84 | + */ | ||
| 85 | + private String reference; | ||
| 86 | + | ||
| 87 | + /** | ||
| 88 | + * Status of the extension. | ||
| 89 | + */ | ||
| 90 | + private YangStatusType status = YangStatusType.CURRENT; | ||
| 91 | + | ||
| 92 | + /** | ||
| 93 | + * Returns the YANG name of extension. | ||
| 94 | + * | ||
| 95 | + * @return the name of extension as defined in YANG file | ||
| 96 | + */ | ||
| 97 | + public String getName() { | ||
| 98 | + return name; | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + /** | ||
| 102 | + * Sets the YANG name of extension. | ||
| 103 | + * | ||
| 104 | + * @param name the name of extension as defined in YANG file | ||
| 105 | + */ | ||
| 106 | + public void setName(String name) { | ||
| 107 | + this.name = name; | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + /** | ||
| 111 | + * Returns the YANG argument name of extension. | ||
| 112 | + * | ||
| 113 | + * @return the name of argument as defined in YANG file | ||
| 114 | + */ | ||
| 115 | + public String getArgumentName() { | ||
| 116 | + return argumentName; | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + /** | ||
| 120 | + * Sets the YANG argument name of extension. | ||
| 121 | + * | ||
| 122 | + * @param argumentName the name of argument as defined in YANG file | ||
| 123 | + */ | ||
| 124 | + public void setArgumentName(String argumentName) { | ||
| 125 | + this.argumentName = argumentName; | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + /** | ||
| 129 | + * Returns the description. | ||
| 130 | + * | ||
| 131 | + * @return the description | ||
| 132 | + */ | ||
| 133 | + @Override | ||
| 134 | + public String getDescription() { | ||
| 135 | + return description; | ||
| 136 | + } | ||
| 137 | + | ||
| 138 | + /** | ||
| 139 | + * Sets the description. | ||
| 140 | + * | ||
| 141 | + * @param description set the description | ||
| 142 | + */ | ||
| 143 | + @Override | ||
| 144 | + public void setDescription(String description) { | ||
| 145 | + this.description = description; | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | + /** | ||
| 149 | + * Returns the textual reference. | ||
| 150 | + * | ||
| 151 | + * @return the reference | ||
| 152 | + */ | ||
| 153 | + @Override | ||
| 154 | + public String getReference() { | ||
| 155 | + return reference; | ||
| 156 | + } | ||
| 157 | + | ||
| 158 | + /** | ||
| 159 | + * Sets the textual reference. | ||
| 160 | + * | ||
| 161 | + * @param reference the reference to set | ||
| 162 | + */ | ||
| 163 | + @Override | ||
| 164 | + public void setReference(String reference) { | ||
| 165 | + this.reference = reference; | ||
| 166 | + } | ||
| 167 | + | ||
| 168 | + /** | ||
| 169 | + * Returns the status. | ||
| 170 | + * | ||
| 171 | + * @return the status | ||
| 172 | + */ | ||
| 173 | + @Override | ||
| 174 | + public YangStatusType getStatus() { | ||
| 175 | + return status; | ||
| 176 | + } | ||
| 177 | + | ||
| 178 | + /** | ||
| 179 | + * Sets the status. | ||
| 180 | + * | ||
| 181 | + * @param status the status to set | ||
| 182 | + */ | ||
| 183 | + @Override | ||
| 184 | + public void setStatus(YangStatusType status) { | ||
| 185 | + this.status = status; | ||
| 186 | + } | ||
| 187 | + | ||
| 188 | + /** | ||
| 189 | + * Returns the type of the data. | ||
| 190 | + * | ||
| 191 | + * @return returns EXTENSION_DATA | ||
| 192 | + */ | ||
| 193 | + @Override | ||
| 194 | + public YangConstructType getYangConstructType() { | ||
| 195 | + return YangConstructType.EXTENSION_DATA; | ||
| 196 | + } | ||
| 197 | + | ||
| 198 | + /** | ||
| 199 | + * Validates the data on entering the corresponding parse tree node. | ||
| 200 | + * | ||
| 201 | + * @throws DataModelException a violation of data model rules | ||
| 202 | + */ | ||
| 203 | + @Override | ||
| 204 | + public void validateDataOnEntry() | ||
| 205 | + throws DataModelException { | ||
| 206 | + // TODO auto-generated method stub, to be implemented by parser | ||
| 207 | + } | ||
| 208 | + | ||
| 209 | + /** | ||
| 210 | + * Validates the data on exiting the corresponding parse tree node. | ||
| 211 | + * | ||
| 212 | + * @throws DataModelException a violation of data model rules | ||
| 213 | + */ | ||
| 214 | + @Override | ||
| 215 | + public void validateDataOnExit() | ||
| 216 | + throws DataModelException { | ||
| 217 | + // TODO : to be implemented | ||
| 218 | + } | ||
| 219 | +} |
| ... | @@ -231,6 +231,11 @@ public class YangModule | ... | @@ -231,6 +231,11 @@ public class YangModule |
| 231 | private List<YangResolutionInfo> augmentResolutionList; | 231 | private List<YangResolutionInfo> augmentResolutionList; |
| 232 | 232 | ||
| 233 | /** | 233 | /** |
| 234 | + * extension list. | ||
| 235 | + */ | ||
| 236 | + private List<YangExtension> extensionList; | ||
| 237 | + | ||
| 238 | + /** | ||
| 234 | * Creates a YANG node of module type. | 239 | * Creates a YANG node of module type. |
| 235 | */ | 240 | */ |
| 236 | public YangModule() { | 241 | public YangModule() { |
| ... | @@ -247,6 +252,7 @@ public class YangModule | ... | @@ -247,6 +252,7 @@ public class YangModule |
| 247 | includeList = new LinkedList<YangInclude>(); | 252 | includeList = new LinkedList<YangInclude>(); |
| 248 | listOfLeaf = new LinkedList<YangLeaf>(); | 253 | listOfLeaf = new LinkedList<YangLeaf>(); |
| 249 | listOfLeafList = new LinkedList<YangLeafList>(); | 254 | listOfLeafList = new LinkedList<YangLeafList>(); |
| 255 | + extensionList = new LinkedList<YangExtension>(); | ||
| 250 | } | 256 | } |
| 251 | 257 | ||
| 252 | /** | 258 | /** |
| ... | @@ -557,6 +563,33 @@ public class YangModule | ... | @@ -557,6 +563,33 @@ public class YangModule |
| 557 | } | 563 | } |
| 558 | 564 | ||
| 559 | /** | 565 | /** |
| 566 | + * Adds extension in extension list. | ||
| 567 | + * | ||
| 568 | + * @param extension the extension to be added | ||
| 569 | + */ | ||
| 570 | + public void addExtension(YangExtension extension) { | ||
| 571 | + getExtensionList().add(extension); | ||
| 572 | + } | ||
| 573 | + | ||
| 574 | + /** | ||
| 575 | + * Returns the extension list. | ||
| 576 | + * | ||
| 577 | + * @return the extension list | ||
| 578 | + */ | ||
| 579 | + public List<YangExtension> getExtensionList() { | ||
| 580 | + return extensionList; | ||
| 581 | + } | ||
| 582 | + | ||
| 583 | + /** | ||
| 584 | + * Sets the extension list. | ||
| 585 | + * | ||
| 586 | + * @param extensionList the list of extension | ||
| 587 | + */ | ||
| 588 | + public void setExtensionList(List<YangExtension> extensionList) { | ||
| 589 | + this.extensionList = extensionList; | ||
| 590 | + } | ||
| 591 | + | ||
| 592 | + /** | ||
| 560 | * Returns the type of the parsed data. | 593 | * Returns the type of the parsed data. |
| 561 | * | 594 | * |
| 562 | * @return returns MODULE_DATA | 595 | * @return returns MODULE_DATA |
| ... | @@ -639,7 +672,7 @@ public class YangModule | ... | @@ -639,7 +672,7 @@ public class YangModule |
| 639 | leafrefResolutionList.add(resolutionInfo); | 672 | leafrefResolutionList.add(resolutionInfo); |
| 640 | } else if (type == ResolvableType.YANG_BASE) { | 673 | } else if (type == ResolvableType.YANG_BASE) { |
| 641 | baseResolutionList.add(resolutionInfo); | 674 | baseResolutionList.add(resolutionInfo); |
| 642 | - } else if (type == ResolvableType.YANG_AUGMENT) { | 675 | + } else if (type == ResolvableType.YANG_AUGMENT) { |
| 643 | augmentResolutionList.add(resolutionInfo); | 676 | augmentResolutionList.add(resolutionInfo); |
| 644 | } else if (type == ResolvableType.YANG_IDENTITYREF) { | 677 | } else if (type == ResolvableType.YANG_IDENTITYREF) { |
| 645 | identityrefResolutionList.add(resolutionInfo); | 678 | identityrefResolutionList.add(resolutionInfo); |
| ... | @@ -659,7 +692,7 @@ public class YangModule | ... | @@ -659,7 +692,7 @@ public class YangModule |
| 659 | leafrefResolutionList = resolutionList; | 692 | leafrefResolutionList = resolutionList; |
| 660 | } else if (type == ResolvableType.YANG_BASE) { | 693 | } else if (type == ResolvableType.YANG_BASE) { |
| 661 | baseResolutionList = resolutionList; | 694 | baseResolutionList = resolutionList; |
| 662 | - } else if (type == ResolvableType.YANG_AUGMENT) { | 695 | + } else if (type == ResolvableType.YANG_AUGMENT) { |
| 663 | augmentResolutionList = resolutionList; | 696 | augmentResolutionList = resolutionList; |
| 664 | } else if (type == ResolvableType.YANG_IDENTITYREF) { | 697 | } else if (type == ResolvableType.YANG_IDENTITYREF) { |
| 665 | identityrefResolutionList = resolutionList; | 698 | identityrefResolutionList = resolutionList; | ... | ... |
| ... | @@ -224,6 +224,11 @@ public class YangSubModule | ... | @@ -224,6 +224,11 @@ public class YangSubModule |
| 224 | private List<YangResolutionInfo> identityrefResolutionList; | 224 | private List<YangResolutionInfo> identityrefResolutionList; |
| 225 | 225 | ||
| 226 | /** | 226 | /** |
| 227 | + * extension list. | ||
| 228 | + */ | ||
| 229 | + private List<YangExtension> extensionList; | ||
| 230 | + | ||
| 231 | + /** | ||
| 227 | * Augment resolution list. | 232 | * Augment resolution list. |
| 228 | */ | 233 | */ |
| 229 | private List<YangResolutionInfo> augmentResolutionList; | 234 | private List<YangResolutionInfo> augmentResolutionList; |
| ... | @@ -244,6 +249,7 @@ public class YangSubModule | ... | @@ -244,6 +249,7 @@ public class YangSubModule |
| 244 | includeList = new LinkedList<YangInclude>(); | 249 | includeList = new LinkedList<YangInclude>(); |
| 245 | listOfLeaf = new LinkedList<YangLeaf>(); | 250 | listOfLeaf = new LinkedList<YangLeaf>(); |
| 246 | listOfLeafList = new LinkedList<YangLeafList>(); | 251 | listOfLeafList = new LinkedList<YangLeafList>(); |
| 252 | + extensionList = new LinkedList<YangExtension>(); | ||
| 247 | } | 253 | } |
| 248 | 254 | ||
| 249 | /** | 255 | /** |
| ... | @@ -601,7 +607,7 @@ public class YangSubModule | ... | @@ -601,7 +607,7 @@ public class YangSubModule |
| 601 | leafrefResolutionList.add(resolutionInfo); | 607 | leafrefResolutionList.add(resolutionInfo); |
| 602 | } else if (type == ResolvableType.YANG_BASE) { | 608 | } else if (type == ResolvableType.YANG_BASE) { |
| 603 | baseResolutionList.add(resolutionInfo); | 609 | baseResolutionList.add(resolutionInfo); |
| 604 | - } else if (type == ResolvableType.YANG_AUGMENT) { | 610 | + } else if (type == ResolvableType.YANG_AUGMENT) { |
| 605 | augmentResolutionList.add(resolutionInfo); | 611 | augmentResolutionList.add(resolutionInfo); |
| 606 | } else if (type == ResolvableType.YANG_IDENTITYREF) { | 612 | } else if (type == ResolvableType.YANG_IDENTITYREF) { |
| 607 | identityrefResolutionList.add(resolutionInfo); | 613 | identityrefResolutionList.add(resolutionInfo); |
| ... | @@ -621,7 +627,7 @@ public class YangSubModule | ... | @@ -621,7 +627,7 @@ public class YangSubModule |
| 621 | leafrefResolutionList = resolutionList; | 627 | leafrefResolutionList = resolutionList; |
| 622 | } else if (type == ResolvableType.YANG_BASE) { | 628 | } else if (type == ResolvableType.YANG_BASE) { |
| 623 | baseResolutionList = resolutionList; | 629 | baseResolutionList = resolutionList; |
| 624 | - } else if (type == ResolvableType.YANG_AUGMENT) { | 630 | + } else if (type == ResolvableType.YANG_AUGMENT) { |
| 625 | augmentResolutionList = resolutionList; | 631 | augmentResolutionList = resolutionList; |
| 626 | } else if (type == ResolvableType.YANG_IDENTITYREF) { | 632 | } else if (type == ResolvableType.YANG_IDENTITYREF) { |
| 627 | identityrefResolutionList = resolutionList; | 633 | identityrefResolutionList = resolutionList; |
| ... | @@ -684,4 +690,31 @@ public class YangSubModule | ... | @@ -684,4 +690,31 @@ public class YangSubModule |
| 684 | public void setListOfFeature(List<YangFeature> listOfFeature) { | 690 | public void setListOfFeature(List<YangFeature> listOfFeature) { |
| 685 | this.listOfFeature = listOfFeature; | 691 | this.listOfFeature = listOfFeature; |
| 686 | } | 692 | } |
| 693 | + | ||
| 694 | + /** | ||
| 695 | + * Adds extension in extension list. | ||
| 696 | + * | ||
| 697 | + * @param extension the extension to be added | ||
| 698 | + */ | ||
| 699 | + public void addExtension(YangExtension extension) { | ||
| 700 | + getExtensionList().add(extension); | ||
| 701 | + } | ||
| 702 | + | ||
| 703 | + /** | ||
| 704 | + * Returns the extension list. | ||
| 705 | + * | ||
| 706 | + * @return the extension list | ||
| 707 | + */ | ||
| 708 | + public List<YangExtension> getExtensionList() { | ||
| 709 | + return extensionList; | ||
| 710 | + } | ||
| 711 | + | ||
| 712 | + /** | ||
| 713 | + * Sets the extension list. | ||
| 714 | + * | ||
| 715 | + * @param extensionList the list of extension | ||
| 716 | + */ | ||
| 717 | + public void setExtensionList(List<YangExtension> extensionList) { | ||
| 718 | + this.extensionList = extensionList; | ||
| 719 | + } | ||
| 687 | } | 720 | } | ... | ... |
| ... | @@ -382,7 +382,12 @@ public enum YangConstructType { | ... | @@ -382,7 +382,12 @@ public enum YangConstructType { |
| 382 | /** | 382 | /** |
| 383 | * Identifies the YANG anyxml element parsed data. | 383 | * Identifies the YANG anyxml element parsed data. |
| 384 | */ | 384 | */ |
| 385 | - ANYXML_DATA; | 385 | + ANYXML_DATA, |
| 386 | + | ||
| 387 | + /** | ||
| 388 | + * Identifies the YANG argument element parsed data. | ||
| 389 | + */ | ||
| 390 | + ARGUMENT_DATA; | ||
| 386 | 391 | ||
| 387 | /** | 392 | /** |
| 388 | * Returns the YANG construct keyword corresponding to enum values. | 393 | * Returns the YANG construct keyword corresponding to enum values. |
| ... | @@ -539,6 +544,8 @@ public enum YangConstructType { | ... | @@ -539,6 +544,8 @@ public enum YangConstructType { |
| 539 | return "deviation"; | 544 | return "deviation"; |
| 540 | case ANYXML_DATA: | 545 | case ANYXML_DATA: |
| 541 | return "anyxml"; | 546 | return "anyxml"; |
| 547 | + case ARGUMENT_DATA: | ||
| 548 | + return "argument"; | ||
| 542 | default: | 549 | default: |
| 543 | return "yang"; | 550 | return "yang"; |
| 544 | } | 551 | } | ... | ... |
| ... | @@ -16,8 +16,14 @@ | ... | @@ -16,8 +16,14 @@ |
| 16 | 16 | ||
| 17 | package org.onosproject.yangutils.linker.impl; | 17 | package org.onosproject.yangutils.linker.impl; |
| 18 | 18 | ||
| 19 | +import java.io.Serializable; | ||
| 20 | +import java.util.Iterator; | ||
| 21 | +import java.util.LinkedList; | ||
| 22 | +import java.util.List; | ||
| 23 | +import java.util.Stack; | ||
| 19 | import org.onosproject.yangutils.datamodel.Resolvable; | 24 | import org.onosproject.yangutils.datamodel.Resolvable; |
| 20 | import org.onosproject.yangutils.datamodel.ResolvableType; | 25 | import org.onosproject.yangutils.datamodel.ResolvableType; |
| 26 | +import org.onosproject.yangutils.datamodel.TraversalType; | ||
| 21 | import org.onosproject.yangutils.datamodel.YangAtomicPath; | 27 | import org.onosproject.yangutils.datamodel.YangAtomicPath; |
| 22 | import org.onosproject.yangutils.datamodel.YangAugment; | 28 | import org.onosproject.yangutils.datamodel.YangAugment; |
| 23 | import org.onosproject.yangutils.datamodel.YangAugmentableNode; | 29 | import org.onosproject.yangutils.datamodel.YangAugmentableNode; |
| ... | @@ -58,12 +64,10 @@ import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes; | ... | @@ -58,12 +64,10 @@ import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes; |
| 58 | import org.onosproject.yangutils.linker.YangLinkingPhase; | 64 | import org.onosproject.yangutils.linker.YangLinkingPhase; |
| 59 | import org.onosproject.yangutils.linker.exceptions.LinkerException; | 65 | import org.onosproject.yangutils.linker.exceptions.LinkerException; |
| 60 | 66 | ||
| 61 | -import java.io.Serializable; | 67 | +import static org.onosproject.yangutils.datamodel.TraversalType.CHILD; |
| 62 | -import java.util.Iterator; | 68 | +import static org.onosproject.yangutils.datamodel.TraversalType.PARENT; |
| 63 | -import java.util.LinkedList; | 69 | +import static org.onosproject.yangutils.datamodel.TraversalType.ROOT; |
| 64 | -import java.util.List; | 70 | +import static org.onosproject.yangutils.datamodel.TraversalType.SIBILING; |
| 65 | -import java.util.Stack; | ||
| 66 | - | ||
| 67 | import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.addResolutionInfo; | 71 | import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.addResolutionInfo; |
| 68 | import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.INTER_FILE_LINKED; | 72 | import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.INTER_FILE_LINKED; |
| 69 | import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.INTRA_FILE_RESOLVED; | 73 | import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.INTRA_FILE_RESOLVED; |
| ... | @@ -1007,16 +1011,33 @@ public class YangResolutionInfoImpl<T> | ... | @@ -1007,16 +1011,33 @@ public class YangResolutionInfoImpl<T> |
| 1007 | /** | 1011 | /** |
| 1008 | * Search the grouping node's children for presence of uses node. | 1012 | * Search the grouping node's children for presence of uses node. |
| 1009 | */ | 1013 | */ |
| 1014 | + TraversalType curTraversal = ROOT; | ||
| 1010 | YangNode curNode = node.getChild(); | 1015 | YangNode curNode = node.getChild(); |
| 1011 | while (curNode != null) { | 1016 | while (curNode != null) { |
| 1017 | + if (curNode.getName().equals(node.getName())) { | ||
| 1018 | + // if we have traversed all the child nodes, then exit from loop | ||
| 1019 | + return; | ||
| 1020 | + } | ||
| 1021 | + | ||
| 1022 | + // if child nodes has uses, then add it to resolution stack | ||
| 1012 | if (curNode instanceof YangUses) { | 1023 | if (curNode instanceof YangUses) { |
| 1013 | YangEntityToResolveInfoImpl<YangUses> unResolvedEntityInfo = new YangEntityToResolveInfoImpl<>(); | 1024 | YangEntityToResolveInfoImpl<YangUses> unResolvedEntityInfo = new YangEntityToResolveInfoImpl<>(); |
| 1014 | unResolvedEntityInfo.setEntityToResolve((YangUses) curNode); | 1025 | unResolvedEntityInfo.setEntityToResolve((YangUses) curNode); |
| 1015 | unResolvedEntityInfo.setHolderOfEntityToResolve(node); | 1026 | unResolvedEntityInfo.setHolderOfEntityToResolve(node); |
| 1016 | addInPartialResolvedStack((YangEntityToResolveInfoImpl<T>) unResolvedEntityInfo); | 1027 | addInPartialResolvedStack((YangEntityToResolveInfoImpl<T>) unResolvedEntityInfo); |
| 1028 | + } | ||
| 1017 | 1029 | ||
| 1030 | + // Traversing all the child nodes of grouping | ||
| 1031 | + if (curTraversal != PARENT && curNode.getChild() != null) { | ||
| 1032 | + curTraversal = CHILD; | ||
| 1033 | + curNode = curNode.getChild(); | ||
| 1034 | + } else if (curNode.getNextSibling() != null) { | ||
| 1035 | + curTraversal = SIBILING; | ||
| 1036 | + curNode = curNode.getNextSibling(); | ||
| 1037 | + } else { | ||
| 1038 | + curTraversal = PARENT; | ||
| 1039 | + curNode = curNode.getParent(); | ||
| 1018 | } | 1040 | } |
| 1019 | - curNode = curNode.getNextSibling(); | ||
| 1020 | } | 1041 | } |
| 1021 | } | 1042 | } |
| 1022 | 1043 | ||
| ... | @@ -1421,7 +1442,7 @@ public class YangResolutionInfoImpl<T> | ... | @@ -1421,7 +1442,7 @@ public class YangResolutionInfoImpl<T> |
| 1421 | * @param resolutionInfo information about the YANG construct which has to be resolved | 1442 | * @param resolutionInfo information about the YANG construct which has to be resolved |
| 1422 | * @throws DataModelException a violation of data model rules | 1443 | * @throws DataModelException a violation of data model rules |
| 1423 | */ | 1444 | */ |
| 1424 | - public void setAbsolutePathFromRelativePathInLeafref(T resolutionInfo) throws DataModelException { | 1445 | + public void setAbsolutePathFromRelativePathInLeafref(T resolutionInfo) throws DataModelException { |
| 1425 | if (resolutionInfo instanceof YangLeafRef) { | 1446 | if (resolutionInfo instanceof YangLeafRef) { |
| 1426 | 1447 | ||
| 1427 | YangNode parentOfLeafref = ((YangLeafRef) resolutionInfo).getParentNodeOfLeafref(); | 1448 | YangNode parentOfLeafref = ((YangLeafRef) resolutionInfo).getParentNodeOfLeafref(); | ... | ... |
| ... | @@ -24,6 +24,7 @@ import org.onosproject.yangutils.datamodel.utils.Parsable; | ... | @@ -24,6 +24,7 @@ import org.onosproject.yangutils.datamodel.utils.Parsable; |
| 24 | import org.onosproject.yangutils.datamodel.utils.YangConstructType; | 24 | import org.onosproject.yangutils.datamodel.utils.YangConstructType; |
| 25 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangListener; | 25 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangListener; |
| 26 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | 26 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; |
| 27 | +import org.onosproject.yangutils.parser.impl.listeners.ArgumentListener; | ||
| 27 | import org.onosproject.yangutils.parser.impl.listeners.AugmentListener; | 28 | import org.onosproject.yangutils.parser.impl.listeners.AugmentListener; |
| 28 | import org.onosproject.yangutils.parser.impl.listeners.BaseFileListener; | 29 | import org.onosproject.yangutils.parser.impl.listeners.BaseFileListener; |
| 29 | import org.onosproject.yangutils.parser.impl.listeners.BaseListener; | 30 | import org.onosproject.yangutils.parser.impl.listeners.BaseListener; |
| ... | @@ -42,6 +43,7 @@ import org.onosproject.yangutils.parser.impl.listeners.EnumListener; | ... | @@ -42,6 +43,7 @@ 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.ErrorAppTagListener; | 44 | import org.onosproject.yangutils.parser.impl.listeners.ErrorAppTagListener; |
| 44 | import org.onosproject.yangutils.parser.impl.listeners.ErrorMessageListener; | 45 | import org.onosproject.yangutils.parser.impl.listeners.ErrorMessageListener; |
| 46 | +import org.onosproject.yangutils.parser.impl.listeners.ExtensionListener; | ||
| 45 | import org.onosproject.yangutils.parser.impl.listeners.FeatureListener; | 47 | import org.onosproject.yangutils.parser.impl.listeners.FeatureListener; |
| 46 | import org.onosproject.yangutils.parser.impl.listeners.FractionDigitsListener; | 48 | import org.onosproject.yangutils.parser.impl.listeners.FractionDigitsListener; |
| 47 | import org.onosproject.yangutils.parser.impl.listeners.GroupingListener; | 49 | import org.onosproject.yangutils.parser.impl.listeners.GroupingListener; |
| ... | @@ -436,12 +438,12 @@ public class TreeWalkListener implements GeneratedYangListener { | ... | @@ -436,12 +438,12 @@ public class TreeWalkListener implements GeneratedYangListener { |
| 436 | 438 | ||
| 437 | @Override | 439 | @Override |
| 438 | public void enterExtensionStatement(GeneratedYangParser.ExtensionStatementContext ctx) { | 440 | public void enterExtensionStatement(GeneratedYangParser.ExtensionStatementContext ctx) { |
| 439 | - handleUnsupportedYangConstruct(YangConstructType.EXTENSION_DATA, ctx, UNSUPPORTED_YANG_CONSTRUCT); | 441 | + ExtensionListener.processExtensionEntry(this, ctx); |
| 440 | } | 442 | } |
| 441 | 443 | ||
| 442 | @Override | 444 | @Override |
| 443 | public void exitExtensionStatement(GeneratedYangParser.ExtensionStatementContext ctx) { | 445 | public void exitExtensionStatement(GeneratedYangParser.ExtensionStatementContext ctx) { |
| 444 | - // do nothing | 446 | + ExtensionListener.processExtensionExit(this, ctx); |
| 445 | } | 447 | } |
| 446 | 448 | ||
| 447 | @Override | 449 | @Override |
| ... | @@ -456,7 +458,7 @@ public class TreeWalkListener implements GeneratedYangListener { | ... | @@ -456,7 +458,7 @@ public class TreeWalkListener implements GeneratedYangListener { |
| 456 | 458 | ||
| 457 | @Override | 459 | @Override |
| 458 | public void enterArgumentStatement(GeneratedYangParser.ArgumentStatementContext ctx) { | 460 | public void enterArgumentStatement(GeneratedYangParser.ArgumentStatementContext ctx) { |
| 459 | - // do nothing. | 461 | + ArgumentListener.processArgumentEntry(this, ctx); |
| 460 | } | 462 | } |
| 461 | 463 | ||
| 462 | @Override | 464 | @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 | + | ||
| 17 | +package org.onosproject.yangutils.parser.impl.listeners; | ||
| 18 | + | ||
| 19 | +import org.onosproject.yangutils.datamodel.YangExtension; | ||
| 20 | +import org.onosproject.yangutils.datamodel.utils.Parsable; | ||
| 21 | +import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | ||
| 22 | +import org.onosproject.yangutils.parser.exceptions.ParserException; | ||
| 23 | +import org.onosproject.yangutils.parser.impl.TreeWalkListener; | ||
| 24 | + | ||
| 25 | +import static org.onosproject.yangutils.datamodel.utils.YangConstructType.ARGUMENT_DATA; | ||
| 26 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; | ||
| 27 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; | ||
| 28 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; | ||
| 29 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; | ||
| 30 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; | ||
| 31 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; | ||
| 32 | + | ||
| 33 | +/* | ||
| 34 | + * Reference: RFC6020 and YANG ANTLR Grammar | ||
| 35 | + * | ||
| 36 | + * ABNF grammar as per RFC6020 | ||
| 37 | + * argument-stmt = argument-keyword sep identifier-arg-str optsep | ||
| 38 | + * (";" / | ||
| 39 | + * "{" stmtsep | ||
| 40 | + * [yin-element-stmt stmtsep] | ||
| 41 | + * "}") | ||
| 42 | + * * | ||
| 43 | + * ANTLR grammar rule | ||
| 44 | + * argumentStatement : ARGUMENT_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE argumentBody RIGHT_CURLY_BRACE); | ||
| 45 | + * argumentBody : yinElementStatement?; | ||
| 46 | + */ | ||
| 47 | + | ||
| 48 | +/** | ||
| 49 | + * Represents listener based call back function corresponding to the "argument" | ||
| 50 | + * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020. | ||
| 51 | + */ | ||
| 52 | +public final class ArgumentListener { | ||
| 53 | + | ||
| 54 | + /** | ||
| 55 | + * Creates a new argument listener. | ||
| 56 | + */ | ||
| 57 | + private ArgumentListener() { | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + /** | ||
| 61 | + * It is called when parser receives an input matching the grammar rule | ||
| 62 | + * (argument), performs validation and updates the data model tree. | ||
| 63 | + * | ||
| 64 | + * @param listener listener's object | ||
| 65 | + * @param ctx context object of the grammar rule | ||
| 66 | + */ | ||
| 67 | + public static void processArgumentEntry(TreeWalkListener listener, | ||
| 68 | + GeneratedYangParser.ArgumentStatementContext ctx) { | ||
| 69 | + | ||
| 70 | + // Check for stack to be non empty. | ||
| 71 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, ARGUMENT_DATA, ctx.identifier().getText(), ENTRY); | ||
| 72 | + | ||
| 73 | + String identifier = getValidIdentifier(ctx.identifier().getText(), ARGUMENT_DATA, ctx); | ||
| 74 | + | ||
| 75 | + Parsable curData = listener.getParsedDataStack().peek(); | ||
| 76 | + if (curData instanceof YangExtension) { | ||
| 77 | + YangExtension extension = ((YangExtension) curData); | ||
| 78 | + extension.setArgumentName(identifier); | ||
| 79 | + } else { | ||
| 80 | + throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, ARGUMENT_DATA, | ||
| 81 | + ctx.identifier().getText(), ENTRY)); | ||
| 82 | + } | ||
| 83 | + } | ||
| 84 | +} |
| ... | @@ -52,8 +52,8 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp | ... | @@ -52,8 +52,8 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp |
| 52 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidAbsoluteSchemaNodeId; | 52 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidAbsoluteSchemaNodeId; |
| 53 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat; | 53 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat; |
| 54 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; | 54 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; |
| 55 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityEitherOne; | ||
| 55 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne; | 56 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne; |
| 56 | -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateMutuallyExclusiveChilds; | ||
| 57 | import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangAugmentNode; | 57 | import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangAugmentNode; |
| 58 | 58 | ||
| 59 | /* | 59 | /* |
| ... | @@ -176,8 +176,8 @@ public final class AugmentListener { | ... | @@ -176,8 +176,8 @@ public final class AugmentListener { |
| 176 | validateCardinalityMaxOne(ctx.descriptionStatement(), DESCRIPTION_DATA, AUGMENT_DATA, ctx.augment().getText()); | 176 | validateCardinalityMaxOne(ctx.descriptionStatement(), DESCRIPTION_DATA, AUGMENT_DATA, ctx.augment().getText()); |
| 177 | validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, AUGMENT_DATA, ctx.augment().getText()); | 177 | validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, AUGMENT_DATA, ctx.augment().getText()); |
| 178 | validateCardinalityMaxOne(ctx.whenStatement(), WHEN_DATA, AUGMENT_DATA, ctx.augment().getText()); | 178 | validateCardinalityMaxOne(ctx.whenStatement(), WHEN_DATA, AUGMENT_DATA, ctx.augment().getText()); |
| 179 | - validateMutuallyExclusiveChilds(ctx.dataDefStatement(), DATA_DEF_DATA, ctx.caseStatement(), | 179 | + validateCardinalityEitherOne(ctx.dataDefStatement(), DATA_DEF_DATA, ctx.caseStatement(), |
| 180 | - CASE_DATA, AUGMENT_DATA, ctx.augment().getText()); | 180 | + CASE_DATA, AUGMENT_DATA, ctx.augment().getText(), ctx); |
| 181 | } | 181 | } |
| 182 | 182 | ||
| 183 | /** | 183 | /** | ... | ... |
| ... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
| 16 | 16 | ||
| 17 | package org.onosproject.yangutils.parser.impl.listeners; | 17 | package org.onosproject.yangutils.parser.impl.listeners; |
| 18 | 18 | ||
| 19 | +import org.onosproject.yangutils.datamodel.YangAugment; | ||
| 19 | import org.onosproject.yangutils.datamodel.YangCase; | 20 | import org.onosproject.yangutils.datamodel.YangCase; |
| 20 | import org.onosproject.yangutils.datamodel.YangChoice; | 21 | import org.onosproject.yangutils.datamodel.YangChoice; |
| 21 | import org.onosproject.yangutils.datamodel.YangNode; | 22 | import org.onosproject.yangutils.datamodel.YangNode; |
| ... | @@ -104,7 +105,7 @@ public final class CaseListener { | ... | @@ -104,7 +105,7 @@ public final class CaseListener { |
| 104 | int charPositionInLine = ctx.getStart().getCharPositionInLine(); | 105 | int charPositionInLine = ctx.getStart().getCharPositionInLine(); |
| 105 | detectCollidingChildUtil(listener, line, charPositionInLine, identifier, CASE_DATA); | 106 | detectCollidingChildUtil(listener, line, charPositionInLine, identifier, CASE_DATA); |
| 106 | 107 | ||
| 107 | - if (curData instanceof YangChoice) { | 108 | + if (curData instanceof YangChoice || curData instanceof YangAugment) { |
| 108 | YangCase caseNode = getYangCaseNode(JAVA_GENERATION); | 109 | YangCase caseNode = getYangCaseNode(JAVA_GENERATION); |
| 109 | caseNode.setName(identifier); | 110 | caseNode.setName(identifier); |
| 110 | YangNode curNode = (YangNode) curData; | 111 | YangNode curNode = (YangNode) curData; | ... | ... |
| ... | @@ -35,14 +35,12 @@ import org.onosproject.yangutils.parser.exceptions.ParserException; | ... | @@ -35,14 +35,12 @@ import org.onosproject.yangutils.parser.exceptions.ParserException; |
| 35 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; | 35 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; |
| 36 | 36 | ||
| 37 | import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION; | 37 | import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION; |
| 38 | -import static org.onosproject.yangutils.datamodel.utils.YangConstructType.CASE_DATA; | ||
| 39 | import static org.onosproject.yangutils.datamodel.utils.YangConstructType.CHOICE_DATA; | 38 | import static org.onosproject.yangutils.datamodel.utils.YangConstructType.CHOICE_DATA; |
| 40 | import static org.onosproject.yangutils.datamodel.utils.YangConstructType.CONFIG_DATA; | 39 | import static org.onosproject.yangutils.datamodel.utils.YangConstructType.CONFIG_DATA; |
| 41 | import static org.onosproject.yangutils.datamodel.utils.YangConstructType.DEFAULT_DATA; | 40 | import static org.onosproject.yangutils.datamodel.utils.YangConstructType.DEFAULT_DATA; |
| 42 | import static org.onosproject.yangutils.datamodel.utils.YangConstructType.DESCRIPTION_DATA; | 41 | import static org.onosproject.yangutils.datamodel.utils.YangConstructType.DESCRIPTION_DATA; |
| 43 | import static org.onosproject.yangutils.datamodel.utils.YangConstructType.MANDATORY_DATA; | 42 | import static org.onosproject.yangutils.datamodel.utils.YangConstructType.MANDATORY_DATA; |
| 44 | import static org.onosproject.yangutils.datamodel.utils.YangConstructType.REFERENCE_DATA; | 43 | import static org.onosproject.yangutils.datamodel.utils.YangConstructType.REFERENCE_DATA; |
| 45 | -import static org.onosproject.yangutils.datamodel.utils.YangConstructType.SHORT_CASE_DATA; | ||
| 46 | import static org.onosproject.yangutils.datamodel.utils.YangConstructType.STATUS_DATA; | 44 | import static org.onosproject.yangutils.datamodel.utils.YangConstructType.STATUS_DATA; |
| 47 | import static org.onosproject.yangutils.datamodel.utils.YangConstructType.WHEN_DATA; | 45 | import static org.onosproject.yangutils.datamodel.utils.YangConstructType.WHEN_DATA; |
| 48 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil; | 46 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil; |
| ... | @@ -57,7 +55,6 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp | ... | @@ -57,7 +55,6 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp |
| 57 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; | 55 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; |
| 58 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; | 56 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; |
| 59 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne; | 57 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne; |
| 60 | -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateMutuallyExclusiveChilds; | ||
| 61 | import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangChoiceNode; | 58 | import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangChoiceNode; |
| 62 | 59 | ||
| 63 | /* | 60 | /* |
| ... | @@ -181,7 +178,5 @@ public final class ChoiceListener { | ... | @@ -181,7 +178,5 @@ public final class ChoiceListener { |
| 181 | validateCardinalityMaxOne(ctx.descriptionStatement(), DESCRIPTION_DATA, CHOICE_DATA, | 178 | validateCardinalityMaxOne(ctx.descriptionStatement(), DESCRIPTION_DATA, CHOICE_DATA, |
| 182 | ctx.identifier().getText()); | 179 | ctx.identifier().getText()); |
| 183 | validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, CHOICE_DATA, ctx.identifier().getText()); | 180 | validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, CHOICE_DATA, ctx.identifier().getText()); |
| 184 | - validateMutuallyExclusiveChilds(ctx.shortCaseStatement(), SHORT_CASE_DATA, ctx.caseStatement(), CASE_DATA, | ||
| 185 | - CHOICE_DATA, ctx.identifier().getText()); | ||
| 186 | } | 181 | } |
| 187 | } | 182 | } | ... | ... |
| ... | @@ -171,8 +171,11 @@ public final class ContainerListener { | ... | @@ -171,8 +171,11 @@ public final class ContainerListener { |
| 171 | try { | 171 | try { |
| 172 | yangContainer.validateDataOnExit(); | 172 | yangContainer.validateDataOnExit(); |
| 173 | } catch (DataModelException e) { | 173 | } catch (DataModelException e) { |
| 174 | - throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA, | 174 | + ParserException parserException = new ParserException(constructExtendedListenerErrorMessage( |
| 175 | - CONTAINER_DATA, ctx.identifier().getText(), EXIT, e.getMessage())); | 175 | + UNHANDLED_PARSED_DATA, CONTAINER_DATA, ctx.identifier().getText(), EXIT, e.getMessage())); |
| 176 | + parserException.setLine(ctx.getStart().getLine()); | ||
| 177 | + parserException.setCharPosition(ctx.getStart().getCharPositionInLine()); | ||
| 178 | + throw parserException; | ||
| 176 | } | 179 | } |
| 177 | listener.getParsedDataStack().pop(); | 180 | listener.getParsedDataStack().pop(); |
| 178 | } else { | 181 | } 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 | + | ||
| 17 | +package org.onosproject.yangutils.parser.impl.listeners; | ||
| 18 | + | ||
| 19 | +import org.onosproject.yangutils.datamodel.YangExtension; | ||
| 20 | +import org.onosproject.yangutils.datamodel.YangModule; | ||
| 21 | +import org.onosproject.yangutils.datamodel.YangSubModule; | ||
| 22 | +import org.onosproject.yangutils.datamodel.utils.Parsable; | ||
| 23 | +import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | ||
| 24 | +import org.onosproject.yangutils.parser.exceptions.ParserException; | ||
| 25 | +import org.onosproject.yangutils.parser.impl.TreeWalkListener; | ||
| 26 | + | ||
| 27 | +import static org.onosproject.yangutils.datamodel.utils.YangConstructType.EXTENSION_DATA; | ||
| 28 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; | ||
| 29 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; | ||
| 30 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; | ||
| 31 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; | ||
| 32 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER; | ||
| 33 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; | ||
| 34 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; | ||
| 35 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; | ||
| 36 | + | ||
| 37 | +/* | ||
| 38 | + * Reference: RFC6020 and YANG ANTLR Grammar | ||
| 39 | + * | ||
| 40 | + * ABNF grammar as per RFC6020 | ||
| 41 | + * extension-stmt = extension-keyword sep identifier-arg-str optsep | ||
| 42 | + * (";" / | ||
| 43 | + * "{" stmtsep | ||
| 44 | + * ;; these stmts can appear in any order | ||
| 45 | + * [argument-stmt stmtsep] | ||
| 46 | + * [status-stmt stmtsep] | ||
| 47 | + * [description-stmt stmtsep] | ||
| 48 | + * [reference-stmt stmtsep] | ||
| 49 | + * "}") | ||
| 50 | + * | ||
| 51 | + * ANTLR grammar rule | ||
| 52 | + * extensionStatement : EXTENSION_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE extensionBody RIGHT_CURLY_BRACE); | ||
| 53 | + */ | ||
| 54 | + | ||
| 55 | +/** | ||
| 56 | + * Represents listener based call back function corresponding to the "extension" | ||
| 57 | + * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020. | ||
| 58 | + */ | ||
| 59 | +public final class ExtensionListener { | ||
| 60 | + | ||
| 61 | + /** | ||
| 62 | + * Creates a new extension listener. | ||
| 63 | + */ | ||
| 64 | + private ExtensionListener() { | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + /** | ||
| 68 | + * Performs validation and updates the data model tree. It is called when parser | ||
| 69 | + * receives an input matching the grammar rule (extension). | ||
| 70 | + * | ||
| 71 | + * @param listener listener's object | ||
| 72 | + * @param ctx context object of the grammar rule | ||
| 73 | + */ | ||
| 74 | + public static void processExtensionEntry(TreeWalkListener listener, | ||
| 75 | + GeneratedYangParser.ExtensionStatementContext ctx) { | ||
| 76 | + | ||
| 77 | + // Check for stack to be non empty. | ||
| 78 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, EXTENSION_DATA, ctx.identifier().getText(), ENTRY); | ||
| 79 | + | ||
| 80 | + String identifier = getValidIdentifier(ctx.identifier().getText(), EXTENSION_DATA, ctx); | ||
| 81 | + | ||
| 82 | + YangExtension extension = new YangExtension(); | ||
| 83 | + extension.setName(identifier); | ||
| 84 | + | ||
| 85 | + Parsable curData = listener.getParsedDataStack().peek(); | ||
| 86 | + switch (curData.getYangConstructType()) { | ||
| 87 | + case MODULE_DATA: | ||
| 88 | + YangModule module = ((YangModule) curData); | ||
| 89 | + module.addExtension(extension); | ||
| 90 | + break; | ||
| 91 | + case SUB_MODULE_DATA: | ||
| 92 | + YangSubModule subModule = ((YangSubModule) curData); | ||
| 93 | + subModule.addExtension(extension); | ||
| 94 | + break; | ||
| 95 | + default: | ||
| 96 | + throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, EXTENSION_DATA, | ||
| 97 | + ctx.identifier().getText(), ENTRY)); | ||
| 98 | + } | ||
| 99 | + listener.getParsedDataStack().push(extension); | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + /** | ||
| 103 | + * Performs validation and updates the data model tree. It is called when parser exits | ||
| 104 | + * from grammar rule(extension). | ||
| 105 | + * | ||
| 106 | + * @param listener listener's object | ||
| 107 | + * @param ctx context object of the grammar rule | ||
| 108 | + */ | ||
| 109 | + public static void processExtensionExit(TreeWalkListener listener, | ||
| 110 | + GeneratedYangParser.ExtensionStatementContext ctx) { | ||
| 111 | + | ||
| 112 | + // Check for stack to be non empty. | ||
| 113 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, EXTENSION_DATA, ctx.identifier().getText(), EXIT); | ||
| 114 | + | ||
| 115 | + if (!(listener.getParsedDataStack().peek() instanceof YangExtension)) { | ||
| 116 | + throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, EXTENSION_DATA, | ||
| 117 | + ctx.identifier().getText(), EXIT)); | ||
| 118 | + } | ||
| 119 | + listener.getParsedDataStack().pop(); | ||
| 120 | + } | ||
| 121 | +} |
| ... | @@ -37,7 +37,6 @@ import static org.onosproject.yangutils.datamodel.utils.YangConstructType.DESCRI | ... | @@ -37,7 +37,6 @@ import static org.onosproject.yangutils.datamodel.utils.YangConstructType.DESCRI |
| 37 | import static org.onosproject.yangutils.datamodel.utils.YangConstructType.GROUPING_DATA; | 37 | import static org.onosproject.yangutils.datamodel.utils.YangConstructType.GROUPING_DATA; |
| 38 | import static org.onosproject.yangutils.datamodel.utils.YangConstructType.REFERENCE_DATA; | 38 | import static org.onosproject.yangutils.datamodel.utils.YangConstructType.REFERENCE_DATA; |
| 39 | import static org.onosproject.yangutils.datamodel.utils.YangConstructType.STATUS_DATA; | 39 | import static org.onosproject.yangutils.datamodel.utils.YangConstructType.STATUS_DATA; |
| 40 | -import static org.onosproject.yangutils.datamodel.utils.YangConstructType.TYPEDEF_DATA; | ||
| 41 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil; | 40 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil; |
| 42 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; | 41 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; |
| 43 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; | 42 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; |
| ... | @@ -50,7 +49,6 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp | ... | @@ -50,7 +49,6 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp |
| 50 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; | 49 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; |
| 51 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; | 50 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; |
| 52 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne; | 51 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne; |
| 53 | -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateMutuallyExclusiveChilds; | ||
| 54 | import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangGroupingNode; | 52 | import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangGroupingNode; |
| 55 | 53 | ||
| 56 | /* | 54 | /* |
| ... | @@ -172,7 +170,5 @@ public final class GroupingListener { | ... | @@ -172,7 +170,5 @@ public final class GroupingListener { |
| 172 | validateCardinalityMaxOne(ctx.descriptionStatement(), DESCRIPTION_DATA, GROUPING_DATA, | 170 | validateCardinalityMaxOne(ctx.descriptionStatement(), DESCRIPTION_DATA, GROUPING_DATA, |
| 173 | ctx.identifier().getText()); | 171 | ctx.identifier().getText()); |
| 174 | validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, GROUPING_DATA, ctx.identifier().getText()); | 172 | validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, GROUPING_DATA, ctx.identifier().getText()); |
| 175 | - validateMutuallyExclusiveChilds(ctx.typedefStatement(), TYPEDEF_DATA, ctx.groupingStatement(), GROUPING_DATA, | ||
| 176 | - GROUPING_DATA, ctx.identifier().getText()); | ||
| 177 | } | 173 | } |
| 178 | } | 174 | } | ... | ... |
| ... | @@ -28,11 +28,9 @@ import org.onosproject.yangutils.parser.impl.TreeWalkListener; | ... | @@ -28,11 +28,9 @@ import org.onosproject.yangutils.parser.impl.TreeWalkListener; |
| 28 | 28 | ||
| 29 | import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION; | 29 | import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION; |
| 30 | import static org.onosproject.yangutils.datamodel.utils.YangConstructType.DESCRIPTION_DATA; | 30 | import static org.onosproject.yangutils.datamodel.utils.YangConstructType.DESCRIPTION_DATA; |
| 31 | -import static org.onosproject.yangutils.datamodel.utils.YangConstructType.GROUPING_DATA; | ||
| 32 | import static org.onosproject.yangutils.datamodel.utils.YangConstructType.NOTIFICATION_DATA; | 31 | import static org.onosproject.yangutils.datamodel.utils.YangConstructType.NOTIFICATION_DATA; |
| 33 | import static org.onosproject.yangutils.datamodel.utils.YangConstructType.REFERENCE_DATA; | 32 | import static org.onosproject.yangutils.datamodel.utils.YangConstructType.REFERENCE_DATA; |
| 34 | import static org.onosproject.yangutils.datamodel.utils.YangConstructType.STATUS_DATA; | 33 | import static org.onosproject.yangutils.datamodel.utils.YangConstructType.STATUS_DATA; |
| 35 | -import static org.onosproject.yangutils.datamodel.utils.YangConstructType.TYPEDEF_DATA; | ||
| 36 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil; | 34 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil; |
| 37 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; | 35 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; |
| 38 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; | 36 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; |
| ... | @@ -45,7 +43,6 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp | ... | @@ -45,7 +43,6 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp |
| 45 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; | 43 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; |
| 46 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; | 44 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; |
| 47 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne; | 45 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne; |
| 48 | -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateMutuallyExclusiveChilds; | ||
| 49 | import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangNotificationNode; | 46 | import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangNotificationNode; |
| 50 | 47 | ||
| 51 | /* | 48 | /* |
| ... | @@ -159,7 +156,5 @@ public final class NotificationListener { | ... | @@ -159,7 +156,5 @@ public final class NotificationListener { |
| 159 | ctx.identifier().getText()); | 156 | ctx.identifier().getText()); |
| 160 | validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, NOTIFICATION_DATA, | 157 | validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, NOTIFICATION_DATA, |
| 161 | ctx.identifier().getText()); | 158 | ctx.identifier().getText()); |
| 162 | - validateMutuallyExclusiveChilds(ctx.typedefStatement(), TYPEDEF_DATA, ctx.groupingStatement(), GROUPING_DATA, | ||
| 163 | - NOTIFICATION_DATA, ctx.identifier().getText()); | ||
| 164 | } | 159 | } |
| 165 | } | 160 | } | ... | ... |
| ... | @@ -16,9 +16,9 @@ | ... | @@ -16,9 +16,9 @@ |
| 16 | 16 | ||
| 17 | package org.onosproject.yangutils.parser.impl.listeners; | 17 | package org.onosproject.yangutils.parser.impl.listeners; |
| 18 | 18 | ||
| 19 | +import org.onosproject.yangutils.datamodel.YangModule; | ||
| 19 | import org.onosproject.yangutils.datamodel.YangNode; | 20 | import org.onosproject.yangutils.datamodel.YangNode; |
| 20 | import org.onosproject.yangutils.datamodel.YangRpc; | 21 | import org.onosproject.yangutils.datamodel.YangRpc; |
| 21 | -import org.onosproject.yangutils.datamodel.YangModule; | ||
| 22 | import org.onosproject.yangutils.datamodel.YangSubModule; | 22 | import org.onosproject.yangutils.datamodel.YangSubModule; |
| 23 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | 23 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
| 24 | import org.onosproject.yangutils.datamodel.utils.Parsable; | 24 | import org.onosproject.yangutils.datamodel.utils.Parsable; |
| ... | @@ -28,23 +28,23 @@ import org.onosproject.yangutils.parser.impl.TreeWalkListener; | ... | @@ -28,23 +28,23 @@ import org.onosproject.yangutils.parser.impl.TreeWalkListener; |
| 28 | 28 | ||
| 29 | import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION; | 29 | import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION; |
| 30 | import static org.onosproject.yangutils.datamodel.utils.YangConstructType.DESCRIPTION_DATA; | 30 | import static org.onosproject.yangutils.datamodel.utils.YangConstructType.DESCRIPTION_DATA; |
| 31 | -import static org.onosproject.yangutils.datamodel.utils.YangConstructType.GROUPING_DATA; | ||
| 32 | import static org.onosproject.yangutils.datamodel.utils.YangConstructType.INPUT_DATA; | 31 | import static org.onosproject.yangutils.datamodel.utils.YangConstructType.INPUT_DATA; |
| 33 | import static org.onosproject.yangutils.datamodel.utils.YangConstructType.OUTPUT_DATA; | 32 | import static org.onosproject.yangutils.datamodel.utils.YangConstructType.OUTPUT_DATA; |
| 34 | import static org.onosproject.yangutils.datamodel.utils.YangConstructType.REFERENCE_DATA; | 33 | import static org.onosproject.yangutils.datamodel.utils.YangConstructType.REFERENCE_DATA; |
| 35 | import static org.onosproject.yangutils.datamodel.utils.YangConstructType.RPC_DATA; | 34 | import static org.onosproject.yangutils.datamodel.utils.YangConstructType.RPC_DATA; |
| 36 | import static org.onosproject.yangutils.datamodel.utils.YangConstructType.STATUS_DATA; | 35 | import static org.onosproject.yangutils.datamodel.utils.YangConstructType.STATUS_DATA; |
| 37 | -import static org.onosproject.yangutils.datamodel.utils.YangConstructType.TYPEDEF_DATA; | ||
| 38 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil; | 36 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil; |
| 39 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; | 37 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; |
| 40 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; | 38 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; |
| 41 | -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; | ||
| 42 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage; | 39 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage; |
| 43 | -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.*; | 40 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; |
| 41 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; | ||
| 42 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER; | ||
| 43 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; | ||
| 44 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA; | ||
| 44 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; | 45 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; |
| 45 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; | 46 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; |
| 46 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne; | 47 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne; |
| 47 | -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateMutuallyExclusiveChilds; | ||
| 48 | import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangRpcNode; | 48 | import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangRpcNode; |
| 49 | 49 | ||
| 50 | /* | 50 | /* |
| ... | @@ -157,8 +157,6 @@ public final class RpcListener { | ... | @@ -157,8 +157,6 @@ public final class RpcListener { |
| 157 | validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, RPC_DATA, ctx.identifier().getText()); | 157 | validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, RPC_DATA, ctx.identifier().getText()); |
| 158 | validateCardinalityMaxOne(ctx.inputStatement(), INPUT_DATA, RPC_DATA, ctx.identifier().getText()); | 158 | validateCardinalityMaxOne(ctx.inputStatement(), INPUT_DATA, RPC_DATA, ctx.identifier().getText()); |
| 159 | validateCardinalityMaxOne(ctx.outputStatement(), OUTPUT_DATA, RPC_DATA, ctx.identifier().getText()); | 159 | validateCardinalityMaxOne(ctx.outputStatement(), OUTPUT_DATA, RPC_DATA, ctx.identifier().getText()); |
| 160 | - validateMutuallyExclusiveChilds(ctx.typedefStatement(), TYPEDEF_DATA, ctx.groupingStatement(), GROUPING_DATA, | ||
| 161 | - RPC_DATA, ctx.identifier().getText()); | ||
| 162 | } | 160 | } |
| 163 | 161 | ||
| 164 | } | 162 | } | ... | ... |
| ... | @@ -208,29 +208,30 @@ public final class ListenerValidation { | ... | @@ -208,29 +208,30 @@ public final class ListenerValidation { |
| 208 | /** | 208 | /** |
| 209 | * Checks if a either of one construct occurrence. | 209 | * Checks if a either of one construct occurrence. |
| 210 | * | 210 | * |
| 211 | - * @param child1Context first optional child's context | 211 | + * @param child1Context first optional child's context |
| 212 | * @param yangChild1Construct first child construct for whom cardinality is | 212 | * @param yangChild1Construct first child construct for whom cardinality is |
| 213 | * to be validated | 213 | * to be validated |
| 214 | - * @param child2Context second optional child's context | 214 | + * @param child2Context second optional child's context |
| 215 | * @param yangChild2Construct second child construct for whom cardinality is | 215 | * @param yangChild2Construct second child construct for whom cardinality is |
| 216 | * to be validated | 216 | * to be validated |
| 217 | * @param yangParentConstruct parent construct | 217 | * @param yangParentConstruct parent construct |
| 218 | - * @param parentName parent name | 218 | + * @param parentName parent name |
| 219 | + * @param parentContext parents's context | ||
| 219 | * @throws ParserException exception if cardinality check fails | 220 | * @throws ParserException exception if cardinality check fails |
| 220 | */ | 221 | */ |
| 221 | - public static void validateMutuallyExclusiveChilds(List<?> child1Context, YangConstructType yangChild1Construct, | 222 | + public static void validateCardinalityEitherOne(List<?> child1Context, YangConstructType yangChild1Construct, |
| 222 | - List<?> child2Context, YangConstructType yangChild2Construct, | 223 | + List<?> child2Context, YangConstructType yangChild2Construct, |
| 223 | - YangConstructType yangParentConstruct, String parentName) | 224 | + YangConstructType yangParentConstruct, String parentName, |
| 225 | + ParserRuleContext parentContext) | ||
| 224 | throws ParserException { | 226 | throws ParserException { |
| 225 | 227 | ||
| 226 | - if (!child1Context.isEmpty() && !child2Context.isEmpty()) { | 228 | + if (child1Context.isEmpty() && child2Context.isEmpty()) { |
| 227 | - ParserException parserException = new ParserException("YANG file error: \"" | 229 | + ParserException parserException = new ParserException("YANG file error: Either \"" |
| 228 | - + getYangConstructType(yangChild1Construct) + "\" & \"" + getYangConstructType(yangChild2Construct) | 230 | + + getYangConstructType(yangChild1Construct) + "\" or \"" + getYangConstructType(yangChild2Construct) |
| 229 | - + "\" should be mutually exclusive in \"" + getYangConstructType(yangParentConstruct) + " " | 231 | + + "\" should be present in \"" + getYangConstructType(yangParentConstruct) + " " |
| 230 | + parentName + "\"."); | 232 | + parentName + "\"."); |
| 231 | - | 233 | + parserException.setLine(parentContext.getStart().getLine()); |
| 232 | - parserException.setLine(((ParserRuleContext) child2Context).getStart().getLine()); | 234 | + parserException.setCharPosition(parentContext.getStart().getCharPositionInLine()); |
| 233 | - parserException.setCharPosition(((ParserRuleContext) child2Context).getStart().getCharPositionInLine()); | ||
| 234 | throw parserException; | 235 | throw parserException; |
| 235 | } | 236 | } |
| 236 | } | 237 | } | ... | ... |
| ... | @@ -103,6 +103,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.REFERENCE_CARDINALIT | ... | @@ -103,6 +103,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.REFERENCE_CARDINALIT |
| 103 | import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; | 103 | import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; |
| 104 | import static org.onosproject.yangutils.utils.UtilConstants.SERVICE; | 104 | import static org.onosproject.yangutils.utils.UtilConstants.SERVICE; |
| 105 | import static org.onosproject.yangutils.utils.UtilConstants.SLASH; | 105 | import static org.onosproject.yangutils.utils.UtilConstants.SLASH; |
| 106 | +import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO; | ||
| 106 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile; | 107 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile; |
| 107 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.readAppendFile; | 108 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.readAppendFile; |
| 108 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD; | 109 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD; |
| ... | @@ -1688,6 +1689,12 @@ public class TempJavaFragmentFiles { | ... | @@ -1688,6 +1689,12 @@ public class TempJavaFragmentFiles { |
| 1688 | */ | 1689 | */ |
| 1689 | private void removeAugmentedInfoImport(List<String> imports) { | 1690 | private void removeAugmentedInfoImport(List<String> imports) { |
| 1690 | imports.remove(getJavaImportData().getYangAugmentedInfoImport()); | 1691 | imports.remove(getJavaImportData().getYangAugmentedInfoImport()); |
| 1692 | + for (JavaQualifiedTypeInfo type : getJavaImportData().getImportSet()) { | ||
| 1693 | + if (type.getClassInfo().equals(YANG_AUGMENTED_INFO)) { | ||
| 1694 | + getJavaImportData().getImportSet().remove(type); | ||
| 1695 | + getJavaExtendsListHolder().getExtendsList().remove(type); | ||
| 1696 | + } | ||
| 1697 | + } | ||
| 1691 | } | 1698 | } |
| 1692 | 1699 | ||
| 1693 | /** | 1700 | /** | ... | ... |
| ... | @@ -16,9 +16,10 @@ | ... | @@ -16,9 +16,10 @@ |
| 16 | 16 | ||
| 17 | package org.onosproject.yangutils.parser.impl.listeners; | 17 | package org.onosproject.yangutils.parser.impl.listeners; |
| 18 | 18 | ||
| 19 | -import static org.hamcrest.MatcherAssert.assertThat; | 19 | +import java.io.IOException; |
| 20 | -import static org.hamcrest.core.Is.is; | 20 | +import java.util.ListIterator; |
| 21 | import org.junit.Test; | 21 | import org.junit.Test; |
| 22 | +import org.onosproject.yangutils.datamodel.YangAugment; | ||
| 22 | import org.onosproject.yangutils.datamodel.YangCase; | 23 | import org.onosproject.yangutils.datamodel.YangCase; |
| 23 | import org.onosproject.yangutils.datamodel.YangChoice; | 24 | import org.onosproject.yangutils.datamodel.YangChoice; |
| 24 | import org.onosproject.yangutils.datamodel.YangContainer; | 25 | import org.onosproject.yangutils.datamodel.YangContainer; |
| ... | @@ -29,8 +30,8 @@ import org.onosproject.yangutils.datamodel.YangNodeType; | ... | @@ -29,8 +30,8 @@ import org.onosproject.yangutils.datamodel.YangNodeType; |
| 29 | import org.onosproject.yangutils.parser.exceptions.ParserException; | 30 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
| 30 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; | 31 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; |
| 31 | 32 | ||
| 32 | -import java.io.IOException; | 33 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 33 | -import java.util.ListIterator; | 34 | +import static org.hamcrest.core.Is.is; |
| 34 | 35 | ||
| 35 | /** | 36 | /** |
| 36 | * Test cases for case listener. | 37 | * Test cases for case listener. |
| ... | @@ -202,4 +203,36 @@ public class CaseListenerTest { | ... | @@ -202,4 +203,36 @@ public class CaseListenerTest { |
| 202 | YangLeaf leafInfo2 = leafIterator2.next(); | 203 | YangLeaf leafInfo2 = leafIterator2.next(); |
| 203 | assertThat(leafInfo2.getName(), is("beer")); | 204 | assertThat(leafInfo2.getName(), is("beer")); |
| 204 | } | 205 | } |
| 206 | + | ||
| 207 | + /** | ||
| 208 | + * Checks case substatement of augment. | ||
| 209 | + */ | ||
| 210 | + @Test | ||
| 211 | + public void processCaseSubStatementOfAugment() throws IOException, ParserException { | ||
| 212 | + | ||
| 213 | + YangNode node = manager.getDataModel("src/test/resources/CaseSubStatementOfAugment.yang"); | ||
| 214 | + | ||
| 215 | + // Check whether the data model tree returned is of type module. | ||
| 216 | + assertThat((node instanceof YangModule), is(true)); | ||
| 217 | + | ||
| 218 | + // Check whether the node type is set properly to module. | ||
| 219 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
| 220 | + | ||
| 221 | + // Check whether the module name is set correctly. | ||
| 222 | + YangModule yangNode = (YangModule) node; | ||
| 223 | + assertThat(yangNode.getName(), is("event")); | ||
| 224 | + | ||
| 225 | + YangAugment augment = ((YangAugment) yangNode.getChild()); | ||
| 226 | + assertThat(augment.getName(), is("/snmp:snmp/snmp:engine/snmp:listen/snmp:transport")); | ||
| 227 | + | ||
| 228 | + YangCase yangCase = ((YangCase) augment.getChild()); | ||
| 229 | + assertThat(yangCase.getName(), is("tls")); | ||
| 230 | + | ||
| 231 | + YangCase yangCase1 = ((YangCase) yangCase.getNextSibling()); | ||
| 232 | + assertThat(yangCase1.getName(), is("dtls")); | ||
| 233 | + | ||
| 234 | + YangContainer container = ((YangContainer) yangCase.getChild()); | ||
| 235 | + assertThat(container.getName(), is("tls")); | ||
| 236 | + assertThat(container.getListOfLeaf().iterator().next().getName(), is("ip")); | ||
| 237 | + } | ||
| 205 | } | 238 | } | ... | ... |
| 1 | +/* | ||
| 2 | + * Copyright 2016-present Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | + | ||
| 17 | +package org.onosproject.yangutils.parser.impl.listeners; | ||
| 18 | + | ||
| 19 | +import java.io.IOException; | ||
| 20 | +import org.junit.Test; | ||
| 21 | +import org.onosproject.yangutils.datamodel.YangExtension; | ||
| 22 | +import org.onosproject.yangutils.datamodel.YangModule; | ||
| 23 | +import org.onosproject.yangutils.datamodel.YangNode; | ||
| 24 | +import org.onosproject.yangutils.datamodel.YangNodeType; | ||
| 25 | +import org.onosproject.yangutils.parser.exceptions.ParserException; | ||
| 26 | +import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; | ||
| 27 | + | ||
| 28 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
| 29 | +import static org.hamcrest.core.Is.is; | ||
| 30 | + | ||
| 31 | +/** | ||
| 32 | + * Test cases for testing extension listener. | ||
| 33 | + */ | ||
| 34 | +public class ExtensionListenerTest { | ||
| 35 | + | ||
| 36 | + private final YangUtilsParserManager manager = new YangUtilsParserManager(); | ||
| 37 | + | ||
| 38 | + /** | ||
| 39 | + * Checks extension statement as sub-statement of module. | ||
| 40 | + */ | ||
| 41 | + @Test | ||
| 42 | + public void processValidExtensionStatement() throws IOException, ParserException { | ||
| 43 | + | ||
| 44 | + YangNode node = manager.getDataModel("src/test/resources/ValidExtensionStatement.yang"); | ||
| 45 | + | ||
| 46 | + assertThat((node instanceof YangModule), is(true)); | ||
| 47 | + | ||
| 48 | + // Check whether the node type is set properly to module. | ||
| 49 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
| 50 | + | ||
| 51 | + YangModule yangNode = (YangModule) node; | ||
| 52 | + assertThat(yangNode.getName(), is("ietf-yang-compiler-annotation")); | ||
| 53 | + | ||
| 54 | + YangExtension extension = yangNode.getExtensionList().iterator().next(); | ||
| 55 | + assertThat(extension.getName(), is("compiler-annotation")); | ||
| 56 | + assertThat(extension.getArgumentName(), is("target")); | ||
| 57 | + assertThat(extension.getDescription(), is("\"This extension allows for defining compiler annotations\"")); | ||
| 58 | + } | ||
| 59 | +} | ||
| 60 | + |
| ... | @@ -16,13 +16,19 @@ | ... | @@ -16,13 +16,19 @@ |
| 16 | 16 | ||
| 17 | package org.onosproject.yangutils.plugin.manager; | 17 | package org.onosproject.yangutils.plugin.manager; |
| 18 | 18 | ||
| 19 | +import java.io.IOException; | ||
| 20 | +import java.util.Iterator; | ||
| 21 | +import java.util.ListIterator; | ||
| 19 | import org.apache.maven.plugin.MojoExecutionException; | 22 | import org.apache.maven.plugin.MojoExecutionException; |
| 20 | import org.junit.Rule; | 23 | import org.junit.Rule; |
| 21 | import org.junit.Test; | 24 | import org.junit.Test; |
| 22 | import org.junit.rules.ExpectedException; | 25 | import org.junit.rules.ExpectedException; |
| 26 | +import org.onosproject.yangutils.datamodel.YangAugment; | ||
| 27 | +import org.onosproject.yangutils.datamodel.YangContainer; | ||
| 23 | import org.onosproject.yangutils.datamodel.YangDerivedInfo; | 28 | import org.onosproject.yangutils.datamodel.YangDerivedInfo; |
| 24 | import org.onosproject.yangutils.datamodel.YangGrouping; | 29 | import org.onosproject.yangutils.datamodel.YangGrouping; |
| 25 | import org.onosproject.yangutils.datamodel.YangLeaf; | 30 | import org.onosproject.yangutils.datamodel.YangLeaf; |
| 31 | +import org.onosproject.yangutils.datamodel.YangList; | ||
| 26 | import org.onosproject.yangutils.datamodel.YangModule; | 32 | import org.onosproject.yangutils.datamodel.YangModule; |
| 27 | import org.onosproject.yangutils.datamodel.YangNode; | 33 | import org.onosproject.yangutils.datamodel.YangNode; |
| 28 | import org.onosproject.yangutils.datamodel.YangNodeType; | 34 | import org.onosproject.yangutils.datamodel.YangNodeType; |
| ... | @@ -36,10 +42,6 @@ import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; | ... | @@ -36,10 +42,6 @@ import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; |
| 36 | import org.onosproject.yangutils.utils.io.impl.YangFileScanner; | 42 | import org.onosproject.yangutils.utils.io.impl.YangFileScanner; |
| 37 | import org.onosproject.yangutils.utils.io.impl.YangPluginConfig; | 43 | import org.onosproject.yangutils.utils.io.impl.YangPluginConfig; |
| 38 | 44 | ||
| 39 | -import java.io.IOException; | ||
| 40 | -import java.util.Iterator; | ||
| 41 | -import java.util.ListIterator; | ||
| 42 | - | ||
| 43 | import static org.hamcrest.CoreMatchers.nullValue; | 45 | import static org.hamcrest.CoreMatchers.nullValue; |
| 44 | import static org.hamcrest.MatcherAssert.assertThat; | 46 | import static org.hamcrest.MatcherAssert.assertThat; |
| 45 | import static org.hamcrest.core.Is.is; | 47 | import static org.hamcrest.core.Is.is; |
| ... | @@ -779,4 +781,60 @@ public class InterFileLinkingTest { | ... | @@ -779,4 +781,60 @@ public class InterFileLinkingTest { |
| 779 | assertThat(referredNode1.getName(), is("module2")); | 781 | assertThat(referredNode1.getName(), is("module2")); |
| 780 | assertThat(referredNode1.getPriority(), is(3)); | 782 | assertThat(referredNode1.getPriority(), is(3)); |
| 781 | } | 783 | } |
| 784 | + | ||
| 785 | + /** | ||
| 786 | + * Checks contents of uses are copied as child of grouping. | ||
| 787 | + */ | ||
| 788 | + @Test | ||
| 789 | + public void usesInsideChildOfGrouping() | ||
| 790 | + throws IOException, ParserException, MojoExecutionException { | ||
| 791 | + | ||
| 792 | + String searchDir = "src/test/resources/usesInsideChildOfGrouping"; | ||
| 793 | + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); | ||
| 794 | + utilManager.parseYangFileInfoSet(); | ||
| 795 | + utilManager.resolveDependenciesUsingLinker(); | ||
| 796 | + | ||
| 797 | + YangNode selfNode = null; | ||
| 798 | + YangNode refNode1 = null; | ||
| 799 | + | ||
| 800 | + for (YangNode rootNode : utilManager.getYangNodeSet()) { | ||
| 801 | + if (rootNode.getName().equals("ietf-network")) { | ||
| 802 | + selfNode = rootNode; | ||
| 803 | + } else if (rootNode.getName().equals("ietf-te-topology")) { | ||
| 804 | + refNode1 = rootNode; | ||
| 805 | + } | ||
| 806 | + } | ||
| 807 | + | ||
| 808 | + // Check whether the data model tree returned is of type module. | ||
| 809 | + assertThat(selfNode instanceof YangModule, is(true)); | ||
| 810 | + assertThat(selfNode.getNodeType(), is(MODULE_NODE)); | ||
| 811 | + YangModule yangNode = (YangModule) selfNode; | ||
| 812 | + assertThat(yangNode.getName(), is("ietf-network")); | ||
| 813 | + | ||
| 814 | + YangModule refNode = (YangModule) refNode1; | ||
| 815 | + assertThat(refNode.getName(), is("ietf-te-topology")); | ||
| 816 | + | ||
| 817 | + YangAugment augment = ((YangAugment) refNode.getChild().getNextSibling(). | ||
| 818 | + getNextSibling().getNextSibling().getNextSibling()); | ||
| 819 | + assertThat(augment.getName(), is("/nw:networks/nw:network/nw:node")); | ||
| 820 | + | ||
| 821 | + YangUses uses = ((YangUses) augment.getChild()); | ||
| 822 | + YangContainer container = ((YangContainer) uses.getNextSibling()); | ||
| 823 | + assertThat(container.getName(), is("te")); | ||
| 824 | + | ||
| 825 | + container = ((YangContainer) container.getChild()); | ||
| 826 | + assertThat(container.getName(), is("config")); | ||
| 827 | + | ||
| 828 | + uses = ((YangUses) container.getChild().getNextSibling()); | ||
| 829 | + assertThat(uses.getName(), is("te-node-config-attributes")); | ||
| 830 | + | ||
| 831 | + YangContainer container1 = ((YangContainer) uses.getNextSibling()); | ||
| 832 | + assertThat(container1.getName(), is("te-node-attributes")); | ||
| 833 | + | ||
| 834 | + uses = ((YangUses) container1.getChild()); | ||
| 835 | + assertThat(uses.getName(), is("te-node-connectivity-matrix")); | ||
| 836 | + | ||
| 837 | + YangList list = ((YangList) uses.getNextSibling()); | ||
| 838 | + assertThat(list.getName(), is("connectivity-matrix")); | ||
| 839 | + } | ||
| 782 | } | 840 | } | ... | ... |
| 1 | +module event { | ||
| 2 | + | ||
| 3 | + namespace "http://example.com/event"; | ||
| 4 | + prefix "ev"; | ||
| 5 | + | ||
| 6 | + augment /snmp:snmp/snmp:engine/snmp:listen/snmp:transport { | ||
| 7 | + if-feature tlstm; | ||
| 8 | + case tls { | ||
| 9 | + container tls { | ||
| 10 | + description | ||
| 11 | + "A list of IPv4 and IPv6 addresses and ports to which the | ||
| 12 | + engine listens for SNMP messages over TLS."; | ||
| 13 | + leaf ip { | ||
| 14 | + type inet:ip-address; | ||
| 15 | + mandatory true; | ||
| 16 | + description | ||
| 17 | + "The IPv4 or IPv6 address on which the engine listens | ||
| 18 | + for SNMP messages over TLS."; | ||
| 19 | + } | ||
| 20 | + leaf port { | ||
| 21 | + type inet:port-number; | ||
| 22 | + description | ||
| 23 | + "The TCP port on which the engine listens for SNMP | ||
| 24 | + messages over TLS. | ||
| 25 | + If the port is not configured, an engine that | ||
| 26 | + acts as a Command Responder uses port 10161, and | ||
| 27 | + an engine that acts as a Notification Receiver | ||
| 28 | + uses port 10162."; | ||
| 29 | + } | ||
| 30 | + } | ||
| 31 | + } | ||
| 32 | + case dtls { | ||
| 33 | + container dtls1 { | ||
| 34 | + description | ||
| 35 | + "A list of IPv4 and IPv6 addresses and ports to which the | ||
| 36 | + engine listens for SNMP messages over DTLS."; | ||
| 37 | + leaf ip { | ||
| 38 | + type inet:ip-address; | ||
| 39 | + mandatory true; | ||
| 40 | + description | ||
| 41 | + "The IPv4 or IPv6 address on which the engine listens | ||
| 42 | + for SNMP messages over DTLS."; | ||
| 43 | + } | ||
| 44 | + leaf port { | ||
| 45 | + type inet:port-number; | ||
| 46 | + description | ||
| 47 | + "The UDP port on which the engine listens for SNMP | ||
| 48 | + messages over DTLS. | ||
| 49 | + If the port is not configured, an engine that | ||
| 50 | + acts as a Command Responder uses port 10161, and | ||
| 51 | + an engine that acts as a Notification Receiver | ||
| 52 | + uses port 10162."; | ||
| 53 | + } | ||
| 54 | + } | ||
| 55 | + } | ||
| 56 | + } | ||
| 57 | +} | ||
| 58 | + |
| 1 | +module ietf-yang-compiler-annotation { | ||
| 2 | + | ||
| 3 | + namespace "urn:ietf:params:xml:ns:yang:ietf-yang-compiler-annotation"; | ||
| 4 | + | ||
| 5 | + prefix "ca"; | ||
| 6 | + | ||
| 7 | + organization | ||
| 8 | + "IETF NETMOD (NETCONF Data Modeling Language) Working Group"; | ||
| 9 | + | ||
| 10 | + contact | ||
| 11 | + "WG Web: <http://tools.ietf.org/wg/netmod/> | ||
| 12 | + WG List: <mailto:netmod@ietf.org>"; | ||
| 13 | + | ||
| 14 | + description | ||
| 15 | + "This YANG module defines an extension statement that allows for | ||
| 16 | + defining compiler annotations. | ||
| 17 | + | ||
| 18 | + The key words 'MUST', 'MUST NOT', 'REQUIRED', 'SHALL', 'SHALL | ||
| 19 | + NOT', 'SHOULD', 'SHOULD NOT', 'RECOMMENDED', 'MAY', and | ||
| 20 | + 'OPTIONAL' in the module text are to be interpreted as described | ||
| 21 | + in RFC 2119 (http://tools.ietf.org/html/rfc2119)."; | ||
| 22 | + | ||
| 23 | + revision 2016-07-08 { | ||
| 24 | + description | ||
| 25 | + "Initial revision."; | ||
| 26 | + reference | ||
| 27 | + "draft-agv-netmod-yang-compiler-metadata: | ||
| 28 | + Defining and Using compiler annotations with YANG"; | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + extension compiler-annotation { | ||
| 32 | + argument target; | ||
| 33 | + description "This extension allows for defining compiler annotations"; | ||
| 34 | + } // compiler-annotation | ||
| 35 | + } //module agv-yang-compiler-annotation | ||
| 36 | + |
| 1 | +module ietf-network { | ||
| 2 | + yang-version 1; | ||
| 3 | + namespace "urn:ietf:params:xml:ns:yang:ietf-network"; | ||
| 4 | + prefix nd; | ||
| 5 | + | ||
| 6 | + revision 2015-12-08 { | ||
| 7 | + description | ||
| 8 | + "Initial revision. | ||
| 9 | + NOTE TO RFC EDITOR: Please replace the following reference | ||
| 10 | + to draft-ietf-i2rs-yang-network-topo-02 with | ||
| 11 | + RFC number when published (i.e. RFC xxxx)."; | ||
| 12 | + } | ||
| 13 | + | ||
| 14 | + container networks { | ||
| 15 | + list network { | ||
| 16 | + key "network-id"; | ||
| 17 | + leaf network-id { | ||
| 18 | + type string; | ||
| 19 | + } | ||
| 20 | + list node { | ||
| 21 | + key "node-id"; | ||
| 22 | + leaf node-id { | ||
| 23 | + type string; | ||
| 24 | + } | ||
| 25 | + } | ||
| 26 | + } | ||
| 27 | + } | ||
| 28 | +} |
utils/yangutils/plugin/src/test/resources/usesInsideChildOfGrouping/ietf-te-topology.yang
0 → 100644
| 1 | +module ietf-te-topology { | ||
| 2 | + yang-version 1; | ||
| 3 | + namespace "urn:ietf:params:xml:ns:yang:ietf-te-topology"; | ||
| 4 | + | ||
| 5 | + prefix "tet"; | ||
| 6 | + | ||
| 7 | + import ietf-network { | ||
| 8 | + prefix "nw"; | ||
| 9 | + } | ||
| 10 | + | ||
| 11 | + revision "2016-03-17" { | ||
| 12 | + description "Initial revision"; | ||
| 13 | + } | ||
| 14 | + | ||
| 15 | + grouping te-node-augment { | ||
| 16 | + container te { | ||
| 17 | + presence "TE support."; | ||
| 18 | + | ||
| 19 | + leaf te-node-id { | ||
| 20 | + type string; | ||
| 21 | + mandatory true; | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + container config { | ||
| 25 | + uses te-node-config; | ||
| 26 | + } // config | ||
| 27 | + } // te | ||
| 28 | + } // te-node-augment | ||
| 29 | + | ||
| 30 | + grouping te-node-config { | ||
| 31 | + leaf-list te-node-template { | ||
| 32 | + if-feature template; | ||
| 33 | + type string; | ||
| 34 | + } | ||
| 35 | + uses te-node-config-attributes; | ||
| 36 | + } // te-node-config | ||
| 37 | + | ||
| 38 | + grouping te-node-config-attributes { | ||
| 39 | + container te-node-attributes { | ||
| 40 | + leaf admin-status { | ||
| 41 | + type string; | ||
| 42 | + } | ||
| 43 | + uses te-node-connectivity-matrix; | ||
| 44 | + } // te-node-attributes | ||
| 45 | + } // te-node-config-attributes | ||
| 46 | + | ||
| 47 | + grouping te-node-connectivity-matrix { | ||
| 48 | + list connectivity-matrix { | ||
| 49 | + key "id"; | ||
| 50 | + leaf id { | ||
| 51 | + type uint32; | ||
| 52 | + description "Identifies the connectivity-matrix entry."; | ||
| 53 | + } | ||
| 54 | + } | ||
| 55 | + } // te-node-connectivity-matrix | ||
| 56 | + | ||
| 57 | + augment "/nw:networks/nw:network/nw:node" { | ||
| 58 | + uses te-node-augment; | ||
| 59 | + } | ||
| 60 | +} |
-
Please register or login to post a comment