/* * 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. */ #ifndef __FIB_TABLE_H__ #define __FIB_TABLE_H__ #include #include #include #include #include /** * @brief * A protocol Independent FIB table */ typedef struct fib_table_t_ { /** * Which protocol this table serves. Used to switch on the union above. */ fib_protocol_t ft_proto; /** * number of locks on the table */ u16 ft_locks; /** * Table ID (hash key) for this FIB. */ u32 ft_table_id; /** * Index into FIB vector. */ fib_node_index_t ft_index; /** * flow hash configuration */ u32 ft_flow_hash_config; /** * Per-source route counters */ u32 ft_src_route_counts[FIB_SOURCE_MAX]; /** * Total route counters */ u32 ft_total_route_counts; /** * Table description */ u8* ft_desc; } fib_table_t; /** * @brief * Format the description/name of the table */ extern u8* format_fib_table_name(u8* s, va_list ap); /** * @brief * Perfom a longest prefix match in the non-forwarding table * * @param fib_index * The index of the FIB * * @param prefix * The prefix to lookup * * @return * The index of the fib_entry_t for the best match, which may be the default route */ extern fib_node_index_t fib_table_lookup(u32 fib_index, const fib_prefix_t *prefix); /** * @brief * Perfom an exact match in the non-forwarding table * * @param fib_index * The index of the FIB * * @param prefix * The prefix to lookup * * @return * The index of the fib_entry_t for the exact match, or INVALID * is there is no match. */ extern fib_node_index_t fib_table_lookup_exact_match(u32 fib_index, const fib_prefix_t *prefix); /** * @brief * Get the less specific (covering) prefix * * @param fib_index * The index of the FIB * * @param prefix * The prefix to lookup * * @return * The index of the less specific fib_entry_t. */ extern fib_node_index_t fib_table_get_less_specific(u32 fib_index, const fib_prefix_t *prefix); /** * @brief * Add a 'special' entry to the FIB that links to the adj passed * A special entry is an entry that the FIB is not expect to resolve * via the usual mechanisms (i.e. recurisve or neighbour adj DB lookup). * Instead the client/source provides the adj to link to. * This add is reference counting per-source. So n 'removes' are required * for n 'adds', if the entry is no longer required. * * @param fib_index * The index of the FIB * * @param prefix * The prefix to add * * @param source * The ID of the client/source adding the entry. * * @param flags * Flags for the entry. * * @param adj_index * The adjacency to link to. * * @return * the index of the fib_entry_t that is created (or exists already). */ extern fib_node_index_t fib_table_entry_special_add(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, fib_entry_flag_t flags, adj_index_t adj_index); /** * @brief * Add a 'special' entry to the FIB that links to the DPO passed * A special entry is an entry that the FIB is not expect to resolve * via the usual mechanisms (i.e. recurisve or neighbour adj DB lookup). * Instead the client/source provides the DPO to link to. * This add is reference counting per-source. So n 'removes' are required * for n 'adds', if the entry is no longer required. * * @param fib_index * The index of the FIB * * @param prefix * The prefix to add * * @param source * The ID of the client/source adding the entry. * * @param flags * Flags for the entry. * * @param dpo * The DPO to link to. * * @return * the index of the fib_entry_t that is created (or existed already). */ extern fib_node_index_t fib_table_entry_special_dpo_add(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, fib_entry_flag_t stype, const dpo_id_t *dpo); /** * @brief * Update a 'special' entry to the FIB that links to the DPO passed * A special entry is an entry that the FIB is not expect to resolve * via the usual mechanisms (i.e. recurisve or neighbour adj DB lookup). * Instead the client/source provides the DPO to link to. * Special entries are add/remove reference counted per-source. So n * 'removes' are required for n 'adds', if the entry is no longer required. * An 'update' is an 'add' if no 'add' has already been called, otherwise an 'add' * is therefore assumed to act on the reference instance of that add. * * @param fib_entry_index * The index of the FIB entry to update * * @param source * The ID of the client/source adding the entry. * * @param flags * Flags for the entry. * * @param dpo * The DPO to link to. * * @return * the index of the fib_entry_t that is created (or existed already). */ extern fib_node_index_t fib_table_entry_special_dpo_update (u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, fib_entry_flag_t stype, const dpo_id_t *dpo); /** * @brief * Remove a 'special' entry from the FIB. * This add is reference counting per-source. So n 'removes' are required * for n 'adds', if the entry is no longer required. * * @param fib_index * The index of the FIB * * @param prefix * The prefix to remove * * @param source * The ID of the client/source adding the entry. * */ extern void fib_table_entry_special_remove(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source); /** * @brief * Add one path to an entry (aka route) in the FIB. If the entry does not * exist, it will be created. * See the documentation for fib_route_path_t for more descirptions of * the path parameters. * * @param fib_index * The index of the FIB * * @param prefix * The prefix for the entry to add * * @param source * The ID of the client/source adding the entry. * * @param flags * Flags for the entry. * * @paran next_hop_proto * The protocol of the next hop. This cannot be derived in the event that * the next hop is all zeros. * * @param next_hop * The address of the next-hop. * * @param sw_if_index * The index of the interface. * * @param next_hop_fib_index, * The fib index of the next-hop for recursive resolution * * @param next_hop_weight * [un]equal cost path weight * * @param next_hop_label_stack * The path's out-going label stack. NULL is there is none. * * @param pf * Flags for the path * * @return * the index of the fib_entry_t that is created (or existed already). */ extern fib_node_index_t fib_table_entry_path_add(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, fib_entry_flag_t flags, fib_protocol_t next_hop_proto, const ip46_address_t *next_hop, u32 next_hop_sw_if_index, u32 next_hop_fib_index, u32 next_hop_weight, mpls_label_t *next_hop_label_stack, fib_route_path_flags_t pf); /** * @brief * Add n paths to an entry (aka route) in the FIB. If the entry does not * exist, it will be created. * See the documentation for fib_route_path_t for more descirptions of * the path parameters. * * @param fib_index * The index of the FIB * * @param prefix * The prefix for the entry to add * * @param source * The ID of the client/source adding the entry. * * @param flags * Flags for the entry. * * @param rpaths * A vector of paths. Not const since th
/*
 * 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) 2005 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