Skip to content

Commit

Permalink
Generate JSON actions and keys fields array even when they are empty (#…
Browse files Browse the repository at this point in the history
…5022)

* Generate JSON actions and keys fields array even when they are empty

Generate JSON actions, keys fields array even when they are empty
Also generate keysize = 0 whenever the keysize is zero instead of
omitting it from the JSON

Signed-off-by: Victor Nogueira <[email protected]>

* Adapt generated samples to JSON change

Signed-off-by: Victor Nogueira <[email protected]>

---------

Signed-off-by: Victor Nogueira <[email protected]>
  • Loading branch information
vbnogueira authored Nov 20, 2024
1 parent e66525a commit 8273608
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 14 deletions.
15 changes: 6 additions & 9 deletions backends/tc/introspection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,25 +307,22 @@ Util::JsonObject *IntrospectionGenerator::genTableInfo(struct TableAttributes *t
tableJson->emplace("tentries", tbl->tentries);
tableJson->emplace("permissions", tbl->permissions);
tableJson->emplace("nummask", tbl->numMask);
if (tbl->keysize != 0) {
tableJson->emplace("keysize", tbl->keysize);
}
tableJson->emplace("keysize", tbl->keysize);

auto keysJson = new Util::JsonArray();
for (auto keyField : tbl->keyFields) {
auto keyJson = genKeyInfo(keyField);
keysJson->append(keyJson);
}
if (keysJson->size() != 0) {
tableJson->emplace("keyfields", keysJson);
}
tableJson->emplace("keyfields", keysJson);

auto actionsJson = new Util::JsonArray();
for (auto action : tbl->actions) {
auto actionJson = genActionInfo(action);
actionsJson->append(actionJson);
}
if (actionsJson->size() != 0) {
tableJson->emplace("actions", actionsJson);
}
tableJson->emplace("actions", actionsJson);

return tableJson;
}

Expand Down
3 changes: 2 additions & 1 deletion testdata/p4tc_samples_outputs/default_action_example_01.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
"match_type" : "exact",
"bitwidth" : 8
}
]
],
"actions" : []
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@
"match_type" : "exact",
"bitwidth" : 13
}
]
],
"actions" : []
},
{
"name" : "MainControlImpl/set_ct_options",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@
"match_type" : "exact",
"bitwidth" : 13
}
]
],
"actions" : []
},
{
"name" : "MainControlImpl/set_ct_options",
Expand Down
3 changes: 2 additions & 1 deletion testdata/p4tc_samples_outputs/noaction_example_02.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
"match_type" : "exact",
"bitwidth" : 3
}
]
],
"actions" : []
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
"match_type" : "exact",
"bitwidth" : 3
}
]
],
"actions" : []
}
]
}

0 comments on commit 8273608

Please sign in to comment.