Search in sources :

Example 11 with LwM2mObjectEnabler

use of org.eclipse.leshan.client.resource.LwM2mObjectEnabler in project leshan by eclipse.

the class QueueModeIntegrationTestHelper method createClient.

@Override
public void createClient() {
    // Create objects Enabler
    ObjectsInitializer initializer = new ObjectsInitializer(new LwM2mModel(createObjectModels()));
    initializer.setInstancesForObject(LwM2mId.SECURITY, Security.noSec("coap://" + server.getUnsecuredAddress().getHostString() + ":" + server.getUnsecuredAddress().getPort(), 12345));
    initializer.setInstancesForObject(LwM2mId.SERVER, new Server(12345, LIFETIME, BindingMode.UQ, false));
    initializer.setInstancesForObject(LwM2mId.DEVICE, new Device("Eclipse Leshan", MODEL_NUMBER, "12345", "UQ") {

        @Override
        public ExecuteResponse execute(int resourceid, String params) {
            if (resourceid == 4) {
                return ExecuteResponse.success();
            } else {
                return super.execute(resourceid, params);
            }
        }
    });
    List<LwM2mObjectEnabler> objects = initializer.createMandatory();
    objects.addAll(initializer.create(2, 2000));
    // Build Client
    LeshanClientBuilder builder = new LeshanClientBuilder(currentEndpointIdentifier.get());
    builder.setObjects(objects);
    client = builder.build();
}
Also used : LwM2mObjectEnabler(org.eclipse.leshan.client.resource.LwM2mObjectEnabler) Server(org.eclipse.leshan.client.object.Server) ObjectsInitializer(org.eclipse.leshan.client.resource.ObjectsInitializer) Device(org.eclipse.leshan.client.object.Device) LeshanClientBuilder(org.eclipse.leshan.client.californium.LeshanClientBuilder) ExecuteResponse(org.eclipse.leshan.core.response.ExecuteResponse) LwM2mModel(org.eclipse.leshan.core.model.LwM2mModel)

Example 12 with LwM2mObjectEnabler

use of org.eclipse.leshan.client.resource.LwM2mObjectEnabler in project leshan by eclipse.

the class IntegrationTestHelper method createClient.

public void createClient() {
    // Create objects Enabler
    ObjectsInitializer initializer = new ObjectsInitializer(new LwM2mModel(createObjectModels()));
    initializer.setInstancesForObject(LwM2mId.SECURITY, Security.noSec("coap://" + server.getUnsecuredAddress().getHostString() + ":" + server.getUnsecuredAddress().getPort(), 12345));
    initializer.setInstancesForObject(LwM2mId.SERVER, new Server(12345, LIFETIME, BindingMode.U, false));
    initializer.setInstancesForObject(LwM2mId.DEVICE, new Device("Eclipse Leshan", MODEL_NUMBER, "12345", "U") {

        @Override
        public ExecuteResponse execute(int resourceid, String params) {
            if (resourceid == 4) {
                return ExecuteResponse.success();
            } else {
                return super.execute(resourceid, params);
            }
        }
    });
    List<LwM2mObjectEnabler> objects = initializer.createMandatory();
    objects.addAll(initializer.create(2, 2000));
    // Build Client
    LeshanClientBuilder builder = new LeshanClientBuilder(currentEndpointIdentifier.get());
    builder.setObjects(objects);
    client = builder.build();
}
Also used : LwM2mObjectEnabler(org.eclipse.leshan.client.resource.LwM2mObjectEnabler) Server(org.eclipse.leshan.client.object.Server) LeshanServer(org.eclipse.leshan.server.californium.impl.LeshanServer) ObjectsInitializer(org.eclipse.leshan.client.resource.ObjectsInitializer) Device(org.eclipse.leshan.client.object.Device) LeshanClientBuilder(org.eclipse.leshan.client.californium.LeshanClientBuilder) ExecuteResponse(org.eclipse.leshan.core.response.ExecuteResponse) LwM2mModel(org.eclipse.leshan.core.model.LwM2mModel)

Example 13 with LwM2mObjectEnabler

