21#ifndef BM_BM_SIM_DEBUGGER_H_
22#define BM_BM_SIM_DEBUGGER_H_
33using device_id_t = uint64_t;
34using s_device_id_t = device_id_t;
43#define DBG_CTR_PARSER (1 << 24)
44#define DBG_CTR_PARSE_STATE (2 << 24)
45#define DBG_CTR_CONTROL (3 << 24)
46#define DBG_CTR_TABLE (4 << 24)
47#define DBG_CTR_CONDITION (5 << 24)
48#define DBG_CTR_ACTION (6 << 24)
49#define DBG_CTR_DEPARSER (7 << 24)
51#define DBG_CTR_EXIT(x) (x | (0x80 << 24))
55 static constexpr uint64_t FIELD_COND =
56 std::numeric_limits<uint64_t>::max() - 1;
58 static constexpr uint64_t FIELD_ACTION =
59 std::numeric_limits<uint64_t>::max() - 2;
65 bool operator==(
const PacketId& other)
const {
66 return packet_id == other.packet_id && copy_id == other.copy_id;
69 bool operator!=(
const PacketId& other)
const {
70 return !(*
this == other);
73 static PacketId make(uint64_t packet_id, uint64_t copy_id) {
74 return {packet_id, copy_id};
78 static void init_debugger(
const std::string &addr, device_id_t device_id);
80 static DebuggerIface *get() {
85 static std::string get_addr();
87 static DebuggerIface *debugger;
89 static constexpr PacketId dummy_PacketId{0u, 0u};
97 using PacketId = Debugger::PacketId;
99 void notify_update(
const PacketId &packet_id,
100 uint64_t
id,
const char *bytes,
int nbits) {
101 notify_update_(packet_id,
id, bytes, nbits);
104 void notify_update(
const PacketId &packet_id,
105 uint64_t
id, uint32_t v) {
106 notify_update_(packet_id,
id, v);
109 void notify_ctr(
const PacketId &packet_id, uint32_t ctr) {
110 notify_ctr_(packet_id, ctr);
113 void packet_in(
const PacketId &packet_id,
int port) {
114 packet_in_(packet_id, port);
117 void packet_out(
const PacketId &packet_id,
int port) {
118 packet_out_(packet_id, port);
121 void config_change() {
125 std::string get_addr()
const {
133 virtual void notify_update_(
const PacketId &packet_id, uint64_t
id,
134 const char *bytes,
int nbits) = 0;
136 virtual void notify_update_(
const PacketId &packet_id, uint64_t
id,
139 virtual void notify_ctr_(
const PacketId &packet_id, uint32_t ctr) = 0;
141 virtual void packet_in_(
const PacketId &packet_id,
int port) = 0;
143 virtual void packet_out_(
const PacketId &packet_id,
int port) = 0;
145 virtual void config_change_() = 0;
147 virtual std::string get_addr_()
const = 0;
151#define DEBUGGER_NOTIFY_UPDATE(packet_id, id, bytes, nbits) \
152 Debugger::get()->notify_update(packet_id, id, bytes, nbits);
153#define DEBUGGER_NOTIFY_UPDATE_V(packet_id, id, v) \
154 Debugger::get()->notify_update(packet_id, id, v);
155#define DEBUGGER_NOTIFY_CTR(packet_id, ctr) \
156 Debugger::get()->notify_ctr(packet_id, ctr);
157#define DEBUGGER_PACKET_IN(packet_id, port) \
158 Debugger::get()->packet_in(packet_id, port);
159#define DEBUGGER_PACKET_OUT(packet_id, port) \
160 Debugger::get()->packet_out(packet_id, port);
162#define DEBUGGER_NOTIFY_UPDATE(packet_id, id, bytes, nbits)
163#define DEBUGGER_NOTIFY_UPDATE_V(packet_id, id, v)
164#define DEBUGGER_NOTIFY_CTR(packet_id, ctr)
165#define DEBUGGER_PACKET_IN(packet_id, port)
166#define DEBUGGER_PACKET_OUT(packet_id, port)