ip-neighbor: Send API event when neighbor is removed
[vpp.git] / src / vnet / ip-neighbor / ip_neighbor_types.h
1 /*
2  * ip_neighbor.h: ip neighbor generic services
3  *
4  * Copyright (c) 2018 Cisco and/or its affiliates.
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #ifndef __INCLUDE_IP_NEIGHBOR_TYPES_H__
19 #define __INCLUDE_IP_NEIGHBOR_TYPES_H__
20
21 #include <vnet/ip/ip_types.h>
22 #include <vnet/ethernet/mac_address.h>
23 #include <vnet/fib/fib_types.h>
24
25 #define foreach_ip_neighbor_flag                 \
26   _(STATIC, 1 << 0, "static", "S")               \
27   _(DYNAMIC, 1 << 1, "dynamic", "D")             \
28   _(NO_FIB_ENTRY, 1 << 2, "no-fib-entry", "N")   \
29   _(PENDING, 1 << 3, "pending", "P")             \
30   _(STALE, 1 << 4, "stale", "A")                 \
31
32 typedef enum ip_neighbor_flags_t_
33 {
34   IP_NEIGHBOR_FLAG_NONE = 0,
35 #define _(a,b,c,d) IP_NEIGHBOR_FLAG_##a = b,
36   foreach_ip_neighbor_flag
37 #undef _
38 } __clib_packed ip_neighbor_flags_t;
39
40 typedef struct ip_neighbor_watcher_t_
41 {
42   u32 ipw_pid;
43   u32 ipw_client;
44   int ipw_api_version;
45 } ip_neighbor_watcher_t;
46
47 extern u8 *format_ip_neighbor_watcher (u8 * s, va_list * args);
48
49 typedef struct ip_neighbor_key_t_
50 {
51   ip_address_t ipnk_ip;
52   u8 __pad[3];
53   u32 ipnk_sw_if_index;
54 } __clib_packed ip_neighbor_key_t;
55
56 /**
57  * A representation of an IP neighbour/peer
58  */
59 typedef struct ip_neighbor_t_
60 {
61   /**
62    * The idempotent key
63    */
64   ip_neighbor_key_t *ipn_key;
65
66   /**
67    * The learned MAC address of the neighbour
68    */
69   mac_address_t ipn_mac;
70
71   /**
72    * Falgs for this object
73    */
74   ip_neighbor_flags_t ipn_flags;
75
76   /**
77    * Aging related data
78    *  - last time the neighbour was probed
79    *  - number of probes - 3 and it's dead
80    */
81   f64 ipn_time_last_updated;
82   u8 ipn_n_probes;
83   index_t ipn_elt;
84
85   /**
86    * The index of the adj fib created for this neighbour
87    */
88   fib_node_index_t ipn_fib_entry_index;
89 } ip_neighbor_t;
90
91 extern u8 *format_ip_neighbor_flags (u8 * s, va_list * args);
92 extern u8 *format_ip_neighbor_key (u8 * s, va_list * args);
93 extern u8 *format_ip_neighbor (u8 * s, va_list * args);
94
95 extern ip_neighbor_t *ip_neighbor_get (index_t ipni);
96
97 typedef struct ip_neighbor_learn_t_
98 {
99   ip_address_t ip;
100   mac_address_t mac;
101   u32 sw_if_index;
102 } ip_neighbor_learn_t;
103
104
105 typedef enum ip_neighbor_event_flags_t_
106 {
107   IP_NEIGHBOR_EVENT_ADDED = (1 << 0),
108   IP_NEIGHBOR_EVENT_REMOVED = (1 << 1),
109 } ip_neighbor_event_flags_t;
110
111 typedef struct ip_neighbor_event_t_
112 {
113   ip_neighbor_watcher_t ipne_watch;
114   ip_neighbor_event_flags_t ipne_flags;
115   ip_neighbor_t ipne_nbr;
116 } ip_neighbor_event_t;
117
118 extern void ip_neighbor_clone (const ip_neighbor_t * ipn,
119                                ip_neighbor_t * clone);
120
121 extern void ip_neighbor_free (ip_neighbor_t * ipn);
122
123
124
125 #endif /* __INCLUDE_IP_NEIGHBOR_H__ */
126
127 /*
128  * fd.io coding-style-patch-verification: ON
129  *
130  * Local Variables:
131  * eval: (c-set-style "gnu")
132  * End:
133  */