module ietf-microwave-radio-link {
  yang-version 1.1;
  namespace "urn:ietf:params:xml:ns:yang:ietf-microwave-radio-link";
  prefix mrl;

  import ietf-yang-types {
    prefix yang;
    reference
      "RFC 6991";
  }
  import iana-if-type {
    prefix ianaift;
  }
  import ietf-interfaces {
    prefix if;
    reference
      "RFC 8343";
  }
  import ietf-interface-protection {
    prefix ifprot;
    reference
      "RFC 8561";
  }
  import ietf-microwave-types {
    prefix mw-types;
    reference
      "RFC 8561";
  }

  organization
    "Internet Engineering Task Force (IETF) CCAMP WG";
  contact
    "WG List: <mailto:ccamp@ietf.org>

     Editors:
      Jonas Ahlberg (jonas.ahlberg@ericsson.com)
      Min Ye (amy.yemin@huawei.com)
      Xi Li (Xi.Li@neclab.eu)
      Daniela Spreafico (daniela.spreafico@nokia.com)
      Marko Vaupotic (Marko.Vaupotic@aviatnet.com)";
  description
    "This is a module for the entities in
     a generic microwave system.

     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 8561; see
     the RFC itself for full legal notices.";

  revision 2019-06-19 {
    description
      "Initial revision.";
    reference
      "RFC 8561: A YANG Data Model for Microwave Radio Link";
  }

  /*
   * Features
   */

  feature xpic {
    description
      "Indicates that the device supports XPIC.";
    reference
      "ETSI TR 102 311";
  }

  feature mimo {
    description
      "Indicates that the device supports MIMO.";
    reference
      "ETSI TR 102 311";
  }

  feature tdm {
    description
      "Indicates that the device supports TDM.";
  }

  /*
   * Typedefs
   */

  typedef power {
    type decimal64 {
      fraction-digits 1;
    }
    description
      "Type used for the power values in the data nodes
       for configuration or status.";
  }

  /*
   * Radio Link Terminal (RLT)
   */

  augment "/if:interfaces/if:interface" {
    when "derived-from-or-self(if:type,"
       + "'ianaift:wwanPP')";
    description
      "Addition of data nodes for the radio link terminal to
       the standard Interface data model, for interfaces of
       the type 'wwanPP'.";
    leaf id {
      type string;
      description
        "Descriptive identity of the radio link terminal used by
         far-end RLT to check that it's connected to the correct
         near-end RLT.  Does not need to be configured if this
         check is not used.";
    }
    leaf mode {
      type identityref {
        base mw-types:rlt-mode;
      }
      mandatory true;
      description
        "A description of the mode in which the radio link
         terminal is configured.  The format is X plus Y.
         X represents the number of bonded carrier terminations.
         Y represents the number of protecting carrier
         terminations.";
    }
    leaf-list carrier-terminations {
      type if:interface-ref;
      must "derived-from-or-self(/if:interfaces/if:interface"
         + "[if:name = current()]"
         + "/if:type, 'ianaift:wwanPP2')" {
        description
          "The type of interface must be
           'wwanPP2'.";
      }
      min-elements 1;
      description
        "A list of references to carrier terminations
         included in the radio link terminal.";
    }

    leaf-list rlp-groups {
      type leafref {
        path "/mrl:radio-link-protection-groups/"
           + "mrl:protection-group/mrl:name";
      }
      description
        "A list of references to the carrier termination
         groups configured for radio link protection in this
         radio link terminal.";
    }
    leaf-list xpic-pairs {
      if-feature "xpic";
      type leafref {
        path "/mrl:xpic-pairs/mrl:xpic-pair/mrl:name";
      }
      description
        "A list of references to the XPIC pairs used in this
         radio link terminal.  One pair can be used by two
         terminals.";
      reference
        "ETSI TR 102 311";
    }
    leaf-list mimo-groups {
      if-feature "mimo";
      type leafref {
        path "/mrl:mimo-groups/mrl:mimo-group/mrl:name";
      }
      description
        "A reference to the MIMO group used in this
         radio link terminal.  One group can be used by more
         than one terminal.";
      reference
        "ETSI TR 102 311";
    }
    list tdm-connections {
      if-feature "tdm";
      key "tdm-type";
      description
        "A list stating the number of active TDM connections
         of a specified tdm-type that is configured to be
         supported by the RLT.";
      leaf tdm-type {
        type identityref {
          base mw-types:tdm-type;
        }
        description
          "The type of TDM connection, which also indicates
           the supported capacity.";
      }
      leaf tdm-connections {
        type uint16;
        mandatory true;
        description
          "Number of connections of the specified type.";
      }
    }
  }

