Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ethernet : Added support in ethernet #10124

Closed
wants to merge 1 commit into from

Conversation

garfieldG
Copy link
Contributor

@garfieldG garfieldG commented Aug 2, 2018

-new network_manager module gives the ability to control Ethernet related (as ip,mac and etc...) through parameters

Additional context
-To use network_manager in rcS add the line "network_manager start" before mavlink

@garfieldG
Copy link
Contributor Author

Related to nuttx pull request

@dagar dagar self-requested a review August 2, 2018 14:37
@dagar
Copy link
Member

dagar commented Aug 2, 2018

A couple initial thoughts.

Running network manager as a task is a huge waste of memory

I don't have a better solution in mind at the moment, but spreading network configuration across parameters feels pretty awkward. Do you actually need it to be runtime configurable like this, or is it just a convenient way to make it persistent?

@garfieldG
Copy link
Contributor Author

garfieldG commented Aug 2, 2018

@dagar network manager does run as a task, but after setting all the Ethernet related it exits immediately.
It is a convenient way, not a must, you can always set it in defconfig, but it does make it simpler when you have more than one drone in one subnet (no network manager - you'll need to change each drone it's mac and IP in the defconfig, compile it differently for each drone and use untagged version)

Copy link
Member

@davids5 davids5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@garfieldG This is cool! Thank you.

@@ -0,0 +1,241 @@
/****************************************************************************
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this structured this way?

This seems like it should a new file in the common stm32 board code and called from init function based on #define values for IP and MAC. A wrapper systemcmd could be added and a init script call could be done from rcS or read from SD card file to set mac, ip etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davids5
Hi,

So some thoughts after reading your comment.

There is no need to add a file in order to use "#define" values , the define values are already used, the network manager only uses the parameters values, if someone wants to use the "#define" values then there's no need in network manager or similar.
The "#define" values are set in defconfig:
-CONFIG_NSH_IPADDR
-CONFIG_NSH_DRIPADDR
-CONFIG_NSH_NETMASK
-CONFIG_NSH_MACADDR

SD card can be changed or moved while parameters are per plane.
From my experience it is easy to use the Ethernet related values as parameters.
You can change it very easily, no need to take the SD off, change it and put it back.
If you're not sure what the IP is (or some other value) you can always look in a program like QGC, and again no need to read values from a file saved on the SD.
It's quick and easy to use (especially in case of more than one person using the same plane and more than one plane) and I do think that the values should be changed through parameters.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@garfieldG - Thank you for the perspective. I always am looking from a deeply embedded point of view at the cost of a feature set on resources. So it is good from me to have your perspective from a use-case perspective. Thank you for the changes for the defines.

@@ -2702,7 +2711,11 @@ MavlinkReceiver::receive_start(pthread_t *thread, Mavlink *parent)
param.sched_priority = SCHED_PRIORITY_MAX - 80;
(void)pthread_attr_setschedparam(&receiveloop_attr, &param);

#ifdef CONFIG_NET
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be better structured as

#if !defined(CONFIG_NET)
#  define NET_ADDED_STACK 0
#  else 
#  define NET_ADDED_STACK 1360
#endif

At the top of file or header
and use
pthread_attr_setstacksize(&receiveloop_attr, PX4_STACK_ADJUSTED(2840+NET_ADDED_STACK ));
here

@@ -2683,7 +2763,11 @@ Mavlink::start(int argc, char *argv[])
px4_task_spawn_cmd(buf,
SCHED_DEFAULT,
SCHED_PRIORITY_DEFAULT,
#ifdef CONFIG_NET
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as comment as below - in general where possible 1 ifdef to configure the deltas and then no ifdefs in the code is a cleaner approach.

@garfieldG
Copy link
Contributor Author

@davids5
Thanks for the response!
I'll look into it on sunday

@LorenzMeier
Copy link
Member

Parameters make total sense, yes.

break;

//multicast
#if defined(CONFIG_NET_IGMP) && defined(CONFIG_NET_ROUTE)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is NuttX specific but probably also works on Linux. So probably best to do under one define (as @davids5 suggested).

@@ -243,7 +249,7 @@ Mavlink::Mavlink() :
_rate_tx(0.0f),
_rate_txerr(0.0f),
_rate_rx(0.0f),
#ifdef __PX4_POSIX
#if defined(CONFIG_NET) || defined(__PX4_POSIX)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating a new define __PX4_NETWORK and setting that above for when NuttX networking is enabled or POSIX is available is cleaner.


ret = sendto(_socket_fd, _network_buf, _network_buf_len, 0,
(struct sockaddr *)&_src_addr, sizeof(_src_addr));
#ifdef CONFIG_NET
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this also true for POSIX? The source address has to be initialized.

@LorenzMeier
Copy link
Member

@dagar Would you want to help this to get to completion so you can leverage this as well on your F7 unit?

@garfieldG
Copy link
Contributor Author

@davids5
Added defines as requested

@garfieldG
Copy link
Contributor Author

@LorenzMeier Thanks! Actually not sure where should I create the new define. Maybe whenever __PX4_POSIX is defined then define CONFIG_NET?

Copy link
Member

@bkueng bkueng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work @garfieldG ! I'm interested to know the general resource usage of the NuttX networking stack. On what board are you testing this?
What is the CPU load?
By how much does RAM usage increase?


void NetworkManager::task_main()
{
_param_sub = orb_subscribe(ORB_ID(parameter_update));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, the initial thought was to enable IP changes after startup, but it was canceled afterwards due to problems we encountered


int NetworkManager::start(int argc, char *argv[])
{
_taskmap_id = px4_task_spawn_cmd("network_manager", SCHED_DEFAULT, SCHED_PRIORITY_DEFAULT, 1200,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed, as the task exits right after configuration. Can you directly execute the config inside the main task? Or is it something that takes a long time?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's needed.
It's here 'cause NetworkManager was supposed to be a running task that can handle changes with parameters, but it was changed later on.

* @min 0
* @max 255
*/
PARAM_DEFINE_INT32(ETH_IP_ADDR_0, 192);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please use a single parameter for the IP and the Gateway? Both are 4 bytes each and fit into a single parameter.
We should then make sure QGC learns how to display IP addresses (@DonLakeFlyer @dogmaphobic ) and add the metadata.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was structured like this because of the GUI and the fact that one parameter can be a very long number and it seemed like less comfortable solution. Do you think it's better to use a single parameter? It was a real conflict.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the fact that one parameter can be a very long number and it seemed like less comfortable solution.

