tcp_stream.h revision 7e18fa1b
1/*
2 * Copyright (c) 2016-2017  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 _TCP_STREAM_H_
17#define _TCP_STREAM_H_
18
19#include <rte_vect.h>
20#include <tle_dring.h>
21#include <tle_tcp.h>
22#include <tle_event.h>
23
24#include "stream.h"
25#include "misc.h"
26#include "tcp_misc.h"
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32enum {
33	TCP_ST_CLOSED,
34	TCP_ST_LISTEN,
35	TCP_ST_SYN_SENT,
36	TCP_ST_SYN_RCVD,
37	TCP_ST_ESTABLISHED,
38	TCP_ST_FIN_WAIT_1,
39	TCP_ST_FIN_WAIT_2,
40	TCP_ST_CLOSE_WAIT,
41	TCP_ST_CLOSING,
42	TCP_ST_LAST_ACK,
43	TCP_ST_TIME_WAIT,
44	TCP_ST_NUM
45};
46
47enum {
48	TCP_OP_LISTEN =  0x1,
49	TCP_OP_ACCEPT =  0x2,
50	TCP_OP_CONNECT = 0x4,
51	TCP_OP_CLOSE =   0x8,
52};
53
54struct tcb {
55	volatile uint16_t state;
56	volatile uint16_t uop; /* operations by user performed */
57	struct {
58		uint32_t nxt;
59		uint32_t irs; /* initial received sequence */
60		uint32_t wnd;
61		uint32_t ts;
62		struct {
63			uint32_t seq;
64			uint32_t on;
65		} frs;
66		uint32_t srtt;   /* smoothed round trip time (scaled by >> 3) */
67		uint32_t rttvar; /* rtt variance */
68		uint16_t mss;
69		uint8_t  wscale;
70		uint8_t  dupack;
71	} rcv;
72	struct {
73		uint64_t nxt;
74		uint64_t una;
75		uint64_t rcvr; /* recover RFC 6582 */
76		uint64_t fss;  /* FIN sequence # */
77		uint32_t fastack; /* # of partial acks in fast retransmit */
78		uint32_t wnd;
79		union wui wu; /* window update */
80		uint32_t ack; /* last sent ack */
81		uint32_t ts;
82		uint32_t cwnd;     /* congestion window */
83		uint32_t ssthresh; /* slow start threshold */
84		uint32_t rto;      /* retransmission timeout */
85		uint32_t rto_tw;   /* TIME_WAIT retransmission timeout */
86		uint32_t iss;      /* initial send sequence */
87		uint16_t mss;
88		uint8_t  wscale;
89		uint8_t nb_retx; /* number of retransmission */
90		uint8_t nb_retm; /**< max number of retx attempts. */
91	} snd;
92	struct syn_opts so; /* initial syn options. */
93};
94
95struct tle_tcp_stream {
96
97	struct tle_stream s;
98
99	uint32_t flags;
100	rte_atomic32_t use;
101
102	struct stbl_entry *ste;     /* entry in streams table. */
103	struct tcb tcb;
104
105	struct {
106		void *handle;
107	} timer;
108
109	struct {
110		struct tle_event *ev;
111		struct tle_stream_cb cb;
112	} err;
113
114	struct {
115		struct rte_ring *q;     /* listen (syn) queue */
116		struct ofo *ofo;
117		struct tle_event *ev;    /* user provided recv event. */
118		struct tle_stream_cb cb; /* user provided recv callback. */
119	} rx __rte_cache_aligned;
120
121	struct {
122		rte_atomic32_t arm;  /* when > 0 stream is in to-send queue */
123		struct {
124			uint32_t nb_elem;  /* number of objects per drb. */
125			uint32_t nb_max;   /* number of drbs per stream. */
126			struct rte_ring *r;
127		} drb;
128		struct rte_ring *q;  /* (re)tx queue */
129		struct tle_event *ev;
130		struct tle_stream_cb cb;
131		struct tle_dest dst;
132	} tx __rte_cache_aligned;
133
134} __rte_cache_aligned;
135
136#define TCP_STREAM(p)	\
137((struct tle_tcp_stream *)((uintptr_t)(p) - offsetof(struct tle_tcp_stream, s)))
138
139#define TCP_STREAM_TX_PENDING(s)	\
140	((s)->tx.drb.nb_max != rte_ring_count((s)->tx.drb.r))
141
142#define TCP_STREAM_TX_FINISHED(s)	\
143	((s)->tx.drb.nb_max == rte_ring_count((s)->tx.drb.r))
144
145#include "stream_table.h"
146
147struct sdr {
148	rte_spinlock_t lock;
149	STAILQ_HEAD(, tle_stream) fe;
150	STAILQ_HEAD(, tle_stream) be;
151};
152
153struct tcp_streams {
154	struct stbl st;
155	struct tle_timer_wheel *tmr; /* timer wheel */
156	struct rte_ring *tsq;        /* to-send streams queue */
157	struct sdr dr;               /* death row for zombie streams */
158	struct tle_tcp_stream s[];   /* array of allocated streams. */
159};
160
161#define CTX_TCP_STREAMS(ctx)	((struct tcp_streams *)(ctx)->streams.buf)
162#define CTX_TCP_STLB(ctx)	(&CTX_TCP_STREAMS(ctx)->st)
163#define CTX_TCP_TMWHL(ctx)	(CTX_TCP_STREAMS(ctx)->tmr)
164#define CTX_TCP_TSQ(ctx)	(CTX_TCP_STREAMS(ctx)->tsq)
165#define CTX_TCP_SDR(ctx)	(&CTX_TCP_STREAMS(ctx)->dr)
166
167#ifdef __cplusplus
168}
169#endif
170
171#endif /* _TCP_STREAM_H_ */
172