module opendaylight-table-types {
    namespace "urn:opendaylight:table:types";
    prefix table;

    import opendaylight-flow-types {prefix flow;revision-date "2013-10-26";}
    import opendaylight-action-types {prefix action;}
    import opendaylight-multipart-types { prefix multipart; revision-date "2017-01-12"; }

    revision "2013-10-26" {
        description "Initial revision of table service";
    }

    typedef table-id {
        type uint8;
    }

    typedef table-ref {
        type instance-identifier;
    }

    typedef table-config {
        type bits {
            bit DEPRECATED-MASK;
        }
    }

    // field types
    identity match-field {
        description "Base identity for match Fields";
    }

    identity in_port {
        base match-field;
        description "Match for Switch input port.";
    }
    identity in_phy_port {
        base match-field;
        description "Match for Switch physical input port.";
    }
    identity metadata {
        base match-field;
        description "Match for Metadata passed between tables.";
    }
    identity eth_dst {
        base match-field;
        description "Match for Ethernet destination address.";
    }
    identity eth_src {
        base match-field;
        description "Match for Ethernet source address.";
    }
    identity eth_type {
        base match-field;
        description "Match for Ethernet frame type.";
    }
    identity vlan_vid {
        base match-field;
        description "Match for VLAN id.";
    }
    identity vlan_pcp {
        base match-field;
        description "Match for VLAN priority.";
    }
    identity ip_dscp {
        base match-field;
        description "Match for IP DSCP (6 bits in ToS field).";
    }
    identity ip_ecn {
        base match-field;
        description "Match for IP ECN (2 bits in ToS field).";
    }
    identity ip_proto {
        base match-field;
        description "Match for IP protocol.";
    }
    identity ipv4_src {
        base match-field;
        description "Match for IPv4 source address.";
    }
    identity ipv4_dst {
        base match-field;
        description "Match for IPv4 destination address.";
    }
    identity tcp_src {
        base match-field;
        description "Match for TCP source port.";
    }
    identity tcp_dst {
        base match-field;
        description "Match for TCP destination port.";
    }
    identity udp_src {
        base match-field;
        description "Match for UDP source port.";
    }
    identity udp_dst {
        base match-field;
        description "Match for UDP destination port.";
    }
    identity sctp_src {
        base match-field;
        description "Match for SCTP source port.";
    }
    identity sctp_dst {
        base match-field;
        description "Match for SCTP destination port.";
    }
    identity icmpv4_type {
        base match-field;
        description "Match for ICMP type.";
    }
    identity icmpv4_code {
        base match-field;
        description "Match for ICMP code.";
    }
    identity arp_op {
        base match-field;
        description "Match for ARP opcode.";
    }
    identity arp_spa {
        base match-field;
        description "Match for ARP source IPv4 address.";
    }
    identity arp_tpa {
        base match-field;
        description "Match for ARP target IPv4 address.";
    }
    identity arp_sha {
        base match-field;
        description "Match for ARP source hardware address.";
    }
    identity arp_tha {
        base match-field;
        description "Match for ARP target hardware address.";
    }
    identity ipv6_src {
        base match-field;
        description "Match for IPv6 source address.";
    }
    identity ipv6_dst {
        base match-field;
        description "Match for IPv6 destination address.";
    }
    identity ipv6_flabel {
        base match-field;
        description "Match for IPv6 Flow Label";
    }
    identity icmpv6_type {
        base match-field;
        description "Match for ICMPv6 type.";
    }
    identity icmpv6_code {
        base match-field;
        description "Match for ICMPv6 code.";
    }
    identity ipv6_nd_target {
        base match-field;
        description "Match for Target address for ND.";
    }
    identity ipv6_nd_sll {
        base match-field;
        description "Match for Source link-layer for ND.";
    }
    identity ipv6_nd_tll {
        base match-field;
        description "Match for Target link-layer for ND.";
    }
    identity mpls_label {
        base match-field;
        description "Match for MPLS label.";
    }
    identity mpls_tc {
        base match-field;
        description "Match for MPLS TC.";
    }
    identity mpls_bos {
        base match-field;
        description "Match for MPLS BoS bit.";
    }
    identity pbb_isid {
        base match-field;
        description "Match for PBB I-SID.";
    }
    identity tunnel_id {
        base match-field;
        description "Match for Logical Port Metadata";
    }
    identity ipv6_exthdr {
        base match-field;
        description "Match for IPv6 Extension Header pseudo-field";
    }
    identity tcp_flags {
        base match-field;
        description "TCP Flags Match";
    }
    identity tunnel_ipv4_dst {
        base match-field;
        description "IPv4 destination tunnel endpoint address.";
    }
    identity tunnel_ipv4_src {
        base match-field;
        description "IPv4 source tunnel endpoint address.";
    }

    grouping set-field-match {
        list set-field-match {
        key "match-type";
            leaf match-type {
                type identityref {
                    base match-field;
                }
            }
            leaf has-mask {
                type boolean;
            }
        }
    }

    grouping table-feature-prop-type {
        choice table-feature-prop-type {
            case instructions {
                container instructions {
                    uses flow:instruction-list;
                }
            }

            case instructions-miss {
                container instructions-miss {
                    uses flow:instruction-list;
                }
            }

            case next-table {
                container tables {
                    leaf-list table-ids {
                        type uint8;
                        ordered-by user;
                    }
                }
            }

            case next-table-miss {
                container tables-miss {
                    leaf-list table-ids {
                        type uint8;
                        ordered-by user;
                    }
                }
            }

            case write-actions {
                container write-actions {
                    uses action:action-list;
                }
            }

            case write-actions-miss {
                container write-actions-miss {
                    uses action:action-list;
                }
            }

            case apply-actions {
                container apply-actions {
                    uses action:action-list;
                }
            }

            case apply-actions-miss {
                container apply-actions-miss {
                    uses action:action-list;
                }
            }

            case match {
                container match-setfield {
                    uses set-field-match;
                }
            }

            case wildcards {
                container wildcard-setfield {
                    uses set-field-match;
                }
            }

            case write-setfield {
                container write-setfield {
                    uses set-field-match;
                }
            }

            case write-setfield-miss {
                container write-setfield-miss {
                    uses set-field-match;
                }
            }

            case apply-setfield {
                container apply-setfield {
                    uses set-field-match;
                }
            }

            case apply-setfield-miss {
                container apply-setfield-miss {
                    uses set-field-match;
                }
            }
        }
    }

    grouping table-features {
        list table-features {
            key "table-id";

            leaf table-id {
                type uint8;
            }

            leaf name {
                description "Name of the table";
                type string;
            }

            leaf metadata-match {
                description "Bits of metadata table can match";
                type uint64;
            }

            leaf metadata-write {
                description "Bits of metadata table can write";
                type uint64;
            }

            leaf max-entries {
                description "Max number of entries supported";
                type uint32;
            }

            leaf config {
                description "Bitmap of OFPTC_ values";
                type table-config;
            }

            container table-properties {
                list table-feature-properties {
                     key "order";
                     uses action:ordered;
                     uses table-feature-prop-type;
                }
            }
        }
    }

    augment "/multipart:multipart-reply/multipart:multipart-reply-body" {
        case multipart-reply-table-features {
            uses table-features;
        }
    }

    augment "/multipart:multipart-request/multipart:multipart-request-body" {
        case multipart-request-table-features {
            uses table-features;
        }
    }
}