Search in sources :

Example 1 with DeviceConnection

use of org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DeviceConnection in project open-smart-grid-platform by OSGP.

the class AsduSteps method thenIShouldSendAGeneralInterrogationCommandToDevice.

@Then("I should send a general interrogation command to device {string}")
public void thenIShouldSendAGeneralInterrogationCommandToDevice(final String deviceIdentification) throws Exception {
    LOGGER.debug("Then I should send a general interrogation command to device {}", deviceIdentification);
    final DeviceConnection deviceConnection = (DeviceConnection) this.clientConnectionCacheSpy.getConnection(deviceIdentification);
    final Connection connectionMock = deviceConnection.getConnection();
    verify(connectionMock).interrogation(eq(0), eq(CauseOfTransmission.ACTIVATION), any(IeQualifierOfInterrogation.class));
}
Also used : DeviceConnection(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DeviceConnection) DeviceConnection(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DeviceConnection) Connection(org.openmuc.j60870.Connection) IeQualifierOfInterrogation(org.openmuc.j60870.ie.IeQualifierOfInterrogation) Then(io.cucumber.java.en.Then)

Example 2 with DeviceConnection

use of org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DeviceConnection in project open-smart-grid-platform by OSGP.

the class ConnectionSteps method givenIec60870DeviceIsNotConnected.

@Given("the IEC60870 device is not connected")
public void givenIec60870DeviceIsNotConnected() throws ConnectionFailureException {
    LOGGER.debug("Given IEC60870 device is not connected");
    // Make sure the client connect works as expected
    final DeviceConnection deviceConnection = new DeviceConnection(mock(Connection.class), this.connectionParameters);
    when(this.clientMock.connect(eq(this.connectionParameters), any(ClientConnectionEventListener.class))).thenReturn(deviceConnection);
}
Also used : DeviceConnection(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DeviceConnection) DeviceConnection(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DeviceConnection) Connection(org.openmuc.j60870.Connection) ClientConnectionEventListener(org.opensmartgridplatform.adapter.protocol.iec60870.domain.services.ClientConnectionEventListener) Given(io.cucumber.java.en.Given)

Example 3 with DeviceConnection

use of org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DeviceConnection in project open-smart-grid-platform by OSGP.

the class ConnectionSteps method whenIConnectToIEC60870Device.

@When("I connect to IEC60870 device {string}")
public void whenIConnectToIEC60870Device(final String deviceIdentification) throws Exception {
    LOGGER.debug("When I connect to IEC60870 device {}", deviceIdentification);
    final Iec60870Device device = this.iec60870DeviceSteps.getDevice(deviceIdentification).orElseThrow(() -> new Exception("Device not found"));
    final DeviceType deviceType = device.getDeviceType();
    final String connectionDeviceIdentification = device.getConnectionDeviceIdentification();
    this.connectionParameters = this.initConnectionParameters(connectionDeviceIdentification);
    this.connectionEventListener = new ClientConnectionEventListener.Builder().withDeviceIdentification(connectionDeviceIdentification).withClientAsduHandlerRegistry(this.clientAsduHandlerRegistry).withClientConnectionCache(this.connectionCacheSpy).withLoggingService(this.loggingService).withLogItemFactory(this.logItemFactory).withResponseMetadata(this.initResponseMetadata(deviceIdentification, deviceType)).withResponseMetadataFactory(this.responseMetadataFactory).build();
    when(this.clientMock.connect(any(ConnectionParameters.class), any(ConnectionEventListener.class))).thenReturn(new DeviceConnection(this.connection, this.connectionParameters));
}
Also used : DeviceType(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DeviceType) ConnectionParameters(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ConnectionParameters) DeviceConnection(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DeviceConnection) Iec60870Device(org.opensmartgridplatform.adapter.protocol.iec60870.domain.entities.Iec60870Device) ConnectionFailureException(org.opensmartgridplatform.shared.exceptionhandling.ConnectionFailureException) ClientConnectionAlreadyInCacheException(org.opensmartgridplatform.adapter.protocol.iec60870.domain.exceptions.ClientConnectionAlreadyInCacheException) ClientConnectionEventListener(org.opensmartgridplatform.adapter.protocol.iec60870.domain.services.ClientConnectionEventListener) ClientConnectionEventListener(org.opensmartgridplatform.adapter.protocol.iec60870.domain.services.ClientConnectionEventListener) ConnectionEventListener(org.openmuc.j60870.ConnectionEventListener) When(io.cucumber.java.en.When)

Example 4 with DeviceConnection

use of org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DeviceConnection in project open-smart-grid-platform by OSGP.

the class ConnectionSteps method givenIec60870DeviceIsConnected.