use of org.eclipse.leshan.client.resource.LwM2mObjectEnabler in project leshan by eclipse.

the class SecureIntegrationTestHelper method createX509CertClient.

// TODO implement X509 support for client
public void createX509CertClient(PrivateKey privatekey, Certificate[] trustedCertificates) {
    ObjectsInitializer initializer = new ObjectsInitializer();
    // TODO security instance with certificate info
    initializer.setInstancesForObject(LwM2mId.SECURITY, Security.noSec("coaps://" + server.getSecuredAddress().getHostString() + ":" + server.getSecuredAddress().getPort(), 12345));
    initializer.setInstancesForObject(LwM2mId.SERVER, new Server(12345, LIFETIME, BindingMode.U, false));
    initializer.setInstancesForObject(LwM2mId.DEVICE, new Device("Eclipse Leshan", MODEL_NUMBER, "12345", "U"));
    List<LwM2mObjectEnabler> objects = initializer.createMandatory();
    objects.add(initializer.create(2));
    InetSocketAddress clientAddress = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
    DtlsConnectorConfig.Builder config = new DtlsConnectorConfig.Builder().setAddress(clientAddress);
    // TODO we should read the config from the security object
    config.setIdentity(privatekey, clientX509CertChain, false);
    config.setTrustStore(trustedCertificates);
    CoapServer coapServer = new CoapServer();
    CoapEndpoint.CoapEndpointBuilder coapBuilder = new CoapEndpoint.CoapEndpointBuilder();
    coapBuilder.setConnector(new DTLSConnector(config.build()));
    coapBuilder.setNetworkConfig(new NetworkConfig());
    coapServer.addEndpoint(coapBuilder.build());
    LeshanClientBuilder builder = new LeshanClientBuilder(getCurrentEndpoint());
    builder.setLocalAddress(clientAddress.getHostString(), clientAddress.getPort());
    builder.setObjects(objects);
    client = builder.build();
}
Also used : LwM2mObjectEnabler(org.eclipse.leshan.client.resource.LwM2mObjectEnabler) CoapServer(org.eclipse.californium.core.CoapServer) Server(org.eclipse.leshan.client.object.Server) ObjectsInitializer(org.eclipse.leshan.client.resource.ObjectsInitializer) Device(org.eclipse.leshan.client.object.Device) InetSocketAddress(java.net.InetSocketAddress) LeshanClientBuilder(org.eclipse.leshan.client.californium.LeshanClientBuilder) NetworkConfig(org.eclipse.californium.core.network.config.NetworkConfig) CoapServer(org.eclipse.californium.core.CoapServer) DtlsConnectorConfig(org.eclipse.californium.scandium.config.DtlsConnectorConfig) DTLSConnector(org.eclipse.californium.scandium.DTLSConnector) CoapEndpoint(org.eclipse.californium.core.network.CoapEndpoint)

Example 14 with LwM2mObjectEnabler

use of org.eclipse.leshan.client.resource.LwM2mObjectEnabler in project leshan by eclipse.

the class SecureIntegrationTestHelper method setNewPsk.

public void setNewPsk(LwM2mClient client, String identity) {
    LwM2mObjectEnabler securityObject = client.getObjectEnablers().get(0);
    WriteResponse write = securityObject.write(ServerIdentity.SYSTEM, new WriteRequest(LwM2mId.SECURITY, 0, LwM2mId.SEC_PUBKEY_IDENTITY, identity.getBytes()));
    System.out.println(write);
}
Also used : LwM2mObjectEnabler(org.eclipse.leshan.client.resource.LwM2mObjectEnabler) WriteRequest(org.eclipse.leshan.core.request.WriteRequest) WriteResponse(org.eclipse.leshan.core.response.WriteResponse)

Example 15 with LwM2mObjectEnabler

use of org.eclipse.leshan.client.resource.LwM2mObjectEnabler in project leshan by eclipse.

the class SecureIntegrationTestHelper method createRPKClient.

