LCOV - code coverage report
Current view: top level - app/test-flow-perf - items_gen.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 109 0.0 %
Date: 2024-04-01 19:00:53 Functions: 0 16 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright 2020 Mellanox Technologies, Ltd
       3                 :            :  *
       4                 :            :  * This file contain the implementations of the items
       5                 :            :  * related methods. Each Item have a method to prepare
       6                 :            :  * the item and add it into items array in given index.
       7                 :            :  */
       8                 :            : 
       9                 :            : #include <stdint.h>
      10                 :            : #include <rte_flow.h>
      11                 :            : 
      12                 :            : #include "items_gen.h"
      13                 :            : #include "config.h"
      14                 :            : 
      15                 :            : /* Storage for additional parameters for items */
      16                 :            : struct additional_para {
      17                 :            :         rte_be32_t src_ip;
      18                 :            :         uint8_t core_idx;
      19                 :            : };
      20                 :            : 
      21                 :            : static void
      22                 :          0 : add_ether(struct rte_flow_item *items,
      23                 :            :         uint8_t items_counter,
      24                 :            :         __rte_unused struct additional_para para)
      25                 :            : {
      26                 :            :         static struct rte_flow_item_eth eth_spec;
      27                 :            :         static struct rte_flow_item_eth eth_mask;
      28                 :            : 
      29                 :          0 :         items[items_counter].type = RTE_FLOW_ITEM_TYPE_ETH;
      30                 :          0 :         items[items_counter].spec = &eth_spec;
      31                 :          0 :         items[items_counter].mask = &eth_mask;
      32                 :          0 : }
      33                 :            : 
      34                 :            : static void
      35                 :          0 : add_vlan(struct rte_flow_item *items,
      36                 :            :         uint8_t items_counter,
      37                 :            :         __rte_unused struct additional_para para)
      38                 :            : {
      39                 :            :         static struct rte_flow_item_vlan vlan_spec = {
      40                 :            :                 .hdr.vlan_tci = RTE_BE16(VLAN_VALUE),
      41                 :            :         };
      42                 :            :         static struct rte_flow_item_vlan vlan_mask = {
      43                 :            :                 .hdr.vlan_tci = RTE_BE16(0xffff),
      44                 :            :         };
      45                 :            : 
      46                 :          0 :         items[items_counter].type = RTE_FLOW_ITEM_TYPE_VLAN;
      47                 :          0 :         items[items_counter].spec = &vlan_spec;
      48                 :          0 :         items[items_counter].mask = &vlan_mask;
      49                 :          0 : }
      50                 :            : 
      51                 :            : static void
      52                 :          0 : add_ipv4(struct rte_flow_item *items,
      53                 :            :         uint8_t items_counter, struct additional_para para)
      54                 :            : {
      55                 :            :         static struct rte_flow_item_ipv4 ipv4_specs[RTE_MAX_LCORE] __rte_cache_aligned;
      56                 :            :         static struct rte_flow_item_ipv4 ipv4_masks[RTE_MAX_LCORE] __rte_cache_aligned;
      57                 :          0 :         uint8_t ti = para.core_idx;
      58                 :            : 
      59                 :          0 :         ipv4_specs[ti].hdr.src_addr = RTE_BE32(para.src_ip);
      60                 :          0 :         ipv4_masks[ti].hdr.src_addr = RTE_BE32(0xffffffff);
      61                 :            : 
      62                 :          0 :         items[items_counter].type = RTE_FLOW_ITEM_TYPE_IPV4;
      63                 :          0 :         items[items_counter].spec = &ipv4_specs[ti];
      64                 :          0 :         items[items_counter].mask = &ipv4_masks[ti];
      65                 :          0 : }
      66                 :            : 
      67                 :            : 
      68                 :            : static void
      69                 :          0 : add_ipv6(struct rte_flow_item *items,
      70                 :            :         uint8_t items_counter, struct additional_para para)
      71                 :            : {
      72                 :            :         static struct rte_flow_item_ipv6 ipv6_specs[RTE_MAX_LCORE] __rte_cache_aligned;
      73                 :            :         static struct rte_flow_item_ipv6 ipv6_masks[RTE_MAX_LCORE] __rte_cache_aligned;
      74                 :          0 :         uint8_t ti = para.core_idx;
      75                 :            :         uint8_t i;
      76                 :            : 
      77                 :            :         /** Set ipv6 src **/
      78                 :          0 :         for (i = 0; i < 16; i++) {
      79                 :            :                 /* Currently src_ip is limited to 32 bit */
      80                 :          0 :                 if (i < 4)
      81                 :          0 :                         ipv6_specs[ti].hdr.src_addr[15 - i] = para.src_ip >> (i * 8);
      82                 :          0 :                 ipv6_masks[ti].hdr.src_addr[15 - i] = 0xff;
      83                 :            :         }
      84                 :            : 
      85                 :          0 :         items[items_counter].type = RTE_FLOW_ITEM_TYPE_IPV6;
      86                 :          0 :         items[items_counter].spec = &ipv6_specs[ti];
      87                 :          0 :         items[items_counter].mask = &ipv6_masks[ti];
      88                 :          0 : }
      89                 :            : 
      90                 :            : static void
      91                 :          0 : add_tcp(struct rte_flow_item *items,
      92                 :            :         uint8_t items_counter,
      93                 :            :         __rte_unused struct additional_para para)
      94                 :            : {
      95                 :            :         static struct rte_flow_item_tcp tcp_spec;
      96                 :            :         static struct rte_flow_item_tcp tcp_mask;
      97                 :            : 
      98                 :          0 :         items[items_counter].type = RTE_FLOW_ITEM_TYPE_TCP;
      99                 :          0 :         items[items_counter].spec = &tcp_spec;
     100                 :          0 :         items[items_counter].mask = &tcp_mask;
     101                 :          0 : }
     102                 :            : 
     103                 :            : static void
     104                 :          0 : add_udp(struct rte_flow_item *items,
     105                 :            :         uint8_t items_counter,
     106                 :            :         __rte_unused struct additional_para para)
     107                 :            : {
     108                 :            :         static struct rte_flow_item_udp udp_spec;
     109                 :            :         static struct rte_flow_item_udp udp_mask;
     110                 :            : 
     111                 :          0 :         items[items_counter].type = RTE_FLOW_ITEM_TYPE_UDP;
     112                 :          0 :         items[items_counter].spec = &udp_spec;
     113                 :          0 :         items[items_counter].mask = &udp_mask;
     114                 :          0 : }
     115                 :            : 
     116                 :            : static void
     117                 :          0 : add_vxlan(struct rte_flow_item *items,
     118                 :            :         uint8_t items_counter,
     119                 :            :         struct additional_para para)
     120                 :            : {
     121                 :            :         static struct rte_flow_item_vxlan vxlan_specs[RTE_MAX_LCORE] __rte_cache_aligned;
     122                 :            :         static struct rte_flow_item_vxlan vxlan_masks[RTE_MAX_LCORE] __rte_cache_aligned;
     123                 :          0 :         uint8_t ti = para.core_idx;
     124                 :            :         uint32_t vni_value;
     125                 :            :         uint8_t i;
     126                 :            : 
     127                 :            :         vni_value = VNI_VALUE;
     128                 :            : 
     129                 :            :         /* Set standard vxlan vni */
     130                 :          0 :         for (i = 0; i < 3; i++) {
     131                 :          0 :                 vxlan_specs[ti].hdr.vni[2 - i] = vni_value >> (i * 8);
     132                 :          0 :                 vxlan_masks[ti].hdr.vni[2 - i] = 0xff;
     133                 :            :         }
     134                 :            : 
     135                 :            :         /* Standard vxlan flags */
     136                 :          0 :         vxlan_specs[ti].hdr.flags = 0x8;
     137                 :            : 
     138                 :          0 :         items[items_counter].type = RTE_FLOW_ITEM_TYPE_VXLAN;
     139                 :          0 :         items[items_counter].spec = &vxlan_specs[ti];
     140                 :          0 :         items[items_counter].mask = &vxlan_masks[ti];
     141                 :          0 : }
     142                 :            : 
     143                 :            : static void
     144                 :          0 : add_vxlan_gpe(struct rte_flow_item *items,
     145                 :            :         uint8_t items_counter,
     146                 :            :         __rte_unused struct additional_para para)
     147                 :            : {
     148                 :            :         static struct rte_flow_item_vxlan_gpe vxlan_gpe_specs[RTE_MAX_LCORE] __rte_cache_aligned;
     149                 :            :         static struct rte_flow_item_vxlan_gpe vxlan_gpe_masks[RTE_MAX_LCORE] __rte_cache_aligned;
     150                 :          0 :         uint8_t ti = para.core_idx;
     151                 :            :         uint32_t vni_value;
     152                 :            :         uint8_t i;
     153                 :            : 
     154                 :            :         vni_value = VNI_VALUE;
     155                 :            : 
     156                 :            :         /* Set vxlan-gpe vni */
     157                 :          0 :         for (i = 0; i < 3; i++) {
     158                 :          0 :                 vxlan_gpe_specs[ti].hdr.vni[2 - i] = vni_value >> (i * 8);
     159                 :          0 :                 vxlan_gpe_masks[ti].hdr.vni[2 - i] = 0xff;
     160                 :            :         }
     161                 :            : 
     162                 :            :         /* vxlan-gpe flags */
     163                 :          0 :         vxlan_gpe_specs[ti].hdr.flags = 0x0c;
     164                 :            : 
     165                 :          0 :         items[items_counter].type = RTE_FLOW_ITEM_TYPE_VXLAN_GPE;
     166                 :          0 :         items[items_counter].spec = &vxlan_gpe_specs[ti];
     167                 :          0 :         items[items_counter].mask = &vxlan_gpe_masks[ti];
     168                 :          0 : }
     169                 :            : 
     170                 :            : static void
     171                 :          0 : add_gre(struct rte_flow_item *items,
     172                 :            :         uint8_t items_counter,
     173                 :            :         __rte_unused struct additional_para para)
     174                 :            : {
     175                 :            :         static struct rte_flow_item_gre gre_spec = {
     176                 :            :                 .protocol = RTE_BE16(RTE_ETHER_TYPE_TEB),
     177                 :            :         };
     178                 :            :         static struct rte_flow_item_gre gre_mask = {
     179                 :            :                 .protocol = RTE_BE16(0xffff),
     180                 :            :         };
     181                 :            : 
     182                 :          0 :         items[items_counter].type = RTE_FLOW_ITEM_TYPE_GRE;
     183                 :          0 :         items[items_counter].spec = &gre_spec;
     184                 :          0 :         items[items_counter].mask = &gre_mask;
     185                 :          0 : }
     186                 :            : 
     187                 :            : static void
     188                 :          0 : add_geneve(struct rte_flow_item *items,
     189                 :            :         uint8_t items_counter,
     190                 :            :         __rte_unused struct additional_para para)
     191                 :            : {
     192                 :            :         static struct rte_flow_item_geneve geneve_specs[RTE_MAX_LCORE] __rte_cache_aligned;
     193                 :            :         static struct rte_flow_item_geneve geneve_masks[RTE_MAX_LCORE] __rte_cache_aligned;
     194                 :          0 :         uint8_t ti = para.core_idx;
     195                 :            :         uint32_t vni_value;
     196                 :            :         uint8_t i;
     197                 :            : 
     198                 :            :         vni_value = VNI_VALUE;
     199                 :            : 
     200                 :          0 :         for (i = 0; i < 3; i++) {
     201                 :          0 :                 geneve_specs[ti].vni[2 - i] = vni_value >> (i * 8);
     202                 :          0 :                 geneve_masks[ti].vni[2 - i] = 0xff;
     203                 :            :         }
     204                 :            : 
     205                 :          0 :         items[items_counter].type = RTE_FLOW_ITEM_TYPE_GENEVE;
     206                 :          0 :         items[items_counter].spec = &geneve_specs[ti];
     207                 :          0 :         items[items_counter].mask = &geneve_masks[ti];
     208                 :          0 : }
     209                 :            : 
     210                 :            : static void
     211                 :          0 : add_gtp(struct rte_flow_item *items,
     212                 :            :         uint8_t items_counter,
     213                 :            :         __rte_unused struct additional_para para)
     214                 :            : {
     215                 :            :         static struct rte_flow_item_gtp gtp_spec = {
     216                 :            :                 .hdr.teid = RTE_BE32(TEID_VALUE),
     217                 :            :         };
     218                 :            :         static struct rte_flow_item_gtp gtp_mask = {
     219                 :            :                 .hdr.teid = RTE_BE32(0xffffffff),
     220                 :            :         };
     221                 :            : 
     222                 :          0 :         items[items_counter].type = RTE_FLOW_ITEM_TYPE_GTP;
     223                 :          0 :         items[items_counter].spec = &gtp_spec;
     224                 :          0 :         items[items_counter].mask = &gtp_mask;
     225                 :          0 : }
     226                 :            : 
     227                 :            : static void
     228                 :          0 : add_meta_data(struct rte_flow_item *items,
     229                 :            :         uint8_t items_counter,
     230                 :            :         __rte_unused struct additional_para para)
     231                 :            : {
     232                 :            :         static struct rte_flow_item_meta meta_spec = {
     233                 :            :                 .data = RTE_BE32(META_DATA),
     234                 :            :         };
     235                 :            :         static struct rte_flow_item_meta meta_mask = {
     236                 :            :                 .data = RTE_BE32(0xffffffff),
     237                 :            :         };
     238                 :            : 
     239                 :          0 :         items[items_counter].type = RTE_FLOW_ITEM_TYPE_META;
     240                 :          0 :         items[items_counter].spec = &meta_spec;
     241                 :          0 :         items[items_counter].mask = &meta_mask;
     242                 :          0 : }
     243                 :            : 
     244                 :            : 
     245                 :            : static void
     246                 :          0 : add_meta_tag(struct rte_flow_item *items,
     247                 :            :         uint8_t items_counter,
     248                 :            :         __rte_unused struct additional_para para)
     249                 :            : {
     250                 :            :         static struct rte_flow_item_tag tag_spec = {
     251                 :            :                 .data = RTE_BE32(META_DATA),
     252                 :            :                 .index = TAG_INDEX,
     253                 :            :         };
     254                 :            :         static struct rte_flow_item_tag tag_mask = {
     255                 :            :                 .data = RTE_BE32(0xffffffff),
     256                 :            :                 .index = 0xff,
     257                 :            :         };
     258                 :            : 
     259                 :          0 :         items[items_counter].type = RTE_FLOW_ITEM_TYPE_TAG;
     260                 :          0 :         items[items_counter].spec = &tag_spec;
     261                 :          0 :         items[items_counter].mask = &tag_mask;
     262                 :          0 : }
     263                 :            : 
     264                 :            : static void
     265                 :          0 : add_icmpv4(struct rte_flow_item *items,
     266                 :            :         uint8_t items_counter,
     267                 :            :         __rte_unused struct additional_para para)
     268                 :            : {
     269                 :            :         static struct rte_flow_item_icmp icmpv4_spec;
     270                 :            :         static struct rte_flow_item_icmp icmpv4_mask;
     271                 :            : 
     272                 :          0 :         items[items_counter].type = RTE_FLOW_ITEM_TYPE_ICMP;
     273                 :          0 :         items[items_counter].spec = &icmpv4_spec;
     274                 :          0 :         items[items_counter].mask = &icmpv4_mask;
     275                 :          0 : }
     276                 :            : 
     277                 :            : static void
     278                 :          0 : add_icmpv6(struct rte_flow_item *items,
     279                 :            :         uint8_t items_counter,
     280                 :            :         __rte_unused struct additional_para para)
     281                 :            : {
     282                 :            :         static struct rte_flow_item_icmp6 icmpv6_spec;
     283                 :            :         static struct rte_flow_item_icmp6 icmpv6_mask;
     284                 :            : 
     285                 :          0 :         items[items_counter].type = RTE_FLOW_ITEM_TYPE_ICMP6;
     286                 :          0 :         items[items_counter].spec = &icmpv6_spec;
     287                 :          0 :         items[items_counter].mask = &icmpv6_mask;
     288                 :          0 : }
     289                 :            : 
     290                 :            : void
     291                 :          0 : fill_items(struct rte_flow_item *items,
     292                 :            :         uint64_t *flow_items, uint32_t outer_ip_src,
     293                 :            :         uint8_t core_idx)
     294                 :            : {
     295                 :            :         uint8_t items_counter = 0;
     296                 :            :         uint8_t i, j;
     297                 :          0 :         struct additional_para additional_para_data = {
     298                 :            :                 .src_ip = outer_ip_src,
     299                 :            :                 .core_idx = core_idx,
     300                 :            :         };
     301                 :            : 
     302                 :            :         /* Support outer items up to tunnel layer only. */
     303                 :            :         static const struct items_dict {
     304                 :            :                 uint64_t mask;
     305                 :            :                 void (*funct)(
     306                 :            :                         struct rte_flow_item *items,
     307                 :            :                         uint8_t items_counter,
     308                 :            :                         struct additional_para para
     309                 :            :                         );
     310                 :            :         } items_list[] = {
     311                 :            :                 {
     312                 :            :                         .mask = RTE_FLOW_ITEM_TYPE_META,
     313                 :            :                         .funct = add_meta_data,
     314                 :            :                 },
     315                 :            :                 {
     316                 :            :                         .mask = RTE_FLOW_ITEM_TYPE_TAG,
     317                 :            :                         .funct = add_meta_tag,
     318                 :            :                 },
     319                 :            :                 {
     320                 :            :                         .mask = RTE_FLOW_ITEM_TYPE_ETH,
     321                 :            :                         .funct = add_ether,
     322                 :            :                 },
     323                 :            :                 {
     324                 :            :                         .mask = RTE_FLOW_ITEM_TYPE_VLAN,
     325                 :            :                         .funct = add_vlan,
     326                 :            :                 },
     327                 :            :                 {
     328                 :            :                         .mask = RTE_FLOW_ITEM_TYPE_IPV4,
     329                 :            :                         .funct = add_ipv4,
     330                 :            :                 },
     331                 :            :                 {
     332                 :            :                         .mask = RTE_FLOW_ITEM_TYPE_IPV6,
     333                 :            :                         .funct = add_ipv6,
     334                 :            :                 },
     335                 :            :                 {
     336                 :            :                         .mask = RTE_FLOW_ITEM_TYPE_TCP,
     337                 :            :                         .funct = add_tcp,
     338                 :            :                 },
     339                 :            :                 {
     340                 :            :                         .mask = RTE_FLOW_ITEM_TYPE_UDP,
     341                 :            :                         .funct = add_udp,
     342                 :            :                 },
     343                 :            :                 {
     344                 :            :                         .mask = RTE_FLOW_ITEM_TYPE_VXLAN,
     345                 :            :                         .funct = add_vxlan,
     346                 :            :                 },
     347                 :            :                 {
     348                 :            :                         .mask = RTE_FLOW_ITEM_TYPE_VXLAN_GPE,
     349                 :            :                         .funct = add_vxlan_gpe,
     350                 :            :                 },
     351                 :            :                 {
     352                 :            :                         .mask = RTE_FLOW_ITEM_TYPE_GRE,
     353                 :            :                         .funct = add_gre,
     354                 :            :                 },
     355                 :            :                 {
     356                 :            :                         .mask = RTE_FLOW_ITEM_TYPE_GENEVE,
     357                 :            :                         .funct = add_geneve,
     358                 :            :                 },
     359                 :            :                 {
     360                 :            :                         .mask = RTE_FLOW_ITEM_TYPE_GTP,
     361                 :            :                         .funct = add_gtp,
     362                 :            :                 },
     363                 :            :                 {
     364                 :            :                         .mask = RTE_FLOW_ITEM_TYPE_ICMP,
     365                 :            :                         .funct = add_icmpv4,
     366                 :            :                 },
     367                 :            :                 {
     368                 :            :                         .mask = RTE_FLOW_ITEM_TYPE_ICMP6,
     369                 :            :                         .funct = add_icmpv6,
     370                 :            :                 },
     371                 :            :         };
     372                 :            : 
     373                 :          0 :         for (j = 0; j < MAX_ITEMS_NUM; j++) {
     374                 :          0 :                 if (flow_items[j] == 0)
     375                 :            :                         break;
     376                 :          0 :                 for (i = 0; i < RTE_DIM(items_list); i++) {
     377                 :          0 :                         if ((flow_items[j] &
     378                 :          0 :                                 FLOW_ITEM_MASK(items_list[i].mask)) == 0)
     379                 :            :                                 continue;
     380                 :          0 :                         items_list[i].funct(
     381                 :          0 :                                 items, items_counter++,
     382                 :            :                                 additional_para_data
     383                 :            :                         );
     384                 :          0 :                         break;
     385                 :            :                 }
     386                 :            :         }
     387                 :            : 
     388                 :          0 :         items[items_counter].type = RTE_FLOW_ITEM_TYPE_END;
     389                 :          0 : }

Generated by: LCOV version 1.14