-
Notifications
You must be signed in to change notification settings - Fork 1
/
packet.hpp
72 lines (53 loc) · 1.74 KB
/
packet.hpp
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
#ifndef IXY_PACKET_HPP
#define IXY_PACKET_HPP
#include <iostream>
#include <memory>
#include "mempool.hpp"
namespace ixy {
class Packet {
friend class IxgbeDevice;
public:
// remove copy constructor
Packet(const Packet &) = delete;
// remove copy assignment
auto operator=(const Packet &) -> Packet & = delete;
// re-add implicitly removed move constructor
Packet(Packet &&) = default;
// re-add implicitly removed move assignment
auto operator=(Packet &&) -> Packet & = default;
~Packet() {
if (pool) {
pool->free_buf(pool_entry);
}
}
[[nodiscard]] auto at(uint64_t n) -> uint8_t & {
if (n >= len) {
throw std::out_of_range{"tried to access byte " + std::to_string(n) + " out of " + std::to_string(len) + " bytes"};
}
return *(addr_virt + n);
};
[[nodiscard]] auto get_virt_addr() -> uint8_t * {
return addr_virt;
}
[[nodiscard]] auto get_phys_addr() -> uint64_t {
return addr_phys;
}
[[nodiscard]] auto size() const -> uint64_t {
return len;
}
private:
Packet(uint8_t *addr_virt, uint64_t addr_phys, uint64_t len, std::shared_ptr<Mempool> pool, uint64_t pool_entry)
:
addr_virt{addr_virt},
addr_phys{addr_phys},
len{len},
pool{std::move(pool)},
pool_entry{pool_entry} {}
uint8_t *addr_virt;
uint64_t addr_phys;
uint64_t len;
std::shared_ptr<Mempool> pool;
uint64_t pool_entry;
};
} // namespace ixy
#endif //IXY_PACKET_HPP