Internet Draft Vinod Kumar S NETMOD Working Group Gaurav Agrawal Category: Operational Anil Kumar S N Expires: December 30, 2016 Huawei Technologies June 28, 2016 Defining and Using Metadata for YANG compilers draft-agv-netmod-yang-compiler-metadata-00 Status of this Memo This Internet-Draft is submitted in full conformance with the provisions of BCP 78 and BCP 79. Internet-Drafts are working documents of the Internet Engineering Task Force (IETF). Note that other groups may also distribute working documents as Internet-Drafts. The list of current Internet- Drafts is at http://datatracker.ietf.org/drafts/current/. Internet-Drafts are draft documents valid for a maximum of six months and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use Internet-Drafts as reference material or to cite them other than as "work in progress." This Internet-Draft will expire on December 30, 2016. Copyright Notice Copyright (c) 2013 IETF Trust and the persons identified as the document authors. All rights reserved. This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (http://trustee.ietf.org/license-info) in effect on the date of publication of this document. Please review these documents carefully, as they describe your rights and restrictions with respect to this document. Code Components extracted from this document must include Simplified BSD License text as described in Section 4.e of the Trust Legal Provisions and are provided without warranty as described in the Simplified BSD License. AGV Expires December 30, 2016 [Page 1] INTERNET DRAFT Metadata for YANG compilers June 28, 2016 Abstract This document defines a YANG extension statement that allows for defining compiler metadata (annotations) in YANG modules. Table of Contents 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 3 2. Terminology . . . . . . . . . . . . . . . . . . . . . . . . . 5 2.1. Keywords . . . . . . . . . . . . . . . . . . . . . . . . . 5 2.2. Terms Defined in Other Documents . . . . . . . . . . . . . 5 2.4. Definitions of New Terms . . . . . . . . . . . . . . . . . 6 3. Defining compiler annotations in YANG . . . . . . . . . . . . 6 3.1. Example Definition . . . . . . . . . . . . . . . . . . . . 8 4. Using Annotations . . . . . . . . . . . . . . . . . . . . . . 9 5. Metadata YANG Module . . . . . . . . . . . . . . . . . . . . . 9 8. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 13 9 Security Considerations . . . . . . . . . . . . . . . . . . . . 13 10. Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . 13 11 References . . . . . . . . . . . . . . . . . . . . . . . . . . 14 11.1 Normative References . . . . . . . . . . . . . . . . . . . 14 11.2 Informative References . . . . . . . . . . . . . . . . . . 14 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . . 15 AGV Expires December 30, 2016 [Page 2] INTERNET DRAFT Metadata for YANG compilers June 28, 2016 1. Introduction YANG started as a data modeling language used to model configuration data, state data, remote procedure calls, and notifications for network management protocols. The purpose of YANG was focused on expressing the data organization while being exchanged over network. It also addressed the constraints that needs to be taken care by the data set exchanged. YANG has out grown the purpose for which it was invented. Due to its simplicity in structure and flexibility many tools have been developed which tries to ease the application development by automating the code generated corresponding to defined schema. All the implementation related data structures / classes could be auto generated and applications only concentrate on the business logic implementation. Applications are being relieved from actual protocol implementation for exchanging information with external system. The purpose of YANG was focused on expressing the data organization while being exchanged over network. Hence the scope of automation in application development cannot cater to data organization / processing within the system. So there is a need to support compiler annotations in YANG, by which applications can instruct the YANG utilities or compilers to automate the application development related to data organization / processing. Typical use cases are: o Feed input to YANG compiler/utilities which can be used to automate the code generation based on standard data structure or collections. o Enable the code generation to incorporate the design patterns required by applications. o Enable the data structure or collections to have multiple indexes beyond the current supported list's key(s). Since the actual implementation would required searching the data based on different leaf combinations. o Enable applications to model internal data organization, required for business logic implementation, and not exposed to outside world. Usage of compiler annotations are dependent on the compiler consuming it. This draft is intended to document YANG extension to support AGV Expires December 30, 2016 [Page 3] INTERNET DRAFT Metadata for YANG compilers June 28, 2016 defining compiler annotation framework.It is outside the scope of this document about the specific compiler annotation(s) definition / usage. Individual annotation definition and usage SHOULD be standardized in other docs. Definition and usage of compiler annotation is limited to a particular protocol or application development within a device, it has no effect on how the management information is exchanged between 2 devices over network. A server SHOULD share its YANG file(s) after removing the compiler annotations that was added for its implementation. A client MUST ignore any compiler annotations present in the YANG file(s). A client MAY redefine the compiler annotation as per its implementation requirements. Clients MAY also add new annotation depending on its implementation requirements. This document proposes a systematic way for defining compiler metadata annotations. For this purpose, YANG extension statement "compiler-annotation" is defined in the module "agv-yang-compiler- annotation" (Section 5). Other YANG modules importing this module can use the "compiler-annotation" statement for defining one or more compiler annotations. The benefits of defining the compiler-annotations in a YANG module are the following: o Applications can use YANG as a tool to design the application implementation. o Enhance the YANG compiler(s) capability to automate the application development process. o Enhance the protocol development to provide better application development framework. o YANG could be extended to support data modeling for protocol beyond NETCONF or RESTCONF. Due to the rules for YANG extensions (see sec. 6.3.1 in [I-D.ietf- netmod-rfc6020bis]), compiler-annotation definitions posit relatively weak conformance requirements. The alternative of introducing a new built-in YANG mechanism for compiler annotations was considered, but it was seen as a major change to the language that is inappropriate for YANG 1.1, which was chartered as a maintenance revision. After evaluating real-life usage of compiler metadata annotations, it is designed in such way that the ABNF grammar can seamlessly adapt the current defined compiler annotations. AGV Expires December 30, 2016 [Page 4] INTERNET DRAFT Metadata for YANG compilers June 28, 2016 2. Terminology 2.1. Keywords The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in [RFC2119]. 2.2. Terms Defined in Other Documents The following terms are defined in [RFC6241]: o capability, o client, o datastore, o message, o protocol operation, o server. The following terms are defined in [I-D.ietf-netmod-rfc6020bis]: o action, o anydata, o anyxml, o built-in type, o container, o data model, o data node, o data tree, o derived type, o extension, o leaf, AGV Expires December 30, 2016 [Page 5] INTERNET DRAFT Metadata for YANG compilers June 28, 2016 o leaf-list, o list, o module, o RPC input and output. 2.4. Definitions of New Terms o compiler-annotation: a single item of compiler metadata that is attached to YANG constructs. o compiler metadata: additional information that complements a schema tree. o metadata object: an object in JSON encoding that contains all annotations attached to a given data node instance. 3. Defining compiler annotations in YANG Compiler metadata annotations are defined by YANG extension statement "ca:compiler-annotation". This YANG language extension is defined in the module "agv-yang-compiler-annotation" (Section 5). sub-statements of "ca:compiler-annotation" are shown in Table 2. They are all core YANG statements, and the numbers in the second column refer to the corresponding section in [I-D.ietf-netmod- rfc6020bis] where each statement is described. +---------------+---------------------+-------------+ | sub-statement | RFC 6020bis section | cardinality | +---------------+---------------------+-------------+ | description | 7.21.3 | 0..1 | | if-feature | 7.20.2 | 0..n | | reference | 7.21.4 | 0..1 | | status | 7.21.2 | 0..1 | | units | 7.3.3 | 0..1 | | @ANNOTATION | Current Section 5 | 1..n | +---------------+---------------------+-------------+ Table 2: Substatements of "ca:compiler-annotation". A YANG construct can have one or more compiler annotation. The @ANNOTATION substatement, which MUST be present at least once, follows the ABNF specification as defined in section 5. An compiler annotation can be made conditional by using one or more "if- feature" statements; the compiler annotation is then consumed by compilers and perform the desired operation in compilation. AGV Expires December 30, 2016 [Page 6] INTERNET DRAFT Metadata for YANG compilers June 28, 2016 The semantics and usage rules for a compiler-annotation SHOULD be fully specified in another document. A compiler-annotation MUST NOT change the schema tree semantics defined by YANG. For example, it is illegal to define and use an compiler-annotation that allows modification to data-def-stmts. The "status" statement can be used exactly as for YANG schema nodes. AGV Expires December 30, 2016 [Page 7] INTERNET DRAFT Metadata for YANG compilers June 28, 2016 3.1. Example Definition The following module defines the "MappedCollection" compiler- annotation: module example-compiler-annotation { namespace "urn:agv:params:xml:ns:yang:example-compiler-annotation"; prefix "example"; import agv-yang-compiler-annotation{ prefix "ca"; } organization "IETF NETMOD (NETCONF Data Modeling Language) Working Group"; contact "WG Web: WG List: "; description "This YANG module demonstrates the usage of compiler annotation by any module."; revision 2016-06-22 { description "Initial revision."; reference "RFC draft agv: example of defining and using compiler annotations with YANG"; } container candidate-servers{ list server { ca:compiler-annotation{ @MappedCollection(collection-type='map', map-key='name') @OverrideImpl('DefaultServer'); } key "name"; unique "ip port"; leaf name { type string; } leaf ip { type inet:ip-address; AGV Expires December 30, 2016 [Page 8] INTERNET DRAFT Metadata for YANG compilers June 28, 2016 } leaf port { type inet:port-number; } } } } 4. Using Annotations By defining a YANG module in which a compiler metadata annotation is defined using the "ca:compiler-annotation" statement, an application indicates compiler to handle that compiler-annotation according to the compiler-annotation's definition. That is, the compiler- annotation uses it as input for automation of code generation or applications development. Depending on its semantics, an annotation may have an effect only in certain schema trees and/or on specific schema node types. A client MUST NOT use the compiler-annotation to interpret the schema even if it is advertised by a server. 5. Metadata YANG Module RFC Editor: In this section, replace all occurrences of 'XXXX' with the actual RFC number and all occurrences of the revision date below with the date of RFC publication (and remove this note). RFC Editor: Also please replace all occurrences of 'RFC 6020bis' with the actual RFC number that will be assigned to [I-D.ietf-netmod- rfc6020bis]. AGV Expires December 30, 2016 [Page 9] INTERNET DRAFT Metadata for YANG compilers June 28, 2016 file "agv-yang-compiler-annotation.yang" module agv-yang-compiler-annotation { namespace "urn:agv:params:xml:ns:yang:agv-yang-compiler-annotation"; prefix "ca"; organization "IETF NETMOD (NETCONF Data Modeling Language) Working Group"; contact "WG Web: WG List: "; description "This YANG module defines an extension statement that allows for defining compiler annotations. The key words 'MUST', 'MUST NOT', 'REQUIRED', 'SHALL', 'SHALL NOT', 'SHOULD', 'SHOULD NOT', 'RECOMMENDED', 'MAY', and 'OPTIONAL' in the module text are to be interpreted as described in RFC 2119 (http://tools.ietf.org/html/rfc2119)."; revision 2016-06-22 { description "Initial revision."; reference "RFC draft agv: Defining and Using compiler annotations with YANG"; } extension compiler-annotation { description "This extension allows for defining compiler annotations for any body-stmts. The 'ca:compiler-annotation' statement contains annotations applicable to its parent statement. It's purpose is to provide additional information to compiler about internal implementation of the modeled information. It MAY be consumed by the compiler of the device supporting the schema. The peer device using the schema for communication, MUST NOT depend on the ca:compiler-annotations for interpreting the schema of the information exchanged. AGV Expires December 30, 2016 [Page 10] INTERNET DRAFT Metadata for YANG compilers June 28, 2016 The ca:compiler-annotation defined with this extension statement do not affect the namespace or get impacted by the namespace of the YANG file where it is used. Semantics of the annotation and other documentation can be specified using the following standard YANG substatements (all are optional): 'description', 'reference', 'status', and 'units'. The presence of a 'if-feature' child to the ca: compiler-annotation, means the compiler consumes the annotation when the feature is supported by the device. Server MAY trim the ca:compiler-annotations in the schema while sharing it to a client in protocol exchange. Client receiving the schema from a Server in protocol exchange, SHOULD ignore the ca:compiler-annotations present in the schema definition. The must be 1 or more child entries with '@ANNOTATION_NAME' as per the compiler-annotation ABNF grammar defined in draft agv-yang-compiler-annotation. compiler-annotation-stmt = compiler-annotation-keyword optsep \"{\" stmtsep ;; these stmts can appear in any order [description-stmt stmtsep] *(if-feature-stmt stmtsep) [reference-stmt stmtsep] [status-stmt stmtsep] [units-stmt stmtsep] 1*(annotation-stmt stmtsep) \"}\" annotation-stmt = \"@\" annotation-type [annotation-parameter-specification] \";\" annotation-type = identifier annotation-parameter-specification = \"(\" optsep annotation-parameter-specification-arg optsep \")\" annotation-parameter-specification-arg = annotation-para-value / annotation-para-instance *(\",\" annotation-para-instance) annotation-para-instance = annotation-para-type-identifier optsep \"=\" optsep annotation-para-value AGV Expires December 30, 2016 [Page 11] INTERNET DRAFT Metadata for YANG compilers June 28, 2016 annotation-para-type-identifier = identifier annotation-para-value = identifier The choosen ABNF can be updated in YANG 2.0 as part of any body-stmts and this extension can be obsloted"; } // compiler-annotation } //module agv-yang-compiler-annotation AGV Expires December 30, 2016 [Page 12] INTERNET DRAFT Metadata for YANG compilers June 28, 2016 8. IANA Considerations RFC Editor: In this section, replace all occurrences of 'XXXX' with the actual RFC number and all occurrences of the revision date below with the date of RFC publication (and remove this note). This document registers a URI in the "IETF XML registry" [RFC3688]. Following the format in RFC 3688, the following registration has been made. ------------------------------------------------------------------ URI: urn:agv:params:xml:ns:yang:agv-yang-compiler-annotation Registrant Contact: The NETMOD WG of the IETF. XML: N/A, the requested URI is an XML namespace. ------------------------------------------------------------------ This document registers a YANG module in the "YANG Module Names" registry [RFC6020]. ------------------------------------------------------------------ name: agv-yang-compiler-annotation namespace: urn:agv:params:xml:ns:yang: agv-yang-compiler-annotation prefix: md reference: RFC XXXX ------------------------------------------------------------------ 9 Security Considerations This document introduces a mechanism for defining compiler metadata annotations in YANG modules and attaching them to instances of YANG schema nodes. By itself, this mechanism represents no security threat. Security implications of a particular compiler-annotation defined using this mechanism MUST be duly considered and documented in the the compiler-annotation's definition. 10. Acknowledgments AGV Expires December 30, 2016 [Page 13] INTERNET DRAFT Metadata for YANG compilers June 28, 2016 11 References 11.1 Normative References I-D.ietf-netmod-rfc6020bis] Bjorklund, M., "The YANG 1.1 Data Modeling Language", draft-ietf-netmod-rfc6020bis-11 (work in progress), February 2016. I-D.ietf-netmod-yang-json] Lhotka, L., "JSON Encoding of Data Modeled with YANG", draft-ietf-netmod-yang-json-09 (work in progress), March 2016. RFC2119] Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", BCP 14, RFC 2119, DOI 10.17487/RFC2119, March 1997, . RFC3688] Mealling, M., "The IETF XML Registry", BCP 81, RFC 3688, DOI 10.17487/RFC3688, January 2004, . RFC5234] Crocker, D., Ed. and P. Overell, "Augmented BNF for Syntax Specifications: ABNF", STD 68, RFC 5234, DOI 10.17487/RFC5234, January 2008, . RFC6020] Bjorklund, M., Ed., "YANG - A Data Modeling Language for the Network Configuration Protocol (NETCONF)", RFC 6020, DOI 10.17487/RFC6020, October 2010, . 11.2 Informative References [I-D.ietf-netconf-restconf] Bierman, A., Bjorklund, M., and K. Watsen, "RESTCONF Protocol", draft-ietf-netconf-restconf-10 (work in progress), March 2016. [RFC6241] Enns, R., Ed., Bjorklund, M., Ed., Schoenwaelder, J., and A. Bierman, Ed., "Network Configuration Protocol (NETCONF)", RFC 6241, DOI 10.17487/RFC6241, June 2011, . AGV Expires December 30, 2016 [Page 14] INTERNET DRAFT Metadata for YANG compilers June 28, 2016 Authors' Addresses Vinod Kumar S Huawei Technologies India Pvt. Ltd, Near EPIP Industrial Area, Kundalahalli Village, Whitefield, Bangalore - 560066 EMail: vinods.kumar@huawei.com Gaurav Agrawal Huawei Technologies India Pvt. Ltd, Near EPIP Industrial Area, Kundalahalli Village, Whitefield, Bangalore - 560066 EMail: gaurav.agrawal@huawei.com Anil Kumar S N Huawei Technologies India Pvt. Ltd, Near EPIP Industrial Area, Kundalahalli Village, Whitefield, Bangalore - 560066 EMail: anil.ietf@gmail.com AGV Expires December 30, 2016 [Page 15]