You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2021/10/21 14:50:05 UTC

[GitHub] [incubator-nuttx] anchao opened a new pull request #4716: arch/sim: add native socket support based on usrsock

anchao opened a new pull request #4716:
URL: https://github.com/apache/incubator-nuttx/pull/4716


   ## Summary
   
   arch/sim: add native socket support based on usrsock 
   
   The network simulation of nuttx is difficult to implement on some platforms, in order to make it easier for application developers, add a feature to bypasses the nuttx IP stack to directly access the network resources from host os.
   
   Signed-off-by: chao.an <an...@xiaomi.com>
   
   ## Impact
   
   N/A, new feature
   
   ## Testing
   
   iperf test


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] gustavonihei commented on a change in pull request #4716: arch/sim: add native socket support based on usrsock

Posted by GitBox <gi...@apache.org>.
gustavonihei commented on a change in pull request #4716:
URL: https://github.com/apache/incubator-nuttx/pull/4716#discussion_r735807590



##########
File path: arch/sim/Kconfig
##########
@@ -127,15 +127,32 @@ config SIM_WALLTIME_SIGNAL
 
 endchoice
 
+choice
+	prompt "Simulated Network Interface"
+	default SIM_NETNULL if !NET_ETHERNET
+	default SIM_NETDEV if NET_ETHERNET
+
+config SIM_NETNULL
+	bool "Simulated Network NULL Device"
+	---help---
+		Simulated Network NULL Device.
+
 config SIM_NETDEV
 	bool "Simulated Network Device"
-	default y
 	select ARCH_HAVE_NETDEV_STATISTICS
 	select SCHED_LPWORK
 	depends on NET_ETHERNET
 	---help---
 		Build in support for a simulated network device.
 
+config SIM_NETUSRSOCK
+	bool "Simulated Network Device with Native Stack via usrsock"
+	depends on NET_USRSOCK
+	---help---
+		Build-in support for a simulated network device using native stack via usrsock

Review comment:
       ```suggestion
   		Built-in support for a simulated network device using native stack via usrsock
   ```
   It is still not fully correct.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] gustavonihei commented on a change in pull request #4716: arch/sim: add native socket support based on usrsock

Posted by GitBox <gi...@apache.org>.
gustavonihei commented on a change in pull request #4716:
URL: https://github.com/apache/incubator-nuttx/pull/4716#discussion_r735951594



##########
File path: arch/sim/src/sim/up_usrsock.c
##########
@@ -0,0 +1,443 @@
+/****************************************************************************
+ * arch/sim/src/sim/up_usrsock.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <fcntl.h>
+#include <errno.h>
+#include <poll.h>
+#include <syslog.h>
+#include <string.h>
+
+#include <nuttx/fs/fs.h>
+#include <nuttx/net/usrsock.h>
+
+#include "up_usrsock_host.h"
+
+/****************************************************************************
+ * Private Type Declarations
+ ****************************************************************************/
+
+struct usrsock_s
+{
+  struct file usock;
+  uint8_t data[4096];
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+typedef int (*usrsock_handler_t)(FAR struct usrsock_s *usrsock,
+                                 FAR const void *data, size_t len);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static struct usrsock_s g_usrsock;
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static int usrsock_send(FAR struct usrsock_s *usrsock,
+                        FAR const void *buf, size_t len)
+{
+  FAR uint8_t *data = (FAR uint8_t *)buf;
+  ssize_t ret;
+
+  while (len > 0)
+    {
+      ret = file_write(&usrsock->usock, data, len);
+      if (ret < 0)
+        {
+          return ret;
+        }
+
+      data += ret;
+      len  -= ret;
+    }
+
+  return 0;
+}
+
+static int usrsock_send_ack(FAR struct usrsock_s *usrsock,
+                            uint8_t xid, int32_t result)
+{
+  struct usrsock_message_req_ack_s ack;
+
+  ack.head.msgid = USRSOCK_MESSAGE_RESPONSE_ACK;
+  ack.head.flags = (result == -EINPROGRESS);
+
+  ack.xid    = xid;
+  ack.result = result;
+
+  return usrsock_send(usrsock, &ack, sizeof(ack));
+}
+
+static int usrsock_send_dack(FAR struct usrsock_s *usrsock,
+                             struct usrsock_message_datareq_ack_s *ack,

Review comment:
       Use of the `FAR` qualifier is inconsistent throughout this source file. We should either add it to every pointer to data, or remove them altogether.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] anchao commented on a change in pull request #4716: arch/sim: add native socket support based on usrsock

Posted by GitBox <gi...@apache.org>.
anchao commented on a change in pull request #4716:
URL: https://github.com/apache/incubator-nuttx/pull/4716#discussion_r736390301



##########
File path: arch/sim/Kconfig
##########
@@ -127,15 +127,26 @@ config SIM_WALLTIME_SIGNAL
 
 endchoice
 
+choice
+	prompt "Simulated Network Interface"
+	default SIM_NETDEV if NET_ETHERNET
+

Review comment:
       Yes, add an empty choice is a good point if this is a new feature added,
   but in this configure use the optional option will cause the defconfig updated if the application samples select the SIM_NETDEV by default, seriously, I do not want the update every config one by one, I just want to keep the current defconfig.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] gustavonihei commented on a change in pull request #4716: arch/sim: add native socket support based on usrsock

