module yuma123-netconf-types {

   namespace "http://yuma123.org/ns/yuma123-netconf-types";

   prefix "nct";

   // for the uri data type
   import ietf-inet-types { prefix "inet"; }

   // for the xpath data type
   import ietf-yang-types { prefix "yang"; }

   // for NCX 'metadata' language extension
   import yuma-ncx { prefix "ncx"; }

   description 
      "NETCONF Protocol 
        * Data Types
        * Abstract object for PDU components
        * RPCs
       Translated from RFC 4741.";

   contact
     "Originally Translated by Andy Bierman.
      Send comments to <vladimir@transpacket.com>.";

   revision 2017-06-23 {
     description
       "Removed dependency to ietf-netconf.";
   }

   revision 2017-03-26 {
     description
       "Changed namespace in order to edit the original
        netconfcentral model. Splitted yuma-netconf
        into yuma123-netconf and yuma123-netconf-types";
   }

   typedef session-id-or-zero-type {
     type uint32;
     description
       "NETCONF Session Id or Zero to indicate none.
        Duplicates the typedef from ietf-netconf module
        to avoid dependency";
   }

   typedef Language {
     description "XML language type for LangString";
     type string {
       pattern '[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*';
     }
   }

   typedef ConfigURIType {
     type inet:uri;
   }

   typedef LangString {
     description "XML string with a language attribute.";
     type string;
     ncx:metadata "Language lang";
   }

   typedef MessageId {
     description "NETCONF message-id attribute";
     type  string {
        length "1..4095";
     }
   }

   typedef ErrorType {
     description "NETCONF Error Type";
     type enumeration {
       enum transport;
       enum rpc;
       enum protocol;
       enum application;
     }
   }


   // NETCONF Simple Types

