module ietf-if-l3-vlan {
  yang-version 1.1;

  namespace "urn:ietf:params:xml:ns:yang:ietf-if-l3-vlan";

  prefix if-l3-vlan;

  import ietf-interfaces {
    prefix if;
  }

  import iana-if-type {
    prefix ianaift;
  }

  import ieee802-dot1q-types {
    prefix dot1q-types;
  }

  import ietf-interfaces-common {
    prefix if-cmn;
  }

  organization
    "IETF NETMOD (NETCONF Data Modeling Language) Working Group";

  contact
    "WG Web:   <http://tools.ietf.org/wg/netmod/>
     WG List:  <mailto:netmod@ietf.org>

     WG Chair: Lou Berger
               <mailto:lberger@labn.net>

     WG Chair: Kent Watsen
               <mailto:kwatsen@juniper.net>

     Editor:   Robert Wilton
               <mailto:rwilton@cisco.com>";

  description
    "This YANG module models L3 VLAN sub-interfaces";
  revision 2017-07-03 {
    description "Latest draft revision";

    reference
      "Internet-Draft draft-ietf-netmod-sub-intf-vlan-model-02";
  }

  /*
   * Add support for the 802.1Q VLAN encapsulation syntax on layer 3
   * terminated VLAN sub-interfaces.
   */
  augment "/if:interfaces/if:interface/if-cmn:encapsulation/" +
          "if-cmn:encaps-type" {
    when
        "derived-from-or-self(../if:type,
                              'ianaift:ethernetCsmacd') or
         derived-from-or-self(../if:type,
                              'ianaift:ieee8023adLag') or
         derived-from-or-self(../if:type,
                              'if-cmn:ethSubInterface')" {
      description
        "Applies only to Ethernet-like interfaces and
         sub-interfaces";
    }

    description
      "Augment the generic interface encapsulation with an
       basic 802.1Q VLAN encapsulation for sub-interfaces.";

    /*
     * Matches a single VLAN Id, or pair of VLAN Ids to classify
     * traffic into an L3 service.
     */
    case dot1q-vlan {
      container dot1q-vlan {
        must
          'count(../../if-cmn:forwarding-mode) = 0 or ' +
          'derived-from-or-self(../../if-cmn:forwarding-mode,' +
                                '"if-cmn:layer-3-forwarding")' {
            error-message
              "If the interface forwarding-mode leaf is set then it
               must be set to an identity that derives from
               layer-3-forwarding";

            description
              "The forwarding-mode leaf on an interface can
               optionally be used to enforce consistency of
               configuration";
          }

        description
          "Match VLAN tagged frames with specific VLAN Ids";
        container outer-tag {
          presence "The outermost VLAN tag exists";

          description
            "Classifies traffic using the outermost VLAN tag on the
             frame.";

          uses dot1q-types:dot1q-tag-classifier-grouping;
        }

        container second-tag {
          must
            '../outer-tag/dot1q-tag/tag-type = "s-vlan" and ' +
            'dot1q-tag/tag-type = "c-vlan"' {

            error-message
              "When matching two tags, the outermost tag must be
               specified and of S-VLAN type and the second outermost
               tag must be of C-VLAN tag type";

            description
              "For IEEE 802.1Q interoperability, when matching two
               tags, it is required that the outermost tag exists and
               is an S-VLAN, and the second outermost tag is a
               C-VLAN";
          }

          presence "The second outermost VLAN tag exists";

          description
            "Classifies traffic using the second outermost VLAN tag
             on the frame.";

          uses dot1q-types:dot1q-tag-classifier-grouping;
        }
      }
    }
  }
}
