aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet/interface.h
AgeCommit message (Expand)AuthorFilesLines
2018-02-26vnet: add 25G interface speed flagDamjan Marion1-2/+4
2018-02-13vnet:remove duplicate interface function macroEyal Bari1-15/+3
2018-01-24Improve tunnel interface creation performanceJohn Lo1-0/+4
2017-08-01P2P EthernetPavel Kotucek1-0/+15
2017-07-18TCP/UDP checksum offload APIDave Barach1-0/+3
2017-07-13Fix crash with worker threads on 4K VXLAN/BD setup (VPP-907)John Lo1-6/+2
2017-07-12Deprecate support for flattened output nodesDamjan Marion1-3/+0
2017-06-21Introduce default rx mode for device driversDamjan Marion1-0/+2
2017-05-10vnet: introduce error state for sw interfacesDamjan Marion1-0/+3
2017-05-10device: Add callback for set interface rx-modeSteven1-9/+17
2017-05-02Add interface rx mode commands, unify rx mode and placement CLIDamjan Marion1-0/+15
2017-04-10Common device-input interrupt infraDamjan Marion1-0/+3
2017-04-06Use thread local storage for thread indexDamjan Marion1-1/+1
2017-03-20vnet: add device-input threadplacement infraDamjan Marion1-0/+6
2017-03-07CLI: hide deleted interfacesEyal Bari1-0/+3
2017-02-13Basic support for LISP-GPE encapsulated NSH packetsFlorin Coras1-1/+3
2016-12-28Reorganize source tree to use single autotools instanceDamjan Marion1-0/+658
*/ .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) 2015 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 "vat.h"
#include "plugin.h"

vat_main_t vat_main;

int connect_to_vpe(char *name)
{
    vat_main_t * vam = &vat_main;
    api_main_t * am = &api_main;

    if (vl_client_connect_to_vlib("/vpe-api", name, 32) < 0)
        return -1;
    
    vam->vl_input_queue = am->shmem_hdr->vl_input_queue;
    vam->my_client_index = am->my_client_index;

    return 0;
}

void vlib_cli_output(struct vlib_main_t * vm, char * fmt, ...)
{ clib_warning ("BUG");} 


static u8 * format_api_error (u8 * s, va_list * args)
{
    vat_main_t * vam = va_arg (*args, vat_main_t *);
    i32 error = va_arg (*args, u32);
    uword * p;

    p = hash_get (vam->error_string_by_error_number, -error);

    if (p)
        s = format (s, "%s", p[0]);
    else
        s = format (s, "%d", error);
    return s;
}

void do_one_file (vat_main_t * vam)
{
    int rv;
    int (*fp)(vat_main_t *vam);
    int arg_len;
    unformat_input_t _input;
    u8 *cmdp, *argsp;
    uword * p;
    u8 * this_cmd = 0;

    vam->input = &_input;

    /* Used by the "quit" command handler */
    if (setjmp (vam->jump_buf) != 0)
        return;
    
    while (1) {
        if (vam->ifp == stdin) {
            if (vam->exec_mode == 0)
                rv = write (1, "vat# ", 5);
            else
                rv = write (1, "exec# ", 6);
        }
            
        _vec_len(vam->inbuf) = 4096;
            
        if (fgets ((char *)vam->inbuf, vec_len(vam->inbuf), vam->ifp) == 0)
            break;
            
        vam->input_line_number ++;

        vec_free (this_cmd);

        this_cmd = (u8 *) clib_macro_eval (&vam->macro_main, (char *)vam->inbuf,
                                           1 /* complain */);
            
        if (vam->exec_mode == 0) {
            /* Split input into cmd + args */
            cmdp = this_cmd;
        
            while (cmdp < (this_cmd + vec_len(this_cmd))) {
                if (*cmdp == ' ' || *cmdp == '\t' || *cmdp == '\n') {
                    cmdp++;
                } else
                    break;
            }
            argsp = cmdp;
            while (argsp < (this_cmd + vec_len(this_cmd))) {
                if (*argsp != ' ' && *argsp != '\t' && *argsp != '\n') {
                    argsp++;
                } else
                    break;
            }
            *argsp++ = 0;
            while (argsp < (this_cmd + vec_len(this_cmd))) {
                if (*argsp == ' ' || *argsp == '\t' || *argsp == '\n') {
                    argsp++;
                } else
                    break;
            }
            
            
            /* Blank input line? */
            if (*cmdp == 0)
                continue;
            
            p = hash_get_mem (vam->function_by_name, cmdp);
            if (p == 0) {
                errmsg ("'%s': function not found\n", cmdp);
                continue;
            }
            
            arg_len = strlen((char *) argsp);
            
            unformat_init_string (vam->input, (char *)argsp, arg_len);
            fp = (void *)p[0];
        } else {
            unformat_init_string (vam->input, (char *) this_cmd, 
                                  strlen((char *) this_cmd));
            cmdp = this_cmd;
            fp = exec;
        }

        rv = (*fp)(vam);
        if (rv < 0)
            errmsg ("%s error: %U\n", cmdp, format_api_error, vam, rv);
        unformat_free (vam->input);

        if (vam->regenerate_interface_table) {
            vam->regenerate_interface_table = 0;
            api_sw_interface_dump (vam);
        }
    }
}

