/* * Copyright (c) 2015 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. */ /* Copyright (c) 2010 Eliot Dresselhaus Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #if 0 #ifdef __OPTIMIZE__ #undef CLIB_DEBUG #endif #endif #include #include #include #include #include #include #ifdef CLIB_HAVE_VEC128 typedef struct { u32 n_iter; u32 seed; u32 verbose; u32 n_keys; u32 log2_size; u32 n_key_u32; u32 n_vectors_div_4; u32 n_vectors_mod_4; u32 *keys; u32 *results; u32 *vhash_get_key_indices; u32 *vhash_get_results; u32 *vhash_key_indices; u32 *vhash_results; vhash_t vhash; uword **key_hash; struct { u64 n_clocks; u64 n_vectors; u64 n_calls; } get_stats, set_stats, unset_stats; } test_vhash_main_t; always_inline u32 test_vhash_key_gather (void *_tm, u32 vi, u32 wi, u32 n_key_u32s) { test_vhash_main_t *tm = _tm; ASSERT (n_key_u32s == tm->n_key_u32); ASSERT (wi < n_key_u32s); vi = vec_elt (tm->vhash_key_indices, vi); return vec_elt (tm->keys, vi * n_key_u32s + wi); } always_inline u32x4 test_vhash_4key_gather (void *_tm, u32 vi, u32 wi, u32 n_key_u32s) { test_vhash_main_t *tm = _tm; u32 *p; u32x4_union_t x; ASSERT (n_key_u32s == tm->n_key_u32); ASSERT (wi < n_key_u32s); p = vec_elt_at_index (tm->vhash_key_indices, vi + 0); x.as_u32[0] = tm->keys[p[0] * n_key_u32s + wi]; x.as_u32[1] = tm->keys[p[1] * n_key_u32s + wi]; x.as_u32[2] = tm->keys[p[2] * n_key_u32s + wi]; x.as_u32[3] = tm->keys[p[3] * n_key_u32s + wi]; return x.as_u32x4; } always_inline u32 test_vhash_get_result (void *_tm, u32 vector_index, u32 result_index, u32 n_key_u32s) { test_vhash_main_t *tm = _tm; u32 *p = vec_elt_at_index (tm->vhash_results, vector_index); p[0] = result_index; return result_index; } always_inline u32x4 test_vhash_get_4result (void *_tm, u32 vector_index, u32x4 results, u32 n_key_u32s) { test_vhash_main_t *tm = _tm; u32 *p = vec_elt_at_index (tm->vhash_results, vector_index); *(u32x4 *) p = results; return results; } always_inline u32 test_vhash_set_result (void *_tm, u32 vector_index, u32 old_result, u32 n_key_u32s) { test_vhash_main_t *tm = _tm; u32 *p = vec_elt_at_index (tm->vhash_results, vector_index); u32 new_result = p[0]; p[0] = old_result; return new_result; } always_inline u32 test_vhash_unset_result (void *_tm, u32 i, u32 old_result, u32 n_key_u32s) { test_vhash_main_t *tm = _tm; u32 *p = vec_elt_at_index (tm->vhash_results, i); p[0] = old_result; return 0; } #define _(N_KEY_U32) \ always_inline u32 \ test_vhash_key_gather_##N_KEY_U32 (void * _tm, u32 vi, u32 i) \ { return test_vhash_key_gather (_tm, vi, i, N_KEY_U32); } \ \ always_inline u32x4 \ test_vhash_key_gather_4_##N_KEY_U32 (void * _tm, u32 vi, u32 i) \ { return test_vhash_4key_gather (_tm, vi, i, N_KEY_U32); } \ \ clib_pipeline_stage \ (test_vhash_gather_keys_stage_##N_KEY_U32, \ test_vhash_main_t *, tm, i, \ { \ vhash_gather_4key_stage \ (&tm->vhash, \ /* vector_index */ i, \ test_vhash_key_gather_4_##N_KEY_U32, \ tm, \ N_KEY_U32); \ }) \ \ clib_pipeline_stage_no_inline \ (test_vhash_gather_keys_mod_stage_##N_KEY_U32, \ test_vhash_main_t *, tm, i, \ { \ vhash_gather_key_stage \ (&tm->vhash, \ /* vector_index */ tm->n_vectors_div_4, \ /* n_vectors */ tm->n_vectors_mod_4, \ test_vhash_key_gather_##N_KEY_U32, \ tm, \ N_KEY_U32); \ }) \ \ clib_pipeline_stage \ (test_vhash_hash_finalize_stage_##N_KEY_U32, \ test_vhash_main_t *, tm, i, \ { \ vhash_finalize_stage (&tm->vhash, i, N_KEY_U32); \ }) \ \ clib_pipeline_stage_no_inline \ (test_vhash_hash_finalize_mod_stage_##N_KEY_U32, \ test_vhash_main_t *, tm, i, \ { \ vhash_finalize_stage (&tm->vhash, tm->n_vectors_div_4, N_KEY_U32); \ }) \ \ clib_pipeline_stage \ (test_vhash_get_stage_##N_KEY_U32, \ test_vhash_main_t *, tm, i, \ { \ vhash_get_4_stage (&tm->vhash, \ /* vector_index */ i, \ test_vhash_get_4result, \ tm, N_KEY_U32); \ }) \ \ clib_pipeline_stage_no_inline \ (test_vhash_get_mod_stage_##N_KEY_U32, \ test_vhash_main_t *, tm, i, \ { \ vhash_get_stage (&tm->vhash, \ /* vector_index */ tm->n_vectors_div_4, \ /* n_vectors */ tm->n_vectors_mod_4, \ test_vhash_get_result, \ tm, N_KEY_U32); \ }) \ \ clib_pipeline_stage \ (test_vhash_set_stage_##N_KEY_U32, \ test_vhash_main_t *, tm, i, \ { \ vhash_set_stage (&tm->vhash, \ /* vector_index */ i, \ /* n_vectors */ VECTOR_WORD_TYPE_LEN (u32), \ test_vhash_set_result, \ tm, N_KEY_U32); \ }) \ \ clib_pipeline_stage_no_inline \ (test_vhash_set_mod_stage_##N_KEY_U32, \ test_vhash_main_t *, tm, i, \ { \ vhash_set_stage (&tm->vhash, \ /* vector_index */ tm->n_vectors_div_4, \ /* n_vectors */ tm->n_vectors_mod_4, \ test_vhash_set_result, \ tm, N_KEY_U32); \ }) \ \ clib_pipeline_stage \ (test_vhash_unset_stage_##N_KEY_U32, \ test_vhash_main_t *, tm, i, \ { \ vhash_unset_stage (&tm->vhash, \ /* vector_index */ i, \ /* n_vectors */ VECTOR_WORD_TYPE_LEN (u32), \ test_vhash_unset_result, \ tm, N_KEY_U32); \ }) \ \
/*
 * 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_disposition : The BIER disposition object
 *
 * A BIER disposition object is used to pop the BIER header for for-us
 * packets and steer the packet down the payload protocol specific graph
 */

#ifndef __BIER_DISP_ENTRY_H__
#define __BIER_DISP_ENTRY_H__

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

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

    /**
     * The DPO contributed from the per-payload protocol parents
     * on cacheline 1.
     */
    struct
    {
        dpo_id_t bde_dpo;
        u32 bde_rpf_id;
    } bde_fwd[BIER_HDR_N_PROTO];

    /**
     * number of locks
     */
    u32 bde_locks;

    /**
     * The path-lists used by per-payload protocol parents.
     * We don't add the disp entry to the graph as a sibling
     * since there is nothing we can do with the updates to
     * forwarding.
     */
    fib_node_index_t bde_pl[BIER_HDR_N_PROTO];
} bier_disp_entry_t;

extern index_t bier_disp_entry_add_or_lock(void);
extern