session: cleanup part 3
[vpp.git] / src / vnet / session / transport.h
1 /*
2  * Copyright (c) 2016-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 VNET_VNET_URI_TRANSPORT_H_
17 #define VNET_VNET_URI_TRANSPORT_H_
18
19 #include <vnet/vnet.h>
20 #include <vnet/ip/ip.h>
21 #include <vnet/tcp/tcp_debug.h>
22
23 typedef enum transport_dequeue_type_
24 {
25   TRANSPORT_TX_PEEK,            /**< reliable transport protos */
26   TRANSPORT_TX_DEQUEUE,         /**< unreliable transport protos */
27   TRANSPORT_TX_INTERNAL,        /**< apps acting as transports */
28   TRANSPORT_TX_DGRAM,           /**< datagram mode */
29   TRANSPORT_TX_N_FNS
30 } transport_tx_fn_type_t;
31
32 typedef enum transport_service_type_
33 {
34   TRANSPORT_SERVICE_VC,         /**< virtual circuit service */
35   TRANSPORT_SERVICE_CL,         /**< connectionless service */
36   TRANSPORT_SERVICE_APP,        /**< app transport service */
37   TRANSPORT_N_SERVICES
38 } transport_service_type_t;
39
40 typedef struct _transport_stats
41 {
42   u64 tx_bytes;
43 } transport_stats_t;
44
45 typedef struct _spacer
46 {
47   u64 bucket;
48   u32 max_burst_size;
49   f32 tokens_per_period;
50   u64 last_update;
51 } spacer_t;
52
53 /*
54  * Protocol independent transport properties associated to a session
55  */
56 typedef struct _transport_connection
57 {
58   /** Connection ID */
59   union
60   {
61     /*
62      * Network connection ID tuple
63      */
64     struct
65     {
66       ip46_address_t rmt_ip;    /**< Remote IP */
67       ip46_address_t lcl_ip;    /**< Local IP */
68       u16 rmt_port;             /**< Remote port */
69       u16 lcl_port;             /**< Local port */
70       u8 is_ip4;                /**< Flag if IP4 connection */
71       u8 proto;                 /**< Protocol id */
72       u32 fib_index;            /**< Network namespace */
73     };
74     /*
75      * Opaque connection ID
76      */
77     u8 opaque_conn_id[42];
78   };
79
80   u32 s_index;                  /**< Parent session index */
81   u32 c_index;                  /**< Connection index in transport pool */
82   u32 thread_index;             /**< Worker-thread index */
83
84   /*fib_node_index_t rmt_fei;
85      dpo_id_t rmt_dpo; */
86
87   u8 flags;                     /**< Transport specific flags */
88   transport_stats_t stats;      /**< Transport connection stats */
89   spacer_t pacer;               /**< Simple transport pacer */
90
91 #if TRANSPORT_DEBUG
92   elog_track_t elog_track;      /**< Event logging */
93   u32 cc_stat_tstamp;           /**< CC stats timestamp */
94 #endif
95
96   /** Macros for 'derived classes' where base is named "connection" */
97 #define c_lcl_ip connection.lcl_ip
98 #define c_rmt_ip connection.rmt_ip
99 #define c_lcl_ip4 connection.lcl_ip.ip4
100 #define c_rmt_ip4 connection.rmt_ip.ip4
101 #define c_lcl_ip6 connection.lcl_ip.ip6
102 #define c_rmt_ip6 connection.rmt_ip.ip6
103 #define c_lcl_port connection.lcl_port
104 #define c_rmt_port connection.rmt_port
105 #define c_proto connection.proto
106 #define c_fib_index connection.fib_index
107 #define c_s_index connection.s_index
108 #define c_c_index connection.c_index
109 #define c_is_ip4 connection.is_ip4
110 #define c_thread_index connection.thread_index
111 #define c_elog_track connection.elog_track
112 #define c_cc_stat_tstamp connection.cc_stat_tstamp
113 #define c_rmt_fei connection.rmt_fei
114 #define c_rmt_dpo connection.rmt_dpo
115 #define c_opaque_id connection.opaque_conn_id
116 #define c_stats connection.stats
117 #define c_pacer connection.pacer
118 #define c_flags connection.flags
119 } transport_connection_t;
120
121 #define TRANSPORT_CONNECTION_F_IS_TX_PACED      1 << 0
122
123 typedef enum _transport_proto
124 {
125   TRANSPORT_PROTO_TCP,
126   TRANSPORT_PROTO_UDP,
127   TRANSPORT_PROTO_SCTP,
128   TRANSPORT_PROTO_NONE,
129   TRANSPORT_PROTO_TLS,
130   TRANSPORT_PROTO_UDPC,
131   TRANSPORT_N_PROTO
132 } transport_proto_t;
133
134 u8 *format_transport_proto (u8 * s, va_list * args);
135 u8 *format_transport_proto_short (u8 * s, va_list * args);
136 u8 *format_transport_connection (u8 * s, va_list * args);
137 u8 *format_transport_listen_connection (u8 * s, va_list * args);
138 u8 *format_transport_half_open_connection (u8 * s, va_list * args);
139
140 uword unformat_transport_proto (unformat_input_t * input, va_list * args);
141
142 #define foreach_transport_endpoint_fields                               \
143   _(ip46_address_t, ip) /**< ip address in net order */                 \
144   _(u16, port)          /**< port in net order */                       \
145   _(u8, is_ip4)         /**< set if ip4 */                              \
146   _(u32, sw_if_index)   /**< interface endpoint is associated with  */  \
147   _(u32, fib_index)     /**< fib table endpoint is associated with */   \
148
149 typedef struct transport_endpoint_
150 {
151 #define _(type, name) type name;
152   foreach_transport_endpoint_fields
153 #undef _
154 } transport_endpoint_t;
155
156 #define foreach_transport_endpoint_cfg_fields                           \
157   foreach_transport_endpoint_fields                                     \
158   _(transport_endpoint_t, peer)                                         \
159
160 typedef struct transport_endpoint_pair_
161 {
162 #define _(type, name) type name;
163   foreach_transport_endpoint_cfg_fields
164 #undef _
165 } transport_endpoint_cfg_t;
166
167 typedef clib_bihash_24_8_t transport_endpoint_table_t;
168
169 #define ENDPOINT_INVALID_INDEX ((u32)~0)
170
171 always_inline u8
172 transport_connection_fib_proto (transport_connection_t * tc)
173 {
174   return tc->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
175 }
176
177 always_inline u8
178 transport_endpoint_fib_proto (transport_endpoint_t * tep)
179 {
180   return tep->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
181 }
182
183 int transport_alloc_local_port (u8 proto, ip46_address_t * ip);
184 int transport_alloc_local_endpoint (u8 proto, transport_endpoint_cfg_t * rmt,
185                                     ip46_address_t * lcl_addr,
186                                     u16 * lcl_port);
187 void transport_endpoint_cleanup (u8 proto, ip46_address_t * lcl_ip, u16 port);
188 u8 transport_protocol_is_cl (transport_proto_t tp);
189 transport_service_type_t transport_protocol_service_type (transport_proto_t);
190 transport_tx_fn_type_t transport_protocol_tx_fn_type (transport_proto_t tp);
191 void transport_init (void);
192
193 #endif /* VNET_VNET_URI_TRANSPORT_H_ */
194
195 /*
196  * fd.io coding-style-patch-verification: ON
197  *
198  * Local Variables:
199  * eval: (c-set-style "gnu")
200  * End:
201  */