Exemple #1
0
static int
test_of_list_packet_queue_OF_VERSION_1_0(void)
{
    of_list_packet_queue_t *list;
    int value = 1;

    list = of_list_packet_queue_new(OF_VERSION_1_0);
    TEST_ASSERT(list != NULL);
    TEST_ASSERT(list->version == OF_VERSION_1_0);
    TEST_ASSERT(list->length == 0);
    TEST_ASSERT(list->parent == NULL);
    TEST_ASSERT(list->object_id == OF_LIST_PACKET_QUEUE);

    value = list_setup_of_list_packet_queue_OF_VERSION_1_0(list, value);
    TEST_ASSERT(value != 0);

    /* Now check values */
    value = 1;
    value = list_check_of_list_packet_queue_OF_VERSION_1_0(list, value);
    TEST_ASSERT(value != 0);

    of_list_packet_queue_delete(list);

    return TEST_PASS;
}
Exemple #2
0
indigo_error_t indigo_port_queue_config_get(of_queue_get_config_request_t *queue_config_request,
                                            of_queue_get_config_reply_t **queue_config_reply)
{
  of_queue_get_config_reply_t *reply;
  indigo_error_t err = INDIGO_ERROR_NONE;
  OFDPA_ERROR_t ofdpa_rv = OFDPA_E_NONE;
  of_port_no_t req_of_port_num;
  of_packet_queue_t *of_packet_queue;
  of_list_packet_queue_t *of_list_packet_queue;

  uint32_t queueId = 0;
  uint32_t numQueues = 0;
  uint32_t dump_all = 0;
  uint32_t port;

  LOG_TRACE("%s called", __FUNCTION__);

  if (queue_config_request->version < OF_VERSION_1_3)
  {
    LOG_ERROR("Unsupported OpenFlow version 0x%x.", queue_config_request->version);
    return INDIGO_ERROR_VERSION;
  }

  /* Allocate memory for reply.
   * NOTE: This memory is freed by the caller of
   *       indigo_port_queue_config_get()  */
  reply = of_queue_get_config_reply_new(queue_config_request->version);
  if (reply == NULL)
  {
    LOG_ERROR("Could not allocate queue config reply");
    return INDIGO_ERROR_RESOURCE;
  }

  *queue_config_reply = reply;

  of_packet_queue = of_packet_queue_new(queue_config_request->version);
  if (of_packet_queue == NULL)
  {
    LOG_ERROR("Failed to allocate memory for of_packet_queue.");
    of_queue_get_config_reply_delete(*queue_config_reply);
    return INDIGO_ERROR_RESOURCE;
  }

  /* Allocate the memory for the packet_queue struct */
  of_list_packet_queue = of_list_packet_queue_new(queue_config_request->version);
  if (of_list_packet_queue == NULL)
  {
    LOG_ERROR("Failed to allocate memory for of_list_packet_queue.");
    of_packet_queue_delete(of_packet_queue);
    of_queue_get_config_reply_delete(*queue_config_reply);
    return INDIGO_ERROR_RESOURCE;
  }

  of_queue_get_config_reply_queues_bind(*queue_config_reply, of_list_packet_queue);

  /* Get the port from request */
  of_queue_get_config_request_port_get(queue_config_request, &req_of_port_num);

  /* Check if the port is OFPP_ANY */
  if (req_of_port_num == OF_PORT_DEST_WILDCARD_BY_VERSION(queue_config_request->version))
  {
    ofdpa_rv = ofdpaPortNextGet(0, &port);
    if (ofdpa_rv != OFDPA_E_NONE)
    {
      LOG_ERROR("Error geting first port. (ofdpa_rv = %d)", ofdpa_rv);
    }
    err = indigoConvertOfdpaRv(ofdpa_rv);
    dump_all = 1;
  }
  else
  {
    port = req_of_port_num;
  }

  if (err == INDIGO_ERROR_NONE)
  {
    do
    {
      of_queue_get_config_reply_port_set(*queue_config_reply, port);
      /* Set the of_packet_queue struct elements */
      ofdpa_rv = ofdpaNumQueuesGet(port, &numQueues);
      if (ofdpa_rv != OFDPA_E_NONE)
      {
        LOG_ERROR("Error getting maximum queues supported on port %d. (ofdpa_rv = %d)", port, ofdpa_rv);
        err = indigoConvertOfdpaRv(ofdpa_rv);
        break;
      }
      for (queueId = 0; queueId < numQueues; queueId++)
      {
        err = ind_ofdpa_queue_config_queue_set(of_packet_queue, port, queueId);
        if (err != INDIGO_ERROR_NONE)
        {
          LOG_ERROR("Error setting of_packet_queue. (err = %d)", err);
          err = indigoConvertOfdpaRv(ofdpa_rv);
          break;
        }

        of_list_packet_queue_append(of_list_packet_queue, of_packet_queue);
      }

      if (!dump_all)
      {
        break;
      }
    }while((ofdpaPortNextGet(port, &port) == OFDPA_E_NONE) && (err == INDIGO_ERROR_NONE));
  }

  of_packet_queue_delete(of_packet_queue);
  of_list_packet_queue_delete(of_list_packet_queue);

 /* Free the reply message only on failure.
    Reply message is freed by the caller on success */
  if (err != INDIGO_ERROR_NONE)
  {
    of_queue_get_config_reply_delete(*queue_config_reply);
    *queue_config_reply = NULL;
  }

  return err;
}