module org-openroadm-device {
  namespace "http://org/openroadm/device";
  prefix org-openroadm-device;

  import ietf-yang-types {
    prefix ietf-yang-types;
    revision-date 2013-07-15;
  }
  import ietf-inet-types {
    prefix ietf-inet-types;
    revision-date 2013-07-15;
  }
  import ietf-netconf {
    prefix ietf-nc;
    revision-date 2011-06-01;
  }
  import org-openroadm-common-types {
    prefix org-openroadm-common-types;
    revision-date 2018-10-19;
  }
  import org-openroadm-resource-types {
    prefix org-openroadm-resource-types;
    revision-date 2018-10-19;
  }
  import org-openroadm-physical-types {
    prefix org-openroadm-physical-types;
    revision-date 2018-10-19;
  }
  import org-openroadm-user-mgmt {
    prefix org-openroadm-user-mgmt;
    revision-date 2017-12-15;
  }
  import org-openroadm-port-types {
    prefix org-openroadm-port-types;
    revision-date 2018-10-19;
  }
  import org-openroadm-interfaces {
    prefix org-openroadm-interfaces;
    revision-date 2017-06-26;
  }
  import org-openroadm-swdl {
    prefix org-openroadm-swdl;
    revision-date 2018-10-19;
  }
  import org-openroadm-equipment-states-types {
    prefix org-openroadm-equipment-states-types;
    revision-date 2017-12-15;
  }
  import org-openroadm-switching-pool-types {
    prefix org-openroadm-switching-pool-types;
    revision-date 2017-12-15;
  }

  organization
    "Open ROADM MSA";
  contact
    "OpenROADM.org";
  description
    "YANG definitions of ROADM device
     
     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 netconf.  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 2017-02-06 {
    description
      "Version 1.2.1 - removed pattern for current-datetime in info tree and rpc";
  }
  revision 2016-10-14 {
    description
      "Version 1.2";
  }

  grouping create-tech-info-group {
    leaf shelf-id {
      type leafref {
        path "/org-openroadm-device/shelves/shelf-name";
      }
      description
        "shelf ID";
    }
    leaf log-file-name {
      type string;
      description
        "The log file name a vendor can specify for a given log collection operation";
    }
  }

  grouping device-common {
    leaf node-id {
      type org-openroadm-common-types:node-id-type;
      default "openroadm";
      description
        "Globally unique identifier for a device.";
    }
    leaf node-number {
      type uint32;
      description
        "Number assigned to a ROADM node at a 
         given office";
    }
    leaf node-type {
      type org-openroadm-common-types:node-types;
      config true;
      mandatory true;
      description
        "Identifier for node-type e.g Roadm, xponder.
         Once the node-type is configured, it should not be modified.";
    }
    leaf clli {
      type string;
      description
        "Common Language Location Identifier.";
    }
    uses org-openroadm-physical-types:node-info;
    leaf ipAddress {
      type ietf-inet-types:ip-address;
      description
        "IP Address of device";
    }
    leaf prefix-length {
      type uint8 {
        range "0..128";
      }
      description
        "The length of the subnet prefix";
    }
    leaf defaultGateway {
      type ietf-inet-types:ip-address;
      description
        "Default Gateway";
    }
    leaf source {
      type enumeration {
        enum "static" {
          value 1;
        }
        enum "dhcp" {
          value 2;
        }
      }
      config false;
    }
    leaf current-ipAddress {
      type ietf-inet-types:ip-address;
      config false;
      description
        "Current IP Address of device";
    }
    leaf current-prefix-length {
      type uint8 {
        range "0..128";
      }
      config false;
      description
        "The current length of the subnet prefix";
    }
    leaf current-defaultGateway {
      type ietf-inet-types:ip-address;
      config false;
      description
        "Current Default Gateway";
    }
    leaf macAddress {
      type ietf-yang-types:mac-address;
      config false;
      description
        "MAC Address of device";
    }
    leaf softwareVersion {
      type string;
      config false;
      description
        "Software version";
    }
    leaf openroadm-version {
      type org-openroadm-common-types:openroadm-version-type;
      config false;
      description
        "openroadm version used on the device";
    }
    leaf template {
      type string;
      description
        "Template information used in the deployment.";
    }
    leaf current-datetime {
      type ietf-yang-types:date-and-time;
      config false;
      description
        "The current system date and time in UTC. Format: YYYY-MM-DDTHH:MM:SS.mm+ ";
    }
    container geoLocation {
      description
        "GPS location";
      leaf latitude {
        type decimal64 {
          fraction-digits 16;
          range "-90 .. 90";
        }
        description
          "[From wikipedia] Latitude is an angle (defined below)
           which ranges from 0 at the Equator to 90 (North or
           South) at the poles";
      }
      leaf longitude {
        type decimal64 {
          fraction-digits 16;
          range "-180 .. 180";
        }
        description
          "[From wikipedia] The longitude is measured as the
           angle east or west from the Prime Meridian, ranging
           from 0 at the Prime Meridian to +180 eastward and
           -180 westward.";
      }
    }
  }