  /*
   * Carrier Termination
   */

  augment "/if:interfaces/if:interface" {
    when "derived-from-or-self(if:type,"
       + "'ianaift:wwanPP2')";
    description
      "Addition of data nodes for carrier termination to
       the standard Interface data model, for interfaces
       of the type 'wwanPP2'.";
    leaf carrier-id {
      type string;
      default "A";
      description
        "ID of the carrier (e.g., A, B, C, or D).
         Used in XPIC and MIMO configurations to check that
         the carrier termination is connected to the correct
         far-end carrier termination.  Should be the same
         carrier ID on both sides of the hop.  Left as
         default value when MIMO and XPIC are not in use.";
    }
    leaf tx-enabled {
      type boolean;
      default "false";
      description
        "Disables (false) or enables (true) the transmitter.
         Only applicable when the interface is enabled
         (interface:enabled = true); otherwise, it's always
         disabled.";
    }
    leaf tx-oper-status {
      type enumeration {
        enum off {
          description
            "Transmitter is off.";
        }
        enum on {
          description
            "Transmitter is on.";
        }
        enum standby {
          description
            "Transmitter is in standby.";
        }
      }
      config false;
      description
        "Shows the operative status of the transmitter.";
    }
    leaf tx-frequency {
      type uint32;
      units "kHz";
      mandatory true;
      description
        "Selected transmitter frequency.";
    }
    choice freq-or-distance {
      leaf rx-frequency {
        type uint32;
        units "kHz";
        description
          "Selected receiver frequency.";
      }
      leaf duplex-distance {
        type int32;
        units "kHz";
        description
          "Distance between transmitter and receiver frequencies.";
      }
      mandatory true;
      description
        "A choice to configure rx-frequency directly or compute
         it as duplex-distance subtracted from tx-frequency.";
    }
    leaf actual-rx-frequency {
      type uint32;
      units "kHz";
      config false;
      description
        "Computed receiver frequency.";
    }
    leaf actual-duplex-distance {
      type uint32;
      units "kHz";
      config false;
      description
        "Computed distance between Tx and Rx frequencies.";
    }
    leaf channel-separation {
      type uint32;
      units "kHz";
      mandatory true;
      description
        "The amount of bandwidth allocated to a carrier.  The
         distance between adjacent channels in a radio
         frequency channels arrangement";
      reference
        "ETSI EN 302 217-1";
    }
    leaf polarization {
      type enumeration {
        enum horizontal {
          description
            "Horizontal polarization.";
        }
        enum vertical {
          description
            "Vertical polarization.";
        }
        enum not-specified {
          description
            "Polarization not specified.";
        }
      }
      default "not-specified";
      description
        "Polarization - a textual description for info only.";
    }
    choice power-mode {
      container rtpc {
        description
          "Remote Transmit Power Control (RTPC).";
        reference
          "ETSI EN 302 217-1";
        leaf maximum-nominal-power {
          type power {
            range "-99..99";
          }
          units "dBm";
          mandatory true;
          description
            "Selected output power.";

          reference
            "ETSI EN 302 217-1";
        }
      }
      container atpc {
        description
          "Automatic Transmitter Power Control (ATPC).";
        reference
          "ETSI EN 302 217-1";
        leaf maximum-nominal-power {
          type power {
            range "-99..99";
          }
          units "dBm";
          mandatory true;
          description
            "Selected maximum output power.  Minimum output
             power is the same as the system capability,
             minimum-power.";
          reference
            "ETSI EN 302 217-1";
        }
        leaf atpc-lower-threshold {
          type power {
            range "-99..-20";
          }
          units "dBm";
          must 'current() <= ../atpc-upper-threshold';
          mandatory true;
          description
            "The lower threshold for the input power at the
             far end, which is used in the ATPC mode.";
          reference
            "ETSI EN 302 217-1";
        }
        leaf atpc-upper-threshold {
          type power {
            range "-99..-20";
          }
          units "dBm";
          mandatory true;
          description
            "The upper threshold for the input power at the
             far end, which is used in the ATPC mode.";
          reference
            "ETSI EN 302 217-1";
        }
      }
      mandatory true;
      description
        "A choice of RTPC or ATPC.";
    }
    leaf actual-transmitted-level {
      type power {
        range "-99..99";
      }
      units "dBm";
      config false;
      description
        "Actual transmitted power level (0.1 dBm resolution).";
      reference
        "ETSI EN 301 129";
    }
    leaf actual-received-level {
      type power {
        range "-99..-20";
      }
      units "dBm";
      config false;
      description
        "Actual received power level (0.1 dBm resolution).";
      reference
        "ETSI EN 301 129";
    }
    choice coding-modulation-mode {
      container single {
        description
          "A single modulation order only.";
        reference
          "ETSI EN 302 217-1";
        leaf selected-cm {
          type identityref {
            base mw-types:coding-modulation;
          }
          mandatory true;
          description
            "Selected the single coding/modulation.";
        }
      }
      container adaptive {
        description
          "Adaptive coding/modulation.";
        reference
          "ETSI EN 302 217-1";

        leaf selected-min-acm {
          type identityref {
            base mw-types:coding-modulation;
          }
          mandatory true;
          description
            "Selected minimum coding/modulation.
             Adaptive coding/modulation shall not go
             below this value.";
        }
        leaf selected-max-acm {
          type identityref {
            base mw-types:coding-modulation;
          }
          mandatory true;
          description
            "Selected maximum coding/modulation.
             Adaptive coding/modulation shall not go
             above this value.";
        }
      }
      mandatory true;
      description
        "A selection of single or
         adaptive coding/modulation mode.";
    }
    leaf actual-tx-cm {
      type identityref {
        base mw-types:coding-modulation;
      }
      config false;
      description
        "Actual coding/modulation in transmitting direction.";
    }
    leaf actual-snir {
      type decimal64 {
        fraction-digits 1;
        range "0..99";
      }
      units "dB";
      config false;
      description
        "Actual signal to noise plus the interference ratio
         (0.1 dB resolution).";
    }
    leaf actual-xpi {
      if-feature "xpic";
      type decimal64 {
        fraction-digits 1;
        range "0..99";
      }
      units "dB";
      config false;
      description
        "The actual carrier to cross-polar interference.
         Only valid if XPIC is enabled (0.1 dB resolution).";
      reference
        "ETSI TR 102 311";
    }
    container ct-performance-thresholds {
      description
        "Specification of thresholds for when alarms should
         be sent and cleared for various performance counters.";
      leaf received-level-alarm-threshold {
        type power {
          range "-99..-20";
        }
        units "dBm";
        default "-99";
        description
          "An alarm is sent when the received power level is
           below the specified threshold.";
        reference
          "ETSI EN 301 129";
      }
      leaf transmitted-level-alarm-threshold {
        type power {
          range "-99..99";
        }
        units "dBm";
        default "-99";
        description
          "An alarm is sent when the transmitted power level
           is below the specified threshold.";
        reference
          "ETSI EN 301 129";
      }
      leaf ber-alarm-threshold {
        type enumeration {
          enum 1e-9 {
            description
              "Threshold at 1e-9 (10^-9).";
          }
          enum 1e-8 {
            description
              "Threshold at 1e-8 (10^-8).";
          }
          enum 1e-7 {
            description
              "Threshold at 1e-7 (10^-7).";
          }
          enum 1e-6 {
            description
              "Threshold at 1e-6 (10^-6).";
          }
          enum 1e-5 {
            description
              "Threshold at 1e-5 (10^-5).";
          }
          enum 1e-4 {
            description
              "Threshold at 1e-4 (10^-4).";
          }
          enum 1e-3 {
            description
              "Threshold at 1e-3 (10^-3).";
          }
          enum 1e-2 {
            description
              "Threshold at 1e-2 (10^-2).";
          }
          enum 1e-1 {
            description
              "Threshold at 1e-1 (10^-1).";
          }
        }
        default "1e-6";
        description
          "Specification of at which BER an alarm should
           be raised.";
        reference
          "ETSI EN 302 217-1";
      }
    }
    leaf if-loop {
      type enumeration {
        enum disabled {
          description
            "Disables the IF Loop.";
        }
        enum client {
          description
            "Loops the signal back to the client side.";
        }
        enum radio {
          description
            "Loops the signal back to the radio side.";
        }
      }
      default "disabled";
      description
        "Enable (client/radio) or disable (disabled)
         the IF Loop, which loops the signal back to
         the client side or the radio side.";
    }
    leaf rf-loop {
      type enumeration {
        enum disabled {
          description
            "Disables the RF Loop.";
        }
        enum client {
          description
            "Loops the signal back to the client side.";
        }
        enum radio {
          description
            "Loops the signal back to the radio side.";
        }
      }
      default "disabled";
      description
        "Enable (client/radio) or disable (disabled)
         the RF loop, which loops the signal back to
         the client side or the radio side.";
    }
    container capabilities {
      config false;
      description
        "Capabilities of the installed equipment and
         some selected configurations.";
      leaf min-tx-frequency {
        type uint32;
        units "kHz";
        description
          "Minimum Tx frequency possible to use.";
      }
      leaf max-tx-frequency {
        type uint32;
        units "kHz";
        description
          "Maximum Tx frequency possible to use.";
      }
      leaf min-rx-frequency {
        type uint32;
        units "kHz";
        description
          "Minimum Rx frequency possible to use.";
      }
      leaf max-rx-frequency {
        type uint32;
        units "kHz";
        description
          "Maximum Tx frequency possible to use.";
      }
      leaf minimum-power {
        type power;
        units "dBm";
        description
          "The minimum output power supported.";
        reference
          "ETSI EN 302 217-1";
      }
      leaf maximum-available-power {
        type power;
        units "dBm";
        description
          "The maximum output power supported.";
        reference
          "ETSI EN 302 217-1";
      }
      leaf available-min-acm {
        type identityref {
          base mw-types:coding-modulation;
        }
        description
          "Minimum coding-modulation possible to use.";
      }
      leaf available-max-acm {
        type identityref {
          base mw-types:coding-modulation;
        }
        description
          "Maximum coding-modulation possible to use.";
      }
    }
    container error-performance-statistics {
      config false;

      description
        "ITU-T G.826 error performance statistics relevant for
         a microwave/millimeter wave carrier.";
      leaf bbe {
        type yang:counter32;
        units "number of block errors";
        description
          "Number of Background Block Errors (BBEs).  A BBE is an
           errored block not occurring as part of Severely Errored
           Seconds (SES).  Discontinuities in the value of this
           counter can occur at re-initialization of the management
           system and at other times as indicated by the value of
           'discontinuity-time' in ietf-interfaces.";
        reference
          "ITU-T G.826";
      }
      leaf es {
        type yang:counter32;
        units "seconds";
        description
          "Number of Errored Seconds (ES).  An ES is a one-second
           period with one or more errored blocks or at least one
           defect.  Discontinuities in the value of this counter
           can occur at re-initialization of the management system
           and at other times as indicated by the value of
           'discontinuity-time' in ietf-interfaces.";
        reference
          "ITU-T G.826";
      }
      leaf ses {
        type yang:counter32;
        units "seconds";
        description
          "Number of SES.  SES is a one-second period that contains
           equal or more than 30% errored blocks or at least
           one defect.  SES is a subset of ES.  Discontinuities in
           the value of this counter can occur at re-initialization
           of the management system and at other times as indicated
           by the value of 'discontinuity-time' in ietf-interfaces.";
        reference
          "ITU-T G.826";
      }
      leaf uas {
        type yang:counter32;
        units "seconds";
        description
          "Number of Unavailable Seconds (UAS); that is, the
           total time that the node has been unavailable.
           Discontinuities in the value of this counter can occur
           at re-initialization of the management system and at
           other times as indicated by the value of
           'discontinuity-time' in ietf-interfaces.";
        reference
          "ITU-T G.826";
      }
    }
    container radio-performance-statistics {
      config false;
      description
        "ETSI EN 301 129 radio physical interface statistics relevant
         for a carrier termination.";
      leaf min-rltm {
        type power {
          range "-99..-20";
        }
        units "dBm";
        description
          "Minimum received power level.  Discontinuities in the
           value of this counter can occur at re-initialization
           of the management system and at other times as
           indicated by the value of 'discontinuity-time' in
           ietf-interfaces.";
        reference
          "ETSI EN 301 129";
      }
      leaf max-rltm {
        type power {
          range "-99..-20";
        }
        units "dBm";
        description
          "Maximum received power level.  Discontinuities in the
           value of this counter can occur at re-initialization
           of the management system and at other times as
           indicated by the value of 'discontinuity-time' in
           ietf-interfaces.";
        reference
          "ETSI EN 301 129";
      }
      leaf min-tltm {
        type power {
          range "-99..99";
        }
        units "dBm";

        description
          "Minimum transmitted power level.  Discontinuities
           in the value of this counter can occur at
           re-initialization of the management system and
           at other times as indicated by the value of
           'discontinuity-time' in ietf-interfaces.";
        reference
          "ETSI EN 301 129";
      }
      leaf max-tltm {
        type power {
          range "-99..99";
        }
        units "dBm";
        description
          "Maximum transmitted power level.  Discontinuities
           in the value of this counter can occur at
           re-initialization of the management system and
           at other times as indicated by the value of
           'discontinuity-time' in ietf-interfaces.";
        reference
          "ETSI EN 301 129";
      }
    }
  }

