コード例 #1
0
ファイル: pipeline_stage.c プロジェクト: tidatida/lagopus
static void
s_once_proc(void) {
  lagopus_result_t r;

  if ((r = lagopus_hashmap_create(&s_ps_name_tbl, LAGOPUS_HASHMAP_TYPE_STRING,
                                  NULL)) != LAGOPUS_RESULT_OK) {
    lagopus_perror(r);
    lagopus_exit_fatal("can't initialize the name - pipeline stage table.\n");
  }

  if ((r = lagopus_hashmap_create(&s_ps_obj_tbl, LAGOPUS_HASHMAP_TYPE_ONE_WORD,
                                  NULL)) != LAGOPUS_RESULT_OK) {
    lagopus_perror(r);
    lagopus_exit_fatal("can't initialize the pipeline stage table.\n");
  }

  (void)pthread_atfork(NULL, NULL, s_child_at_fork);
}
コード例 #2
0
ファイル: rib_notifier.c プロジェクト: hibitomo/lagopus
/**
 * Initialize.
 * Create table for interface information.
 */
lagopus_result_t
rib_notifier_init() {
  lagopus_result_t rv;
  lagopus_rwlock_create(&ifinfo_lock);
  rv = lagopus_hashmap_create(&ifinfo_hashmap,
                              LAGOPUS_HASHMAP_TYPE_ONE_WORD,
                              ifinfo_entry_free);
  return rv;
}
コード例 #3
0
ファイル: channel_mgr.c プロジェクト: JackieXie168/lagopus
static void
initialize_internal(void) {
  lagopus_result_t ret;

  ret = lagopus_mutex_create(&lock);
  if (ret != LAGOPUS_RESULT_OK) {
    lagopus_exit_fatal("channel_mgr_initialize:lagopus_mutex_create");
  }

  ret = lagopus_hashmap_create(&main_table, LAGOPUS_HASHMAP_TYPE_STRING,
                               channel_entry_free);
  if (ret != LAGOPUS_RESULT_OK) {
    lagopus_exit_fatal("channel_mgr_initialize:lagopus_hashmap_create");
  }

  ret = lagopus_hashmap_create(&dp_table, LAGOPUS_HASHMAP_TYPE_ONE_WORD,
                               channel_list_entry_free);
  if (ret != LAGOPUS_RESULT_OK) {
    lagopus_exit_fatal("channel_mgr_initialize:lagopus_hashmap_create");
  }

}
コード例 #4
0
ファイル: callout.c プロジェクト: 1514louluo/lagopus
static void
s_once_proc(void) {
  lagopus_result_t r;

  if ((r = lagopus_mutex_create(&s_sched_lck)) != LAGOPUS_RESULT_OK) {
    lagopus_perror(r);
    lagopus_exit_fatal("can't initialize the callout scheduler main mutex.\n");
  }

  if ((r = lagopus_mutex_create(&s_lck)) != LAGOPUS_RESULT_OK) {
    lagopus_perror(r);
    lagopus_exit_fatal("can't initialize the callout global mutex.\n");
  }

  if ((r = lagopus_cond_create(&s_sched_cnd)) != LAGOPUS_RESULT_OK) {
    lagopus_perror(r);
    lagopus_exit_fatal("can't initialize the callout cond.\n");
  }

  if ((r = lagopus_hashmap_create(&s_tsk_tbl,
                                  LAGOPUS_HASHMAP_TYPE_ONE_WORD,
                                  NULL)) != LAGOPUS_RESULT_OK) {
    lagopus_perror(r);
    lagopus_exit_fatal("can't initialize the callout table.\n");
  }

  if ((r = lagopus_bbq_create(&s_urgent_tsk_q, lagopus_callout_task_t,
                              CALLOUT_TASK_MAX, s_task_freeup)) != 
      LAGOPUS_RESULT_OK) {
    lagopus_perror(r);
    lagopus_exit_fatal("can't initialize the callout urgent tasks queue.\n");
  }

  if ((r = lagopus_bbq_create(&s_idle_tsk_q, lagopus_callout_task_t,
                              CALLOUT_TASK_MAX, s_task_freeup)) !=
      LAGOPUS_RESULT_OK) {
    lagopus_perror(r);
    lagopus_exit_fatal("can't initialize the callout idle tasks queue.\n");
  }

  if ((r = lagopus_mutex_create_recursive(&s_q_lck)) != LAGOPUS_RESULT_OK) {
    lagopus_perror(r);
    lagopus_exit_fatal("can't initialize the callout task queue mutex.\n");
  }

  TAILQ_INIT(&s_chrono_tsk_q);
}
コード例 #5
0
ファイル: flowinfo_metadata.c プロジェクト: lagopus/lagopus
struct flowinfo *
new_flowinfo_metadata(void) {
  struct flowinfo *self;

  self = calloc(1, sizeof(struct flowinfo));
  if (self != NULL) {
    lagopus_hashmap_create(&self->hashmap, LAGOPUS_HASHMAP_TYPE_ONE_WORD,
                           freeup_flowinfo);
    /* misc is not used */
    self->add_func = add_flow_metadata;
    self->del_func = del_flow_metadata;
    self->match_func = match_flow_metadata;
    self->find_func = find_flow_metadata;
    self->destroy_func = destroy_flowinfo_metadata;
  }
  return self;
}
コード例 #6
0
ファイル: ofp_bridgeq_mgr.c プロジェクト: D-TOKIOKA/lagopus
static void
initialize_internal(void) {
  lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES;

  /* create hashmap */
  ret = lagopus_hashmap_create(&bridgeq_table,
                               LAGOPUS_HASHMAP_TYPE_ONE_WORD,
                               bridgeq_freeup_proc);
  if (ret != LAGOPUS_RESULT_OK) {
    lagopus_exit_fatal("Can't create bridgeq table.\n");
  }

  ret = lagopus_mutex_create(&lock);
  if (ret != LAGOPUS_RESULT_OK) {
    lagopus_exit_fatal("Can't create lock.\n");
  }
}
コード例 #7
0
ファイル: flowdb_test.c プロジェクト: 1514louluo/lagopus
void
setUp(void) {
  datastore_bridge_info_t info;

  TEST_ASSERT_NULL(bridge);
  TEST_ASSERT_NULL(flowdb);
  TEST_ASSERT_NULL(ports);
  TEST_ASSERT_NULL(group_table);

  TEST_ASSERT_EQUAL(dp_api_init(), LAGOPUS_RESULT_OK);
  memset(&info, 0, sizeof(info));
  info.dpid = dpid;
  info.fail_mode = DATASTORE_BRIDGE_FAIL_MODE_SECURE;
  TEST_ASSERT_TRUE(LAGOPUS_RESULT_OK == dp_bridge_create(bridge_name, &info));
  TEST_ASSERT_NOT_NULL(bridge = dp_bridge_lookup(bridge_name));
  TEST_ASSERT_NOT_NULL(flowdb = bridge->flowdb);
  TEST_ASSERT_EQUAL(lagopus_hashmap_create(&ports,
                                           LAGOPUS_HASHMAP_TYPE_ONE_WORD,
                                           NULL), LAGOPUS_RESULT_OK);
  TEST_ASSERT_NOT_NULL(group_table = group_table_alloc(bridge));
}
コード例 #8
0
ファイル: check0.c プロジェクト: JackieXie168/lagopus
static void
s_once_proc(void) {
  lagopus_result_t r;

  if ((r = lagopus_hashmap_create(&s_tbl, LAGOPUS_HASHMAP_TYPE_STRING,
                                  NULL)) != LAGOPUS_RESULT_OK) {
    lagopus_perror(r);
    lagopus_exit_fatal("can't initialize an object table.\n");
  }

  if ((r = datastore_register_table(MY_COMMAND_NAME,
                                    &s_tbl,
                                    s_update,
                                    NULL,
                                    NULL,
                                    NULL,
                                    NULL,
                                    NULL)) != LAGOPUS_RESULT_OK) {
    lagopus_perror(r);
    lagopus_exit_fatal("can't register an object table for \"%s\".\n",
                       MY_COMMAND_NAME);
  }

  if ((r = datastore_create_interp(&s_interp)) != LAGOPUS_RESULT_OK) {
    lagopus_perror(r);
    lagopus_exit_fatal("can't create the datastore interpretor.\n");
  }

  if ((r = datastore_interp_register_command(&s_interp, NULL,
           MY_COMMAND_NAME, s_parse)) !=
      LAGOPUS_RESULT_OK) {
    lagopus_perror(r);
    lagopus_exit_fatal("can't register an object command \"%s\".\n",
                       MY_COMMAND_NAME);
  }

  (void)pthread_atfork(NULL, NULL, s_child_at_fork);
}
コード例 #9
0
ファイル: snmpmgr.c プロジェクト: tidatida/lagopus
static void
initialize_internal(void) {
  lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES;
  void *logger_client_arg = NULL;
  char *master_agentx_socket = NULL;
  char *ping_interval_string = NULL;
  uint16_t ping_interval = 0;

  state = SNMPMGR_NONE;

  /* `is_thread` is able to be changed only once here */
  is_thread = is_thread_dummy;
  if (is_thread == false && thdptr_dummy != NULL) {
    *thdptr_dummy = NULL;
  } else if (thdptr_dummy != NULL) {
    *thdptr_dummy = &snmpmgr;
  } else {
    /* never reached! */
    return;
  }

  if (lagopus_mutex_create(&snmp_lock) != LAGOPUS_RESULT_OK) {
    return;
  }

  if (lagopus_mutex_create(&snmp_state_lock) != LAGOPUS_RESULT_OK) {
    return;
  }

  snmp_set_do_debugging(false);

  /* setup Net-SNMP logger to use the lagopus logging function */
  if (snmp_register_callback(SNMP_CALLBACK_LIBRARY,
                             SNMP_CALLBACK_LOGGING,
                             snmp_log_callback_wrapper,
                             logger_client_arg) != SNMPERR_SUCCESS) {
    return;
  }
  snmp_enable_calllog();

  /* setup the SNMP module to be Agentx subagent */
  netsnmp_enable_subagent();

#ifdef THE_CONFSYS_ERA
  master_agentx_socket = config_get("snmp master-agentx-socket WORD");
  if (master_agentx_socket == NULL) {
    config_set_default("snmp master-agentx-socket WORD",
                       (char *)DEFAULT_SNMPMGR_AGENTX_SOCKET);
    master_agentx_socket = config_get("snmp master-agentx-socket WORD");
  }
#else
  /*
   * FIXME:
   *	Fetch it from the datastore.
   */
  master_agentx_socket = (char *)DEFAULT_SNMPMGR_AGENTX_SOCKET;
#endif /* THE_CONFSYS_ERA */
  lagopus_msg_debug(25, "master agentx socket is %s\n", master_agentx_socket);

  if (netsnmp_ds_set_string(NETSNMP_DS_APPLICATION_ID,
                            NETSNMP_DS_AGENT_X_SOCKET,
                            master_agentx_socket)
      != SNMPERR_SUCCESS) {
    initialize_ret = LAGOPUS_RESULT_SNMP_API_ERROR;
    return;
  }

  /* don't read/write configuration files */
  if (netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID,
                             NETSNMP_DS_LIB_DONT_PERSIST_STATE,
                             true) != SNMPERR_SUCCESS) {
    initialize_ret = LAGOPUS_RESULT_SNMP_API_ERROR;
    return;
  }
  if (netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID,
                             NETSNMP_DS_LIB_DISABLE_PERSISTENT_LOAD,
                             true) != SNMPERR_SUCCESS) {
    initialize_ret = LAGOPUS_RESULT_SNMP_API_ERROR;
    return;
  }

  /* the interval [sec] to send ping to AgentX master agent */