Posted by GitBox <gi...@apache.org>.
gustavonihei commented on a change in pull request #4716:
URL: https://github.com/apache/incubator-nuttx/pull/4716#discussion_r736366967



##########
File path: arch/sim/Kconfig
##########
@@ -127,15 +127,26 @@ config SIM_WALLTIME_SIGNAL
 
 endchoice
 
+choice
+	prompt "Simulated Network Interface"
+	default SIM_NETDEV if NET_ETHERNET

Review comment:
       ```suggestion
   	default SIM_NETDEV
   ```
   This dependency is redundant.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] gustavonihei commented on a change in pull request #4716: arch/sim: add native socket support based on usrsock

Posted by GitBox <gi...@apache.org>.
gustavonihei commented on a change in pull request #4716:
URL: https://github.com/apache/incubator-nuttx/pull/4716#discussion_r733902683



##########
File path: arch/sim/Kconfig
##########
@@ -127,15 +127,32 @@ config SIM_WALLTIME_SIGNAL
 
 endchoice
 
+choice
+	prompt "Simulated Network Interface"
+	default SIM_NETNULL if !NET_ETHERNET
+	default SIM_NETDEV if NET_ETHERNET
+
+config SIM_NETNULL
+	bool "Simulated Network NULL Device"
+	---help---
+		Simulated Network NULL Device.
+
 config SIM_NETDEV
 	bool "Simulated Network Device"
-	default y
 	select ARCH_HAVE_NETDEV_STATISTICS
 	select SCHED_LPWORK
 	depends on NET_ETHERNET
 	---help---
 		Build in support for a simulated network device.
 
+config SIM_NETUSRSOCK
+	bool "Simulated Network Device with Native Stack via usrsock"
+	depends on NET_USRSOCK
+	---help---
+		Build in support for a simulated network device using native stack via usrsock