  grouping slot-info {
    description
      "slots information. To be populated by NE during retrieval.";
    leaf slot-name {
      type string;
      description
        "The name of this slot.";
    }
    leaf label {
      type string;
      description
        "Faceplate label";
    }
    leaf provisioned-circuit-pack {
      type leafref {
        path "/org-openroadm-device/circuit-packs/circuit-pack-name";
      }
      description
        "The supported circuit-pack. It will be empty if holder status is empty-not-prov, or installed-not-prov";
    }
    leaf slot-status {
      type enumeration {
        enum "empty-not-prov" {
          value 1;
          description
            "Slot is empty and not provisioned";
        }
        enum "empty-prov-match" {
          value 2;
          description
            "Slot is empty and expected type is provisioned";
        }
        enum "empty-prov-mismatch" {
          value 3;
          description
            "Slot is empty and an unsupported type is provisioned";
        }
        enum "installed-not-prov" {
          value 4;
          description
            "Slot is occupied but not provisioned";
        }
        enum "installed-prov-match" {
          value 5;
          description
            "Slot is occupied with matching provisioned type";
        }
        enum "installed-prov-mismatch" {
          value 6;
          description
            "Slot is occupied with mismatched provisioned type";
        }
      }
    }
  }

  grouping shelves {
    list shelves {
      key "shelf-name";
      uses shelf;
    }
  }

  grouping shelf {
    leaf shelf-name {
      type string;
      description
        "Unique identifier for this shelf within a device";
    }
    leaf shelf-type {
      type string;
      mandatory true;
      description
        "The shelf type: describe the shelf with a unique string.";
    }
    leaf rack {
      type string;
      description
        "Reflect the shelf physical location data including floor, aisle, bay values.";
    }
    leaf shelf-position {
      type string;
      description
        "Reflect the shelf vertical position within an equipment bay.";
    }
    leaf administrative-state {
      type org-openroadm-equipment-states-types:admin-states;
      description
        "Admin State of the shelf";
    }
    uses org-openroadm-physical-types:common-info;
    leaf equipment-state {
      type org-openroadm-equipment-states-types:states;
      description
        "equipment state for the shelf, used to track the lifecycle state.";
    }
    leaf due-date {
      type ietf-yang-types:date-and-time;
      description
        "due date for the shelf.";
    }
    list slots {
      key "slot-name";
      config false;
      description
        "List of slots on this shelf. To be populated by NE during retrieval.";
      uses slot-info;
    }
  }

  grouping circuit-packs {
    list circuit-packs {
      key "circuit-pack-name";
      description
        "List of circuit packs. This includes common equipment, like fans, power supplies, etc.";
      leaf circuit-pack-type {
        type string;
        mandatory true;
        description
          "Type of circuit-pack";
      }
      leaf circuit-pack-product-code {
        type string;
        description
          "Product Code for the circuit-pack";
      }
      uses circuit-pack;
    }
  }

  grouping circuit-pack-features {
    leaf software-load-version {
      type string;
      config false;
      description
        "Software version running on the circuit pack.";
    }
    list circuit-pack-features {
      config false;
      container feature {
        description
          "List of features supported by the installed load and indications on whether the features have been applied or not.";
        leaf description {
          type string;
          description
            "Feature description.";
        }
        leaf activated {
          type boolean;
          description
            "Indicator if the feature has been activated.";
        }
      }
    }
    list circuit-pack-components {
      config false;
      container component {
        description
          "Optional list of components on the circuit-pack and the load information applicable to those components.  If a load is not up to date and will upgrade when a cold restart occurs, the version that will be applied should also be listed.  If there is no misalignment, this does not need to be reported.";
        leaf name {
          type string;
          description
            "Name of a component on the circuit-pack that can have a load applied to it.";
        }
        leaf current-version {
          type string;
          description
            "Name of the load version currently running on the component.";
        }
        leaf version-to-apply {
          type string;
          description
            "Name of the load version for the component that will be applied when cold restart occurs on the circuit-pack.";
        }
      }
    }
  }

  grouping circuit-pack {
    leaf circuit-pack-name {
      type string;
      description
        "Unique identifier for this circuit-pack within a device";
    }
    leaf administrative-state {
      type org-openroadm-equipment-states-types:admin-states;
      description
        "Administrative state of circuit-pack";
    }
    uses org-openroadm-physical-types:common-info;
    container circuit-pack-category {
      config false;
      description
        "General type of circuit-pack";
      uses org-openroadm-common-types:equipment-type;
    }
    leaf equipment-state {
      type org-openroadm-equipment-states-types:states;
      description
        "Equipment state, which complements operational state.";
    }
    leaf circuit-pack-mode {
      type string;
      default "NORMAL";
      description
        "Circuit-pack mode allowed. e.g. NORMAL or REGEN";
    }
    leaf shelf {
      type leafref {
        path "/org-openroadm-device/shelves/shelf-name";
      }
      mandatory true;
    }
    leaf slot {
      type string;
      mandatory true;
    }
    leaf subSlot {
      type string;
      mandatory false;
    }
    leaf is-pluggable-optics {
      type boolean;
      config false;
      mandatory true;
      description
        "True if circuitpack is pluggable optics";
    }
    leaf due-date {
      type ietf-yang-types:date-and-time;
      description
        "due date for this circuit-pack.";
    }
    container parent-circuit-pack {
      description
        "In the case of circuit packs that contain other equipment (modules or pluggables), this captures the hierarchy of that equipment.  It is a vendor specific design decision if the ports for single-port pluggables are modeled as children of the parent circuit-pack, or as children of the pluggable circuit-pack contained in the parent circuit-pack.  For modules with multiple ports, it is recommended that ports be children of the module and not the carrier, to help in fault correlation and isolation in the case of a module failure.";
      uses circuit-pack-name;
      leaf cp-slot-name {
        type string;
        description
          "Slot name on parent-circuit-pack.";
      }
    }
    list cp-slots {
      key "slot-name";
      config false;
      description
        "List of circuit-pack slots on this circuit-pack. To be populated by NE during retrieval.";
      uses slot-info;
      leaf slot-type {
        type enumeration {
          enum "pluggable-optics-holder" {
            value 1;
            description
              "slot accepts dedicated pluggable port circuit-pack";
          }
          enum "other" {
            value 2;
            description
              "slot accepts parent circuit-pack";
          }
        }
      }
    }
    uses circuit-pack-features;
    list ports {
      key "port-name";
      description
        "List of ports on this circuit-pack. Note that pluggables are considered independent circuit-packs.  All ports that are physically present on a pluggable, need to be modeled as a port against that pluggable circuit-pack, and not against the parent circuit-pack.";
      uses port;
      container roadm-port {
        when "../port-qual='roadm-external'";
        uses org-openroadm-port-types:roadm-port;
      }
      container transponder-port {
        when "../port-qual='xpdr-network' or ../port-qual='xpdr-client' or ../port-qual='switch-network' or ../port-qual='switch-client'";
        uses org-openroadm-port-types:common-port;
      }
      container otdr-port {
        when "../port-qual='otdr'";
        description
          "Settings for otdr port.";
        leaf launch-cable-length {
          type uint32;
          units "m";
          default "30";
        }
        leaf port-direction {
          type org-openroadm-common-types:direction;
        }
      }
      container ila-port {
        when "../port-qual='ila-external'";
        uses org-openroadm-port-types:common-port;
      }
    }
  }

