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.
15 #include <vlib/vlib.h>
16 #include <vlib/unix/unix.h>
17 #include <vnet/plugin/plugin.h>
18 #include <vnet/ethernet/ethernet.h>
20 #include <api/vpe_msg_enum.h>
22 /** \mainpage Virtual Packet Edge Documentation
23 * \section intro_sec Introduction
25 * VPE is a specific vector packet processing application,
26 * designed to steer packets to/from tenant virtual machines.
31 vpe_main_init (vlib_main_t * vm)
34 vlib_unix_cli_set_prompt ("DBGvpp# ");
36 vlib_unix_cli_set_prompt ("vpp# ");
38 /* Turn off network stack components which we don't want */
39 vlib_mark_init_function_complete (vm, srp_init);
43 * Load plugins from /usr/lib/vpp_plugins by default
45 char *vlib_plugin_path = "/usr/lib/vpp_plugins";
47 void *vnet_get_handoff_structure (void)
49 static vnet_plugin_handoff_t _rv, *rv = &_rv;
51 rv->vnet_main = vnet_get_main();
52 rv->ethernet_main = ðernet_main;
56 int main (int argc, char * argv[])
59 vlib_main_t * vm = &vlib_global_main;
60 void vl_msg_api_set_first_available_msg_id (u16);
61 uword main_heap_size = (1ULL << 30);
64 void vlib_set_get_handoff_structure_cb (void *cb);
67 __builtin_cpu_init ();
68 const char * msg = "ERROR: This binary requires CPU with %s extensions.\n";
70 if (!__builtin_cpu_supports(a)) \
72 fprintf(stderr, msg, b); \
97 * Load startup config from file.
98 * usage: vpp -c /etc/vpp/startup.conf
100 if ((argc == 3) && !strncmp(argv[1], "-c", 2))
105 char ** argv_ = NULL;
109 fp = fopen (argv[2], "r");
112 fprintf(stderr, "open configuration file '%s' failed\n", argv[2]);
115 argv_ = calloc(1, sizeof(char *));
118 arg = strndup(argv[0], 1024);
124 if (fgets(inbuf, 4096, fp) == 0)
126 p = strtok(inbuf, " \t\n");
131 char ** tmp = realloc(argv_, argc_ * sizeof(char *));
135 arg = strndup(p, 1024);
138 argv_[argc_ - 1] = arg;
139 p = strtok(NULL, " \t\n");
145 char ** tmp = realloc(argv_, (argc_ + 1) * sizeof(char *));
156 * Look for and parse the "heapsize" config parameter.
157 * Manual since none of the clib infra has been bootstrapped yet.
159 * Format: heapsize <nn>[mM][gG]
162 for (i = 1; i < (argc-1); i++) {
163 if (!strncmp (argv[i], "plugin_path", 11)) {
165 vlib_plugin_path = argv[++i];
166 } else if (!strncmp (argv[i], "heapsize", 8)) {
167 sizep = (u8 *) argv[i+1];
169 while (*sizep >= '0' && *sizep <= '9') {
171 size += *sizep++ - '0';
176 "warning: heapsize parse error '%s', use default %lld\n",
177 argv[i], (long long int) main_heap_size);
181 main_heap_size = size;
183 if (*sizep == 'g' || *sizep == 'G')
184 main_heap_size <<= 30;
185 else if (*sizep == 'm' || *sizep == 'M')
186 main_heap_size <<= 20;
192 /* Set up the plugin message ID allocator right now... */
193 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
195 /* Allocate main heap */
196 if (clib_mem_init (0, main_heap_size)) {
197 vm->init_functions_called = hash_create (0, /* value bytes */ 0);
199 vlib_set_get_handoff_structure_cb (&vnet_get_handoff_structure);
200 return vlib_unix_main (argc, argv);
203 int rv __attribute__((unused)) =
204 write (2, "Main heap allocation failure!\r\n", 31);
210 static clib_error_t *
211 heapsize_config (vlib_main_t * vm, unformat_input_t * input)
215 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
216 if (unformat (input, "%dm", &junk)
217 || unformat (input, "%dM", &junk)
218 || unformat (input, "%dg", &junk)
219 || unformat (input, "%dG", &junk))
222 return clib_error_return (0, "unknown input '%U'",
223 format_unformat_error, input);
228 VLIB_CONFIG_FUNCTION (heapsize_config, "heapsize");
230 static clib_error_t *
231 plugin_path_config (vlib_main_t * vm, unformat_input_t * input)
235 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
236 if (unformat (input, "%s", &junk)) {
241 return clib_error_return (0, "unknown input '%U'",
242 format_unformat_error, input);
247 VLIB_CONFIG_FUNCTION (plugin_path_config, "plugin_path");
249 void vl_msg_api_post_mortem_dump(void);
253 vl_msg_api_post_mortem_dump();
257 void vhost_user_unmap_all (void) __attribute__((weak));
258 void vhost_user_unmap_all (void) { }
260 void os_exit (int code)
262 static int recursion_block;
271 vl_msg_api_post_mortem_dump();
272 vhost_user_unmap_all();
278 void vl_msg_api_barrier_sync(void)
280 vlib_worker_thread_barrier_sync (vlib_get_main());
283 void vl_msg_api_barrier_release(void)
285 vlib_worker_thread_barrier_release (vlib_get_main());
288 /* This application needs 1 thread stack for the stats pthread */
289 u32 vlib_app_num_thread_stacks_needed (void)
295 * Depending on the configuration selected above,
296 * it may be necessary to generate stub graph nodes.
297 * It is never OK to ignore "node 'x' refers to unknown node 'y'
303 static clib_error_t *
304 test_crash_command_fn (vlib_main_t * vm,
305 unformat_input_t * input,
306 vlib_cli_command_t * cmd)
308 u64 * p = (u64 *)0xdefec8ed;
316 VLIB_CLI_COMMAND (test_crash_command, static) = {
317 .path = "test crash",
318 .short_help = "crash the bus!",
319 .function = test_crash_command_fn,