bmv2
Designing your own switch target with bmv2
Loading...
Searching...
No Matches
event_logger.h
Go to the documentation of this file.
1/* Copyright 2013-present Barefoot Networks, Inc.
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16/*
17 * Antonin Bas (antonin@barefootnetworks.com)
18 *
19 */
20
22
23#ifndef BM_BM_SIM_EVENT_LOGGER_H_
24#define BM_BM_SIM_EVENT_LOGGER_H_
25
26#include <bm/config.h>
27
28#include <memory>
29#include <string>
30#include <utility>
31
32#include "device_id.h"
33#include "phv_forward.h"
34#include "transport.h"
35
36namespace bm {
37
38class Packet;
39
40// Forward declarations of P4 object classes. This is ugly, but:
41// 1) I don't have to worry about circular dependencies
42// 2) If I decide to switch from id to name for msgs, I won't have to modify the
43// EventLogger interface
44class Parser;
45class Deparser;
46class MatchTableAbstract;
47class MatchEntry;
48class ActionFn;
49struct ActionData;
50class Conditional;
51class Checksum;
52class Pipeline;
53
54using entry_handle_t = uint32_t;
55
70 public:
71 explicit EventLogger(std::unique_ptr<TransportIface> transport,
72 device_id_t device_id = 0)
73 : transport_instance(std::move(transport)), device_id(device_id) { }
74
75 // we need the ingress / egress ports, but they are part of the Packet
77 void packet_in(const Packet &packet);
79 void packet_out(const Packet &packet);
80
81 void parser_start(const Packet &packet, const Parser &parser);
82 void parser_done(const Packet &packet, const Parser &parser);
83 void parser_extract(const Packet &packet, header_id_t header);
84
85 void deparser_start(const Packet &packet, const Deparser &deparser);
86 void deparser_done(const Packet &packet, const Deparser &deparser);
87 void deparser_emit(const Packet &packet, header_id_t header);
88
89 void checksum_update(const Packet &packet, const Checksum &checksum);
90
91 void pipeline_start(const Packet &packet, const Pipeline &pipeline);
92 void pipeline_done(const Packet &packet, const Pipeline &pipeline);
93
94 void condition_eval(const Packet &packet,
95 const Conditional &cond, bool result);
96 void table_hit(const Packet &packet,
97 const MatchTableAbstract &table, entry_handle_t handle);
98 void table_miss(const Packet &packet, const MatchTableAbstract &table);
99
100 void action_execute(const Packet &packet,
101 const ActionFn &action_fn, const ActionData &action_data);
102
103 void config_change();
104
105 static EventLogger *get() {
106 static EventLogger event_logger(TransportIface::make_dummy());
107 return &event_logger;
108 }
109
110 static void init(std::unique_ptr<TransportIface> transport,
111 device_id_t device_id = 0) {
112 get()->transport_instance = std::move(transport);
113 get()->device_id = device_id;
114 }
115
116 private:
117 std::unique_ptr<TransportIface> transport_instance{nullptr};
118 device_id_t device_id{};
119};
120
121} // namespace bm
122
130#ifdef BM_ELOG_ON
131#define BMELOG(fn, ...) bm::EventLogger::get()->fn(__VA_ARGS__)
132#else
133#define BMELOG(fn, ...)
134#endif
135
136#endif // BM_BM_SIM_EVENT_LOGGER_H_
Definition deparser.h:50
Definition event_logger.h:69
void packet_in(const Packet &packet)
Signal that a packet was received by the switch.
void packet_out(const Packet &packet)
Signal that a packet was transmitted by the switch.
Definition packet.h:98
Implements a P4 parser.
Definition parser.h:324
Definition pipeline.h:36