Yes exactly. That's why we should to extend QGC so that it shows the IP in the form 192.168.1.1.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, there's a problem doing so...
Let's say we wan't to change the IP parameter value to 192.168.0.1 with the param set command.
The actual value that will be stored is 127.255.255.255 (LONG_MAX), I suspect the problem is with the do_set function that uses strtol.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! So we would need to fix the parameters. But that would cause more bloat to go to 64 bits (unless the union already is that big - IDNR)

I think this further reinforces @dagar
#10124 (comment) and also suggest the parameters need some design effort for isolation (things stores but not user facing) and scalability.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should then make sure QGC learns how to display IP addresses (@DonLakeFlyer @dogmaphobic ) and add the metadata.

That would require a parameter type of IP address to be added to mavlink and then flow through to QGC changes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not mac using 2 parameters?

We can do that too but it's more than 4 bytes. A 64 bit param type would be helpful.

For the param set we can easily extend it to accept the form x.y.z.w.


@DonLakeFlyer

That would require a parameter type of IP address to be added to mavlink and then flow through to QGC changes.

Why mavlink? We can do it through the unit in the param xml metadata. It would still be an INT32 as underlying type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! So we would need to fix the parameters. But that would cause more bloat to go to 64 bits

Why not just using uint32? why 64?

For the param set we can easily extend it to accept the form x.y.z.w.

I think this is my preferred idea, much more user friendly

We can do that too but it's more than 4 bytes. A 64 bit param type would be helpful.

Yes, it would be. But if for some reason we don't want a 64 bit param we can use 2 32 bit param for mac, do you think it's a good idea? or is it just another thing that will complicate the user experience?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if for some reason we don't want a 64 bit param we can use 2 32 bit param for mac, do you think it's a good idea? or is it just another thing that will complicate the user experience?

I think that would complicate the user experience too much.

@dagar
Copy link
Member

dagar commented Aug 6, 2018

I don't think parameters really make sense for this kind of configuration, but it's our only option at the moment. We need something like a mavlink message to configure the network interface atomically with a different storage backend internally. Something for another day...

I'll test this on the F7 board I have with ethernet.

@garfieldG
Copy link
Contributor Author

@bkueng I tested it on a costume board.
I can't tell you how much the RAM will increase, but it will increase.
It could be an issue with f4 and I do recommend to eliminate unnecessary.
In f7 it should be OK.

@davids5
Copy link
Member

davids5 commented Aug 7, 2018

Seeing that the CONFIGxxx come from the defconfig and nuttx has to be built with the config, We have 2 options. 1) maintain and carry a separate board config target with _ehternet or 2) have a process to concatenates the net config with all that is needed by NuttX for a given release I think it is worth pointing out that the current nuttx release has had many Networking related changes since the fork point. The process to update to current nuttx has to be scheduled and supported. But first we need the ability to QA the upgrade on all platforms.

@dagar
Copy link
Member

dagar commented Aug 8, 2018

As discussed on the dev call I propose splitting off the mavlink changes into a separate PR we can test, review, merge ASAP and the network_manager discussion can continue here.

@garfieldG
Copy link
Contributor Author

@dagar Added a new PR with Mavlink changes

@garfieldG
Copy link
Contributor Author

@davids5 @dagar @bkueng
Did we get to any decision regarding the network manager?
Do you want me to change the IP and the gateway to two one parameter each? What are we doing regarding the parameters? Are we adding support in x.y.z.w format or will we use it as is and use the 2's complement calc?

-new network_manager module gives the ability to control ethernet related (as ip,mac and etc...) through parameters
@stale stale bot closed this Jul 8, 2019
@julianoes
Copy link
Contributor

@davids5 what's the status here?

@julianoes julianoes reopened this Jul 9, 2019
@stale stale bot removed the Admin: Wont fix label Jul 9, 2019
@davids5
Copy link
Member

davids5 commented Jul 9, 2019

@julianoes IIRC @dagar had an issue with the use of param for the IP address, but no other solutions was developed.

@julianoes
Copy link
Contributor

When I read it I see that @garfieldG 's questions never got answered.

@PX4 PX4 deleted a comment from stale bot Jul 11, 2019
@PX4 PX4 deleted a comment from stale bot Jul 11, 2019
@PX4 PX4 deleted a comment from stale bot Jul 11, 2019
@stale
Copy link

stale bot commented Oct 9, 2019

This issue has been automatically marked as stale because it has not had recent activity. Thank you for your contributions.

@dagar
Copy link
Member

dagar commented Oct 15, 2019

FYI @dinomani

@stale
Copy link

stale bot commented Jan 14, 2020

This issue has been automatically marked as stale because it has not had recent activity. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants