module ietf-udp-notif-transport {
  yang-version 1.1;
  namespace
    "urn:ietf:params:xml:ns:yang:ietf-udp-notif-transport";
  prefix unt;
  import ietf-subscribed-notifications {
    prefix sn;
    reference
      "RFC 8639: Subscription to YANG Notifications";
  }
  import ietf-subscribed-notif-receivers {
    prefix snr;
    reference
      "RFC YYYY: An HTTPS-based Transport for
                 Configured Subscriptions";
  }
  import ietf-udp-client {
    prefix udpc;
    reference
      "RFC ZZZZ: YANG Grouping for UDP Clients and UDP Servers";
  }
  import ietf-tls-client {
    prefix tlsc;
    reference
      "RFC TTTT: YANG Groupings for TLS Clients and TLS Servers";
  }
  import ietf-tls-common {
    prefix tlscmn;
    reference
      "RFC TTTT: YANG Groupings for TLS Clients and TLS Servers";
  }

  organization "IETF NETCONF (Network Configuration) Working Group";
  contact
    "WG Web:   <http:/tools.ietf.org/wg/netconf/>
     WG List:  <mailto:netconf@ietf.org>

     Authors:  Guangying Zheng
               <mailto:zhengguangying@huawei.com>
               Tianran Zhou
               <mailto:zhoutianran@huawei.com>
               Thomas Graf
               <mailto:thomas.graf@swisscom.com>
               Pierre Francois
               <mailto:pierre.francois@insa-lyon.fr>
               Alex Huang Feng
               <mailto:alex.huang-feng@insa-lyon.fr>
               Paolo Lucente
               <mailto:paolo@ntt.net>";

  description
    "Defines a model for configuring UDP-Notif as a transport
    for Configured Subscriptions.

    Copyright (c) 2024 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 XXXX; see the RFC
    itself for full legal notices.";

  revision 2024-10-17 {
    description
      "Initial revision";
    reference
      "RFC XXXX: UDP-based Transport for Configured Subscriptions";
  }

 /*
  * FEATURES
  */
  feature encode-cbor {
    description
      "This feature indicates that CBOR encoding of notification
       messages is supported.";
  }
  feature dtls13 {
    description
      "This feature indicates that DTLS 1.3 encryption of UDP
       packets is supported.";
  }
  feature segmentation {
    description
      "This feature indicates segmentation of notification messages
      is supported.";
  }

 /*
  * IDENTITIES
  */
  identity udp-notif {
    base sn:transport;
    base sn:configurable-encoding;
    description
      "UDP-Notif is used as transport for notification messages
        and state change notifications.";
  }

  identity encode-cbor {
    base sn:encoding;
    description
      "Encode data using CBOR as described in RFC 9254.";
    reference
      "RFC 9254: CBOR Encoding of Data Modeled with YANG";
  }

  grouping udp-notif-receiver-grouping {
    description
      "Provides a reusable description of a UDP-Notif target
      receiver.";

    uses udpc:udp-client-grouping {
      refine remote-port {
        mandatory true;
      }
    }

    container dtls {
      if-feature dtls13;
      presence dtls;
      uses tlsc:tls-client-grouping {
        // Using tls-client-grouping without TLS1.2 parameters
        // allowing only DTLS 1.3
        refine "client-identity/auth-type/tls12-psk" {
          // create the logical impossibility of enabling TLS1.2
          if-feature "not tlsc:client-ident-tls12-psk";
        }
        refine "server-authentication/tls12-psks" {
          // create the logical impossibility of enabling TLS1.2
          if-feature "not tlsc:server-auth-tls12-psk";
        }
        refine "hello-params/tls-versions/min" {
          must "not(derived-from-or-self(current(), "
            + "'tlscmn:tls12'))" {
            error-message
                  "TLS 1.2 is not supported as min TLS version";
          }
        }
        refine "hello-params/tls-versions/max" {
          must "not(derived-from-or-self(current(), "
            + "'tlscmn:tls12'))" {
            error-message
                  "TLS 1.2 is not supported as max TLS version";
          }
        }
      }
      description
        "Container for configuring DTLS 1.3 parameters.";
    }

    leaf enable-segmentation {
      if-feature segmentation;
      type boolean;
      default true;
      description
        "The switch for the segmentation feature. When disabled, the
        publisher will not allow fragment for a very large data";
    }

    leaf max-segment-size {
      when "../enable-segmentation = 'true'";
      if-feature segmentation;
      type uint16;
      description
        "UDP-Notif provides a configurable max-segment-size to
        control the size of each segment (UDP-Notif header, with
        options, included).";
    }
  }

  augment "/sn:subscriptions/snr:receiver-instances/" +
          "snr:receiver-instance/snr:transport-type" {
    case udp-notif {
      container udp-notif-receiver {
        description
          "The UDP-notif receiver to send notifications to.";
        uses udp-notif-receiver-grouping;
      }
    }
    description
      "Augment the transport-type choice to include the 'udp-notif'
       transport.";
  }
}
