-
Notifications
You must be signed in to change notification settings - Fork 198
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
Multiport linux support #303
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work!
I think we need to enable filtering of incoming packets dependent on Ethertype already in the Linux kernel, otherwise it will be lots of work for the application. See os_eth_init()
in https://github.com/rtlabs-com/p-net/blob/6670292041fd85c028ed1d40c22d5b1ced2fd882/src/osal/linux/osal_eth.c
207a56b
to
d904487
Compare
Rebased on latest master |
d904487
to
548fd5e
Compare
Rebased |
548fd5e
to
c9e0ad4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!
Mostly trivial changes
c9e0ad4
to
6a56f03
Compare
6a56f03
to
29654d3
Compare
29654d3
to
a0ff3a9
Compare
Review comments fixed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed changes for Ethernet, LLDP and port handling. Didn't look at code for sample app and unit tests.
a0ff3a9
to
f1e70e3
Compare
Review comments fixed |
f1e70e3
to
60262b9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done!
60262b9
to
65f6a41
Compare
for test. */ | ||
char c; | ||
|
||
memset (p_if_list, 0, sizeof (*p_if_list)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be simpler to use strtok(_r)? here instead? Something along the lines of:
char * argv[16];
char * p;
char * saveptr;
/* Split line into argv using space as delimiter */
p = strtok_r (line, " ", &saveptr);
while (p != NULL && argc < NELEMENTS (argv) - 1)
{
argv[argc++] = p;
p = strtok_r (NULL, " ", &saveptr);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, possibly. My first idea was to use strtok, but then I needed to copy arg_str for strtok to be able to insert '\0' and I also need to copy the strings so I ended up with this implementation.
Do you prefer that I use a strtok-based implementation instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When possible we should use the standard libraries. Unfortunately strok is not reentrant and strok_r (which is reentrant) might not be portable (it's not available on windows for instance). So let's stick with this for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This network initialization / configuration from the application is messy. We will try to improvement according to #316. In this case this code may disappear.
test/mocks.cpp
Outdated
@@ -57,8 +58,9 @@ pnal_eth_handle_t * mock_pnal_eth_init ( | |||
{ | |||
pnal_eth_handle_t * handle; | |||
|
|||
handle = (pnal_eth_handle_t *)calloc (1, sizeof (pnal_eth_handle_t)); | |||
handle = (pnal_eth_handle_t *)calloc (1, 10 /*sizeof (pnal_eth_handle_t)*/); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this intended?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree this looks strange. See updated mock implementation.
test/mocks.cpp
Outdated
@@ -103,6 +105,11 @@ int mock_pnal_eth_send (pnal_eth_handle_t * handle, pnal_buf_t * p_buf) | |||
return p_buf->len; | |||
} | |||
|
|||
int mock_pnal_eth_recv (void * arg, pnal_buf_t * buf) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems backwards? The purpose of a mock-function is to decouple from external dependencies. This instead adds an external dependency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated the mock implementation.
Done
test/test_dcp.cpp
Outdated
@@ -101,10 +101,10 @@ TEST_F (DcpTest, DcpHelloTest) | |||
|
|||
p_buf = pnal_buf_alloc (PF_FRAME_BUFFER_SIZE); | |||
memcpy (p_buf->payload, get_name_req, sizeof (get_name_req)); | |||
ret = pf_eth_recv (net, p_buf); | |||
ret = mock_pnal_eth_recv (net, p_buf); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is being tested here? Looks like it is a test of the mock-function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated the the mock implementation to avoid this.
Done
3a8e838
to
f1de47b
Compare
Rebased branch on master |
@@ -59,6 +66,10 @@ pnal_eth_handle_t * mock_pnal_eth_init ( | |||
|
|||
handle = (pnal_eth_handle_t *)calloc (1, sizeof (pnal_eth_handle_t)); | |||
|
|||
handle->if_name = if_name; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of allocating a pnal_eth_handle_t object in this function, perhaps one could initialise mock_os_data.eth_if_handle in mock_init() to some constant pointer, e.g (void*)42, and then return it here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. BTW, doesn't the calloc call leak memory for every test-case using mock_clear()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I assume so. I will update according to Fredriks idea.
1f5358b
to
6ce2de1
Compare
/* Initialize everything (and the DCP protocol) */ | ||
/* First initialize the network interface */ | ||
net->eth_handle = | ||
pnal_eth_init (p_cfg->if_cfg.main_port.if_name, pf_eth_recv, (void *)net); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove #define pnal_eth_init mock_pnal_eth_init
also
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, second push below is a rebase on master
6ce2de1
to
fd69be0
Compare
- See doc/multiple_ports.rst for information on how to configure and run a mulitport configuration - Verified on Raspberry Pi with additional USB ethernet interfaces
fd69be0
to
c48c415
Compare
and run a mulitport configuration