Esempio n. 1
0
static int dpdk_stats_config(oconfig_item_t *ci) {
  DPDK_STATS_TRACE();

  int ret = dpdk_stats_preinit();
  if (ret)
    return ret;

  dpdk_stats_ctx_t *ctx = DPDK_STATS_CTX_GET(g_hc);

  for (int i = 0; i < ci->children_num; i++) {
    oconfig_item_t *child = ci->children + i;

    if ((strcasecmp("EnabledPortMask", child->key) == 0) &&
        (child->values[0].type == OCONFIG_TYPE_NUMBER)) {
      ctx->config.enabled_port_mask = child->values[0].value.number;
      DEBUG("%s: Enabled Port Mask 0x%X", DPDK_STATS_PLUGIN,
            ctx->config.enabled_port_mask);
    } else if (strcasecmp("SharedMemObj", child->key) == 0) {
      cf_util_get_string_buffer(child, g_shm_name, sizeof(g_shm_name));
      DEBUG("%s: Shared memory object %s", DPDK_STATS_PLUGIN, g_shm_name);
      dpdk_stats_reinit_helper();
    } else if (strcasecmp("EAL", child->key) == 0) {
      ret = dpdk_helper_eal_config_parse(g_hc, child);
      if (ret)
        return ret;
    }
  }

  int port_num = 0;

  /* parse port names after EnabledPortMask was parsed */
  for (int i = 0; i < ci->children_num; i++) {
    oconfig_item_t *child = ci->children + i;

    if (strcasecmp("PortName", child->key) == 0) {

      while (!(ctx->config.enabled_port_mask & (1 << port_num)))
        port_num++;

      cf_util_get_string_buffer(child, ctx->config.port_name[port_num],
                                sizeof(ctx->config.port_name[port_num]));
      DEBUG("%s: Port %d Name: %s", DPDK_STATS_PLUGIN, port_num,
            ctx->config.port_name[port_num]);

      port_num++;
    }
  }

  return ret;
}
Esempio n. 2
0
static int dpdk_stats_config(oconfig_item_t *ci) {
  DPDK_STATS_TRACE();

  int ret = dpdk_stats_preinit();
  if (ret) {
    g_state = DPDK_STAT_STATE_CFG_ERR;
    return 0;
  }

  dpdk_stats_ctx_t *ctx = DPDK_STATS_CTX_GET(g_hc);

  for (int i = 0; i < ci->children_num; i++) {
    oconfig_item_t *child = ci->children + i;

    if (strcasecmp("EnabledPortMask", child->key) == 0)
      ret = cf_util_get_int(child, (int *)&ctx->config.enabled_port_mask);
    else if (strcasecmp("SharedMemObj", child->key) == 0) {
      ret = cf_util_get_string_buffer(child, g_shm_name, sizeof(g_shm_name));
      if (ret == 0)
        ret = dpdk_stats_reinit_helper();
    } else if (strcasecmp("EAL", child->key) == 0)
      ret = dpdk_helper_eal_config_parse(g_hc, child);
    else if (strcasecmp("PortName", child->key) != 0) {
      ERROR(DPDK_STATS_PLUGIN ": unrecognized configuration option %s",
            child->key);
      ret = -1;
    }

    if (ret != 0) {
      g_state = DPDK_STAT_STATE_CFG_ERR;
      return 0;
    }
  }

  DEBUG(DPDK_STATS_PLUGIN ": Enabled Port Mask 0x%X",
        ctx->config.enabled_port_mask);
  DEBUG(DPDK_STATS_PLUGIN ": Shared memory object %s", g_shm_name);

  int port_num = 0;

  /* parse port names after EnabledPortMask was parsed */
  for (int i = 0; i < ci->children_num; i++) {
    oconfig_item_t *child = ci->children + i;

    if (strcasecmp("PortName", child->key) == 0) {

      while (!(ctx->config.enabled_port_mask & (1 << port_num)))
        port_num++;

      if (cf_util_get_string_buffer(child, ctx->config.port_name[port_num],
                                    sizeof(ctx->config.port_name[port_num]))) {
        g_state = DPDK_STAT_STATE_CFG_ERR;
        return 0;
      }

      DEBUG(DPDK_STATS_PLUGIN ": Port %d Name: %s", port_num,
            ctx->config.port_name[port_num]);

      port_num++;
    }
  }

  return 0;
}
Esempio n. 3
0
static int dpdk_events_config(oconfig_item_t *ci) {
  DPDK_EVENTS_TRACE();
  int ret = dpdk_events_preinit();
  if (ret) {
    g_state |= DPDK_EVENTS_STATE_CFG_ERR;
    return 0;
  }

  dpdk_events_ctx_t *ec = DPDK_EVENTS_CTX_GET(g_hc);

  /* Disabling link_status and keep_alive since <Plugin/> config section
   * specifies if those should be enabled */
  ec->config.keep_alive.enabled = ec->config.link_status.enabled = 0;
  memset(&ec->config.keep_alive.lcore_mask, 0,
         sizeof(ec->config.keep_alive.lcore_mask));

  for (int i = 0; i < ci->children_num; i++) {
    oconfig_item_t *child = ci->children + i;

    if (strcasecmp("EAL", child->key) == 0)
      ret = dpdk_helper_eal_config_parse(g_hc, child);
    else if (strcasecmp("Event", child->key) == 0) {
      char event_type[DATA_MAX_NAME_LEN];

      if (cf_util_get_string_buffer(child, event_type, sizeof(event_type)))
        ret = -1;
      else if (strcasecmp(event_type, "link_status") == 0) {
        ret = dpdk_events_link_status_config(ec, child);
        if (ret) {
          g_state |= DPDK_EVENTS_STATE_LS_CFG_ERR;
          continue;
        }
      } else if (strcasecmp(event_type, "keep_alive") == 0) {
        ret = dpdk_events_keep_alive_config(ec, child);
        if (ret) {
          g_state |= DPDK_EVENTS_STATE_KA_CFG_ERR;
          continue;
        }
      } else {
        ERROR(DPDK_EVENTS_PLUGIN ": The selected event \"%s\" is unknown.",
              event_type);
        ret = -1;
      }
    } else {
      ERROR(DPDK_EVENTS_PLUGIN ": unrecognized configuration option %s.",
            child->key);
      ret = -1;
    }

    if (ret != 0) {
      g_state |= DPDK_EVENTS_STATE_CFG_ERR;
      return 0;
    }
  }

  if (g_state & DPDK_EVENTS_STATE_KA_CFG_ERR) {
    ERROR(DPDK_EVENTS_PLUGIN
          ": Invalid keep alive configuration. Event disabled.");
    ec->config.keep_alive.enabled = 0;
  }

  if (g_state & DPDK_EVENTS_STATE_LS_CFG_ERR) {
    ERROR(DPDK_EVENTS_PLUGIN
          ": Invalid link status configuration. Event disabled.");
    ec->config.link_status.enabled = 0;
  }

  if (!ec->config.keep_alive.enabled && !ec->config.link_status.enabled) {
    ERROR(DPDK_EVENTS_PLUGIN ": At least one type of events should be "
                             "configured for collecting. Plugin misconfigured");
    g_state |= DPDK_EVENTS_STATE_CFG_ERR;
    return 0;
  }

  return 0;
}