#ifdef THE_CONFSYS_ERA
  ping_interval_string = config_get("snmp ping-interval-second 1-255");
  if (ping_interval_string != NULL &&
      (ret = check_ping_interval(ping_interval_string, &ping_interval))
      != LAGOPUS_RESULT_OK) {
    config_set_default("snmp ping-interval-second 1-255",
                       (char *) __STR__(DEFAULT_SNMPMGR_AGENTX_PING_INTERVAL_SEC));
    ping_interval_string = config_get("snmp ping-interval-second 1-255");
    ping_interval = DEFAULT_SNMPMGR_AGENTX_PING_INTERVAL_SEC; /* default value */
  }
#else
  /*
   * FIXME:
   *	Fetch it from the datastore.
   */
  ping_interval = DEFAULT_SNMPMGR_AGENTX_PING_INTERVAL_SEC;
#endif /* THE_CONFSYS_ERA */

  if (netsnmp_ds_set_int(NETSNMP_DS_APPLICATION_ID,
                         NETSNMP_DS_AGENT_AGENTX_PING_INTERVAL,
                         (int)ping_interval)
      != SNMPERR_SUCCESS) {
    initialize_ret = LAGOPUS_RESULT_SNMP_API_ERROR;
    return;
  }

  if (init_agent(SNMP_TYPE) != SNMPERR_SUCCESS) {
    initialize_ret = LAGOPUS_RESULT_SNMP_API_ERROR;
    return;
  }

  if ((ret = lagopus_hashmap_create(&iftable_entry_hash,
                                    LAGOPUS_HASHMAP_TYPE_STRING,
                                    delete_entry)) != LAGOPUS_RESULT_OK) {
    lagopus_perror(ret);
    exit(1);
  }

  init_ifTable();
  init_ifNumber();
  init_dot1dBaseBridgeAddress();
  init_dot1dBaseNumPorts();
  init_dot1dBasePortTable();
  init_dot1dBaseType();

  if (is_thread == false) {
    initialize_ret = LAGOPUS_RESULT_OK;
  } else {
    keep_running = true;
    initialize_ret = lagopus_thread_create(&snmpmgr,
                                           snmpmgr_thread_loop,
                                           snmpmgr_thread_finally_called,
                                           NULL,
                                           "snmpmgr",
                                           NULL);
  }

  lagopus_msg_info("SNMP manager initialized.\n");
}
コード例 #10
0
ファイル: flow_cmd.c プロジェクト: tidatida/lagopus
static inline lagopus_result_t
initialize_internal(void) {
  lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES;
  datastore_interp_t s_interp = datastore_get_master_interp();

  /* create hashmap for sub cmds. */
  if ((ret = lagopus_hashmap_create(&sub_cmd_table,
                                    LAGOPUS_HASHMAP_TYPE_STRING,
                                    NULL)) != LAGOPUS_RESULT_OK) {
    lagopus_perror(ret);
    goto done;
  }

  if (((ret = sub_cmd_add(ADD_SUB_CMD,
                          add_sub_cmd_parse,
                          &sub_cmd_table)) !=
       LAGOPUS_RESULT_OK) ||
      ((ret = sub_cmd_add(MOD_SUB_CMD,
                          mod_sub_cmd_parse,
                          &sub_cmd_table)) !=
       LAGOPUS_RESULT_OK) ||
      ((ret = sub_cmd_add(DEL_SUB_CMD,
                          del_sub_cmd_parse,
                          &sub_cmd_table)) !=
       LAGOPUS_RESULT_OK)) {
    goto done;
  }

  /* create hashmap for sub cmds (not name). */
  if ((ret = lagopus_hashmap_create(&sub_cmd_not_name_table,
                                    LAGOPUS_HASHMAP_TYPE_STRING,
                                    NULL)) != LAGOPUS_RESULT_OK) {
    lagopus_perror(ret);
    goto done;
  }

  if (((ret = sub_cmd_add(CONFIG_SUB_CMD, config_sub_cmd_parse,
                          &sub_cmd_not_name_table)) !=
       LAGOPUS_RESULT_OK)) {
    goto done;
  }

  /* create hashmap for dump opts. */
  if ((ret = lagopus_hashmap_create(&dump_opt_table,
                                    LAGOPUS_HASHMAP_TYPE_STRING,
                                    NULL)) != LAGOPUS_RESULT_OK) {
    lagopus_perror(ret);
    goto done;
  }

  if (((ret = opt_add(opt_strs[OPT_TABLE_ID], table_id_opt_parse,
                     &dump_opt_table)) !=
       LAGOPUS_RESULT_OK) ||
      ((ret = opt_add(opt_strs[OPT_WITH_STATS], with_stats_opt_parse,
                      &dump_opt_table)) !=
       LAGOPUS_RESULT_OK)) {
    goto done;
  }

  /* create hashmap for config opts. */
  if ((ret = lagopus_hashmap_create(&config_opt_table,
                                    LAGOPUS_HASHMAP_TYPE_STRING,
                                    NULL)) != LAGOPUS_RESULT_OK) {
    lagopus_perror(ret);
    goto done;
  }

  if ((ret = opt_add(opt_strs[OPT_TMP_DIR], tmp_dir_opt_parse,
                     &config_opt_table)) !=
      LAGOPUS_RESULT_OK) {
    goto done;
  }

  if ((ret = flow_cmd_mod_initialize()) !=
      LAGOPUS_RESULT_OK) {
    goto done;
  }

  if ((ret = datastore_interp_register_command(&s_interp, CONFIGURATOR_NAME,
             CMD_NAME, flow_cmd_parse)) !=
      LAGOPUS_RESULT_OK) {
    lagopus_perror(ret);
    goto done;
  }

  if ((ret = flow_cmd_dump_initialize()) != LAGOPUS_RESULT_OK) {
    goto done;
  }

done:
  return ret;
}
コード例 #11
0
ファイル: numa.c プロジェクト: roccen/lagopus
static inline void
s_init_numa_thingies(void) {
  numa_set_strict(1);

  s_n_cpus = (int64_t)sysconf(_SC_NPROCESSORS_CONF);
  if (s_n_cpus > 0) {
    s_numa_nodes = (unsigned int *)malloc(sizeof(int) * (size_t)s_n_cpus);
    if (s_numa_nodes != NULL) {
      int i;
      lagopus_result_t r;

      (void)memset((void *)s_numa_nodes, 0, sizeof(int) * (size_t)s_n_cpus);

      for (i = 0; i < (int)s_n_cpus; i++) {
        s_numa_nodes[i] = (unsigned int)numa_node_of_cpu(i);
        if (s_min_numa_node > s_numa_nodes[i]) {
          s_min_numa_node = s_numa_nodes[i];
        }
        if (s_max_numa_node < s_numa_nodes[i]) {
          s_max_numa_node = s_numa_nodes[i];
        }
      }

#ifndef DO_NUMA_EVNE_ONE_NODE
      if (s_max_numa_node > s_min_numa_node) {
        r = lagopus_hashmap_create(&s_tbl,
                                   LAGOPUS_HASHMAP_TYPE_ONE_WORD, NULL);
        if (r == LAGOPUS_RESULT_OK) {
          s_is_numa = true;

          s_alloc_proc = s_numa_alloc;
          s_free_proc = s_numa_free;
          
          lagopus_msg_debug(5, "The NUMA aware memory allocator is "
                            "initialized.\n");
        } else {
          lagopus_perror(r);
          lagopus_exit_fatal("can't initialize the "
                             "NUMA memory allocation table.\n");
        }
      } else {
        s_alloc_proc = s_uma_alloc;
        s_free_proc = s_uma_free;

        lagopus_msg_debug(5, "There is only one NUMA node on this machine. "
                          "No NUMA aware memory allocation is enabled.\n");
      }
#else
      r = lagopus_hashmap_create(&s_tbl,
                                 LAGOPUS_HASHMAP_TYPE_ONE_WORD, NULL);
      if (r == LAGOPUS_RESULT_OK) {
        s_is_numa = true;

        s_alloc_proc = s_numa_alloc;
        s_free_proc = s_numa_free;
          
        lagopus_msg_debug(5, "The NUMA aware memory allocator is "
                          "initialized.\n");
      } else {
        lagopus_perror(r);
        lagopus_exit_fatal("can't initialize the "
                           "NUMA memory allocation table.\n");
      }
#endif /* ! DO_NUMA_EVNE_ONE_NODE */
    }
  }
}