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