Search in sources :

Example 1 with Link

use of org.eclipse.leshan.core.link.Link in project thingsboard by thingsboard.

the class LwM2MBootstrapConfigStoreTaskProvider method findSecurityInstanceId.

protected void findSecurityInstanceId(Link[] objectLinks) {
    log.info("Object after discover: [{}]", objectLinks);
    this.securityInstances = new HashMap<>();
    for (Link link : objectLinks) {
        if (link.getUriReference().startsWith("/0/")) {
            try {
                LwM2mPath path = new LwM2mPath(link.getUriReference());
                if (path.isObjectInstance()) {
                    if (link.getLinkParams().containsKey("ssid")) {
                        int serverId = Integer.parseInt(link.getLinkParams().get("ssid").getUnquoted());
                        if (!this.securityInstances.containsKey(serverId)) {
                            this.securityInstances.put(serverId, path.getObjectInstanceId());
                        } else {
                            log.error("Invalid lwm2mSecurityInstance by [{}]", path.getObjectInstanceId());
                        }
                        this.securityInstances.put(Integer.valueOf(link.getLinkParams().get("ssid").getUnquoted()), path.getObjectInstanceId());
                    } else {
                        if (!this.securityInstances.containsKey(0)) {
                            this.securityInstances.put(0, path.getObjectInstanceId());
                        } else {
                            log.error("Invalid bootstrapSecurityInstance by [{}]", path.getObjectInstanceId());
                        }
                    }
                }
            } catch (Exception e) {
                // ignore if this is not a LWM2M path
                log.error("Invalid LwM2MPath starting by \"/0/\"");
            }
        }
    }
}
Also used : LwM2mPath(org.eclipse.leshan.core.node.LwM2mPath) Link(org.eclipse.leshan.core.link.Link)

Example 2 with Link

use of org.eclipse.leshan.core.link.Link in project thingsboard by thingsboard.

the class LwM2mClientTest method setRegistration.

@Test
public void setRegistration() {
    LwM2mClient client = new LwM2mClient("nodeId", "testEndpoint");
    Registration registration = new Registration.Builder("test", "testEndpoint", Identity.unsecure(new InetSocketAddress(1000))).objectLinks(new Link[0]).build();
    Assertions.assertDoesNotThrow(() -> client.setRegistration(registration));
}
Also used : Registration(org.eclipse.leshan.server.registration.Registration) InetSocketAddress(java.net.InetSocketAddress) Link(org.eclipse.leshan.core.link.Link) Test(org.junit.Test)

Example 3 with Link

use of org.eclipse.leshan.core.link.Link in project thingsboard by thingsboard.

the class LwM2MClientSerDesTest method serializeDeserialize.

