QUIC: Initial multi stream support
[vpp.git] / src / plugins / quic / quic.h
1 /*
2  * Copyright (c) 2019 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 __included_quic_h__
17 #define __included_quic_h__
18
19 #include <vnet/session/application_interface.h>
20
21 #include <vppinfra/lock.h>
22 #include <vppinfra/tw_timer_1t_3w_1024sl_ov.h>
23
24 #include <quicly.h>
25 #include <quicly/streambuf.h>
26
27
28 #define QUIC_DEBUG                0
29 #define QUIC_DEBUG_LEVEL_CLIENT   0
30 #define QUIC_DEBUG_LEVEL_SERVER   0
31
32 #define QUIC_DEFAULT_CA_CERT_PATH        "/etc/ssl/certs/ca-certificates.crt"
33
34 #define QUIC_TIMER_HANDLE_INVALID ((u32) ~0)
35
36 #define QUIC_TSTAMP_RESOLUTION  0.001   /* QUIC tick resolution (1ms) */
37
38
39 #if QUIC_DEBUG
40 #define QUIC_DBG(_lvl, _fmt, _args...)           \
41   if (_lvl <= QUIC_DEBUG)                \
42     clib_warning (_fmt, ##_args)
43 #else
44 #define QUIC_DBG(_lvl, _fmt, _args...)
45 #endif
46
47 #define QUIC_CONN_STATE_HANDSHAKE 0
48 #define QUIC_CONN_STATE_READY     1
49
50 enum quic_session_type_t
51 {
52   QUIC_SESSION_TYPE_QUIC = 0,
53   QUIC_SESSION_TYPE_STREAM = 1,
54   QUIC_SESSION_TYPE_LISTEN = INT32_MAX,
55 };
56
57
58 /* *INDENT-OFF* */
59 typedef CLIB_PACKED (struct quic_ctx_id_
60 {
61   u32 parent_app_wrk_id;
62   u32 parent_app_id;
63   union {
64     CLIB_PACKED (struct {
65       session_handle_t quic_session_handle; // TODO: remove
66       session_handle_t udp_session_handle;
67       quicly_conn_t *conn;
68       u32 listener_ctx_id;
69       u8 udp_is_ip4;
70     });
71     CLIB_PACKED (struct {
72       session_handle_t stream_session_handle; // TODO: remove
73       quicly_stream_t *stream;
74       u32 quic_connection_ctx_id;
75     });
76   };
77   u8 is_stream;
78 }) quic_ctx_id_t;
79 /* *INDENT-ON* */
80
81 STATIC_ASSERT (sizeof (quic_ctx_id_t) <= 42, "ctx id must be less than 42");
82
83 // This structure is used to implement the concept of VPP connection for QUIC.
84 // We create one per connection and one per stream.
85 typedef struct quic_ctx_
86 {
87   union
88   {
89     transport_connection_t connection;
90     quic_ctx_id_t c_quic_ctx_id;
91   };
92   u8 *srv_hostname;
93   u32 client_opaque;
94   u32 timer_handle;
95   u8 conn_state;
96   u8 is_listener;
97 } quic_ctx_t;
98
99 typedef struct quic_stream_data_
100 {
101   quicly_streambuf_t streambuf;
102   u32 ctx_id;
103 } quic_stream_data_t;
104
105 typedef struct quic_worker_ctx_
106 {
107   CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
108   u32 time_now;                                 /**< worker time */
109   tw_timer_wheel_1t_3w_1024sl_ov_t timer_wheel;    /**< worker timer wheel */
110 } quic_worker_ctx_t;
111
112 typedef struct quic_main_
113 {
114   u32 app_index;
115   quic_ctx_t **ctx_pool;
116   quic_worker_ctx_t *wrk_ctx;
117   f64 tstamp_ticks_per_clock;
118
119   /*
120    * Config
121    */
122   quicly_context_t quicly_ctx;
123   ptls_handshake_properties_t hs_properties;
124   quicly_cid_plaintext_t next_cid;
125   u8 use_test_cert_in_ca;
126   char *ca_cert_path;
127 } quic_main_t;
128
129 #endif /* __included_quic_h__ */
130
131 /*
132  * fd.io coding-style-patch-verification: ON
133  *
134  * Local Variables:
135  * eval: (c-set-style "gnu")
136  * End:
137  */