A Protocol Independent Hierarchical FIB (VPP-352)
[vpp.git] / vnet / vnet / adj / adj.h
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 /**
16  * An adjacency is a representation of an attached L3 peer.
17  *
18  * Adjacency Sub-types:
19  *   - neighbour: a representation of an attached L3 peer.
20  *                Key:{addr,interface,link/ether-type}
21  *           SHARED
22  *   - glean: used to drive ARP/ND for packets destined to a local sub-net.
23  *            'glean' mean use the packet's destination address as the target
24  *            address in the ARP packet.
25  *          UNSHARED. Only one per-interface.
26  *   - midchain: a nighbour adj on a virtual/tunnel interface.
27  *   - rewrite: an adj with no key, but with a rewrite string.
28  *
29  * The API to create and update the adjacency is very sub-type specific. This
30  * is intentional as it encourages the user to carefully consider which adjacency
31  * sub-type they are really using, and hence assign it data in the appropriate
32  * sub-type space in the union of sub-types. This prevents the adj becoming a
33  * disorganised dumping group for 'my features needs a u16 somewhere' data. It
34  * is important to enforce this approach as space in the adjacency is a premium,
35  * as we need it to fit in 1 cache line.
36  *
37  * the API is also based around an index to an ajdacency not a raw pointer. This
38  * is so the user doesn't suffer the same limp inducing firearm injuries that
39  * the author suffered as the adjacenices can realloc.
40  */
41
42 #ifndef __ADJ_H__
43 #define __ADJ_H__
44
45 #include <vnet/ip/lookup.h>
46 #include <vnet/adj/adj_types.h>
47 #include <vnet/adj/adj_nbr.h>
48 #include <vnet/adj/adj_rewrite.h>
49 #include <vnet/adj/adj_glean.h>
50
51 /**
52  * @brief
53  *   Take a reference counting lock on the adjacency
54  */
55 extern void adj_lock(adj_index_t adj_index);
56 /**
57  * @brief
58  *   Release a reference counting lock on the adjacency
59  */
60 extern void adj_unlock(adj_index_t adj_index);
61
62 /**
63  * @brief
64  *  Add a child dependent to an adjacency. The child will
65  *  thus be informed via its registerd back-walk function
66  *  when the adjacency state changes.
67  */
68 extern u32 adj_child_add(adj_index_t adj_index,
69                          fib_node_type_t type,
70                          fib_node_index_t child_index);
71 /**
72  * @brief
73  *  Remove a child dependent
74  */
75 extern void adj_child_remove(adj_index_t adj_index,
76                              u32 sibling_index);
77
78 /**
79  * @brief
80  * The global adjacnecy heap. Exposed for fast/inline data-plane access
81  */
82 extern ip_adjacency_t *adj_heap;
83
84 /**
85  * @brief 
86  * Adjacency packet counters
87  */
88 extern vlib_combined_counter_main_t adjacency_counters;
89
90 /**
91  * @brief
92  * Get a pointer to an adjacency object from its index
93  */
94 static inline ip_adjacency_t *
95 adj_get (adj_index_t adj_index)
96 {
97     return (vec_elt_at_index(adj_heap, adj_index));
98 }
99
100 #endif