use of org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener in project open-smart-grid-platform by OSGP.
the class DlmsConnectionFactoryTest method createsConnectionManagerForLls0Device.
@Test
void createsConnectionManagerForLls0Device() throws Exception {
final DlmsDevice device = new DlmsDeviceBuilder().withLls1Active(false).build();
final DlmsMessageListener listener = new InvocationCountingDlmsMessageListener();
when(this.lls0Connector.connect(this.messageMetadata, device, listener)).thenReturn(this.connection);
final DlmsConnectionManager expected = this.newConnectionManager(device, listener, this.lls0Connector);
this.factory.createAndHandleConnection(this.messageMetadata, device, listener, this.task);
this.assertConnectionManagerForDevice(expected);
}
use of org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener in project open-smart-grid-platform by OSGP.
the class DlmsConnectionFactoryTest method createAndHandleConnectionThrowsForHls3Device.
@Test
void createAndHandleConnectionThrowsForHls3Device() {
final DlmsDevice device = new DlmsDeviceBuilder().withHls3Active(true).build();
final DlmsMessageListener listener = new InvocationCountingDlmsMessageListener();
assertThatExceptionOfType(FunctionalException.class).isThrownBy(() -> this.factory.createAndHandleConnection(this.messageMetadata, device, listener, this.task));
}
use of org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener in project open-smart-grid-platform by OSGP.
the class RecoverKeyProcess method canConnectUsingNewKeys.
private boolean canConnectUsingNewKeys(final DlmsDevice device) {
DlmsConnection connection = null;
InvocationCountingDlmsMessageListener dlmsMessageListener = null;
Permit permit = null;
try {
// before starting the recovery process check if there are still keys with status NEW
final boolean hasNewSecret = this.secretManagementService.hasNewSecret(this.messageMetadata, this.deviceIdentification);
if (!hasNewSecret) {
log.warn("[{}] Device {} has no NEW key to use in KeyRecovery process", this.messageMetadata.getCorrelationUid(), this.deviceIdentification);
return false;
}
if (this.throttlingClientConfig.clientEnabled()) {
permit = this.throttlingClientConfig.throttlingClient().requestPermitUsingNetworkSegmentIfIdsAreAvailable(this.messageMetadata.getBaseTransceiverStationId(), this.messageMetadata.getCellId());
} else {
this.throttlingService.openConnection();
}
if (device.needsInvocationCounter()) {
dlmsMessageListener = new InvocationCountingDlmsMessageListener();
}
this.domainHelperService.setIpAddressFromMessageMetadataOrSessionProvider(device, this.messageMetadata);
connection = this.hls5Connector.connectUnchecked(this.messageMetadata, device, dlmsMessageListener, this.secretManagementService::getNewOrActiveKeyPerSecretType);
return connection != null;
} catch (final ThrottlingPermitDeniedException e) {
throw e;
} catch (final Exception e) {
log.warn("Connection exception during key recovery process for device: {} {}", device.getDeviceIdentification(), e.getMessage(), e);
return false;
} finally {
if (connection != null) {
try {
connection.close();
} catch (final IOException e) {
log.warn("Closing connection exception: {}", e.getMessage(), e);
}
}
if (this.throttlingClientConfig.clientEnabled()) {
if (permit != null) {
this.throttlingClientConfig.throttlingClient().releasePermit(permit);
}
} else {
this.throttlingService.closeConnection();
}
if (dlmsMessageListener != null) {
final int numberOfSentMessages = dlmsMessageListener.getNumberOfSentMessages();
device.incrementInvocationCounter(numberOfSentMessages);
this.deviceRepository.save(device);
}
}
}
use of org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener in project open-smart-grid-platform by OSGP.
the class DlmsConnectionHelperTest method initializesInvocationCounterWhenInvocationCounterIsOutOfSyncForIskraDevice.
@Test
void initializesInvocationCounterWhenInvocationCounterIsOutOfSyncForIskraDevice() throws Exception {
final DlmsDevice device = new DlmsDeviceBuilder().withHls5Active(true).withProtocol("SMR").withInvocationCounter(123L).build();
final DlmsMessageListener listener = new InvocationCountingDlmsMessageListener();
final ConnectionException exception = new ConnectionException("Error creating connection for device E0033006878667817 with Ip address:62.133.86.119 Port:4059 " + "UseHdlc:false UseSn:false Message:UNKNOWN: Received an association response (AARE) with an" + " error message. Result name REJECTED_PERMANENT. Assumed fault: user.");
doThrow(exception).when(this.connectionFactory).createAndHandleConnection(this.messageMetadata, device, listener, null, this.task);
assertThrows(ConnectionException.class, () -> this.helper.createAndHandleConnectionForDevice(this.messageMetadata, device, listener, null, this.task));
verify(this.invocationCounterManager).initializeInvocationCounter(this.messageMetadata, device);
verify(this.connectionFactory, times(2)).createAndHandleConnection(this.messageMetadata, device, listener, null, this.task);
}
use of org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener in project open-smart-grid-platform by OSGP.
the class DlmsConnectionHelperTest method createsConnectionForDeviceThatNeedsInvocationCounterWithInvocationCounterInitialized.
@Test
void createsConnectionForDeviceThatNeedsInvocationCounterWithInvocationCounterInitialized() throws Exception {
final DlmsDevice device = new DlmsDeviceBuilder().withHls5Active(true).withInvocationCounter(123L).build();
final DlmsMessageListener listener = new InvocationCountingDlmsMessageListener();
doNothing().when(this.connectionFactory).createAndHandleConnection(this.messageMetadata, device, listener, null, this.task);
this.helper.createAndHandleConnectionForDevice(this.messageMetadata, device, listener, this.task);
verifyNoMoreInteractions(this.invocationCounterManager);
}
Aggregations