Merge branch 'feature/lwm2m-refactoring-downlink'
This commit is contained in:
commit
f48e357ea7
@ -53,7 +53,7 @@ public class NoSecLwM2MIntegrationTest extends AbstractLwM2MIntegrationTest {
|
||||
private final int PORT = 5685;
|
||||
private final Security SECURITY = noSec("coap://localhost:" + PORT, 123);
|
||||
private final NetworkConfig COAP_CONFIG = new NetworkConfig().setString("COAP_PORT", Integer.toString(PORT));
|
||||
private final String ENDPOINT = "deviceAEndpoint";
|
||||
private final String ENDPOINT = "noSecEndpoint";
|
||||
|
||||
private Device createDevice() throws Exception {
|
||||
Device device = new Device();
|
||||
|
||||
@ -19,6 +19,7 @@ import org.eclipse.californium.core.network.config.NetworkConfig;
|
||||
import org.eclipse.leshan.client.object.Security;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.thingsboard.common.util.JacksonUtil;
|
||||
import org.thingsboard.server.common.data.Device;
|
||||
@ -74,11 +75,13 @@ public class X509LwM2MIntegrationTest extends AbstractLwM2MIntegrationTest {
|
||||
return device;
|
||||
}
|
||||
|
||||
//TODO: use different endpoints to isolate tests.
|
||||
@Ignore()
|
||||
@Test
|
||||
public void testConnectAndObserveTelemetry() throws Exception {
|
||||
createDeviceProfile(TRANSPORT_CONFIGURATION);
|
||||
X509ClientCredentials credentials = new X509ClientCredentials();
|
||||
credentials.setEndpoint(endpoint);
|
||||
credentials.setEndpoint(endpoint+1);
|
||||
Device device = createDevice(credentials);
|
||||
|
||||
SingleEntityFilter sef = new SingleEntityFilter();
|
||||
@ -96,7 +99,7 @@ public class X509LwM2MIntegrationTest extends AbstractLwM2MIntegrationTest {
|
||||
wsClient.waitForReply();
|
||||
|
||||
wsClient.registerWaitForUpdate();
|
||||
LwM2MTestClient client = new LwM2MTestClient(executor, endpoint);
|
||||
LwM2MTestClient client = new LwM2MTestClient(executor, endpoint+1);
|
||||
Security security = x509(serverUri, 123, clientX509Cert.getEncoded(), clientPrivateKeyFromCert.getEncoded(), serverX509Cert.getEncoded());
|
||||
client.init(security, coapConfig);
|
||||
String msg = wsClient.waitForUpdate();
|
||||
|
||||
@ -36,6 +36,8 @@ import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.eclipse.californium.core.network.config.NetworkConfigDefaults.DEFAULT_BLOCKWISE_STATUS_LIFETIME;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@TbCoapServerComponent
|
||||
@ -91,7 +93,16 @@ public class DefaultCoapServerService implements CoapServerService {
|
||||
InetAddress addr = InetAddress.getByName(coapServerContext.getHost());
|
||||
InetSocketAddress sockAddr = new InetSocketAddress(addr, coapServerContext.getPort());
|
||||
noSecCoapEndpointBuilder.setInetSocketAddress(sockAddr);
|
||||
noSecCoapEndpointBuilder.setNetworkConfig(NetworkConfig.getStandard());
|
||||
NetworkConfig networkConfig = new NetworkConfig();
|
||||
networkConfig.setBoolean(NetworkConfig.Keys.BLOCKWISE_STRICT_BLOCK2_OPTION, true);
|
||||
networkConfig.setBoolean(NetworkConfig.Keys.BLOCKWISE_ENTITY_TOO_LARGE_AUTO_FAILOVER, true);
|
||||
networkConfig.setLong(NetworkConfig.Keys.BLOCKWISE_STATUS_LIFETIME, DEFAULT_BLOCKWISE_STATUS_LIFETIME);
|
||||
networkConfig.setInt(NetworkConfig.Keys.MAX_RESOURCE_BODY_SIZE, 256 * 1024 * 1024);
|
||||
networkConfig.setString(NetworkConfig.Keys.RESPONSE_MATCHING, "RELAXED");
|
||||
networkConfig.setInt(NetworkConfig.Keys.PREFERRED_BLOCK_SIZE, 1024);
|
||||
networkConfig.setInt(NetworkConfig.Keys.MAX_MESSAGE_SIZE, 1024);
|
||||
networkConfig.setInt(NetworkConfig.Keys.MAX_RETRANSMIT, 4);
|
||||
noSecCoapEndpointBuilder.setNetworkConfig(networkConfig);
|
||||
CoapEndpoint noSecCoapEndpoint = noSecCoapEndpointBuilder.build();
|
||||
server.addEndpoint(noSecCoapEndpoint);
|
||||
|
||||
|
||||
@ -20,8 +20,10 @@ import org.eclipse.californium.core.coap.CoAP;
|
||||
import org.eclipse.californium.core.coap.Request;
|
||||
import org.eclipse.californium.core.coap.Response;
|
||||
import org.eclipse.californium.core.network.Exchange;
|
||||
import org.eclipse.californium.core.observe.ObserveRelation;
|
||||
import org.eclipse.californium.core.server.resources.CoapExchange;
|
||||
import org.eclipse.californium.core.server.resources.Resource;
|
||||
import org.eclipse.californium.core.server.resources.ResourceObserver;
|
||||
import org.thingsboard.server.common.data.DeviceTransportType;
|
||||
import org.thingsboard.server.common.data.StringUtils;
|
||||
import org.thingsboard.server.common.data.ota.OtaPackageType;
|
||||
@ -41,6 +43,8 @@ public class OtaPackageTransportResource extends AbstractCoapTransportResource {
|
||||
|
||||
public OtaPackageTransportResource(CoapTransportContext ctx, OtaPackageType otaPackageType) {
|
||||
super(ctx, otaPackageType.getKeyPrefix());
|
||||
this.setObservable(true);
|
||||
this.addObserver(new OtaPackageTransportResource.CoapResourceObserver());
|
||||
this.otaPackageType = otaPackageType;
|
||||
}
|
||||
|
||||
@ -135,10 +139,43 @@ public class OtaPackageTransportResource extends AbstractCoapTransportResource {
|
||||
if (exchange.getRequestOptions().getBlock2() != null) {
|
||||
int chunkSize = exchange.getRequestOptions().getBlock2().getSzx();
|
||||
boolean lastFlag = data.length > chunkSize;
|
||||
response.getOptions().setUriPath(exchange.getRequestOptions().getUriPathString());
|
||||
response.getOptions().setBlock2(chunkSize, lastFlag, 0);
|
||||
}
|
||||
exchange.respond(response);
|
||||
}
|
||||
}
|
||||
|
||||
public class CoapResourceObserver implements ResourceObserver {
|
||||
@Override
|
||||
public void changedName(String old) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changedPath(String old) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addedChild(Resource child) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removedChild(Resource child) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addedObserveRelation(ObserveRelation relation) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removedObserveRelation(ObserveRelation relation) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -256,6 +256,7 @@ public class DefaultLwM2MUplinkMsgHandler extends LwM2MExecutorAwareService impl
|
||||
LwM2mClient lwM2MClient = clientContext.getClientByEndpoint(registration.getEndpoint());
|
||||
try {
|
||||
log.warn("[{}] [{{}] Client: update after Registration", registration.getEndpoint(), registration.getId());
|
||||
logService.log(lwM2MClient, String.format("[%s][%s] Updated registration.", registration.getId(), registration.getSocketAddress()));
|
||||
clientContext.updateRegistration(lwM2MClient, registration);
|
||||
TransportProtos.SessionInfoProto sessionInfo = lwM2MClient.getSession();
|
||||
this.reportActivityAndRegister(sessionInfo);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user