Browse Source

lwm2m: client queue Mode

pull/10174/head
nick 3 years ago
parent
commit
cb674048e7
  1. 18
      application/src/test/java/org/thingsboard/server/transport/lwm2m/AbstractLwM2MIntegrationTest.java
  2. 7
      application/src/test/java/org/thingsboard/server/transport/lwm2m/client/LwM2MTestClient.java
  3. 6
      application/src/test/java/org/thingsboard/server/transport/lwm2m/ota/sql/OtaLwM2MIntegrationTest.java
  4. 2
      application/src/test/java/org/thingsboard/server/transport/lwm2m/rpc/AbstractRpcLwM2MIntegrationTest.java
  5. 4
      application/src/test/java/org/thingsboard/server/transport/lwm2m/security/AbstractSecurityLwM2MIntegrationTest.java
  6. 8
      application/src/test/java/org/thingsboard/server/transport/lwm2m/security/sql/NoSecLwM2MIntegrationTest.java
  7. 12
      common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/client/LwM2mClientContextImpl.java

18
application/src/test/java/org/thingsboard/server/transport/lwm2m/AbstractLwM2MIntegrationTest.java

@ -219,7 +219,8 @@ public abstract class AbstractLwM2MIntegrationTest extends AbstractTransportInte
public void basicTestConnectionObserveTelemetry(Security security, public void basicTestConnectionObserveTelemetry(Security security,
LwM2MDeviceCredentials deviceCredentials, LwM2MDeviceCredentials deviceCredentials,
Configuration coapConfig, Configuration coapConfig,
String endpoint) throws Exception { String endpoint,
boolean queueMode) throws Exception {
Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITH_PARAMS, getBootstrapServerCredentialsNoSec(NONE)); Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITH_PARAMS, getBootstrapServerCredentialsNoSec(NONE));
createDeviceProfile(transportConfiguration); createDeviceProfile(transportConfiguration);
Device device = createDevice(deviceCredentials, endpoint); Device device = createDevice(deviceCredentials, endpoint);
@ -236,7 +237,7 @@ public abstract class AbstractLwM2MIntegrationTest extends AbstractTransportInte
getWsClient().waitForReply(); getWsClient().waitForReply();
getWsClient().registerWaitForUpdate(); getWsClient().registerWaitForUpdate();
createNewClient(security, null, coapConfig, false, endpoint, null); createNewClient(security, null, coapConfig, false, endpoint, null, queueMode);
deviceId = device.getId().getId().toString(); deviceId = device.getId().getId().toString();
awaitObserveReadAll(0, deviceId); awaitObserveReadAll(0, deviceId);
String msg = getWsClient().waitForUpdate(); String msg = getWsClient().waitForUpdate();
@ -304,15 +305,26 @@ public abstract class AbstractLwM2MIntegrationTest extends AbstractTransportInte
this.resources = resources; this.resources = resources;
} }
public void createNewClient(Security security, Security securityBs, Configuration coapConfig, boolean isRpc,
String endpoint) throws Exception {
this.createNewClient(security, securityBs, coapConfig, isRpc, endpoint, null, false);
}
public void createNewClient(Security security, Security securityBs, Configuration coapConfig, boolean isRpc, public void createNewClient(Security security, Security securityBs, Configuration coapConfig, boolean isRpc,
String endpoint, Integer clientDtlsCidLength) throws Exception { String endpoint, Integer clientDtlsCidLength) throws Exception {
this.createNewClient(security, securityBs, coapConfig, isRpc, endpoint, clientDtlsCidLength, false);
}
public void createNewClient(Security security, Security securityBs, Configuration coapConfig, boolean isRpc,
String endpoint, Integer clientDtlsCidLength, boolean queueMode) throws Exception {
this.clientDestroy(); this.clientDestroy();
lwM2MTestClient = new LwM2MTestClient(this.executor, endpoint); lwM2MTestClient = new LwM2MTestClient(this.executor, endpoint);
try (ServerSocket socket = new ServerSocket(0)) { try (ServerSocket socket = new ServerSocket(0)) {
int clientPort = socket.getLocalPort(); int clientPort = socket.getLocalPort();
lwM2MTestClient.init(security, securityBs, coapConfig, clientPort, isRpc, lwM2MTestClient.init(security, securityBs, coapConfig, clientPort, isRpc,
this.defaultLwM2mUplinkMsgHandlerTest, this.clientContextTest, isWriteAttribute, clientDtlsCidLength); this.defaultLwM2mUplinkMsgHandlerTest, this.clientContextTest, isWriteAttribute
, clientDtlsCidLength, queueMode);
} }
} }

