2 * Copyright (c) 2015 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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include <vppinfra/cpu.h>
17 #include <vlib/vlib.h>
18 #include <vlib/unix/unix.h>
19 #include <vnet/plugin/plugin.h>
20 #include <vnet/ethernet/ethernet.h>
22 #include <api/vpe_msg_enum.h>
25 #include <vnet/devices/dpdk/dpdk.h>
29 vpe_main_init (vlib_main_t * vm)
32 vlib_unix_cli_set_prompt ("DBGvpp# ");
34 vlib_unix_cli_set_prompt ("vpp# ");
36 /* Turn off network stack components which we don't want */
37 vlib_mark_init_function_complete (vm, srp_init);
41 * Load plugins from /usr/lib/vpp_plugins by default
43 char *vlib_plugin_path = "/usr/lib/vpp_plugins";
45 void *vnet_get_handoff_structure (void)
47 static vnet_plugin_handoff_t _rv, *rv = &_rv;
49 rv->vnet_main = vnet_get_main();
50 rv->ethernet_main = ðernet_main;
54 int main (int argc, char * argv[])
57 vlib_main_t * vm = &vlib_global_main;
58 void vl_msg_api_set_first_available_msg_id (u16);
59 uword main_heap_size = (1ULL << 30);
62 void vlib_set_get_handoff_structure_cb (void *cb);
65 const char * msg = "ERROR: This binary requires CPU with %s extensions.\n";
67 if (!clib_cpu_supports_ ## a ()) \
69 fprintf(stderr, msg, b); \
95 * Load startup config from file.
96 * usage: vpp -c /etc/vpp/startup.conf
98 if ((argc == 3) && !strncmp(argv[1], "-c", 2))
103 char ** argv_ = NULL;
107 fp = fopen (argv[2], "r");
110 fprintf(stderr, "open configuration file '%s' failed\n", argv[2]);
113 argv_ = calloc(1, sizeof(char *));
116 arg = strndup(argv[0], 1024);
122 if (fgets(inbuf, 4096, fp) == 0)
124 p = strtok(inbuf, " \t\n");
129 char ** tmp = realloc(argv_, argc_ * sizeof(char *));
133 arg = strndup(p, 1024);
136 argv_[argc_ - 1] = arg;
137 p = strtok(NULL, " \t\n");
143 char ** tmp = realloc(argv_, (argc_ + 1) * sizeof(char *));
154 * Look for and parse the "heapsize" config parameter.
155 * Manual since none of the clib infra has been bootstrapped yet.
157 * Format: heapsize <nn>[mM][gG]
160 for (i = 1; i < (argc-1); i++) {
161 if (!strncmp (argv[i], "plugin_path", 11)) {
163 vlib_plugin_path = argv[++i];
164 } else if (!strncmp (argv[i], "heapsize", 8)) {
165 sizep = (u8 *) argv[i+1];
167 while (*sizep >= '0' && *sizep <= '9') {
169 size += *sizep++ - '0';
174 "warning: heapsize parse error '%s', use default %lld\n",
175 argv[i], (long long int) main_heap_size);
179 main_heap_size = size;
181 if (*sizep == 'g' || *sizep == 'G')
182 main_heap_size <<= 30;
183 else if (*sizep == 'm' || *sizep == 'M')
184 main_heap_size <<= 20;
190 /* Set up the plugin message ID allocator right now... */
191 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
193 /* Allocate main heap */
194 if (clib_mem_init (0, main_heap_size)) {
195 vm->init_functions_called = hash_create (0, /* value bytes */ 0);
199 dpdk_pmd_constructor_init();
202 unix_physmem_init(vm, 0 /* fail_if_physical_memory_not_present */);
204 vlib_set_get_handoff_structure_cb (&vnet_get_handoff_structure);
205 return vlib_unix_main (argc, argv);
208 int rv __attribute__((unused)) =
209 write (2, "Main heap allocation failure!\r\n", 31);
215 static clib_error_t *
216 heapsize_config (vlib_main_t * vm, unformat_input_t * input)
220 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
221 if (unformat (input, "%dm", &junk)
222 || unformat (input, "%dM", &junk)
223 || unformat (input, "%dg", &junk)
224 || unformat (input, "%dG", &junk))
227 return clib_error_return (0, "unknown input '%U'",
228 format_unformat_error, input);
233 VLIB_CONFIG_FUNCTION (heapsize_config, "heapsize");
235 static clib_error_t *
236 plugin_path_config (vlib_main_t * vm, unformat_input_t * input)
240 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
241 if (unformat (input, "%s", &junk)) {
246 return clib_error_return (0, "unknown input '%U'",
247 format_unformat_error, input);
252 VLIB_CONFIG_FUNCTION (plugin_path_config, "plugin_path");
254 void vl_msg_api_post_mortem_dump(void);
258 vl_msg_api_post_mortem_dump();
262 void vhost_user_unmap_all (void) __attribute__((weak));
263 void vhost_user_unmap_all (void) { }
265 void os_exit (int code)
267 static int recursion_block;
276 vl_msg_api_post_mortem_dump();
277 vhost_user_unmap_all();
283 void vl_msg_api_barrier_sync(void)
285 vlib_worker_thread_barrier_sync (vlib_get_main());
288 void vl_msg_api_barrier_release(void)
290 vlib_worker_thread_barrier_release (vlib_get_main());
293 /* This application needs 1 thread stack for the stats pthread */
294 u32 vlib_app_num_thread_stacks_needed (void)
300 * Depending on the configuration selected above,
301 * it may be necessary to generate stub graph nodes.
302 * It is never OK to ignore "node 'x' refers to unknown node 'y'
308 static clib_error_t *
309 test_crash_command_fn (vlib_main_t * vm,
310 unformat_input_t * input,
311 vlib_cli_command_t * cmd)
313 u64 * p = (u64 *)0xdefec8ed;
321 VLIB_CLI_COMMAND (test_crash_command, static) = {
322 .path = "test crash",
323 .short_help = "crash the bus!",
324 .function = test_crash_command_fn,