module openflowplugin-extension-nicira-match {
    yang-version 1;

    namespace "urn:opendaylight:openflowplugin:extension:nicira:match";
    prefix "openflowplugin-nicira-match";

    import yang-ext {prefix ext; revision-date "2013-07-09";}
    import flow-node-inventory {prefix fni; revision-date 2013-08-19; }
    import opendaylight-inventory {prefix inv;revision-date "2013-08-19";}
    import sal-flow {prefix sal-flow;revision-date "2013-08-19";}
    import packet-processing {prefix sal-packet;revision-date "2013-07-09";}
    import openflowplugin-extension-general {prefix ext-gen;revision-date "2014-07-14";}
    import opendaylight-flow-statistics {prefix odl-flow-stats;revision-date "2013-08-19";}
    import opendaylight-direct-statistics {prefix odl-direct-stats;revision-date "2016-05-11";}
    import nicira-match {prefix nicira-match;revision-date "2014-04-21";}
    import ietf-inet-types {prefix inet; revision-date "2013-07-15";}
    import ietf-yang-types {prefix yang; revision-date "2013-07-15";}

    description
        "Nicira openflow match extensions.";

    revision "2014-07-14" {
        description "Initial revision";
    }

    identity nxm-nx-reg0-key {
        base ext-gen:extension-key;
    }
    identity nxm-nx-reg1-key {
        base ext-gen:extension-key;
    }
    identity nxm-nx-reg2-key {
        base ext-gen:extension-key;
    }
    identity nxm-nx-reg3-key {
        base ext-gen:extension-key;
    }
    identity nxm-nx-reg4-key {
        base ext-gen:extension-key;
    }
    identity nxm-nx-reg5-key {
        base ext-gen:extension-key;
    }
    identity nxm-nx-reg6-key {
        base ext-gen:extension-key;
    }
    identity nxm-nx-reg7-key {
        base ext-gen:extension-key;
    }
    identity nxm-nx-tun-id-key {
        base ext-gen:extension-key;
    }
    identity nxm-nx-arp-sha-key {
        base ext-gen:extension-key;
    }
    identity nxm-nx-arp-tha-key {
        base ext-gen:extension-key;
    }
    identity nxm-of-arp-op-key {
        base ext-gen:extension-key;
    }
    identity nxm-of-arp-spa-key {
        base ext-gen:extension-key;
    }
    identity nxm-of-arp-tpa-key {
        base ext-gen:extension-key;
    }
    identity nxm-of-in-port-key {
        base ext-gen:extension-key;
    }
    identity nxm-nx-tun-ipv4-dst-key {
        base ext-gen:extension-key;
    }
    identity nxm-nx-tun-ipv4-src-key {
        base ext-gen:extension-key;
    }
    identity nxm-of-eth-src-key {
        base ext-gen:extension-key;
    }
    identity nxm-of-eth-dst-key {
        base ext-gen:extension-key;
    }
    identity nxm-of-eth-type-key {
        base ext-gen:extension-key;
    }
    identity nxm-nx-nsp-key {
        base ext-gen:extension-key;
    }
    identity nxm-nx-nsi-key {
        base ext-gen:extension-key;
    }
    identity nxm-nx-nshc-1-key {
        base ext-gen:extension-key;
    }
    identity nxm-nx-nshc-2-key {
        base ext-gen:extension-key;
    }
    identity nxm-nx-nshc-3-key {
        base ext-gen:extension-key;
    }
    identity nxm-nx-nshc-4-key {
        base ext-gen:extension-key;
    }
    identity nxm-of-tcp-src-key {
        base ext-gen:extension-key;
    }
    identity nxm-of-tcp-dst-key {
        base ext-gen:extension-key;
    }
    identity nxm-of-udp-src-key {
        base ext-gen:extension-key;
    }
    identity nxm-of-udp-dst-key {
        base ext-gen:extension-key;
    }
    identity nxm-nx-ct-mark-key {
        base ext-gen:extension-key;
    }
    identity nxm-nx-ct-state-key {
        base ext-gen:extension-key;
    }
    identity nxm-nx-ct-zone-key {
        base ext-gen:extension-key;
    }
    identity nxm-nx-ct-tp-src-key {
        base ext-gen:extension-key;
    }
    identity nxm-nx-ct-tp-dst-key {
        base ext-gen:extension-key;
    }
    identity nxm-nx-pkt-mark-key {
        base ext-gen:extension-key;
    }
    identity nxm-of-ip-dst-key {
        base ext-gen:extension-key;
    }
    identity nxm-of-ip-src-key {
        base ext-gen:extension-key;
    }
    identity nxm-of-icmp-type-key {
        base ext-gen:extension-key;
    }
    identity nxm-nx-nsh-flags-key {
        base ext-gen:extension-key;
    }
    identity nxm-nx-nsh-mdtype-key {
        base ext-gen:extension-key;
    }
    identity nxm-nx-nsh-np-key {
        base ext-gen:extension-key;
    }
    identity nxm-nx-nsh-ttl-key {
        base ext-gen:extension-key;
    }
    grouping ipv4-address-grouping {
        leaf ipv4-address {
            type inet:ipv4-address;
        }
    }
    grouping mac-address-grouping {
        leaf mac-address {
            type yang:mac-address;
        }
    }