  grouping odu-connection {
    description
      "Grouping used to define odu-connections.";
    leaf connection-name {
      type string;
      description
        "roadm-connection and odu-connection share the same resource-type and resource definition (e.g. connection)";
    }
    leaf direction {
      type enumeration {
        enum "unidirectional" {
          value 1;
        }
        enum "bidirectional" {
          value 2;
        }
      }
      default "bidirectional";
      description
        "Directionality of connection. If bidirectional, both directions are created.";
    }
    container source {
      leaf src-if {
        type leafref {
          path "/org-openroadm-device/interface/name";
        }
        mandatory true;
      }
    }
    container destination {
      leaf dst-if {
        type leafref {
          path "/org-openroadm-device/interface/name";
        }
        mandatory true;
      }
    }
  }

  grouping connection {
    description
      "Grouping used to define connections.";
    leaf connection-name {
      type string;
    }
    leaf opticalControlMode {
      type org-openroadm-common-types:optical-control-mode;
      default "off";
      description
        "Whether connection is currently in power or gain/loss mode";
      reference "openroadm.org: Open ROADM MSA Specification.";
    }
    leaf target-output-power {
      type org-openroadm-common-types:power-dBm;
      description
        "The output target power for this connection. When set, the ROADM will work to ensure that current-output-power reaches this level.";
    }
    container source {
      leaf src-if {
        type leafref {
          path "/org-openroadm-device/interface/name";
        }
        mandatory true;
      }
    }
    container destination {
      leaf dst-if {
        type leafref {
          path "/org-openroadm-device/interface/name";
        }
        mandatory true;
      }
    }
  }

  grouping degree {
    leaf degree-number {
      type uint16;
      must "not( current() > /org-openroadm-device/info/max-degrees) and current() > 0" {
        error-message "Degree not supported by device ";
        description
          "Validating if the degree is supported by device";
      }
    }
    leaf max-wavelengths {
      type uint16;
      config false;
      mandatory true;
      description
        "maximum number of wavelengths";
    }
    list circuit-packs {
      key "index";
      description
        "list for Cards associated with a degree";
      leaf index {
        type uint32;
      }
      uses circuit-pack-name {
        refine "circuit-pack-name" {
          mandatory true;
        }
      }
    }
    list connection-ports {
      key "index";
      description
        "Port associated with degree: One if bi-directional; two if uni-directional";
      leaf index {
        type uint32;
      }
      uses port-name {
        refine "circuit-pack-name" {
          mandatory true;
        }
        refine "port-name" {
          mandatory true;
        }
      }
    }
    container otdr-port {
      description
        "otdr port associated with degree.";
      uses port-name;
    }
    uses mc-capabilities-g;
  }

  grouping amplifier {
    leaf amp-number {
      type uint8 {
        range "1..128";
      }
      description
        "Unique identifier/number for the amplifier entry which corresponds to a logical amplifier";
    }
    leaf amp-type {
      type org-openroadm-common-types:amplifier-types;
      config false;
      mandatory true;
      description
        "Amplifier type";
    }
    leaf control-mode {
      type org-openroadm-common-types:line-amplifier-control-mode;
      default "off";
      description
        "Whether the line amplifier is currently in off or gainLoss mode. control-mode can only be set to gainLoss when target-gain, target-tilt and egress-average-channel-power are set and the OMS interfaces are provisioned. The amplifier will be turned off when the control-mode is set to off";
    }
    leaf amp-gain-range {
      type org-openroadm-common-types:amplifier-gain-range;
      default "gain-range-1";
      config false;
      description
        "Amplifier gain-range (gain-range 1 to 4 for switched gain amplifiers)
         gain-range-1 (default value) for standard amplifiers";
    }
    leaf target-gain {
      type org-openroadm-common-types:ratio-dB;
      config true;
      description
        "Target overall Amplifier Signal gain, excluding ASE, including VOA attenuation.
         Defined as optional for ODL support, but shall be considered as mandatory and provided
         by the controller when the control-mode is set to gainLoss for amplifier setting";
    }
    leaf target-tilt {
      type org-openroadm-common-types:ratio-dB;
      config true;
      description
        "Target tilt configured in case of smart EDFA.
         Tilt value provided as specified in Open-ROADM-MSA-specifications spreadsheet
         Defined as optional for ODL support, but shall be considered as mandatory and provided
         by the controller when the control-mode is set to gainLoss for amplifier setting";
    }
    leaf egress-average-channel-power {
      type org-openroadm-common-types:power-dBm;
      config true;
      description
        "Based upon the total max power across the 4.8 THz passband.
         Defined as optional for ODL support, but shall be considered as mandatory and provided
         by the controller when the control-mode is set to gainLoss for amplifier setting";
    }
    leaf out-voa-att {
      type org-openroadm-common-types:ratio-dB;
      config false;
      description
        "Used to provide the value output VOA attenuation, optional";
    }
    leaf partner-amp {
      type leafref {
        path "../amp-number";
      }
      config false;
      description
        "amp-number of amp module that is functionally associated to the amplifier  
         in the opposite direction";
    }
    leaf ila-direction-label {
      type string;
      description
        "Amplifier direction. Each operators may have its own naming convention.
         Shall be consistent with tx-instance-port-direction-label and rx-instance-port-direction-label.";
    }
  }

  grouping external-links {
    description
      "YANG definitions for external links.. 
       - physical links between ROADMs and between the ROADMs and XPonders, which can be added and removed manually.";
    list external-link {
      key "external-link-name";
      uses external-link;
    }
  }

  grouping external-link {
    leaf external-link-name {
      type string;
    }
    container source {
      uses org-openroadm-resource-types:device-id {
        refine "node-id" {
          mandatory true;
        }
      }
      uses org-openroadm-resource-types:port-name {
        refine "circuit-pack-name" {
          mandatory true;
        }
        refine "port-name" {
          mandatory true;
        }
      }
    }
    container destination {
      uses org-openroadm-resource-types:device-id {
        refine "node-id" {
          mandatory true;
        }
      }
      uses org-openroadm-resource-types:port-name {
        refine "circuit-pack-name" {
          mandatory true;
        }
        refine "port-name" {
          mandatory true;
        }
      }
    }
  }

  grouping internal-links {
    list internal-link {
      key "internal-link-name";
      config false;
      uses internal-link;
    }
  }

  grouping internal-link {
    leaf internal-link-name {
      type string;
    }
    container source {
      uses port-name {
        refine "circuit-pack-name" {
          mandatory true;
        }
        refine "port-name" {
          mandatory true;
        }
      }
    }
    container destination {
      uses port-name {
        refine "circuit-pack-name" {
          mandatory true;
        }
        refine "port-name" {
          mandatory true;
        }
      }
    }
  }

  grouping physical-links {
    description
      "YANG definitions for physical links.
       - physical links (fiber, cables,etc.) between ports within a node. ";
    list physical-link {
      key "physical-link-name";
      uses physical-link;
    }
  }

  grouping physical-link {
    leaf physical-link-name {
      type string;
    }
    container source {
      uses port-name {
        refine "circuit-pack-name" {
          mandatory true;
        }
        refine "port-name" {
          mandatory true;
        }
      }
    }
    container destination {
      uses port-name {
        refine "circuit-pack-name" {
          mandatory true;
        }
        refine "port-name" {
          mandatory true;
        }
      }
    }
  }

  grouping srg {
    leaf max-add-drop-ports {
      type uint16;
      config false;
      mandatory true;
      description
        "The max number of ports available for a given srg";
    }
    leaf current-provisioned-add-drop-ports {
      type uint16;
      config false;
      mandatory true;
      description
        "The number of ports currently provisioned for a given srg.";
    }
    leaf srg-number {
      type uint16;
      must "not(current()>/org-openroadm-device/info/max-srgs) and current()>0" {
        error-message "invalid SRG";
        description
          "Validating if the srg is supported by add/drop group";
      }
    }
    leaf wavelength-duplication {
      type org-openroadm-common-types:wavelength-duplication-type;
      config false;
      mandatory true;
      description
        "Whether the SRG can handle duplicate wavelengths and if so to what extent.";
    }
    list circuit-packs {
      key "index";
      description
        "list for Cards associated with an add/drop group and srg";
      leaf index {
        type uint32;
      }
      uses circuit-pack-name {
        refine "circuit-pack-name" {
          mandatory true;
        }
      }
    }
    uses mc-capabilities-g;
  }

  grouping xponder {
    leaf xpdr-number {
      type uint16;
      must "current() > 0" {
        error-message "Xponder not supported by device ";
        description
          "Validating if the Xponder is supported by device";
      }
    }
    leaf xpdr-type {
      type org-openroadm-common-types:xpdr-node-types;
      mandatory true;
      description
        "Identifier for xponder-type e.g Transponder, Muxponder";
    }
    leaf recolor {
      type boolean;
      config false;
      description
        "Indication if recolor is supported";
    }
    list xpdr-port {
      key "index";
      description
        "Network Ports with in a Xponder";
      leaf index {
        type uint32;
      }
      uses port-name {
        refine "circuit-pack-name" {
          mandatory true;
        }
        refine "port-name" {
          mandatory true;
        }
      }
      leaf eqpt-srg-id {
        type uint32;
        description
          "Shared Risk Group identifier. All ports in a circuit-pack will have same srg-id";
      }
    }
  }

