module ietf-softwire-ce {
  yang-version 1.1;
  namespace "urn:ietf:params:xml:ns:yang:ietf-softwire-ce";
  prefix softwire-ce;

  import ietf-inet-types {
    prefix inet;
    reference "Section 4 of RFC 6991";
  }
  import ietf-interfaces {
    prefix if;
    reference "RFC 8343: A YANG Data Model for Interface Management";
  }
  import ietf-softwire-common {
    prefix softwire-common;
    reference
      "RFC XXXX: YANG Modules for IPv4-in-IPv6 Address plus Port
                 Softwires";
  }
  import iana-tunnel-type {
    prefix iana-tunnel-type;
    reference
      "RFC YYYY: Tunnel Interface Types YANG Module";
  }

  organization
    "IETF Softwire Working Group";
  contact
    "WG Web:   <https://datatracker.ietf.org/wg/softwire/>
     WG List:  <mailto:softwire@ietf.org>

     Author:  Qi Sun
              <mailto:sunqi.ietf@gmail.com>

     Author:  Linhui Sun
              <mailto:lh.sunlinh@gmail.com>

     Author:  Yong Cui
              <mailto:yong@csnet1.cs.tsinghua.edu.cn>

     Editor:  Ian Farrer
              <mailto:ian.farrer@telekom.de>

     Author:  Sladjana Zoric
              <mailto:sladjana.zoric@telekom.de>

     Editor:  Mohamed Boucadair
              <mailto:mohamed.boucadair@orange.com>

     Author:  Rajiv Asati
               <mailto:rajiva@cisco.com>";
  description
    "This document defines a YANG module for the configuration and
     management of A+P Softwire Customer Premises Equipment (CEs). It
     covers Lightweight 4over6, MAP-E, and MAP-T mechanisms.

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

  revision 2019-01-11 {
    description
      "Initial revision.";
    reference
      "RFC XXXX: YANG Modules for IPv4-in-IPv6 Address plus Port
                 Softwires";
  }

  /*
   * Features
   */

  feature binding-mode {
    description
      "Binding is used for configuring the Lightweight 4over6 mechanism.

       Binding based softwire mechanisms are IPv4-over-IPv6 tunnelling
       transition mechanisms specifically intended for complete
       independence between the IPv6 subnet prefix (and IPv6 address)
       and IPv4 address, with or without IPv4 address sharing.

       This is accomplished by maintaining state for each softwire
       (per-subscriber state) in the central Border Relay (BR) and using
       a hub-and-spoke forwarding architecture. In order to delegate the
       NAPT function and achieve IPv4 address sharing, port-restricted
       IPv4 addresses needs to be allocated to CEs.

       This feature indicates that the network element can function as
       one or more binding based softwire instances.";
    reference
      "RFC7596: Lightweight 4over6: An Extension to the Dual-Stack Lite
                Architecture
       RFC7597: Mapping of Address and Port with Encapsulation (MAP-E)
       RFC7599: Mapping of Address and Port using Translation (MAP-T)";
  }

  feature map-e {
    description
      "MAP-E is an IPv6 transition mechanism for transporting IPv4
       packets across an IPv6 network using IP encapsulation. MAP-E
       allows for a reduction of the amount of centralized state using
       rules to express IPv4/IPv6 address mappings. This introduces an
       algorithmic relationship between the IPv6 subnet and IPv4
       address.

       This feature indicates that the network element can function as
       one or more MAP-E softwire instances.";
    reference
      "RFC7597: Mapping of Address and Port with Encapsulation (MAP-E)";
  }

  feature map-t {
    description
      "MAP-T is an IPv6 transition mechanism for transporting IPv4
       packets across an IPv6 network using IP translation. It leverages
       a double stateless NAT64 based solution as well as the stateless
       algorithmic address & transport layer port mapping algorithm
       defined for MAP-E.

       This feature indicates that the network element can function as
       one or more MAP-T softwire instances.";
    reference
      "RFC7599: Mapping of Address and Port using Translation (MAP-T)";
  }

  // Binding Entry

  grouping binding-entry {
    description
      "The binding BR (Border Relay) maintains an address binding table
       that contains the binding between the CE's IPv6 address,
       the allocated IPv4 address and restricted port-set.";
    leaf binding-ipv6info {
      type union {
        type inet:ipv6-address;
        type inet:ipv6-prefix;
      }
      description
        "The IPv6 information for a binding entry.

         When the IPv6 prefix type is used,
         the IPv6 source address of the CE is constructed
         according to the description in RFC7596.

         If the IPv6 address type is used, the CE can use
         any valid /128 address from a prefix assigned to
         the CE.";
      reference "Section 5.1 of RFC7596.";
    }
    leaf br-ipv6-addr {
      type inet:ipv6-address;
      mandatory true;
      description
        "The IPv6 address of the binding BR.";
    }
  }
  // configuration and stateful parameters for softwire CE interface

  augment "/if:interfaces/if:interface" {
    when "derived-from(if:type, 'iana-tunnel-type:aplusp')";
    description
      "Softwire CE interface configuration";
    leaf softwire-payload-mtu {
      type uint16;
      units "bytes";
      description
        "The payload IPv4 MTU for the softwire tunnel.";
    }
    leaf softwire-path-mru {
      type uint16;
      units "bytes";
      description
        "The path MRU for the softwire (payload + encapsulation
         overhead).";
      reference
        "RFC 4213: Basic Transition Mechanisms for IPv6 Hosts and
                   Routers";
    }
    choice ce-type {
      description
        "Sets the softwire CE mechanism";
      case binding {
        if-feature "binding-mode";
        description
          "CE binding configuration";
        uses binding-entry;
      }
      case algo {
        if-feature "map-e or map-t";
        description
          "CE algorithm configuration";
        container algo-instances {
          description
            "Collection of MAP-E/MAP-T parameters";
          list algo-instance {
            key "name";
            description
              "MAP forwarding rule instance for
               MAP-E/MAP-T";
            leaf name {
              type string;
              mandatory true;
              description
                "The name is used to uniquely identify an algorithm
                 instance.

                 This name can be automatically assigned
                 or explicitly configured.";
            }
            uses softwire-common:algorithm-instance;
          }
        }
      }
    }
  }
  augment "/if:interfaces/if:interface/if:statistics" {
    when "derived-from(../if:type, 'iana-tunnel-type:aplusp')";
    description
      "Softwire CE interface statistics.";
    uses softwire-common:traffic-stat;
  }

  /*
   * Notifications
   */

  notification softwire-ce-event {
    if-feature "binding-mode";
    description
      "CE notification";
    leaf ce-binding-ipv6-addr-change {
      type inet:ipv6-address;
      mandatory true;
      description
        "This notification is generated whenever the CE's binding IPv6
         address changes for any reason.";
    }
  }
}
