// Copyright 2013, Big Switch Networks, Inc.
//
// LoxiGen is licensed under the Eclipse Public License,
// version 1.0 (EPL), with the following special exception:
//
// LOXI Exception
//
// As a special exception to the terms of the EPL, you may
// distribute libraries generated by LoxiGen (LoxiGen Libraries)
// under the terms of your choice, provided that copyright and
// licensing notices generated by LoxiGen are not altered or removed
// from the LoxiGen Libraries and the notice provided below is (i)
// included in the LoxiGen Libraries, if distributed in source code
// form and (ii) included in any documentation for the LoxiGen
// Libraries, if distributed in binary form.
//
// Notice: "Copyright 2013, Big Switch Networks, Inc.
// This library was generated by the LoxiGen Compiler."
//
// You may not use this file except in compliance with the EPL or
// LOXI Exception. You may obtain a copy of the EPL at:
//
// http://www.eclipse.org/legal/epl-v10.html
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an "AS
// IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied. See the EPL for the specific language
// governing permissions and limitations under the EPL.

#version 4
#version 5
#version 6

// Retrieves the checksum for every bucket in a table. The entries are ordered
// by bucket index.
//
// The checksum of a bucket is the sum of the cookies of all entries in the
// bucket. Flows are bucketed based on a prefix of the cookie.
struct of_bsn_flow_checksum_bucket_stats_request : of_bsn_stats_request {
    uint8_t version;
    uint8_t type == 18;
    uint16_t length;
    uint32_t xid;
    uint16_t stats_type == 0xffff;
    enum ofp_stats_request_flags flags;
    pad(4);
    uint32_t experimenter == 0x5c16c7;
    uint32_t subtype == 10;
    uint8_t table_id;
};

struct of_bsn_flow_checksum_bucket_stats_entry {
    uint64_t checksum;
};

struct of_bsn_flow_checksum_bucket_stats_reply : of_bsn_stats_reply {
    uint8_t version;
    uint8_t type == 19;
    uint16_t length;
    uint32_t xid;
    uint16_t stats_type == 0xffff;
    enum ofp_stats_reply_flags flags;
    pad(4);
    uint32_t experimenter == 0x5c16c7;
    uint32_t subtype == 10;
    list(of_bsn_flow_checksum_bucket_stats_entry_t) entries;
};


// Retrieves the checksum for every table.
//
// The checksum of a table is the sum of the cookies of all entries in the
// table.
struct of_bsn_table_checksum_stats_request : of_bsn_stats_request {
    uint8_t version;
    uint8_t type == 18;
    uint16_t length;
    uint32_t xid;
    uint16_t stats_type == 0xffff;
    enum ofp_stats_request_flags flags;
    pad(4);
    uint32_t experimenter == 0x5c16c7;
    uint32_t subtype == 11;
};

struct of_bsn_table_checksum_stats_entry {
    uint8_t table_id;
    uint64_t checksum;
};

struct of_bsn_table_checksum_stats_reply : of_bsn_stats_reply {
    uint8_t version;
    uint8_t type == 19;
    uint16_t length;
    uint32_t xid;
    uint16_t stats_type == 0xffff;
    enum ofp_stats_reply_flags flags;
    pad(4);
    uint32_t experimenter == 0x5c16c7;
    uint32_t subtype == 11;
    list(of_bsn_table_checksum_stats_entry_t) entries;
};


// This message sets the size of the buckets array. The switch may reject this
// message if the table has entries. buckets_size must be a power of 2.
struct of_bsn_table_set_buckets_size : of_bsn_header {
    uint8_t version;
    uint8_t type == 4;
    uint16_t length;
    uint32_t xid;
    uint32_t experimenter == 0x5c16c7;
    uint32_t subtype == 61;
    pad(1);
    uint8_t table_id;
    pad(2);
    uint32_t buckets_size;
};
