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_STARTING, /* Session is starting */ 25 STATE_ONGOING, /* 1st packet has been received, last packet not yet */ 26 STATE_LAST_PACKET_RECEIVED, /* Last packet has been received */ 27 STATE_COMPLETED /* Session completed, stats pkt can be sent if needed */ 28 }; 29 30 struct session { 31 int id; 32 33 /* Tuple for UDP */ 34 uint16_t port; 35 struct net_addr ip; 36 37 enum state state; 38 enum session_proto proto; 39 40 /* Stat data */ 41 uint32_t counter; 42 uint32_t next_id; 43 uint32_t outorder; 44 uint32_t error; 45 uint64_t length; 46 int64_t start_time; 47 uint32_t last_time; 48 int32_t jitter; 49 int32_t last_transit_time; 50 51 /* Stats packet*/ 52 struct zperf_server_hdr stat; 53 54 #ifdef CONFIG_ZPERF_SESSION_PER_THREAD 55 struct zperf_results result; 56 struct zperf_async_upload_context async_upload_ctx; 57 struct zperf_work *zperf; 58 bool in_progress; /* is this session finished or not */ 59 bool wait_for_start; /* wait until the user starts the sessions */ 60 #endif /* CONFIG_ZPERF_SESSION_PER_THREAD */ 61 }; 62 63 typedef void (*session_cb_t)(struct session *ses, enum session_proto proto, 64 void *user_data); 65 66 struct session *get_session(const struct sockaddr *addr, 67 enum session_proto proto); 68 struct session *get_free_session(const struct sockaddr *addr, 69 enum session_proto proto); 70 void zperf_session_init(void); 71 void zperf_reset_session_stats(struct session *session); 72 /* Reset all sessions for a given protocol. */ 73 void zperf_session_reset(enum session_proto proto); 74 void zperf_session_foreach(enum session_proto proto, session_cb_t cb, 75 void *user_data); 76 77 #endif /* __ZPERF_SESSION_H */ 78