blob: 1ed7189ffc9e54a91551494c05501ca13f2effb2 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
2 * Copyright (c) 2015 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 * pg_stream.c: packet generator streams
17 *
18 * Copyright (c) 2008 Eliot Dresselhaus
19 *
20 * Permission is hereby granted, free of charge, to any person obtaining
21 * a copy of this software and associated documentation files (the
22 * "Software"), to deal in the Software without restriction, including
23 * without limitation the rights to use, copy, modify, merge, publish,
24 * distribute, sublicense, and/or sell copies of the Software, and to
25 * permit persons to whom the Software is furnished to do so, subject to
26 * the following conditions:
27 *
28 * The above copyright notice and this permission notice shall be
29 * included in all copies or substantial portions of the Software.
30 *
31 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
35 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
36 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
37 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38 */
39
40#include <vnet/vnet.h>
41#include <vnet/pg/pg.h>
Damjan Marion3d9c86e2016-07-04 21:04:40 +020042#include <vnet/ethernet/ethernet.h>
Neale Ranns0bfe5d82016-08-25 15:29:12 +010043#include <vnet/ip/ip.h>
44#include <vnet/mpls/mpls.h>
Damjan Marion51327ac2016-11-09 11:59:42 +010045#include <vnet/devices/devices.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070046
47/* Mark stream active or inactive. */
Calvin71e97c62016-08-19 16:23:14 -040048void
49pg_stream_enable_disable (pg_main_t * pg, pg_stream_t * s, int want_enabled)
Ed Warnickecb9cada2015-12-08 15:45:58 -070050{
Damjan Marion64034362016-11-07 22:19:55 +010051 vlib_main_t *vm;
Calvin71e97c62016-08-19 16:23:14 -040052 vnet_main_t *vnm = vnet_get_main ();
53 pg_interface_t *pi = pool_elt_at_index (pg->interfaces, s->pg_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -070054
55 want_enabled = want_enabled != 0;
56
57 if (pg_stream_is_enabled (s) == want_enabled)
58 /* No change necessary. */
59 return;
Calvin71e97c62016-08-19 16:23:14 -040060
Ed Warnickecb9cada2015-12-08 15:45:58 -070061 if (want_enabled)
62 s->n_packets_generated = 0;
63
64 /* Toggle enabled flag. */
65 s->flags ^= PG_STREAM_FLAGS_IS_ENABLED;
66
Calvin71e97c62016-08-19 16:23:14 -040067 ASSERT (!pool_is_free (pg->streams, s));
Ed Warnickecb9cada2015-12-08 15:45:58 -070068
Damjan Marion3a4ed392016-11-08 13:20:42 +010069 vec_validate (pg->enabled_streams, s->worker_index);
70 pg->enabled_streams[s->worker_index] =
71 clib_bitmap_set (pg->enabled_streams[s->worker_index], s - pg->streams,
72 want_enabled);
Ed Warnickecb9cada2015-12-08 15:45:58 -070073
Damjan Marion3d9c86e2016-07-04 21:04:40 +020074 if (want_enabled)
75 {
76 vnet_hw_interface_set_flags (vnm, pi->hw_if_index,
Calvin71e97c62016-08-19 16:23:14 -040077 VNET_HW_INTERFACE_FLAG_LINK_UP);
Ed Warnickecb9cada2015-12-08 15:45:58 -070078
Damjan Marion3d9c86e2016-07-04 21:04:40 +020079 vnet_sw_interface_set_flags (vnm, pi->sw_if_index,
Calvin71e97c62016-08-19 16:23:14 -040080 VNET_SW_INTERFACE_FLAG_ADMIN_UP);
Damjan Marion3d9c86e2016-07-04 21:04:40 +020081 }
Calvin71e97c62016-08-19 16:23:14 -040082
Damjan Marion64034362016-11-07 22:19:55 +010083 if (vlib_num_workers ())
84 vm = vlib_get_worker_vlib_main (s->worker_index);
85 else
86 vm = vlib_get_main ();
87
88 vlib_node_set_state (vm, pg_input_node.index,
Damjan Marion3a4ed392016-11-08 13:20:42 +010089 (clib_bitmap_is_zero
90 (pg->enabled_streams[s->worker_index]) ?
Damjan Marion64034362016-11-07 22:19:55 +010091 VLIB_NODE_STATE_DISABLED : VLIB_NODE_STATE_POLLING));
Ed Warnickecb9cada2015-12-08 15:45:58 -070092
93 s->packet_accumulator = 0;
94 s->time_last_generate = 0;
95}
96
Calvin71e97c62016-08-19 16:23:14 -040097static u8 *
98format_pg_interface_name (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -070099{
Calvin71e97c62016-08-19 16:23:14 -0400100 pg_main_t *pg = &pg_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700101 u32 if_index = va_arg (*args, u32);
Calvin71e97c62016-08-19 16:23:14 -0400102 pg_interface_t *pi;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700103
Damjan Marion3d9c86e2016-07-04 21:04:40 +0200104 pi = pool_elt_at_index (pg->interfaces, if_index);
105 s = format (s, "pg%d", pi->id);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700106
107 return s;
108}
109
Damjan Marion3d9c86e2016-07-04 21:04:40 +0200110static clib_error_t *
111pg_interface_admin_up_down (vnet_main_t * vnm, u32 hw_if_index, u32 flags)
112{
113 u32 hw_flags = 0;
114
115 if (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP)
116 hw_flags = VNET_HW_INTERFACE_FLAG_LINK_UP;
117
Calvin71e97c62016-08-19 16:23:14 -0400118 vnet_hw_interface_set_flags (vnm, hw_if_index, hw_flags);
Damjan Marion3d9c86e2016-07-04 21:04:40 +0200119
120 return 0;
121}
122
Calvin71e97c62016-08-19 16:23:14 -0400123/* *INDENT-OFF* */
Damjan Marion3d9c86e2016-07-04 21:04:40 +0200124VNET_DEVICE_CLASS (pg_dev_class) = {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700125 .name = "pg",
126 .tx_function = pg_output,
127 .format_device_name = format_pg_interface_name,
Damjan Marion3d9c86e2016-07-04 21:04:40 +0200128 .admin_up_down_function = pg_interface_admin_up_down,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700129};
Calvin71e97c62016-08-19 16:23:14 -0400130/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700131
Neale Rannsb80c5362016-10-08 13:03:40 +0100132static u8 *
133pg_build_rewrite (vnet_main_t * vnm,
134 u32 sw_if_index,
135 vnet_link_t link_type, const void *dst_address)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700136{
Neale Rannsb80c5362016-10-08 13:03:40 +0100137 u8 *rewrite = NULL;
138 u16 *h;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700139
Neale Rannsb80c5362016-10-08 13:03:40 +0100140 vec_validate (rewrite, sizeof (*h) - 1);
141 h = (u16 *) rewrite;
142 h[0] = clib_host_to_net_u16 (vnet_link_to_l3_proto (link_type));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700143
Neale Rannsb80c5362016-10-08 13:03:40 +0100144 return (rewrite);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700145}
146
Calvin71e97c62016-08-19 16:23:14 -0400147/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700148VNET_HW_INTERFACE_CLASS (pg_interface_class,static) = {
149 .name = "Packet generator",
Neale Rannsb80c5362016-10-08 13:03:40 +0100150 .build_rewrite = pg_build_rewrite,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700151};
Calvin71e97c62016-08-19 16:23:14 -0400152/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700153
Damjan Marion3d9c86e2016-07-04 21:04:40 +0200154static u32
155pg_eth_flag_change (vnet_main_t * vnm, vnet_hw_interface_t * hi, u32 flags)
156{
157 /* nothing for now */
158 return 0;
159}
160
Calvin71e97c62016-08-19 16:23:14 -0400161u32
162pg_interface_add_or_get (pg_main_t * pg, uword if_id)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700163{
Calvin71e97c62016-08-19 16:23:14 -0400164 vnet_main_t *vnm = vnet_get_main ();
165 vlib_main_t *vm = vlib_get_main ();
166 pg_interface_t *pi;
167 vnet_hw_interface_t *hi;
Damjan Marion3d9c86e2016-07-04 21:04:40 +0200168 uword *p;
169 u32 i;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700170
Damjan Marion3d9c86e2016-07-04 21:04:40 +0200171 p = hash_get (pg->if_index_by_if_id, if_id);
172
173 if (p)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700174 {
Damjan Marion3d9c86e2016-07-04 21:04:40 +0200175 return p[0];
176 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700177 else
178 {
Damjan Marion3d9c86e2016-07-04 21:04:40 +0200179 u8 hw_addr[6];
Calvin71e97c62016-08-19 16:23:14 -0400180 f64 now = vlib_time_now (vm);
Damjan Marion3d9c86e2016-07-04 21:04:40 +0200181 u32 rnd;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700182
Damjan Marion3d9c86e2016-07-04 21:04:40 +0200183 pool_get (pg->interfaces, pi);
184 i = pi - pg->interfaces;
185
186 rnd = (u32) (now * 1e6);
187 rnd = random_u32 (&rnd);
Calvin71e97c62016-08-19 16:23:14 -0400188 clib_memcpy (hw_addr + 2, &rnd, sizeof (rnd));
Damjan Marion3d9c86e2016-07-04 21:04:40 +0200189 hw_addr[0] = 2;
190 hw_addr[1] = 0xfe;
191
192 pi->id = if_id;
193 ethernet_register_interface (vnm, pg_dev_class.index, i, hw_addr,
194 &pi->hw_if_index, pg_eth_flag_change);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700195 hi = vnet_get_hw_interface (vnm, pi->hw_if_index);
196 pi->sw_if_index = hi->sw_if_index;
Damjan Marion3d9c86e2016-07-04 21:04:40 +0200197
198 hash_set (pg->if_index_by_if_id, if_id, i);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100199
Damjan Marion64034362016-11-07 22:19:55 +0100200 if (vlib_num_workers ())
201 {
202 pi->lockp = clib_mem_alloc_aligned (CLIB_CACHE_LINE_BYTES,
203 CLIB_CACHE_LINE_BYTES);
204 *pi->lockp = 0;
205 }
206
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100207 ip4_sw_interface_enable_disable (pi->hw_if_index, 1);
208 ip6_sw_interface_enable_disable (pi->hw_if_index, 1);
209 mpls_sw_interface_enable_disable (&mpls_main, pi->hw_if_index, 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700210 }
211
212 return i;
213}
214
Calvin71e97c62016-08-19 16:23:14 -0400215static void
216do_edit (pg_stream_t * stream,
217 pg_edit_group_t * g, pg_edit_t * e, uword want_commit)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700218{
219 u32 i, i0, i1, mask, n_bits_left;
Calvin71e97c62016-08-19 16:23:14 -0400220 u8 *v, *s, *m;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700221
222 i0 = e->lsb_bit_offset / BITS (u8);
223
224 /* Make space for edit in value and mask. */
225 vec_validate (g->fixed_packet_data, i0);
226 vec_validate (g->fixed_packet_data_mask, i0);
227
228 if (e->type != PG_EDIT_FIXED)
229 {
230 switch (e->type)
231 {
232 case PG_EDIT_RANDOM:
233 case PG_EDIT_INCREMENT:
234 e->last_increment_value = pg_edit_get_value (e, PG_EDIT_LO);
235 break;
236
237 default:
238 break;
239 }
240
Calvin71e97c62016-08-19 16:23:14 -0400241 if (want_commit)
242 {
243 ASSERT (e->type != PG_EDIT_INVALID_TYPE);
244 vec_add1 (g->non_fixed_edits, e[0]);
245 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700246 return;
247 }
248
249 s = g->fixed_packet_data;
250 m = g->fixed_packet_data_mask;
251
252 n_bits_left = e->n_bits;
253 i0 = e->lsb_bit_offset / BITS (u8);
254 i1 = e->lsb_bit_offset % BITS (u8);
255
256 v = e->values[PG_EDIT_LO];
257 i = pg_edit_n_alloc_bytes (e) - 1;
258
259 /* Odd low order bits?. */
260 if (i1 != 0 && n_bits_left > 0)
261 {
262 u32 n = clib_min (n_bits_left, BITS (u8) - i1);
263
264 mask = pow2_mask (n) << i1;
265
266 ASSERT (i0 < vec_len (s));
267 ASSERT (i < vec_len (v));
Calvin71e97c62016-08-19 16:23:14 -0400268 ASSERT ((v[i] & ~mask) == 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700269
270 s[i0] |= v[i] & mask;
271 m[i0] |= mask;
272
273 i0--;
274 i--;
275 n_bits_left -= n;
276 }
277
278 /* Even bytes. */
279 while (n_bits_left >= 8)
280 {
281 ASSERT (i0 < vec_len (s));
282 ASSERT (i < vec_len (v));
283
284 s[i0] = v[i];
285 m[i0] = ~0;
286
287 i0--;
288 i--;
289 n_bits_left -= 8;
290 }
291
292 /* Odd high order bits. */
293 if (n_bits_left > 0)
294 {
295 mask = pow2_mask (n_bits_left);
296
297 ASSERT (i0 < vec_len (s));
298 ASSERT (i < vec_len (v));
Calvin71e97c62016-08-19 16:23:14 -0400299 ASSERT ((v[i] & ~mask) == 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700300
301 s[i0] |= v[i] & mask;
302 m[i0] |= mask;
303 }
304
305 if (want_commit)
306 pg_edit_free (e);
307}
308
Calvin71e97c62016-08-19 16:23:14 -0400309void
310pg_edit_group_get_fixed_packet_data (pg_stream_t * s,
311 u32 group_index,
312 void *packet_data,
313 void *packet_data_mask)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700314{
Calvin71e97c62016-08-19 16:23:14 -0400315 pg_edit_group_t *g = pg_stream_get_group (s, group_index);
316 pg_edit_t *e;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700317
Calvin71e97c62016-08-19 16:23:14 -0400318 vec_foreach (e, g->edits) do_edit (s, g, e, /* want_commit */ 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700319
Calvin71e97c62016-08-19 16:23:14 -0400320 clib_memcpy (packet_data, g->fixed_packet_data,
321 vec_len (g->fixed_packet_data));
322 clib_memcpy (packet_data_mask, g->fixed_packet_data_mask,
323 vec_len (g->fixed_packet_data_mask));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700324}
325
Calvin71e97c62016-08-19 16:23:14 -0400326static void
327perform_fixed_edits (pg_stream_t * s)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700328{
Calvin71e97c62016-08-19 16:23:14 -0400329 pg_edit_group_t *g;
330 pg_edit_t *e;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700331 word i;
332
333 for (i = vec_len (s->edit_groups) - 1; i >= 0; i--)
334 {
335 g = vec_elt_at_index (s->edit_groups, i);
Calvin71e97c62016-08-19 16:23:14 -0400336 vec_foreach (e, g->edits) do_edit (s, g, e, /* want_commit */ 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700337
338 /* All edits have either been performed or added to
Calvin71e97c62016-08-19 16:23:14 -0400339 g->non_fixed_edits. So, we can delete the vector. */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700340 vec_free (g->edits);
341 }
342
343 vec_free (s->fixed_packet_data_mask);
344 vec_free (s->fixed_packet_data);
345 vec_foreach (g, s->edit_groups)
Calvin71e97c62016-08-19 16:23:14 -0400346 {
347 int i;
348 g->start_byte_offset = vec_len (s->fixed_packet_data);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700349
Calvin71e97c62016-08-19 16:23:14 -0400350 /* Relocate and copy non-fixed edits from group to stream. */
351 vec_foreach (e, g->non_fixed_edits)
352 e->lsb_bit_offset += g->start_byte_offset * BITS (u8);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700353
Calvin71e97c62016-08-19 16:23:14 -0400354 for (i = 0; i < vec_len (g->non_fixed_edits); i++)
355 ASSERT (g->non_fixed_edits[i].type != PG_EDIT_INVALID_TYPE);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700356
Calvin71e97c62016-08-19 16:23:14 -0400357 vec_add (s->non_fixed_edits,
358 g->non_fixed_edits, vec_len (g->non_fixed_edits));
359 vec_free (g->non_fixed_edits);
360
361 vec_add (s->fixed_packet_data,
362 g->fixed_packet_data, vec_len (g->fixed_packet_data));
363 vec_add (s->fixed_packet_data_mask,
364 g->fixed_packet_data_mask, vec_len (g->fixed_packet_data_mask));
365 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700366}
367
Calvin71e97c62016-08-19 16:23:14 -0400368void
369pg_stream_add (pg_main_t * pg, pg_stream_t * s_init)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700370{
Damjan Marion64034362016-11-07 22:19:55 +0100371 vlib_main_t *vm = vlib_get_main ();
Calvin71e97c62016-08-19 16:23:14 -0400372 pg_stream_t *s;
373 uword *p;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700374
Calvin71e97c62016-08-19 16:23:14 -0400375 if (!pg->stream_index_by_name)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700376 pg->stream_index_by_name
377 = hash_create_vec (0, sizeof (s->name[0]), sizeof (uword));
378
379 /* Delete any old stream with the same name. */
380 if (s_init->name
381 && (p = hash_get_mem (pg->stream_index_by_name, s_init->name)))
382 {
383 pg_stream_del (pg, p[0]);
384 }
385
386 pool_get (pg->streams, s);
387 s[0] = s_init[0];
388
389 /* Give it a name. */
Calvin71e97c62016-08-19 16:23:14 -0400390 if (!s->name)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700391 s->name = format (0, "stream%d", s - pg->streams);
392 else
393 s->name = vec_dup (s->name);
394
395 hash_set_mem (pg->stream_index_by_name, s->name, s - pg->streams);
396
397 /* Get fixed part of buffer data. */
Damjan Marionddbdd4f2016-07-08 22:08:16 +0200398 if (s->edit_groups)
399 perform_fixed_edits (s);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700400
401 /* Determine packet size. */
402 switch (s->packet_size_edit_type)
403 {
404 case PG_EDIT_INCREMENT:
405 case PG_EDIT_RANDOM:
406 if (s->min_packet_bytes == s->max_packet_bytes)
407 s->packet_size_edit_type = PG_EDIT_FIXED;
408 break;
409
410 default:
411 /* Get packet size from fixed edits. */
412 s->packet_size_edit_type = PG_EDIT_FIXED;
Calvin71e97c62016-08-19 16:23:14 -0400413 if (!s->replay_packet_templates)
414 s->min_packet_bytes = s->max_packet_bytes =
415 vec_len (s->fixed_packet_data);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700416 break;
417 }
418
419 s->last_increment_packet_size = s->min_packet_bytes;
420
421 {
Calvin71e97c62016-08-19 16:23:14 -0400422 pg_buffer_index_t *bi;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700423 int n;
424
Juraj Slobodae3371af2016-12-02 14:37:16 +0100425#if DPDK > 0
426 s->buffer_bytes = VLIB_BUFFER_DATA_SIZE;
427#endif
428
Calvin71e97c62016-08-19 16:23:14 -0400429 if (!s->buffer_bytes)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700430 s->buffer_bytes = s->max_packet_bytes;
431
432 s->buffer_bytes = vlib_buffer_round_size (s->buffer_bytes);
433
434 n = s->max_packet_bytes / s->buffer_bytes;
435 n += (s->max_packet_bytes % s->buffer_bytes) != 0;
436
437 vec_resize (s->buffer_indices, n);
438
439 vec_foreach (bi, s->buffer_indices)
Damjan Marion64034362016-11-07 22:19:55 +0100440 {
Damjan Marion64034362016-11-07 22:19:55 +0100441 bi->free_list_index =
Damjan Marion409ef612016-11-11 21:35:18 +0100442 vlib_buffer_create_free_list (vm, s->buffer_bytes,
Damjan Marion64034362016-11-07 22:19:55 +0100443 "pg stream %d buffer #%d",
444 s - pg->streams,
445 1 + (bi - s->buffer_indices));
446 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700447 }
448
449 /* Find an interface to use. */
Damjan Marion3d9c86e2016-07-04 21:04:40 +0200450 s->pg_if_index = pg_interface_add_or_get (pg, s->if_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700451
452 {
Calvin71e97c62016-08-19 16:23:14 -0400453 pg_interface_t *pi = pool_elt_at_index (pg->interfaces, s->pg_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700454 vlib_rx_or_tx_t rx_or_tx;
455
456 vlib_foreach_rx_tx (rx_or_tx)
Calvin71e97c62016-08-19 16:23:14 -0400457 {
458 if (s->sw_if_index[rx_or_tx] == ~0)
459 s->sw_if_index[rx_or_tx] = pi->sw_if_index;
460 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700461 }
462
463 /* Connect the graph. */
Damjan Marion51327ac2016-11-09 11:59:42 +0100464 s->next_index = vlib_node_add_next (vm, device_input_node.index,
465 s->node_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700466}
467
Calvin71e97c62016-08-19 16:23:14 -0400468void
469pg_stream_del (pg_main_t * pg, uword index)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700470{
Damjan Marion64034362016-11-07 22:19:55 +0100471 vlib_main_t *vm = vlib_get_main ();
Calvin71e97c62016-08-19 16:23:14 -0400472 pg_stream_t *s;
473 pg_buffer_index_t *bi;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700474
475 s = pool_elt_at_index (pg->streams, index);
476
477 pg_stream_enable_disable (pg, s, /* want_enabled */ 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700478 hash_unset_mem (pg->stream_index_by_name, s->name);
479
480 vec_foreach (bi, s->buffer_indices)
Calvin71e97c62016-08-19 16:23:14 -0400481 {
Damjan Marion409ef612016-11-11 21:35:18 +0100482 vlib_buffer_delete_free_list (vm, bi->free_list_index);
Calvin71e97c62016-08-19 16:23:14 -0400483 clib_fifo_free (bi->buffer_fifo);
484 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700485
486 pg_stream_free (s);
487 pool_put (pg->streams, s);
488}
489
Calvin71e97c62016-08-19 16:23:14 -0400490
491/*
492 * fd.io coding-style-patch-verification: ON
493 *
494 * Local Variables:
495 * eval: (c-set-style "gnu")
496 * End:
497 */