aboutsummaryrefslogtreecommitdiffstats
path: root/test/gtest/test_tle_udp_stream.h
blob: d0256c31d92d82d15ad15531e781bfb52ccf31d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
 * Copyright (c) 2016  Intel Corporation.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef TEST_TLE_UDP_STREAM_H_
#define TEST_TLE_UDP_STREAM_H_
#include <iostream>
#include <arpa/inet.h>
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include <rte_errno.h>

#include <tle_udp_impl.h>
#include <tle_event.h>

int
dummy_lookup4(void *opaque, const struct in_addr *addr,
	struct tle_udp_dest *res)
{
	RTE_SET_USED(opaque);
	RTE_SET_USED(addr);
	RTE_SET_USED(res);
	return -ENOENT;
}

int
dummy_lookup6(void *opaque, const struct in6_addr *addr,
	struct tle_udp_dest *res)
{
	RTE_SET_USED(opaque);
	RTE_SET_USED(addr);
	RTE_SET_USED(res);
	return -ENOENT;
}

struct tle_udp_ctx_param ctx_prm_tmpl = {
	.socket_id = SOCKET_ID_ANY,
	.max_streams = 0x10,
	.max_stream_rbufs = 0x100,
	.max_stream_sbufs = 0x100
};

struct tle_udp_dev_param dev_prm_tmpl = {
	.rx_offload = 0x100,
	.tx_offload = 0x100
};

class test_tle_udp_stream: public ::testing::Test {
public:
	void setup_dev_prm(struct tle_udp_dev_param *,
			char const *, char const *);
	struct tle_udp_ctx *setup_ctx(struct tle_udp_ctx_param *prm);
	struct tle_udp_dev *setup_dev(struct tle_udp_ctx *ctx,
			struct tle_udp_dev_param *dev_prm);
	struct tle_evq *setup_event();

	virtual void SetUp(void)
	{
		char const *ipv4_laddr = "192.168.0.1";
		char const *ipv4_raddr = "192.168.0.2";
		char const *ipv6 = "fe80::21e:67ff:fec2:2568";
		struct tle_udp_ctx_param cprm;

		ctx = nullptr;
		dev = nullptr;
		stream = nullptr;
		/* Setup Context */
		cprm = ctx_prm_tmpl;
		cprm.lookup4 = dummy_lookup4;
		cprm.lookup6 = dummy_lookup6;
		ctx = setup_ctx(&cprm);
		/* Setup Dev */
		memset(&dev_prm, 0, sizeof(dev_prm));
		setup_dev_prm(&dev_prm, ipv4_laddr, ipv6);
		dev = setup_dev(ctx, &dev_prm);

		/* Stream Param & Event param */
		memset(&stream_prm, 0, sizeof(struct tle_udp_stream_param));
		inet_pton(AF_INET, ipv4_laddr, &stream_prm.local_addr);
		inet_pton(AF_INET, ipv4_raddr, &stream_prm.remote_addr);
		stream_prm.local_addr.ss_family = AF_INET;
		stream_prm.remote_addr.ss_family = AF_INET;
		stream_prm.recv_ev = tle_event_alloc(setup_event(), nullptr);
		stream_prm.send_ev = tle_event_alloc(setup_event(), nullptr);
	}

	virtual void TearDown(void)
	{
		ret = 0;
		tle_udp_stream_close(stream);
		tle_udp_del_dev(dev);
		tle_udp_destroy(ctx);
	}

	int ret;
	struct tle_udp_ctx *ctx;
	struct tle_udp_dev *dev;
	struct tle_udp_stream *stream;

	struct tle_udp_ctx_param ctx_prm;
	struct tle_udp_dev_param dev_prm;
	struct tle_udp_stream_param stream_prm;
};

struct tle_evq *test_tle_udp_stream::setup_event() {
	int32_t socket_id;
	uint32_t max_events;
	struct tle_evq_param evq_params;
	struct tle_evq *evq;

	socket_id = SOCKET_ID_ANY;
	max_events = 10;
	rte_errno = 0;
	memset(&evq_params, 0, sizeof(struct tle_evq_param));
	evq_params.socket_id = socket_id;
	evq_params.max_events = max_events;
	evq = tle_evq_create(&evq_params);
	return evq;
}

struct tle_udp_ctx
*test_tle_udp_stream::setup_ctx(struct tle_udp_ctx_param *prm) {
	struct tle_udp_ctx *ctx;

	ctx = tle_udp_create(prm);

	return ctx;
}

struct tle_udp_dev
*test_tle_udp_stream::setup_dev(struct tle_udp_ctx *ctx,
		struct tle_udp_dev_param *dev_prm) {

	struct tle_udp_dev *dev;

	dev = tle_udp_add_dev(ctx, dev_prm);

	return dev;
}

void test_tle_udp_stream::setup_dev_prm(struct tle_udp_dev_param *dev_prm,
		char const *ipv4, char const *ipv6) {

	inet_pton(AF_INET, ipv4, &dev_prm->local_addr4);
	inet_pton(AF_INET6, ipv6, &dev_prm->local_addr6);

}

#endif /* TEST_TLE_UDP_STREAM_H_ */