FD.io VPP  v17.04-9-g99c0734
Vector Packet Processing
adj.h
Go to the documentation of this file.
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_glean.h>
49 
50 /**
51  * @brief
52  * Take a reference counting lock on the adjacency
53  */
54 extern void adj_lock(adj_index_t adj_index);
55 /**
56  * @brief
57  * Release a reference counting lock on the adjacency
58  */
59 extern void adj_unlock(adj_index_t adj_index);
60 
61 /**
62  * @brief
63  * Add a child dependent to an adjacency. The child will
64  * thus be informed via its registerd back-walk function
65  * when the adjacency state changes.
66  */
67 extern u32 adj_child_add(adj_index_t adj_index,
68  fib_node_type_t type,
69  fib_node_index_t child_index);
70 /**
71  * @brief
72  * Remove a child dependent
73  */
74 extern void adj_child_remove(adj_index_t adj_index,
75  u32 sibling_index);
76 
77 /**
78  * @brief Walk the Adjacencies on a given interface
79  */
80 extern void adj_walk (u32 sw_if_index,
81  adj_walk_cb_t cb,
82  void *ctx);
83 
84 /**
85  * @brief Return the link type of the adjacency
86  */
88 
89 /**
90  * @brief Return the sw interface index of the adjacency.
91  */
93 
94 /**
95  * @brief Return the link type of the adjacency
96  */
97 extern const u8* adj_get_rewrite (adj_index_t ai);
98 
99 /**
100  * @brief Notify the adjacency subsystem that the features settings for
101  * an interface have changed
102  */
103 extern void adj_feature_update (u32 sw_if_index, u8 arc_index, u8 is_enable);
104 
105 /**
106  * @brief
107  * The global adjacnecy pool. Exposed for fast/inline data-plane access
108  */
109 extern ip_adjacency_t *adj_pool;
110 
111 /**
112  * @brief
113  * Adjacency packet counters
114  */
116 
117 /**
118  * @brief Global Config for enabling per-adjacency counters
119  * This is configurable because it comes with a non-negligible
120  * performance cost. */
121 extern int adj_per_adj_counters;
122 
123 /**
124  * @brief
125  * Get a pointer to an adjacency object from its index
126  */
127 static inline ip_adjacency_t *
128 adj_get (adj_index_t adj_index)
129 {
130  return (vec_elt_at_index(adj_pool, adj_index));
131 }
132 
133 /**
134  * @brief Get the global configuration option for enabling per-adj counters
135  */
136 static inline int
138 {
139  return (adj_per_adj_counters);
140 }
141 
142 #endif
u32 adj_child_add(adj_index_t adj_index, fib_node_type_t type, fib_node_index_t child_index)
Add a child dependent to an adjacency.
Definition: adj.c:234
enum fib_node_type_t_ fib_node_type_t
The types of nodes in a FIB graph.
Definitions for all things IP (v4|v6) unicast and multicast lookup related.
IP unicast adjacency.
Definition: lookup.h:193
void adj_walk(u32 sw_if_index, adj_walk_cb_t cb, void *ctx)
Walk the Adjacencies on a given interface.
Definition: adj.c:321
static ip_adjacency_t * adj_get(adj_index_t adj_index)
Get a pointer to an adjacency object from its index.
Definition: adj.h:128
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
ip_adjacency_t * adj_pool
The global adjacnecy pool.
Definition: adj.c:36
void adj_lock(adj_index_t adj_index)
An adjacency is a representation of an attached L3 peer.
Definition: adj.c:198
const u8 * adj_get_rewrite(adj_index_t ai)
Return the link type of the adjacency.
Definition: adj.c:366
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:28
adj_walk_rc_t(* adj_walk_cb_t)(adj_index_t ai, void *ctx)
Call back function when walking adjacencies.
Definition: adj_types.h:50
u32 adj_index_t
An index for adjacencies.
Definition: adj_types.h:30
void adj_feature_update(u32 sw_if_index, u8 arc_index, u8 is_enable)
Notify the adjacency subsystem that the features settings for an interface have changed.
Definition: adj.c:302
unsigned int u32
Definition: types.h:88
enum vnet_link_t_ vnet_link_t
Link Type: A description of the protocol of packets on the link.
vnet_link_t adj_get_link_type(adj_index_t ai)
Return the link type of the adjacency.
Definition: adj.c:340
vlib_combined_counter_main_t adjacency_counters
Adjacency packet counters.
Definition: adj.c:31
unsigned char u8
Definition: types.h:56
void adj_child_remove(adj_index_t adj_index, u32 sibling_index)
Remove a child dependent.
Definition: adj.c:251
u32 adj_get_sw_if_index(adj_index_t ai)
Return the sw interface index of the adjacency.
Definition: adj.c:353
A collection of combined counters.
Definition: counter.h:180
int adj_per_adj_counters
Global Config for enabling per-adjacency counters This is configurable because it comes with a non-ne...
Definition: adj.c:42
void adj_unlock(adj_index_t adj_index)
Release a reference counting lock on the adjacency.
Definition: adj.c:215
static int adj_are_counters_enabled(void)
Get the global configuration option for enabling per-adj counters.
Definition: adj.h:137