void classification_test_cos_set_queue(void)
{
	int retval;
	char cosname[ODP_COS_NAME_LEN];
	odp_cls_cos_param_t cls_param;
	odp_pool_t pool;
	odp_queue_t queue;
	odp_queue_t queue_cos;
	odp_cos_t cos_queue;
	odp_queue_t recvqueue;

	pool = pool_create("cls_basic_pool");
	CU_ASSERT_FATAL(pool != ODP_POOL_INVALID);

	queue = queue_create("cls_basic_queue", true);
	CU_ASSERT_FATAL(queue != ODP_QUEUE_INVALID);

	sprintf(cosname, "CoSQueue");
	odp_cls_cos_param_init(&cls_param);
	cls_param.pool = pool;
	cls_param.queue = queue;
	cls_param.drop_policy = ODP_COS_DROP_POOL;
	cos_queue = odp_cls_cos_create(cosname, &cls_param);
	CU_ASSERT_FATAL(cos_queue != ODP_COS_INVALID);

	queue_cos = queue_create("QueueCoS", true);
	CU_ASSERT_FATAL(queue_cos != ODP_QUEUE_INVALID);

	retval = odp_cos_queue_set(cos_queue, queue_cos);
	CU_ASSERT(retval == 0);
	recvqueue = odp_cos_queue(cos_queue);
	CU_ASSERT(recvqueue == queue_cos);

	odp_cos_destroy(cos_queue);
	odp_queue_destroy(queue_cos);
	odp_queue_destroy(queue);
	odp_pool_destroy(pool);
}
示例#2
0
static odp_cos_t build_cos_w_queue(const char *name)
{
	odp_cos_t cos;
	odp_queue_t queue_cos;
	odp_queue_param_t qparam;

	cos = odp_cos_create(name);
	if (cos == ODP_COS_INVALID) {
		OFP_ERR("Failed to create COS");
		return ODP_COS_INVALID;
	}

	memset(&qparam, 0, sizeof(odp_queue_param_t));
	qparam.sched.prio  = ODP_SCHED_PRIO_DEFAULT;
	qparam.sched.sync  = ODP_SCHED_SYNC_ATOMIC;
	qparam.sched.group = ODP_SCHED_GROUP_ALL;

	queue_cos = odp_queue_create(name,
				ODP_QUEUE_TYPE_SCHED,
				&qparam);
	if (queue_cos == ODP_QUEUE_INVALID) {
		OFP_ERR("Failed to create queue\n");
		odp_cos_destroy(cos);
		return ODP_COS_INVALID;
	}

#if ODP_VERSION < 104
	if (odp_cos_set_queue(cos, queue_cos) < 0) {
#else
	if (odp_cos_queue_set(cos, queue_cos) < 0) {
#endif
		OFP_ERR("Failed to set queue on COS");
		odp_cos_destroy(cos);
		odp_queue_destroy(queue_cos);
		return ODP_COS_INVALID;
	}

	return cos;
}

static odp_cos_t build_cos_set_queue(const char *name, odp_queue_t queue_cos)
{
	odp_cos_t cos;

	cos = odp_cos_create(name);
	if (cos == ODP_COS_INVALID) {
		OFP_ERR("Failed to create COS");
		return ODP_COS_INVALID;
	}

#if ODP_VERSION < 104
	if (odp_cos_set_queue(cos, queue_cos) < 0) {
#else
	if (odp_cos_queue_set(cos, queue_cos) < 0) {
#endif
		OFP_ERR("Failed to set queue on COS");
		odp_cos_destroy(cos);
		return ODP_COS_INVALID;
	}

	return cos;
}

static odp_pmr_t build_udp_prm(void)
{
	uint32_t pmr_udp_val = TEST_PORT;
	uint32_t pmr_udp_mask = 0xffffffff;

#if ODP_VERSION < 104
	return odp_pmr_create(ODP_PMR_UDP_DPORT,
			      &pmr_udp_val,
			      &pmr_udp_mask,
			      1);
#else
	const odp_pmr_match_t match = {
		.term = ODP_PMR_UDP_DPORT,
		.val = &pmr_udp_val,
		.mask = &pmr_udp_mask,
		.val_sz = 1
	};

	return odp_pmr_create(&match);
#endif
}

static void app_processing(void)
{
	int fd_rcv = -1;
	char buf[1500];
	int len = sizeof(buf);

	do {
		struct ofp_sockaddr_in addr = {0};

		fd_rcv = ofp_socket(OFP_AF_INET, OFP_SOCK_DGRAM,
				OFP_IPPROTO_UDP);
		if (fd_rcv == -1) {
			OFP_ERR("Faild to create RCV socket (errno = %d)\n",
				ofp_errno);
			break;
		}

		addr.sin_len = sizeof(struct ofp_sockaddr_in);
		addr.sin_family = OFP_AF_INET;
		addr.sin_port = odp_cpu_to_be_16(TEST_PORT);
		addr.sin_addr.s_addr = IP4(192, 168, 100, 1);

		if (ofp_bind(fd_rcv, (const struct ofp_sockaddr *)&addr,
			sizeof(struct ofp_sockaddr_in)) == -1) {
			OFP_ERR("Faild to bind socket (errno = %d)\n",
				ofp_errno);
			break;
		}

		len = ofp_recv(fd_rcv, buf, len, 0);
		if (len == -1)
			OFP_ERR("Faild to receive data (errno = %d)\n",
				ofp_errno);
		else
			OFP_INFO("Data received: length = %d.\n", len);

	} while (0);

	if (fd_rcv != -1) {
		ofp_close(fd_rcv);
		fd_rcv = -1;
	}
	OFP_INFO("Test ended.\n");
}