module org-openroadm-otn-odu-interfaces {
  namespace "http://org/openroadm/otn-odu-interfaces";
  prefix org-openroadm-otn-odu-interfaces;

  import org-openroadm-device {
    prefix org-openroadm-device;
    revision-date 2018-10-19;
  }
  import org-openroadm-interfaces {
    prefix openROADM-if;
    revision-date 2017-06-26;
  }
  import org-openroadm-maintenance-testsignal {
    prefix org-openroadm-maint-testsignal;
    revision-date 2017-12-15;
  }
  import org-openroadm-otn-common {
    prefix org-openroadm-otn-common;
    revision-date 2017-06-26;
  }
  import org-openroadm-otn-common-types {
    prefix org-openroadm-otn-common-types;
    revision-date 2017-12-15;
  }

  organization
    "Open ROADM MSA";
  contact
    "OpenROADM.org";
  description
    "YANG definitions for device facility otnodu interfaces.
     
     Copyright of the Members of the Open ROADM MSA Agreement dated (c) 2016, 
     AT&T Intellectual Property.  All other rights reserved.
     
     Redistribution and use in source and binary forms, with or without modification, 
     are permitted provided that the following conditions are met:
     
     * Redistributions of source code must retain the above copyright notice, this 
       list of conditions and the following disclaimer.
     * Redistributions in binary form must reproduce the above copyright notice, 
       this list of conditions and the following disclaimer in the documentation and/or 
       other materials provided with the distribution.
     * Neither the Members of the Open ROADM MSA Agreement nor the names of its 
       contributors may be used to endorse or promote products derived from this software 
       without specific prior written permission.
     
     THIS SOFTWARE IS PROVIDED BY THE MEMBERS OF THE OPEN ROADM MSA  AGREEMENT ''AS IS'' 
     AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
     WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
     IN NO EVENT THE MEMBERS OF THE OPEN ROADM MSA  AGREEMENT BE LIABLE FOR ANY DIRECT, 
     INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;  LOSS OF USE, DATA, 
     OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
     WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
     ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
     POSSIBILITY OF SUCH DAMAGE.
     
     Also contains code components extracted from IETF Interfaces.  These code components
     are copyrighted and licensed as follows:
     
     Copyright (c) 2016 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.";

  revision 2018-10-19 {
    description
      "Version 2.2.1";
  }
  revision 2017-12-15 {
    description
      "Version 2.2";
  }
  revision 2017-09-29 {
    description
      "Version 2.1";
  }
  revision 2017-07-28 {
    description
      "Version 2.0.1 - added revision-date to imports";
  }
  revision 2017-06-26 {
    description
      "Version 2.0";
  }
  revision 2016-10-14 {
    description
      "Version 1.2";
  }

  grouping msi-entry {
    leaf trib-slot {
      type uint16;
      description
        "tributary slot (TS)";
    }
    leaf odtu-type {
      type identityref {
        base org-openroadm-otn-common-types:odtu-type-identity;
      }
      description
        "ODTU type, part of the MSI (Multiplex Structure Identifier)";
    }
    leaf trib-port {
      type uint16;
      description
        "Tributary Port Number (0-based), part of the MSI";
    }
    leaf trib-port-payload {
      type string;
      description
        "interface name being mapped to trib-port";
    }
  }

  grouping odu-attributes {
    description
      "ODU attributes";
    leaf rate {
      type identityref {
        base org-openroadm-otn-common-types:odu-rate-identity;
      }
      description
        "rate identity of the ODU. 'identityref' is used
         to allow to extend for future higher rates";
    }
    leaf odu-function {
      type identityref {
        base org-openroadm-otn-common-types:odu-function-identity;
      }
      description
        "function of the ODU interface";
    }
    leaf monitoring-mode {
      type enumeration {
        enum "not-terminated" {
          description
            "Not Terminated: no detection or generation.
             Overhead is passed through the interface transparently in receive direction";
        }
        enum "terminated" {
          description
            "Terminated: detection and generation enabled.
             Overhead is erased (replaced with all zeros) in receive direction";
        }
        enum "monitored" {
          description
            "Monitored: detection enabled.
             Overhead is passed through the interface transparently in receive direction";
        }
      }
      description
        "Monitoring mode of the ODU Overhead";
    }
    leaf no-oam-function {
      type empty;
      description
        "No OAM functionality exists for this ODU interface, the entity exists in software only. This entity does not report alarms or PM and does not support TCM, TTI, delay measurement, loopbacks, test signal and other hardware-based functions. This is an optional parameter, only needs to be present when no-oam-function supported for this interface.";
    }
    leaf proactive-delay-measurement-enabled {
      type boolean;
      description
        "enable/disable proactive Delay Measurement";
    }
    uses parent-odu-allocation;
    uses org-openroadm-otn-common:trail-trace;
    uses org-openroadm-otn-common:deg-threshold;
    list tcm {
      key "layer tcm-direction";
      max-elements "6";
      description
        "Tandem Connection Management";
      uses tcm-attributes;
    }
    uses opu;
  }

