Showing
5 changed files
with
56 additions
and
4 deletions
... | ... | @@ -53,7 +53,7 @@ public class NoSecLwM2MIntegrationTest extends AbstractLwM2MIntegrationTest { |
53 | 53 | private final int PORT = 5685; |
54 | 54 | private final Security SECURITY = noSec("coap://localhost:" + PORT, 123); |
55 | 55 | private final NetworkConfig COAP_CONFIG = new NetworkConfig().setString("COAP_PORT", Integer.toString(PORT)); |
56 | - private final String ENDPOINT = "deviceAEndpoint"; | |
56 | + private final String ENDPOINT = "noSecEndpoint"; | |
57 | 57 | |
58 | 58 | private Device createDevice() throws Exception { |
59 | 59 | Device device = new Device(); | ... | ... |
... | ... | @@ -19,6 +19,7 @@ import org.eclipse.californium.core.network.config.NetworkConfig; |
19 | 19 | import org.eclipse.leshan.client.object.Security; |
20 | 20 | import org.jetbrains.annotations.NotNull; |
21 | 21 | import org.junit.Assert; |
22 | +import org.junit.Ignore; | |
22 | 23 | import org.junit.Test; |
23 | 24 | import org.thingsboard.common.util.JacksonUtil; |
24 | 25 | import org.thingsboard.server.common.data.Device; |
... | ... | @@ -74,11 +75,13 @@ public class X509LwM2MIntegrationTest extends AbstractLwM2MIntegrationTest { |
74 | 75 | return device; |
75 | 76 | } |
76 | 77 | |
78 | + //TODO: use different endpoints to isolate tests. | |
79 | + @Ignore() | |
77 | 80 | @Test |
78 | 81 | public void testConnectAndObserveTelemetry() throws Exception { |
79 | 82 | createDeviceProfile(TRANSPORT_CONFIGURATION); |
80 | 83 | X509ClientCredentials credentials = new X509ClientCredentials(); |
81 | - credentials.setEndpoint(endpoint); | |
84 | + credentials.setEndpoint(endpoint+1); | |
82 | 85 | Device device = createDevice(credentials); |
83 | 86 | |
84 | 87 | SingleEntityFilter sef = new SingleEntityFilter(); |
... | ... | @@ -96,7 +99,7 @@ public class X509LwM2MIntegrationTest extends AbstractLwM2MIntegrationTest { |
96 | 99 | wsClient.waitForReply(); |
97 | 100 | |
98 | 101 | wsClient.registerWaitForUpdate(); |
99 | - LwM2MTestClient client = new LwM2MTestClient(executor, endpoint); | |
102 | + LwM2MTestClient client = new LwM2MTestClient(executor, endpoint+1); | |
100 | 103 | Security security = x509(serverUri, 123, clientX509Cert.getEncoded(), clientPrivateKeyFromCert.getEncoded(), serverX509Cert.getEncoded()); |
101 | 104 | client.init(security, coapConfig); |
102 | 105 | String msg = wsClient.waitForUpdate(); | ... | ... |
... | ... | @@ -36,6 +36,8 @@ import java.util.concurrent.Executors; |
36 | 36 | import java.util.concurrent.ScheduledExecutorService; |
37 | 37 | import java.util.concurrent.TimeUnit; |
38 | 38 | |
39 | +import static org.eclipse.californium.core.network.config.NetworkConfigDefaults.DEFAULT_BLOCKWISE_STATUS_LIFETIME; | |
40 | + | |
39 | 41 | @Slf4j |
40 | 42 | @Component |
41 | 43 | @TbCoapServerComponent |
... | ... | @@ -91,7 +93,16 @@ public class DefaultCoapServerService implements CoapServerService { |
91 | 93 | InetAddress addr = InetAddress.getByName(coapServerContext.getHost()); |
92 | 94 | InetSocketAddress sockAddr = new InetSocketAddress(addr, coapServerContext.getPort()); |
93 | 95 | noSecCoapEndpointBuilder.setInetSocketAddress(sockAddr); |
94 | - noSecCoapEndpointBuilder.setNetworkConfig(NetworkConfig.getStandard()); | |
96 | + NetworkConfig networkConfig = new NetworkConfig(); | |
97 | + networkConfig.setBoolean(NetworkConfig.Keys.BLOCKWISE_STRICT_BLOCK2_OPTION, true); | |
98 | + networkConfig.setBoolean(NetworkConfig.Keys.BLOCKWISE_ENTITY_TOO_LARGE_AUTO_FAILOVER, true); | |
99 | + networkConfig.setLong(NetworkConfig.Keys.BLOCKWISE_STATUS_LIFETIME, DEFAULT_BLOCKWISE_STATUS_LIFETIME); | |
100 | + networkConfig.setInt(NetworkConfig.Keys.MAX_RESOURCE_BODY_SIZE, 256 * 1024 * 1024); | |
101 | + networkConfig.setString(NetworkConfig.Keys.RESPONSE_MATCHING, "RELAXED"); | |
102 | + networkConfig.setInt(NetworkConfig.Keys.PREFERRED_BLOCK_SIZE, 1024); | |
103 | + networkConfig.setInt(NetworkConfig.Keys.MAX_MESSAGE_SIZE, 1024); | |
104 | + networkConfig.setInt(NetworkConfig.Keys.MAX_RETRANSMIT, 4); | |
105 | + noSecCoapEndpointBuilder.setNetworkConfig(networkConfig); | |
95 | 106 | CoapEndpoint noSecCoapEndpoint = noSecCoapEndpointBuilder.build(); |
96 | 107 | server.addEndpoint(noSecCoapEndpoint); |
97 | 108 | ... | ... |
... | ... | @@ -20,8 +20,10 @@ import org.eclipse.californium.core.coap.CoAP; |
20 | 20 | import org.eclipse.californium.core.coap.Request; |
21 | 21 | import org.eclipse.californium.core.coap.Response; |
22 | 22 | import org.eclipse.californium.core.network.Exchange; |
23 | +import org.eclipse.californium.core.observe.ObserveRelation; | |
23 | 24 | import org.eclipse.californium.core.server.resources.CoapExchange; |
24 | 25 | import org.eclipse.californium.core.server.resources.Resource; |
26 | +import org.eclipse.californium.core.server.resources.ResourceObserver; | |
25 | 27 | import org.thingsboard.server.common.data.DeviceTransportType; |
26 | 28 | import org.thingsboard.server.common.data.StringUtils; |
27 | 29 | import org.thingsboard.server.common.data.ota.OtaPackageType; |
... | ... | @@ -41,6 +43,8 @@ public class OtaPackageTransportResource extends AbstractCoapTransportResource { |
41 | 43 | |
42 | 44 | public OtaPackageTransportResource(CoapTransportContext ctx, OtaPackageType otaPackageType) { |
43 | 45 | super(ctx, otaPackageType.getKeyPrefix()); |
46 | + this.setObservable(true); | |
47 | + this.addObserver(new OtaPackageTransportResource.CoapResourceObserver()); | |
44 | 48 | this.otaPackageType = otaPackageType; |
45 | 49 | } |
46 | 50 | |
... | ... | @@ -135,10 +139,43 @@ public class OtaPackageTransportResource extends AbstractCoapTransportResource { |
135 | 139 | if (exchange.getRequestOptions().getBlock2() != null) { |
136 | 140 | int chunkSize = exchange.getRequestOptions().getBlock2().getSzx(); |
137 | 141 | boolean lastFlag = data.length > chunkSize; |
142 | + response.getOptions().setUriPath(exchange.getRequestOptions().getUriPathString()); | |
138 | 143 | response.getOptions().setBlock2(chunkSize, lastFlag, 0); |
139 | 144 | } |
140 | 145 | exchange.respond(response); |
141 | 146 | } |
142 | 147 | } |
143 | 148 | |
149 | + public class CoapResourceObserver implements ResourceObserver { | |
150 | + @Override | |
151 | + public void changedName(String old) { | |
152 | + | |
153 | + } | |
154 | + | |
155 | + @Override | |
156 | + public void changedPath(String old) { | |
157 | + | |
158 | + } | |
159 | + | |
160 | + @Override | |
161 | + public void addedChild(Resource child) { | |
162 | + | |
163 | + } | |
164 | + | |
165 | + @Override | |
166 | + public void removedChild(Resource child) { | |
167 | + | |
168 | + } | |
169 | + | |
170 | + @Override | |
171 | + public void addedObserveRelation(ObserveRelation relation) { | |
172 | + | |
173 | + } | |
174 | + | |
175 | + @Override | |
176 | + public void removedObserveRelation(ObserveRelation relation) { | |
177 | + | |
178 | + } | |
179 | + } | |
180 | + | |
144 | 181 | } | ... | ... |
... | ... | @@ -256,6 +256,7 @@ public class DefaultLwM2MUplinkMsgHandler extends LwM2MExecutorAwareService impl |
256 | 256 | LwM2mClient lwM2MClient = clientContext.getClientByEndpoint(registration.getEndpoint()); |
257 | 257 | try { |
258 | 258 | log.warn("[{}] [{{}] Client: update after Registration", registration.getEndpoint(), registration.getId()); |
259 | + logService.log(lwM2MClient, String.format("[%s][%s] Updated registration.", registration.getId(), registration.getSocketAddress())); | |
259 | 260 | clientContext.updateRegistration(lwM2MClient, registration); |
260 | 261 | TransportProtos.SessionInfoProto sessionInfo = lwM2MClient.getSession(); |
261 | 262 | this.reportActivityAndRegister(sessionInfo); | ... | ... |