LCOV - code coverage report
Current view: top level - vnet/pg - stream.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 231 262 88.2 %
Date: 2023-10-26 01:39:38 Functions: 20 23 87.0 %

          Line data    Source code
       1             : /*
       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>
      42             : #include <vnet/ethernet/ethernet.h>
      43             : #include <vnet/ip/ip.h>
      44             : #include <vnet/mpls/mpls.h>
      45             : #include <vnet/devices/devices.h>
      46             : 
      47             : /* Mark stream active or inactive. */
      48             : void
      49       47003 : pg_stream_enable_disable (pg_main_t * pg, pg_stream_t * s, int want_enabled)
      50             : {
      51             :   vlib_main_t *vm;
      52       47003 :   vnet_main_t *vnm = vnet_get_main ();
      53       47003 :   pg_interface_t *pi = pool_elt_at_index (pg->interfaces, s->pg_if_index);
      54             : 
      55       47003 :   want_enabled = want_enabled != 0;
      56             : 
      57       47003 :   if (pg_stream_is_enabled (s) == want_enabled)
      58             :     /* No change necessary. */
      59       15658 :     return;
      60             : 
      61       31345 :   if (want_enabled)
      62       15673 :     s->n_packets_generated = 0;
      63             : 
      64             :   /* Toggle enabled flag. */
      65       31345 :   s->flags ^= PG_STREAM_FLAGS_IS_ENABLED;
      66             : 
      67       31345 :   ASSERT (!pool_is_free (pg->streams, s));
      68             : 
      69       31345 :   vec_validate (pg->enabled_streams, s->worker_index);
      70       62690 :   pg->enabled_streams[s->worker_index] =
      71       31345 :     clib_bitmap_set (pg->enabled_streams[s->worker_index], s - pg->streams,
      72             :                      want_enabled);
      73             : 
      74       31345 :   if (want_enabled)
      75             :     {
      76       15673 :       vnet_hw_interface_set_flags (vnm, pi->hw_if_index,
      77             :                                    VNET_HW_INTERFACE_FLAG_LINK_UP);
      78             : 
      79       15673 :       vnet_sw_interface_set_flags (vnm, pi->sw_if_index,
      80             :                                    VNET_SW_INTERFACE_FLAG_ADMIN_UP);
      81             :     }
      82             : 
      83       31345 :   if (vlib_num_workers ())
      84        1499 :     vm = vlib_get_worker_vlib_main (s->worker_index);
      85             :   else
      86       29846 :     vm = vlib_get_main ();
      87             : 
      88       31345 :   vlib_node_set_state (vm, pg_input_node.index,
      89       31345 :                        (clib_bitmap_is_zero
      90       31345 :                         (pg->enabled_streams[s->worker_index]) ?
      91             :                         VLIB_NODE_STATE_DISABLED : VLIB_NODE_STATE_POLLING));
      92             : 
      93       31345 :   s->packet_accumulator = 0;
      94       31345 :   s->time_last_generate = 0;
      95             : }
      96             : 
      97             : static u8 *
      98      333097 : format_pg_output_trace (u8 * s, va_list * va)
      99             : {
     100      333097 :   CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *);
     101      333097 :   CLIB_UNUSED (vlib_node_t * node) = va_arg (*va, vlib_node_t *);
     102      333097 :   pg_output_trace_t *t = va_arg (*va, pg_output_trace_t *);
     103      333097 :   u32 indent = format_get_indent (s);
     104             : 
     105      333097 :   s = format (s, "%Ubuffer 0x%x: %U", format_white_space, indent,
     106             :               t->buffer_index, format_vnet_buffer_no_chain, &t->buffer);
     107             : 
     108      333097 :   s = format (s, "\n%U%U", format_white_space, indent,
     109      333097 :               format_ethernet_header_with_length, t->buffer.pre_data,
     110             :               sizeof (t->buffer.pre_data));
     111             : 
     112      333097 :   return s;
     113             : }
     114             : 
     115             : static u8 *
     116        8780 : format_pg_interface_name (u8 * s, va_list * args)
     117             : {
     118        8780 :   pg_main_t *pg = &pg_main;
     119        8780 :   u32 if_index = va_arg (*args, u32);
     120             :   pg_interface_t *pi;
     121             : 
     122        8780 :   pi = pool_elt_at_index (pg->interfaces, if_index);
     123        8780 :   s = format (s, "pg%d", pi->id);
     124             : 
     125        8780 :   return s;
     126             : }
     127             : 
     128             : static clib_error_t *
     129        4824 : pg_interface_admin_up_down (vnet_main_t * vnm, u32 hw_if_index, u32 flags)
     130             : {
     131        4824 :   u32 hw_flags = 0;
     132             : 
     133        4824 :   if (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP)
     134        2595 :     hw_flags = VNET_HW_INTERFACE_FLAG_LINK_UP;
     135             : 
     136        4824 :   vnet_hw_interface_set_flags (vnm, hw_if_index, hw_flags);
     137             : 
     138        4824 :   return 0;
     139             : }
     140             : 
     141             : static int
     142       19407 : pg_mac_address_cmp (const mac_address_t * m1, const mac_address_t * m2)
     143             : {
     144       19407 :   return (!mac_address_cmp (m1, m2));
     145             : }
     146             : 
     147             : static clib_error_t *
     148       24422 : pg_add_del_mac_address (vnet_hw_interface_t * hi,
     149             :                         const u8 * address, u8 is_add)
     150             : {
     151       24422 :   pg_main_t *pg = &pg_main;
     152             : 
     153       24422 :   if (ethernet_address_cast (address))
     154             :     {
     155             :       mac_address_t mac;
     156             :       pg_interface_t *pi;
     157             : 
     158       24418 :       pi = pool_elt_at_index (pg->interfaces, hi->dev_instance);
     159             : 
     160       24418 :       mac_address_from_bytes (&mac, address);
     161       24418 :       if (is_add)
     162       13978 :         vec_add1 (pi->allowed_mcast_macs, mac);
     163             :       else
     164             :         {
     165       19407 :           u32 pos = vec_search_with_function (pi->allowed_mcast_macs, &mac,
     166             :                                               pg_mac_address_cmp);
     167       10440 :           if (~0 != pos)
     168       10440 :             vec_del1 (pi->allowed_mcast_macs, pos);
     169             :         }
     170             :     }
     171       24422 :   return (NULL);
     172             : }
     173             : 
     174             : /* *INDENT-OFF* */
     175       12095 : VNET_DEVICE_CLASS (pg_dev_class) = {
     176             :   .name = "pg",
     177             :   .tx_function = pg_output,
     178             :   .format_device_name = format_pg_interface_name,
     179             :   .format_tx_trace = format_pg_output_trace,
     180             :   .admin_up_down_function = pg_interface_admin_up_down,
     181             :   .mac_addr_add_del_function = pg_add_del_mac_address,
     182             : };
     183             : /* *INDENT-ON* */
     184             : 
     185             : static u8 *
     186           0 : pg_build_rewrite (vnet_main_t * vnm,
     187             :                   u32 sw_if_index,
     188             :                   vnet_link_t link_type, const void *dst_address)
     189             : {
     190           0 :   u8 *rewrite = NULL;
     191             :   u16 *h;
     192             : 
     193           0 :   vec_validate (rewrite, sizeof (*h) - 1);
     194           0 :   h = (u16 *) rewrite;
     195           0 :   h[0] = clib_host_to_net_u16 (vnet_link_to_l3_proto (link_type));
     196             : 
     197           0 :   return (rewrite);
     198             : }
     199             : 
     200             : /* *INDENT-OFF* */
     201        8063 : VNET_HW_INTERFACE_CLASS (pg_interface_class,static) = {
     202             :   .name = "Packet generator",
     203             :   .build_rewrite = pg_build_rewrite,
     204             : };
     205             : /* *INDENT-ON* */
     206             : 
     207             : static u32
     208         457 : pg_eth_flag_change (vnet_main_t * vnm, vnet_hw_interface_t * hi, u32 flags)
     209             : {
     210             :   /* nothing for now */
     211         457 :   return 0;
     212             : }
     213             : 
     214             : void
     215           2 : pg_interface_enable_disable_coalesce (pg_interface_t * pi, u8 enable,
     216             :                                       u32 tx_node_index)
     217             : {
     218           2 :   if (enable)
     219             :     {
     220           2 :       gro_flow_table_init (&pi->flow_table, 1 /* is_l2 */ ,
     221             :                            tx_node_index);
     222           2 :       pi->coalesce_enabled = 1;
     223             :     }
     224             :   else
     225             :     {
     226           0 :       pi->coalesce_enabled = 0;
     227           0 :       gro_flow_table_free (pi->flow_table);
     228             :     }
     229           2 : }
     230             : 
     231             : u8 *
     232           0 : format_pg_tun_tx_trace (u8 *s, va_list *args)
     233             : {
     234           0 :   CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
     235           0 :   CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
     236             : 
     237           0 :   s = format (s, "PG: tunnel (no-encap)");
     238           0 :   return s;
     239             : }
     240             : 
     241        8063 : VNET_HW_INTERFACE_CLASS (pg_tun_hw_interface_class) = {
     242             :   .name = "PG-tun",
     243             :   //.format_header = format_gre_header_with_length,
     244             :   //.unformat_header = unformat_gre_header,
     245             :   .build_rewrite = NULL,
     246             :   //.update_adjacency = gre_update_adj,
     247             :   .flags = VNET_HW_INTERFACE_CLASS_FLAG_P2P,
     248             :   .tx_hash_fn_type = VNET_HASH_FN_TYPE_IP,
     249             : };
     250             : 
     251             : u32
     252       18156 : pg_interface_add_or_get (pg_main_t *pg, uword if_id, u8 gso_enabled,
     253             :                          u32 gso_size, u8 coalesce_enabled,
     254             :                          pg_interface_mode_t mode)
     255             : {
     256       18156 :   vnet_main_t *vnm = vnet_get_main ();
     257       18156 :   vlib_main_t *vm = vlib_get_main ();
     258             :   pg_interface_t *pi;
     259             :   vnet_hw_interface_t *hi;
     260             :   uword *p;
     261             :   u32 i;
     262             : 
     263       18156 :   p = hash_get (pg->if_index_by_if_id, if_id);
     264             : 
     265       18156 :   if (p)
     266             :     {
     267       16665 :       return p[0];
     268             :     }
     269             :   else
     270             :     {
     271        1491 :       vnet_eth_interface_registration_t eir = {};
     272             :       u8 hw_addr[6];
     273        1491 :       f64 now = vlib_time_now (vm);
     274             :       u32 rnd;
     275             : 
     276        1491 :       pool_get (pg->interfaces, pi);
     277        1491 :       i = pi - pg->interfaces;
     278             : 
     279        1491 :       rnd = (u32) (now * 1e6);
     280        1491 :       rnd = random_u32 (&rnd);
     281        1491 :       clib_memcpy_fast (hw_addr + 2, &rnd, sizeof (rnd));
     282        1491 :       hw_addr[0] = 2;
     283        1491 :       hw_addr[1] = 0xfe;
     284             : 
     285        1491 :       pi->id = if_id;
     286        1491 :       pi->mode = mode;
     287             : 
     288        1491 :       switch (pi->mode)
     289             :         {
     290        1485 :         case PG_MODE_ETHERNET:
     291        1485 :           eir.dev_class_index = pg_dev_class.index;
     292        1485 :           eir.dev_instance = i;
     293        1485 :           eir.address = hw_addr;
     294        1485 :           eir.cb.flag_change = pg_eth_flag_change;
     295        1485 :           pi->hw_if_index = vnet_eth_register_interface (vnm, &eir);
     296        1485 :           break;
     297           6 :         case PG_MODE_IP4:
     298             :         case PG_MODE_IP6:
     299           6 :           pi->hw_if_index = vnet_register_interface (
     300             :             vnm, pg_dev_class.index, i, pg_tun_hw_interface_class.index, i);
     301           6 :           break;
     302             :         }
     303        1491 :       hi = vnet_get_hw_interface (vnm, pi->hw_if_index);
     304        1491 :       if (gso_enabled)
     305             :         {
     306           5 :           vnet_hw_if_set_caps (vnm, pi->hw_if_index, VNET_HW_IF_CAP_TCP_GSO);
     307           5 :           pi->gso_enabled = 1;
     308           5 :           pi->gso_size = gso_size;
     309           5 :           if (coalesce_enabled)
     310             :             {
     311           0 :               pg_interface_enable_disable_coalesce (pi, 1, hi->tx_node_index);
     312             :             }
     313             :         }
     314        1491 :       pi->sw_if_index = hi->sw_if_index;
     315             : 
     316        1491 :       hash_set (pg->if_index_by_if_id, if_id, i);
     317             : 
     318        1491 :       vec_validate (pg->if_id_by_sw_if_index, hi->sw_if_index);
     319        1491 :       pg->if_id_by_sw_if_index[hi->sw_if_index] = i;
     320             : 
     321        1491 :       if (vlib_num_workers ())
     322             :         {
     323          61 :           pi->lockp = clib_mem_alloc_aligned (CLIB_CACHE_LINE_BYTES,
     324             :                                               CLIB_CACHE_LINE_BYTES);
     325          61 :           *pi->lockp = 0;
     326             :         }
     327             :     }
     328             : 
     329        1491 :   return i;
     330             : }
     331             : 
     332             : static void
     333         209 : do_edit (pg_stream_t * stream,
     334             :          pg_edit_group_t * g, pg_edit_t * e, uword want_commit)
     335             : {
     336             :   u32 i, i0, i1, mask, n_bits_left;
     337             :   u8 *v, *s, *m;
     338             : 
     339         209 :   i0 = e->lsb_bit_offset / BITS (u8);
     340             : 
     341             :   /* Make space for edit in value and mask. */
     342         209 :   vec_validate (g->fixed_packet_data, i0);
     343         209 :   vec_validate (g->fixed_packet_data_mask, i0);
     344             : 
     345         209 :   if (e->type != PG_EDIT_FIXED)
     346             :     {
     347          12 :       switch (e->type)
     348             :         {
     349           2 :         case PG_EDIT_RANDOM:
     350             :         case PG_EDIT_INCREMENT:
     351           2 :           e->last_increment_value = pg_edit_get_value (e, PG_EDIT_LO);
     352           2 :           break;
     353             : 
     354          10 :         default:
     355          10 :           break;
     356             :         }
     357             : 
     358          12 :       if (want_commit)
     359             :         {
     360          10 :           ASSERT (e->type != PG_EDIT_INVALID_TYPE);
     361          10 :           vec_add1 (g->non_fixed_edits, e[0]);
     362             :         }
     363          12 :       return;
     364             :     }
     365             : 
     366         197 :   s = g->fixed_packet_data;
     367         197 :   m = g->fixed_packet_data_mask;
     368             : 
     369         197 :   n_bits_left = e->n_bits;
     370         197 :   i0 = e->lsb_bit_offset / BITS (u8);
     371         197 :   i1 = e->lsb_bit_offset % BITS (u8);
     372             : 
     373         197 :   v = e->values[PG_EDIT_LO];
     374         197 :   i = pg_edit_n_alloc_bytes (e) - 1;
     375             : 
     376             :   /* Odd low order bits?. */
     377         197 :   if (i1 != 0 && n_bits_left > 0)
     378             :     {
     379          36 :       u32 n = clib_min (n_bits_left, BITS (u8) - i1);
     380             : 
     381          36 :       mask = pow2_mask (n) << i1;
     382             : 
     383          36 :       ASSERT (i0 < vec_len (s));
     384          36 :       ASSERT (i < vec_len (v));
     385          36 :       ASSERT ((v[i] & ~mask) == 0);
     386             : 
     387          36 :       s[i0] |= v[i] & mask;
     388          36 :       m[i0] |= mask;
     389             : 
     390          36 :       i0--;
     391          36 :       i--;
     392          36 :       n_bits_left -= n;
     393             :     }
     394             : 
     395             :   /* Even bytes. */
     396        1953 :   while (n_bits_left >= 8)
     397             :     {
     398        1756 :       ASSERT (i0 < vec_len (s));
     399        1756 :       ASSERT (i < vec_len (v));
     400             : 
     401        1756 :       s[i0] = v[i];
     402        1756 :       m[i0] = ~0;
     403             : 
     404        1756 :       i0--;
     405        1756 :       i--;
     406        1756 :       n_bits_left -= 8;
     407             :     }
     408             : 
     409             :   /* Odd high order bits. */
     410         197 :   if (n_bits_left > 0)
     411             :     {
     412          28 :       mask = pow2_mask (n_bits_left);
     413             : 
     414          28 :       ASSERT (i0 < vec_len (s));
     415          28 :       ASSERT (i < vec_len (v));
     416          28 :       ASSERT ((v[i] & ~mask) == 0);
     417             : 
     418          28 :       s[i0] |= v[i] & mask;
     419          28 :       m[i0] |= mask;
     420             :     }
     421             : 
     422         197 :   if (want_commit)
     423         185 :     pg_edit_free (e);
     424             : }
     425             : 
     426             : void
     427           1 : pg_edit_group_get_fixed_packet_data (pg_stream_t * s,
     428             :                                      u32 group_index,
     429             :                                      void *packet_data,
     430             :                                      void *packet_data_mask)
     431             : {
     432           1 :   pg_edit_group_t *g = pg_stream_get_group (s, group_index);
     433             :   pg_edit_t *e;
     434             : 
     435          15 :   vec_foreach (e, g->edits) do_edit (s, g, e, /* want_commit */ 0);
     436             : 
     437           1 :   clib_memcpy_fast (packet_data, g->fixed_packet_data,
     438           1 :                     vec_len (g->fixed_packet_data));
     439           1 :   clib_memcpy_fast (packet_data_mask, g->fixed_packet_data_mask,
     440           1 :                     vec_len (g->fixed_packet_data_mask));
     441           1 : }
     442             : 
     443             : static void
     444          14 : perform_fixed_edits (pg_stream_t * s)
     445             : {
     446             :   pg_edit_group_t *g;
     447             :   pg_edit_t *e;
     448             :   word i;
     449             : 
     450          59 :   for (i = vec_len (s->edit_groups) - 1; i >= 0; i--)
     451             :     {
     452          45 :       g = vec_elt_at_index (s->edit_groups, i);
     453         240 :       vec_foreach (e, g->edits) do_edit (s, g, e, /* want_commit */ 1);
     454             : 
     455             :       /* All edits have either been performed or added to
     456             :          g->non_fixed_edits.  So, we can delete the vector. */
     457          45 :       vec_free (g->edits);
     458             :     }
     459             : 
     460          14 :   vec_free (s->fixed_packet_data_mask);
     461          14 :   vec_free (s->fixed_packet_data);
     462          59 :   vec_foreach (g, s->edit_groups)
     463             :   {
     464             :     int i;
     465          45 :     g->start_byte_offset = vec_len (s->fixed_packet_data);
     466             : 
     467             :     /* Relocate and copy non-fixed edits from group to stream. */
     468          55 :     vec_foreach (e, g->non_fixed_edits)
     469          10 :       e->lsb_bit_offset += g->start_byte_offset * BITS (u8);
     470             : 
     471          55 :     for (i = 0; i < vec_len (g->non_fixed_edits); i++)
     472          10 :       ASSERT (g->non_fixed_edits[i].type != PG_EDIT_INVALID_TYPE);
     473             : 
     474          45 :     vec_add (s->non_fixed_edits,
     475             :              g->non_fixed_edits, vec_len (g->non_fixed_edits));
     476          45 :     vec_free (g->non_fixed_edits);
     477             : 
     478          45 :     vec_add (s->fixed_packet_data,
     479             :              g->fixed_packet_data, vec_len (g->fixed_packet_data));
     480          45 :     vec_add (s->fixed_packet_data_mask,
     481             :              g->fixed_packet_data_mask, vec_len (g->fixed_packet_data_mask));
     482             :   }
     483          14 : }
     484             : 
     485             : void
     486       15671 : pg_stream_add (pg_main_t * pg, pg_stream_t * s_init)
     487             : {
     488       15671 :   vlib_main_t *vm = vlib_get_main ();
     489             :   pg_stream_t *s;
     490             :   uword *p;
     491             : 
     492       15671 :   if (!pg->stream_index_by_name)
     493             :     pg->stream_index_by_name
     494         485 :       = hash_create_vec (0, sizeof (s->name[0]), sizeof (uword));
     495             : 
     496             :   /* Delete any old stream with the same name. */
     497       15671 :   if (s_init->name
     498       31342 :       && (p = hash_get_mem (pg->stream_index_by_name, s_init->name)))
     499             :     {
     500           1 :       pg_stream_del (pg, p[0]);
     501             :     }
     502             : 
     503       15671 :   pool_get (pg->streams, s);
     504       15671 :   s[0] = s_init[0];
     505             : 
     506             :   /* Give it a name. */
     507       15671 :   if (!s->name)
     508           0 :     s->name = format (0, "stream%d", s - pg->streams);
     509             :   else
     510       15671 :     s->name = vec_dup (s->name);
     511             : 
     512       31342 :   hash_set_mem (pg->stream_index_by_name, s->name, s - pg->streams);
     513             : 
     514             :   /* Get fixed part of buffer data. */
     515       15671 :   if (s->edit_groups)
     516          14 :     perform_fixed_edits (s);
     517             : 
     518             :   /* Determine packet size. */
     519       15671 :   switch (s->packet_size_edit_type)
     520             :     {
     521          14 :     case PG_EDIT_INCREMENT:
     522             :     case PG_EDIT_RANDOM:
     523          14 :       if (s->min_packet_bytes == s->max_packet_bytes)
     524          14 :         s->packet_size_edit_type = PG_EDIT_FIXED;
     525          14 :       break;
     526             : 
     527       15657 :     default:
     528             :       /* Get packet size from fixed edits. */
     529       15657 :       s->packet_size_edit_type = PG_EDIT_FIXED;
     530       15657 :       if (!s->replay_packet_templates)
     531           0 :         s->min_packet_bytes = s->max_packet_bytes =
     532           0 :           vec_len (s->fixed_packet_data);
     533       15657 :       break;
     534             :     }
     535             : 
     536       15671 :   s->last_increment_packet_size = s->min_packet_bytes;
     537             : 
     538             :   {
     539             :     int n;
     540             : 
     541       15671 :     s->buffer_bytes = vlib_buffer_get_default_data_size (vm);
     542       15671 :     n = s->max_packet_bytes / s->buffer_bytes;
     543       15671 :     n += (s->max_packet_bytes % s->buffer_bytes) != 0;
     544             : 
     545       15671 :     vec_resize (s->buffer_indices, n);
     546             :   }
     547             : 
     548             :   /* Find an interface to use. */
     549       31342 :   s->pg_if_index = pg_interface_add_or_get (
     550       15671 :     pg, s->if_id, 0 /* gso_enabled */, 0 /* gso_size */,
     551             :     0 /* coalesce_enabled */, PG_MODE_ETHERNET);
     552             : 
     553       15671 :   if (s->sw_if_index[VLIB_RX] == ~0)
     554             :     {
     555       15657 :       pg_interface_t *pi = pool_elt_at_index (pg->interfaces, s->pg_if_index);
     556             :       /*
     557             :        * Default the RX interface if unset. It's a bad mistake to
     558             :        * set [VLIB_TX] prior to ip lookup, since the ip lookup code
     559             :        * interprets [VLIB_TX] as a fib index...
     560             :        */
     561       15657 :       s->sw_if_index[VLIB_RX] = pi->sw_if_index;
     562             :     }
     563             : 
     564             :   /* Connect the graph. */
     565       31342 :   s->next_index = vlib_node_add_next (vm, device_input_node.index,
     566       15671 :                                       s->node_index);
     567       15671 : }
     568             : 
     569             : void
     570       15658 : pg_stream_del (pg_main_t * pg, uword index)
     571             : {
     572             :   pg_stream_t *s;
     573             :   pg_buffer_index_t *bi;
     574             : 
     575       15658 :   s = pool_elt_at_index (pg->streams, index);
     576             : 
     577       15658 :   pg_stream_enable_disable (pg, s, /* want_enabled */ 0);
     578       31316 :   hash_unset_mem (pg->stream_index_by_name, s->name);
     579             : 
     580       35201 :   vec_foreach (bi, s->buffer_indices)
     581             :   {
     582       19543 :     clib_fifo_free (bi->buffer_fifo);
     583             :   }
     584             : 
     585       15658 :   pg_stream_free (s);
     586       15658 :   pool_put (pg->streams, s);
     587       15658 : }
     588             : 
     589             : void
     590           0 : pg_stream_change (pg_main_t * pg, pg_stream_t * s)
     591             : {
     592             :   /* Determine packet size. */
     593           0 :   switch (s->packet_size_edit_type)
     594             :     {
     595           0 :     case PG_EDIT_INCREMENT:
     596             :     case PG_EDIT_RANDOM:
     597           0 :       if (s->min_packet_bytes == s->max_packet_bytes)
     598           0 :         s->packet_size_edit_type = PG_EDIT_FIXED;
     599             :     case PG_EDIT_FIXED:
     600           0 :       break;
     601             : 
     602           0 :     default:
     603             :       /* Get packet size from fixed edits. */
     604           0 :       s->packet_size_edit_type = PG_EDIT_FIXED;
     605           0 :       if (!s->replay_packet_templates)
     606           0 :         s->min_packet_bytes = s->max_packet_bytes =
     607           0 :           vec_len (s->fixed_packet_data);
     608           0 :       break;
     609             :     }
     610             : 
     611           0 :   s->last_increment_packet_size = s->min_packet_bytes;
     612           0 : }
     613             : 
     614             : 
     615             : /*
     616             :  * fd.io coding-style-patch-verification: ON
     617             :  *
     618             :  * Local Variables:
     619             :  * eval: (c-set-style "gnu")
     620             :  * End:
     621             :  */

Generated by: LCOV version 1.14