FD.io VPP  v18.01.2-1-g9b554f3
Vector Packet Processing
oam_api.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * oam_api.c - vnet OAM api
4  *
5  * Copyright (c) 2016 Cisco and/or its affiliates.
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at:
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *------------------------------------------------------------------
18  */
19 
20 #include <vnet/vnet.h>
21 #include <vlibmemory/api.h>
22 
23 #include <vpp/oam/oam.h>
24 
25 #include <vpp/api/vpe_msg_enum.h>
26 
27 #define vl_typedefs /* define message structures */
28 #include <vpp/api/vpe_all_api_h.h>
29 #undef vl_typedefs
30 #define vl_endianfun /* define message structures */
31 #include <vpp/api/vpe_all_api_h.h>
32 #undef vl_endianfun
33 /* instantiate all the print functions we know about */
34 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
35 #define vl_printfun
36 #include <vpp/api/vpe_all_api_h.h>
37 #undef vl_printfun
39 
40 #define foreach_oam_api_msg \
41 _(WANT_OAM_EVENTS, want_oam_events) \
42 _(OAM_ADD_DEL, oam_add_del)
43 
44 pub_sub_handler (oam_events, OAM_EVENTS);
45 
46 void
48 {
53 
54  /* *INDENT-OFF* */
55  pool_foreach(reg, vam->oam_events_registrations,
56  ({
57  q = vl_api_client_index_to_input_queue (reg->client_index);
58  if (q)
59  {
60  mp = vl_msg_api_alloc (sizeof (*mp));
61  mp->_vl_msg_id = ntohs (VL_API_OAM_EVENT);
62  clib_memcpy (mp->dst_address, &t->dst_address,
63  sizeof (mp->dst_address));
64  mp->state = t->state;
65  vl_msg_api_send_shmem (q, (u8 *)&mp);
66  }
67  }));
68  /* *INDENT-ON* */
69 }
70 
71 static void
73 {
74  vl_api_oam_add_del_reply_t *rmp;
75  int rv;
76 
78  (ip4_address_t *) mp->dst_address,
79  ntohl (mp->vrf_id), (int) (mp->is_add));
80 
81  REPLY_MACRO (VL_API_OAM_ADD_DEL_REPLY);
82 }
83 
84 #define vl_msg_name_crc_list
85 #include <vpp/oam/oam.api.h>
86 #undef vl_msg_name_crc_list
87 
88 static void
90 {
91 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
92  foreach_vl_msg_name_crc_oam;
93 #undef _
94 }
95 
96 static clib_error_t *
98 {
99  api_main_t *am = &api_main;
100 
101 #define _(N,n) \
102  vl_msg_api_set_handlers(VL_API_##N, #n, \
103  vl_api_##n##_t_handler, \
104  vl_noop_handler, \
105  vl_api_##n##_t_endian, \
106  vl_api_##n##_t_print, \
107  sizeof(vl_api_##n##_t), 1);
109 #undef _
110 
111  /*
112  * Set up the (msg_name, crc, message-id) table
113  */
115 
116  return 0;
117 }
118 
120 
121 /*
122  * fd.io coding-style-patch-verification: ON
123  *
124  * Local Variables:
125  * eval: (c-set-style "gnu")
126  * End:
127  */
OAM event structure.
Definition: oam.api:28
static void setup_message_id_table(api_main_t *am)
Definition: oam_api.c:89
void send_oam_event(oam_target_t *t)
Definition: oam_api.c:47
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:438
u8 dst_address[4]
Definition: oam.api:62
VLIB_API_INIT_FUNCTION(oam_api_hookup)
#define REPLY_MACRO(t)
pub_sub_handler(oam_events, OAM_EVENTS)
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:198
api_main_t api_main
Definition: api_shared.c:35
vlib_main_t * vm
Definition: buffer.c:283
static clib_error_t * oam_api_hookup(vlib_main_t *vm)
Definition: oam_api.c:97
int vpe_oam_add_del_target(ip4_address_t *src_address, ip4_address_t *dst_address, u32 fib_id, int is_add)
Definition: oam.c:60
OAM add / del target request.
Definition: oam.api:56
static void vl_api_oam_add_del_t_handler(vl_api_oam_add_del_t *mp)
Definition: oam_api.c:72
#define foreach_oam_api_msg
Definition: oam_api.c:40
vpe_api_main_t vpe_api_main
Definition: interface_api.c:49
struct _unix_shared_memory_queue unix_shared_memory_queue_t
u8 src_address[4]
Definition: oam.api:61