void classification_test_destroy_cos(void)
{
	odp_cos_t cos;
	char name[ODP_COS_NAME_LEN];
	odp_pool_t pool;
	odp_queue_t queue;
	odp_cls_cos_param_t cls_param;
	int retval;

	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(name, "ClassOfService");
	odp_cls_cos_param_init(&cls_param);
	cls_param.pool = pool;
	cls_param.queue = queue;
	cls_param.drop_policy = ODP_COS_DROP_POOL;

	cos = odp_cls_cos_create(name, &cls_param);
	CU_ASSERT_FATAL(cos != ODP_COS_INVALID);
	retval = odp_cos_destroy(cos);
	CU_ASSERT(retval == 0);
	retval = odp_cos_destroy(ODP_COS_INVALID);
	CU_ASSERT(retval < 0);

	odp_pool_destroy(pool);
	odp_queue_destroy(queue);
}
static void classification_test_destroy_cos(void)
{
	odp_cos_t cos;
	char name[ODP_COS_NAME_LEN];
	int retval;
	sprintf(name, "ClassOfService");
	cos = odp_cos_create(name);
	CU_ASSERT_FATAL(cos != ODP_COS_INVALID);
	retval = odp_cos_destroy(cos);
	CU_ASSERT(retval == 0);
	retval = odp_cos_destroy(ODP_COS_INVALID);
	CU_ASSERT(retval < 0);
}
Beispiel #3
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;
	odp_cls_cos_param_t cos_param;

	odp_queue_param_init(&qparam);
	qparam.type = ODP_QUEUE_TYPE_SCHED;
	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, &qparam);
	if (queue_cos == ODP_QUEUE_INVALID) {
		OFP_ERR("Failed to create queue\n");
		return ODP_COS_INVALID;
	}

	odp_cls_cos_param_init(&cos_param);
	cos_param.queue = queue_cos;
	cos_param.pool = odp_pool_lookup(SHM_PKT_POOL_NAME);
	cos = odp_cls_cos_create(name, &cos_param);
	if (cos == ODP_COS_INVALID) {
		OFP_ERR("Failed to create COS");
		odp_cos_destroy(cos);
		odp_queue_destroy(queue_cos);
		return ODP_COS_INVALID;
	}

	return cos;
}
void classification_test_cos_set_drop(void)
{
	int retval;
	char cosname[ODP_COS_NAME_LEN];
	odp_cos_t cos_drop;
	odp_queue_t queue;
	odp_pool_t pool;
	odp_cls_cos_param_t cls_param;

	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, "CoSDrop");
	odp_cls_cos_param_init(&cls_param);
	cls_param.pool = pool;
	cls_param.queue = queue;
	cls_param.drop_policy = ODP_COS_DROP_POOL;
	cos_drop = odp_cls_cos_create(cosname, &cls_param);
	CU_ASSERT_FATAL(cos_drop != ODP_COS_INVALID);

	retval = odp_cos_drop_set(cos_drop, ODP_COS_DROP_POOL);
	CU_ASSERT(retval == 0);
	retval = odp_cos_drop_set(cos_drop, ODP_COS_DROP_NEVER);
	CU_ASSERT(retval == 0);
	odp_cos_destroy(cos_drop);
	odp_pool_destroy(pool);
	odp_queue_destroy(queue);
}
int classification_suite_term(void)
{
	int i;
	int retcode = 0;

	if (0 >	destroy_inq(pktio_loop)) {
		fprintf(stderr, "destroy pktio inq failed.\n");
		retcode = -1;
	}

	if (0 > odp_pktio_close(pktio_loop)) {
		fprintf(stderr, "pktio close failed.\n");
		retcode = -1;
	}

	if (0 != odp_pool_destroy(pool_default)) {
		fprintf(stderr, "pool_default destroy failed.\n");
		retcode = -1;
	}

	for (i = 0; i < CLS_ENTRIES; i++)
		odp_cos_destroy(cos_list[i]);

	for (i = 0; i < CLS_ENTRIES; i++)
		odp_pmr_destroy(pmr_list[i]);

	for (i = 0; i < CLS_ENTRIES; i++)
		odp_queue_destroy(queue_list[i]);

	return retcode;
}
static void classification_test_create_cos(void)
{
	odp_cos_t cos;
	char name[ODP_COS_NAME_LEN];
	sprintf(name, "ClassOfService");
	cos = odp_cos_create(name);
	CU_ASSERT_FATAL(cos != ODP_COS_INVALID);
	CU_ASSERT(odp_cos_to_u64(cos) != odp_cos_to_u64(ODP_COS_INVALID));
	odp_cos_destroy(cos);
}
static void classification_test_cos_set_drop(void)
{
	int retval;
	char cosname[ODP_COS_NAME_LEN];
	sprintf(cosname, "CoSDrop");
	odp_cos_t cos_drop;
	cos_drop = odp_cos_create(cosname);
	CU_ASSERT_FATAL(cos_drop != ODP_COS_INVALID);

	retval = odp_cos_set_drop(cos_drop, ODP_COS_DROP_POOL);
	CU_ASSERT(retval == 0);
	retval = odp_cos_set_drop(cos_drop, ODP_COS_DROP_NEVER);
	CU_ASSERT(retval == 0);
	odp_cos_destroy(cos_drop);
}
static void classification_test_cos_set_queue(void)
{
	int retval;
	char cosname[ODP_COS_NAME_LEN];
	char queuename[ODP_QUEUE_NAME_LEN];
	odp_queue_param_t qparam;
	odp_queue_t queue_cos;
	odp_cos_t cos_queue;
	sprintf(cosname, "CoSQueue");
	cos_queue = odp_cos_create(cosname);
	CU_ASSERT_FATAL(cos_queue != ODP_COS_INVALID);

	qparam.sched.prio = ODP_SCHED_PRIO_HIGHEST;
	qparam.sched.sync = ODP_SCHED_SYNC_NONE;
	qparam.sched.group = ODP_SCHED_GROUP_ALL;
	sprintf(queuename, "%s", "QueueCoS");

	queue_cos = odp_queue_create(queuename,
				     ODP_QUEUE_TYPE_SCHED, &qparam);
	retval = odp_cos_set_queue(cos_queue, queue_cos);
	CU_ASSERT(retval == 0);
	odp_cos_destroy(cos_queue);
	odp_queue_destroy(queue_cos);
}
Beispiel #9
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");
}