module ietf-connection-oriented-oam {
  yang-version 1.1;
  namespace "urn:ietf:params:xml:ns:yang:ietf-connection-oriented-oam";
  prefix co-oam;

  import ietf-yang-types {
    prefix yang;
  }
  import ietf-inet-types {
    prefix inet;
  }
  import ietf-interfaces {
    prefix if;
  }

  organization
    "IETF LIME Working Group";
  contact
    "WG Web:    http://datatracker.ietf.org/wg/lime
     WG List:   <mailto:lime@ietf.org>
     Editor:    Deepak Kumar <dekumar@cisco.com>
     Editor:    Qin Wu <bill.wu@huawei.com>
     Editor:    Michael Wang <wangzitao@huawei.com>";
  description
    "This YANG module defines the generic configuration,
     statistics and RPC for connection-oriented OAM
     to be used within IETF in a protocol-independent manner.
     Functional-level abstraction is independent
     with YANG modeling. It is assumed that each protocol
     maps corresponding abstracts to its native format.
     Each protocol may extend the YANG data model defined
     here to include protocol-specific extensions

     Copyright (c) 2019 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).

     This version of this YANG module is part of RFC 8531; see
     the RFC itself for full legal notices.";

  revision 2019-02-11 2019-03-11 {
    description
      "Initial revision.";
    reference
      "RFC 8531: Generic YANG Data Model for Connection-
       Oriented Operations, Administration, and Maintenance (OAM)
       Protocols";
  }

  feature connectivity-verification {
    description
      "This feature indicates that the server supports
       executing a connectivity verification OAM command and
       returning a response.  Servers that do not advertise
       this feature will not support executing a
       connectivity verification command or RPC model for a
       connectivity verification command.";
  }

  feature continuity-check {
    description
      "This feature indicates that the server supports
       executing a Continuity Check OAM command and
       returning a response.  Servers that do not advertise
       this feature will not support executing a
       Continuity Check command or RPC model for a
       Continuity Check command.";
  }

  feature traceroute {
    description
      "This feature indicates that the server supports
       executing a traceroute OAM command and
       returning a response.  Servers that do not advertise
       this feature will not support executing a
       traceroute command or RPC model for a
       traceroute command.";
  }

  feature mip {
    description
      "This feature indicates that the Maintenance
       Intermediate Point (MIP) needs to be explicitly configured";
  }

  identity technology-types {
    description
      "This is the base identity of technology types that are
       TRILL, MPLS-TP, etc.";
  }

  identity command-sub-type {
    description
      "Defines different RPC command subtypes,
       e.g., TRILL OAM as specified in RFC 6905; this is
       optional for most cases.";
    reference
      "RFC 6905: Requirements for OAM in Transparent
       Interconnection of Lots of Links (TRILL)";
  }

  identity on-demand {
    base command-sub-type;
    description
      "On-demand activation indicates that the tool is activated
       manually to detect a specific anomaly.
       An on-demand OAM method requires only transient configuration.";
    reference
      "RFC 7276: An Overview of Operations, Administration, and
       Maintenance (OAM) Tools";
  }

  identity proactive {
    base command-sub-type;
    description
      "Proactive activation indicates that the tool is activated on a
       continual basis, where messages are sent periodically, and errors
       are detected when a certain number of expected messages are not
       received.  A proactive OAM method requires persistent
       configuration.";
    reference
      "RFC 7276: An Overview of Operations, Administration, and
       Maintenance (OAM) Tools";
  }

  identity name-format {
    description
      "This defines the name format, CFM (IEEE 802.1Q) defines varying
       styles of names.  It is expected that name format is an identity
       reference to be extended with new types.";
  }

  identity name-format-null {
    base name-format;
    description
      "Defines name format as null.";
  }

  identity identifier-format {
    description
      "Identifier-format identity can be augmented to define other
       format identifiers used in MEP-ID, etc.";
  }

  identity identifier-format-integer {
    base identifier-format;
    description
      "Defines identifier-format to be integer.";
  }

  identity defect-types {
    description
      "Defines different defect types, e.g.,
       Remote Defect Indication (RDI), loss of continuity.";
  }

  identity rdi {
    base defect-types;
    description
      "The RDI indicates the
       aggregate health of the remote Maintenance End Points (MEPs).";
  }

  identity remote-mep-defect {
    base defect-types;
    description
      "Indicates that one or more of the remote MEPs are
       reporting a failure.";
  }

  identity loss-of-continuity {
    base defect-types;
    description
      "Indicates that there are no proactive Continuity Check (CC)
       OAM packets from the source MEP (and in the case of
       Connectivity Verification, this includes the requirement to have
       the expected unique, technology-dependent source MEP identifier)
       received within the interval.";
    reference
      "RFC 6371: Operations, Administration, and Maintenance
       Framework for MPLS-Based Transport Networks";
  }

  identity cv-defect {
    base defect-types;
    description
      "This function should support monitoring between the MEPs
       and, in addition, between a MEP and MIP.  When performing
       Connectivity Verification, the Continuity Check and
       Connectivity Verification (CC-V) messages need to include
       unique identification of the MEG that is being monitored and
       the MEP that originated the message.";
    reference
      "RFC 6371: Operations, Administration, and Maintenance
       Framework for MPLS-Based Transport Networks";
  }

  identity invalid-oam-defect {
    base defect-types;
    description
      "Indicates that one or more invalid OAM messages have been
       received and that 3.5 times that OAM message transmission
       interval has not yet expired.";
  }
  identity cross-connect-defect {
    base defect-types;
    description
      "Indicates that one or more cross-connect defect
       (for example, a service ID does not match the VLAN)
       messages have been received and that 3.5 times that OAM message
       transmission interval has not yet expired.";
  }

  typedef mep-name {
    type string;
    description
      "Generic administrative name for a MEP.";
  }

  typedef time-interval {
    type decimal64 {
      fraction-digits 2;
    }
    units "milliseconds";
    description
      "Time interval between packets in milliseconds.
       Time interval should not be less than 0.
       0 means no packets are sent.";
  }

  typedef md-name-string {
    type string;
    description
      "Generic administrative name for Maintenance Domain (MD).";
  }

  typedef ma-name-string {
    type string;
    description
      "Generic administrative name for a
       Maintenance Association (MA).";
  }

  typedef oam-counter32 {
    type yang:zero-based-counter32;
    description
      "Define 32-bit counter for OAM.";
  }

  typedef md-level {
    type uint32 {
      range "0..255";
    }
    description
      "Maintenance Domain Level.  The level may be restricted in
       certain protocols (e.g., protocol in layer 0 to layer 7).";
  }

  grouping maintenance-domain-reference {
    description
      "This grouping uniquely identifies a Maintenance Domain.";
    leaf maintenance-domain {
      type leafref {
        path "/co-oam:domains/co-oam:domain/co-oam:md-name-string";
      }
      description
        "A reference to a specific Maintenance Domain.";
    }
  }

  grouping maintenance-association-reference {
    description
      "This grouping uniquely identifies a
       Maintenance Association.  It consists
       of a maintenance-domain-reference and
       a maintenance-association leafref.";
    uses maintenance-domain-reference;
    leaf maintenance-association {
      type leafref {
        path "/co-oam:domains/co-oam:domain[co-oam:md-name-string "
        +"=
           + "= current()/../maintenance-domain]/co-oam:mas"
        +"/co-oam:ma/co-oam:ma-name-string";
           + "/co-oam:ma/co-oam:ma-name-string";
      }
      description
        "A reference to a specific Maintenance Association.";
    }
  }

  grouping maintenance-association-end-point-reference {
    description
      "This grouping uniquely identifies
       a Maintenance Association.  It consists
       of a maintenance-association-reference and
       a maintenance-association-end-point leafref.";
    uses maintenance-association-reference;
    leaf maintenance-association-end-point {
      type leafref {
        path "/co-oam:domains/co-oam:domain[co-oam:md-name-string "
        +"=
           + "= current()/../maintenance-domain]/co-oam:mas"
        +"/co-oam:ma[co-oam:ma-name-string
           + "/co-oam:ma[co-oam:ma-name-string = "
        +"current()/../maintenance-association]"
        +"/co-oam:mep/co-oam:mep-name";
           + "current()/../maintenance-association]"
           + "/co-oam:mep/co-oam:mep-name";
      }
      description
        "A reference to a specific Maintenance
         association End Point.";
    }
  }

  grouping time-to-live {
    leaf ttl {
      type uint8;
      description
        "Time to Live.";
    }
    description
      "Time to Live grouping.";
  }

  grouping defect-message {
    choice defect {
      case defect-null {
        description
          "This is a placeholder when no defect status is needed.";
        leaf defect-null {
          type empty;
          description
            "There is no defect to be defined; it will be defined in
             a technology-specific model.";
        }
      }
      case defect-code {
        description
          "This is a placeholder to display defect code.";
        leaf defect-code {
          type int32;
          description
            "Defect code is integer value specific to a technology.";
        }
      }
      description
        "Defect Message choices.";
    }
    description
      "Defect Message.";
  }

  grouping mep-address {
    choice mep-address {
      default ip-address; "ip-address";
      case mac-address {
        leaf mac-address {
          type yang:mac-address;
          description
            "MAC Address.";
        }
        description
          "MAC Address based MEP Addressing.";
      }
      case ip-address {
        leaf ip-address {
          type inet:ip-address;
          description
            "IP Address.";
        }
        description
          "IP Address based MEP Addressing.";
      }
      description
        "MEP Addressing.";
    }
    description
      "Grouping for MEP Address";
  }

  grouping mip-address {
    choice mip-address {
      default ip-address; "ip-address";
      case mac-address {
        leaf mac-address {
          type yang:mac-address;
          description
            "MAC Address of Maintenance Intermediate Point";
        }
        description
          "MAC Address based MIP Addressing.";
      }
      case ip-address {
        leaf ip-address {
          type inet:ip-address;
          description
            "IP Address.";
        }
        description
          "IP Address based MIP Addressing.";
      }
      description
        "MIP Addressing.";
    }
    description
      "MIP Address.";
  }

  grouping maintenance-domain-id {
    description
      "Grouping containing leaves sufficient to identify
       a Maintenance Domain.";
    leaf technology {
      type identityref {
        base technology-types;
      }
      mandatory true;
      description
        "Defines the technology.";
    }
    leaf md-name-string {
      type md-name-string;
      mandatory true;
      description
        "Defines the generic administrative Maintenance Domain name.";
    }
  }

  grouping md-name {
    leaf md-name-format {
      type identityref {
        base name-format;
      }
      description
        "Maintenance Domain Name format.";
    }
    choice md-name {
      case md-name-null {
        leaf md-name-null {
          when "derived-from-or-self(../md-name-format,"
          +"'name-format-null')"
             + "'name-format-null')" {
            description
              "MD name format is equal to null format.";
          }
          type empty;
          description
            "MD name null.";
        }
      }
      description
        "MD name.";
    }
    description
      "MD name.";
  }

  grouping ma-identifier {
    description
      "Grouping containing leaves sufficient to identify an MA.";
    leaf ma-name-string {
      type ma-name-string;
      description
        "MA name string.";
    }
  }

  grouping ma-name {
    description
      "MA name.";
    leaf ma-name-format {
      type identityref {
        base name-format;
      }
      description
        "MA name format.";
    }
    choice ma-name {
      case ma-name-null {
        leaf ma-name-null {
          when "derived-from-or-self(../ma-name-format, "
          +"'name-format-null')"
             + "'name-format-null')" {
            description
              "MA.";
          }
          type empty;
          description
            "Empty";
        }
      }
      description
        "MA name.";
    }
  }

  grouping mep-id {
    choice mep-id {
      default "mep-id-int";
      case mep-id-int {
        leaf mep-id-int {
          type int32;
          description
            "MEP ID
             in integer format.";
        }
      }
      description
        "MEP ID.";
    }
    leaf mep-id-format {
      type identityref {
        base identifier-format;
      }
      description
        "MEP ID format.";
    }
    description
      "MEP ID.";
  }

  grouping mep {
    description
      "Defines elements within the MEP.";
    leaf mep-name {
      type mep-name;
      mandatory true;
      description
        "Generic administrative name of the
         MEP.";
    }
    uses mep-id;
    uses mep-address;
  }

  grouping monitor-stats {
    description
      "Grouping for monitoring statistics; this will be augmented
       by others who use this component.";
    choice monitor-stats {
      default "monitor-null";
      case monitor-null {
        description
          "This is a placeholder when
           no monitoring statistics are needed.";
        leaf monitor-null {
          type empty;
          description
            "There are no monitoring statistics to be defined.";
        }
      }
      description
        "Define the monitor stats.";
    }
  }

  grouping connectivity-context {
    description
      "Grouping defining the connectivity context for an MA,
       for example, an LSP for MPLS-TP.  This will be
       augmented by each protocol that uses this component.";
    choice connectivity-context {
      default "context-null";
      case context-null {
        description
          "This is a placeholder when no context is needed.";
        leaf context-null {
          type empty;
          description
            "There is no context to be defined.";
        }
      }
      description
        "Connectivity context.";
    }
  }

  grouping cos {
    description
      "Grouping for Priority used in transmitted packets,
       for example, in the CoS field in MPLS-TP.";
    leaf cos-id {
      type uint8;
      description
        "Class of Service (CoS) ID; this value is used to indicate
         Class of Service information .";
    }
  }

  grouping mip-grouping {
    uses mip-address;
    description
      "Grouping for MIP
       configuration.";
  }
  container domains {
    description
      "Contains configuration related data.  Within the
       container, there is a list of fault domains.  Each
       domain has a list of MAs.";
    list domain {
      key "technology md-name-string";
      description
        "Define a list of Domains within the
         ietf-connection-oriented-oam module.";
      uses maintenance-domain-id;
      uses md-name;
      leaf md-level {
        type md-level;
        description
          "Define the MD level.";
      }
      container mas {
        description
          "Contains configuration-related data.  Within the
           container, there is a list of MAs.  Each MA has a
           list of MEPs.";
        list ma {
          key "ma-name-string";
          uses ma-identifier;
          uses ma-name;
          uses connectivity-context;
          uses cos {
            description
              "Default class of service for this MA;
               it may be overridden for particular MEPs,
               sessions, or operations.";
          }
          leaf cc-enable {
            type boolean;
            description
              "Indicate whether the CC is enabled.";
          }
          list mep {
            key "mep-name";
            description
              "Contain a list of MEPs.";
            uses mep;
            uses cos;
            leaf cc-enable {
              type boolean;
              description
                "Indicate whether the CC is enabled.";
            }
            list session {
              key "session-cookie";
              description
                "Monitoring session to/from a particular remote MEP.
                 Depending on the protocol, this could represent
                 CC messages received from a single remote MEP (if the
                 protocol uses multicast CCs) or a target to which
                 unicast echo request CCs are sent and from which
                 responses are received (if the protocol uses a
                 unicast request/response mechanism).";
              leaf session-cookie {
                type uint32;
                description
                  "Cookie to identify different sessions, when there
                   are multiple remote MEPs or multiple sessions to
                   the same remote MEP.";
              }
              container destination-mep {
                uses mep-id;
                description
                  "Destination MEP.";
              }
              container destination-mep-address {
                uses mep-address;
                description
                  "Destination MEP Address.";
              }
              uses cos;
            }
          }
          list mip {
            if-feature "mip";
            key "name";
            leaf name {
              type string;
              description
                "Identifier of Maintenance Intermediate Point";
            }
            leaf interface {
              type if:interface-ref;
              description
                "Interface.";
            }
            uses mip-grouping;
            description
              "List for MIP.";
          }
          description
            "Maintenance Association list.";
        }
      }
    }
  }

  notification defect-condition-notification {
    description
      "When the defect condition is met, this notification is sent.";
    leaf technology {
      type identityref {
        base technology-types;
      }
      description
        "The technology.";
    }
    leaf md-name-string {
      type leafref {
        path "/domains/domain/md-name-string";
      }
      mandatory true;
      description
        "Indicate which MD the defect belongs to.";
    }
    leaf ma-name-string {
      type leafref {
        path "/domains/domain/mas/ma/ma-name-string";
      }
      mandatory true;
      description
        "Indicate which MA the defect is associated with.";
    }
    leaf mep-name {
      type leafref {
        path "/domains/domain/mas/ma/mep/mep-name";
      }
      description
        "Indicate which MEP is seeing the defect.";
    }
    leaf defect-type {
      type identityref {
        base defect-types;
      }
      description
        "The currently active defects on the specific MEP.";
    }
    container generating-mepid {
      uses mep-id;
      description
        "Indicate who is generating the defect (if known). If
         unknown, set it to 0.";
    }
    uses defect-message {
      description
        "Defect message to provide more details.";
    }
  }

  notification defect-cleared-notification {
    description
      "When the defect is cleared, this notification is sent.";
    leaf technology {
      type identityref {
        base technology-types;
      }
      description
        "The technology.";
    }
    leaf md-name-string {
      type leafref {
        path "/domains/domain/md-name-string";
      }
      mandatory true;
      description
        "Indicate which MD the defect belongs to";
    }
    leaf ma-name-string {
      type leafref {
        path "/domains/domain/mas/ma/ma-name-string";
      }
      mandatory true;
      description
        "Indicate which MA the defect is associated with.";
    }
    leaf mep-name {
      type leafref {
        path "/domains/domain/mas/ma/mep/mep-name";
      }
      description
        "Indicate which MEP is seeing the defect.";
    }
    leaf defect-type {
      type identityref {
        base defect-types;
      }
      description
        "The currently active defects on the specific MEP.";
    }
    container generating-mepid {
      uses mep-id;
      description
        "Indicate who is generating the defect (if known). If
         unknown, set it to 0.";
    }
    uses defect-message {
      description
        "Defect message to provide more details.";
    }
  }

  rpc continuity-check {
    if-feature "continuity-check";
    description
      "Generates Continuity Check as per Table 4 of RFC 7276.";
    input {
      leaf technology {
        type identityref {
          base technology-types;
        }
        description
          "The technology.";
      }
      leaf md-name-string {
        type leafref {
          path "/domains/domain/md-name-string";
        }
        mandatory true;
        description
          "Indicate which MD the defect belongs to.";
      }
      leaf md-level {
        type leafref {
          path "/domains/domain/md-level";
        }
        description
          "The Maintenance Domain Level.";
      }
      leaf ma-name-string {
        type leafref {
          path "/domains/domain/mas/ma/ma-name-string";
        }
        mandatory true;
        description
          "Indicate which MA the defect is associated with.";
      }
      uses cos;
      uses time-to-live;
      leaf sub-type {
        type identityref {
          base command-sub-type;
        }
        description
          "Defines different command types.";
      }
      leaf source-mep {
        type leafref {
          path "/domains/domain/mas/ma/mep/mep-name";
        }
        description
          "Source MEP.";
      }
      container destination-mep {
        uses mep-address;
        uses mep-id {
          description
            "Only applicable if the destination is a MEP.";
        }
        description
          "Destination MEP.";
      }
      leaf count {
        type uint32;
        default "3";
        description
          "Number of continuity-check messages to be sent.";
      }
      leaf cc-transmit-interval {
        type time-interval;
        description
          "Time interval between echo requests.";
      }
      leaf packet-size {
        type uint32 {
          range "64..10000";
        }
        description
          "Size of continuity-check packets, in octets.";
      }
    }
    output {
      uses monitor-stats {
        description
          "Stats of Continuity Check.";
      }
    }
  }

  rpc continuity-verification {
    if-feature "connectivity-verification";
    description
      "Generates Connectivity Verification as per Table 4 in RFC 7276.";
    input {
      leaf md-name-string {
        type leafref {
          path "/domains/domain/md-name-string";
        }
        mandatory true;
        description
          "Indicate which MD the defect belongs to.";
      }
      leaf md-level {
        type leafref {
          path "/domains/domain/md-level";
        }
        description
          "The Maintenance Domain Level.";
      }
      leaf ma-name-string {
        type leafref {
          path "/domains/domain/mas/ma/ma-name-string";
        }
        mandatory true;
        description
          "Indicate which MA the defect is associated with.";
      }
      uses cos;
      uses time-to-live;
      leaf sub-type {
        type identityref {
          base command-sub-type;
        }
        description
          "Defines different command types.";
      }
      leaf source-mep {
        type leafref {
          path "/domains/domain/mas/ma/mep/mep-name";
        }
        description
          "Source MEP.";
      }
      container destination-mep {
        uses mep-address;
        uses mep-id {
          description
            "Only applicable if the destination is a MEP.";
        }
        description
          "Destination MEP.";
      }
      leaf count {
        type uint32;
        default "3";
        description
          "Number of continuity-verification messages to be sent.";
      }
      leaf interval {
        type time-interval;
        description
          "Time interval between echo requests.";
      }
      leaf packet-size {
        type uint32 {
          range "64..10000";
        }
        description
          "Size of continuity-verification packets, in octets.";
      }
    }
    output {
      uses monitor-stats {
        description
          "Stats of Continuity Check.";
      }
    }
  }

  rpc traceroute {
    if-feature "traceroute";
    description
      "Generates Traceroute or Path Trace and returns response.
       References RFC 7276 for common Toolset name -- for
       MPLS-TP OAM, it's Route Tracing, and for TRILL OAM, it's
       Path Tracing tool.  Starts with TTL of one and increments
       by one at each hop until the destination is reached or TTL
       reaches max value.";
    input {
      leaf md-name-string {
        type leafref {
          path "/domains/domain/md-name-string";
        }
        mandatory true;
        description
          "Indicate which MD the defect belongs to.";
      }
      leaf md-level {
        type leafref {
          path "/domains/domain/md-level";
        }
        description
          "The Maintenance Domain Level.";
      }
      leaf ma-name-string {
        type leafref {
          path "/domains/domain/mas/ma/ma-name-string";
        }
        mandatory true;
        description
          "Indicate which MA the defect is associated with.";
      }
      uses cos;
      uses time-to-live;
      leaf command-sub-type {
        type identityref {
          base command-sub-type;
        }
        description
          "Defines different command types.";
      }
      leaf source-mep {
        type leafref {
          path "/domains/domain/mas/ma/mep/mep-name";
        }
        description
          "Source MEP.";
      }
      container destination-mep {
        uses mep-address;
        uses mep-id {
          description
            "Only applicable if the destination is a MEP.";
        }
        description
          "Destination MEP.";
      }
      leaf count {
        type uint32;
        default "1";
        description
          "Number of traceroute probes to send.  In protocols where a
           separate message is sent at each TTL, this is the number
           of packets to be sent at each TTL.";
      }
      leaf interval {
        type time-interval;
        description
          "Time interval between echo requests.";
      }
    }
    output {
      list response {
        key "response-index";
        leaf response-index {
          type uint8;
          description
            "Arbitrary index for the response.  In protocols that
             guarantee there is only a single response at each TTL,
             the TTL can be used as the response index.";
        }
        uses time-to-live;
        container destination-mep {
          description
            "MEP from which the response has been received";
          uses mep-address;
          uses mep-id {
            description
              "Only applicable if the destination is a MEP.";
          }
        }
        container mip {
          if-feature "mip";
          leaf interface {
            type if:interface-ref;
            description
              "MIP interface.";
          }
          uses mip-address;
          description
            "MIP responding with traceroute";
        }
        uses monitor-stats {
          description
            "Stats of traceroute.";
        }
        description
          "List of responses.";
      }
    }
  }
}

mirror server hosted at Truenetwork, Russian Federation.