1 /*
2  * Copyright (c) 2015 Intel Corporation
3  * Copyright (c) 2023 Arm Limited (or its affiliates). All rights reserved.
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 #ifndef __ZPERF_SESSION_H
8 #define __ZPERF_SESSION_H
9 
10 #include <zephyr/linker/sections.h>
11 #include <zephyr/toolchain.h>
12 
13 #include <zephyr/kernel.h>
14 #include <zephyr/sys/printk.h>
15 
16 #include <zephyr/net/net_ip.h>
17 #include <zephyr/net/net_core.h>
18 
19 #include "zperf_internal.h"
20 
21 /* Type definition */
22 enum state {
23 	STATE_NULL, /* Session has not yet started */
24 	STATE_ONGOING, /* 1st packet has been received, last packet not yet */
25 	STATE_LAST_PACKET_RECEIVED, /* Last packet has been received */
26 	STATE_COMPLETED /* Session completed, stats pkt can be sent if needed */
27 };
28 
29 enum session_proto {
30 	SESSION_UDP = 0,
31 	SESSION_TCP = 1,
32 	SESSION_PROTO_END
33 };
34 
35 struct session {
36 	/* Tuple for UDP */
37 	uint16_t port;
38 	struct net_addr ip;
39 
40 	enum state state;
41 
42 	/* Stat data */
43 	uint32_t counter;
44 	uint32_t next_id;
45 	uint32_t outorder;
46 	uint32_t error;
47 	uint64_t length;
48 	int64_t start_time;
49 	uint32_t last_time;
50 	int32_t jitter;
51 	int32_t last_transit_time;
52 
53 	/* Stats packet*/
54 	struct zperf_server_hdr stat;
55 };
56 
57 struct session *get_session(const struct sockaddr *addr,
58 			    enum session_proto proto);
59 void zperf_session_init(void);
60 void zperf_reset_session_stats(struct session *session);
61 /* Reset all sessions for a given protocol. */
62 void zperf_session_reset(enum session_proto proto);
63 
64 #endif /* __ZPERF_SESSION_H */
65