Add QUIC multistream 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 #include <vppinfra/bihash_16_8.h>
24
25 #include <quicly.h>
26 #include <quicly/streambuf.h>
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_TSTAMP_RESOLUTION  0.001   /* QUIC tick resolution (1ms) */
35
36
37 #if QUIC_DEBUG
38 #define QUIC_DBG(_lvl, _fmt, _args...)           \
39   if (_lvl <= QUIC_DEBUG)                \
40     clib_warning (_fmt, ##_args)
41 #else
42 #define QUIC_DBG(_lvl, _fmt, _args...)
43 #endif
44
45 #define QUIC_CONN_STATE_OPENED    0
46 #define QUIC_CONN_STATE_HANDSHAKE 1
47 #define QUIC_CONN_STATE_READY     2
48
49 /* *INDENT-OFF* */
50 typedef CLIB_PACKED (struct quic_ctx_id_
51 {
52   u32 parent_app_wrk_id;
53   u32 parent_app_id;
54   union {
55     CLIB_PACKED (struct {
56       session_handle_t quic_session_handle; /* TODO: remove */
57       session_handle_t udp_session_handle;
58       quicly_conn_t *conn;
59       u32 listener_ctx_id;
60       u8 udp_is_ip4;
61     });
62     CLIB_PACKED (struct {
63       session_handle_t stream_session_handle; /* TODO: remove */
64       quicly_stream_t *stream;
65       u32 quic_connection_ctx_id;
66     });
67   };
68   u8 is_stream;
69 }) quic_ctx_id_t;
70 /* *INDENT-ON* */
71
72 STATIC_ASSERT (sizeof (quic_ctx_id_t) <= 42, "ctx id must be less than 42");
73
74 /* This structure is used to implement the concept of VPP connection for QUIC.
75  * We create one per connection and one per stream. */
76 typedef struct quic_ctx_
77 {
78   union
79   {
80     transport_connection_t connection;
81     quic_ctx_id_t c_quic_ctx_id;
82   };
83   u8 *srv_hostname;
84   u32 client_opaque;
85   u32 timer_handle;
86   u8 conn_state;
87   u8 is_listener;
88 } quic_ctx_t;
89
90 typedef struct quic_stream_data_
91 {
92   quicly_streambuf_t streambuf;
93   u32 ctx_id;
94 } quic_stream_data_t;
95
96 typedef struct quic_worker_ctx_
97 {
98   CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
99   int64_t time_now;                                /**< worker time */
100   tw_timer_wheel_1t_3w_1024sl_ov_t timer_wheel;    /**< worker timer wheel */
101   u32 *opening_ctx_pool;
102 } quic_worker_ctx_t;
103
104 typedef struct quic_main_
105 {
106   u32 app_index;
107   quic_ctx_t **ctx_pool;
108   quic_worker_ctx_t *wrk_ctx;
109   clib_bihash_16_8_t connection_hash;   /* quicly connection id -> conn handle */
110   f64 tstamp_ticks_per_clock;
111   u32 fake_app_listener_index;  /* ugly hack for accept cb */
112
113   /*
114    * Config
115    */
116   quicly_context_t quicly_ctx;
117   ptls_handshake_properties_t hs_properties;
118   quicly_cid_plaintext_t next_cid;
119   u8 use_test_cert_in_ca;
120   char *ca_cert_path;
121 } quic_main_t;
122
123 #endif /* __included_quic_h__ */
124
125 /*
126  * fd.io coding-style-patch-verification: ON
127  *
128  * Local Variables:
129  * eval: (c-set-style "gnu")
130  * End:
131  */