    grouping nxm-nx-reg-grouping {
        container nxm-nx-reg {
            leaf reg {
                type identityref {
                    base nicira-match:nxm-nx-reg;
                }
            }
            leaf value {
                type uint32;
            }
            leaf mask {
                type uint32;
            }
        }
    }
    grouping nxm-nx-tun-id-grouping {
        container nxm-nx-tun-id {
            leaf value {
                type uint64;
            }
        }
    }
    grouping nxm-nx-arp-sha-grouping {
        container nxm-nx-arp-sha {
            uses mac-address-grouping;
        }
    }
    grouping nxm-nx-arp-tha-grouping {
        container nxm-nx-arp-tha {
            uses mac-address-grouping;
        }
    }
    grouping nxm-of-arp-op-grouping {
        container nxm-of-arp-op {
            description "Prereqs: NXM_OF_ETH_TYPE must match either 0x0806 or 0x8035.";
            leaf value {
                type uint16;
            }
        }
    }
    grouping nxm-of-arp-spa-grouping {
        container nxm-of-arp-spa {
            description "Prereqs: NXM_OF_ETH_TYPE must match either 0x0806 or 0x8035.";
            uses ipv4-address-grouping;
        }
    }
    grouping nxm-of-in-port-grouping {
        container of-in-port {
            leaf value {
                type uint16;
            }
        }
    }
    grouping nxm-of-tcp-src-grouping {
        container nxm-of-tcp-src {
            leaf port {
               type inet:port-number;
            }
            leaf mask {
               type uint16;
            }
        }
    }
    grouping nxm-of-tcp-dst-grouping {
        container nxm-of-tcp-dst {
            leaf port {
                type inet:port-number;
            }
            leaf mask {
               type uint16;
            }
        }
    }
    grouping nxm-of-udp-src-grouping {
        container nxm-of-udp-src {
            leaf port {
               type inet:port-number;
            }
            leaf mask {
               type uint16;
            }
        }
    }
    grouping nxm-of-udp-dst-grouping {
        container nxm-of-udp-dst {
            leaf port {
                        type inet:port-number;
            }
            leaf mask {
               type uint16;
            }
        }
    }
    grouping nxm-of-arp-tpa-grouping {
        container nxm-of-arp-tpa {
            description "Prereqs: NXM_OF_ETH_TYPE must match either 0x0806 or 0x8035.";
            uses ipv4-address-grouping;
        }
    }
    grouping nxm-nx-tun-ipv4-dst-grouping {
        container nxm-nx-tun-ipv4-dst {
            uses ipv4-address-grouping;
        }
    }
    grouping nxm-nx-tun-ipv4-src-grouping {
        container nxm-nx-tun-ipv4-src {
            uses ipv4-address-grouping;
        }
    }
    grouping nxm-of-eth-src-grouping {
        container nxm-of-eth-src {
            uses mac-address-grouping;
        }
    }
    grouping nxm-of-eth-dst-grouping {
        container nxm-of-eth-dst {
            uses mac-address-grouping;
        }
    }
    grouping nxm-of-eth-type-grouping {
        container nxm-of-eth-type {
            leaf value {
                type uint16;
            }
        }
    }
    grouping nxm-nx-nsp-grouping {
        container nxm-nx-nsp {
            leaf value {
                type uint32;
            }
        }
    }
    grouping nxm-nx-nsi-grouping {
        container nxm-nx-nsi {
            leaf nsi {
                type uint8;
            }
        }
    }
    grouping nxm-nx-nshc-1-grouping {
        container nxm-nx-nshc-1 {
            leaf value {
                type uint32;
            }
            leaf mask {
                type uint32;
            }
        }
    }
    grouping nxm-nx-nshc-2-grouping {
        container nxm-nx-nshc-2 {
            leaf value {
                type uint32;
            }
            leaf mask {
                type uint32;
            }
        }
    }
    grouping nxm-nx-nshc-3-grouping {
        container nxm-nx-nshc-3 {
            leaf value {
                type uint32;
            }
            leaf mask {
                type uint32;
            }
        }
    }
    grouping nxm-nx-nshc-4-grouping {
        container nxm-nx-nshc-4 {
            leaf value {
                type uint32;
            }
            leaf mask {
                type uint32;
            }
        }
    }
    grouping nxm-nx-ct-state-grouping {
         container nxm-nx-ct-state {
            leaf ct-state {
               type uint32;
            }
             leaf mask {
               type uint32;
            }
        }
    }
    grouping nxm-nx-ct-zone-grouping {
         container nxm-nx-ct-zone {
            leaf ct-zone {
               type uint16;
            }
        }
    }
    grouping nxm-of-ip-dst-grouping {
        container nxm-of-ip-dst {
            uses ipv4-address-grouping;
        }
    }
    grouping nxm-of-ip-src-grouping {
        container nxm-of-ip-src {
            uses ipv4-address-grouping;
        }
    }
    grouping nxm-of-icmp-type-grouping {
        container nxm-of-icmp-type {
            leaf value {
                type uint8;
            }
        }
    }
    grouping nxm-nx-nsh-flags-grouping {
        container nxm-nx-nsh-flags {
            leaf nsh-flags {
                type uint8;
            }
            leaf mask {
                type uint8;
            }
        }
    }
    grouping nxm-nx-nsh-mdtype-grouping {
        container nxm-nx-nsh-mdtype {
            leaf value {
                type uint8;
            }
        }
    }
    grouping nxm-nx-nsh-np-grouping {
        container nxm-nx-nsh-np {
            leaf value {
                type uint8;
            }
        }
    }
    grouping nxm-nx-nsh-ttl-grouping {
        container nxm-nx-nsh-ttl {
            leaf nsh-ttl {
                type uint8;
            }
        }
    }
    grouping nxm-nx-ct-mark-grouping {
        container nxm-nx-ct-mark {
            leaf ct-mark {
               type uint32;
            }
            leaf mask {
               type uint32;
            }
        }
    }
    grouping nxm-nx-ct-tp-src-grouping {
        container nxm-nx-ct-tp-src {
            leaf ct-tp-src {
               type uint16;
            }
            leaf mask {
               type uint16;
            }
        }
    }
    grouping nxm-nx-ct-tp-dst-grouping {
        container nxm-nx-ct-tp-dst {
            leaf ct-tp-dst {
               type uint16;
            }
            leaf mask {
               type uint16;
            }
        }
    }
    grouping nxm-nx-pkt-mark-grouping {
        container nxm-nx-pkt-mark {
            leaf pkt-mark {
               type uint32;
            }
            leaf mask {
               type uint32;
            }
        }
    }

