1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
/*
* This file is open source software, licensed to you under the terms
* of the Apache License, Version 2.0 (the "License"). See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership. You may not use this file except in compliance with the License.
*
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/*
* Copyright (C) 2014 Cloudius Systems, Ltd.
*/
#ifndef CEPH_MSG_DPDK_NET_H
#define CEPH_MSG_DPDK_NET_H
#include "const.h"
#include "ethernet.h"
#include "Packet.h"
#include "stream.h"
#include "toeplitz.h"
struct hw_features {
// Enable tx ip header checksum offload
bool tx_csum_ip_offload = false;
// Enable tx l4 (TCP or UDP) checksum offload
bool tx_csum_l4_offload = false;
// Enable rx checksum offload
bool rx_csum_offload = false;
// LRO is enabled
bool rx_lro = false;
// Enable tx TCP segment offload
bool tx_tso = false;
// Enable tx UDP fragmentation offload
bool tx_ufo = false;
// Maximum Transmission Unit
uint16_t mtu = 1500;
// Maximun packet len when TCP/UDP offload is enabled
uint16_t max_packet_len = ip_packet_len_max - eth_hdr_len;
};
class forward_hash {
uint8_t data[64];
size_t end_idx = 0;
public:
size_t size() const {
return end_idx;
}
void push_back(uint8_t b) {
ceph_assert(end_idx < sizeof(data));
data[end_idx++] = b;
}
void push_back(uint16_t b) {
push_back(uint8_t(b));
push_back(uint8_t(b >> 8));
}
void push_back(uint32_t b) {
push_back(uint16_t(b));
push_back(uint16_t(b >> 16));
}
const uint8_t& operator[](size_t idx) const {
return data[idx];
}
};
class interface;
class l3_protocol {
public:
struct l3packet {
eth_protocol_num proto_num;
ethernet_address to;
Packet p;
};
using packet_provider_type = std::function<Tub<l3packet> ()>;
private:
interface* _netif;
eth_protocol_num _proto_num;
public:
explicit l3_protocol(interface* netif, eth_protocol_num proto_num, packet_provider_type func);
subscription<Packet, ethernet_address> receive(
std::function<int (Packet, ethernet_address)> rx_fn,
std::function<bool (forward_hash &h, Packet &p, size_t s)> forward);
private:
friend class interface;
};
class DPDKDevice;
struct ipv4_address;
class interface {
CephContext *cct;
struct l3_rx_stream {
stream<Packet, ethernet_address> packet_stream;
std::function<bool (forward_hash&, Packet&, size_t)> forward;
bool ready() { return packet_stream.started(); }
explicit l3_rx_stream(std::function<bool (forward_hash&, Packet&, size_t)>&& fw) : forward(fw) {}
};
std::unordered_map<uint16_t, l3_rx_stream> _proto_map;
std::shared_ptr<DPDKDevice> _dev;
subscription<Packet> _rx;
ethernet_address _hw_address;
struct hw_features _hw_features;
std::vector<l3_protocol::packet_provider_type> _pkt_providers;
private:
int dispatch_packet(EventCenter *c, Packet p);
public:
explicit interface(CephContext *cct, std::shared_ptr<DPDKDevice> dev, EventCenter *center);
ethernet_address hw_address() { return _hw_address; }
const struct hw_features& get_hw_features() const { return _hw_features; }
subscription<Packet, ethernet_address> register_l3(
eth_protocol_num proto_num,
std::function<int (Packet, ethernet_address)> next,
std::function<bool (forward_hash&, Packet&, size_t)> forward);
void forward(EventCenter *source, unsigned target, Packet p);
unsigned hash2cpu(uint32_t hash);
void register_packet_provider(l3_protocol::packet_provider_type func) {
_pkt_providers.push_back(std::move(func));
}
const rss_key_type& rss_key() const;
uint16_t hw_queues_count() const;
void arp_learn(ethernet_address l2, ipv4_address l3);
friend class l3_protocol;
};
#endif //CEPH_MSG_DPDK_NET_H
|