Esempio n. 1
0
static void cli_complete(char *line)
{
	const HIST_ENTRY *hist;
	const char *c;
	LIST_HEAD(msgs);
	int len;
	char *s;

	if (line == NULL) {
		printf("\n");
		cli_exit();
		exit(0);
	}

	line = cli_append_multiline(line);
	if (line == NULL)
		return;

	for (c = line; *c != '\0'; c++)
		if (!isspace(*c))
			break;
	if (*c == '\0')
		return;

	if (!strcmp(line, "quit")) {
		cli_exit();
		exit(0);
	}

	/* avoid duplicate history entries */
	hist = history_get(history_length);
	if (hist == NULL || strcmp(hist->line, line))
		add_history(line);

	len = strlen(line);
	s = xmalloc(len + 2);
	snprintf(s, len + 2, "%s\n", line);
	xfree(line);
	line = s;

	parser_init(state, &msgs);
	scanner_push_buffer(scanner, &indesc_cli, line);
	nft_run(scanner, state, &msgs);
	erec_print_list(stdout, &msgs);
	xfree(line);
	cache_release();
	iface_cache_release();
}
int main()
{	
    cli_init();

    mastercontroller_init();

    uint8_t i = 0;
    while(1) {
        for(i = 0; i < 5; i++) { 
            mastercontroller_process();
            mastercontroller_process();
            mastercontroller_process();
            mastercontroller_process();
            mastercontroller_process();
            usleep(200);
        }
        mastercontroller_tick();
        cli_process();
    }
    cli_exit();
	return 0;
}
Esempio n. 3
0
node_t *process_cli_file(const std::string &filename,
                         const char *include_paths,
                         node_t *root,
                         process_mode mode,
                         node_t *last_cli_root = 0,
                         node_t *last_cli_end = 0,
                         int submode = 0)
  {
  int num_disable = 0;
  std::string line;
  std::smatch result;

  std::fstream fin(filename, std::ios_base::in);

  if(!fin.good())
    {
    std::cerr << "Failed to open " << filename;
    cli_exit(-1);
    }

  std::string path;
  std::string fname;
  std::string ext;
  std::string::size_type s_index;
  if((s_index = filename.find_last_of('/')) != std::string::npos)
    {
    path = filename.substr(0, s_index);
    fname = filename.substr(s_index+1, filename.length() - s_index);
    }
  else
    {
    path = ".";
    fname = filename;
    }

  if((s_index = fname.find_last_of('.')) == std::string::npos)
    ext = "";
  else
    {
    ext = fname.substr(s_index, fname.length() - s_index);
    fname = fname.substr(s_index);
    }

  // we have to set the paths relative to the src filename if we are using
  // a #include and it refers to a relative path

  int line_num = 0;
  while(!fin.eof())
    {
    std::getline(fin, line);

    line_num++;

    size_t pos = 0;
    while(!line.empty() && isspace(line[pos]))
      pos++;

    if(pos > 0)
      line = line.substr(pos);

    if(line.empty())
      continue;


    // Process the file line by line.The orderof processing
    // These different directives is extremely important.And the
    // order below is not arbitrary.
    //
    // We must process #endif not matter what.Otherwise, once
    // we start a #ifdef block that is omitted, we'll never be able
    // to terminate it.Then, we omit every other type of line as long
    // as there is at least one disable #ifdef left.Afterward, we
    // check for illegal directives.A normal command line is handled
    // last.Illegal tokens are checked inside add_cli().
    if(std::regex_search(line, result, std::regex("^#endif")))
      {
      if(label_stack.empty())
        {
        std::cerr << filename << ":" << line_num << ": Unmatched #ifdef/#ifndef";
        cli_exit(-1);
        }

      num_disable -= label_stack.back().second;
      label_stack.pop_back();

      // Skip the rest of processing because some #ifdef / #ifndef is
    // keeping this line from being processed.
      if(num_disable > 0)
        continue;

      // Check for illegal preprocessor directives
      if(std::regex_search(line, result, std::regex("^#")) &&
        !std::regex_search(line, result, std::regex("^#ifdef(\S*//.*)*")) &&
        !std::regex_search(line, result, std::regex("^#submode(\S*//.*)*")) &&
        !std::regex_search(line, result, std::regex("^#endsubmode(\S*//.*)*")) &&
        !std::regex_search(line, result, std::regex("^#include(\S*//.*)*")))
        {
        std::cerr << filename << ":" << line_num << ": Unknown preprocessor directive";
        cli_exit(-1);
        }
      }
    // comment
    else if(std::regex_search(line, result, std::regex("^\s*//\s*(.*)")))
      {
      continue;
      }
    // #ifdef
    else if(std::regex_search(line, result, std::regex("^#ifdef (.+)")))
Esempio n. 4
0
void uxsock_cleanup(void *arg)
{
	cli_exit();
	free_polls();
}
Esempio n. 5
0
/*****************************************************************************
 * main()
 ****************************************************************************/
int main(int argc, char **argv)
{
    global_config_t *cfg;
    int              ret;

    /*
     * Initialize DPDK infrastructure before we do anything else
     */
    ret = rte_eal_init(argc, argv);
    if (ret < 0)
        rte_panic("Cannot init EAL\n");

    /*
     * Initialize RTE timer library
     */
    rte_timer_subsystem_init();
    /*
     * Precalculate the number of cycles per us so we don't do it everytime.
     */
    cycles_per_us = (rte_get_timer_hz() / 1000000);

    /*
     * Return value above to be used to scan app specific options
     */
    argc -= ret;
    argv += ret;

    /*
     * General checks
     */
    if (rte_lcore_count() < 3)
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s\n",
                       "WARP17 needs at least three cores!");
    /* We only support at most 64 cores right now (to make parsing easier). */
    if (rte_lcore_count() > (sizeof(uint64_t) * 8))
        TPG_ERROR_EXIT(EXIT_FAILURE,
                       "ERROR: WARP17 supports at most %"PRIu32" cores!\n",
                       (uint32_t)sizeof(uint64_t) * 8);
    if (rte_eth_dev_count() > TPG_ETH_DEV_MAX)
        TPG_ERROR_EXIT(EXIT_FAILURE,
                       "ERROR: WARP17 works with at most %u ports!\n",
                       TPG_ETH_DEV_MAX);

    /*
     * Initialize various submodules
     */

    if (!cli_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the command line interface");

    if (!rpc_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the RPC server");

    if (!cfg_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s\n",
                       "Failed initializing default configuration!\n");

    if (!cfg_handle_command_line(argc, argv))
        exit(EXIT_FAILURE); /* Error reporting is handled by the function itself */

    if (!trace_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the tracing module");

    if (!trace_filter_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the trace filter module");

    if (!mem_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed allocating required mbufs");

    /* WARNING: Careful when adding code above this point. Up until ports are
     * initialized DPDK can't know that there might be ring interfaces that
     * still need to be created. Therefore any call to rte_eth_dev_count()
     * doesn't include them.
     */
    if (!port_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the Ethernets ports");

    if (!msg_sys_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the message queues");

    if (!test_mgmt_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing test mgmt");

    if (!test_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing tests");

    if (!eth_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the Ethernets pkt handler");

    if (!arp_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the ARP pkt handler");

    if (!route_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the ROUTE module");

    if (!ipv4_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the IPv4 pkt handler");

    if (!tcp_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the TCP pkt handler");

    if (!udp_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the UDP pkt handler");

    if (!tlkp_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the Session lookup engine");

    if (!tlkp_tcp_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the TCP lookup engine");

    if (!tlkp_udp_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the UDP lookup engine");

    if (!tsm_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the TSM module");

    if (!timer_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the TCP timers module");

    if (!pkt_loop_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the pkt loop");

    if (!raw_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the RAW Application module");

    if (!http_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the RAW Application module");

    start_cores();

    /*
     * Process startup command file, if any.
     */
    cfg = cfg_get_config();
    if (cfg != NULL && cfg->gcfg_cmd_file) {
        if (!cli_run_input_file(cfg->gcfg_cmd_file))
            TPG_ERROR_EXIT(EXIT_FAILURE, "Failed to run command file: %s!\n",
                           cfg->gcfg_cmd_file);
    }

    /*
     * Process CLI commands, and other house keeping tasks...
     */
    cli_interact();
    tpg_exit = true;

    /*
     * Exit!!!
     */
    rte_eal_mp_wait_lcore();

    /*
     * Destroy the CLI.
     */
    cli_exit();

    /*
     * Destroy the mgmt RPC server.
     */
    rpc_destroy();
    return 0;
}