Review comment:
       ```suggestion
   		Built-in support for a simulated network device using native stack via usrsock
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] anchao commented on a change in pull request #4716: arch/sim: add native socket support based on usrsock

Posted by GitBox <gi...@apache.org>.
anchao commented on a change in pull request #4716:
URL: https://github.com/apache/incubator-nuttx/pull/4716#discussion_r736136893



##########
File path: arch/sim/src/sim/up_usrsock.c
##########
@@ -0,0 +1,443 @@
+/****************************************************************************
+ * arch/sim/src/sim/up_usrsock.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <fcntl.h>
+#include <errno.h>
+#include <poll.h>
+#include <syslog.h>
+#include <string.h>
+
+#include <nuttx/fs/fs.h>
+#include <nuttx/net/usrsock.h>
+
+#include "up_usrsock_host.h"
+
+/****************************************************************************
+ * Private Type Declarations
+ ****************************************************************************/
+
+struct usrsock_s
+{
+  struct file usock;
+  uint8_t data[4096];
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+typedef int (*usrsock_handler_t)(FAR struct usrsock_s *usrsock,
+                                 FAR const void *data, size_t len);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static struct usrsock_s g_usrsock;
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static int usrsock_send(FAR struct usrsock_s *usrsock,
+                        FAR const void *buf, size_t len)
+{
+  FAR uint8_t *data = (FAR uint8_t *)buf;
+  ssize_t ret;
+
+  while (len > 0)
+    {
+      ret = file_write(&usrsock->usock, data, len);
+      if (ret < 0)
+        {
+          return ret;
+        }
+
+      data += ret;
+      len  -= ret;
+    }
+
+  return 0;
+}
+
+static int usrsock_send_ack(FAR struct usrsock_s *usrsock,
+                            uint8_t xid, int32_t result)
+{
+  struct usrsock_message_req_ack_s ack;
+
+  ack.head.msgid = USRSOCK_MESSAGE_RESPONSE_ACK;
+  ack.head.flags = (result == -EINPROGRESS);
+
+  ack.xid    = xid;
+  ack.result = result;
+
+  return usrsock_send(usrsock, &ack, sizeof(ack));
+}
+
+static int usrsock_send_dack(FAR struct usrsock_s *usrsock,
+                             struct usrsock_message_datareq_ack_s *ack,

Review comment:
       Done

##########
File path: arch/sim/Kconfig
##########
@@ -127,15 +127,32 @@ config SIM_WALLTIME_SIGNAL
 
 endchoice
 
+choice
+	prompt "Simulated Network Interface"
+	default SIM_NETNULL if !NET_ETHERNET
+	default SIM_NETDEV if NET_ETHERNET
+
+config SIM_NETNULL
+	bool "Simulated Network NULL Device"
+	---help---
+		Simulated Network NULL Device.
+
 config SIM_NETDEV
 	bool "Simulated Network Device"
-	default y
 	select ARCH_HAVE_NETDEV_STATISTICS
 	select SCHED_LPWORK
 	depends on NET_ETHERNET
 	---help---
 		Build in support for a simulated network device.
 
+config SIM_NETUSRSOCK
+	bool "Simulated Network Device with Native Stack via usrsock"
+	depends on NET_USRSOCK
+	---help---
+		Build-in support for a simulated network device using native stack via usrsock

Review comment:
       Done




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] gustavonihei commented on a change in pull request #4716: arch/sim: add native socket support based on usrsock

Posted by GitBox <gi...@apache.org>.
gustavonihei commented on a change in pull request #4716:
URL: https://github.com/apache/incubator-nuttx/pull/4716#discussion_r735986323



##########
File path: arch/sim/Kconfig
##########
@@ -127,15 +127,32 @@ config SIM_WALLTIME_SIGNAL
 
 endchoice
 
+choice
+	prompt "Simulated Network Interface"
+	default SIM_NETNULL if !NET_ETHERNET
+	default SIM_NETDEV if NET_ETHERNET
+
+config SIM_NETNULL
+	bool "Simulated Network NULL Device"
+	---help---
+		Simulated Network NULL Device.

Review comment:
       `SIM_NETNULL` is not referenced anywhere. If I read correctly, this seems to be just a dummy config for a non-existing device.
   
   Instead, we could add `optional` keyword to this choice, which makes it disabled by default.
   https://github.com/apache/incubator-nuttx/blob/master/boards/xtensa/esp32/common/Kconfig#L25




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] anchao commented on a change in pull request #4716: arch/sim: add native socket support based on usrsock

Posted by GitBox <gi...@apache.org>.
anchao commented on a change in pull request #4716:
URL: https://github.com/apache/incubator-nuttx/pull/4716#discussion_r735227484



##########
File path: arch/sim/Kconfig
##########
@@ -127,15 +127,32 @@ config SIM_WALLTIME_SIGNAL
 
 endchoice
 
+choice
+	prompt "Simulated Network Interface"
+	default SIM_NETNULL if !NET_ETHERNET
+	default SIM_NETDEV if NET_ETHERNET
+
+config SIM_NETNULL
+	bool "Simulated Network NULL Device"
+	---help---
+		Simulated Network NULL Device.
+
 config SIM_NETDEV
 	bool "Simulated Network Device"
-	default y
 	select ARCH_HAVE_NETDEV_STATISTICS
 	select SCHED_LPWORK
 	depends on NET_ETHERNET
 	---help---
 		Build in support for a simulated network device.
 
+config SIM_NETUSRSOCK
+	bool "Simulated Network Device with Native Stack via usrsock"
+	depends on NET_USRSOCK
+	---help---
+		Build in support for a simulated network device using native stack via usrsock

Review comment:
       Done




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] gustavonihei commented on a change in pull request #4716: arch/sim: add native socket support based on usrsock

Posted by GitBox <gi...@apache.org>.
gustavonihei commented on a change in pull request #4716:
URL: https://github.com/apache/incubator-nuttx/pull/4716#discussion_r736366580



##########
File path: arch/sim/Kconfig
##########
@@ -127,15 +127,26 @@ config SIM_WALLTIME_SIGNAL
 
 endchoice
 
+choice
+	prompt "Simulated Network Interface"
+	default SIM_NETDEV if NET_ETHERNET
+

Review comment:
       Something I wanted to prevent by suggesting the use of `optional` is having this empty choice where the user has basically no action:
   ![image](https://user-images.githubusercontent.com/38959758/138855723-3110ab49-f201-47d8-8632-83d8d2e7a360.png)
   
   How about applying the following changes?
   1) Add `depends on NET` to the root `choice`.
   2) Add `optional` to the `choice`, so that even if there is Networking support, the user may still not select it (no network interface simulation).
   3) Transform `NET_ETHERNET` and `NET_USRSOCK` reverse dependencies of `SIM_NETDEV` and `SIM_NETUSRSOCK`, respectively. This will prevent the `choice` with zero options.
   
   In the end, it would be like this:
   ```kconfig
   choice SIM_NETINF
   	prompt "Simulated Network Interface"
   	default SIM_NETDEV
   	depends on NET
   	optional
   
   config SIM_NETDEV
   	bool "Simulated Network Device"
   	select ARCH_HAVE_NETDEV_STATISTICS
   	select SCHED_LPWORK
   	select NET_ETHERNET
   	---help---
   		Built-in support for a simulated network device.
   
   config SIM_NETUSRSOCK
   	bool "Simulated Network Device with Native Stack via usrsock"
   	select NET_USRSOCK
   	---help---
   		Built-in support for a simulated network device using native stack via usrsock
   
   endchoice
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] gustavonihei commented on a change in pull request #4716: arch/sim: add native socket support based on usrsock

