Ensō 0.4.6
Software API reference
Loading...
Searching...
No Matches
config.cpp
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
40#include <enso/config.h>
41#include <enso/consts.h>
42#include <enso/helpers.h>
43#include <enso/internals.h>
44#include <immintrin.h>
45
46#include <cstdio>
47
48#include "../pcie.h"
49
50namespace enso {
51
52enum ConfigId {
53 FLOW_TABLE_CONFIG_ID = 1,
54 TIMESTAMP_CONFIG_ID = 2,
55 RATE_LIMIT_CONFIG_ID = 3,
56 FALLBACK_QUEUES_CONFIG_ID = 4
57};
58
59struct __attribute__((__packed__)) FlowTableConfig {
60 uint64_t signal;
61 uint64_t config_id;
62 uint16_t dst_port;
63 uint16_t src_port;
64 uint32_t dst_ip;
65 uint32_t src_ip;
66 uint32_t protocol;
67 uint32_t enso_pipe_id;
68 uint8_t pad[28];
69};
70
71struct __attribute__((__packed__)) TimestampConfig {
72 uint64_t signal;
73 uint64_t config_id;
74 uint64_t enable;
75 uint64_t offset;
76 uint8_t pad[32];
77};
78
79struct __attribute__((__packed__)) RateLimitConfig {
80 uint64_t signal;
81 uint64_t config_id;
82 uint16_t denominator;
83 uint16_t numerator;
84 uint32_t enable;
85 uint8_t pad[40];
86};
87
88struct __attribute__((__packed__)) FallbackQueueConfig {
89 uint64_t signal;
90 uint64_t config_id;
91 uint32_t nb_fallback_queues;
92 uint32_t fallback_queue_mask;
93 uint64_t enable_rr;
94 uint8_t pad[32];
95};
96
97int insert_flow_entry(struct NotificationBufPair* notification_buf_pair,
98 uint16_t dst_port, uint16_t src_port, uint32_t dst_ip,
99 uint32_t src_ip, uint32_t protocol,
100 uint32_t enso_pipe_id) {
101 struct FlowTableConfig config;
102
103 config.signal = 2;
104 config.config_id = FLOW_TABLE_CONFIG_ID;
105 config.dst_port = dst_port;
106 config.src_port = src_port;
107 config.dst_ip = dst_ip;
108 config.src_ip = src_ip;
109 config.protocol = protocol;
110 config.enso_pipe_id = enso_pipe_id;
111
112 std::cout << "Inserting flow entry: dst_port=" << dst_port
113 << ", src_port=" << src_port << ", dst_ip=";
114 print_ip(htonl(dst_ip));
115 std::cout << ", src_ip=";
116 print_ip(htonl(src_ip));
117 std::cout << ", protocol=" << protocol << ", enso_pipe_id=" << enso_pipe_id
118 << ")" << std::endl;
119
120 return send_config(notification_buf_pair, (struct TxNotification*)&config);
121}
122
123int enable_timestamp(struct NotificationBufPair* notification_buf_pair,
124 uint8_t offset) {
125 if (offset > 60) {
126 return -1;
127 }
128
129 TimestampConfig config;
130
131 config.signal = 2;
132 config.config_id = TIMESTAMP_CONFIG_ID;
133 config.enable = -1;
134 config.offset = offset;
135
136 return send_config(notification_buf_pair, (struct TxNotification*)&config);
137}
138
139int disable_timestamp(struct NotificationBufPair* notification_buf_pair) {
140 TimestampConfig config;
141
142 config.signal = 2;
143 config.config_id = TIMESTAMP_CONFIG_ID;
144 config.enable = 0;
145
146 return send_config(notification_buf_pair, (struct TxNotification*)&config);
147}
148
149int enable_rate_limit(struct NotificationBufPair* notification_buf_pair,
150 uint16_t num, uint16_t den) {
151 struct RateLimitConfig config;
152
153 config.signal = 2;
154 config.config_id = RATE_LIMIT_CONFIG_ID;
155 config.denominator = den;
156 config.numerator = num;
157 config.enable = -1;
158
159 return send_config(notification_buf_pair, (struct TxNotification*)&config);
160}
161
162int disable_rate_limit(struct NotificationBufPair* notification_buf_pair) {
163 struct RateLimitConfig config;
164
165 config.signal = 2;
166 config.config_id = RATE_LIMIT_CONFIG_ID;
167 config.enable = 0;
168
169 return send_config(notification_buf_pair, (struct TxNotification*)&config);
170}
171
172static int configure_fallback_queues(
173 struct NotificationBufPair* notification_buf_pair,
174 uint32_t nb_fallback_queues, bool enable_rr) {
175 struct FallbackQueueConfig config;
176
177 config.signal = 2;
178 config.config_id = FALLBACK_QUEUES_CONFIG_ID;
179 config.nb_fallback_queues = nb_fallback_queues;
180 config.enable_rr = enable_rr ? -1 : 0;
181
182 // Round down to the nearest power of 2.
183 uint32_t cnt = 0;
184 while (nb_fallback_queues) {
185 nb_fallback_queues >>= 1;
186 ++cnt;
187 }
188 config.fallback_queue_mask = cnt ? (1 << (cnt - 1)) - 1 : 0;
189
190 return send_config(notification_buf_pair, (struct TxNotification*)&config);
191}
192
193static int set_round_robin(struct NotificationBufPair* notification_buf_pair,
194 bool enable_rr) {
195 int nb_fallback_queues = get_nb_fallback_queues(notification_buf_pair);
196 if (nb_fallback_queues < 0) {
197 return nb_fallback_queues;
198 }
199
200 if (set_round_robin_status(notification_buf_pair, enable_rr)) {
201 return -1;
202 }
203
204 return configure_fallback_queues(notification_buf_pair, nb_fallback_queues,
205 enable_rr);
206}
207
208int enable_round_robin(struct NotificationBufPair* notification_buf_pair) {
209 return set_round_robin(notification_buf_pair, true);
210}
211
212int disable_round_robin(struct NotificationBufPair* notification_buf_pair) {
213 return set_round_robin(notification_buf_pair, false);
214}
215
217 struct NotificationBufPair* notification_buf_pair) {
218 int enable_rr = get_round_robin_status(notification_buf_pair);
219
220 if (enable_rr < 0) {
221 return enable_rr;
222 }
223
224 int nb_fallback_queues = get_nb_fallback_queues(notification_buf_pair);
225 if (nb_fallback_queues < 0) {
226 return nb_fallback_queues;
227 }
228
229 return configure_fallback_queues(notification_buf_pair, nb_fallback_queues,
230 (bool)enable_rr);
231}
232
233} // namespace enso
Functions to configure the data plane.
int enable_timestamp(struct NotificationBufPair *notification_buf_pair, uint8_t offset=kDefaultRttOffset)
Enables hardware timestamping.
Definition: config.cpp:123
int enable_round_robin(struct NotificationBufPair *notification_buf_pair)
Enables packet round robin for the fallback pipes.
Definition: config.cpp:208
int disable_timestamp(struct NotificationBufPair *notification_buf_pair)
Disables hardware timestamping.
Definition: config.cpp:139
int enable_rate_limit(struct NotificationBufPair *notification_buf_pair, uint16_t num, uint16_t den)
Enables hardware rate limit.
Definition: config.cpp:149
int update_fallback_queues_config(struct NotificationBufPair *notification_buf_pair)
Update the device's fallback queues configuration.
Definition: config.cpp:216
int disable_rate_limit(struct NotificationBufPair *notification_buf_pair)
Disables hardware rate limit.
Definition: config.cpp:162
int insert_flow_entry(struct NotificationBufPair *notification_buf_pair, uint16_t dst_port, uint16_t src_port, uint32_t dst_ip, uint32_t src_ip, uint32_t protocol, uint32_t enso_pipe_id)
Inserts flow entry in the data plane flow table that will direct all packets matching the flow entry ...
Definition: config.cpp:97
int disable_round_robin(struct NotificationBufPair *notification_buf_pair)
Disables packet round robin for the fallback pipes. Using a hash of the packet's five tuple to select...
Definition: config.cpp:212
Constants used throughout the codebase. Some of these constants need to be kept in sync with the hard...
Miscellaneous helper functions.
Definitions that are internal to Enso. They should not be exposed to applications.
int set_round_robin_status(struct NotificationBufPair *notification_buf_pair, bool round_robin)
Sets the round robin status for the device.
Definition: pcie.cpp:614
int send_config(struct NotificationBufPair *notification_buf_pair, struct TxNotification *config_notification)
Sends configuration to the NIC.
Definition: pcie.cpp:569
int get_nb_fallback_queues(struct NotificationBufPair *notification_buf_pair)
Get number of fallback queues currently in use.
Definition: pcie.cpp:608
int get_round_robin_status(struct NotificationBufPair *notification_buf_pair)
Gets the round robin status for the device.
Definition: pcie.cpp:621