Loading src/automation/src/main/java/eu/teraflow/automation/AutomationServiceImpl.java +44 −28 Original line number Diff line number Diff line Loading @@ -50,7 +50,11 @@ public class AutomationServiceImpl implements AutomationService { device -> { final var id = deviceId; if (!device.isEnabled()) { if (device.isEnabled()) { LOGGER.warnf("%s has already been enabled. Ignoring...", device); return; } LOGGER.infof(MESSAGE, device); final var initialConfiguration = Loading @@ -71,12 +75,9 @@ public class AutomationServiceImpl implements AutomationService { .with( configuredDeviceId -> LOGGER.infof( "Device [%s] has been enabled and configured successfully with %s.\n", "Device [%s] has been successfully enabled and configured with %s.\n", id, deviceConfig)); }); } else { LOGGER.infof("%s has been already enabled. Ignoring...", device); } }); return deserializedDeviceUni; Loading @@ -92,13 +93,23 @@ public class AutomationServiceImpl implements AutomationService { device -> { final var id = deviceId; if (device.isDisabled()) { LOGGER.warnf("%s has already been disabled. Ignoring...", device); return; } device.disableDevice(); LOGGER.infof("Disabled device [%s]", id); LOGGER.infof(MESSAGE, device); final var empty = deviceService.deleteDevice(device.getDeviceId()); empty .subscribe() .with(emptyMessage -> LOGGER.infof("Device [%s] has been deleted.\n", id)); .with( emptyMessage -> LOGGER.infof("Device [%s] has been successfully deleted.\n", id)); }); return deserializedDeviceUni; Loading @@ -114,6 +125,11 @@ public class AutomationServiceImpl implements AutomationService { device -> { final var id = deviceId; if (!device.isEnabled()) { LOGGER.warnf("Cannot update disabled device %s. Ignoring...", device); return; } LOGGER.infof(MESSAGE, device); device.setDeviceConfiguration(deviceConfig); final var updatedDeviceIdUni = deviceService.configureDevice(device); Loading @@ -123,7 +139,7 @@ public class AutomationServiceImpl implements AutomationService { .with( configuredDeviceId -> LOGGER.infof( "Device [%s] has been updated successfully with %s.\n", "Device [%s] has been successfully updated with %s.\n", id, deviceConfig)); }); Loading src/automation/src/main/java/eu/teraflow/automation/ContextSubscriber.java +5 −3 Original line number Diff line number Diff line Loading @@ -78,9 +78,11 @@ public class ContextSubscriber { automationService.deleteDevice(deviceEvent.getDeviceId()); break; case UPDATE: LOGGER.infof("Received %s for device [%s]", event, deviceId); automationService.updateDevice( deviceEvent.getDeviceId(), deviceEvent.getDeviceConfig().orElse(null)); LOGGER.warnf( "Received %s for device [%s]. " + "No automation action on an already updated device", event, deviceId); break; case UNDEFINED: logWarningMessage(event, deviceId, eventType); break; Loading src/automation/src/main/java/eu/teraflow/automation/context/model/Device.java +8 −0 Original line number Diff line number Diff line Loading @@ -61,10 +61,18 @@ public class Device { return deviceOperationalStatus == DeviceOperationalStatus.ENABLED; } public boolean isDisabled() { return deviceOperationalStatus == DeviceOperationalStatus.DISABLED; } public void enableDevice() { this.deviceOperationalStatus = DeviceOperationalStatus.ENABLED; } public void disableDevice() { this.deviceOperationalStatus = DeviceOperationalStatus.DISABLED; } public String getDeviceId() { return deviceId; } Loading src/device/service/drivers/p4/p4_global_options.py +5 −3 Original line number Diff line number Diff line Loading @@ -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. """ } Loading Loading @@ -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_ src/device/service/drivers/p4/p4_manager.py +2 −20 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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 Loading Loading @@ -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) Loading @@ -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) Loading Loading @@ -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: Loading Loading
src/automation/src/main/java/eu/teraflow/automation/AutomationServiceImpl.java +44 −28 Original line number Diff line number Diff line Loading @@ -50,7 +50,11 @@ public class AutomationServiceImpl implements AutomationService { device -> { final var id = deviceId; if (!device.isEnabled()) { if (device.isEnabled()) { LOGGER.warnf("%s has already been enabled. Ignoring...", device); return; } LOGGER.infof(MESSAGE, device); final var initialConfiguration = Loading @@ -71,12 +75,9 @@ public class AutomationServiceImpl implements AutomationService { .with( configuredDeviceId -> LOGGER.infof( "Device [%s] has been enabled and configured successfully with %s.\n", "Device [%s] has been successfully enabled and configured with %s.\n", id, deviceConfig)); }); } else { LOGGER.infof("%s has been already enabled. Ignoring...", device); } }); return deserializedDeviceUni; Loading @@ -92,13 +93,23 @@ public class AutomationServiceImpl implements AutomationService { device -> { final var id = deviceId; if (device.isDisabled()) { LOGGER.warnf("%s has already been disabled. Ignoring...", device); return; } device.disableDevice(); LOGGER.infof("Disabled device [%s]", id); LOGGER.infof(MESSAGE, device); final var empty = deviceService.deleteDevice(device.getDeviceId()); empty .subscribe() .with(emptyMessage -> LOGGER.infof("Device [%s] has been deleted.\n", id)); .with( emptyMessage -> LOGGER.infof("Device [%s] has been successfully deleted.\n", id)); }); return deserializedDeviceUni; Loading @@ -114,6 +125,11 @@ public class AutomationServiceImpl implements AutomationService { device -> { final var id = deviceId; if (!device.isEnabled()) { LOGGER.warnf("Cannot update disabled device %s. Ignoring...", device); return; } LOGGER.infof(MESSAGE, device); device.setDeviceConfiguration(deviceConfig); final var updatedDeviceIdUni = deviceService.configureDevice(device); Loading @@ -123,7 +139,7 @@ public class AutomationServiceImpl implements AutomationService { .with( configuredDeviceId -> LOGGER.infof( "Device [%s] has been updated successfully with %s.\n", "Device [%s] has been successfully updated with %s.\n", id, deviceConfig)); }); Loading
src/automation/src/main/java/eu/teraflow/automation/ContextSubscriber.java +5 −3 Original line number Diff line number Diff line Loading @@ -78,9 +78,11 @@ public class ContextSubscriber { automationService.deleteDevice(deviceEvent.getDeviceId()); break; case UPDATE: LOGGER.infof("Received %s for device [%s]", event, deviceId); automationService.updateDevice( deviceEvent.getDeviceId(), deviceEvent.getDeviceConfig().orElse(null)); LOGGER.warnf( "Received %s for device [%s]. " + "No automation action on an already updated device", event, deviceId); break; case UNDEFINED: logWarningMessage(event, deviceId, eventType); break; Loading
src/automation/src/main/java/eu/teraflow/automation/context/model/Device.java +8 −0 Original line number Diff line number Diff line Loading @@ -61,10 +61,18 @@ public class Device { return deviceOperationalStatus == DeviceOperationalStatus.ENABLED; } public boolean isDisabled() { return deviceOperationalStatus == DeviceOperationalStatus.DISABLED; } public void enableDevice() { this.deviceOperationalStatus = DeviceOperationalStatus.ENABLED; } public void disableDevice() { this.deviceOperationalStatus = DeviceOperationalStatus.DISABLED; } public String getDeviceId() { return deviceId; } Loading
src/device/service/drivers/p4/p4_global_options.py +5 −3 Original line number Diff line number Diff line Loading @@ -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. """ } Loading Loading @@ -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_
src/device/service/drivers/p4/p4_manager.py +2 −20 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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 Loading Loading @@ -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) Loading @@ -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) Loading Loading @@ -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: Loading