bmv2
Designing your own switch target with bmv2
|
Go to the documentation of this file.
23 #ifndef BM_BM_SIM_PACKET_H_
24 #define BM_BM_SIM_PACKET_H_
38 #include "device_id.h"
41 #include "phv_source.h"
42 #include "phv_forward.h"
55 class CopyIdGenerator {
57 static constexpr
size_t W = 4096;
62 Cntr() noexcept : max(0), num(0) { }
77 std::array<std::atomic<Cntr>, W> arr{{}};
103 using clock = std::chrono::system_clock;
105 using buffer_state_t = PacketBuffer::state_t;
110 static constexpr
size_t INVALID_ENTRY_INDEX =
111 std::numeric_limits<size_t>::max();
132 void set_ingress_port(
int port) { ingress_port = port; }
142 return std::to_string(packet_id) +
"." + std::to_string(copy_id);
145 void set_copy_id(
copy_id_t id) { copy_id = id; }
158 void set_payload_size(
size_t size) { payload_size = size; }
160 size_t get_payload_size()
const {
return payload_size; }
166 return std::min(buffer.get_data_size(), truncated_length);
173 char *
data() {
return buffer.start(); }
176 const char *
data()
const {
return buffer.start(); }
182 return buffer.save_state();
187 buffer.restore_state(state);
191 assert(payload_size > 0);
192 return buffer.end() - payload_size;
195 const char *payload()
const {
196 assert(payload_size > 0);
197 return buffer.end() - payload_size;
204 truncated_length = std::min(length, truncated_length);
207 char *prepend(
size_t bytes) {
return buffer.push(bytes); }
209 char *remove(
size_t bytes) {
210 assert(buffer.get_data_size() >= payload_size + bytes);
211 return buffer.pop(bytes);
219 const PacketBuffer &get_packet_buffer()
const {
return buffer; }
221 uint64_t get_ingress_ts_ms()
const {
return ingress_ts_ms; }
234 void set_entry_index(
size_t idx) { entry_index = idx; }
239 void set_error_code(
const ErrorCode &code) { error_code = code; }
245 void set_checksum_error(
const bool b) { checksum_error = b; }
330 static Packet make_new(PHVSourceIface *phv_source);
334 PHVSourceIface *phv_source);
344 PHVSourceIface *phv_source);
346 void update_signature(uint64_t seed = 0);
347 void set_ingress_ts();
350 port_t ingress_port{0};
354 int ingress_length{0};
361 uint64_t signature{0};
363 PacketBuffer buffer{};
365 size_t payload_size{0};
367 size_t truncated_length{std::numeric_limits<size_t>::max()};
369 clock::time_point ingress_ts{};
370 uint64_t ingress_ts_ms{};
372 std::unique_ptr<PHV> phv;
374 PHVSourceIface *phv_source{
nullptr};
378 std::array<uint64_t, nb_registers> registers;
382 size_t entry_index{INVALID_ENTRY_INDEX};
386 bool checksum_error{
false};
389 static CopyIdGenerator *copy_id_gen;
394 #endif // BM_BM_SIM_PACKET_H_
void set_register(size_t idx, uint64_t v)
Write to general purpose register at index idx.
Definition: packet.h:230
std::unique_ptr< Packet > clone_with_phv_reset_metadata_ptr() const
void set_ingress_length(int length)
Definition: packet.h:156
cxt_id_t get_context() const
Returns the id of the Context this packet currently belongs to.
Definition: packet.h:287
uint64_t get_signature() const
Get a 64-bit hash of the incoming packet data.
Definition: packet.h:215
size_t get_entry_index() const
Definition: packet.h:237
std::unique_ptr< Packet > clone_with_phv_ptr() const
uint64_t copy_id_t
Integral type used to distinguish between different clones of a packet.
Definition: packet.h:50
bool is_marked_for_exit() const
Definition: packet.h:266
PHV * get_phv()
Get a pointer to the packet's phv.
Definition: packet.h:225
Packet clone_with_phv_reset_metadata() const
char * data()
Definition: packet.h:173
ErrorCode get_error_code() const
Definition: packet.h:243
int get_ingress_port() const
Get the ingress_port of the packet.
Definition: packet.h:128
const PHV * get_phv() const
Get a pointer to the packet's phv.
Definition: packet.h:227
size_t get_data_size() const
Definition: packet.h:165
uint32_t port_t
Integral type used to identify a given port.
Definition: packet.h:53
void truncate(size_t length)
Definition: packet.h:203
static ErrorCode make_invalid()
Definition: parser_error.h:57
uint64_t packet_id_t
Integral type used to identify a given data packet.
Definition: packet.h:47
void change_context(cxt_id_t new_cxt)
const buffer_state_t save_buffer_state() const
Definition: packet.h:181
Definition: parser_error.h:35
packet_id_t get_packet_id() const
Definition: packet.h:122
copy_id_t get_copy_id() const
Definition: packet.h:137
const std::string get_unique_id() const
Definition: packet.h:141
bool get_checksum_error() const
Definition: packet.h:249
Packet clone_no_phv() const
Packet & operator=(const Packet &other)=delete
Deleted copy assignment operator.
Packet(const Packet &other)=delete
Deleted copy constructor.
Packet clone_choose_context(cxt_id_t new_cxt) const
int get_egress_port() const
Definition: packet.h:126
void reset_exit()
Definition: packet.h:263
Packet clone_with_phv() const
Definition: packet_buffer.h:48
int get_ingress_length() const
Definition: packet.h:151
static constexpr size_t nb_registers
Number of general purpose registers per packet.
Definition: packet.h:108
const char * data() const
Definition: packet.h:176
void mark_for_exit()
Definition: packet.h:260
std::unique_ptr< Packet > clone_no_phv_ptr() const
std::unique_ptr< Packet > clone_choose_context_ptr(cxt_id_t new_cxt) const
void restore_buffer_state(const buffer_state_t &state)
See save_buffer_state()
Definition: packet.h:186
void set_egress_port(int port)
Set the egress_port of the packet, which is the target responsibility.
Definition: packet.h:131
uint64_t get_register(size_t idx)
Read general purpose register at index idx.
Definition: packet.h:232