blob: 273c9ad430bbbd9de0faa4d256a637690b9d2c35 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
2 * mc_socket.h: socket based multicast for vlib mc
3 *
4 * Copyright (c) 2010 Cisco and/or its affiliates.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef __included_mc_socket_h__
19#define __included_mc_socket_h__
20
21#include <vlib/unix/unix.h>
22#include <netinet/in.h>
23
Dave Barach9b8ffd92016-07-08 08:13:45 -040024typedef struct
25{
Ed Warnickecb9cada2015-12-08 15:45:58 -070026 int socket;
27 struct sockaddr_in tx_addr;
28} mc_multicast_socket_t;
29
30/* TCP catchup socket */
Dave Barach9b8ffd92016-07-08 08:13:45 -040031typedef struct
32{
Ed Warnickecb9cada2015-12-08 15:45:58 -070033 int socket;
34 u32 unix_file_index;
35
Dave Barach9b8ffd92016-07-08 08:13:45 -040036 u8 *input_vector;
37 u8 *output_vector;
Ed Warnickecb9cada2015-12-08 15:45:58 -070038 u32 output_vector_n_written;
39
40 u32 connect_in_progress;
41} mc_socket_catchup_t;
42
Dave Barach9b8ffd92016-07-08 08:13:45 -040043typedef struct mc_socket_main_t
44{
Ed Warnickecb9cada2015-12-08 15:45:58 -070045 mc_main_t mc_main;
46
47 /* Multicast mastership/to-relay/from-relay sockets. */
48 mc_multicast_socket_t multicast_sockets[MC_N_TRANSPORT_TYPE];
49
50 /* Unicast UDP ack sockets */
51 int ack_socket;
52
53 /* TCP catchup server socket */
54 int catchup_server_socket;
55
56 /* Pool of stream-private catchup sockets */
57 mc_socket_catchup_t *catchups;
58
Dave Barach9b8ffd92016-07-08 08:13:45 -040059 uword *catchup_index_by_file_descriptor;
Ed Warnickecb9cada2015-12-08 15:45:58 -070060
61 u32 rx_mtu_n_bytes;
62
63 /* Receive MTU in bytes and VLIB buffers. */
64 u32 rx_mtu_n_buffers;
65
66 /* Vector of RX VLIB buffers. */
Dave Barach9b8ffd92016-07-08 08:13:45 -040067 u32 *rx_buffers;
Ed Warnickecb9cada2015-12-08 15:45:58 -070068 /* Vector of scatter/gather descriptors for sending/receiving VLIB buffers
69 via kernel. */
Dave Barach9b8ffd92016-07-08 08:13:45 -040070 struct iovec *iovecs;
Ed Warnickecb9cada2015-12-08 15:45:58 -070071
72 /* IP address of interface to use for multicast. */
73 u32 if_ip4_address_net_byte_order;
Dave Barach9b8ffd92016-07-08 08:13:45 -040074
Ed Warnickecb9cada2015-12-08 15:45:58 -070075 u32 ack_udp_port;
76 u32 catchup_tcp_port;
77
78 /* Interface on which to listen for multicasts. */
Dave Barach9b8ffd92016-07-08 08:13:45 -040079 char *multicast_interface_name;
Ed Warnickecb9cada2015-12-08 15:45:58 -070080
81 /* Multicast address to use (e.g. 0xefff0000).
82 Host byte order. */
83 u32 multicast_tx_ip4_address_host_byte_order;
84
85 /* TTL to use for multicasts. */
86 u32 multicast_ttl;
87
88 /* Multicast ports for mastership, joins, etc. will be chosen
89 starting at the given port in host byte order.
90 A total of MC_N_TRANSPORT_TYPE ports will be used. */
91 u32 base_multicast_udp_port_host_byte_order;
92} mc_socket_main_t;
93
94always_inline u32
95mc_socket_peer_id_get_address (mc_peer_id_t i)
96{
97 u32 a = ((i.as_u8[0] << 24)
Dave Barach9b8ffd92016-07-08 08:13:45 -040098 | (i.as_u8[1] << 16) | (i.as_u8[2] << 8) | (i.as_u8[3] << 0));
Ed Warnickecb9cada2015-12-08 15:45:58 -070099 return clib_host_to_net_u32 (a);
100}
101
102always_inline u32
103mc_socket_peer_id_get_port (mc_peer_id_t i)
Dave Barach9b8ffd92016-07-08 08:13:45 -0400104{
105 return clib_host_to_net_u16 ((i.as_u8[4] << 8) | i.as_u8[5]);
106}
Ed Warnickecb9cada2015-12-08 15:45:58 -0700107
108static_always_inline mc_peer_id_t
109mc_socket_set_peer_id (u32 address_net_byte_order, u32 port_host_byte_order)
110{
111 mc_peer_id_t i;
112 u32 a = ntohl (address_net_byte_order);
113 u32 p = port_host_byte_order;
114 i.as_u8[0] = (a >> 24) & 0xff;
115 i.as_u8[1] = (a >> 16) & 0xff;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400116 i.as_u8[2] = (a >> 8) & 0xff;
117 i.as_u8[3] = (a >> 0) & 0xff;
118 i.as_u8[4] = (p >> 8) & 0xff;
119 i.as_u8[5] = (p >> 0) & 0xff;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700120 i.as_u8[6] = 0;
121 i.as_u8[7] = 0;
122 return i;
123}
124
Dave Barach9b8ffd92016-07-08 08:13:45 -0400125clib_error_t *mc_socket_main_init (mc_socket_main_t * msm,
126 char **intfc_probe_list,
127 int n_intfcs_to_probe);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700128#endif /* __included_mc_socket_h__ */
129
Dave Barach9b8ffd92016-07-08 08:13:45 -0400130
131/*
132 * fd.io coding-style-patch-verification: ON
133 *
134 * Local Variables:
135 * eval: (c-set-style "gnu")
136 * End:
137 */