static void init_error_string_table (vat_main_t * vam)
{

    vam->error_string_by_error_number = hash_create (0, sizeof(uword));

#define _(n,v,s) hash_set (vam->error_string_by_error_number, -v, s);
    foreach_vnet_api_error;
#undef _

    hash_set (vam->error_string_by_error_number, 99, "Misc");
}

static i8 *eval_current_file (macro_main_t *mm, i32 complain)
{
    vat_main_t * vam = &vat_main;
    return ((i8 *) format (0, "%s%c", vam->current_file, 0));
}

static i8 *eval_current_line (macro_main_t *mm, i32 complain)
{
    vat_main_t * vam = &vat_main;
    return ((i8 *) format (0, "%d%c", vam->input_line_number, 0));
}


int main (int argc, char ** argv)
{
    vat_main_t * vam = &vat_main;
    unformat_input_t _argv, *a = &_argv;
    u8 **input_files = 0;
    u8 *output_file = 0;
    u8 *chroot_prefix;
    u8 *this_input_file;
    u8 interactive = 1;
    u8 json_output = 0;
    u8 * heap;
    mheap_t * h;
    int i;

    clib_mem_init (0, 128<<20);

    heap = clib_mem_get_per_cpu_heap();
    h = mheap_header (heap);
      
    /* make the main heap thread-safe */
    h->flags |= MHEAP_FLAG_THREAD_SAFE;

    clib_macro_init (&vam->macro_main);
    clib_macro_add_builtin (&vam->macro_main, "current_file", eval_current_file);
    clib_macro_add_builtin (&vam->macro_main, "current_line", eval_current_line);

    init_error_string_table (vam);

    unformat_init_command_line (a, argv);

    while (unformat_check_input(a) != UNFORMAT_END_OF_INPUT) {
        if (unformat (a, "in %s", &this_input_file))
            vec_add1 (input_files, this_input_file);
        else if (unformat (a, "out %s", &output_file))
            ;
        else if (unformat (a, "script"))
            interactive = 0;
        else if (unformat (a, "json"))
            json_output = 1;
        else if (unformat (a, "plugin_path %s", (u8 *)&vat_plugin_path))
            vec_add1 (vat_plugin_path, 0);
        else if (unformat (a, "plugin_name_filter %s", 
                           (u8 *)&vat_plugin_name_filter))
            vec_add1 (vat_plugin_name_filter, 0);
        else if (unformat (a, "chroot prefix %s", &chroot_prefix)) {
            vl_set_memory_root_path ((char *)chroot_prefix);
        } else {
            fformat (stderr, 
                     "%s: usage [in <f1> ... in <fn>] [out <fn>] [script] [json]\n");
            exit (1);
        }
    }

    if (output_file)
        vam->ofp = fopen ((char *) output_file, "w");
    else
        vam->ofp = stdout;

    if (vam->ofp == NULL) {
        fformat (stderr, "Couldn't open output file %s\n",
                 output_file ? (char *) output_file : "stdout");
        exit (1);
    }

    clib_time_init (&vam->clib_time);

    vat_api_hookup(vam);
    vat_plugin_api_reference();

    if (connect_to_vpe("vpp_api_test") < 0) {
        svm_region_exit();
        fformat (stderr, "Couldn't connect to vpe, exiting...\n");
        exit (1);
    }

    vam->json_output = json_output;

    if (!json_output) {
        api_sw_interface_dump (vam);
    }

    vec_validate (vam->inbuf, 4096);

    vam->current_file = (u8 *) "plugin-init";
    vat_plugin_init (vam);

    for (i = 0; i < vec_len (input_files); i++) {
        vam->ifp = fopen ((char *) input_files[i], "r");
        if (vam->ifp == NULL) {
            fformat (stderr, "Couldn't open input file %s\n",
                     input_files[i]);
            continue;
        }
        vam->current_file = input_files[i];
        vam->input_line_number = 0;
        do_one_file (vam);
        fclose (vam->ifp);
    }

    if (output_file)
        fclose (vam->ofp);

    if (interactive) {
        vam->ifp = stdin;
        vam->ofp = stdout;
        vam->current_file = (u8 *) "interactive";
        do_one_file (vam);
        fclose(vam->ifp);
    }

    vl_client_disconnect_from_vlib();
    exit (0);
}