7
application/src/test/java/org/thingsboard/server/transport/lwm2m/client/LwM2MTestClient.java

@ -129,7 +129,7 @@ public class LwM2MTestClient {
public void init(Security security, Security securityBs,Configuration coapConfig, int port, boolean isRpc, public void init(Security security, Security securityBs,Configuration coapConfig, int port, boolean isRpc,
LwM2mUplinkMsgHandler defaultLwM2mUplinkMsgHandler, LwM2mUplinkMsgHandler defaultLwM2mUplinkMsgHandler,
LwM2mClientContext clientContext, boolean isWriteAttribute, Integer cIdLength) throws InvalidDDFFileException, IOException { LwM2mClientContext clientContext, boolean isWriteAttribute, Integer cIdLength, boolean queueMode) throws InvalidDDFFileException, IOException {
Assert.assertNull("client already initialized", leshanClient); Assert.assertNull("client already initialized", leshanClient);
this.defaultLwM2mUplinkMsgHandlerTest = defaultLwM2mUplinkMsgHandler; this.defaultLwM2mUplinkMsgHandlerTest = defaultLwM2mUplinkMsgHandler;
this.clientContext = clientContext; this.clientContext = clientContext;
@ -263,11 +263,10 @@ public class LwM2MTestClient {
boolean reconnectOnUpdate = false; boolean reconnectOnUpdate = false;
engineFactory.setReconnectOnUpdate(reconnectOnUpdate); engineFactory.setReconnectOnUpdate(reconnectOnUpdate);
engineFactory.setResumeOnConnect(true); engineFactory.setResumeOnConnect(true);
// new
/** /**
* Client use queue mode (not fully implemented). * Client use queue mode.
*/ */
boolean queueMode = false;
engineFactory.setQueueMode(queueMode); engineFactory.setQueueMode(queueMode);
// Create client // Create client

6
application/src/test/java/org/thingsboard/server/transport/lwm2m/ota/sql/OtaLwM2MIntegrationTest.java

@ -59,7 +59,7 @@ public class OtaLwM2MIntegrationTest extends AbstractOtaLwM2MIntegrationTest {
createDeviceProfile(transportConfiguration); createDeviceProfile(transportConfiguration);
LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsNoSec(createNoSecClientCredentials(this.CLIENT_ENDPOINT_WITHOUT_FW_INFO)); LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsNoSec(createNoSecClientCredentials(this.CLIENT_ENDPOINT_WITHOUT_FW_INFO));
final Device device = createDevice(deviceCredentials, this.CLIENT_ENDPOINT_WITHOUT_FW_INFO); final Device device = createDevice(deviceCredentials, this.CLIENT_ENDPOINT_WITHOUT_FW_INFO);
createNewClient(SECURITY_NO_SEC, null, COAP_CONFIG, false, this.CLIENT_ENDPOINT_WITHOUT_FW_INFO, null); createNewClient(SECURITY_NO_SEC, null, COAP_CONFIG, false, this.CLIENT_ENDPOINT_WITHOUT_FW_INFO);
awaitObserveReadAll(0, device.getId().getId().toString()); awaitObserveReadAll(0, device.getId().getId().toString());
device.setFirmwareId(createFirmware().getId()); device.setFirmwareId(createFirmware().getId());
@ -84,7 +84,7 @@ public class OtaLwM2MIntegrationTest extends AbstractOtaLwM2MIntegrationTest {
createDeviceProfile(transportConfiguration); createDeviceProfile(transportConfiguration);
LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsNoSec(createNoSecClientCredentials(this.CLIENT_ENDPOINT_OTA5)); LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsNoSec(createNoSecClientCredentials(this.CLIENT_ENDPOINT_OTA5));
final Device device = createDevice(deviceCredentials, this.CLIENT_ENDPOINT_OTA5); final Device device = createDevice(deviceCredentials, this.CLIENT_ENDPOINT_OTA5);
createNewClient(SECURITY_NO_SEC, null, COAP_CONFIG, false, this.CLIENT_ENDPOINT_OTA5, null); createNewClient(SECURITY_NO_SEC, null, COAP_CONFIG, false, this.CLIENT_ENDPOINT_OTA5);
awaitObserveReadAll(9, device.getId().getId().toString()); awaitObserveReadAll(9, device.getId().getId().toString());
device.setFirmwareId(createFirmware().getId()); device.setFirmwareId(createFirmware().getId());
@ -114,7 +114,7 @@ public class OtaLwM2MIntegrationTest extends AbstractOtaLwM2MIntegrationTest {
createDeviceProfile(transportConfiguration); createDeviceProfile(transportConfiguration);
LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsNoSec(createNoSecClientCredentials(this.CLIENT_ENDPOINT_OTA9)); LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsNoSec(createNoSecClientCredentials(this.CLIENT_ENDPOINT_OTA9));
final Device device = createDevice(deviceCredentials, this.CLIENT_ENDPOINT_OTA9); final Device device = createDevice(deviceCredentials, this.CLIENT_ENDPOINT_OTA9);
createNewClient(SECURITY_NO_SEC, null, COAP_CONFIG, false, this.CLIENT_ENDPOINT_OTA9, null); createNewClient(SECURITY_NO_SEC, null, COAP_CONFIG, false, this.CLIENT_ENDPOINT_OTA9);
awaitObserveReadAll(9, device.getId().getId().toString()); awaitObserveReadAll(9, device.getId().getId().toString());
device.setSoftwareId(createSoftware().getId()); device.setSoftwareId(createSoftware().getId());

2
application/src/test/java/org/thingsboard/server/transport/lwm2m/rpc/AbstractRpcLwM2MIntegrationTest.java

@ -91,7 +91,7 @@ public abstract class AbstractRpcLwM2MIntegrationTest extends AbstractLwM2MInteg
private void initRpc () throws Exception { private void initRpc () throws Exception {
String endpoint = DEVICE_ENDPOINT_RPC_PREF + endpointSequence.incrementAndGet(); String endpoint = DEVICE_ENDPOINT_RPC_PREF + endpointSequence.incrementAndGet();
createNewClient(SECURITY_NO_SEC, null, COAP_CONFIG, true, endpoint, null); createNewClient(SECURITY_NO_SEC, null, COAP_CONFIG, true, endpoint);
expectedObjects = ConcurrentHashMap.newKeySet(); expectedObjects = ConcurrentHashMap.newKeySet();
expectedObjectIdVers = ConcurrentHashMap.newKeySet(); expectedObjectIdVers = ConcurrentHashMap.newKeySet();
expectedInstances = ConcurrentHashMap.newKeySet(); expectedInstances = ConcurrentHashMap.newKeySet();

4
application/src/test/java/org/thingsboard/server/transport/lwm2m/security/AbstractSecurityLwM2MIntegrationTest.java

@ -196,7 +196,7 @@ public abstract class AbstractSecurityLwM2MIntegrationTest extends AbstractLwM2M
boolean isStartLw) throws Exception { boolean isStartLw) throws Exception {
createDeviceProfile(transportConfiguration); createDeviceProfile(transportConfiguration);
final Device device = createDevice(deviceCredentials, endpoint); final Device device = createDevice(deviceCredentials, endpoint);
createNewClient(security, securityBs, coapConfig, true, endpoint, null); createNewClient(security, securityBs, coapConfig, true, endpoint);
lwM2MTestClient.start(isStartLw); lwM2MTestClient.start(isStartLw);
if (isAwaitObserveReadAll) { if (isAwaitObserveReadAll) {
awaitObserveReadAll(0, device.getId().getId().toString()); awaitObserveReadAll(0, device.getId().getId().toString());
@ -244,7 +244,7 @@ public abstract class AbstractSecurityLwM2MIntegrationTest extends AbstractLwM2M
createDeviceProfile(transportConfiguration); createDeviceProfile(transportConfiguration);
final Device device = createDevice(deviceCredentials, endpoint); final Device device = createDevice(deviceCredentials, endpoint);
String deviceIdStr = device.getId().getId().toString(); String deviceIdStr = device.getId().getId().toString();
createNewClient(security, securityBs, coapConfig, true, endpoint, null); createNewClient(security, securityBs, coapConfig, true, endpoint);
lwM2MTestClient.start(true); lwM2MTestClient.start(true);
awaitObserveReadAll(0, deviceIdStr); awaitObserveReadAll(0, deviceIdStr);
await(awaitAlias) await(awaitAlias)

8
application/src/test/java/org/thingsboard/server/transport/lwm2m/security/sql/NoSecLwM2MIntegrationTest.java

@ -32,7 +32,13 @@ public class NoSecLwM2MIntegrationTest extends AbstractSecurityLwM2MIntegrationT
public void testWithNoSecConnectLwm2mSuccessAndObserveTelemetry() throws Exception { public void testWithNoSecConnectLwm2mSuccessAndObserveTelemetry() throws Exception {
String clientEndpoint = CLIENT_ENDPOINT_NO_SEC; String clientEndpoint = CLIENT_ENDPOINT_NO_SEC;
LwM2MDeviceCredentials clientCredentials = getDeviceCredentialsNoSec(createNoSecClientCredentials(clientEndpoint)); LwM2MDeviceCredentials clientCredentials = getDeviceCredentialsNoSec(createNoSecClientCredentials(clientEndpoint));
super.basicTestConnectionObserveTelemetry(SECURITY_NO_SEC, clientCredentials, COAP_CONFIG, clientEndpoint); super.basicTestConnectionObserveTelemetry(SECURITY_NO_SEC, clientCredentials, COAP_CONFIG, clientEndpoint, false);
}
@Test
public void testWithNoSecQueueModeConnectLwm2mSuccessAndObserveTelemetry() throws Exception {
String clientEndpoint = CLIENT_ENDPOINT_NO_SEC + "_QueueMode";
LwM2MDeviceCredentials clientCredentials = getDeviceCredentialsNoSec(createNoSecClientCredentials(clientEndpoint));
super.basicTestConnectionObserveTelemetry(SECURITY_NO_SEC, clientCredentials, COAP_CONFIG, clientEndpoint, true);
} }
// Bootstrap + Lwm2m // Bootstrap + Lwm2m

12
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/client/LwM2mClientContextImpl.java

@ -461,11 +461,15 @@ public class LwM2mClientContextImpl implements LwM2mClientContext {
PowerMode powerMode = client.getPowerMode(); PowerMode powerMode = client.getPowerMode();
OtherConfiguration profileSettings = null; OtherConfiguration profileSettings = null;
if (powerMode == null) { if (powerMode == null) {
var clientProfile = getProfile(client.getProfileId()); if (client.getProfileId() == null) {
profileSettings = clientProfile.getClientLwM2mSettings();
powerMode = profileSettings.getPowerMode();
if (powerMode == null) {
powerMode = PowerMode.DRX; powerMode = PowerMode.DRX;
} else {
var clientProfile = getProfile(client.getProfileId());
profileSettings = clientProfile.getClientLwM2mSettings();
powerMode = profileSettings.getPowerMode();
if (powerMode == null) {
powerMode = PowerMode.DRX;
}
} }
} }
if (PowerMode.DRX.equals(powerMode)) { if (PowerMode.DRX.equals(powerMode)) {

Loading…
Cancel
Save