use of org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.IED in project Protocol-Adapter-IEC61850 by OSGP.
the class Iec61850ChannelHandlerServer method processRegistrationMessage.
private void processRegistrationMessage(final RegisterDeviceRequest message, final String correlationId) {
this.logMessage(message);
String deviceIdentification = message.getDeviceIdentification();
String deviceType = Ssld.SSLD_TYPE;
final IED ied = IED.FLEX_OVL;
String ipAddress = message.getIpAddress();
// set, the values will be used to set an IP address for a device.
if (this.testDeviceId != null && this.testDeviceId.equals(deviceIdentification) && this.testDeviceIp != null) {
LOGGER.info("Using testDeviceId: {} and testDeviceIp: {}", this.testDeviceId, this.testDeviceIp);
deviceIdentification = this.testDeviceId;
deviceType = Ssld.SSLD_TYPE;
ipAddress = this.testDeviceIp;
}
final DeviceRegistrationDataDto deviceRegistrationData = new DeviceRegistrationDataDto(ipAddress, deviceType, true);
final RequestMessage requestMessage = new RequestMessage(correlationId, "no-organisation", deviceIdentification, ipAddress, deviceRegistrationData);
LOGGER.info("Sending register device request to OSGP with correlation ID: " + correlationId);
this.osgpRequestMessageSender.send(requestMessage, DeviceFunctionDto.REGISTER_DEVICE.name());
try {
this.deviceRegistrationService.disableRegistration(deviceIdentification, InetAddress.getByName(ipAddress), ied, ied.getDescription());
LOGGER.info("Disabled registration for device: {}, at IP address: {}", deviceIdentification, ipAddress);
} catch (final Exception e) {
LOGGER.error("Failed to disable registration for device: {}, at IP address: {}", deviceIdentification, ipAddress, e);
}
}
use of org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.IED in project open-smart-grid-platform by OSGP.
the class Iec61850Client method connect.
/**
* Connect to a given device. This will try to establish the {@link ClientAssociation} between
* client and IED.
*
* @param deviceIdentification The device identification.
* @param ipAddress The IP address of the device.
* @param reportListener The report listener instance which can be created using {@link
* Iec61850ClientEventListenerFactory}.
* @param port The port number of the IED.
* @return An {@link Iec61850ClientAssociation} instance.
* @throws ConnectionFailureException In case the connection to the device could not be
* established.
*/
public Iec61850ClientAssociation connect(final String deviceIdentification, final InetAddress ipAddress, final Iec61850ClientBaseEventListener reportListener, final int port) throws ConnectionFailureException {
// Alternatively you could use ClientSap(SocketFactory factory) to e.g.
// connect using SSL.
final ClientSap clientSap = new ClientSap();
final Iec61850ClientAssociation clientAssociation;
LOGGER.info("Attempting to connect to server: {} on port: {}, max redelivery count: {} and max retry count: {}", ipAddress.getHostAddress(), port, this.maxRedeliveriesForIec61850Requests, this.maxRetryCount);
try {
clientSap.setResponseTimeout(this.connectionTimeout);
final ClientAssociation association = clientSap.associate(ipAddress, port, null, reportListener);
clientAssociation = new Iec61850ClientAssociation(association, reportListener);
} catch (final IOException e) {
// An IOException will always indicate a fatal exception. It
// indicates that the association was closed and
// cannot be recovered. You will need to create a new association
// using ClientSap.associate() in order to
// reconnect.
LOGGER.error("Error connecting to device: {}", deviceIdentification, e);
throw new ConnectionFailureException(e.getMessage(), e);
}
LOGGER.info("Connected to device: {}", deviceIdentification);
return clientAssociation;
}
use of org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.IED in project open-smart-grid-platform by OSGP.
the class DeviceRegistrationService method disableRegistration.
/**
* After the device has registered with the platform successfully, the device has to be informed
* that the registration worked. Disable an attribute so the device will stop attempting to
* register once a minute.
*
* @param deviceIdentification The device identification.
* @param ipAddress The IP address of the device.
* @param ied The type of IED.
* @param serverName The server name.
* @throws ProtocolAdapterException In case the connection to the device can not be established or
* the connection breaks during communication.
*/
public void disableRegistration(final String deviceIdentification, final InetAddress ipAddress, final IED ied, final String serverName) throws ProtocolAdapterException {
final DeviceConnectionParameters deviceConnectionParameters = DeviceConnectionParameters.newBuilder().ipAddress(ipAddress.getHostAddress()).deviceIdentification(deviceIdentification).ied(ied).serverName(serverName).logicalDevice(LogicalDevice.LIGHTING.getDescription()).build();
final DeviceConnection deviceConnection = this.iec61850DeviceConnectionService.connectWithoutConnectionCaching(deviceConnectionParameters, "");
final Function<Void> function = new Function<Void>() {
@Override
public Void apply(final DeviceMessageLog deviceMessageLog) throws ProtocolAdapterException {
DeviceRegistrationService.this.disableRegistration(deviceConnection);
DeviceRegistrationService.this.setLocationInformation(deviceConnection);
if (DeviceRegistrationService.this.isReportingAfterDeviceRegistrationEnabled) {
LOGGER.info("Reporting enabled for device: {}", deviceConnection.getDeviceIdentification());
DeviceRegistrationService.this.enableReporting(deviceConnection);
} else {
LOGGER.info("Reporting disabled for device: {}", deviceIdentification);
DeviceRegistrationService.this.iec61850DeviceConnectionService.disconnect(deviceConnection, null);
}
return null;
}
};
this.iec61850DeviceConnectionService.sendCommandWithRetry(function, deviceIdentification);
}
use of org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.IED in project open-smart-grid-platform by OSGP.
the class Iec61850DaRtuDeviceService method connectAndRetrieveServerModel.
// ======================================
// PRIVATE DEVICE COMMUNICATION METHODS =
// ======================================
private ServerModel connectAndRetrieveServerModel(final DeviceRequest deviceRequest, final String serverName) throws ProtocolAdapterException {
final DeviceConnectionParameters deviceConnectionParameters = DeviceConnectionParameters.newBuilder().ipAddress(deviceRequest.getIpAddress()).deviceIdentification(deviceRequest.getDeviceIdentification()).ied(IED.DA_RTU).serverName(serverName).logicalDevice(LogicalDevice.RTU.getDescription() + 1).build();
this.iec61850DeviceConnectionService.connect(deviceConnectionParameters, deviceRequest.getOrganisationIdentification());
return this.iec61850DeviceConnectionService.getServerModel(deviceRequest.getDeviceIdentification());
}
use of org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.IED in project open-smart-grid-platform by OSGP.
the class Iec61850DeviceConnectionService method connect.
public DeviceConnection connect(final DeviceConnectionParameters deviceConnectionParameters, final String organisationIdentification, final boolean cacheConnection) throws ConnectionFailureException {
final String deviceIdentification = deviceConnectionParameters.getDeviceIdentification();
final String serverName = deviceConnectionParameters.getServerName();
final IED ied = deviceConnectionParameters.getIed();
// an usable for the given deviceIdentification.
try {
if (cacheConnection && this.testIfConnectionIsCachedAndAlive(deviceIdentification, ied, serverName, deviceConnectionParameters.getLogicalDevice())) {
return new DeviceConnection(this.fetchIec61850Connection(deviceIdentification), deviceIdentification, organisationIdentification, serverName);
}
} catch (final ProtocolAdapterException e) {
this.logProtocolAdapterException(deviceIdentification, e);
}
final InetAddress inetAddress = this.convertIpAddress(deviceConnectionParameters.getIpAddress());
// Connect to obtain ClientAssociation and ServerModel.
LOGGER.info("Trying to connect to deviceIdentification: {} at IP address {} using response time-out: {}", deviceIdentification, deviceConnectionParameters.getIpAddress(), this.responseTimeout);
final DateTime startTime = DateTime.now();
// Create instance of appropriate event listener.
Iec61850ClientBaseEventListener eventListener = null;
try {
eventListener = this.iec61850ClientEventListenerFactory.getEventListener(ied, deviceIdentification, organisationIdentification);
} catch (final ProtocolAdapterException e) {
this.logProtocolAdapterException(deviceIdentification, e);
}
final Iec61850Device iec61850Device = this.iec61850DeviceRepository.findByDeviceIdentification(deviceIdentification);
final int port = this.determinePortForIec61850Device(ied, iec61850Device);
// Try to connect and receive the ClientAssociation.
final Iec61850ClientAssociation iec61850ClientAssociation = this.iec61850Client.connect(deviceIdentification, inetAddress, eventListener, port);
final ClientAssociation clientAssociation = iec61850ClientAssociation.getClientAssociation();
// Set response time-out.
clientAssociation.setResponseTimeout(this.responseTimeout);
// Read the ServerModel, either from the device or from a SCL file.
ServerModel serverModel;
try {
serverModel = this.readServerModel(clientAssociation, deviceIdentification, iec61850Device);
} catch (final ProtocolAdapterException e) {
LOGGER.error("ProtocolAdapterException: unable to read ServerModel for deviceIdentification {}", deviceIdentification, e);
throw new ConnectionFailureException(e.getMessage(), e);
}
// Cache the connection.
final Iec61850Connection iec61850Connection = new Iec61850Connection(iec61850ClientAssociation, serverModel, startTime, ied);
if (cacheConnection) {
this.cacheIec61850Connection(deviceIdentification, iec61850Connection);
}
final DeviceConnection connection = new DeviceConnection(iec61850Connection, deviceIdentification, organisationIdentification, serverName);
final DateTime endTime = DateTime.now();
LOGGER.info("Connected to device: {}, fetched server model. Start time: {}, end time: {}, total time in milliseconds: {}", deviceIdentification, startTime, endTime, endTime.minus(startTime.getMillis()).getMillis());
this.iec61850RtuDeviceReportingService.enableReportingForDevice(connection, deviceIdentification, serverName);
return connection;
}
Aggregations