25#include <seastar/core/deleter.hh>
26#include <seastar/core/queue.hh>
27#include <seastar/core/stream.hh>
29#include <seastar/net/toeplitz.hh>
30#include <seastar/net/ethernet.hh>
31#include <seastar/net/packet.hh>
32#include <seastar/net/const.hh>
33#include <unordered_map>
58 void push_back(uint8_t b) {
59 assert(end_idx <
sizeof(data));
62 void push_back(uint16_t b) {
63 push_back(uint8_t(b));
64 push_back(uint8_t(b >> 8));
66 void push_back(uint32_t b) {
67 push_back(uint16_t(b));
68 push_back(uint16_t(b >> 16));
70 const uint8_t& operator[](
size_t idx)
const {
77 bool tx_csum_ip_offload =
false;
79 bool tx_csum_l4_offload =
false;
81 bool rx_csum_offload =
false;
91 uint16_t max_packet_len = ip_packet_len_max - eth_hdr_len;
97 eth_protocol_num proto_num;
101 using packet_provider_type = std::function<std::optional<l3packet> ()>;
104 eth_protocol_num _proto_num;
115 struct l3_rx_stream {
119 l3_rx_stream(std::function<
bool (
forward_hash&,
packet&,
size_t)>&& fw) : ready(packet_stream.started()), forward(fw) {}
121 std::unordered_map<uint16_t, l3_rx_stream> _proto_map;
122 std::shared_ptr<device> _dev;
125 std::vector<l3_protocol::packet_provider_type> _pkt_providers;
129 explicit interface(std::shared_ptr<device> dev);
132 future<> register_l3(eth_protocol_num proto_num,
135 void forward(
unsigned cpuid,
packet p);
136 unsigned hash2cpu(uint32_t hash);
137 void register_packet_provider(l3_protocol::packet_provider_type func) {
138 _pkt_providers.push_back(std::move(func));
140 uint16_t hw_queues_count();
141 rss_key_type rss_key()
const;
166 copy_frags += nr_frags;
196 void inc_csum_err() {
219 using packet_provider_type = std::function<std::optional<packet> ()>;
220 std::vector<packet_provider_type> _pkt_providers;
221 std::optional<std::array<uint8_t, 128>> _sw_reta;
224 std::unique_ptr<internal::poller> _tx_poller;
228 const std::string _stats_plugin_name;
229 const std::string _queue_name;
234 qp(
bool register_copy_stats =
false,
235 const std::string stats_plugin_name = std::string(
"network"),
243 (void)send(std::move(p.front()));
249 virtual void rx_start() {};
250 void configure_proxies(
const std::map<unsigned, float>& cpu_weights);
252 void build_sw_reta(
const std::map<unsigned, float>& cpu_weights);
253 void proxy_send(
packet p) {
254 _proxy_packetq.push_back(std::move(p));
256 void register_packet_provider(packet_provider_type func) {
257 _pkt_providers.push_back(std::move(func));
265 std::unique_ptr<qp*[]> _queues;
266 size_t _rss_table_bits = 0;
269 _queues = std::make_unique<qp*[]>(smp::count);
272 qp& queue_for_cpu(
unsigned cpu) {
return *_queues[cpu]; }
274 void l2receive(
packet p) {
276 (void)_queues[
this_shard_id()]->_rx_stream.produce(std::move(p));
281 virtual rss_key_type rss_key()
const {
return default_rsskey_40bytes; }
282 virtual uint16_t hw_queues_count() {
return 1; }
283 virtual future<> link_ready() {
return make_ready_future<>(); }
285 virtual unsigned hash2qid(uint32_t hash) {
286 return hash % hw_queues_count();
288 void set_local_queue(std::unique_ptr<qp> dev);
289 template <
typename Func>
290 unsigned forward_dst(
unsigned src_cpuid, Func&& hashfn) {
291 auto&
qp = queue_for_cpu(src_cpuid);
295 auto hash = hashfn() >> _rss_table_bits;
296 auto& reta = *
qp._sw_reta;
297 return reta[hash % reta.size()];
299 virtual unsigned hash2cpu(uint32_t hash) {
302 return forward_dst(hash2qid(hash), [hash] {
return hash; });
Definition: circular_buffer.hh:63
A representation of a possibly not-yet-computed value.
Definition: future.hh:1240
holds the metric definition.
Definition: metrics_registration.hh:94
Definition: program-options.hh:293
holds the metric_groups definition needed by class that reports metrics
Seastar API namespace.
Definition: abort_on_ebadf.hh:26
shard_id this_shard_id() noexcept
Returns shard_id of the of the current shard.
Definition: shard_id.hh:52
Definition: ethernet.hh:37
void update_frags_stats(uint64_t nfrags, uint64_t nbytes)
Definition: net.hh:176
void update_copy_stats(uint64_t nr_frags, uint64_t bytes)
Definition: net.hh:165
void update_pkts_bunch(uint64_t count)
Definition: net.hh:153