Posted by GitBox <gi...@apache.org>.
gustavonihei commented on a change in pull request #4716:
URL: https://github.com/apache/incubator-nuttx/pull/4716#discussion_r736413303



##########
File path: arch/sim/Kconfig
##########
@@ -127,15 +127,26 @@ config SIM_WALLTIME_SIGNAL
 
 endchoice
 
+choice
+	prompt "Simulated Network Interface"
+	default SIM_NETDEV if NET_ETHERNET
+

Review comment:
       Well, it seems you agree that the proposed change is good.
   If what's holding is the update of `sim` defconfigs, let's work this out.
   Adding `optional` keyword just imposes a `CONFIG_SIM_NETDEV=y` in some defconfigs where there is Network support.
   In this case, I simply forced it on those defconfigs and used `tools/refresh.sh` on the entire `boards/sim/sim/sim/configs/*` directory.
   Here is a patch for it:
   
   ```patch
   diff --git a/boards/sim/sim/sim/configs/libcxxtest/defconfig b/boards/sim/sim/sim/configs/libcxxtest/defconfig
   index 86a397f45f..b5954e7a7a 100644
   --- a/boards/sim/sim/sim/configs/libcxxtest/defconfig
   +++ b/boards/sim/sim/sim/configs/libcxxtest/defconfig
   @@ -86,6 +86,7 @@ CONFIG_SCHED_HAVE_PARENT=y
    CONFIG_SCHED_ONEXIT=y
    CONFIG_SCHED_WAITPID=y
    CONFIG_SDCLONE_DISABLE=y
   +CONFIG_SIM_NETDEV=y
    CONFIG_START_MONTH=6
    CONFIG_START_YEAR=2008
    CONFIG_STDIO_DISABLE_BUFFERING=y
   diff --git a/boards/sim/sim/sim/configs/module/defconfig b/boards/sim/sim/sim/configs/module/defconfig
   index d1b44066ee..468ded86a8 100644
   --- a/boards/sim/sim/sim/configs/module/defconfig
   +++ b/boards/sim/sim/sim/configs/module/defconfig
   @@ -69,6 +69,7 @@ CONFIG_SCHED_ONEXIT=y
    CONFIG_SCHED_WAITPID=y
    CONFIG_SDCLONE_DISABLE=y
    CONFIG_SIG_DEFAULT=y
   +CONFIG_SIM_NETDEV=y
    CONFIG_START_MONTH=6
    CONFIG_START_YEAR=2008
    CONFIG_STDIO_DISABLE_BUFFERING=y
   diff --git a/boards/sim/sim/sim/configs/module32/defconfig b/boards/sim/sim/sim/configs/module32/defconfig
   index 5e6d376f83..514e19a23f 100644
   --- a/boards/sim/sim/sim/configs/module32/defconfig
   +++ b/boards/sim/sim/sim/configs/module32/defconfig
   @@ -69,6 +69,7 @@ CONFIG_SCHED_WAITPID=y
    CONFIG_SDCLONE_DISABLE=y
    CONFIG_SIG_DEFAULT=y
    CONFIG_SIM_M32=y
   +CONFIG_SIM_NETDEV=y
    CONFIG_START_MONTH=6
    CONFIG_START_YEAR=2008
    CONFIG_STDIO_DISABLE_BUFFERING=y
   diff --git a/boards/sim/sim/sim/configs/rpserver/defconfig b/boards/sim/sim/sim/configs/rpserver/defconfig
   index 311e40c986..bf6c33e43a 100644
   --- a/boards/sim/sim/sim/configs/rpserver/defconfig
   +++ b/boards/sim/sim/sim/configs/rpserver/defconfig
   @@ -63,6 +63,7 @@ CONFIG_SCHED_HPWORK=y
    CONFIG_SCHED_WAITPID=y
    CONFIG_SIG_DEFAULT=y
    CONFIG_SIM_M32=y
   +CONFIG_SIM_NETDEV=y
    CONFIG_SIM_NET_BRIDGE=y
    CONFIG_SIM_RPTUN_MASTER=y
    CONFIG_SYSLOG_PREFIX=y
   diff --git a/boards/sim/sim/sim/configs/sotest/defconfig b/boards/sim/sim/sim/configs/sotest/defconfig
   index 938e129702..4c8d8ed7e3 100644
   --- a/boards/sim/sim/sim/configs/sotest/defconfig
   +++ b/boards/sim/sim/sim/configs/sotest/defconfig
   @@ -68,6 +68,7 @@ CONFIG_SCHED_ONEXIT=y
    CONFIG_SCHED_WAITPID=y
    CONFIG_SDCLONE_DISABLE=y
    CONFIG_SIG_DEFAULT=y
   +CONFIG_SIM_NETDEV=y
    CONFIG_START_MONTH=6
    CONFIG_START_YEAR=2008
    CONFIG_STDIO_DISABLE_BUFFERING=y
   diff --git a/boards/sim/sim/sim/configs/sotest32/defconfig b/boards/sim/sim/sim/configs/sotest32/defconfig
   index df436747e0..607ccc3f5a 100644
   --- a/boards/sim/sim/sim/configs/sotest32/defconfig
   +++ b/boards/sim/sim/sim/configs/sotest32/defconfig
   @@ -69,6 +69,7 @@ CONFIG_SCHED_WAITPID=y
    CONFIG_SDCLONE_DISABLE=y
    CONFIG_SIG_DEFAULT=y
    CONFIG_SIM_M32=y
   +CONFIG_SIM_NETDEV=y
    CONFIG_START_MONTH=6
    CONFIG_START_YEAR=2008
    CONFIG_STDIO_DISABLE_BUFFERING=y
   diff --git a/boards/sim/sim/sim/configs/vpnkit/defconfig b/boards/sim/sim/sim/configs/vpnkit/defconfig
   index 3f45b1cdaf..d82b8abfe8 100644
   --- a/boards/sim/sim/sim/configs/vpnkit/defconfig
   +++ b/boards/sim/sim/sim/configs/vpnkit/defconfig
   @@ -81,6 +81,7 @@ CONFIG_SCHED_HAVE_PARENT=y
    CONFIG_SCHED_ONEXIT=y
    CONFIG_SCHED_WAITPID=y
    CONFIG_SDCLONE_DISABLE=y
   +CONFIG_SIM_NETDEV=y
    CONFIG_SIM_NETDEV_VPNKIT=y
    CONFIG_START_MONTH=6
    CONFIG_START_YEAR=2008
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] gustavonihei commented on a change in pull request #4716: arch/sim: add native socket support based on usrsock

Posted by GitBox <gi...@apache.org>.
gustavonihei commented on a change in pull request #4716:
URL: https://github.com/apache/incubator-nuttx/pull/4716#discussion_r736413303



##########
File path: arch/sim/Kconfig
##########
@@ -127,15 +127,26 @@ config SIM_WALLTIME_SIGNAL
 
 endchoice
 
+choice
+	prompt "Simulated Network Interface"
+	default SIM_NETDEV if NET_ETHERNET
+

Review comment:
       Well, it seems you agree that the proposed change is good.
   If what's holding is the update of `sim` defconfigs, let's work this out.
   Adding `optional` keyword just imposes a `CONFIG_SIM_NETDEV=y` in some defconfigs where there is Network support.
   In this case, I simply forced it on those defconfigs and used `tools/refresh.sh` on the entire directory.
   Here is a patch for it:
   
   ```patch
   diff --git a/boards/sim/sim/sim/configs/libcxxtest/defconfig b/boards/sim/sim/sim/configs/libcxxtest/defconfig
   index 86a397f45f..b5954e7a7a 100644
   --- a/boards/sim/sim/sim/configs/libcxxtest/defconfig
   +++ b/boards/sim/sim/sim/configs/libcxxtest/defconfig
   @@ -86,6 +86,7 @@ CONFIG_SCHED_HAVE_PARENT=y
    CONFIG_SCHED_ONEXIT=y
    CONFIG_SCHED_WAITPID=y
    CONFIG_SDCLONE_DISABLE=y
   +CONFIG_SIM_NETDEV=y
    CONFIG_START_MONTH=6
    CONFIG_START_YEAR=2008
    CONFIG_STDIO_DISABLE_BUFFERING=y
   diff --git a/boards/sim/sim/sim/configs/module/defconfig b/boards/sim/sim/sim/configs/module/defconfig
   index d1b44066ee..468ded86a8 100644
   --- a/boards/sim/sim/sim/configs/module/defconfig
   +++ b/boards/sim/sim/sim/configs/module/defconfig
   @@ -69,6 +69,7 @@ CONFIG_SCHED_ONEXIT=y
    CONFIG_SCHED_WAITPID=y
    CONFIG_SDCLONE_DISABLE=y
    CONFIG_SIG_DEFAULT=y
   +CONFIG_SIM_NETDEV=y
    CONFIG_START_MONTH=6
    CONFIG_START_YEAR=2008
    CONFIG_STDIO_DISABLE_BUFFERING=y
   diff --git a/boards/sim/sim/sim/configs/module32/defconfig b/boards/sim/sim/sim/configs/module32/defconfig
   index 5e6d376f83..514e19a23f 100644
   --- a/boards/sim/sim/sim/configs/module32/defconfig
   +++ b/boards/sim/sim/sim/configs/module32/defconfig
   @@ -69,6 +69,7 @@ CONFIG_SCHED_WAITPID=y
    CONFIG_SDCLONE_DISABLE=y
    CONFIG_SIG_DEFAULT=y
    CONFIG_SIM_M32=y
   +CONFIG_SIM_NETDEV=y
    CONFIG_START_MONTH=6
    CONFIG_START_YEAR=2008
    CONFIG_STDIO_DISABLE_BUFFERING=y
   diff --git a/boards/sim/sim/sim/configs/rpserver/defconfig b/boards/sim/sim/sim/configs/rpserver/defconfig
   index 311e40c986..bf6c33e43a 100644
   --- a/boards/sim/sim/sim/configs/rpserver/defconfig
   +++ b/boards/sim/sim/sim/configs/rpserver/defconfig
   @@ -63,6 +63,7 @@ CONFIG_SCHED_HPWORK=y
    CONFIG_SCHED_WAITPID=y
    CONFIG_SIG_DEFAULT=y
    CONFIG_SIM_M32=y
   +CONFIG_SIM_NETDEV=y
    CONFIG_SIM_NET_BRIDGE=y
    CONFIG_SIM_RPTUN_MASTER=y
    CONFIG_SYSLOG_PREFIX=y
   diff --git a/boards/sim/sim/sim/configs/sotest/defconfig b/boards/sim/sim/sim/configs/sotest/defconfig
   index 938e129702..4c8d8ed7e3 100644
   --- a/boards/sim/sim/sim/configs/sotest/defconfig
   +++ b/boards/sim/sim/sim/configs/sotest/defconfig
   @@ -68,6 +68,7 @@ CONFIG_SCHED_ONEXIT=y
    CONFIG_SCHED_WAITPID=y
    CONFIG_SDCLONE_DISABLE=y
    CONFIG_SIG_DEFAULT=y
   +CONFIG_SIM_NETDEV=y
    CONFIG_START_MONTH=6
    CONFIG_START_YEAR=2008
    CONFIG_STDIO_DISABLE_BUFFERING=y
   diff --git a/boards/sim/sim/sim/configs/sotest32/defconfig b/boards/sim/sim/sim/configs/sotest32/defconfig
   index df436747e0..607ccc3f5a 100644
   --- a/boards/sim/sim/sim/configs/sotest32/defconfig
   +++ b/boards/sim/sim/sim/configs/sotest32/defconfig
   @@ -69,6 +69,7 @@ CONFIG_SCHED_WAITPID=y
    CONFIG_SDCLONE_DISABLE=y
    CONFIG_SIG_DEFAULT=y
    CONFIG_SIM_M32=y
   +CONFIG_SIM_NETDEV=y
    CONFIG_START_MONTH=6
    CONFIG_START_YEAR=2008
    CONFIG_STDIO_DISABLE_BUFFERING=y
   diff --git a/boards/sim/sim/sim/configs/vpnkit/defconfig b/boards/sim/sim/sim/configs/vpnkit/defconfig
   index 3f45b1cdaf..d82b8abfe8 100644
   --- a/boards/sim/sim/sim/configs/vpnkit/defconfig
   +++ b/boards/sim/sim/sim/configs/vpnkit/defconfig
   @@ -81,6 +81,7 @@ CONFIG_SCHED_HAVE_PARENT=y
    CONFIG_SCHED_ONEXIT=y
    CONFIG_SCHED_WAITPID=y
    CONFIG_SDCLONE_DISABLE=y
   +CONFIG_SIM_NETDEV=y
    CONFIG_SIM_NETDEV_VPNKIT=y
    CONFIG_START_MONTH=6
    CONFIG_START_YEAR=2008
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] xiaoxiang781216 merged pull request #4716: arch/sim: add native socket support based on usrsock

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 merged pull request #4716:
URL: https://github.com/apache/incubator-nuttx/pull/4716


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] anchao commented on a change in pull request #4716: arch/sim: add native socket support based on usrsock

