use of com.alliander.osgp.oslp.OslpEnvelope in project Protocol-Adapter-OSLP by OSGP.
the class RegisterDevice method sendEventNotificationCommand.
public DeviceMessageStatus sendEventNotificationCommand(final Long id, final Integer event, final String description, final Integer index, final boolean hasTimestamp) {
// Find device.
Device device = this.deviceManagementService.findDevice(id);
if (device == null) {
// Set the DeviceMessageStatus NOT_FOUND as the device is not found.
return DeviceMessageStatus.NOT_FOUND;
}
this.errorMessage = "";
try {
// Set index when provided in request.
final int sequenceNumber = device.doGetNextSequence();
final String timestamp = this.getFormattedCurrentTimestamp();
final Oslp.Event oslpEvent = Oslp.Event.valueOf(event);
// Create request and write outgoing request to log.
final OslpEnvelope request = this.createEventNotificationRequest(device, sequenceNumber, oslpEvent, description, index, timestamp, hasTimestamp);
this.writeOslpLogItem(request, device, false);
// Send event notification message and receive response.
final OslpEnvelope response = this.sendRequest(device, request);
// Write incoming response to log.
this.writeOslpLogItem(response, device, true);
// Get the sequence number from the response envelope and check it.
this.checkSequenceNumber(response.getSequenceNumber(), sequenceNumber);
// Success, update the sequence number of the device.
device.setSequenceNumber(sequenceNumber);
device = this.deviceManagementService.updateDevice(device);
// Set the DeviceMessageStatus OK as the SendEvent is Success.
return DeviceMessageStatus.OK;
} catch (final Exception e) {
LOGGER.error("send event notification exception", e);
this.errorMessage = e.getMessage();
// successful.
return DeviceMessageStatus.FAILURE;
}
}
use of com.alliander.osgp.oslp.OslpEnvelope in project Protocol-Adapter-OSLP by OSGP.
the class RegisterDevice method sendConfirmDeviceRegistrationCommand.
public DeviceMessageStatus sendConfirmDeviceRegistrationCommand(final long deviceId) {
// Find device.
Device device = this.deviceManagementService.findDevice(deviceId);
if (device == null) {
// Set the DeviceMessageStatus NOT_FOUND as the device is not found.
return DeviceMessageStatus.NOT_FOUND;
}
this.errorMessage = "";
try {
final Integer sequenceNumber = device.doGetNextSequence();
// Create registration confirmation message.
final OslpEnvelope oslpRequest = this.createEnvelopeBuilder(device.getDeviceUid(), sequenceNumber).withPayloadMessage(Message.newBuilder().setConfirmRegisterDeviceRequest(Oslp.ConfirmRegisterDeviceRequest.newBuilder().setRandomDevice(device.getRandomDevice()).setRandomPlatform(device.getRandomPlatform())).build()).build();
// Write outgoing request to log.
this.writeOslpLogItem(oslpRequest, device, false);
final OslpEnvelope response = this.sendRequest(device, oslpRequest);
// Write incoming response to log.
this.writeOslpLogItem(response, device, true);
// Get the sequence number from the response envelope and check it.
this.checkSequenceNumber(response.getSequenceNumber(), sequenceNumber);
// Get the two random numbers and check them both.
this.checkRandomDeviceAndRandomPlatform(device.getRandomDevice(), response.getPayloadMessage().getConfirmRegisterDeviceResponse().getRandomDevice(), device.getRandomPlatform(), response.getPayloadMessage().getConfirmRegisterDeviceResponse().getRandomPlatform());
// Successful.
device.setSequenceNumber(sequenceNumber);
device = this.deviceManagementService.updateDevice(device);
// Check if there has been an out of sequence security event.
OutOfSequenceEvent outOfSequenceEvent = this.oslpChannelHandler.hasOutOfSequenceEventForDevice(device.getId());
while (outOfSequenceEvent != null) {
// An event has occurred, send
// SECURITY_EVENTS_OUT_OF_SEQUENCE_VALUE event notification.
this.sendEventNotificationCommand(outOfSequenceEvent.getDeviceId(), Oslp.Event.SECURITY_EVENTS_OUT_OF_SEQUENCE_VALUE, "out of sequence event occurred at time stamp: " + outOfSequenceEvent.getTimestamp().toString() + " for request: " + outOfSequenceEvent.getRequest(), null);
// Check if there has been another event, this will return null
// if no more events are present in the list.
outOfSequenceEvent = this.oslpChannelHandler.hasOutOfSequenceEventForDevice(device.getId());
}
// successful.
return DeviceMessageStatus.OK;
} catch (final Exception e) {
LOGGER.error("confirm device registration exception", e);
this.errorMessage = e.getMessage();
// is NOT successful.
return DeviceMessageStatus.FAILURE;
}
}
use of com.alliander.osgp.oslp.OslpEnvelope in project Protocol-Adapter-OSLP by OSGP.
the class CommonGetConfigurationRequestMessageProcessor method processSignedOslpEnvelope.
@Override
public void processSignedOslpEnvelope(final String deviceIdentification, final SignedOslpEnvelopeDto signedOslpEnvelopeDto) {
final UnsignedOslpEnvelopeDto unsignedOslpEnvelopeDto = signedOslpEnvelopeDto.getUnsignedOslpEnvelopeDto();
final OslpEnvelope oslpEnvelope = signedOslpEnvelopeDto.getOslpEnvelope();
final String correlationUid = unsignedOslpEnvelopeDto.getCorrelationUid();
final String organisationIdentification = unsignedOslpEnvelopeDto.getOrganisationIdentification();
final String domain = unsignedOslpEnvelopeDto.getDomain();
final String domainVersion = unsignedOslpEnvelopeDto.getDomainVersion();
final String messageType = unsignedOslpEnvelopeDto.getMessageType();
final String ipAddress = unsignedOslpEnvelopeDto.getIpAddress();
final int retryCount = unsignedOslpEnvelopeDto.getRetryCount();
final boolean isScheduled = unsignedOslpEnvelopeDto.isScheduled();
final DeviceResponseHandler deviceResponseHandler = new DeviceResponseHandler() {
@Override
public void handleResponse(final DeviceResponse deviceResponse) {
CommonGetConfigurationRequestMessageProcessor.this.handleGetConfigurationDeviceResponse(deviceResponse, CommonGetConfigurationRequestMessageProcessor.this.responseMessageSender, domain, domainVersion, messageType, retryCount);
}
@Override
public void handleException(final Throwable t, final DeviceResponse deviceResponse) {
CommonGetConfigurationRequestMessageProcessor.this.handleUnableToConnectDeviceResponse(deviceResponse, t, null, CommonGetConfigurationRequestMessageProcessor.this.responseMessageSender, deviceResponse, domain, domainVersion, messageType, isScheduled, retryCount);
}
};
final DeviceRequest deviceRequest = new DeviceRequest(organisationIdentification, deviceIdentification, correlationUid);
try {
this.deviceService.doGetConfiguration(oslpEnvelope, deviceRequest, deviceResponseHandler, ipAddress);
} catch (final IOException e) {
this.handleError(e, correlationUid, organisationIdentification, deviceIdentification, domain, domainVersion, messageType, retryCount);
}
}
use of com.alliander.osgp.oslp.OslpEnvelope in project Protocol-Adapter-OSLP by OSGP.
the class CommonRebootRequestMessageProcessor method processSignedOslpEnvelope.
@Override
public void processSignedOslpEnvelope(final String deviceIdentification, final SignedOslpEnvelopeDto signedOslpEnvelopeDto) {
final UnsignedOslpEnvelopeDto unsignedOslpEnvelopeDto = signedOslpEnvelopeDto.getUnsignedOslpEnvelopeDto();
final OslpEnvelope oslpEnvelope = signedOslpEnvelopeDto.getOslpEnvelope();
final String correlationUid = unsignedOslpEnvelopeDto.getCorrelationUid();
final String organisationIdentification = unsignedOslpEnvelopeDto.getOrganisationIdentification();
final String domain = unsignedOslpEnvelopeDto.getDomain();
final String domainVersion = unsignedOslpEnvelopeDto.getDomainVersion();
final String messageType = unsignedOslpEnvelopeDto.getMessageType();
final String ipAddress = unsignedOslpEnvelopeDto.getIpAddress();
final int retryCount = unsignedOslpEnvelopeDto.getRetryCount();
final boolean isScheduled = unsignedOslpEnvelopeDto.isScheduled();
final DeviceResponseHandler deviceResponseHandler = new DeviceResponseHandler() {
@Override
public void handleResponse(final DeviceResponse deviceResponse) {
CommonRebootRequestMessageProcessor.this.handleEmptyDeviceResponse(deviceResponse, CommonRebootRequestMessageProcessor.this.responseMessageSender, domain, domainVersion, messageType, retryCount);
}
@Override
public void handleException(final Throwable t, final DeviceResponse deviceResponse) {
CommonRebootRequestMessageProcessor.this.handleUnableToConnectDeviceResponse(deviceResponse, t, null, CommonRebootRequestMessageProcessor.this.responseMessageSender, deviceResponse, domain, domainVersion, messageType, isScheduled, retryCount);
}
};
final DeviceRequest deviceRequest = new DeviceRequest(organisationIdentification, deviceIdentification, correlationUid);
try {
this.deviceService.doSetReboot(oslpEnvelope, deviceRequest, deviceResponseHandler, ipAddress);
} catch (final IOException e) {
this.handleError(e, correlationUid, organisationIdentification, deviceIdentification, domain, domainVersion, messageType, retryCount);
}
}
use of com.alliander.osgp.oslp.OslpEnvelope in project Protocol-Adapter-OSLP by OSGP.
the class CommonSetDeviceVerificationKeyRequestMessageProcessor method processSignedOslpEnvelope.
@Override
public void processSignedOslpEnvelope(final String deviceIdentification, final SignedOslpEnvelopeDto signedOslpEnvelopeDto) {
final UnsignedOslpEnvelopeDto unsignedOslpEnvelopeDto = signedOslpEnvelopeDto.getUnsignedOslpEnvelopeDto();
final OslpEnvelope oslpEnvelope = signedOslpEnvelopeDto.getOslpEnvelope();
final String correlationUid = unsignedOslpEnvelopeDto.getCorrelationUid();
final String organisationIdentification = unsignedOslpEnvelopeDto.getOrganisationIdentification();
final String domain = unsignedOslpEnvelopeDto.getDomain();
final String domainVersion = unsignedOslpEnvelopeDto.getDomainVersion();
final String messageType = unsignedOslpEnvelopeDto.getMessageType();
final String ipAddress = unsignedOslpEnvelopeDto.getIpAddress();
final int retryCount = unsignedOslpEnvelopeDto.getRetryCount();
final boolean isScheduled = unsignedOslpEnvelopeDto.isScheduled();
final DeviceResponseHandler deviceResponseHandler = new DeviceResponseHandler() {
@Override
public void handleResponse(final DeviceResponse deviceResponse) {
CommonSetDeviceVerificationKeyRequestMessageProcessor.this.handleEmptyDeviceResponse(deviceResponse, CommonSetDeviceVerificationKeyRequestMessageProcessor.this.responseMessageSender, domain, domainVersion, messageType, retryCount);
}
@Override
public void handleException(final Throwable t, final DeviceResponse deviceResponse) {
CommonSetDeviceVerificationKeyRequestMessageProcessor.this.handleUnableToConnectDeviceResponse(deviceResponse, t, null, CommonSetDeviceVerificationKeyRequestMessageProcessor.this.responseMessageSender, deviceResponse, domain, domainVersion, messageType, isScheduled, retryCount);
}
};
final DeviceRequest deviceRequest = new DeviceRequest(organisationIdentification, deviceIdentification, correlationUid);
try {
this.deviceService.doSetDeviceVerificationKey(oslpEnvelope, deviceRequest, deviceResponseHandler, ipAddress);
} catch (final IOException e) {
this.handleError(e, correlationUid, organisationIdentification, deviceIdentification, domain, domainVersion, messageType, retryCount);
}
}
Aggregations