blob: 1ed6e0b9eec09ff6732ba30f20a622b398fdc40f [file] [log] [blame]
Florin Coras04e53442017-07-16 17:12:15 -07001/*
2 * Copyright (c) 2017 Cisco and/or its affiliates.
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 SRC_VNET_SESSION_STREAM_SESSION_H_
17#define SRC_VNET_SESSION_STREAM_SESSION_H_
18
19#include <vnet/vnet.h>
20#include <svm/svm_fifo.h>
Florin Corascea194d2017-10-02 00:18:51 -070021#include <vnet/session/transport.h>
Florin Coras04e53442017-07-16 17:12:15 -070022
23#define foreach_session_type \
24 _(IP4_TCP, ip4_tcp) \
25 _(IP4_UDP, ip4_udp) \
26 _(IP6_TCP, ip6_tcp) \
27 _(IP6_UDP, ip6_udp)
28
29typedef enum
30{
31#define _(A, a) SESSION_TYPE_##A,
32 foreach_session_type
33#undef _
34 SESSION_N_TYPES,
35} session_type_t;
36
37/*
38 * Application session state
39 */
40typedef enum
41{
42 SESSION_STATE_LISTENING,
43 SESSION_STATE_CONNECTING,
44 SESSION_STATE_ACCEPTING,
45 SESSION_STATE_READY,
46 SESSION_STATE_CLOSED,
47 SESSION_STATE_N_STATES,
48} stream_session_state_t;
49
50typedef struct _stream_session_t
51{
52 /** fifo pointers. Once allocated, these do not move */
53 svm_fifo_t *server_rx_fifo;
54 svm_fifo_t *server_tx_fifo;
55
56 /** Type */
57 u8 session_type;
58
59 /** State */
Florin Coras1f152cd2017-08-18 19:28:03 -070060 volatile u8 session_state;
Florin Coras04e53442017-07-16 17:12:15 -070061
62 u8 thread_index;
63
64 /** To avoid n**2 "one event per frame" check */
65 u8 enqueue_epoch;
66
Florin Coras04e53442017-07-16 17:12:15 -070067 /** svm segment index where fifos were allocated */
68 u32 svm_segment_index;
69
70 /** Session index in per_thread pool */
71 u32 session_index;
72
73 /** Transport specific */
74 u32 connection_index;
75
76 /** stream server pool index */
77 u32 app_index;
78
79 /** Parent listener session if the result of an accept */
80 u32 listener_index;
81
Florin Coras0e9c33b2017-08-14 22:33:41 -070082 CLIB_CACHE_LINE_ALIGN_MARK (pad);
Florin Coras04e53442017-07-16 17:12:15 -070083} stream_session_t;
84
Florin Corascea194d2017-10-02 00:18:51 -070085typedef struct _session_endpoint
86{
87 /*
88 * Network specific
89 */
90#define _(type, name) type name;
91 foreach_transport_connection_fields
92#undef _
93 /*
94 * Session specific
95 */
96 u8 transport_proto; /**< transport protocol for session */
97} session_endpoint_t;
98
99#define SESSION_IP46_ZERO \
100{ \
101 .ip6 = { \
102 { 0, 0, }, \
103 }, \
104}
105#define SESSION_ENDPOINT_NULL \
106{ \
107 .sw_if_index = ENDPOINT_INVALID_INDEX, \
108 .ip = SESSION_IP46_ZERO, \
109 .fib_index = ENDPOINT_INVALID_INDEX, \
110 .is_ip4 = 0, \
111 .port = 0, \
112 .transport_proto = 0, \
113}
114
115#define session_endpoint_to_transport(_sep) ((transport_endpoint_t *)_sep)
116
117always_inline u8
118session_endpoint_fib_proto (session_endpoint_t * sep)
119{
120 return sep->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
121}
122
Florin Coras04e53442017-07-16 17:12:15 -0700123#endif /* SRC_VNET_SESSION_STREAM_SESSION_H_ */
124
125/*
126 * fd.io coding-style-patch-verification: ON
127 *
128 * Local Variables:
129 * eval: (c-set-style "gnu")
130 * End:
131 */