Skip to content

Commit

Permalink
net: samples: native_sim support
Browse files Browse the repository at this point in the history
Add native sim support to samples aws_iot, azure_iot_hub and udp.

Signed-off-by: Giacomo Dematteis <giacomo.dematteis@nordicsemi.no>
  • Loading branch information
DematteisGiacomo authored and rlubos committed Jan 3, 2024
1 parent 0ab5a76 commit 882627d
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 3 deletions.
49 changes: 49 additions & 0 deletions samples/net/aws_iot/boards/native_sim.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#
# Copyright (c) 2023 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

# Networking config
CONFIG_NET_TCP=y
CONFIG_NET_UDP=y
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_POSIX_NAMES=y
CONFIG_NET_SOCKETS_SOCKOPT_TLS=y
CONFIG_NET_PKT_RX_COUNT=32
CONFIG_NET_PKT_TX_COUNT=32
CONFIG_NET_BUF_RX_COUNT=32
CONFIG_NET_BUF_TX_COUNT=32
CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=3
CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=4
CONFIG_NET_MAX_CONTEXTS=10
CONFIG_NET_L2_ETHERNET=y
CONFIG_NET_CONTEXT_SNDTIMEO=y

CONFIG_ETH_NATIVE_POSIX=y
CONFIG_ETH_NATIVE_POSIX_RANDOM_MAC=y

# Network driver config
CONFIG_TEST_RANDOM_GENERATOR=y

# TLS configuration
CONFIG_MBEDTLS=y
CONFIG_MBEDTLS_BUILTIN=y
CONFIG_MBEDTLS_ENABLE_HEAP=y
CONFIG_MBEDTLS_HEAP_SIZE=40000
CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=7168
CONFIG_MBEDTLS_PEM_CERTIFICATE_FORMAT=y
CONFIG_MBEDTLS_KEY_EXCHANGE_RSA_ENABLED=y
CONFIG_MBEDTLS_MAC_SHA256_ENABLED=y

# DNS
CONFIG_DNS_RESOLVER=y
CONFIG_DNS_SERVER_IP_ADDRESSES=y
CONFIG_DNS_SERVER1="8.8.8.8"
CONFIG_DNS_RESOLVER_MAX_SERVERS=2

