summaryrefslogtreecommitdiffstats
path: root/src/examples
diff options
context:
space:
mode:
authorAnlu Yan <ayan@cisco.com>2017-02-14 18:07:40 -0800
committerDamjan Marion <dmarion.lists@gmail.com>2017-02-16 15:09:26 +0000
commita4cb12b30d51be3463315688179297404783fe8d (patch)
tree66bbe4f2a622e72648f503ba845d142dff97f084 /src/examples
parentb33f413af46ec8dff7f222dbd5bc3bcec1502d3d (diff)
Fix sample plugin breakage.
Add vat_helper_macros.h to be installed in /usr/include/vlibapi Define a version for the sample plugin (separate from the VPP versioning). Hook up vnet_main in plugin init. Change-Id: I293b9dc824d0813ea2bb8747d535e4210a88b385 Signed-off-by: Anlu Yan <ayan@cisco.com>
Diffstat (limited to 'src/examples')
-rw-r--r--src/examples/sample-plugin/sample/sample.c27
-rw-r--r--src/examples/sample-plugin/sample/sample.h4
2 files changed, 9 insertions, 22 deletions
diff --git a/src/examples/sample-plugin/sample/sample.c b/src/examples/sample-plugin/sample/sample.c
index 603cb2d0ee4..7588dbc0aea 100644
--- a/src/examples/sample-plugin/sample/sample.c
+++ b/src/examples/sample-plugin/sample/sample.c
@@ -79,26 +79,11 @@ do { \
#define foreach_sample_plugin_api_msg \
_(SAMPLE_MACSWAP_ENABLE_DISABLE, sample_macswap_enable_disable)
-/*
- * This routine exists to convince the vlib plugin framework that
- * we haven't accidentally copied a random .dll into the plugin directory.
- *
- * Also collects global variable pointers passed from the vpp engine
- */
-
-clib_error_t *
-vlib_plugin_register (vlib_main_t * vm, vnet_plugin_handoff_t * h,
- int from_early_init)
-{
- sample_main_t * sm = &sample_main;
- clib_error_t * error = 0;
-
- sm->vlib_main = vm;
- sm->vnet_main = h->vnet_main;
- sm->ethernet_main = h->ethernet_main;
-
- return error;
-}
+/* *INDENT-OFF* */
+VLIB_PLUGIN_REGISTER () = {
+ .version = SAMPLE_PLUGIN_BUILD_VER,
+};
+/* *INDENT-ON* */
/* Action function shared between message handler and debug CLI */
@@ -229,6 +214,8 @@ static clib_error_t * sample_init (vlib_main_t * vm)
clib_error_t * error = 0;
u8 * name;
+ sm->vnet_main = vnet_get_main ();
+
name = format (0, "sample_%08x%c", api_version, 0);
/* Ask for a correctly-sized block of API message decode slots */
diff --git a/src/examples/sample-plugin/sample/sample.h b/src/examples/sample-plugin/sample/sample.h
index 6137ffff487..c9778f74298 100644
--- a/src/examples/sample-plugin/sample/sample.h
+++ b/src/examples/sample-plugin/sample/sample.h
@@ -28,13 +28,13 @@ typedef struct {
u16 msg_id_base;
/* convenience */
- vlib_main_t * vlib_main;
vnet_main_t * vnet_main;
- ethernet_main_t * ethernet_main;
} sample_main_t;
sample_main_t sample_main;
extern vlib_node_registration_t sample_node;
+#define SAMPLE_PLUGIN_BUILD_VER "1.0"
+
#endif /* __included_sample_h__ */
me.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) 2016 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.
 */


#include <vnet/vnet.h>
#include <vnet/mfib/mfib_signal.h>
#include <vppinfra/dlist.h>

/**
 * @brief Pool of signals
 */
static mfib_signal_t *mfib_signal_pool;

/**
 * @brief pool of dlist elements
 */
static dlist_elt_t *mfib_signal_dlist_pool;

/**
 * the list/set of interfaces with signals pending
 */
typedef struct mfib_signal_q_t_
{
    /**
     * the dlist indext that is the head of the list
     */
    u32 mip_head;

    /**
     * Spin lock to protect the list
     */
    int mip_lock;
} mfib_signal_q_t;

/**
 * @brief The pending queue of signals to deliver to the control plane
 */
static mfib_signal_q_t mfib_signal_pending ;

