Skip to content

Commit

Permalink
Deprecate .txt, support .txtpb
Browse files Browse the repository at this point in the history
  • Loading branch information
fruffy committed Jan 23, 2024
1 parent c11d28e commit 4bd4aff
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions backends/p4test/run-p4-sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ def process_file(options, argv):
ppfile = tmpdir + "/" + basename # after parsing
referenceOutputs = ",".join(list(rename.keys()))
stderr = tmpdir + "/" + basename + "-stderr"
p4runtimeFile = tmpdir + "/" + basename + ".p4info.txt"
p4runtimeEntriesFile = tmpdir + "/" + basename + ".entries.txt"
p4runtimeFile = tmpdir + "/" + basename + ".p4info.txtpb"
p4runtimeEntriesFile = tmpdir + "/" + basename + ".entries.txtpb"

# Create the `json_outputs` directory if it doesn't already exist. There's a
# race here since multiple tests may run this code in parallel, so we can't
Expand Down
17 changes: 11 additions & 6 deletions control-plane/p4RuntimeSerializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,24 @@ limitations under the License.
*/
#include "p4RuntimeSerializer.h"


#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wpedantic"
#include <google/protobuf/text_format.h>
#include <google/protobuf/util/json_util.h>
#pragma GCC diagnostic pop

#include <algorithm>
#include <iostream>
#include <iterator>
#include <optional>
#include <set>
#include <typeinfo>
#include <unordered_map>
#include <utility>
#include <vector>

#include "lib/error.h"

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wpedantic"
Expand All @@ -53,14 +54,11 @@ limitations under the License.
#include "frontends/p4/externInstance.h"
#include "frontends/p4/fromv1.0/v1model.h"
#include "frontends/p4/methodInstance.h"
#include "frontends/p4/parseAnnotations.h"
#include "frontends/p4/simplify.h"
#include "frontends/p4/typeChecking/typeChecker.h"
#include "frontends/p4/typeMap.h"
#include "ir/ir.h"
#include "lib/log.h"
#include "lib/nullstream.h"
#include "lib/ordered_set.h"
#include "p4RuntimeAnnotations.h"
#include "p4RuntimeArchHandler.h"
#include "p4RuntimeArchStandard.h"
Expand Down Expand Up @@ -1469,6 +1467,7 @@ void P4RuntimeAPI::serializeP4InfoTo(std::ostream *destination, P4RuntimeFormat
case P4RuntimeFormat::JSON:
success = writers::writeJsonTo(*p4Info, destination);
break;
case P4RuntimeFormat::TEXT_PROTOBUF:
case P4RuntimeFormat::TEXT:
success = writers::writeTextTo(*p4Info, destination);
break;
Expand All @@ -1488,6 +1487,7 @@ void P4RuntimeAPI::serializeEntriesTo(std::ostream *destination, P4RuntimeFormat
case P4RuntimeFormat::JSON:
success = writers::writeJsonTo(*entries, destination);
break;
case P4RuntimeFormat::TEXT_PROTOBUF:
case P4RuntimeFormat::TEXT:
success = writers::writeTextTo(*entries, destination);
break;
Expand Down Expand Up @@ -1515,7 +1515,11 @@ static bool parseFileNames(cstring fileNameVector, std::vector<cstring> &files,
formats.push_back(P4::P4RuntimeFormat::JSON);
} else if (suffix == ".bin") {
formats.push_back(P4::P4RuntimeFormat::BINARY);
} else if (suffix == ".txtpb") {
formats.push_back(P4::P4RuntimeFormat::TEXT_PROTOBUF);
} else if (suffix == ".txt") {
::warning(ErrorType::WARN_DEPRECATED,
".txt format is being deprecated; use .txtpb instead");
formats.push_back(P4::P4RuntimeFormat::TEXT);
} else {
::error(ErrorType::ERR_UNKNOWN,
Expand All @@ -1525,7 +1529,8 @@ static bool parseFileNames(cstring fileNameVector, std::vector<cstring> &files,
}
} else {
::error(ErrorType::ERR_UNKNOWN,
"%1%: unknown file kind; known suffixes are .bin, .txt, .json", name);
"%1%: unknown file kind; known suffixes are .bin, .txt, .json, and .txtpb",
name);
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion control-plane/p4RuntimeSerializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class CompilerOptions;
namespace P4 {

/// P4Runtime serialization formats.
enum class P4RuntimeFormat { BINARY, JSON, TEXT };
enum class P4RuntimeFormat { BINARY, JSON, TEXT, TEXT_PROTOBUF };

/// A P4 program's control-plane API, represented in terms of P4Runtime's data
/// structures. Can be inspected or serialized.
Expand Down

0 comments on commit 4bd4aff

Please sign in to comment.