    grouping all-matches-grouping {
        uses nxm-nx-reg-grouping;
        uses nxm-nx-tun-id-grouping;
        uses nxm-nx-arp-sha-grouping;
        uses nxm-nx-arp-tha-grouping;
        uses nxm-of-arp-op-grouping;
        uses nxm-of-arp-spa-grouping;
        uses nxm-of-arp-tpa-grouping;
        uses nxm-of-in-port-grouping;
        uses nxm-nx-tun-ipv4-dst-grouping;
        uses nxm-nx-tun-ipv4-src-grouping;
        uses nxm-of-eth-src-grouping;
        uses nxm-of-eth-dst-grouping;
        uses nxm-of-eth-type-grouping;
        uses nxm-nx-nsp-grouping;
        uses nxm-nx-nsi-grouping;
        uses nxm-nx-nshc-1-grouping;
        uses nxm-nx-nshc-2-grouping;
        uses nxm-nx-nshc-3-grouping;
        uses nxm-nx-nshc-4-grouping;
        uses nxm-nx-nsh-flags-grouping;
        uses nxm-nx-nsh-mdtype-grouping;
        uses nxm-nx-nsh-np-grouping;
        uses nxm-nx-nsh-ttl-grouping;
        uses nxm-of-tcp-src-grouping;
        uses nxm-of-tcp-dst-grouping;
        uses nxm-of-udp-src-grouping;
        uses nxm-of-udp-dst-grouping;
        uses nxm-nx-ct-state-grouping;
        uses nxm-nx-ct-zone-grouping;
        uses nxm-of-ip-dst-grouping;
        uses nxm-of-ip-src-grouping;
        uses nxm-of-icmp-type-grouping;
        uses nxm-nx-ct-mark-grouping;
        uses nxm-nx-ct-tp-src-grouping;
        uses nxm-nx-ct-tp-dst-grouping;
        uses nxm-nx-pkt-mark-grouping;
    }

