Skip to content

Commit

Permalink
Fixes to extra checks on JSON data
Browse files Browse the repository at this point in the history
Tables with type indirect and indirect_ws need not have a key
"default_entry".  The p4c BMv2 backend warns about such tables
(i.e. those with implementation equal to action_profile or
action_selector) that the target does not support default_action for
them.

Signed-off-by: Andy Fingerhut <[email protected]>
  • Loading branch information
jafingerhut committed Jan 14, 2025
1 parent c660463 commit 4b660ec
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/bm_sim/P4Objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1920,6 +1920,12 @@ P4Objects::init_pipelines(const Json::Value &cfg_root,
const auto table_type = cfg_table["type"].asString();

const auto &cfg_default_entry = cfg_table["default_entry"];
if (!cfg_default_entry.isMember("action_id")) {
throw json_exception(
EFormat() << "'default_entry' of table '" << table_name
<< "' must have key 'action_id'",
cfg_default_entry);
}
const p4object_id_t action_id = cfg_default_entry["action_id"].asInt();
const ActionFn *action = get_action_by_id(action_id); assert(action);

Expand Down Expand Up @@ -1949,15 +1955,18 @@ P4Objects::init_pipelines(const Json::Value &cfg_root,
is_action_entry_const);
} else {
throw json_exception(
EFormat() << "'default_action' of table '" << table_name
<< "' should have key 'action_data'",
EFormat() << "'default_entry' of table '" << table_name
<< "' must have key 'action_data'",
cfg_default_entry);
}
} else {
throw json_exception(
EFormat() << "Table '" << table_name << "' should have key"
<< " 'default_action'",
cfg_table);
const auto table_type = cfg_table["type"].asString();
if ((table_type != "indirect") && (table_type != "indirect_ws")) {
throw json_exception(
EFormat() << "Table '" << table_name << "' with type '"
<< table_type << "' must have key" << " 'default_entry'",
cfg_table);
}
}

// for 'simple' tables, it is possible to specify immutable entries
Expand Down

0 comments on commit 4b660ec

Please sign in to comment.