module openconfig-yang-types {
  yang-version 1;
  namespace "http://openconfig.net/yang/types/yang";
  prefix oc-yang;

  import openconfig-extensions {
    prefix oc-ext;
  }

  organization
    "OpenConfig working group";
  contact
    "OpenConfig working group
     www.openconfig.net";
  description
    "This module contains a set of extension types to the
     YANG builtin types that are used across multiple
     OpenConfig models.

     Portions of this code were derived from IETF RFC 6021.
     Please reproduce this note if possible.

     IETF code is subject to the following copyright and license:
     Copyright (c) IETF Trust and the persons identified as authors of
     the code.
     All rights reserved.

     Redistribution and use in source and binary forms, with or without
     modification, is permitted pursuant to, and subject to the license
     terms contained in, the Simplified BSD License set forth in
     Section 4.c of the IETF Trust's Legal Provisions Relating
     to IETF Documents (http://trustee.ietf.org/license-info).";

  revision 2021-07-14 {
    description
      "Use auto-generated regex for certain pattern statements:
       - dotted-quad
       - date-and-time
       - date

       For date-and-time, allow lowercase z and t in the pattern.";
    reference
      "0.3.1";
  }
  revision 2021-03-02 {
    description
      "Fix date-and-time and date's pattern statement, and remove the
       regexp-posix extension, which makes pattern statements conform to the
       YANG standard.";
    reference
      "0.3.0";
  }
  revision 2020-06-30 {
    description
      "Add OpenConfig POSIX pattern extensions.";
    reference
      "0.2.2";
  }
  revision 2018-11-21 {
    description
      "Add OpenConfig module metadata extensions.";
    reference
      "0.2.1";
  }
  revision 2018-04-24 {
    description
      "Add date typedef";
    reference
      "0.2.0";
  }
  revision 2017-07-30 {
    description
      "Fixed unprintable character";
    reference
      "0.1.2";
  }
  revision 2017-04-03 {
    description
      "Update copyright notice.";
    reference
      "0.1.1";
  }
  revision 2017-01-26 {
    description
      "Initial module for inet types";
    reference
      "0.1.0";
  }

  oc-ext:openconfig-version "0.3.1";
  oc-ext:catalog-organization "openconfig";
  oc-ext:origin "openconfig";

  typedef dotted-quad {
    type string {
      oc-ext:posix-pattern "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])){3})$";
      pattern "([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])){3}";
    }
    description
      "An unsigned 32-bit integer expressed as a dotted quad. The
       format is four octets written as decimal numbers separated
       with a period character.";
  }

  typedef hex-string {
    type string {
      oc-ext:posix-pattern "^[0-9a-fA-F]*$";
      pattern "[0-9a-fA-F]*";
    }
    description
      "A string consisting of a hexadecimal characters.";
  }

  typedef counter32 {
    type uint32;
    description
      "A 32-bit counter. A counter value is a monotonically increasing
       value which is used to express a count of a number of
       occurrences of a particular event or entity. When the counter
       reaches its maximum value, in this case 2^32-1, it wraps to 0.

       Discontinuities in the counter are generally triggered only when
       the counter is reset to zero.";
  }

  typedef counter64 {
    type uint64;
    description
      "A 64-bit counter. A counter value is a monotonically increasing
       value which is used to express a count of a number of
       occurrences of a particular event or entity. When a counter64
       reaches its maximum value, 2^64-1, it loops to zero.
       Discontinuities in a counter are generally triggered only when
       the counter is reset to zero, through operator or system
       intervention.";
  }

  typedef date-and-time {
    type string {
      oc-ext:posix-pattern "^([0-9]{4}\\-(0[1-9]|1[0-2])\\-(0[1-9]|[12][0-9]|3[01])[Tt](0[0-9]|1[0-9]|2[0-3]):(0[0-9]|[1-5][0-9]):(0[0-9]|[1-5][0-9]|60)(\\.[0-9]+)?([Zz]|([+-](0[0-9]|1[0-9]|2[0-3]):(0[0-9]|[1-5][0-9]))))$";
      pattern "[0-9]{4}\\-(0[1-9]|1[0-2])\\-(0[1-9]|[12][0-9]|3[01])[Tt](0[0-9]|1[0-9]|2[0-3]):(0[0-9]|[1-5][0-9]):(0[0-9]|[1-5][0-9]|60)(\\.[0-9]+)?([Zz]|([+-](0[0-9]|1[0-9]|2[0-3]):(0[0-9]|[1-5][0-9])))";
    }
    description
      "A date and time, expressed in the format described in RFC3339.
       That is to say:

       YYYY-MM-DDTHH:MM:SSZ+-hh:mm

       where YYYY is the year, MM is the month expressed as a two-digit
       month (zero padding if required), DD is the day of the month,
       expressed as a two digit value. T is the literal character 'T',
       HH is the hour of the day expressed as a two digit number, using
       the 24-hour clock, MM is the minute of the hour expressed as a
       two digit number. Z is the literal character 'Z', followed by a
       timezone offset expressed in hours (hh) and minutes (mm), both
       expressed as two digit numbers. The time offset is specified as
       a positive or negative offset to UTC using the '+' or '-'
       character preceding the offset.

       Optionally, fractional seconds can be expressed after the minute
       of the hour as a decimal number of unspecified precision
       reflecting fractions of a second.";
    reference
      "RFC3339 - Date and Time on the Internet: Timestamps";
  }

  typedef date {
    type string {
      oc-ext:posix-pattern "^([0-9]{4}\\-(0[1-9]|1[0-2])\\-(0[1-9]|[12][0-9]|3[01]))$";
      pattern "[0-9]{4}\\-(0[1-9]|1[0-2])\\-(0[1-9]|[12][0-9]|3[01])";
    }
    description
      "A full UTC date, expressed in the format described in RFC3339.
       That is to say:

       YYYY-MM-DD

       where YYYY is the year, MM is the month expressed as a two-digit
       month (zero padding if required), DD is the day of the month,
       expressed as a two digit value.";
    reference
      "RFC3339 - Date and Time on the Internet: full-date";
  }

  typedef gauge64 {
    type uint64;
    description
      "A gauge value may increase or decrease - and reflects a value
       at a particular point in time. If the value of the variable
       being modeled using the gauge exceeds its maximum - 2^64-1 in
       this case - the gauge is set to its maximum value.";
  }

  typedef phys-address {
    type string {
      oc-ext:posix-pattern "^([0-9a-fA-F]{2}(:[0-9a-fA-F]{2})*)?$";
      pattern "([0-9a-fA-F]{2}(:[0-9a-fA-F]{2})*)?";
    }
    description
      "A physical layer address, expressed as a series of pairs of
       hexadecimal digits.";
  }

  typedef mac-address {
    type string {
      oc-ext:posix-pattern "^[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){5}$";
      pattern "[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){5}";
    }
    description
      "An IEEE 802 MAC address";
  }
}