    // MATCH augmentations
    // RPCS
    augment "/sal-flow:add-flow/sal-flow:input/sal-flow:match/ext-gen:extension-list/ext-gen:extension" {
        ext:augment-identifier "nx-aug-match-rpc-add-flow";
        uses all-matches-grouping;
    }
    augment "/sal-flow:remove-flow/sal-flow:input/sal-flow:match/ext-gen:extension-list/ext-gen:extension" {
        ext:augment-identifier "nx-aug-match-rpc-remove-flow";
        uses all-matches-grouping;
    }
    augment "/sal-flow:update-flow/sal-flow:input/sal-flow:original-flow/sal-flow:match/ext-gen:extension-list/ext-gen:extension" {
        ext:augment-identifier "nx-aug-match-rpc-update-flow-original";
        uses all-matches-grouping;
    }
    augment "/sal-flow:update-flow/sal-flow:input/sal-flow:updated-flow/sal-flow:match/ext-gen:extension-list/ext-gen:extension" {
        ext:augment-identifier "nx-aug-match-rpc-update-flow-updated";
        uses all-matches-grouping;
    }

    // DATA
    augment "/inv:nodes/inv:node/fni:table/fni:flow/fni:match/ext-gen:extension-list/ext-gen:extension" {
        ext:augment-identifier "nx-aug-match-nodes-node-table-flow";
        uses all-matches-grouping;
    }
    augment "/sal-packet:packet-in-message/sal-packet:match/ext-gen:extension-list/ext-gen:extension" {
        ext:augment-identifier "nx-aug-match-packet-in-message";
        uses all-matches-grouping;
    }

    // NOTIFICATIONS
    augment "/sal-flow:switch-flow-removed/sal-flow:match/ext-gen:extension-list/ext-gen:extension" {
        ext:augment-identifier "nx-aug-match-notif-switch-flow-removed";
        uses all-matches-grouping;
    }
    augment "/sal-packet:packet-received/sal-packet:match/ext-gen:extension-list/ext-gen:extension" {
        ext:augment-identifier "nx-aug-match-notif-packet-in";
        uses all-matches-grouping;
    }
    augment "/odl-flow-stats:flows-statistics-update/odl-flow-stats:flow-and-statistics-map-list/odl-flow-stats:match/ext-gen:extension-list/ext-gen:extension" {
        ext:augment-identifier "nx-aug-match-notif-update-flow-stats";
        uses all-matches-grouping;
    }
    augment "/odl-direct-stats:get-flow-statistics/odl-direct-stats:output/odl-direct-stats:flow-and-statistics-map-list/odl-direct-stats:match/ext-gen:extension-list/ext-gen:extension" {
        ext:augment-identifier "nx-aug-match-rpc-get-flow-stats";
        uses all-matches-grouping;
    }

}