module ietf-te-device {
  yang-version 1.1;
  namespace "urn:ietf:params:xml:ns:yang:ietf-te-device";

  prefix te-dev;

  /* Import TE module */

  import ietf-te {
    prefix te;
    reference
      "RFC 10057: A YANG Data Model for Traffic Engineering Tunnels,
       Label Switched Paths, and Interfaces";
  }

  /* Import TE types */

  import ietf-te-types {
    prefix te-types;
    reference
      "RFC 10056: Common YANG Data Types for Traffic Engineering.";
  }
  import ietf-interfaces {
    prefix if;
    reference
      "RFC8343: A YANG Data Model for Interface Management";
  }
  import ietf-routing-types {
    prefix rt-types;
    reference
      "RFC8294: Common YANG Data Types for the Routing Area";
  }

  organization
    "IETF Traffic Engineering Architecture and Signaling (TEAS)
     Working Group";
  contact
    "WG Web:   <https://datatracker.ietf.org/wg/teas/>
     WG List:  <mailto:teas@ietf.org>

     Editor:   Tarek Saad
               <mailto:tsaad.net@gmail.com>

     Editor:   Rakesh Gandhi
               <mailto:rgandhi@cisco.com>

     Editor:   Vishnu Pavan Beeram
               <mailto:vbeeram@juniper.net>

     Editor:   Himanshu Shah
               <mailto:hshah@ciena.com>

     Editor:   Xufeng Liu
               <mailto: xufeng.liu.ietf@gmail.com>

     Editor:   Igor Bryskin
               <mailto:i_bryskin@yahoo.com>";

  description
    "This module defines a data model for TE device configurations,
     state, and RPCs.

