Ensō 0.4.6
Software API reference
Loading...
Searching...
No Matches
socket.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022, Carnegie Mellon University
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted (subject to the limitations in the disclaimer
6 * below) provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * * Neither the name of the copyright holder nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
20 * THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
21 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
22 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
30 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
41#ifndef SOFTWARE_INCLUDE_ENSO_SOCKET_H_
42#define SOFTWARE_INCLUDE_ENSO_SOCKET_H_
43
44#include <arpa/inet.h>
45#include <enso/consts.h>
46#include <linux/types.h>
47
48namespace enso {
49
50typedef unsigned short sa_family_t;
51typedef unsigned int socklen_t;
52
53#define MAX_NB_CORES 128
54#define MAX_NB_SOCKETS MAX_NB_FLOWS
55
56void set_bdf(uint16_t bdf_);
57
58int socket(int domain, int type, int protocol, bool fallback) noexcept;
59
60int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen) noexcept;
61
62uint64_t get_socket_phys_addr(int sockfd);
63
64void *get_socket_virt_addr(int sockfd);
65
66uint64_t convert_buf_addr_to_phys(int sockfd, void *addr);
67
68int shutdown(int sockfd, int how) noexcept;
69
70/*
71 * Receives packets using a POSIX-like interface. Here *buf is the address to a
72 * buffer allocated by the user. The function will copy the received data to
73 * this buffer.
74 */
75ssize_t recv(int sockfd, void *buf, size_t len, int flags);
76
77ssize_t recv_zc(int sockfd, void **buf, size_t len, int flags);
78
79ssize_t recv_select(int ref_sockfd, int *sockfd, void **buf, size_t len,
80 int flags);
81
82/*
83 * Send the bytes pointed by address `phys_addr` through the `sockfd` socket.
84 * There are two important differences to a traditional POSIX `send`:
85 * - Memory must be pinned (phys_addr needs to be a physical address);
86 * - It is not safe to change the buffer content until the transmission is done.
87 *
88 * This function blocks until it can send but returns before the transmission is
89 * over. To figure out when the transmission is over, use the `get_completions`
90 * function.
91 */
92ssize_t send(int sockfd, uint64_t phys_addr, size_t len, int flags);
93
94/*
95 * Return the number of transmission requests that were completed since the last
96 * call to this function. Since transmissions are always completed in order, one
97 * can figure out which transmissions were completed by keeping track of all the
98 * calls to `send`. There can be only up to `kMaxPendingTxRequests` requests
99 * completed between two calls to `send`. However, if `send` is called multiple
100 * times, without calling `get_completions` the number of completed requests can
101 * surpass `kMaxPendingTxRequests`.
102 */
103uint32_t get_completions(int ref_sockfd);
104
105/*
106 * Enable hardware timestamping for the device. This applies to all sockets.
107 */
108int enable_device_timestamp(int ref_sockfd, uint8_t offset = kDefaultRttOffset);
109
110/*
111 * Disable hardware timestamping for the device. This applies to all sockets.
112 */
113int disable_device_timestamp(int ref_sockfd);
114
115/*
116 * Enable hardware rate limit for the device. This applies to all sockets.
117 */
118int enable_device_rate_limit(int ref_sockfd, uint16_t num, uint16_t den);
119
120/*
121 * Disable hardware rate limit for the device. This applies to all sockets.
122 */
123int disable_device_rate_limit(int ref_sockfd);
124
125/*
126 * Enable round robin for the device. This applies to all sockets.
127 */
128int enable_device_round_robin(int ref_sockfd);
129
130/*
131 * Disable round robin for the device. This applies to all sockets.
132 */
133int disable_device_round_robin(int ref_sockfd);
134
135/*
136 * Free packet buffer. Use this to free received packets.
137 */
138void free_enso_pipe(int sockfd, size_t len);
139
140void print_sock_stats(int sockfd);
141
142} // namespace enso
143
144#endif // SOFTWARE_INCLUDE_ENSO_SOCKET_H_
Constants used throughout the codebase. Some of these constants need to be kept in sync with the hard...