static void
mfib_signal_list_init (void)
{
    dlist_elt_t *head;
    u32 hi;

    pool_get(mfib_signal_dlist_pool, head);
    hi = head - mfib_signal_dlist_pool;

    mfib_signal_pending.mip_head = hi;
    clib_dlist_init(mfib_signal_dlist_pool, hi);
}

void
mfib_signal_module_init (void)
{
    mfib_signal_list_init();
}

static inline void
mfib_signal_lock_aquire (void)
{
    while (__sync_lock_test_and_set (&mfib_signal_pending.mip_lock, 1))
        ;
}

static inline void
mfib_signal_lock_release (void)
{
    mfib_signal_pending.mip_lock = 0;
}

#define MFIB_SIGNAL_CRITICAL_SECTION(_body) \
{                                           \
    mfib_signal_lock_aquire();              \
    do {                                    \
        _body;                              \
    } while (0);                            \
    mfib_signal_lock_release();             \
}

int
mfib_signal_send_one (struct _unix_shared_memory_queue *q,
                      u32 context)
{
    u32 li, si;

    /*
     * with the lock held, pop a signal from the q.
     */
    MFIB_SIGNAL_CRITICAL_SECTION(
    ({
        li = clib_dlist_remove_head(mfib_signal_dlist_pool,
                                    mfib_signal_pending.mip_head);
    }));

    if (~0 != li)
    {
        mfib_signal_t *mfs;
        mfib_itf_t *mfi;
        dlist_elt_t *elt;

        elt = pool_elt_at_index(mfib_signal_dlist_pool, li);
        si = elt->value;

        mfs = pool_elt_at_index(mfib_signal_pool, si);
        mfi = mfib_itf_get(mfs->mfs_itf);
        mfi->mfi_si = INDEX_INVALID;
        __sync_fetch_and_and(&mfi->mfi_flags,
                             ~MFIB_ITF_FLAG_SIGNAL_PRESENT);


        vl_mfib_signal_send_one(q, context, mfs);

        /*
         * with the lock held, return the resoruces of the signals posted
         */
        MFIB_SIGNAL_CRITICAL_SECTION(
        ({
            pool_put_index(mfib_signal_pool, si);
            pool_put_index(mfib_signal_dlist_pool, li);
        }));

        return (1);
    }
    return (0);
}

void
mfib_signal_push (const mfib_entry_t *mfe,
                  mfib_itf_t *mfi,
                  vlib_buffer_t *b0)
{
    mfib_signal_t *mfs;
    dlist_elt_t *elt;
    u32 si, li;

    MFIB_SIGNAL_CRITICAL_SECTION(
    ({
        pool_get(mfib_signal_pool, mfs);
        pool_get(mfib_signal_dlist_pool, elt);

        si = mfs - mfib_signal_pool;
        li = elt - mfib_signal_dlist_pool;

        elt->value = si;
        mfi->mfi_si = li;

        clib_dlist_addhead(mfib_signal_dlist_pool,
                           mfib_signal_pending.mip_head,
                           li);
    }));

    mfs->mfs_entry = mfib_entry_get_index(mfe);
    mfs->mfs_itf = mfib_itf_get_index(mfi);

    if (NULL != b0)
    {
        mfs->mfs_buffer_len = b0->current_length;
        memcpy(mfs->mfs_buffer,
               vlib_buffer_get_current(b0),
               (mfs->mfs_buffer_len > MFIB_SIGNAL_BUFFER_SIZE ?
                MFIB_SIGNAL_BUFFER_SIZE :
                mfs->mfs_buffer_len));
    }
    else
    {
        mfs->mfs_buffer_len = 0;
    }
}

void
mfib_signal_remove_itf (const mfib_itf_t *mfi)
{
    u32 li;

    /*
     * lock the queue to prevent further additions while we fiddle.
     */
    li = mfi->mfi_si;

    if (INDEX_INVALID != li)
    {
        /*
         * it's in the pending q
         */
        MFIB_SIGNAL_CRITICAL_SECTION(
        ({
            dlist_elt_t *elt;

            /*
             * with the lock held;
             *  - remove the signal from the pending list
             *  - free up the signal and list entry obejcts
             */
            clib_dlist_remove(mfib_signal_dlist_pool, li);

            elt = pool_elt_at_index(mfib_signal_dlist_pool, li);
            pool_put_index(mfib_signal_pool, elt->value);
            pool_put(mfib_signal_dlist_pool, elt);
        }));
    }
}