// TODO implement RPK support for client
public void createRPKClient() {
    ObjectsInitializer initializer = new ObjectsInitializer();
    initializer.setInstancesForObject(LwM2mId.SECURITY, Security.rpk("coaps://" + server.getSecuredAddress().getHostString() + ":" + server.getSecuredAddress().getPort(), 12345, clientPublicKey.getEncoded(), clientPrivateKey.getEncoded(), serverPublicKey.getEncoded()));
    initializer.setInstancesForObject(LwM2mId.SERVER, new Server(12345, LIFETIME, BindingMode.U, false));
    initializer.setInstancesForObject(LwM2mId.DEVICE, new Device("Eclipse Leshan", MODEL_NUMBER, "12345", "U"));
    List<LwM2mObjectEnabler> objects = initializer.createMandatory();
    objects.add(initializer.create(2));
    InetSocketAddress clientAddress = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
    DtlsConnectorConfig.Builder config = new DtlsConnectorConfig.Builder().setAddress(clientAddress);
    // TODO we should read the config from the security object
    // TODO no way to provide a dynamic config with the current scandium API
    config.setIdentity(clientPrivateKey, clientPublicKey);
    CoapServer coapServer = new CoapServer();
    CoapEndpoint.CoapEndpointBuilder coapBuilder = new CoapEndpoint.CoapEndpointBuilder();
    coapBuilder.setConnector(new DTLSConnector(config.build()));
    coapBuilder.setNetworkConfig(new NetworkConfig());
    coapServer.addEndpoint(coapBuilder.build());
    LeshanClientBuilder builder = new LeshanClientBuilder(getCurrentEndpoint());
    builder.setLocalAddress(clientAddress.getHostString(), clientAddress.getPort());
    builder.setObjects(objects);
    client = builder.build();
}
Also used : LwM2mObjectEnabler(org.eclipse.leshan.client.resource.LwM2mObjectEnabler) CoapServer(org.eclipse.californium.core.CoapServer) Server(org.eclipse.leshan.client.object.Server) ObjectsInitializer(org.eclipse.leshan.client.resource.ObjectsInitializer) Device(org.eclipse.leshan.client.object.Device) InetSocketAddress(java.net.InetSocketAddress) LeshanClientBuilder(org.eclipse.leshan.client.californium.LeshanClientBuilder) NetworkConfig(org.eclipse.californium.core.network.config.NetworkConfig) CoapServer(org.eclipse.californium.core.CoapServer) DtlsConnectorConfig(org.eclipse.californium.scandium.config.DtlsConnectorConfig) DTLSConnector(org.eclipse.californium.scandium.DTLSConnector) CoapEndpoint(org.eclipse.californium.core.network.CoapEndpoint)

Aggregations

LwM2mObjectEnabler (org.eclipse.leshan.client.resource.LwM2mObjectEnabler)16 LeshanClientBuilder (org.eclipse.leshan.client.californium.LeshanClientBuilder)8 ObjectsInitializer (org.eclipse.leshan.client.resource.ObjectsInitializer)8 Device (org.eclipse.leshan.client.object.Device)7 Server (org.eclipse.leshan.client.object.Server)7 ArrayList (java.util.ArrayList)5 InetSocketAddress (java.net.InetSocketAddress)4 HashMap (java.util.HashMap)4 Link (org.eclipse.leshan.Link)4 LwM2mInstanceEnabler (org.eclipse.leshan.client.resource.LwM2mInstanceEnabler)4 ObjectEnabler (org.eclipse.leshan.client.resource.ObjectEnabler)4 Test (org.junit.Test)4 CoapServer (org.eclipse.californium.core.CoapServer)3 CoapEndpoint (org.eclipse.californium.core.network.CoapEndpoint)3 NetworkConfig (org.eclipse.californium.core.network.config.NetworkConfig)3 DTLSConnector (org.eclipse.californium.scandium.DTLSConnector)3 DtlsConnectorConfig (org.eclipse.californium.scandium.config.DtlsConnectorConfig)3 LwM2mModel (org.eclipse.leshan.core.model.LwM2mModel)3 BaseInstanceEnabler (org.eclipse.leshan.client.resource.BaseInstanceEnabler)2 ExecuteResponse (org.eclipse.leshan.core.response.ExecuteResponse)2