test_tle_udp_stream.h revision a152c68e
1/*
2 * Copyright (c) 2016  Intel Corporation.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#ifndef TEST_TLE_UDP_STREAM_H_
17#define TEST_TLE_UDP_STREAM_H_
18#include <iostream>
19#include <arpa/inet.h>
20#include <gtest/gtest.h>
21#include <gmock/gmock.h>
22#include <rte_errno.h>
23
24#include <tle_udp_impl.h>
25#include <tle_event.h>
26
27struct tle_udp_ctx_param ctx_prm_tmpl = {
28	.socket_id = SOCKET_ID_ANY,
29	.max_streams = 0x10,
30	.max_stream_rbufs = 0x100,
31	.max_stream_sbufs = 0x100
32};
33
34struct tle_udp_dev_param dev_prm_tmpl = {
35	.rx_offload = 0x100,
36	.tx_offload = 0x100
37};
38
39class test_tle_udp_stream: public ::testing::Test {
40public:
41	void setup_dev_prm(struct tle_udp_dev_param *,
42			char const *, char const *);
43	struct tle_udp_ctx *setup_ctx(struct tle_udp_ctx_param *prm);
44	struct tle_udp_dev *setup_dev(struct tle_udp_ctx *ctx,
45			struct tle_udp_dev_param *dev_prm);
46	struct tle_evq *setup_event();
47
48	virtual void SetUp(void)
49	{
50		char const *ipv4_laddr = "192.168.0.1";
51		char const *ipv4_raddr = "192.168.0.2";
52		char const *ipv6 = "fe80::21e:67ff:fec2:2568";
53
54		ctx = nullptr;
55		dev = nullptr;
56		stream = nullptr;
57		/* Setup Context */
58		ctx = setup_ctx(&ctx_prm_tmpl);
59		/* Setup Dev */
60		memset(&dev_prm, 0, sizeof(dev_prm));
61		setup_dev_prm(&dev_prm, ipv4_laddr, ipv6);
62		dev = setup_dev(ctx, &dev_prm);
63
64		/* Stream Param & Event param */
65		memset(&stream_prm, 0, sizeof(struct tle_udp_stream_param));
66		inet_pton(AF_INET, ipv4_laddr, &stream_prm.local_addr);
67		inet_pton(AF_INET, ipv4_raddr, &stream_prm.remote_addr);
68		stream_prm.local_addr.ss_family = AF_INET;
69		stream_prm.remote_addr.ss_family = AF_INET;
70		stream_prm.recv_ev = tle_event_alloc(setup_event(), nullptr);
71		stream_prm.send_ev = tle_event_alloc(setup_event(), nullptr);
72	}
73
74	virtual void TearDown(void)
75	{
76		ret = 0;
77		tle_udp_stream_close(stream);
78		tle_udp_del_dev(dev);
79		tle_udp_destroy(ctx);
80	}
81
82	int ret;
83	struct tle_udp_ctx *ctx;
84	struct tle_udp_dev *dev;
85	struct tle_udp_stream *stream;
86
87	struct tle_udp_ctx_param ctx_prm;
88	struct tle_udp_dev_param dev_prm;
89	struct tle_udp_stream_param stream_prm;
90};
91
92struct tle_evq *test_tle_udp_stream::setup_event() {
93	int32_t socket_id;
94	uint32_t max_events;
95	struct tle_evq_param evq_params;
96	struct tle_evq *evq;
97
98	socket_id = SOCKET_ID_ANY;
99	max_events = 10;
100	rte_errno = 0;
101	memset(&evq_params, 0, sizeof(struct tle_evq_param));
102	evq_params.socket_id = socket_id;
103	evq_params.max_events = max_events;
104	evq = tle_evq_create(&evq_params);
105	return evq;
106}
107
108struct tle_udp_ctx
109*test_tle_udp_stream::setup_ctx(struct tle_udp_ctx_param *prm) {
110	struct tle_udp_ctx *ctx;
111
112	ctx = tle_udp_create(prm);
113
114	return ctx;
115}
116
117struct tle_udp_dev
118*test_tle_udp_stream::setup_dev(struct tle_udp_ctx *ctx,
119		struct tle_udp_dev_param *dev_prm) {
120
121	struct tle_udp_dev *dev;
122
123	dev = tle_udp_add_dev(ctx, dev_prm);
124
125	return dev;
126}
127
128void test_tle_udp_stream::setup_dev_prm(struct tle_udp_dev_param *dev_prm,
129		char const *ipv4, char const *ipv6) {
130
131	inet_pton(AF_INET, ipv4, &dev_prm->local_addr4);
132	inet_pton(AF_INET6, ipv6, &dev_prm->local_addr6);
133
134}
135
136#endif /* TEST_TLE_UDP_STREAM_H_ */
137