@Test
public void serializeDeserialize() {
    LwM2mClient client = new LwM2mClient("nodeId", "testEndpoint");
    TransportDeviceInfo tdi = new TransportDeviceInfo();
    tdi.setPowerMode(PowerMode.PSM);
    tdi.setPsmActivityTimer(10000L);
    tdi.setPagingTransmissionWindow(2000L);
    tdi.setEdrxCycle(3000L);
    tdi.setTenantId(TenantId.fromUUID(UUID.randomUUID()));
    tdi.setCustomerId(new CustomerId(UUID.randomUUID()));
    tdi.setDeviceId(new DeviceId(UUID.randomUUID()));
    tdi.setDeviceProfileId(new DeviceProfileId(UUID.randomUUID()));
    tdi.setDeviceName("testDevice");
    tdi.setDeviceType("testType");
    ValidateDeviceCredentialsResponse credentialsResponse = ValidateDeviceCredentialsResponse.builder().deviceInfo(tdi).build();
    client.init(credentialsResponse, UUID.randomUUID());
    Registration registration = new Registration.Builder("test", "testEndpoint", Identity.unsecure(new InetSocketAddress(1000))).supportedContentFormats().objectLinks(new Link[] { new Link("/") }).build();
    client.setRegistration(registration);
    client.setState(LwM2MClientState.REGISTERED);
    client.getSharedAttributes().put("key1", TransportProtos.TsKvProto.newBuilder().setTs(0).setKv(TransportProtos.KeyValueProto.newBuilder().setStringV("test").build()).build());
    client.getSharedAttributes().put("key2", TransportProtos.TsKvProto.newBuilder().setTs(1).setKv(TransportProtos.KeyValueProto.newBuilder().setDoubleV(1.02).build()).build());
    byte[] bytes = LwM2MClientSerDes.serialize(client);
    Assert.assertNotNull(bytes);
    LwM2mClient desClient = LwM2MClientSerDes.deserialize(bytes);
    Assert.assertEquals(client.getNodeId(), desClient.getNodeId());
    Assert.assertEquals(client.getEndpoint(), desClient.getEndpoint());
    Assert.assertEquals(client.getResources(), desClient.getResources());
    Assert.assertEquals(client.getSharedAttributes(), desClient.getSharedAttributes());
    Assert.assertEquals(client.getKeyTsLatestMap(), desClient.getKeyTsLatestMap());
    Assert.assertEquals(client.getTenantId(), desClient.getTenantId());
    Assert.assertEquals(client.getProfileId(), desClient.getProfileId());
    Assert.assertEquals(client.getDeviceId(), desClient.getDeviceId());
    Assert.assertEquals(client.getState(), desClient.getState());
    Assert.assertEquals(client.getSession(), desClient.getSession());
    Assert.assertEquals(client.getPowerMode(), desClient.getPowerMode());
    Assert.assertEquals(client.getPsmActivityTimer(), desClient.getPsmActivityTimer());
    Assert.assertEquals(client.getPagingTransmissionWindow(), desClient.getPagingTransmissionWindow());
    Assert.assertEquals(client.getEdrxCycle(), desClient.getEdrxCycle());
    Assert.assertEquals(client.getRegistration(), desClient.getRegistration());
    Assert.assertEquals(client.isAsleep(), desClient.isAsleep());
    Assert.assertEquals(client.getLastUplinkTime(), desClient.getLastUplinkTime());
    Assert.assertEquals(client.getSleepTask(), desClient.getSleepTask());
    Assert.assertEquals(client.getClientSupportContentFormats(), desClient.getClientSupportContentFormats());
    Assert.assertEquals(client.getDefaultContentFormat(), desClient.getDefaultContentFormat());
    Assert.assertEquals(client.getRetryAttempts().get(), desClient.getRetryAttempts().get());
    Assert.assertEquals(client.getLastSentRpcId(), desClient.getLastSentRpcId());
}
Also used : DeviceProfileId(org.thingsboard.server.common.data.id.DeviceProfileId) TransportDeviceInfo(org.thingsboard.server.common.transport.auth.TransportDeviceInfo) DeviceId(org.thingsboard.server.common.data.id.DeviceId) Registration(org.eclipse.leshan.server.registration.Registration) InetSocketAddress(java.net.InetSocketAddress) CustomerId(org.thingsboard.server.common.data.id.CustomerId) ValidateDeviceCredentialsResponse(org.thingsboard.server.common.transport.auth.ValidateDeviceCredentialsResponse) Link(org.eclipse.leshan.core.link.Link) LwM2mClient(org.thingsboard.server.transport.lwm2m.server.client.LwM2mClient) Test(org.junit.Test)

Example 4 with Link

use of org.eclipse.leshan.core.link.Link in project thingsboard by thingsboard.

the class LwM2MBootstrapConfigStoreTaskProvider method initAfterBootstrapDiscover.

private void initAfterBootstrapDiscover(BootstrapDiscoverResponse response) {
    Link[] links = response.getObjectLinks();
    Arrays.stream(links).forEach(link -> {
        LwM2mPath path = new LwM2mPath(link.getUriReference());
        if (!path.isRoot() && path.getObjectId() < 3) {
            if (path.isObject()) {
                String ver = link.getLinkParams().get("ver") != null ? link.getLinkParams().get("ver").getUnquoted() : "1.0";
                this.supportedObjects.put(path.getObjectId(), ver);
            }
        }
    });
}
Also used : LwM2mPath(org.eclipse.leshan.core.node.LwM2mPath) Link(org.eclipse.leshan.core.link.Link)

Aggregations

Link (org.eclipse.leshan.core.link.Link)4 InetSocketAddress (java.net.InetSocketAddress)2 LwM2mPath (org.eclipse.leshan.core.node.LwM2mPath)2 Registration (org.eclipse.leshan.server.registration.Registration)2 Test (org.junit.Test)2 CustomerId (org.thingsboard.server.common.data.id.CustomerId)1 DeviceId (org.thingsboard.server.common.data.id.DeviceId)1 DeviceProfileId (org.thingsboard.server.common.data.id.DeviceProfileId)1 TransportDeviceInfo (org.thingsboard.server.common.transport.auth.TransportDeviceInfo)1 ValidateDeviceCredentialsResponse (org.thingsboard.server.common.transport.auth.ValidateDeviceCredentialsResponse)1 LwM2mClient (org.thingsboard.server.transport.lwm2m.server.client.LwM2mClient)1