diff --git a/backend/api/endpoints/init.py b/backend/api/endpoints/init.py index 0bbbece..31d83a1 100644 --- a/backend/api/endpoints/init.py +++ b/backend/api/endpoints/init.py @@ -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']) @@ -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: @@ -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 + \ No newline at end of file diff --git a/frontend/src/Components/Helpers/Decoding/DecodingHelper.js b/frontend/src/Components/Helpers/Decoding/DecodingHelper.js index 02fe29c..1f80d4a 100644 --- a/frontend/src/Components/Helpers/Decoding/DecodingHelper.js +++ b/frontend/src/Components/Helpers/Decoding/DecodingHelper.js @@ -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]) ?? ""); }); } diff --git a/frontend/src/Contexts/InitContext.js b/frontend/src/Contexts/InitContext.js index 82ed445..4932cb1 100644 --- a/frontend/src/Contexts/InitContext.js +++ b/frontend/src/Contexts/InitContext.js @@ -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, @@ -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);