   typedef error-tag-type {
     type enumeration {
        enum in-use {
          description
            "The request requires a resource that
             already is in use.";
        }
        enum invalid-value {
          description
            "The request specifies an unacceptable value for one
             or more parameters.";
        }
        enum too-big {
          description
            "The request or response (that would be generated) is
             too large for the implementation to handle.";
        }
        enum missing-attribute {
          description
            "An expected attribute is missing.";
        }
        enum bad-attribute {
          description
            "An attribute value is not correct; e.g., wrong type,
             out of range, pattern mismatch.";
        }
        enum unknown-attribute {
          description
            "An unexpected attribute is present.";
        }
        enum missing-element {
          description
            "An expected element is missing.";
        }
        enum bad-element {
          description
            "An element value is not correct; e.g., wrong type,
             out of range, pattern mismatch.";
        }
        enum unknown-element {
          description
            "An unexpected element is present.";
        }
        enum unknown-namespace {
          description
            "An unexpected namespace is present.";
        }
        enum access-denied {
          description
            "Access to the requested protocol operation, or
             data model is denied because authorization failed.";
        }
        enum lock-denied {
          description
            "Access to the requested lock is denied because the
             lock is currently held by another entity.";
        }
        enum resource-denied {
          description
            "Request could not be completed because of
             insufficient resources.";
        }
        enum rollback-failed {
          description
            "Request to rollback some configuration change (via
             rollback-on-error or discard-changes operations) was
             not completed for some reason.";

        }
        enum data-exists {
          description
            "Request could not be completed because the relevant
             data model content already exists. For example,
             a 'create' operation was attempted on data that
             already exists.";
        }
        enum data-missing {
          description
            "Request could not be completed because the relevant
             data model content does not exist.  For example,
             a 'delete' operation was attempted on
             data that does not exist.";
        }
        enum operation-not-supported {
          description
            "Request could not be completed because the requested
             operation is not supported by this implementation.";
        }
        enum operation-failed {
          description
            "Request could not be completed because the requested
             operation failed for some reason not covered by
             any other error condition.";
        }
        enum partial-operation {
          description
            "This error-tag is obsolete, and SHOULD NOT be sent
             by servers conforming to this document.";
        }
        enum malformed-message {
          description
            "A message could not be handled because it failed to
             be parsed correctly. For example, the message is not
             well-formed XML or it uses an invalid character set.";
        }
      }
      description "NETCONF Error Tag";
      reference "RFC 6241, Appendix A.";
   }

   typedef error-severity-type {
     type enumeration {
       enum error {
         description "Error severity";
       }
       enum warning {
         description "Warning severity";
       }
     }
     description "NETCONF Error Severity";
     reference "RFC XXXX, section 4.3.";
   }

   typedef TestOptionType {
     description 
       "NETCONF 'test-option' Element Content.";
     type enumeration {
       enum test-then-set;
       enum set;
       enum test-only;
     }
   }

   typedef ErrorOptionType {
     description "NETCONF 'error-option' Element Content";
     type enumeration { 
       enum stop-on-error;
       enum continue-on-error;
       enum rollback-on-error;
     }
     default "stop-on-error";
   }

   typedef FilterType {
     description "NETCONF 'filter' Attribute Content";
     type enumeration {
       enum subtree;
       enum xpath;
     }
     default "subtree";
   }

   typedef SelectString {
     description "XPath string used in the select attribute.";
     type string {
       ncx:xpath;
     }
   }

   typedef DefaultOperationType {
     description "NETCONF 'default-operation' Element Content";
     type enumeration { 
       enum merge;
       enum replace;
       enum none;
     }
     default "merge";
   }

   typedef ConfirmTimeoutType {
     description 
       "NETCONF 'confirm-timeout' Element Content";
     type uint32 { 
       range "1..max";
     }
     units "seconds";
     default "600";   // 10 minutes
   }

   // NETCONF Hello PDU Data Types
    
   grouping NcCapabilities {
     description "Generic Capabilities List.";

     container capabilities { 
       config false;
       leaf-list capability {
          description "One Generic Capability URI.";
          type inet:uri;
       }
     }
   }

   // NETCONF Operations PDU Data Types

   grouping ErrorInfoContent {
     description 
       "NETCONF standard 'error-info' Element Content;";

     leaf-list bad-attribute {
       description
         "Name of the missing or invalid XSD attribute.
          Used with missing-attribute, bad-attribute, and
          unknown-attribute error-tag values.";
       type   string;           // xs:QName
       config false;
     }

     leaf-list bad-element {
       description
         "Name of the element that contains (or should contain)
          an invalid XSD attribute when used with missing-attribute,
          bad-attribute, unknown-attribute, error-tag values.
          Name of an invalid or missing element when used with
          then missing-element, bad-element, unknown-element,
          and unknown-namespace error-tag values.";
       type   string;             // xs:QName
       config false;
     }

     leaf-list ok-element {
       description 
         "Identifies an element in the data model
          for which the requested operation has been completed
          for that node and all its child nodes.  This element
          can appear zero or more times in the 'error-info'
          container.  Used with the partial-operation error-tag
          value.";
       type   string;                    // xs:QName
       config false;
     }

     leaf-list err-element {
       description
         "Identifies an element in the data model
          for which the requested operation has failed for that
          node and all its child nodes.  This element
          can appear zero or more times in the 'error-info'
          container.   Used with the partial-operation error-tag
          value.";
        type   string;                   // xs:QName
        config false;
      }

      leaf-list noop-element {
        description
          "Identifies an element in the data model
           for which the requested operation was not attempted for
           that node and all its child nodes.  This element
           can appear zero or more times in the <error-info>
           container.   Used with the partial-operation error-tag
           value.";
        type   string;                  // xs:QName
        config false;
      }

      leaf session-id {
       description
         "Session ID of session holding the
          requested lock, or zero to indicate a non-NETCONF
          entity holds the lock.";
        type session-id-or-zero-type;
        config false;
      }
   }

   grouping RpcErrorType {
      description "NETCONF 'rpc-error' Element Content";

      leaf error-type {
        description 
          "Defines the conceptual layer that the error occurred.";
        type ErrorType;
        mandatory true;
      }

      leaf error-tag {
        description
          "Contains a string identifying the error condition.";
        type error-tag-type;
        mandatory true;
      }

      leaf error-severity {
        description
          "Contains a string identifying the error severity, as
           determined by the device.";
        type error-severity-type;
        mandatory true;
      }

      leaf error-app-tag {
        description
          "Contains a string identifying the data-model-specific
           or implementation-specific error condition, if one exists.
           This element will not be present if no appropriate 
           application error tag can be associated with a particular
           error condition.";
        type string;
      }

     leaf error-path {
       description
         "Contains the absolute XPath [2] expression identifying
          the element path to the node that is associated with the error
          being reported in a particular rpc-error element.  This element
         will not be present if no appropriate payload element can be
         associated with a particular error condition, or if the
         'bad-element' QString returned in the 'error-info' container is
         sufficient to identify the node associated with the error.  When
         the XPath expression is interpreted, the set of namespace
         declarations are those in scope on the rpc-error element,
         including the default namespace.";
       type yang:xpath1.0;
     }

     leaf error-message {
       description
         "Contains a string suitable for human display that
          describes the error condition.  This element will not be present
          if no appropriate message is provided for a particular error
          condition.  This element SHOULD include an xml:lang attribute.";
        type LangString;
      }

      anyxml error-info {
        description
          "Contains protocol- or data-model-specific error content.
           This element will not be present if no such error content is
           provided for a particular error condition.  The list in 
           RFC 4741, Appendix A, defines any mandatory error-info content 
           for each error.  After any protocol-mandated content, a 
           data model definition may mandate that certain application-layer
           error information be included in the error-info container. 
           An implementation may include additional elements to 
           provide extended and/or implementation-specific debugging 
           information.";
      }
   }

   grouping RpcDataReplyType {
      description "NETCONF 'rpc-reply' Error and/or Data Content";

      list rpc-error {
        config false;
        uses RpcErrorType;
      }
      // anyxml data {
      //   config false;
      // }
      // any XML is allowed here, not just 1 el. named data
      // The contents of the 'rpc output' section appears here
   }

   grouping RpcOkReplyType {
      description "NETCONF 'rpc-reply' OK Content.";

      choice ok-or-error {
        leaf ok {
          description
            "Sent in 'rpc-reply' messages if no errors or
             warnings occurred during the processing of an 'rpc' request.";
          type empty;
          config false;
        }

        list rpc-error {
          config false;
          uses RpcErrorType;
        }
      }
   }

   grouping RpcReplyType {
      description "Generic NETCONF 'rpc-reply' content. ";

      choice ok-or-data-error {
        mandatory true;
        config false;

        leaf ok {
          description
            "Sent in 'rpc-reply' messages if no errors or
             warnings occurred during the processing of an 'rpc' request.";
          type empty;
        }

        case data-error {
           uses RpcDataReplyType;
        }
      }
   }
}

