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

  import ietf-inet-types {
    prefix inet;
    reference
      "Section 4 of RFC 6991";
  }

  import ietf-yang-types {
    prefix yang;
    reference
      "Section 3 of RFC 6991";
  }

  organization
    "IETF Softwire Working Group";

  contact
    "WG Web:   <https://datatracker.ietf.org/wg/softwire/>
     WG List:  <mailto:softwire@ietf.org>

    Qi Sun <sunqi.ietf@gmail.com>
    Linhui Sun <lh.sunlinh@gmail.com>
    Yong Cui <yong@csnet1.cs.tsinghua.edu.cn>
    Ian Farrer <ian.farrer@telekom.de>
    Sladjana Zoric <sladjana.zoric@telekom.de>
    Mohamed Boucadair <mohamed.boucadair@orange.com>
    Rajiv <Asati rajiva@cisco.com>
    ";

  description
    "This document defines a YANG data module defining types
     common to all A+P modules.

    Copyright (c) 2018 IETF Trust and the persons identified
    as authors of the code. All rights reserved.
    This version of this YANG module is part of RFC XXXX; see the RFC
    itself for full legal notices.";

  revision 2018-10-19 {
    description
      "Initial revision.";
    reference
      "RFC XXXX: YANG Modules for IPv4-in-IPv6 Address plus Port
                 Softwires";
  }

  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 instance functions as a MAP-E.";

    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 instance functions as a MAP-T instance.";

    reference
       "RFC7599: Mapping of Address and Port using Translation (MAP-T)";
  }

  /*
   * Groupings
   */

  grouping algorithm-instance {
    description
      "Indicates that the instance supports the MAP-E and/or MAP-T
      function. The instance advertises the MAP-E/MAP-T feature
      through the capability exchange mechanism when a NETCONF
      session is established.";

    leaf enable {
      type boolean;
      description
        "Enable/disable an individual MAP-E or MAP-T rule.";
    }
    container algo-versioning {
      description "algorithm's version";
      leaf version {
        type uint64;
        description "Incremental version number for the algorithm";
      }
      leaf date {
        type yang:date-and-time;
        description "Timestamp when the algorithm instance was activated.";
      }
    }
    leaf name {
      type string;
      description "The name for the instance.";
    }
    choice data-plane {
      description "Selects MAP-E (encapsulation) or MAP-T
      (translation)";
      case encapsulation {
        if-feature map-e;
        description "encapsulation for MAP-E";
        leaf br-ipv6-addr {
          type inet:ipv6-address;
          mandatory true;
          description
            "The IPv6 address of the MAP-E BR.";
        }
      }
      case translation {
        if-feature map-t;
        description "translation for MAP-T";
        leaf dmr-ipv6-prefix {
          type inet:ipv6-prefix;
          description
            "The IPv6 prefix of the MAP-T BR.";
        }
      }
    }
    leaf ea-len {
      type uint8;
      mandatory true;
      description
        "Embedded Address (EA) bits are the IPv4 EA-bits in the IPv6
        address identifying an IPv4 prefix/address (or part thereof) or
        a shared IPv4 address (or part thereof) and a port-set
        identifier. The length of the EA-bits is defined as part of
        a MAP rule for a MAP domain.";
    }
    leaf rule-ipv6-prefix {
      type inet:ipv6-prefix;
      mandatory true;
      description
        "The Rule IPv6 prefix defined in the mapping rule.";
    }
    leaf rule-ipv4-prefix {
      type inet:ipv4-prefix;
      mandatory true;
      description
        "The Rule IPv4 prefix defined in the mapping rule.";
    }
    leaf forwarding {
      type boolean;
      mandatory true;
      description
        "This parameter specifies whether the rule may be used for
        forwarding (FMR). If set, this rule is used as an FMR;
        if not set, this rule is a Basic Mapping Rule (BMR) only
        and must not be used for forwarding.";
    }
  }

  grouping traffic-stat {
    description "Traffic statistics";
    leaf sent-ipv4-packets {
      type yang:zero-based-counter64;
      description "Number of decapsulated and forwarded IPv4 packets.

      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'.";
    }
    leaf sent-ipv4-bytes {
      type yang:zero-based-counter64;
      description "Decapsulated/translated IPv4 traffic sent, in bytes

      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'.";
    }
    leaf sent-ipv6-packets {
      type yang:zero-based-counter64;
      description "Number of encapsulated IPv6 packets sent.

      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'.";
    }
    leaf sent-ipv6-bytes {
      type yang:zero-based-counter64;
      description "Encapsulated IPv6 traffic sent, in bytes

      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'.";
    }
    leaf rcvd-ipv4-packets {
      type yang:zero-based-counter64;
      description "Number of incoming IPv4 packets at the
      Internet-facing interface.

      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'.";
    }
    leaf rcvd-ipv4-bytes {
      type yang:zero-based-counter64;
      description "IPv4 traffic received for processing, in bytes.

      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'.";
    }
    leaf rcvd-ipv6-packets {
      type yang:zero-based-counter64;
      description "Number of IPv4-in-IPv6 packets received.

      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'.";
    }
    leaf rcvd-ipv6-bytes {
      type yang:zero-based-counter64;
      description "IPv4-in-IPv6 traffic received, in bytes.

      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'.";
    }
    leaf dropped-ipv4-packets {
      type yang:zero-based-counter64;
      description "Number of IPv4 packets dropped at the
      Internet-facing interface.

      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'.";
    }
    leaf dropped-ipv4-bytes {
      type yang:zero-based-counter64;
      description "IPv4 traffic dropped at the Internet-facing
      interface, in bytes.
      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'.";
    }
    leaf dropped-ipv6-packets {
      type yang:zero-based-counter64;
      description "Number of IPv4-in-IPv6 packets dropped.

      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'.";
    }
    leaf dropped-ipv6-bytes {
      type yang:zero-based-counter64;
      description "IPv4-in-IPv6 traffic dropped, in bytes.

      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'.";
    }
    leaf dropped-ipv4-fragments {
      type yang:zero-based-counter64;
      description "Number of fragmented IPv4 packets dropped.

      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'.";
    }
    leaf dropped-ipv4-fragment-bytes {
      type yang:zero-based-counter64;
      description "Fragmented IPv4 traffic dropped, in bytes.

      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'.";
    }
    leaf ipv6-fragments-reassembled {
      type yang:zero-based-counter64;
      description "Number of IPv6 fragments successfully reassembled.

      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'.";
    }
    leaf ipv6-fragments-bytes-reassembled {
      type yang:zero-based-counter64;
      description "IPv6 fragments successfully reassembled, in bytes.

      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'.";
    }
    leaf out-icmpv4-error-packets {
      type yang:zero-based-counter64;
      description "Internally generated ICMPv4 error packets.

      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'.";
    }
    leaf out-icmpv4-error-bytes {
      type yang:zero-based-counter64;
      description "Internally generated ICMPv4 error messages, in bytes.

      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'.";
    }
    leaf out-icmpv6-error-packets {
      type yang:zero-based-counter64;
      description "Internally generated ICMPv6 error packets.

      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'.";
    }
    leaf out-icmpv6-error-bytes {
      type yang:zero-based-counter64;
      description "Internally generated ICMPv6 error messages, in bytes.

      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'.";
    }
  }
}
