added ability to configure network configuration for lwm2m

This commit is contained in:
YevhenBondarenko 2021-11-17 12:13:05 +02:00
parent 77b9a8c1af
commit 52578645b8
6 changed files with 25 additions and 10 deletions

View File

@ -819,6 +819,9 @@ transport:
log_max_length: "${LWM2M_LOG_MAX_LENGTH:1024}"
# Use redis for Security and Registration stores
redis.enabled: "${LWM2M_REDIS_ENABLED:false}"
network_config:
- key: "PROTOCOL_STAGE_THREAD_COUNT"
value: "${LWM2M_PROTOCOL_STAGE_THREAD_COUNT:12}"
snmp:
enabled: "${SNMP_ENABLED:true}"
response_processing:

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.queue.kafka;
package org.thingsboard.server.common.data;
import lombok.Data;
@ -21,7 +21,7 @@ import lombok.Data;
* Created by ashvayka on 25.09.18.
*/
@Data
public class TbKafkaProperty {
public class TbProperty {
private String key;
private String value;

View File

@ -30,6 +30,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import org.thingsboard.server.common.data.TbProperty;
import java.util.Collections;
import java.util.List;
@ -104,10 +105,10 @@ public class TbKafkaSettings {
private String securityProtocol;
@Setter
private List<TbKafkaProperty> other;
private List<TbProperty> other;
@Setter
private Map<String, List<TbKafkaProperty>> consumerPropertiesPerTopic = Collections.emptyMap();
private Map<String, List<TbProperty>> consumerPropertiesPerTopic = Collections.emptyMap();
public Properties toAdminProps() {
Properties props = toProps();

View File

@ -25,17 +25,16 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.thingsboard.server.common.data.ResourceUtils;
import org.thingsboard.server.common.data.TbProperty;
import org.thingsboard.server.common.transport.config.ssl.SslCredentials;
import org.thingsboard.server.common.transport.config.ssl.SslCredentialsConfig;
import javax.annotation.PostConstruct;
import java.io.InputStream;
import java.security.KeyStore;
import java.util.List;
@Slf4j
@Component
@ConditionalOnExpression("('${service.type:null}'=='tb-transport' && '${transport.lwm2m.enabled:false}'=='true') || '${service.type:null}'=='monolith' || '${service.type:null}'=='tb-core'")
@ConfigurationProperties(prefix = "transport.lwm2m")
public class LwM2MTransportServerConfig implements LwM2MSecureServerConfig {
@Getter
@ -102,6 +101,10 @@ public class LwM2MTransportServerConfig implements LwM2MSecureServerConfig {
@Value("${transport.lwm2m.paging_transmission_window:10000}")
private long pagingTransmissionWindow;
@Getter
@Setter
private List<TbProperty> networkConfig;
@Bean
@ConfigurationProperties(prefix = "transport.lwm2m.server.security.credentials")
public SslCredentialsConfig lwm2mServerCredentials() {

View File

@ -17,6 +17,7 @@ package org.thingsboard.server.transport.lwm2m.server;
import org.eclipse.californium.core.network.config.NetworkConfig;
import org.eclipse.californium.core.network.config.NetworkConfigDefaults;
import org.springframework.util.CollectionUtils;
import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig;
import static org.eclipse.californium.core.network.config.NetworkConfigDefaults.DEFAULT_BLOCKWISE_STATUS_LIFETIME;
@ -25,8 +26,8 @@ public class LwM2mNetworkConfig {
public static NetworkConfig getCoapConfig(Integer serverPortNoSec, Integer serverSecurePort, LwM2MTransportServerConfig config) {
NetworkConfig coapConfig = new NetworkConfig();
coapConfig.setInt(NetworkConfig.Keys.COAP_PORT,serverPortNoSec);
coapConfig.setInt(NetworkConfig.Keys.COAP_SECURE_PORT,serverSecurePort);
coapConfig.setInt(NetworkConfig.Keys.COAP_PORT, serverPortNoSec);
coapConfig.setInt(NetworkConfig.Keys.COAP_SECURE_PORT, serverSecurePort);
/**
Example:Property for large packet:
#NetworkConfig config = new NetworkConfig();
@ -105,6 +106,10 @@ public class LwM2mNetworkConfig {
coapConfig.setInt(NetworkConfig.Keys.MAX_RETRANSMIT, 10);
if (!CollectionUtils.isEmpty(config.getNetworkConfig())) {
config.getNetworkConfig().forEach(p -> coapConfig.setString(p.getKey(), p.getValue()));
}
return coapConfig;
}
}

View File

@ -204,6 +204,9 @@ transport:
paging_transmission_window: "${LWM2M_PAGING_TRANSMISSION_WINDOW:10000}"
# Use redis for Security and Registration stores
redis.enabled: "${LWM2M_REDIS_ENABLED:false}"
network_config:
- key: "PROTOCOL_STAGE_THREAD_COUNT"
value: "${LWM2M_PROTOCOL_STAGE_THREAD_COUNT:12}"
stats:
enabled: "${TB_TRANSPORT_STATS_ENABLED:true}"
print-interval-ms: "${TB_TRANSPORT_STATS_PRINT_INTERVAL_MS:60000}"