Posted by GitBox <gi...@apache.org>.
anchao commented on a change in pull request #4716:
URL: https://github.com/apache/incubator-nuttx/pull/4716#discussion_r736390159



##########
File path: arch/sim/Kconfig
##########
@@ -127,15 +127,26 @@ config SIM_WALLTIME_SIGNAL
 
 endchoice
 
+choice
+	prompt "Simulated Network Interface"
+	default SIM_NETDEV if NET_ETHERNET
+
 config SIM_NETDEV
 	bool "Simulated Network Device"
-	default y
 	select ARCH_HAVE_NETDEV_STATISTICS
 	select SCHED_LPWORK
 	depends on NET_ETHERNET
 	---help---
 		Build in support for a simulated network device.

Review comment:
       let us fix this typo in other PR




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] gustavonihei commented on a change in pull request #4716: arch/sim: add native socket support based on usrsock

Posted by GitBox <gi...@apache.org>.
gustavonihei commented on a change in pull request #4716:
URL: https://github.com/apache/incubator-nuttx/pull/4716#discussion_r736359827



##########
File path: arch/sim/Kconfig
##########
@@ -127,15 +127,26 @@ config SIM_WALLTIME_SIGNAL
 
 endchoice
 
+choice
+	prompt "Simulated Network Interface"
+	default SIM_NETDEV if NET_ETHERNET
+
 config SIM_NETDEV
 	bool "Simulated Network Device"