  grouping degree-number {
    leaf degree-number {
      type leafref {
        path "/org-openroadm-device:org-openroadm-device/org-openroadm-device:degree/org-openroadm-device:degree-number";
      }
      description
        "Degree identifier. Unique within the context of a device.";
    }
  }

  grouping circuit-pack-name {
    leaf circuit-pack-name {
      type leafref {
        path "/org-openroadm-device:org-openroadm-device/org-openroadm-device:circuit-packs/org-openroadm-device:circuit-pack-name";
      }
      description
        "Circuit-Pack identifier. Unique within the context of a device.";
    }
  }

  grouping port-name {
    uses circuit-pack-name;
    leaf port-name {
      type leafref {
        path "/org-openroadm-device:org-openroadm-device/org-openroadm-device:circuit-packs[circuit-pack-name=current()/../org-openroadm-device:circuit-pack-name]/org-openroadm-device:ports/org-openroadm-device:port-name";
      }
      description
        "Port identifier. Unique within the context of a circuit-pack.";
    }
  }

  grouping srg-number {
    leaf srg-number {
      type leafref {
        path "/org-openroadm-device/shared-risk-group/srg-number";
      }
      description
        "Shared Risk Group identifier. Unique within the context of a device.";
    }
  }

  grouping supporting-port-name {
    leaf supporting-circuit-pack-name {
      type leafref {
        path "/org-openroadm-device:org-openroadm-device/org-openroadm-device:circuit-packs/org-openroadm-device:circuit-pack-name";
      }
      description
        "Identifier of the supporting circuit-pack.";
    }
    leaf supporting-port {
      type leafref {
        path "/org-openroadm-device/circuit-packs[circuit-pack-name=current()/../supporting-circuit-pack-name]/ports/port-name";
      }
      description
        "Identifier of the supporting port.";
    }
  }

  grouping interface-name {
    leaf interface-name {
      type leafref {
        path "/org-openroadm-device/interface/name";
      }
      config false;
      description
        "Name of an interface. Unique within the context of a device.";
    }
  }

  grouping interfaces-grp {
    description
      "OpenROADM Interface configuration parameters.";
    list interface {
      key "name";
      description
        "The list of configured interfaces on the device.";
      leaf name {
        type string;
        description
          "The name of the interface.";
      }
      leaf description {
        type string;
        description
          "A textual description of the interface.";
      }
      leaf type {
        type identityref {
          base org-openroadm-interfaces:interface-type;
        }
        mandatory true;
        description
          "The type of the interface.";
      }
      leaf administrative-state {
        type org-openroadm-equipment-states-types:admin-states;
      }
      leaf operational-state {
        type org-openroadm-common-types:state;
        config false;
      }
      leaf circuit-id {
        type string {
          length "0..45";
        }
        description
          "circuit identifier/user label,
           can be used in alarm correlation and/or connection management ";
      }
      leaf supporting-interface {
        type leafref {
          path "/org-openroadm-device/interface/name";
        }
      }
      uses supporting-port-name;
    }
  }

  grouping protection-groups {
    description
      "OpenROADM facility protection configuration parameters.";
    container protection-grps {
      description
        "The list of configured protection groups on the device.";
    }
  }

  grouping port {
    description
      "Grouping of attributes related to a port object.";
    leaf port-name {
      type string;
      mandatory true;
      description
        "Identifier for a port, unique within a circuit pack";
    }
    leaf port-type {
      type string;
      description
        "Type of the pluggable or fixed port.";
    }
    leaf port-qual {
      type org-openroadm-common-types:port-qual;
    }
    leaf port-wavelength-type {
      type org-openroadm-port-types:port-wavelength-types;
      config false;
      description
        "Type of port - single, multiple-wavelength, etc.";
    }
    leaf port-direction {
      type org-openroadm-common-types:direction;
      config false;
      mandatory true;
      description
        "Whether port is uni (tx/rx) or bi-directional and";
    }
    leaf label {
      type string;
      config false;
      description
        "Faceplate label";
    }
    leaf circuit-id {
      type string {
        length "0..45";
      }
      description
        "circuit identifier/user label,
         can be used in alarm correlation and/or connection management ";
    }
    leaf administrative-state {
      type org-openroadm-equipment-states-types:admin-states;
      default "outOfService";
      description
        "Administrative state of port. The value of this field independent of the state of its contained and containing resources.  Setting this a port to administratively down will impact both its operational state, as well the operational state of its contained resources.  If this port is an endpoint to a connection, internal-link, physical-link, etc, then administratively disabling this port will impact the operational state of those items unless they are using some form of port-protection schema.";
    }
    leaf operational-state {
      type org-openroadm-common-types:state;
      config false;
      mandatory true;
      description
        "Operational state of a port";
    }
    leaf-list supported-interface-capability {
      type identityref {
        base org-openroadm-port-types:supported-if-capability;
      }
      config false;
      description
        "Interface types supported on this port";
    }
    leaf logical-connection-point {
      type string;
      description
        "delete or replace with list logical-ports or connections?";
    }
    container partner-port {
      config false;
      description
        "For ports which are not identified as having a direction of bidirectional, this field is used to identify the port which corresponds to the reverse direction. A port pair should include a port for each direction (tx, rx) and report their mate as partner-port.";
      uses port-name;
    }
    container parent-port {
      config false;
      description
        "In the case of port hierarchy, this is the parent port, which is also modeled as port within this circuit-pack. This is used in the case of a port that supports a parallel connector that contains subports.  The parent-port of the subport will be the port that contains this subport.  This can be used to help isolate faults when a single fault on a parallel connector introduces symptomatic failures on the contained subports.";
      uses port-name;
    }
    list interfaces {
      config false;
      description
        "List of the interfaces this port supports.  This is a list of names of instances in the flat instance list";
      uses interface-name;
    }
  }