     Copyright (c) 2026 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 Revised BSD License set
     forth in Section 4.c of the IETF Trust's Legal Provisions
     Relating to IETF Documents
     (https://trustee.ietf.org/license-info).

     This version of this YANG module is part of RFC 10057
     (https://www.rfc-editor.org/info/rfc10057); see the RFC itself
     for full legal notices.";

  revision 2026-11-18 {
    description
      "Initial revision for the TE device YANG module.";
    reference
      "RFC 10057: A YANG Data Model for Traffic Engineering Tunnels,
       Label Switched Paths, and Interfaces";
  }

  grouping lsp-device-timers {
    description
      "Device TE LSP timers configs.";
    leaf lsp-install-interval {
      type uint32;
      units "seconds";
      description
        "TE LSP installation delay time.";
    }
    leaf lsp-cleanup-interval {
      type uint32;
      units "seconds";
      description
        "TE LSP cleanup delay time.";
    }
    leaf lsp-invalidation-interval {
      type uint32;
      units "seconds";
      description
        "TE LSP path invalidation before taking action delay time.";
    }
  }

  grouping te-igp-flooding-bandwidth-config {
    description
      "Configurable items for igp flooding bandwidth
       threshold configuration.";
    leaf threshold-type {
      type enumeration {
        enum delta {
          description
            "'delta' indicates that the local
             system should flood IGP updates when a
             change in reserved bandwidth >= the specified
             delta occurs on the interface.";
        }
        enum threshold-crossed {
          description
            "THRESHOLD-CROSSED indicates that
             the local system should trigger an update (and
             hence flood) the reserved bandwidth when the
             reserved bandwidth changes such that it crosses,
             or becomes equal to one of the threshold values.";
        }
      }
      description
        "The type of threshold that should be used to specify the
         values at which bandwidth is flooded. 'delta' indicates that
         the local system should flood IGP updates when a change in
         reserved bandwidth >= the specified delta occurs on the
         interface. Where 'threshold-crossed' is specified, the local
         system should trigger an update (and hence flood) the
         reserved bandwidth when the reserved bandwidth changes such
         that it crosses, or becomes equal to one of the threshold
         values.";
    }
    leaf delta-percentage {
      when "../threshold-type = 'delta'" {
        description
          "The percentage delta can only be specified when the
           threshold type is specified to be a percentage delta of
           the reserved bandwidth.";
      }
      type rt-types:percentage;
      description
        "The percentage of the maximum-reservable-bandwidth
         considered as the delta that results in an IGP update
         being flooded.";
    }
    leaf threshold-specification {
      when "../threshold-type = 'threshold-crossed'" {
        description
          "The selection of whether mirrored or separate threshold
           values are to be used requires user-specified thresholds
           to be set.";
      }
      type enumeration {
        enum mirrored-up-down {
          description
            "mirrored-up-down indicates that a single set of
             threshold values should be used for both increasing
             and decreasing bandwidth when determining whether
             to trigger updated bandwidth values to be flooded
             in the IGP TE extensions.";
        }
        enum separate-up-down {
          description
            "separate-up-down indicates that a separate
             threshold values should be used for the increasing
             and decreasing bandwidth when determining whether
             to trigger updated bandwidth values to be flooded
             in the IGP TE extensions.";
        }
      }
      description
        "This value specifies whether a single set of threshold
         values should be used for both increasing and decreasing
         bandwidth when determining whether to trigger updated
         bandwidth values to be flooded in the IGP TE extensions.
         'mirrored-up-down' indicates that a single value (or set of
         values) should be used for both increasing and decreasing
         values, where 'separate-up-down' specifies that the
         increasing and decreasing values will be separately
         specified.";
    }
    leaf-list up-thresholds {
      when "../threshold-type = 'threshold-crossed'"
         + "and ../threshold-specification = 'separate-up-down'" {
        description
          "A list of up-thresholds can only be specified when the
           bandwidth update is triggered based on crossing a
           threshold and separate up and down thresholds are
           required.";
      }
      type rt-types:percentage;
      description
        "The thresholds (expressed as a percentage of the maximum
         reservable bandwidth) at which bandwidth updates are to be
         triggered when the bandwidth is increasing.";
    }
    leaf-list down-thresholds {
      when "../threshold-type = 'threshold-crossed'"
         + "and ../threshold-specification = 'separate-up-down'" {
        description
          "A list of down-thresholds can only be specified when the
           bandwidth update is triggered based on crossing a
           threshold and separate up and down thresholds are
           required.";
      }
      type rt-types:percentage;
      description
        "The thresholds (expressed as a percentage of the maximum
         reservable bandwidth) at which bandwidth updates are to be
         triggered when the bandwidth is decreasing.";
    }
    leaf-list up-down-thresholds {
      when "../threshold-type = 'threshold-crossed'"
         + "and ../threshold-specification = 'mirrored-up-down'" {
        description
          "A list of thresholds corresponding to both increasing
           and decreasing bandwidths can be specified only when an
           update is triggered based on crossing a threshold, and
           the same up and down thresholds are required.";
      }
      type rt-types:percentage;
      description
        "The thresholds (expressed as a percentage of the maximum
         reservable bandwidth of the interface) at which bandwidth
         updates are flooded -- used both when the bandwidth is
         increasing and decreasing.";
    }
  }

  /**
   * TE device augmentations
   */
  augment "/te:te" {
    description
      "TE global container.";
    /* TE Interface Configuration Data */
    container interfaces {
      description
        "Configuration data model for TE interfaces.";
      uses te-igp-flooding-bandwidth-config;
      list interface {
        key "name";
        description
          "The list of interfaces enabled for TE.";
        leaf name {
          type if:interface-ref;
          description
            "The reference to interface enabled for TE.";
        }
        /* TE interface parameters */
        leaf te-metric {
          type te-types:te-metric;
          description
            "TE interface metric.";
        }
        choice admin-group-type {
          description
            "TE interface administrative groups
             representation type.";
          case value-admin-groups {
            choice value-admin-group-type {
              description
                "The type of admin-groups.";
              case admin-groups {
                description
                  "Administrative group/Resource
                   class.";
                leaf admin-group {
                  type te-types:admin-group;
                  description
                    "TE interface administrative group.";
                }
              }
              case extended-admin-groups {
                if-feature "te-types:extended-admin-groups";
                description
                  "Extended administrative group/Resource
                   class.";
                leaf extended-admin-group {
                  type te-types:extended-admin-group;
                  description
                    "TE interface extended administrative group.";
                }
              }
            }
          }
          case named-admin-groups {
            list named-admin-groups {
              if-feature "te-types:extended-admin-groups";
              if-feature "te-types:named-extended-admin-groups";
              key "named-admin-group";
              description
                "A list of named admin-group entries.";
              leaf named-admin-group {
                type leafref {
                  path "../../../../te:globals/"
                     + "te:named-admin-groups/te:named-admin-group/"
                     + "te:name";
                }
                description
                  "A named admin-group entry.";
              }
            }
          }
        }
        choice srlg-type {
          description
            "Choice of SRLG configuration.";
          case value-srlgs {
            list values {
              key "value";
              description
                "List of SRLG values that
                 this link is part of.";
              leaf value {
                type uint32 {
                  range "0..4294967295";
                }
                description
                  "Value of the SRLG.";
              }
            }
          }
          case named-srlgs {
            list named-srlgs {
              if-feature "te-types:named-srlg-groups";
              key "named-srlg";
              description
                "A list of named SRLG entries.";
              leaf named-srlg {
                type leafref {
                  path "../../../../te:globals/"
                     + "te:named-srlgs/te:named-srlg/te:name";
                }
                description
                  "A named SRLG entry.";
              }
            }
          }
        }
        uses te-igp-flooding-bandwidth-config;
        list switching-capabilities {
          key "switching-capability";
          description
            "List of interface capabilities for this interface.";
          leaf switching-capability {
            type identityref {
              base te-types:switching-capabilities;
            }
            description
              "Switching Capability for this interface.";
          }
          leaf encoding {
            type identityref {
              base te-types:lsp-encoding-types;
            }
            description
              "Encoding supported by this interface.";
          }
        }
        container te-advertisements-state {
          config false;
          description
            "TE interface advertisements state container.";
          leaf flood-interval {
            type uint32;
            description
              "The periodic flooding interval.";
          }
          leaf last-flooded-time {
            type uint32;
            units "seconds";
            description
              "Time elapsed since last flooding in seconds.";
          }
          leaf next-flooded-time {
            type uint32;
            units "seconds";
            description
              "Time remained for next flooding in seconds.";
          }
          leaf last-flooded-trigger {
            type enumeration {
              enum link-up {
                description
                  "Link-up flooding trigger.";
              }
              enum link-down {
                description
                  "Link-down flooding trigger.";
              }
              enum threshold-up {
                description
                  "Bandwidth reservation up threshold.";
              }
              enum threshold-down {
                description
                  "Bandwidth reservation down threshold.";
              }
              enum bandwidth-change {
                description
                  "Bandwidth capacity change.";
              }
              enum user-initiated {
                description
                  "Initiated by user.";
              }
              enum srlg-change {
                description
                  "SRLG property change.";
              }
              enum periodic-timer {
                description
                  "Periodic timer expired.";
              }
            }
            default "periodic-timer";
            description
              "Trigger for the last flood.";
          }
          list advertised-level-areas {
            key "level-area";
            description
              "List of level-areas that the TE interface is
               advertised in.";
            leaf level-area {
              type uint32;
              description
                "The IGP area or level where the TE interface link
                 state is advertised in.";
            }
          }
        }
      }
    }
  }

  /* TE globals device augmentation */

  augment "/te:te/te:globals" {
    description
      "Global TE device specific configuration parameters.";
    uses lsp-device-timers;
  }

  /* TE tunnels device configuration augmentation */

  augment "/te:te/te:tunnels/te:tunnel" {
    description
      "Tunnel device dependent augmentation.";
    leaf path-invalidation-action {
      type identityref {
        base te-types:path-invalidation-action-type;
      }
      description
        "Tunnel path invalidation action.";
    }
    uses lsp-device-timers;
  }

  /* TE LSPs device state augmentation */

  augment "/te:te/te:lsps/te:lsp" {
    description
      "TE LSP device dependent augmentation.";
    container lsp-timers {
      when "../te:origin-type = 'ingress'" {
        description
          "Applicable to ingress LSPs only.";
      }
      description
        "Ingress LSP timers.";
      leaf uptime {
        type uint32;
        units "seconds";
        description
          "The LSP uptime.";
      }
      leaf time-to-install {
        type uint32;
        units "seconds";
        description
          "The time remaining for a new LSP to be instantiated
           in forwarding to carry traffic.";
      }
      leaf time-to-destroy {
        type uint32;
        units "seconds";
        description
          "The time remaining for an existing LSP to be torn down.";
      }
    }
    container downstream-info {
      when "../te:origin-type != 'egress'" {
        description
          "Downstream information of the LSP.";
      }
      description
        "Downstream information.";
      leaf nhop {
        type te-types:te-tp-id;
        description
          "Downstream next-hop address.";
      }
      leaf outgoing-interface {
        type if:interface-ref;
        description
          "Downstream interface.";
      }
      container neighbor {
        uses te-types:te-generic-node-id;
        description
          "Downstream neighbor address.";
      }
      leaf label {
        type rt-types:generalized-label;
        description
          "Downstream label.";
      }
    }
    container upstream-info {
      when "../te:origin-type != 'ingress'" {
        description
          "Upstream information of the LSP.";
      }
      description
        "Upstream information.";
      leaf phop {
        type te-types:te-tp-id;
        description
          "Upstream next-hop or previous-hop address.";
      }
      container neighbor {
        uses te-types:te-generic-node-id;
        description
          "Upstream neighbor address.";
      }
      leaf label {
        type rt-types:generalized-label;
        description
          "Upstream label.";
      }
    }
  }

  /* TE interfaces RPCs/execution Data */

  rpc link-state-update {
    description
      "Triggers a link state update for the specific interface.";
    input {
      choice filter-type {
        mandatory true;
        description
          "Filter choice.";
        case match-all {
          leaf all {
            type empty;
            mandatory true;
            description
              "Match all TE interfaces.";
          }
        }
        case match-one-interface {
          leaf interface {
            type if:interface-ref;
            description
              "Match a specific TE interface.";
          }
        }
      }
    }
  }
}
