Exemplo n.º 1
0
/* Generated from of10/queue_get_config_reply.data */
static int
test_of10_queue_get_config_reply(void) {
    uint8_t binary[] = {
        0x01, 0x15, 0x00, 0x50, 0x12, 0x34, 0x56, 0x78, 
        0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0x01, 0x00, 0x18, 0x00, 0x00, 
        0x00, 0x01, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0x02, 0x00, 0x28, 0x00, 0x00, 
        0x00, 0x01, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x01, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
        
    };

    of_object_t *obj;

    obj = of_queue_get_config_reply_new(OF_VERSION_1_0);
    of_queue_get_config_reply_port_set(obj, 65534);
    {
        of_object_t list;
        of_queue_get_config_reply_queues_bind(obj, &list);
        {
            of_object_t *obj = of_packet_queue_new(OF_VERSION_1_0);
            {
                of_object_t list;
                of_packet_queue_properties_bind(obj, &list);
                {
                    of_object_t *obj = of_queue_prop_min_rate_new(OF_VERSION_1_0);
                    of_queue_prop_min_rate_rate_set(obj, 5);
                    of_list_append(&list, obj);
                    of_object_delete(obj);
                }
            }
            of_packet_queue_queue_id_set(obj, 1);
            of_list_append(&list, obj);
            of_object_delete(obj);
        }
        {
            of_object_t *obj = of_packet_queue_new(OF_VERSION_1_0);
            {
                of_object_t list;
                of_packet_queue_properties_bind(obj, &list);
                {
                    of_object_t *obj = of_queue_prop_min_rate_new(OF_VERSION_1_0);
                    of_queue_prop_min_rate_rate_set(obj, 6);
                    of_list_append(&list, obj);
                    of_object_delete(obj);
                }
                {
                    of_object_t *obj = of_queue_prop_min_rate_new(OF_VERSION_1_0);
                    of_queue_prop_min_rate_rate_set(obj, 7);
                    of_list_append(&list, obj);
                    of_object_delete(obj);
                }
            }
            of_packet_queue_queue_id_set(obj, 2);
            of_list_append(&list, obj);
            of_object_delete(obj);
        }
    }
    of_queue_get_config_reply_xid_set(obj, 305419896);

    if (sizeof(binary) != WBUF_CURRENT_BYTES(OF_OBJECT_TO_WBUF(obj))
        || memcmp(binary, WBUF_BUF(OF_OBJECT_TO_WBUF(obj)), sizeof(binary))) {
	show_failure(binary, sizeof(binary),
		     WBUF_BUF(OF_OBJECT_TO_WBUF(obj)),
		     WBUF_CURRENT_BYTES(OF_OBJECT_TO_WBUF(obj)));
	of_object_delete(obj);
	return TEST_FAIL;
    }

    of_object_delete(obj);
    return TEST_PASS;
}
Exemplo n.º 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;
}