LCOV - code coverage report
Current view: top level - vnet/dpo - classify_dpo.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 3 37 8.1 %
Date: 2023-10-26 01:39:38 Functions: 1 8 12.5 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2016 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             : #include <vnet/ip/ip.h>
      17             : #include <vnet/dpo/classify_dpo.h>
      18             : #include <vnet/mpls/mpls.h>
      19             : 
      20             : /*
      21             :  * pool of all MPLS Label DPOs
      22             :  */
      23             : classify_dpo_t *classify_dpo_pool;
      24             : 
      25             : static classify_dpo_t *
      26           0 : classify_dpo_alloc (void)
      27             : {
      28             :     classify_dpo_t *cd;
      29             :     vlib_main_t *vm;
      30             :     u8 did_barrier_sync;
      31             : 
      32           0 :     dpo_pool_barrier_sync (vm, classify_dpo_pool, did_barrier_sync);
      33           0 :     pool_get_aligned(classify_dpo_pool, cd, CLIB_CACHE_LINE_BYTES);
      34           0 :     dpo_pool_barrier_release (vm, did_barrier_sync);
      35             : 
      36           0 :     clib_memset(cd, 0, sizeof(*cd));
      37             : 
      38           0 :     return (cd);
      39             : }
      40             : 
      41             : static index_t
      42           0 : classify_dpo_get_index (classify_dpo_t *cd)
      43             : {
      44           0 :     return (cd - classify_dpo_pool);
      45             : }
      46             : 
      47             : index_t
      48           0 : classify_dpo_create (dpo_proto_t proto,
      49             :                      u32 classify_table_index)
      50             : {
      51             :     classify_dpo_t *cd;
      52             : 
      53           0 :     cd = classify_dpo_alloc();
      54           0 :     cd->cd_proto = proto;
      55           0 :     cd->cd_table_index = classify_table_index;
      56             : 
      57           0 :     return (classify_dpo_get_index(cd));
      58             : }
      59             : 
      60             : u8*
      61           0 : format_classify_dpo (u8 *s, va_list *args)
      62             : {
      63           0 :     index_t index = va_arg (*args, index_t);
      64           0 :     CLIB_UNUSED(u32 indent) = va_arg (*args, u32);
      65             :     classify_dpo_t *cd;
      66             : 
      67           0 :     cd = classify_dpo_get(index);
      68             : 
      69           0 :     return (format(s, "%U-classify:[%d]:table:%d",
      70           0 :                    format_dpo_proto, cd->cd_proto,
      71             :                    index, cd->cd_table_index));
      72             : }
      73             : 
      74             : static void
      75           0 : classify_dpo_lock (dpo_id_t *dpo)
      76             : {
      77             :     classify_dpo_t *cd;
      78             : 
      79           0 :     cd = classify_dpo_get(dpo->dpoi_index);
      80             : 
      81           0 :     cd->cd_locks++;
      82           0 : }
      83             : 
      84             : static void
      85           0 : classify_dpo_unlock (dpo_id_t *dpo)
      86             : {
      87             :     classify_dpo_t *cd;
      88             : 
      89           0 :     cd = classify_dpo_get(dpo->dpoi_index);
      90             : 
      91           0 :     cd->cd_locks--;
      92             : 
      93           0 :     if (0 == cd->cd_locks)
      94             :     {
      95           0 :         pool_put(classify_dpo_pool, cd);
      96             :     }
      97           0 : }
      98             : 
      99             : static void
     100           0 : classify_dpo_mem_show (void)
     101             : {
     102           0 :     fib_show_memory_usage("Classify",
     103           0 :                           pool_elts(classify_dpo_pool),
     104           0 :                           pool_len(classify_dpo_pool),
     105             :                           sizeof(classify_dpo_t));
     106           0 : }
     107             : 
     108             : const static dpo_vft_t cd_vft = {
     109             :     .dv_lock = classify_dpo_lock,
     110             :     .dv_unlock = classify_dpo_unlock,
     111             :     .dv_format = format_classify_dpo,
     112             :     .dv_mem_show = classify_dpo_mem_show,
     113             : };
     114             : 
     115             : const static char* const classify_ip4_nodes[] =
     116             : {
     117             :     "ip4-classify",
     118             :     NULL,
     119             : };
     120             : const static char* const classify_ip6_nodes[] =
     121             : {
     122             :     "ip6-classify",
     123             :     NULL,
     124             : };
     125             : const static char* const * const classify_nodes[DPO_PROTO_NUM] =
     126             : {
     127             :     [DPO_PROTO_IP4]  = classify_ip4_nodes,
     128             :     [DPO_PROTO_IP6]  = classify_ip6_nodes,
     129             :     [DPO_PROTO_MPLS] = NULL,
     130             : };
     131             : 
     132             : void
     133         575 : classify_dpo_module_init (void)
     134             : {
     135         575 :     dpo_register(DPO_CLASSIFY, &cd_vft, classify_nodes);
     136         575 : }

Generated by: LCOV version 1.14