Search in sources :

Example 6 with IED

use of org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.IED in project open-smart-grid-platform by OSGP.

the class Iec61850DeviceConnectionService method testIfConnectionIsCachedAndAlive.

private boolean testIfConnectionIsCachedAndAlive(final String deviceIdentification, final IED ied, final String serverName, final String logicalDevice) throws ProtocolAdapterException {
    try {
        LOGGER.info("Trying to find connection in cache for deviceIdentification: {}", deviceIdentification);
        final Iec61850Connection iec61850Connection = this.fetchIec61850Connection(deviceIdentification);
        if (iec61850Connection != null) {
            // Already connected, check if connection is still usable.
            LOGGER.info("Connection found for deviceIdentification: {}", deviceIdentification);
            // requires manual reads of remote data.
            if (ied != null && logicalDevice != null) {
                final String description = this.getActualServerName(ied, serverName);
                LOGGER.info("Testing if connection is alive using {}{}/{}.{} for deviceIdentification: {}", description, logicalDevice, LogicalNode.LOGICAL_NODE_ZERO.getDescription(), DataAttribute.NAME_PLATE.getDescription(), deviceIdentification);
                final FcModelNode modelNode = this.getModelNode(logicalDevice, iec61850Connection, description);
                this.iec61850Client.readNodeDataValues(iec61850Connection.getClientAssociation(), modelNode);
            } else {
                // Read all data values, which is much slower, but requires
                // no manual reads of remote data.
                LOGGER.info("Testing if connection is alive using readAllDataValues() for deviceIdentification: {}", deviceIdentification);
                this.iec61850Client.readAllDataValues(iec61850Connection.getClientAssociation());
            }
            LOGGER.info("Connection is still active for deviceIdentification: {}", deviceIdentification);
            return true;
        }
    } catch (final NodeReadException e) {
        LOGGER.error("Connection is no longer active, removing connection from cache for deviceIdentification: " + deviceIdentification, e);
        this.disconnect(deviceIdentification);
    }
    return false;
}
Also used : Iec61850Connection(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.Iec61850Connection) NodeReadException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeReadException) FcModelNode(com.beanit.openiec61850.FcModelNode)

Example 7 with IED

use of org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.IED in project open-smart-grid-platform by OSGP.

the class Iec61850RtuDeviceService 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.ZOWN_RTU).serverName(serverName).logicalDevice(LogicalDevice.RTU.getDescription() + 1).build();
    this.iec61850DeviceConnectionService.connect(deviceConnectionParameters, deviceRequest.getOrganisationIdentification());
    return this.iec61850DeviceConnectionService.getServerModel(deviceRequest.getDeviceIdentification());
}
Also used : DeviceConnectionParameters(org.opensmartgridplatform.adapter.protocol.iec61850.domain.valueobjects.DeviceConnectionParameters)

Example 8 with IED

use of org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.IED in project open-smart-grid-platform by OSGP.

the class Iec61850ChannelHandlerServer method processRegistrationMessage.

private void processRegistrationMessage(final RegisterDeviceRequest message, final String correlationId) {
    this.logMessage(message);
    final String deviceIdentification = message.getDeviceIdentification();
    if (this.deviceRegistrationService.isKnownDevice(deviceIdentification)) {
        LOGGER.info("Device {} found, start processing this registration message", deviceIdentification);
    } else {
        LOGGER.warn("Ignoring this registration message, because there's no device having identification {}", deviceIdentification);
        return;
    }
    final IED ied = IED.FLEX_OVL;
    final String ipAddress;
    // set, the values will be used to set an IP address for a device.
    if (this.testDeviceIps != null && this.testDeviceIps.containsKey(deviceIdentification)) {
        final String testDeviceIp = this.testDeviceIps.get(deviceIdentification);
        LOGGER.info("Using testDeviceId: {} and testDeviceIp: {}", deviceIdentification, testDeviceIp);
        ipAddress = testDeviceIp;
    } else {
        ipAddress = message.getIpAddress();
    }
    final DeviceRegistrationDataDto deviceRegistrationData = new DeviceRegistrationDataDto(ipAddress, Ssld.SSLD_TYPE, true);
    final RequestMessage requestMessage = new RequestMessage(correlationId, NO_ORGANISATION, deviceIdentification, ipAddress, null, null, deviceRegistrationData);
    LOGGER.info("Sending register device request to OSGP with correlation ID: {}", correlationId);
    this.osgpRequestMessageSender.send(requestMessage, MessageType.REGISTER_DEVICE.name());
    try {
        this.deviceRegistrationService.disableRegistration(deviceIdentification, InetAddress.getByName(ipAddress), ied, ied.getDescription());
        final RequestMessage cdrRequestMessage = new RequestMessage(correlationId, NO_ORGANISATION, deviceIdentification, ipAddress);
        this.osgpRequestMessageSender.send(cdrRequestMessage, MessageType.DEVICE_REGISTRATION_COMPLETED.name());
        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);
    }
}
Also used : RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) IED(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.IED) DeviceRegistrationDataDto(org.opensmartgridplatform.dto.valueobjects.DeviceRegistrationDataDto)

Aggregations

DeviceConnectionParameters (org.opensmartgridplatform.adapter.protocol.iec61850.domain.valueobjects.DeviceConnectionParameters)3 ClientAssociation (com.beanit.openiec61850.ClientAssociation)2 ConnectionFailureException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ConnectionFailureException)2 Iec61850Connection (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.Iec61850Connection)2 DeviceConnection (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection)2 IED (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.IED)2 IED (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.IED)1 DeviceRegistrationDataDto (com.alliander.osgp.dto.valueobjects.DeviceRegistrationDataDto)1 RequestMessage (com.alliander.osgp.shared.infra.jms.RequestMessage)1 ClientSap (com.beanit.openiec61850.ClientSap)1 FcModelNode (com.beanit.openiec61850.FcModelNode)1 ServerModel (com.beanit.openiec61850.ServerModel)1 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 DateTime (org.joda.time.DateTime)1 Iec61850Device (org.opensmartgridplatform.adapter.protocol.iec61850.domain.entities.Iec61850Device)1 DeviceMessageLog (org.opensmartgridplatform.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog)1 NodeReadException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeReadException)1 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)1 Iec61850ClientAssociation (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.Iec61850ClientAssociation)1