P4C
The P4 Compiler
Loading...
Searching...
No Matches
p4RuntimeSerializer.h
1/*
2Copyright 2013-present Barefoot Networks, Inc.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17#ifndef CONTROL_PLANE_P4RUNTIMESERIALIZER_H_
18#define CONTROL_PLANE_P4RUNTIMESERIALIZER_H_
19
20#pragma GCC diagnostic push
21#pragma GCC diagnostic ignored "-Wunused-parameter"
22#pragma GCC diagnostic ignored "-Wpedantic"
23#include <google/protobuf/util/json_util.h>
24#pragma GCC diagnostic pop
25
26#include <iosfwd>
27#include <unordered_map>
28
29#include "lib/cstring.h"
30#include "p4RuntimeTypes.h"
31
32namespace p4 {
33namespace config {
34namespace v1 {
35class P4Info;
36} // namespace v1
37} // namespace config
38namespace v1 {
39class WriteRequest;
40} // namespace v1
41} // namespace p4
42
43namespace P4::IR {
44class P4Program;
45} // namespace P4::IR
46
47namespace P4 {
48class CompilerOptions;
49} // namespace P4
50
51namespace P4 {
52
53using namespace literals;
54
60 void serializeP4InfoTo(std::ostream *destination, P4RuntimeFormat format) const;
63 void serializeEntriesTo(std::ostream *destination, P4RuntimeFormat format) const;
64
67 const ::p4::config::v1::P4Info *p4Info;
70 const ::p4::v1::WriteRequest *entries;
71
72 // Print options to use while outputting JSON.
73 google::protobuf::util::JsonPrintOptions jsonPrintOptions;
74
75 P4RuntimeAPI(const ::p4::config::v1::P4Info *p4Info, const ::p4::v1::WriteRequest *entries)
77 jsonPrintOptions.add_whitespace = true;
78 }
79
80 P4RuntimeAPI(const ::p4::config::v1::P4Info *p4Info, const ::p4::v1::WriteRequest *entries,
81 google::protobuf::util::JsonPrintOptions jsonPrintOptions)
82 : p4Info(p4Info), entries(entries), jsonPrintOptions(jsonPrintOptions) {}
83};
84
85namespace ControlPlaneAPI {
86struct P4RuntimeArchHandlerBuilderIface;
87} // namespace ControlPlaneAPI
88
91 public:
92 static P4RuntimeSerializer *get();
93
94 void registerArch(const cstring archName,
96
109 P4RuntimeAPI generateP4Runtime(const IR::P4Program *program, cstring arch);
110
120 void serializeP4RuntimeIfRequired(const IR::P4Program *program, const CompilerOptions &options);
121
130 void serializeP4RuntimeIfRequired(const P4RuntimeAPI &p4Runtime,
131 const CompilerOptions &options);
132
135 static cstring resolveArch(const CompilerOptions &options);
136
137 private:
139
140 std::unordered_map<cstring, const ControlPlaneAPI::P4RuntimeArchHandlerBuilderIface *>
141 archHandlerBuilders{};
142};
143
146P4RuntimeAPI generateP4Runtime(const IR::P4Program *program, cstring arch = "v1model"_cs);
147
150void serializeP4RuntimeIfRequired(const IR::P4Program *program, const CompilerOptions &options);
151
152} // namespace P4
153
154#endif /* CONTROL_PLANE_P4RUNTIMESERIALIZER_H_ */
Definition frontends/common/options.h:30
Public APIs to generate P4Info message. Uses the singleton pattern.
Definition p4RuntimeSerializer.h:90
Definition cstring.h:85
static cstring resolveArch(const CompilerOptions &options)
Definition p4RuntimeSerializer.cpp:1662
void serializeP4InfoTo(std::ostream *destination, P4RuntimeFormat format) const
Definition p4RuntimeSerializer.cpp:1506
P4RuntimeAPI generateP4Runtime(const IR::P4Program *program, cstring arch)
Definition p4RuntimeSerializer.cpp:1677
void serializeP4RuntimeIfRequired(const IR::P4Program *program, const CompilerOptions &options)
Definition p4RuntimeSerializer.cpp:1583
P4RuntimeAPI generateP4Runtime(const IR::P4Program *program, cstring arch)
Definition p4RuntimeSerializer.cpp:1470
void serializeP4RuntimeIfRequired(const IR::P4Program *program, const CompilerOptions &options)
Definition p4RuntimeSerializer.cpp:1681
void serializeEntriesTo(std::ostream *destination, P4RuntimeFormat format) const
Definition p4RuntimeSerializer.cpp:1527
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
P4RuntimeFormat
P4Runtime serialization formats.
Definition p4RuntimeTypes.h:23
Definition p4RuntimeArchHandler.h:204
Definition p4RuntimeSerializer.h:57
const ::p4::config::v1::P4Info * p4Info
Definition p4RuntimeSerializer.h:67
const ::p4::v1::WriteRequest * entries
Definition p4RuntimeSerializer.h:70