# Network address config
CONFIG_NET_CONFIG_SETTINGS=y
CONFIG_NET_CONFIG_NEED_IPV4=y
CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.1"
CONFIG_NET_CONFIG_MY_IPV4_GW="192.0.2.2"
2 changes: 1 addition & 1 deletion samples/net/aws_iot/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ int main(void)
* This means that NET_EVENT_L4_CONNECTED fires before the
* appropriate handler l4_event_handler() is registered.
*/
if (IS_ENABLED(CONFIG_BOARD_QEMU_X86)) {
if (IS_ENABLED(CONFIG_BOARD_QEMU_X86) || IS_ENABLED(CONFIG_BOARD_NATIVE_SIM)) {
conn_mgr_mon_resend_status();
}

Expand Down
56 changes: 56 additions & 0 deletions samples/net/azure_iot_hub/boards/native_sim.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#
# Copyright (c) 2023 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

# Heap and stacks
CONFIG_HEAP_MEM_POOL_SIZE=1024

# Networking config
CONFIG_NET_TCP=y
CONFIG_NET_UDP=y
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_POSIX_NAMES=y
CONFIG_NET_SOCKETS_SOCKOPT_TLS=y
CONFIG_NET_PKT_RX_COUNT=32
CONFIG_NET_PKT_TX_COUNT=32
CONFIG_NET_BUF_RX_COUNT=32
CONFIG_NET_BUF_TX_COUNT=32
CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=3
CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=4
CONFIG_NET_MAX_CONTEXTS=10
CONFIG_NET_L2_ETHERNET=y
CONFIG_NET_CONTEXT_SNDTIMEO=y

CONFIG_ETH_NATIVE_POSIX=y
CONFIG_ETH_NATIVE_POSIX_RANDOM_MAC=y

# Network driver config
CONFIG_TEST_RANDOM_GENERATOR=y

# TLS configuration
CONFIG_MBEDTLS=y
CONFIG_MBEDTLS_BUILTIN=y
CONFIG_MBEDTLS_ENABLE_HEAP=y
CONFIG_MBEDTLS_HEAP_SIZE=40000
CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=7168
CONFIG_MBEDTLS_PEM_CERTIFICATE_FORMAT=y
CONFIG_MBEDTLS_KEY_EXCHANGE_RSA_ENABLED=y
CONFIG_MBEDTLS_MAC_SHA256_ENABLED=y

# DNS
CONFIG_DNS_RESOLVER=y
CONFIG_DNS_SERVER_IP_ADDRESSES=y
CONFIG_DNS_SERVER1="8.8.8.8"
CONFIG_DNS_RESOLVER_MAX_SERVERS=2

# Network address config
CONFIG_NET_CONFIG_SETTINGS=y
CONFIG_NET_CONFIG_NEED_IPV4=y
CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.1"
CONFIG_NET_CONFIG_MY_IPV4_GW="192.0.2.2"

# Azure IoT Hub library
CONFIG_MQTT_HELPER_SEC_TAG=201
CONFIG_MQTT_HELPER_SECONDARY_SEC_TAG=-1
2 changes: 1 addition & 1 deletion samples/net/azure_iot_hub/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ int main(void)
* This means that NET_EVENT_L4_CONNECTED fires before the
* appropriate handler l4_event_handler() is registered.
*/
if (IS_ENABLED(CONFIG_BOARD_QEMU_X86)) {
if (IS_ENABLED(CONFIG_BOARD_QEMU_X86) || IS_ENABLED(CONFIG_BOARD_NATIVE_SIM)) {
conn_mgr_mon_resend_status();
}

Expand Down
39 changes: 39 additions & 0 deletions samples/net/udp/boards/native_sim.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#
# Copyright (c) 2023 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

# Networking config
CONFIG_NET_TCP=y
CONFIG_NET_UDP=y
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_POSIX_NAMES=y
CONFIG_NET_SOCKETS_SOCKOPT_TLS=y
CONFIG_NET_PKT_RX_COUNT=32
CONFIG_NET_PKT_TX_COUNT=32
CONFIG_NET_BUF_RX_COUNT=32
CONFIG_NET_BUF_TX_COUNT=32
CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=3
CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=4
CONFIG_NET_MAX_CONTEXTS=10
CONFIG_NET_L2_ETHERNET=y
CONFIG_NET_CONTEXT_SNDTIMEO=y

CONFIG_ETH_NATIVE_POSIX=y
CONFIG_ETH_NATIVE_POSIX_RANDOM_MAC=y

# Network driver config
CONFIG_TEST_RANDOM_GENERATOR=y

# DNS
CONFIG_DNS_RESOLVER=y
CONFIG_DNS_SERVER_IP_ADDRESSES=y
CONFIG_DNS_SERVER1="8.8.8.8"
CONFIG_DNS_RESOLVER_MAX_SERVERS=2

# Network address config
CONFIG_NET_CONFIG_SETTINGS=y
CONFIG_NET_CONFIG_NEED_IPV4=y
CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.1"
CONFIG_NET_CONFIG_MY_IPV4_GW="192.0.2.2"
2 changes: 1 addition & 1 deletion samples/net/udp/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ int main(void)
* This means that NET_EVENT_L4_CONNECTED fires before the
* appropriate handler l4_event_handler() is registered.
*/
if (IS_ENABLED(CONFIG_BOARD_QEMU_X86)) {
if (IS_ENABLED(CONFIG_BOARD_QEMU_X86) || IS_ENABLED(CONFIG_BOARD_NATIVE_SIM)) {
conn_mgr_mon_resend_status();
}

Expand Down

0 comments on commit 882627d

Please sign in to comment.