Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[P4_Symbolic] Adding p4_symbolic/symbolic/parser.h [Evaluate parsers symbolically.] #823

Merged
merged 5 commits into from
Dec 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions p4_symbolic/symbolic/parser.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef PINS_P4_SYMBOLIC_SYMBOLIC_PARSER_H_
#define PINS_P4_SYMBOLIC_SYMBOLIC_PARSER_H_

#include "p4_symbolic/ir/ir.pb.h"
#include "p4_symbolic/symbolic/symbolic.h"
#include "z3++.h"

namespace p4_symbolic {
namespace symbolic {
namespace parser {

// Returns a Z3 bit-vector representing the `parser_error` field value of the
// given `error_name`.
absl::StatusOr<z3::expr> GetErrorCodeExpression(const ir::P4Program &program,
const std::string &error_name);

// Evaluates all parsers in the P4 program and returns a map of symbolic headers
// that captures the effect of parser execution given the `ingress_headers`.
//
// Returns error if a header field is not a free bit-vector variable upon
// extracting its header, which could mean the header is extracted twice. We
// require extracting to the same header happens at most once to avoid loops.
//
// If a parser error occurs, the `standard_metadata.parser_error` field will be
// set to the corresponding error code and the function returns immediately. The
// current implementation may only result in 2 types of parser error, NoError
// and NoMatch.
absl::StatusOr<SymbolicPerPacketState> EvaluateParsers(
const ir::P4Program &program,
const SymbolicPerPacketState &ingress_headers);

} // namespace parser
} // namespace symbolic
} // namespace p4_symbolic

#endif // PINS_P4_SYMBOLIC_SYMBOLIC_PARSER_H_
Loading