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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef __included_quic_h__
17 #define __included_quic_h__
19 #include <vnet/session/application_interface.h>
21 #include <vppinfra/lock.h>
22 #include <vppinfra/tw_timer_1t_3w_1024sl_ov.h>
23 #include <vppinfra/bihash_16_8.h>
29 * 2 - connection/stream events
35 #define QUIC_TSTAMP_RESOLUTION 0.001 /* QUIC tick resolution (1ms) */
36 #define QUIC_TIMER_HANDLE_INVALID ((u32) ~0)
37 #define QUIC_SESSION_INVALID ((u32) ~0 - 1)
38 #define QUIC_MAX_PACKET_SIZE 1280
40 #define QUIC_INT_MAX 0x3FFFFFFFFFFFFFFF
41 #define QUIC_FIFO_SIZE (64 << 10)
42 #define QUIC_SEND_PACKET_VEC_SIZE 16
44 /* Taken from quicly.c */
45 #define QUICLY_QUIC_BIT 0x40
47 #define QUICLY_PACKET_TYPE_INITIAL (QUICLY_LONG_HEADER_BIT | QUICLY_QUIC_BIT | 0)
48 #define QUICLY_PACKET_TYPE_0RTT (QUICLY_LONG_HEADER_BIT | QUICLY_QUIC_BIT | 0x10)
49 #define QUICLY_PACKET_TYPE_HANDSHAKE (QUICLY_LONG_HEADER_BIT | QUICLY_QUIC_BIT | 0x20)
50 #define QUICLY_PACKET_TYPE_RETRY (QUICLY_LONG_HEADER_BIT | QUICLY_QUIC_BIT | 0x30)
51 #define QUICLY_PACKET_TYPE_BITMASK 0xf0
54 #define QUIC_ERROR_FULL_FIFO 0xff10
55 #define QUIC_APP_ERROR_CLOSE_NOTIFY QUICLY_ERROR_FROM_APPLICATION_ERROR_CODE(0)
56 #define QUIC_APP_ALLOCATION_ERROR QUICLY_ERROR_FROM_APPLICATION_ERROR_CODE(0x1)
57 #define QUIC_APP_ACCEPT_NOTIFY_ERROR QUICLY_ERROR_FROM_APPLICATION_ERROR_CODE(0x2)
58 #define QUIC_APP_CONNECT_NOTIFY_ERROR QUICLY_ERROR_FROM_APPLICATION_ERROR_CODE(0x3)
61 #define QUIC_DBG(_lvl, _fmt, _args...) \
62 if (_lvl <= QUIC_DEBUG) \
63 clib_warning (_fmt, ##_args)
65 #define QUIC_DBG(_lvl, _fmt, _args...)
68 typedef enum quic_ctx_conn_state_
70 QUIC_CONN_STATE_OPENED,
71 QUIC_CONN_STATE_HANDSHAKE,
72 QUIC_CONN_STATE_READY,
73 QUIC_CONN_STATE_PASSIVE_CLOSING,
74 } quic_ctx_conn_state_t;
77 typedef enum quic_ctx_flags_
79 QUIC_F_IS_STREAM = (1 << 0),
80 QUIC_F_IS_LISTENER = (1 << 1),
84 typedef struct quic_ctx_id_
86 union { /** QUIC ctx case */
95 struct { /** STREAM ctx case */
96 quicly_stream_t *stream;
97 u32 quic_connection_ctx_id;
103 STATIC_ASSERT (sizeof (quic_ctx_id_t) <= 42, "ctx id must be less than 42");
105 /* This structure is used to implement the concept of VPP connection for QUIC.
106 * We create one per connection and one per stream. */
107 typedef struct quic_ctx_
111 transport_connection_t connection;
112 quic_ctx_id_t c_quic_ctx_id;
114 session_handle_t udp_session_handle;
116 u32 parent_app_wrk_id;
121 typedef struct quic_stream_data_
125 u32 app_rx_data_len; /* bytes received, to be read by external app */
126 } quic_stream_data_t;
128 typedef struct quic_worker_ctx_
130 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
131 int64_t time_now; /**< worker time */
132 tw_timer_wheel_1t_3w_1024sl_ov_t timer_wheel; /**< worker timer wheel */
133 u32 *opening_ctx_pool;
136 typedef struct quic_main_
139 quic_ctx_t **ctx_pool;
140 quic_worker_ctx_t *wrk_ctx;
141 clib_bihash_16_8_t connection_hash; /* quicly connection id -> conn handle */
142 f64 tstamp_ticks_per_clock;
147 quicly_context_t quicly_ctx;
148 ptls_handshake_properties_t hs_properties;
149 quicly_cid_plaintext_t next_cid;
152 #endif /* __included_quic_h__ */
155 * fd.io coding-style-patch-verification: ON
158 * eval: (c-set-style "gnu")