  grouping org-openroadm-device-container {
    container org-openroadm-device {
      container info {
        uses device-common;
        leaf max-degrees {
          type uint16;
          config false;
          description
            "Max. number of degrees supported by device";
        }
        leaf max-srgs {
          type uint16;
          config false;
          description
            "Max. number of SRGs in an add/drop group";
        }
        leaf max-num-bin-15min-historical-pm {
          type uint16;
          config false;
          description
            "Max. number of bin the NE support for 15min historical PM";
        }
        leaf max-num-bin-24hour-historical-pm {
          type uint16;
          config false;
          description
            "Max. number of bin the NE support for 24hour historical PM";
        }
      }
      container users {
        description
          "Stores a list of users";
        uses org-openroadm-user-mgmt:user-profile;
      }
      container pending-sw {
        config false;
        uses org-openroadm-swdl:sw-bank;
      }
      uses shelves;
      uses circuit-packs;
      uses interfaces-grp;
      uses protection-groups;
      container protocols {
        description
          "Contains the supported protocols";
      }
      uses internal-links;
      uses physical-links;
      uses external-links;
      list degree {
        when "/org-openroadm-device/info/node-type='rdm'";
        key "degree-number";
        uses degree;
      }
      list shared-risk-group {
        when "/org-openroadm-device/info/node-type='rdm'";
        key "srg-number";
        uses srg;
      }
      list line-amplifier {
        when "/org-openroadm-device/info/node-type='ila'";
        key "amp-number";
        description
          "lists amplifiers in different directions";
        uses amplifier;
        list circuit-pack {
          key "index";
          description
            "list for Cards associated with an amplifier";
          leaf index {
            type uint32;
          }
          uses circuit-pack-name {
            refine "circuit-pack-name" {
              mandatory true;
            }
          }
        }
        list line-port {
          key "port-direction";
          description
            "Port associated with an amplifier which face the line (ila-external): traffic port.";
          leaf port-direction {
            type org-openroadm-common-types:direction;
            config true;
            mandatory true;
            description
              "partly allows identifying ports associated with logical amp :TX for egress, RX for ingress
               TXRX in case of bidirectional port";
          }
          leaf tx-instance-port-direction-label {
            type string;
            config true;
            description
              "Complements ports identification. Used notably in case of bidirectional ports, 
               and/or in multi-degree amplifier nodes. Allows associating one of the directions
               specified in ila-direction-label. Shall be consistent with ila-direction-label";
          }
          leaf rx-instance-port-direction-label {
            type string;
            config true;
            description
              "Complements ports identification. Used notably in case of bidirectional ports, 
               and/or in multi-degree amplifier nodes. Allows associating one of the directions
               specified in ila-direction-label. Shall be consistent with ila-direction-label";
          }
          uses port-name {
            refine "circuit-pack-name" {
              mandatory true;
            }
            refine "port-name" {
              mandatory true;
            }
          }
        }
        list osc-port {
          key "port-direction";
          description
            "Ports associated with OSC";
          leaf port-direction {
            type org-openroadm-common-types:direction;
            config true;
            mandatory true;
            description
              "allows identifying ports associated with logical amp : 
               TX for OSC circuit-pack IN RX for OSC circuit-pack OUT";
          }
          uses port-name {
            refine "circuit-pack-name" {
              mandatory true;
            }
            refine "port-name" {
              mandatory true;
            }
          }
        }
        list otdr-port {
          key "otdr-direction";
          description
            "otdr ports associated with an ILA";
          leaf otdr-direction {
            type string;
            config true;
            description
              "allows identifying associated logical amp port in which OTDR is launched: 
               corresponds to rx-instance-port-direction-label of corresponding amplifier line-port";
          }
          uses port-name {
            refine "circuit-pack-name" {
              mandatory true;
            }
            refine "port-name" {
              mandatory true;
            }
          }
        }
      }
      list xponder {
        when "/org-openroadm-device/info/node-type='xpdr'";
        key "xpdr-number";
        uses xponder;
      }
      list roadm-connections {
        when "/org-openroadm-device/info/node-type='rdm'";
        key "connection-name";
        uses connection;
      }
      list odu-connection {
        when "/org-openroadm-device/info/node-type='xpdr'";
        key "connection-name";
        uses odu-connection;
      }
      list connection-map {
        key "connection-map-number";
        config false;
        leaf connection-map-number {
          type uint32;
          description
            "Unique identifier for this connection-map entry";
        }
        container source {
          leaf circuit-pack-name {
            type leafref {
              path "/org-openroadm-device/circuit-packs/circuit-pack-name";
            }
            mandatory true;
          }
          leaf port-name {
            type leafref {
              path "/org-openroadm-device/circuit-packs[circuit-pack-name=current()/../circuit-pack-name]/ports/port-name";
            }
            mandatory true;
            description
              "Port identifier. Unique within the context of a circuit-pack.";
          }
        }
        list destination {
          key "circuit-pack-name port-name";
          min-elements 1;
          leaf circuit-pack-name {
            type leafref {
              path "/org-openroadm-device/circuit-packs/circuit-pack-name";
            }
            mandatory true;
          }
          leaf port-name {
            type leafref {
              path "/org-openroadm-device/circuit-packs[circuit-pack-name=current()/../circuit-pack-name]/ports/port-name";
            }
            mandatory true;
            description
              "Port identifier. Unique within the context of a circuit-pack.";
          }
        }
      }
      list odu-switching-pools {
        when "/org-openroadm-device/info/node-type='xpdr'";
        key "switching-pool-number";
        config false;
        leaf switching-pool-number {
          type uint16;
          description
            "Unique identifier for this odu-switching-pool";
        }
        leaf switching-pool-type {
          type org-openroadm-switching-pool-types:switching-pool-types;
        }
        list non-blocking-list {
          key "nbl-number";
          config false;
          description
            "List of ports in a non-blocking switch element";
          leaf nbl-number {
            type uint16;
            description
              "Identifier for this non-blocking-list. Unique within odu-switching-pool";
          }
          leaf interconnect-bandwidth-unit {
            type uint32;
            config false;
            description
              "Switch fabric interconnect bandwidth unit rate in bits per second. 
               Represents granularity of switch fabric";
          }
          leaf interconnect-bandwidth {
            type uint32;
            config false;
            description
              "Total interconnect bandwidth for a non-blocking element expressed as 
               number of inter-connect-bandwidth units";
          }
          list port-list {
            key "circuit-pack-name port-name";
            leaf circuit-pack-name {
              type leafref {
                path "/org-openroadm-device/circuit-packs/circuit-pack-name";
              }
              config false;
            }
            leaf port-name {
              type leafref {
                path "/org-openroadm-device/circuit-packs/ports/port-name";
              }
              config false;
              description
                "Port name. Unique within device";
            }
          }
          list pluggable-optics-holder-list {
            key "circuit-pack-name slot-name";
            leaf circuit-pack-name {
              type leafref {
                path "/org-openroadm-device/circuit-packs/circuit-pack-name";
              }
              config false;
              description
                "Name of parent circuit-pack";
            }
            leaf slot-name {
              type leafref {
                path "/org-openroadm-device/circuit-packs/cp-slots/slot-name";
              }
              config false;
              description
                "Name of pluggable-optics-holder";
            }
          }
        }
      }
    }
  }