@Given("an existing connection with IEC60870 device {string} of type {deviceType}")
public void givenIec60870DeviceIsConnected(final String deviceIdentification, final DeviceType deviceType) throws Exception {
    LOGGER.debug("Given an existing connection with IEC60870 device {} of type {}", deviceIdentification, deviceType);
    // Make sure the connection event listener works as expected
    this.connectionParameters = this.initConnectionParameters(deviceIdentification);
    final ResponseMetadata responseMetadata = this.initResponseMetadata(deviceIdentification, deviceType);
    this.connectionEventListener = new ClientConnectionEventListener.Builder().withDeviceIdentification(deviceIdentification).withClientAsduHandlerRegistry(this.clientAsduHandlerRegistry).withClientConnectionCache(this.connectionCacheSpy).withLoggingService(this.loggingService).withLogItemFactory(this.logItemFactory).withResponseMetadata(responseMetadata).withResponseMetadataFactory(this.responseMetadataFactory).build();
    // Make sure a connection could be retrieved from the cache
    // Only needed for scenarios sending requests to a device
    // final Connection connection = mock(Connection.class);
    this.connectionCacheSpy.addConnection(deviceIdentification, new DeviceConnection(this.connection, this.connectionParameters));
}
Also used : DeviceConnection(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DeviceConnection) ResponseMetadata(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ResponseMetadata) ClientConnectionEventListener(org.opensmartgridplatform.adapter.protocol.iec60870.domain.services.ClientConnectionEventListener) Given(io.cucumber.java.en.Given)

Example 5 with DeviceConnection

use of org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DeviceConnection in project open-smart-grid-platform by OSGP.

the class Iec60870Client method connect.

@Override
public ClientConnection connect(final ConnectionParameters connectionParameters, final ConnectionEventListener asduListener) throws ConnectionFailureException {
    final InetAddress address = this.convertIpAddress(connectionParameters.getIpAddress());
    final String deviceIdentification = connectionParameters.getDeviceIdentification();
    final int port = connectionParameters.getPort() == null ? IEC60870_DEFAULT_PORT : connectionParameters.getPort();
    final ClientConnectionBuilder clientConnectionBuilder = new ClientConnectionBuilder(address).setPort(port).setConnectionTimeout(this.connectionTimeout);
    try {
        LOGGER.info("Connecting to device: {}...", deviceIdentification);
        final Connection connection = clientConnectionBuilder.build();
        connection.startDataTransfer(asduListener);
        LOGGER.info("Connected to device: {}", deviceIdentification);
        return new DeviceConnection(connection, connectionParameters);
    } catch (final IOException e) {
        final String errorMessage = "Unable to connect to remote host: " + connectionParameters.getIpAddress();
        LOGGER.error(errorMessage, e);
        throw new ConnectionFailureException(ComponentType.PROTOCOL_IEC60870, errorMessage);
    }
}
Also used : ClientConnectionBuilder(org.openmuc.j60870.ClientConnectionBuilder) ConnectionFailureException(org.opensmartgridplatform.shared.exceptionhandling.ConnectionFailureException) ClientConnection(org.opensmartgridplatform.adapter.protocol.iec60870.domain.services.ClientConnection) DeviceConnection(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DeviceConnection) Connection(org.openmuc.j60870.Connection) DeviceConnection(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DeviceConnection) IOException(java.io.IOException) InetAddress(java.net.InetAddress)

Aggregations

DeviceConnection (org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DeviceConnection)9 ConnectionParameters (org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ConnectionParameters)5 Connection (org.openmuc.j60870.Connection)4 RequestMetadata (org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.RequestMetadata)4 Test (org.junit.jupiter.api.Test)3 IeQualifierOfInterrogation (org.openmuc.j60870.ie.IeQualifierOfInterrogation)3 ClientConnection (org.opensmartgridplatform.adapter.protocol.iec60870.domain.services.ClientConnection)3 ClientConnectionEventListener (org.opensmartgridplatform.adapter.protocol.iec60870.domain.services.ClientConnectionEventListener)3 Given (io.cucumber.java.en.Given)2 ASdu (org.openmuc.j60870.ASdu)2 LogItem (org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.LogItem)2 ConnectionFailureException (org.opensmartgridplatform.shared.exceptionhandling.ConnectionFailureException)2 Then (io.cucumber.java.en.Then)1 When (io.cucumber.java.en.When)1 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 JMSException (javax.jms.JMSException)1 CauseOfTransmission (org.openmuc.j60870.CauseOfTransmission)1 ClientConnectionBuilder (org.openmuc.j60870.ClientConnectionBuilder)1 ConnectionEventListener (org.openmuc.j60870.ConnectionEventListener)1