/*
 * Copyright (c) 2016 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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 License for the specific language governing permissions and
 * limitations under the License.
 */
/**
 * bier_imposition : The BIER imposition object
 *
 * A BIER imposition object is present in the IP mcast output list
 * and represents the imposition of a BIER bitmask. After BIER header
 * imposition the packet is forward within the appropriate/specified
 * BIER table
 */

#ifndef __BIER_IMPOSITION_H__
#define __BIER_IMPOSITION_H__

#include <vnet/bier/bier_types.h>
#include <vnet/fib/fib_types.h>
#include <vnet/dpo/dpo.h>

/**
 * The BIER imposition object
 */
typedef struct bier_imp_t_ {
    /**
     * Required for pool_get_aligned
     */
    CLIB_CACHE_LINE_ALIGN_MARK(cacheline0);

    /**
     * The DPO contributed from the resolving BIER table.
     * One per-IP protocol. This allows us to share a BIER imposition
     * object for a IPv4 and IPv6 mfib path.
     */
    dpo_id_t bi_dpo[FIB_PROTOCOL_IP_MAX];

    /**
     * The Header to impose.
     */
    bier_hdr_t bi_hdr;

    /**
     * The bit string.
     *  This is a memory v. speed tradeoff. We inline here the
     *  largest header type so as the bitstring is on the same
     *  cacheline as the header.
     */
    u8 bi_bits[BIER_HDR_BUCKETS_1024];

    /**
     * The BIER table into which to forward the post imposed packet
     */
    bier_table_id_t bi_tbl;

    /**
     * number of locks
     */
    u32 bi_locks;

} bier_imp_t;

extern index_t bier_imp_add_or_lock(const bier_table_id_t *bt,
                                    bier_bp_t sender,
                                    const bier_bit_string_t *bs);

extern void bier_imp_unlock(index_t bii);
extern void bier_imp_lock(index_t bii);

extern u8* format_bier_imp(u8* s, va_list *ap);

extern void bier_imp_contribute_forwarding(index_t bii,
                                           dpo_proto_t proto,
                                           dpo_id_t *dpo);

extern bier_imp_t *bier_imp_pool;

always_inline bier_imp_t*
bier_imp_get (index_t bii)
{
    return (pool_elt_at_index(bier_imp_pool, bii));
}

#endif
