A Protocol Independent Hierarchical FIB (VPP-352)
[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
23
24 /**
25  * big switch to turn on Adjacency debugging
26  */
27 #undef ADJ_DEBUG
28
29 /*
30  * Debug macro
31  */
32 #ifdef ADJ_DEBUG
33 #define ADJ_DBG(_adj, _fmt, _args...)                   \
34 {                                                       \
35     clib_warning("adj:[%d:%p]:" _fmt,                   \
36                  _adj->heap_handle, _adj,               \
37                  ##_args);                              \
38 }
39 #else
40 #define ADJ_DBG(_e, _fmt, _args...)
41 #endif
42
43 static inline vlib_node_registration_t*
44 adj_get_rewrite_node (fib_link_t linkt)
45 {
46     switch (linkt) {
47     case FIB_LINK_IP4:
48         return (&ip4_rewrite_node);
49     case FIB_LINK_IP6:
50         return (&ip6_rewrite_node);
51     case FIB_LINK_MPLS:
52         return (&mpls_output_node);
53     }
54     ASSERT(0);
55     return (NULL);
56 }
57
58 static inline vnet_l3_packet_type_t
59 adj_fib_link_2_vnet (fib_link_t linkt)
60 {
61     switch (linkt)
62     {
63     case FIB_LINK_IP4:
64         return (VNET_L3_PACKET_TYPE_IP4);
65     case FIB_LINK_IP6:
66         return (VNET_L3_PACKET_TYPE_IP6);
67     case FIB_LINK_MPLS:
68         return (VNET_L3_PACKET_TYPE_MPLS_UNICAST);
69     }
70     return (0);
71 }
72
73 static inline vnet_l3_packet_type_t
74 adj_fib_proto_2_nd (fib_protocol_t fp)
75 {
76     switch (fp)
77     {
78     case FIB_PROTOCOL_IP4:
79         return (VNET_L3_PACKET_TYPE_ARP);
80     case FIB_PROTOCOL_IP6:
81         return (VNET_L3_PACKET_TYPE_IP6);
82     case FIB_PROTOCOL_MPLS:
83         return (VNET_L3_PACKET_TYPE_MPLS_UNICAST);
84     }
85     return (0);
86 }
87
88 extern ip_adjacency_t * adj_alloc(fib_protocol_t proto);
89
90 extern void adj_nbr_remove(fib_protocol_t nh_proto,
91                            fib_link_t link_type,
92                            const ip46_address_t *nh_addr,
93                            u32 sw_if_index);
94 extern void adj_glean_remove(fib_protocol_t proto,
95                              u32 sw_if_index);
96
97 #endif