mirror of
https://github.com/openvswitch/ovs
synced 2025-08-23 18:37:36 +00:00
105 lines
3.3 KiB
C
105 lines
3.3 KiB
C
|
/*
|
||
|
* Copyright (c) 2020 Intel Corporation.
|
||
|
*
|
||
|
* 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.
|
||
|
*/
|
||
|
|
||
|
#include <config.h>
|
||
|
#include <errno.h>
|
||
|
#include "dpif-netdev-lookup.h"
|
||
|
|
||
|
#include "openvswitch/vlog.h"
|
||
|
|
||
|
VLOG_DEFINE_THIS_MODULE(dpif_netdev_lookup);
|
||
|
|
||
|
/* Actual list of implementations goes here */
|
||
|
static struct dpcls_subtable_lookup_info_t subtable_lookups[] = {
|
||
|
/* The autovalidator implementation will not be used by default, it must
|
||
|
* be enabled at compile time to be the default lookup implementation. The
|
||
|
* user may enable it at runtime using the normal "prio-set" command if
|
||
|
* desired. The compile time default switch is here to enable all unit
|
||
|
* tests to transparently run with the autovalidator.
|
||
|
*/
|
||
|
#ifdef DPCLS_AUTOVALIDATOR_DEFAULT
|
||
|
{ .prio = 255,
|
||
|
#else
|
||
|
{ .prio = 0,
|
||
|
#endif
|
||
|
.probe = dpcls_subtable_autovalidator_probe,
|
||
|
.name = "autovalidator", },
|
||
|
|
||
|
/* The default scalar C code implementation. */
|
||
|
{ .prio = 1,
|
||
|
.probe = dpcls_subtable_generic_probe,
|
||
|
.name = "generic", },
|
||
|
};
|
||
|
|
||
|
int32_t
|
||
|
dpcls_subtable_lookup_info_get(struct dpcls_subtable_lookup_info_t **out_ptr)
|
||
|
{
|
||
|
if (out_ptr == NULL) {
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
*out_ptr = subtable_lookups;
|
||
|
return ARRAY_SIZE(subtable_lookups);
|
||
|
}
|
||
|
|
||
|
/* sets the priority of the lookup function with "name". */
|
||
|
int32_t
|
||
|
dpcls_subtable_set_prio(const char *name, uint8_t priority)
|
||
|
{
|
||
|
for (int i = 0; i < ARRAY_SIZE(subtable_lookups); i++) {
|
||
|
if (strcmp(name, subtable_lookups[i].name) == 0) {
|
||
|
subtable_lookups[i].prio = priority;
|
||
|
VLOG_INFO("Subtable function '%s' set priority to %d\n",
|
||
|
name, priority);
|
||
|
return 0;
|
||
|
}
|
||
|
}
|
||
|
VLOG_WARN("Subtable function '%s' not found, failed to set priority\n",
|
||
|
name);
|
||
|
return -EINVAL;
|
||
|
}
|
||
|
|
||
|
dpcls_subtable_lookup_func
|
||
|
dpcls_subtable_get_best_impl(uint32_t u0_bit_count, uint32_t u1_bit_count)
|
||
|
{
|
||
|
/* Iter over each subtable impl, and get highest priority one. */
|
||
|
int32_t prio = -1;
|
||
|
const char *name = NULL;
|
||
|
dpcls_subtable_lookup_func best_func = NULL;
|
||
|
|
||
|
for (int i = 0; i < ARRAY_SIZE(subtable_lookups); i++) {
|
||
|
int32_t probed_prio = subtable_lookups[i].prio;
|
||
|
if (probed_prio > prio) {
|
||
|
dpcls_subtable_lookup_func probed_func;
|
||
|
probed_func = subtable_lookups[i].probe(u0_bit_count,
|
||
|
u1_bit_count);
|
||
|
if (probed_func) {
|
||
|
best_func = probed_func;
|
||
|
prio = probed_prio;
|
||
|
name = subtable_lookups[i].name;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
VLOG_DBG("Subtable lookup function '%s' with units (%d,%d), priority %d\n",
|
||
|
name, u0_bit_count, u1_bit_count, prio);
|
||
|
|
||
|
/* Programming error - we must always return a valid func ptr. */
|
||
|
ovs_assert(best_func != NULL);
|
||
|
|
||
|
return best_func;
|
||
|
}
|