FIB Memory Usage Diagnostics
[vpp.git] / vnet / vnet / adj / adj_internal.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 #ifndef __ADJ_INTERNAL_H__
17 #define __ADJ_INTERNAL_H__
18
19 #include <vnet/adj/adj.h>
20 #include <vnet/ip/ip.h>
21 #include <vnet/mpls/mpls.h>
22 #include <vnet/adj/adj_l2.h>
23
24
25 /**
26  * big switch to turn on Adjacency debugging
27  */
28 #undef ADJ_DEBUG
29
30 /*
31  * Debug macro
32  */
33 #ifdef ADJ_DEBUG
34 #define ADJ_DBG(_adj, _fmt, _args...)           \
35 {                                               \
36     clib_warning("adj:[%d:%p]:" _fmt,           \
37                  _adj - adj_pool, _adj,         \
38                  ##_args);                      \
39 }
40 #else
41 #define ADJ_DBG(_e, _fmt, _args...)
42 #endif
43
44 static inline vlib_node_registration_t*
45 adj_get_rewrite_node (fib_link_t linkt)
46 {
47     switch (linkt) {
48     case FIB_LINK_IP4:
49         return (&ip4_rewrite_node);
50     case FIB_LINK_IP6:
51         return (&ip6_rewrite_node);
52     case FIB_LINK_MPLS:
53         return (&mpls_output_node);
54     case FIB_LINK_ETHERNET:
55         return (&adj_l2_rewrite_node);
56     }
57     ASSERT(0);
58     return (NULL);
59 }
60
61 static inline vnet_l3_packet_type_t
62 adj_fib_link_2_vnet (fib_link_t linkt)
63 {
64     switch (linkt)
65     {
66     case FIB_LINK_IP4:
67         return (VNET_L3_PACKET_TYPE_IP4);
68     case FIB_LINK_IP6:
69         return (VNET_L3_PACKET_TYPE_IP6);
70     case FIB_LINK_MPLS:
71         return (VNET_L3_PACKET_TYPE_MPLS_UNICAST);
72     case FIB_LINK_ETHERNET:
73         break;
74     }
75     return (0);
76 }
77
78 static inline vnet_l3_packet_type_t
79 adj_fib_proto_2_nd (fib_protocol_t fp)
80 {
81     switch (fp)
82     {
83     case FIB_PROTOCOL_IP4:
84         return (VNET_L3_PACKET_TYPE_ARP);
85     case FIB_PROTOCOL_IP6:
86         return (VNET_L3_PACKET_TYPE_IP6);
87     case FIB_PROTOCOL_MPLS:
88         return (VNET_L3_PACKET_TYPE_MPLS_UNICAST);
89     }
90     return (0);
91 }
92
93 /**
94  * @brief
95  * Get a pointer to an adjacency object from its index
96  */
97 static inline adj_index_t
98 adj_get_index (ip_adjacency_t *adj)
99 {
100     return (adj - adj_pool);
101 }
102
103 extern ip_adjacency_t * adj_alloc(fib_protocol_t proto);
104
105 extern void adj_nbr_remove(fib_protocol_t nh_proto,
106                            fib_link_t link_type,
107                            const ip46_address_t *nh_addr,
108                            u32 sw_if_index);
109 extern void adj_glean_remove(fib_protocol_t proto,
110                              u32 sw_if_index);
111
112 #endif