FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
pg_api.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * pg_api.c - vnet pg 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 #include <vnet/pg/pg.h>
23 
24 #include <vnet/format_fns.h>
25 #include <vnet/pg/pg.api_enum.h>
26 #include <vnet/pg/pg.api_types.h>
27 
28 #define REPLY_MSG_ID_BASE pg->msg_id_base
30 
31 static void
33 {
35  int rv = 0;
36 
37  pg_main_t *pg = &pg_main;
38  u32 pg_if_id =
39  pg_interface_add_or_get (pg, ntohl (mp->interface_id), mp->gso_enabled,
40  ntohl (mp->gso_size), 0, PG_MODE_ETHERNET);
41  pg_interface_t *pi = pool_elt_at_index (pg->interfaces, pg_if_id);
42 
43  /* *INDENT-OFF* */
44  REPLY_MACRO2(VL_API_PG_CREATE_INTERFACE_REPLY,
45  ({
46  rmp->sw_if_index = ntohl(pi->sw_if_index);
47  }));
48  /* *INDENT-ON* */
49 }
50 
51 static void
53 {
55  int rv = 0;
56 
57  pg_main_t *pg = &pg_main;
58  u32 pg_if_id =
59  pg_interface_add_or_get (pg, ntohl (mp->interface_id), mp->gso_enabled,
60  ntohl (mp->gso_size), 0, (u8) mp->mode);
61  pg_interface_t *pi = pool_elt_at_index (pg->interfaces, pg_if_id);
62 
63  REPLY_MACRO2 (VL_API_PG_CREATE_INTERFACE_V2_REPLY,
64  ({ rmp->sw_if_index = ntohl (pi->sw_if_index); }));
65 }
66 
67 static void
70 {
71  vl_api_pg_interface_enable_disable_coalesce_reply_t *rmp;
72  int rv = 0;
73 
75 
76  u32 sw_if_index = ntohl (mp->sw_if_index);
77 
78  pg_main_t *pg = &pg_main;
79  vnet_main_t *vnm = vnet_get_main ();
82 
83  if (hw)
84  {
85  pg_interface_t *pi =
87  if (pi->gso_enabled)
89  hw->tx_node_index);
90  else
91  rv = VNET_API_ERROR_CANNOT_ENABLE_DISABLE_FEATURE;
92  }
93  else
94  {
95  rv = VNET_API_ERROR_NO_MATCHING_INTERFACE;
96  }
97 
99  REPLY_MACRO (VL_API_PG_INTERFACE_ENABLE_DISABLE_COALESCE_REPLY);
100 }
101 
102 static void
104 {
105  pg_main_t *pg = &pg_main;
106  vl_api_pg_capture_reply_t *rmp;
107  int rv = 0;
108 
109  vnet_main_t *vnm = vnet_get_main ();
111  vnet_hw_interface_t *hi = 0;
112 
113  u8 *intf_name = format (0, "pg%d", ntohl (mp->interface_id), 0);
114  vec_terminate_c_string (intf_name);
115  u32 hw_if_index = ~0;
116  uword *p = hash_get_mem (im->hw_interface_by_name, intf_name);
117  if (p)
118  hw_if_index = *p;
119  vec_free (intf_name);
120 
121  if (hw_if_index != ~0)
122  {
123  pg_capture_args_t _a, *a = &_a;
124  char *pcap_file_name =
126 
127  hi = vnet_get_sup_hw_interface (vnm, hw_if_index);
128  a->hw_if_index = hw_if_index;
129  a->dev_instance = hi->dev_instance;
130  a->is_enabled = mp->is_enabled;
131  a->pcap_file_name = pcap_file_name;
132  a->count = ntohl (mp->count);
133 
134  clib_error_t *e = pg_capture (a);
135  if (e)
136  {
137  clib_error_report (e);
138  rv = VNET_API_ERROR_CANNOT_CREATE_PCAP_FILE;
139  }
140 
141  vec_free (pcap_file_name);
142  }
143  REPLY_MACRO (VL_API_PG_CAPTURE_REPLY);
144 }
145 
146 static void
148 {
149  vl_api_pg_enable_disable_reply_t *rmp;
150  int rv = 0;
151 
152  pg_main_t *pg = &pg_main;
153  u32 stream_index = ~0;
154 
155  int is_enable = mp->is_enabled != 0;
156 
157  if (vl_api_string_len (&mp->stream_name) > 0)
158  {
159  u8 *stream_name = vl_api_from_api_to_new_vec (mp, &mp->stream_name);
160  uword *p = hash_get_mem (pg->stream_index_by_name, stream_name);
161  if (p)
162  stream_index = *p;
163  vec_free (stream_name);
164  }
165 
166  pg_enable_disable (stream_index, is_enable);
167 
168  REPLY_MACRO (VL_API_PG_ENABLE_DISABLE_REPLY);
169 }
170 
171 #include <vnet/pg/pg.api.c>
172 static clib_error_t *
174 {
175  pg_main_t *pg = &pg_main;
176  /*
177  * Set up the (msg_name, crc, message-id) table
178  */
180 
181  return 0;
182 }
183 
185 
186 /*
187  * fd.io coding-style-patch-verification: ON
188  *
189  * Local Variables:
190  * eval: (c-set-style "gnu")
191  * End:
192  */
pg_interface_enable_disable_coalesce
void pg_interface_enable_disable_coalesce(pg_interface_t *pi, u8 enable, u32 tx_node_index)
Definition: stream.c:215
im
vnet_interface_main_t * im
Definition: interface_output.c:415
VALIDATE_SW_IF_INDEX
#define VALIDATE_SW_IF_INDEX(mp)
Definition: api_helper_macros.h:281
api.h
VLIB_API_INIT_FUNCTION
VLIB_API_INIT_FUNCTION(pg_api_hookup)
vl_api_pg_capture_t::is_enabled
bool is_enabled[default=true]
Definition: pg.api:102
REPLY_MACRO2
#define REPLY_MACRO2(t, body)
Definition: api_helper_macros.h:65
pg_interface_add_or_get
u32 pg_interface_add_or_get(pg_main_t *pg, uword stream_index, u8 gso_enabled, u32 gso_size, u8 coalesce_enabled, pg_interface_mode_t mode)
Definition: stream.c:251
pg.h
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:549
vl_api_pg_enable_disable_t_handler
static void vl_api_pg_enable_disable_t_handler(vl_api_pg_enable_disable_t *mp)
Definition: pg_api.c:147
vnet_interface_main_t
Definition: interface.h:990
vl_api_pg_create_interface_v2_t_handler
static void vl_api_pg_create_interface_v2_t_handler(vl_api_pg_create_interface_v2_t *mp)
Definition: pg_api.c:52
vnet_hw_interface_t::tx_node_index
u32 tx_node_index
Definition: interface.h:653
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
pg_capture
clib_error_t * pg_capture(pg_capture_args_t *a)
Definition: cli.c:81
vl_api_pg_create_interface_v2_t::mode
vl_api_pg_interface_mode_t mode
Definition: pg.api:54
hi
vl_api_ip4_address_t hi
Definition: arp.api:37
clib_error_report
#define clib_error_report(e)
Definition: error.h:113
vnet_hw_interface_t::dev_instance
u32 dev_instance
Definition: interface.h:660
vl_api_pg_create_interface_v2_reply_t
Definition: pg.api:67
vl_api_pg_interface_enable_disable_coalesce_t::sw_if_index
vl_api_interface_index_t sw_if_index
Definition: pg.api:84
vl_api_pg_enable_disable_t
Enable / disable packet generator request.
Definition: pg.api:113
vl_api_pg_interface_enable_disable_coalesce_t
PacketGenerator interface enable/disable packet coalesce.
Definition: pg.api:80
vl_api_pg_capture_t::count
u32 count
Definition: pg.api:103
vl_api_pg_enable_disable_t::is_enabled
bool is_enabled[default=true]
Definition: pg.api:117
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
vl_api_pg_capture_t::interface_id
vl_api_interface_index_t interface_id
Definition: pg.api:101
REPLY_MACRO
#define REPLY_MACRO(t)
Definition: api_helper_macros.h:30
setup_message_id_table
static void setup_message_id_table(api_main_t *am)
Definition: sr_mpls_api.c:174
vl_api_pg_create_interface_t::interface_id
vl_api_interface_index_t interface_id
Definition: pg.api:43
vnet_get_sup_hw_interface_api_visible_or_null
static vnet_hw_interface_t * vnet_get_sup_hw_interface_api_visible_or_null(vnet_main_t *vnm, u32 sw_if_index)
Definition: interface_funcs.h:101
vl_api_pg_interface_enable_disable_coalesce_t::coalesce_enabled
bool coalesce_enabled
Definition: pg.api:85
vl_api_pg_enable_disable_t::stream_name
string stream_name[]
Definition: pg.api:118
vl_api_pg_capture_t
PacketGenerator capture packets on given interface request.
Definition: pg.api:97
pg_capture_args_t
Definition: pg.h:405
uword
u64 uword
Definition: types.h:112
vl_api_pg_create_interface_t
PacketGenerator create interface request.
Definition: pg.api:39
pg_interface_t::gso_enabled
u8 gso_enabled
Definition: pg.h:322
pg_api_hookup
static clib_error_t * pg_api_hookup(vlib_main_t *vm)
Definition: pg_api.c:173
vl_api_string_len
u32 vl_api_string_len(vl_api_string_t *astr)
Definition: api_shared.c:1184
PG_MODE_ETHERNET
@ PG_MODE_ETHERNET
Definition: pg.h:304
BAD_SW_IF_INDEX_LABEL
#define BAD_SW_IF_INDEX_LABEL
Definition: api_helper_macros.h:289
hash_get_mem
#define hash_get_mem(h, key)
Definition: hash.h:269
vl_api_pg_create_interface_t::gso_size
u32 gso_size
Definition: pg.api:45
vnet_hw_interface_t
Definition: interface.h:638
vnet_main_t
Definition: vnet.h:76
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition: vec.h:395
pg_main_t::interfaces
pg_interface_t * interfaces
Definition: pg.h:350
vl_api_pg_create_interface_v2_t::gso_enabled
bool gso_enabled
Definition: pg.api:52
vl_api_pg_create_interface_t::gso_enabled
bool gso_enabled
Definition: pg.api:44
pg_main_t::stream_index_by_name
uword * stream_index_by_name
Definition: pg.h:347
pg_main_t
Definition: pg.h:338
format_fns.h
format
description fragment has unexpected format
Definition: map.api:433
vl_api_pg_create_interface_reply_t
PacketGenerator create interface response.
Definition: pg.api:61
pg_enable_disable
void pg_enable_disable(u32 stream_index, int is_enable)
Definition: cli.c:58
u32
unsigned int u32
Definition: types.h:88
vnet_get_sup_hw_interface
static vnet_hw_interface_t * vnet_get_sup_hw_interface(vnet_main_t *vnm, u32 sw_if_index)
Definition: interface_funcs.h:92
vl_api_pg_create_interface_v2_t::interface_id
vl_api_interface_index_t interface_id
Definition: pg.api:51
api_helper_macros.h
vl_api_pg_create_interface_v2_reply_t::sw_if_index
vl_api_interface_index_t sw_if_index
Definition: pg.api:71
vl_api_pg_create_interface_v2_t::gso_size
u32 gso_size
Definition: pg.api:53
pg_main_t::msg_id_base
u16 msg_id_base
Definition: pg.h:360
vl_api_pg_create_interface_t_handler
static void vl_api_pg_create_interface_t_handler(vl_api_pg_create_interface_t *mp)
Definition: pg_api.c:32
vnet_interface_main_t::hw_interface_by_name
uword * hw_interface_by_name
Definition: interface.h:1004
vl_api_from_api_to_new_vec
u8 * vl_api_from_api_to_new_vec(void *mp, vl_api_string_t *astr)
Definition: api_shared.c:1202
vlib_main_t
Definition: main.h:102
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
a
a
Definition: bitmap.h:525
vec_terminate_c_string
#define vec_terminate_c_string(V)
(If necessary) NULL terminate a vector containing a c-string.
Definition: vec.h:1132
vl_api_pg_capture_t::pcap_file_name
string pcap_file_name[]
Definition: pg.api:104
rv
int __clib_unused rv
Definition: application.c:491
vl_api_pg_capture_t_handler
static void vl_api_pg_capture_t_handler(vl_api_pg_capture_t *mp)
Definition: pg_api.c:103
vnet.h
vl_api_pg_interface_enable_disable_coalesce_t_handler
static void vl_api_pg_interface_enable_disable_coalesce_t_handler(vl_api_pg_interface_enable_disable_coalesce_t *mp)
Definition: pg_api.c:69
pg_interface_t
Definition: pg.h:309
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
vl_api_from_api_to_new_c_string
char * vl_api_from_api_to_new_c_string(vl_api_string_t *astr)
Definition: api_shared.c:1218
vnet_main_t::interface_main
vnet_interface_main_t interface_main
Definition: vnet.h:81
pg_interface_t::sw_if_index
u32 sw_if_index
Definition: pg.h:315
vl_api_pg_create_interface_v2_t
Definition: pg.api:47
vl_api_pg_create_interface_reply_t::sw_if_index
vl_api_interface_index_t sw_if_index
Definition: pg.api:65
pg_main
pg_main_t pg_main
Definition: init.c:44