-	default y
 	select ARCH_HAVE_NETDEV_STATISTICS
 	select SCHED_LPWORK
 	depends on NET_ETHERNET
 	---help---
 		Build in support for a simulated network device.

Review comment:
       ```suggestion
   		Built-in support for a simulated network device.
   ```
   Sorry, forgot to point this before, but it is the same issue as the one I pointed before.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] gustavonihei commented on a change in pull request #4716: arch/sim: add native socket support based on usrsock

Posted by GitBox <gi...@apache.org>.
gustavonihei commented on a change in pull request #4716:
URL: https://github.com/apache/incubator-nuttx/pull/4716#discussion_r735951594



##########
File path: arch/sim/src/sim/up_usrsock.c
##########
@@ -0,0 +1,443 @@
+/****************************************************************************
+ * arch/sim/src/sim/up_usrsock.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <fcntl.h>
+#include <errno.h>
+#include <poll.h>
+#include <syslog.h>
+#include <string.h>
+
+#include <nuttx/fs/fs.h>
+#include <nuttx/net/usrsock.h>
+
+#include "up_usrsock_host.h"
+
+/****************************************************************************
+ * Private Type Declarations
+ ****************************************************************************/
+
+struct usrsock_s
+{
+  struct file usock;
+  uint8_t data[4096];
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+typedef int (*usrsock_handler_t)(FAR struct usrsock_s *usrsock,
+                                 FAR const void *data, size_t len);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static struct usrsock_s g_usrsock;
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static int usrsock_send(FAR struct usrsock_s *usrsock,
+                        FAR const void *buf, size_t len)
+{
+  FAR uint8_t *data = (FAR uint8_t *)buf;
+  ssize_t ret;
+
+  while (len > 0)
+    {
+      ret = file_write(&usrsock->usock, data, len);
+      if (ret < 0)
+        {
+          return ret;
+        }
+
+      data += ret;
+      len  -= ret;
+    }
+
+  return 0;
+}
+
+static int usrsock_send_ack(FAR struct usrsock_s *usrsock,
+                            uint8_t xid, int32_t result)
+{
+  struct usrsock_message_req_ack_s ack;
+
+  ack.head.msgid = USRSOCK_MESSAGE_RESPONSE_ACK;
+  ack.head.flags = (result == -EINPROGRESS);
+
+  ack.xid    = xid;
+  ack.result = result;
+
+  return usrsock_send(usrsock, &ack, sizeof(ack));
+}
+
+static int usrsock_send_dack(FAR struct usrsock_s *usrsock,
+                             struct usrsock_message_datareq_ack_s *ack,

Review comment:
       Use of the `FAR` qualifier is inconsistent throughout this source file.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] gustavonihei commented on a change in pull request #4716: arch/sim: add native socket support based on usrsock

Posted by GitBox <gi...@apache.org>.
gustavonihei commented on a change in pull request #4716:
URL: https://github.com/apache/incubator-nuttx/pull/4716#discussion_r735986323



##########
File path: arch/sim/Kconfig
##########
@@ -127,15 +127,32 @@ config SIM_WALLTIME_SIGNAL
 
 endchoice
 
+choice
+	prompt "Simulated Network Interface"
+	default SIM_NETNULL if !NET_ETHERNET
+	default SIM_NETDEV if NET_ETHERNET
+
+config SIM_NETNULL
+	bool "Simulated Network NULL Device"
+	---help---
+		Simulated Network NULL Device.

Review comment:
       `SIM_NETNULL` is not referenced anywhere. If I read correctly, this seems to be just a dummy config for a non-existing device.
   
   Instead, we could add `optional` keyword to this choice, which makes it disabled by default.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] gustavonihei commented on a change in pull request #4716: arch/sim: add native socket support based on usrsock

