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));
}
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);
}
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));
}
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));
}
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);
}
}
Aggregations