  grouping mc-capabilities-g {
    container mc-capabilities {
      config false;
      description
        "Capabilities of the media channel on a degree or SRG.  This is used to validate mc-ttp provisioning on degrees and SRGs.";
      leaf slot-width-granularity {
        type org-openroadm-common-types:frequency-GHz;
        default "50";
        config false;
        description
          "Width of a slot measured in GHz.";
      }
      leaf center-freq-granularity {
        type org-openroadm-common-types:frequency-GHz;
        default "50";
        config false;
        description
          "Granularity of allowed center frequencies.  The base frequency for this computation is 193.1 THz (G.694.1)";
      }
      leaf min-slots {
        type uint32;
        default "1";
        config false;
        description
          "Minimum number of slots permitted to be joined together to form a media channel.  Must be less than or equal to the max-slots";
      }
      leaf max-slots {
        type uint32;
        default "1";
        config false;
        description
          "Maximum number of slots permitted to be joined together to form a media channel.  Must be greater than or equal to the min-slots";
      }
    }
  }

  grouping common-session-parms {
    description
      "Common session parameters to identify a
       management session.";
    leaf username {
      type org-openroadm-user-mgmt:username-type;
      mandatory true;
      description
        "Name of the user for the session.";
    }
    leaf session-id {
      type ietf-nc:session-id-or-zero-type;
      mandatory true;
      description
        "Identifier of the session.
         A NETCONF session MUST be identified by a non-zero value.
         A non-NETCONF session MAY be identified by the value zero.";
    }
    leaf source-host {
      type ietf-inet-types:ip-address;
      description
        "Address of the remote host for the session.";
    }
  }

  grouping changed-by-parms {
    description
      "Common parameters to identify the source
       of a change event, such as a configuration
       or capability change.";
    container changed-by {
      description
        "Indicates the source of the change.
         If caused by internal action, then the
         empty leaf 'server' will be present.
         If caused by a management session, then
         the name, remote host address, and session ID
         of the session that made the change will be reported.";
      choice server-or-user {
        leaf server {
          type empty;
          description
            "If present, the change was caused
             by the server.";
        }
        case by-user {
          uses common-session-parms;
        }
      }
    }
  }