Posted by GitBox <gi...@apache.org>.
gustavonihei commented on a change in pull request #4716:
URL: https://github.com/apache/incubator-nuttx/pull/4716#discussion_r735986323



##########
File path: arch/sim/Kconfig
##########
@@ -127,15 +127,32 @@ config SIM_WALLTIME_SIGNAL
 
 endchoice
 
+choice
+	prompt "Simulated Network Interface"
+	default SIM_NETNULL if !NET_ETHERNET
+	default SIM_NETDEV if NET_ETHERNET
+
+config SIM_NETNULL
+	bool "Simulated Network NULL Device"
+	---help---
+		Simulated Network NULL Device.

Review comment:
       `SIM_NETNULL` is not referenced anywhere. If I read correctly, this seems to be just a dummy config for a non-existing device.
   
   Instead, we could add `optional` keyword to this choice, which makes it disabled by default.
   See the [kconfig documentation](https://www.kernel.org/doc/Documentation/kbuild/kconfig-language.txt#:~:text=A%20choice%20accepts%20another%20option%20%22optional%22%2C%20which%20allows%20to%20set%20the%0Achoice%20to%20%27n%27%20and%20no%20entry%20needs%20to%20be%20selected.).
   https://github.com/apache/incubator-nuttx/blob/master/boards/xtensa/esp32/common/Kconfig#L25




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] gustavonihei commented on a change in pull request #4716: arch/sim: add native socket support based on usrsock

Posted by GitBox <gi...@apache.org>.
gustavonihei commented on a change in pull request #4716:
URL: https://github.com/apache/incubator-nuttx/pull/4716#discussion_r736359827



##########
File path: arch/sim/Kconfig
##########
@@ -127,15 +127,26 @@ config SIM_WALLTIME_SIGNAL
 
 endchoice
 
+choice
+	prompt "Simulated Network Interface"
+	default SIM_NETDEV if NET_ETHERNET
+
 config SIM_NETDEV
 	bool "Simulated Network Device"
-	default y
 	select ARCH_HAVE_NETDEV_STATISTICS
 	select SCHED_LPWORK
 	depends on NET_ETHERNET
 	---help---
 		Build in support for a simulated network device.

Review comment:
       ```suggestion
   		Built-in support for a simulated network device.
   ```
   Sorry, forgot to point this before, but it is the same issue as the one below.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org