  /*
   * Radio Link Protection Groups
   */

  container radio-link-protection-groups {
    description
      "Configuration of radio link protected groups of
       carrier terminations in a radio link.  More than one
       protected group per radio link terminal is allowed.";
    uses ifprot:protection-groups {
      refine "protection-group/members" {
        must "derived-from-or-self(/if:interfaces/if:interface"
           + "[if:name = current()]"
           + "/if:type, 'ianaift:wwanPP2')" {
          description
            "The type of a protection member must be
             'wwanPP2'.";
        }
      }
      refine "protection-group/working-entity" {
        must "derived-from-or-self(/if:interfaces/if:interface"
           + "[if:name = current()]"
           + "/if:type, 'ianaift:wwanPP2')" {
          description
            "The type of a working-entity must be
             'wwanPP2'.";
        }
      }
    }
  }

  /*
   * XPIC & MIMO groups - Configuration data nodes
   */

  container xpic-pairs {
    if-feature "xpic";
    description
      "Configuration of carrier termination pairs
       for operation in XPIC mode.";
    reference
      "ETSI TR 102 311";
    list xpic-pair {
      key "name";
      description
        "List of carrier termination pairs in XPIC mode.";
      leaf name {
        type string;
        description
          "Name used for identification of the XPIC pair.";
      }
      leaf enabled {
        type boolean;
        default "false";
        description
          "Enable(true)/disable(false) XPIC";
      }
      leaf-list members {
        type if:interface-ref;
        must "derived-from-or-self(/if:interfaces/if:interface"
           + "[if:name = current()]"
           + "/if:type, 'ianaift:wwanPP2')" {
          description
            "The type of a member must be
             'wwanPP2'.";
        }
        min-elements 2;
        max-elements 2;

        description
          "Association to XPIC pairs used in the radio link
           terminal.";
      }
    }
  }
  container mimo-groups {
    if-feature "mimo";
    description
      "Configuration of carrier terminations
       for operation in MIMO mode.";
    reference
      "ETSI TR 102 311";
    list mimo-group {
      key "name";
      description
        "List of carrier terminations in MIMO mode.";
      leaf name {
        type string;
        description
          "Name used for identification of the MIMO group.";
      }
      leaf enabled {
        type boolean;
        default "false";
        description
          "Enable(true)/disable(false) MIMO.";
      }
      leaf-list members {
        type if:interface-ref;
        must "derived-from-or-self(/if:interfaces/if:interface"
           + "[if:name = current()]"
           + "/if:type, 'ianaift:wwanPP2')" {
          description
            "The type of a member must be
             'wwanPP2'.";
        }
        min-elements 2;
        description
          "Association to a MIMO group if used in the radio
           link terminal.";
      }
    }
  }
}
