aboutsummaryrefslogtreecommitdiffstats
path: root/resources/templates/container
AgeCommit message (Expand)AuthorFilesLines
2020-04-22FIX: NF_density MAC addressesPeter Mikus2-4/+4
2020-04-20FIX: NF_density testsPeter Mikus2-4/+4
2020-01-13FIX: NF_density testsPeter Mikus3-6/+6
2019-12-11Introduce VPP-IPsec container tests.Ludovit Mikula2-0/+25
2019-06-04VAT-to-PAPI: ContainerUtilsTibor Frank5-0/+60
Keyword */ .highlight .l { color: #ae81ff } /* Literal */ .highlight .n { color: #f8f8f2 } /* Name */ .highlight .o { color: #f92672 } /* Operator */ .highlight .p { color: #f8f8f2 } /* Punctuation */ .highlight .ch { color: #75715e } /* Comment.Hashbang */ .highlight .cm { color: #75715e } /* Comment.Multiline */ .highlight .cp { color: #75715e } /* Comment.Preproc */ .highlight .cpf { color: #75715e } /* Comment.PreprocFile */ .highlight .c1 { color: #75715e } /* Comment.Single */ .highlight .cs { color: #75715e } /* Comment.Special */ .highlight .gd { color: #f92672 } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .gi { color: #a6e22e } /* Generic.Inserted */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #75715e } /* Generic.Subheading */ .highlight .kc { color: #66d9ef } /* Keyword.Constant */ .highlight .kd { color: #66d9ef } /* Keyword.Declaration */ .highlight .kn { color: #f92672 } /* Keyword.Namespace */ .highlight .kp { color: #66d9ef } /* Keyword.Pseudo */ .highlight .kr { color: #66d9ef } /* Keyword.Reserved */ .highlight .kt { color: #66d9ef } /* Keyword.Type */ .highlight .ld { color: #e6db74 } /* Literal.Date */ .highlight .m { color: #ae81ff } /* Literal.Number */ .highlight .s { color: #e6db74 } /* Literal.String */ .highlight .na { color: #a6e22e } /* Name.Attribute */ .highlight .nb { color: #f8f8f2 } /* Name.Builtin */ .highlight .nc { color: #a6e22e } /* Name.Class */ .highlight .no { color: #66d9ef } /* Name.Constant */ .highlight .nd { color: #a6e22e } /* Name.Decorator */ .highlight .ni { color: #f8f8f2 } /* Name.Entity */ .highlight .ne { color: #a6e22e } /* Name.Exception */ .highlight .nf { color: #a6e22e } /* Name.Function */ .highlight .nl { color: #f8f8f2 } /* Name.Label */ .highlight .nn { color: #f8f8f2 } /* Name.Namespace */ .highlight .nx { color: #a6e22e } /* Name.Other */ .highlight .py { color: #f8f8f2 } /* Name.Property */ .highlight .nt { color: #f92672 } /* Name.Tag */ .highlight .nv { color: #f8f8f2 } /* Name.Variable */ .highlight .ow { color: #f92672 } /* Operator.Word */ .highlight .w { color: #f8f8f2 } /* Text.Whitespace */ .highlight .mb { color: #ae81ff } /* Literal.Number.Bin */ .highlight .mf { color: #ae81ff } /* Literal.Number.Float */ .highlight .mh { color: #ae81ff } /* Literal.Number.Hex */ .highlight .mi { color: #ae81ff } /* Literal.Number.Integer */ .highlight .mo { color: #ae81ff } /* Literal.Number.Oct */ .highlight .sa { color: #e6db74 } /* Literal.String.Affix */ .highlight .sb { color: #e6db74 } /* Literal.String.Backtick */ .highlight .sc { color: #e6db74 } /* Literal.String.Char */ .highlight .dl { color: #e6db74 } /* Literal.String.Delimiter */ .highlight .sd { color: #e6db74 } /* Literal.String.Doc */ .highlight .s2 { color: #e6db74 } /* Literal.String.Double */ .highlight .se { color: #ae81ff } /* Literal.String.Escape */ .highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */ .highlight .si { color: #e6db74 } /* Literal.String.Interpol */ .highlight .sx { color: #e6db74 } /* Literal.String.Other */ .highlight .sr { color: #e6db74 } /* Literal.String.Regex */ .highlight .s1 { color: #e6db74 } /* Literal.String.Single */ .highlight .ss { color: #e6db74 } /* Literal.String.Symbol */ .highlight .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #a6e22e } /* Name.Function.Magic */ .highlight .vc { color: #f8f8f2 } /* Name.Variable.Class */ .highlight .vg { color: #f8f8f2 } /* Name.Variable.Global */ .highlight .vi { color: #f8f8f2 } /* Name.Variable.Instance */ .highlight .vm { color: #f8f8f2 } /* Name.Variable.Magic */ .highlight .il { color: #ae81ff } /* Literal.Number.Integer.Long */ } @media (prefers-color-scheme: light) { .highlight .hll { background-color: #ffffcc } .highlight .c { color: #888888 } /* Comment */ .highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */ .highlight .k { color: #008800; font-weight: bold } /* Keyword */ .highlight .ch { color: #888888 } /* Comment.Hashbang */ .highlight .cm { color: #888888 } /* Comment.Multiline */ .highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */ .highlight .cpf { color: #888888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
/*
 * Copyright (c) 2020 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/** @file
 * @brief Callback multiplex scheme
 */

#ifndef included_callback_data_h
#define included_callback_data_h
#include <vppinfra/clib.h>

/** @brief Declare and define a callback set type
 * @param set_t_ The set type to define
 * @param cb_t_ The callback type to use
 */
#define clib_callback_data_typedef(set_t_, cb_t_)   \
typedef struct set_t_                               \
{                                                   \
  cb_t_* curr;                                      \
  cb_t_* volatile next;                             \
  cb_t_* spare;                                     \
  clib_spinlock_t* lock;                            \
} set_t_

/** @brief Initialize a callback set
 * @param set_ The callback set to initialize
 * @param lock_ The lock to use, if any
 */
#define clib_callback_data_init(set_,lock_)  \
do {                                         \
  (set_)->lock = (lock_);                    \
  (set_)->curr = 0;                          \
  (set_)->next = 0;                          \
  (set_)->spare = 0;                         \
} while (0)

/** @brief Add a callback to the specified callback set
 * @param set_ The callback set
 * @param value_ The value_ to assign the callback
 *
 * Add a callback from the indicated callback set.  If the set is
 * currently being iterated, then the change will be applied after the
 * current full iteration, and prior to the next full iteration.
 */
#define clib_callback_data_add(set_,value_)          \
do {                                                 \
  clib_spinlock_lock_if_init ((set_)->lock);         \
  typeof ((set_)->next) next_ = (set_)->next;        \
  if (PREDICT_TRUE (next_ == 0))                     \
    {                                                \
      next_ = (set_)->spare;                         \
      (set_)->spare = 0;                             \
      vec_append (next_, (set_)->curr);              \
    }                                                \
  u32 sz_ = vec_len (next_);                         \
  vec_validate (next_, sz_);                         \
  next_[sz_] = (value_);                             \
  (set_)->next = next_;                              \
  clib_spinlock_unlock_if_init ((set_)->lock);       \
} while (0)

/** @brief Remove a callback from the specified callback set
 * @param set_ The callback set
 * @param fp_ The current callback function
 * @return 1 if the function was removed, 0 if not
 *
 * Remove a callback from the indicated callback set.  Idempotent.  If
 * the set is currently being iterated, then the change will be applied
 * after the current full iteration, and prior to the next full
 * iteration.
 */
#define clib_callback_data_remove(set_,fp_)          \
({                                                   \
  int found_ = 0;                                    \
  clib_spinlock_lock_if_init ((set_)->lock);         \
  typeof ((set_)->next) next_ = (set_)->next;        \
  if (PREDICT_TRUE (next_ == 0))                     \
    {                                                \
      next_ = (set_)->spare;                         \
      (set_)->spare = 0;                             \
      vec_append (next_, (set_)->curr);              \
    }                                                \
  u32 sz_ = vec_len (next_);                         \
  u32 i_;                                            \
  for (i_ = 0; i_ < sz_; i_++)                       \
    if (next_[i_].fp == (fp_))                       \
      {                                              \
        vec_delete (next_, 1, i_);                   \
        found_ = 1;                                  \
        break;                                       \
      }                                              \
  (set_)->next = next_;                              \
  clib_spinlock_unlock_if_init ((set_)->lock);       \
  found_;                                            \
})

/** @brief Swap a callback in the specified callback set
 * @param set_ The callback set
 * @param fp_ The current callback function
 * @param value_ The value_ to assign the callback
 * @return 1 if the function was swapped, 0 if not
 *
 * Swap a callback in the indicated callback set.  If the callback is
 * not found, then nothing is done.  If the set is currently being
 * iterated, then the change will be applied after the current full
 * iteration, and prior to the next full iteration.
 */
#define clib_callback_data_swap(set_,fp_,value_)     \
({                                                   \
  int found_ = 0;                                    \
  clib_spinlock_lock_if_init ((set_)->lock);         \
  typeof ((set_)->next) next_ = (set_)->next;        \
  if (PREDICT_TRUE (next_ == 0))                     \
    {                                                \
      next_ = (set_)->spare;                         \
      (set_)->spare = 0;                             \
      vec_append (next_, (set_)->curr);              \
    }                                                \
  u32 sz_ = vec_len (next_);                         \
  u32 i_;                                            \
  for (i_ = 0; i_ < sz_; i_++)                       \
    if (next_[i_].fp == (fp_))                       \
      {                                              \
        next_[i_] = (value_);                        \
        found_ = 1;                                  \
        break;                                       \
      }                                              \
  (set_)->next = next_;                              \
  clib_spinlock_unlock_if_init ((set_)->lock);       \
  found_;                                            \
})

/** @brief Ensure a callback is in the specified callback set
 * @param set_ The callback set
 * @param value_ The value_ to assign the callback
 * @return 1 if the function was swapped, 0 if not
 *
 * Add or swap a callback in the indicated callback set.  If the
 * callback is already in the set, it is replaced.  If the callback is
 * not found, then it is added.  If the set is currently being
 * iterated, then the change will be applied after the current full
 * iteration, and prior to the next full iteration.
 */
#define clib_callback_data_ensure(set_,value_)       \
do {                                                 \
  int found_ = 0;                                    \
  clib_spinlock_lock_if_init ((set_)->lock);         \
  typeof ((set_)->next) next_ = (set_)->next;        \
  if (PREDICT_TRUE (next_ == 0))                     \
    {                                                \
      next_ = (set_)->spare;                         \
      (set_)->spare = 0;                             \
      vec_append (next_, (set_)->curr);              \
    }                                                \
  u32 sz_ = vec_len (next_);                         \
  u32 i_;                                            \
  for (i_ = 0; i_ < sz_; i_++)                       \
    if (next_[i_].fp == (value_).fp)                 \
      {                                              \
        found_ = 1;                                  \
        break;                                       \
      }                                              \
  if (!found_)                                       \
    vec_validate (next_, i_);                        \
  next_[i_] = (value_);                              \
  (set_)->next = next_;                              \
  clib_spinlock_unlock_if_init ((set_)->lock);       \
} while(0)

/** @brief Enable/Disable the specified callback
 * @param set_ The callback set
 * @param fp_ The callback function
 * @param ena_ 1 to enable, 0 to disable
 *
 * Enable or disable a callback function, with no data.
 */
#define clib_callback_data_enable_disable(set_,fp_,ena_)   \
do {                                                       \
  if (ena_)                                                \
    {                                                      \
      typeof ((set_)->next[0]) data_ = { .fp = (fp_) };    \
      clib_callback_data_add ((set_), data_);              \
    }                                                      \
  else                                                     \
    clib_callback_data_remove ((set_), (fp_));             \
} while (0)

/** @brief Get the value of a callback, if set.
 * @param set_ The callback set
 * @param fp_ The callback function
 * @param v_ Set to the callback's current value
 * @return 1 if the function is in the set, 0 if not
 */
#define clib_callback_data_get_value(set_,fp_,v_)    \
({                                                   \
  int found_ = 0;                                    \
  clib_spinlock_lock_if_init ((set_)->lock);         \
  typeof ((set_)->next) search_ = (set_)->next;      \
  if (PREDICT_TRUE (search_ == 0))                   \
    search_ = (set_)->curr;                          \
  u32 sz_ = vec_len (search_);                       \
  u32 i_;                                            \
  for (i_ = 0; i_ < sz_; i_++)                       \
    if (search_[i_].fp == (fp_))                     \
      {                                              \
        (v_) = search_[i];                           \
        found_ = 1;                                  \
        break;                                       \
      }                                              \
  clib_spinlock_unlock_if_init ((set_)->lock);       \
  found_;                                            \
})

/** @brief Check if callback is set
 * @param set_ The callback set
 * @param fp_ The callback function
 * @return 1 if the function is in the set, 0 if not
 */
#define clib_callback_data_is_set(set_,fp_)          \
({                                                   \
  int found_ = 0;                                    \
  clib_spinlock_lock_if_init ((set_)->lock);         \
  typeof ((set_)->next) search_ = (set_)->next;      \
  if (PREDICT_TRUE (search_ == 0))                   \
    search_ = (set_)->curr;                          \
  u32 sz_ = vec_len (search_);                       \
  u32 i_;                                            \
  for (i_ = 0; i_ < sz_; i_++)                       \
    if (search_[i_].fp == (fp_))                     \
      {                                              \
        found_ = 1;                                  \
        break;                                       \
      }                                              \
  clib_spinlock_unlock_if_init ((set_)->lock);       \
  found_;                                            \
})

/** @brief Check for and get current callback set
 * @param set_ the callback set
 * @param varargs additional callback parameters
 */
#define clib_callback_data_check_and_get(set_)       \
({                                                   \
  typeof ((set_)->curr) curr_ = (set_)->curr;        \
  if (PREDICT_FALSE ((set_)->next != 0))             \
    {                                                \
      clib_spinlock_lock_if_init ((set_)->lock);     \
      vec_reset_length (curr_);                      \
      (set_)->spare = curr_;                         \
      curr_ = (set_)->next;                          \
      (set_)->next = 0;                              \
      if (PREDICT_FALSE (0 == vec_len (curr_)))      \
        vec_free (curr_);                            \
      (set_)->curr = curr_;                          \
      clib_spinlock_unlock_if_init ((set_)->lock);   \
    }                                                \
  curr_;                                             \
})

/** @brief Iterate and call a callback vector
 * @param vec_ the callback vector
 * @param varargs additional callback parameters
 */
#define clib_callback_data_call_vec(vec_, ...)                                \
  do                                                                          \
    {                                                                         \
      u32 sz_ = vec_len (vec_);                                               \
      u32 i_;                                                                 \
      for (i_ = 0; i_ < sz_; i_++)                                            \
	{                                                                     \
	  clib_prefetch_store (&vec_[i_ + 1]);                                \
	  (vec_[i_].fp) (&vec_[i_], __VA_ARGS__);                             \
	}                                                                     \
    }                                                                         \
  while (0)

/** @brief Call the specified callback set
 * @param set_ the callback set
 * @param varargs additional callback parameters
 */
#define clib_callback_data_call(set_, ...)                           \
do {                                                                 \
  typeof ((set_)->curr) v_ = clib_callback_data_check_and_get(set_); \
  clib_callback_data_iterate (v_, __VA_ARGS__);                      \
} while (0)

/** @brief prefetch the callback set
 * @param set_ The callback set
 */
#define clib_callback_data_prefetch(set_)                                     \
  do                                                                          \
    {                                                                         \
      if (PREDICT_FALSE ((set_)->curr))                                       \
	clib_prefetch_store ((set_)->curr);                                   \
    }                                                                         \
  while (0)

#endif /* included_callback_data_h */

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */