From fb997698849ea6905976063634b286cb6fdab521 Mon Sep 17 00:00:00 2001 From: "Georgios P. Katsikas" Date: Fri, 14 Oct 2022 17:05:53 +0300 Subject: [PATCH] fix(device): avoid conversion to canonical bytes Also, remove unecessary conditions prior to rule insert/update/delete operations Signed-off-by: Georgios P. Katsikas --- .../service/drivers/p4/p4_global_options.py | 8 ++++--- src/device/service/drivers/p4/p4_manager.py | 22 ++----------------- 2 files changed, 7 insertions(+), 23 deletions(-) diff --git a/src/device/service/drivers/p4/p4_global_options.py b/src/device/service/drivers/p4/p4_global_options.py index 86043b671..3457c8d55 100644 --- a/src/device/service/drivers/p4/p4_global_options.py +++ b/src/device/service/drivers/p4/p4_global_options.py @@ -42,7 +42,8 @@ class GlobalOptions: option_helpstrings = { Options.canonical_bytestrings: """ Use byte-padded legacy format for binary strings sent to the P4Runtime server, -instead of the canonical representation. See P4Runtime specification for details. +instead of the canonical representation. See P4Runtime specification for +details. """ } @@ -199,6 +200,7 @@ def make_canonical_if_option_set(bytes_): :return: canonical bytes """ - if GLOBAL_OPTIONS.get_option(Options.canonical_bytestrings): - return to_canonical_bytes(bytes_) + # TODO: Fix canonical representation issue + # if GLOBAL_OPTIONS.get_option(Options.canonical_bytestrings): + # return to_canonical_bytes(bytes_) return bytes_ diff --git a/src/device/service/drivers/p4/p4_manager.py b/src/device/service/drivers/p4/p4_manager.py index dc25e80b5..65f8602ea 100644 --- a/src/device/service/drivers/p4/p4_manager.py +++ b/src/device/service/drivers/p4/p4_manager.py @@ -175,9 +175,7 @@ def insert_table_entry_exact( try: table_entry.insert() LOGGER.info("Inserted exact table entry: %s", table_entry) - except P4RuntimeWriteException as ex: - ex_msg = str(ex) - except P4RuntimeException as ex: + except (P4RuntimeException, P4RuntimeWriteException) as ex: raise P4RuntimeException from ex # Table entry exists, needs to be modified @@ -230,9 +228,7 @@ def insert_table_entry_ternary( try: table_entry.insert() LOGGER.info("Inserted ternary table entry: %s", table_entry) - except P4RuntimeWriteException as ex: - ex_msg = str(ex) - except P4RuntimeException as ex: + except (P4RuntimeException, P4RuntimeWriteException) as ex: raise P4RuntimeException from ex # Table entry exists, needs to be modified @@ -893,10 +889,6 @@ class P4Manager: # Exact match is supported if get_table_type(table) == p4info_pb2.MatchField.EXACT: - if priority != 0: - msg = f"Table {table_name} is non-ternary, priority must be 0" - LOGGER.error(msg) - raise UserError(msg) return insert_table_entry_exact( table_name, match_map, action_name, action_params, metadata, cnt_pkt, cnt_byte) @@ -904,10 +896,6 @@ class P4Manager: # Ternary and LPM matches are supported if get_table_type(table) in \ [p4info_pb2.MatchField.TERNARY, p4info_pb2.MatchField.LPM]: - if priority == 0: - msg = f"Table {table_name} is ternary, priority must be != 0" - LOGGER.error(msg) - raise UserError(msg) return insert_table_entry_ternary( table_name, match_map, action_name, action_params, metadata, priority, cnt_pkt, cnt_byte) @@ -955,12 +943,6 @@ class P4Manager: for action_k, action_v in action_params.items(): table_entry.action[action_k] = action_v - if get_table_type(table) == p4info_pb2.MatchField.EXACT: - if priority != 0: - msg = f"Table {table_name} is non-ternary, priority must be 0" - LOGGER.error(msg) - raise UserError(msg) - if get_table_type(table) in \ [p4info_pb2.MatchField.TERNARY, p4info_pb2.MatchField.LPM]: if priority == 0: -- GitLab