  grouping parent-odu-allocation {
    container parent-odu-allocation {
      when "/org-openroadm-device:org-openroadm-device/org-openroadm-device:interface[org-openroadm-device:name = current()/../../org-openroadm-device:supporting-interface]/org-openroadm-device:type = 'openROADM-if:otnOdu'";
      presence "Explicit assignment of parent ODU trib-slot and trib-port allocation. ";
      leaf trib-port-number {
        type uint16 {
          range "1 .. 80";
        }
        mandatory true;
        description
          "Assigned tributary port number in parent OPU";
      }
      leaf-list trib-slots {
        type uint16 {
          range "1 .. 80";
        }
        min-elements 1;
        max-elements "80";
        description
          "Assigned trib slots occupied in parent OPU MSI";
      }
    }
  }

  grouping opu {
    container opu {
      when "../monitoring-mode = 'terminated' or ../monitoring-mode = 'monitored'";
      description
        "Optical Channel Payload Unit (OPU)";
      leaf payload-type {
        type org-openroadm-otn-common-types:payload-type-def;
        description
          "Payload Type";
      }
      leaf rx-payload-type {
        type org-openroadm-otn-common-types:payload-type-def;
        description
          "Received Payload Type";
      }
      leaf exp-payload-type {
        type org-openroadm-otn-common-types:payload-type-def;
        description
          "Expected Payload Type";
      }
      leaf payload-interface {
        type string;
        description
          "Expected Payload of OPU. It designates client interface name";
      }
      container msi {
        when "../payload-type = '20' or ../payload-type = '21'";
        list tx-msi {
          key "trib-slot";
          description
            "Transmit MSI";
          uses msi-entry;
        }
        list rx-msi {
          key "trib-slot";
          description
            "Receive MSI";
          uses msi-entry;
        }
        list exp-msi {
          key "trib-slot";
          description
            "Expected MSI";
          uses msi-entry;
        }
      }
    }
  }

  grouping tcm-attributes {
    description
      "Tandem Connection Monitoring (TCM) attributes";
    leaf layer {
      type uint8 {
        range "1..6";
      }
      description
        "TCM layer";
    }
    leaf monitoring-mode {
      type enumeration {
        enum "not-terminated" {
          description
            "Not Terminated: no detection or generation.
             Overhead is passed through the interface transparently in receive direction 
             unless extension is set for erase";
        }
        enum "terminated" {
          description
            "Terminated: detection and generation enabled.
             Overhead is erased (replaced with all zeros) in receive direction, unless
             extension is set to passthrough";
        }
        enum "monitored" {
          description
            "Monitored: detection enabled.
             Overhead is passed through the interface transparently in receive direction 
             unless extension is set for erase";
        }
      }
      description
        "Monitoring mode of the TCM layer";
    }
    leaf ltc-act-enabled {
      type boolean;
      description
        "enable/disable alarm transfer on detection of Loss of Tandem Connection (LTC)";
    }
    leaf proactive-delay-measurement-enabled {
      type boolean;
      description
        "enable/disable proactive Delay Measurement for TCM";
    }
    leaf tcm-direction {
      type enumeration {
        enum "up-tcm" {
          description
            "TCM termination direction faces the switch fabric.";
        }
        enum "down-tcm" {
          description
            "TCM termination direction faces the facility";
        }
      }
      description
        "Direction of TCM.";
    }
    uses org-openroadm-otn-common:trail-trace;
    uses org-openroadm-otn-common:deg-threshold;
  }

  grouping odu-container {
    container odu {
      presence "Attribute Nodes for Optical Data Unit (ODU)";
      description
        "Optical Channel Data Unit (ODU)";
      uses odu-attributes {
        refine "opu/rx-payload-type" {
          config false;
        }
        refine "opu/msi" {
          config false;
        }
        refine "no-oam-function" {
          config false;
        }
      }
      uses org-openroadm-maint-testsignal:maint-testsignal;
    }
  }

  augment "/org-openroadm-device:org-openroadm-device/org-openroadm-device:interface" {
    when "org-openroadm-device:type = 'openROADM-if:otnOdu'";
    uses odu-container;
  }
}
