Skip to content

Commit

Permalink
Merge pull request #7 from uni-tue-kn/dev
Browse files Browse the repository at this point in the history
Fixes two crashes when the structure of MATs is changed and an existing state is reloaded from history
  • Loading branch information
MoritzFlu authored Nov 11, 2024
2 parents a91c949 + 7329e34 commit df39802
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
20 changes: 16 additions & 4 deletions backend/api/endpoints/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ def post(self):
p4_info_file_arg = args['p4_info_file']
bmv2_file_arg = args['bmv2_file']
state_id_arg = args['state_id']

warning_msg = ""

try:
self.controller.initialize(switch_id = switch_id_arg, p4_info_file = p4_info_file_arg, bmv2_file = bmv2_file_arg, keep_entries = args['keep_entries'])
Expand Down Expand Up @@ -65,9 +67,18 @@ def post(self):

# re-write the old entries to the switch
table_entries = reinitialized_state.table_entries
changed_tables = []
for table in table_entries:
for entry in table_entries[table]:
self.controller.postTableEntry(switch_id = switch_id_arg, entry = entry["switch_entry"], is_json = False)
try:
self.controller.postTableEntry(switch_id = switch_id_arg, entry = entry["switch_entry"], is_json = False)
except grpc.RpcError:
changed_tables.append(table)
# Skip this table
continue
if changed_tables:
changed_tables_string = ", ".join(changed_tables)
warning_msg += f"MAT structure of tables {changed_tables_string} changed from saved state. Entries are not loaded."

# state doesnt exist -> create a new one
else:
Expand Down Expand Up @@ -96,6 +107,7 @@ def post(self):
return f"Failed to initialize Switch. GRPC Connection is not available: {e}", 500
except Exception as e:
return f"An error occured during switch initialization: {e}", 500




if warning_msg:
return warning_msg, 200

3 changes: 2 additions & 1 deletion frontend/src/Components/Helpers/Decoding/DecodingHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ export function decodeTableEntries(tableEntries, decoding, tableInfo, tableName)
//Decode action values
if (switch_entry.action_params != null) {
Object.entries(switch_entry.action_params).forEach(([param, value]) => {
switch_entry.action_params[param] = decode(value, tableDecoding.action[switch_entry.action_name][param]);
// Default to numerical decoding if there is no decode entry present
switch_entry.action_params[param] = decode(value, (tableDecoding.action[switch_entry.action_name]?.[param]) ?? "");
});
}

Expand Down
9 changes: 6 additions & 3 deletions frontend/src/Contexts/InitContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export function InitProvider({ children }) {
useEffect(updateInitializedFiles, [currentSwitchID]);

function initialize(event, p4_info_file, bmv2_file, keep_entries = false, id = null) {
console.log(id);
axios
.post("/init", {
switch_id:currentSwitchID,
Expand All @@ -47,9 +46,13 @@ export function InitProvider({ children }) {
keep_entries: keep_entries,
state_id: id
})
.then(() => {
.then(res => {
if (res.data){
callSnackbar("warning", "Initialization was successful! " + res.data);
} else {
callSnackbar("success", "Initialization was successful!");
}
updateInitializedFiles();
callSnackbar("success", "Initialization was successful!");
})
.catch(err => {
console.log(err);
Expand Down

0 comments on commit df39802

Please sign in to comment.