Search in sources :

Example 1 with LogicalDevice

use of org.openmuc.jdlms.LogicalDevice in project open-smart-grid-platform by OSGP.

the class DlmsServerConfig method dlmsServer.

@Bean
public DlmsServer dlmsServer(final OsgpServerConnectionListener osgpServerConnectionListener) throws IOException {
    final DlmsServer serverConnection;
    TcpServerBuilder serverBuilder = DlmsServer.tcpServerBuilder(this.port);
    if (this.useHdlc) {
        serverBuilder = serverBuilder.setSessionLayerFactory(ServerSessionLayerFactories.newHdlcSessionLayerFactory());
    }
    serverBuilder = serverBuilder.setConnectionListener(osgpServerConnectionListener);
    for (final Integer logicalDeviceId : LogicalDeviceIdsConverter.convert(this.logicalDeviceIds)) {
        LOGGER.info("preparing logical device {} on port {}", logicalDeviceId, this.port);
        final LogicalDevice logdev = this.buildDevice(logicalDeviceId).build();
        serverBuilder = serverBuilder.registerLogicalDevice(logdev).setReferencingMethod(ReferencingMethod.valueOf(this.referencingMethod.toUpperCase()));
    }
    serverConnection = serverBuilder.build();
    return serverConnection;
}
Also used : TcpServerBuilder(org.openmuc.jdlms.DlmsServer.TcpServerBuilder) DlmsServer(org.openmuc.jdlms.DlmsServer) LogicalDevice(org.openmuc.jdlms.LogicalDevice) Bean(org.springframework.context.annotation.Bean)

Example 2 with LogicalDevice

use of org.openmuc.jdlms.LogicalDevice in project open-smart-grid-platform by OSGP.

the class LogicalDeviceBuilder method build.

public LogicalDevice build() throws IOException {
    final LogicalDevice logicalDevice = new LogicalDevice(this.logicalDeviceId, this.logicalDeviceName, this.manufacturer, this.deviceId);
    if (this.authenticationKeyPath != null && this.encryptionKeyPath != null && this.masterKeyPath != null) {
        final byte[] auth = Files.readAllBytes(new File(this.authenticationKeyPath).toPath());
        final byte[] enc = Files.readAllBytes(new File(this.encryptionKeyPath).toPath());
        final byte[] master = Files.readAllBytes(new File(this.masterKeyPath).toPath());
        final SecuritySuite securitySuite = SecuritySuite.builder().setAuthenticationKey(auth).setAuthenticationMechanism(AuthenticationMechanism.HLS5_GMAC).setGlobalUnicastEncryptionKey(enc).setEncryptionMechanism(EncryptionMechanism.AES_GCM_128).build();
        logicalDevice.addRestriction(this.clientId, securitySuite);
        logicalDevice.setMasterKey(master);
    } else if (1 == this.securityLevel) {
        final SecuritySuite securitySuite = SecuritySuite.builder().setPassword("11111111".getBytes(StandardCharsets.UTF_8)).setAuthenticationMechanism(AuthenticationMechanism.LOW).setEncryptionMechanism(EncryptionMechanism.NONE).build();
        logicalDevice.addRestriction(this.clientId, securitySuite);
    }
    if (this.clientId != PUBLIC_CLIENT_CLIENT_ID && this.securityLevel != 0) {
        // When creating a logical device with a secured non-public interface, add a public client.
        // This ensures that such devices always have a public client interface in addition to the
        // configured
        // interface (usually: management interface).
        // Not that this approach is not realistic in the sense that the public client should not
        // expose the same
        // objects as the secured interface, but for the purposes of a simulator this simplification
        // should be ok.
        this.addPublicClientTo(logicalDevice);
    }
    logicalDevice.registerCosemObject(this.cosemClasses);
    return logicalDevice;
}
Also used : SecuritySuite(org.openmuc.jdlms.SecuritySuite) LogicalDevice(org.openmuc.jdlms.LogicalDevice) File(java.io.File)

Aggregations

LogicalDevice (org.openmuc.jdlms.LogicalDevice)2 File (java.io.File)1 DlmsServer (org.openmuc.jdlms.DlmsServer)1 TcpServerBuilder (org.openmuc.jdlms.DlmsServer.TcpServerBuilder)1 SecuritySuite (org.openmuc.jdlms.SecuritySuite)1 Bean (org.springframework.context.annotation.Bean)1