  rpc led-control {
    description
      "This command is used to allow user to find an entity on the NE,
       The specified entity will have LED blinking.
       The equipmentLedOn alarm will be raised and cleared for the indication";
    input {
      choice equipment-entity {
        mandatory true;
        case shelf {
          leaf shelf-name {
            type leafref {
              path "/org-openroadm-device/shelves/shelf-name";
            }
            mandatory true;
            description
              "shelf-name for the operation";
          }
        }
        case circuit-pack {
          leaf circuit-pack-name {
            type leafref {
              path "/org-openroadm-device/circuit-packs/circuit-pack-name";
            }
            mandatory true;
            description
              "circuit-pack-name for the operation";
          }
        }
      }
      leaf enabled {
        type boolean;
        mandatory true;
        description
          "led-control enabled flag.
           when enabled=true,  equipmentLedOn alarm will be raised
           when enabled=false, equipmentLedOn alarm will be cleared";
      }
    }
    output {
      uses org-openroadm-common-types:rpc-response-status;
    }
  }
  rpc create-tech-info {
    description
      "Collects all log data for debugging and place it in a location accessible via ftp/sftp.
       This model assumes ASYNC operation, i.e. the command will return after the device accepts the command,
       A create-tech-info-notification will be send out later for the result of the operation.
       The log-file is cleared at the start of every create-tech-info operation in order to ensure 
       the up-to-date logs are collected. If a vendor does not support concurrent log collection, the second 
       create-tech-info command will be rejected.";
    input {
      leaf shelf-id {
        type leafref {
          path "/org-openroadm-device/shelves/shelf-name";
        }
        description
          "This optional field is used to specify the shelf for log collection. 
           When this filed is not provided, it is expected to collect logs for the whole node.
           Vendor should reject the command if the whole node log collection is not supported.";
      }
      leaf log-option {
        type string;
        description
          "The log type a vendor can specify. Maybe used in future";
      }
    }
    output {
      uses create-tech-info-group;
      uses org-openroadm-common-types:rpc-response-status;
    }
  }
  rpc get-connection-port-trail {
    input {
      leaf connection-name {
        type string;
        mandatory true;
      }
    }
    output {
      uses org-openroadm-common-types:rpc-response-status;
      list ports {
        uses org-openroadm-common-types:physical-location;
        uses port-name {
          refine "circuit-pack-name" {
            mandatory true;
          }
          refine "port-name" {
            mandatory true;
          }
        }
      }
    }
  }
  rpc disable-automatic-shutoff {
    input {
      choice degree-or-amp {
        mandatory true;
        description
          "The choice describes the option to specify the entity for the disable-automatic-shutoff RPC. It can be degree-number for rdm and amp-number for ila";
        case degree {
          leaf degree-number {
            type leafref {
              path "/org-openroadm-device/degree/degree-number";
            }
            mandatory true;
            description
              "The degree-number defined in degree";
          }
        }
        case amp {
          leaf amp-number {
            type leafref {
              path "/org-openroadm-device/line-amplifier/amp-number";
            }
            mandatory true;
            description
              "The amp-number defined in line-amplifier";
          }
        }
      }
      leaf support-timer {
        type uint16 {
          range "1..600";
        }
        default "20";
      }
    }
    output {
      uses org-openroadm-common-types:rpc-response-status;
    }
  }
  rpc start-scan {
    input {
      choice degree-or-amp {
        mandatory true;
        description
          "The choice describes the option to specify the entity for the start-scan RPC. It can be degree-number for rdm and amp-number for ila";
        case degree {
          leaf degree-number {
            type leafref {
              path "/org-openroadm-device/degree/degree-number";
            }
            mandatory true;
            description
              "The degree-number defined in degree";
          }
        }
        case amp {
          leaf amp-number {
            type leafref {
              path "/org-openroadm-device/line-amplifier/amp-number";
            }
            mandatory true;
            description
              "The amp-number defined in line-amplifier";
          }
        }
      }
      leaf port-direction {
        type org-openroadm-common-types:direction;
      }
      leaf distance {
        type uint32;
      }
      leaf resolution {
        type uint32;
      }
    }
    output {
      uses org-openroadm-common-types:rpc-response-status;
    }
  }
  rpc set-current-datetime {
    description
      "Set the info/current-datetime leaf to the specified value.";
    input {
      leaf current-datetime {
        type ietf-yang-types:date-and-time;
        mandatory true;
        description
          "The current system date and time in UTC. Format: YYYY-MM-DDTHH:MM:SS";
      }
    }
    output {
      uses org-openroadm-common-types:rpc-response-status;
    }
  }
  notification create-tech-info-notification {
    description
      "This Notification is sent when the create-tech-info is complete or failed.";
    uses create-tech-info-group;
    uses org-openroadm-common-types:rpc-response-status;
  }
  notification otdr-scan-result {
    leaf status {
      type enumeration {
        enum "Completed" {
          value 1;
        }
        enum "Failed" {
          value 2;
        }
      }
      mandatory true;
      description
        "Completed or Failed for the scan's final status";
    }
    leaf result-file {
      type string;
    }
  }
  notification change-notification {
    description
      "The Notification that a resource has been added, modified or removed.
       This notification can be triggered by changes in configuration and operational data.
       It shall contain the changed field pointed by the xpath. 
       Typically it is not intended for frequently changing volatile data e.g. PM, power levels";
    leaf change-time {
      type ietf-yang-types:date-and-time;
      description
        "The time the change occurs.";
    }
    uses changed-by-parms;
    leaf datastore {
      type enumeration {
        enum "running" {
          description
            "The <running> datastore has changed.";
        }
        enum "startup" {
          description
            "The <startup> datastore has changed";
        }
      }
      default "running";
      description
        "Indicates which configuration datastore has changed.";
    }
    list edit {
      description
        "An edit (change) record SHOULD be present for each distinct
         edit operation that the server has detected on
         the target datastore.  This list MAY be omitted
         if the detailed edit operations are not known.
         The server MAY report entries in this list for
         changes not made by a NETCONF session.";
      leaf target {
        type instance-identifier;
        description
          "Top most node associated with the configuration or operational change.
           A server SHOULD set this object to the node within
           the datastore that is being altered.  A server MAY
           set this object to one of the ancestors of the actual
           node that was changed, or omit this object, if the
           exact node is not known.";
      }
      leaf operation {
        type ietf-nc:edit-operation-type;
        description
          "Type of edit operation performed.
           A server MUST set this object to the NETCONF edit
           operation performed on the target datastore.";
      }
    }
  }
  uses org-openroadm-device-container;
}
