Skip to contentSkip to conversation

SocketCAN over Ethernet

DISCUSSION Daniel Boström 5 participants 9 messages Apr 3, 2014 – Apr 8, 2014 CAN network drivers

lore
Share & tools
lore
#0 lore raw

Hello,

I am going to try to explain our scenario briefly.

We want to setup a simulation environment for our system running on Ubuntu so that we can use it together with our Windows based simulation tool suite. Currently we are running Ubuntu in a virtual machine using VirtualBox on a Windows host. In Ubuntu we use SocketCAN and we would like to continue to do so but instead of using real CAN hardware somehow setup CAN communication over Ethernet to the Windows host.

I am new to CAN on Linux but I have been reading about SocketCAN and was wondering if we could use virtual can (vcan) somehow?

I appreciate any help clarifying if, and if so, how SocketCAN over Ethernet could be achieved. If you need additional information about our scenario please let me know.

Best regards
Daniel

#1 lore raw

Hello,

I don't know of a direct way of hooking up two socket can interfaces over eth.

If this is just a quick fix or development crutch and not for production you could try the following: Create a VCAN interface on both machines. Create a simple userspace program (perhaps in C) to listen to the VCAN interface, and transmit the frames read, via UDP (or TCP), to the other machine. Create another program to listen to the UDP traffic and dumps it into the VCAN interface on the other host. invert the roles and you've got duplex.

If the arch of the two hosts is binary compatible you don't even need to encode data.

I have done this while I was working on a display software, It allowed me to work on the laptop on the sofa using live can data aggregated by sensors and a server elsewhere.

Regards,
Maximilian Schneider.

Quoted 26 lines · Daniel Boström

Hello,

I am going to try to explain our scenario briefly.

We want to setup a simulation environment for our system running on Ubuntu so that we can use it together with our Windows based simulation tool suite. Currently we are running Ubuntu in a virtual machine using VirtualBox on a Windows host. In Ubuntu we use SocketCAN and we would like to continue to do so but instead of using real CAN hardware somehow setup CAN communication over Ethernet to the Windows host.

I am new to CAN on Linux but I have been reading about SocketCAN and was wondering if we could use virtual can (vcan) somehow?

I appreciate any help clarifying if, and if so, how SocketCAN over Ethernet could be achieved. If you need additional information about our scenario please let me know.

Best regards
Daniel

--
To unsubscribe from this list: send the line "unsubscribe linux-can" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw
In reply to Daniel Boström

Hello Daniel,

Quoted 4 lines · Daniel Boström

Currently we are running Ubuntu in a virtual machine using VirtualBox on a Windows host. In Ubuntu we use SocketCAN and we would like to continue to do so but instead of using real CAN hardware somehow setup CAN communication over Ethernet to the Windows host.

Don't know if I understand you correctly:

Do you want the CAN interfaces to be attached to the Windows host and access these interfaces from Linux ... or the other way around?

Maybe a look at the JAVA tool Kayak (http://kayak.2codeornot2code.org/) might be interesting for you.

Kayak uses the socketcand (https://github.com/dschanoeh/socketcand/) which runs on Linux and provides the CAN interfaces via IP-sockets (to whatever client).

Regards,
Oliver

#8 lore raw
In reply to Daniel Boström

Hello Daniel,

Have a look at socketcand :
https://github.com/dschanoeh/socketcand

It might be exactly what you are looking for...

F. Beaulier

Quoted 26 lines · Daniel Boström

Hello,

I am going to try to explain our scenario briefly.

We want to setup a simulation environment for our system running on Ubuntu so that we can use it together with our Windows based simulation tool suite. Currently we are running Ubuntu in a virtual machine using VirtualBox on a Windows host. In Ubuntu we use SocketCAN and we would like to continue to do so but instead of using real CAN hardware somehow setup CAN communication over Ethernet to the Windows host.

I am new to CAN on Linux but I have been reading about SocketCAN and was wondering if we could use virtual can (vcan) somehow?

I appreciate any help clarifying if, and if so, how SocketCAN over Ethernet could be achieved. If you need additional information about our scenario please let me know.

Best regards
Daniel

--
To unsubscribe from this list: send the line "unsubscribe linux-can" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw
In reply to Oliver Hartkopp
Quoted 7 lines · Oliver Hartkopp <socketcan <at> hartkopp.net> writes:

Hello Daniel,

Quoted 2 lines · Daniel Boström

Currently we are running Ubuntu in a virtual machine using VirtualBox on a Windows host. In Ubuntu we use SocketCAN and we would

like

Quoted 1 line
Quoted 1 line

to continue to do so but instead of using real CAN hardware somehow

setup

Quoted 5 lines
Quoted 1 line

CAN communication over Ethernet to the Windows host.

Don't know if I understand you correctly:

Do you want the CAN interfaces to be attached to the Windows host and

access

Quoted 3 lines

these interfaces from Linux ... or the other way around?

Maybe a look at the JAVA tool Kayak (http://kayak.2codeornot2code.org/)

might

Quoted 3 lines

be interesting for you.

Kayak uses the socketcand (https://github.com/dschanoeh/socketcand/)

which

Quoted 1 line

runs on Linux and provides the CAN interfaces via IP-sockets (to

whatever client).

Quoted 10 lines

Regards,
Oliver

--
To unsubscribe from this list: send the line "unsubscribe linux-can" in the body of a message to majordomo <at> vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

Thank you everyone for the replies.

I will try to explain a bit more what we are trying to do.

Our simulation software (used for testing our system without real hardware) on Windows listens for incoming TCP connections from our system to test (using SocketCAN) running on the Ubuntu VM. So we would like a way to setup CAN communication over Ethernet (TCP) between the Windows and Ubuntu VM. In other words we want to send and receive can messages on both Windows and Ubuntu. socketcand sounds very interesting I will have a look at it.

We have run a similar simulation before but on Windows only and would like to be able to include an ubuntu machine in the simulation as well.

/Daniel

#5 lore raw

I created a vcan interface, built and started the socketcand daemon on the Ubuntu vm and finally installed Kayak on Windows. I had to edit socketcand.conf a bit but now CAN messages sent using cansend from Ubuntu show up in Kayak. I think this is a great start, thanks again for the help.

#2 lore raw
In reply to Max S.

Hi,

Quoted 2 lines · Max S.

I don't know of a direct way of hooking up two socket can interfaces over eth.

This won't probably help Daniel, but some time ago, we implemented an in-kernel CAN-UDP gateway.

Kernel patch is available at
https://rtime.felk.cvut.cz/gitweb/can-eth-gw-linux.git/commit/3f7fc0265e9555dea75cef7709720e62d8da37d8

The commit message says:

Quoted 9 lines

CAN-Ethernet gateway - kernel part

This patch implements CAN-Ethernet (or more precisely CAN-UDP) gateway. The code here is only responsible for routing the messages in kernel space. Initial configuration and setup of the involved sockets is done in user space with cegw utility.

Currently, the gateway support IPv4 and IPv6. CAN_FD frames are note supported.

The user-space counterpart is at
https://rtime.felk.cvut.cz/gitweb/can-utils.git/blob/refs/heads/cegw:/cegw.c

Probably, the only reason, why the gateway should be implemented in the kernel is performance. We measured that the kernel gateway is 12% faster than an user space one (which is not much).

If somebody is interested in more details, let me know.

-Michal

#6 lore raw
In reply to Daniel Boström
Quoted 2 lines · Daniel Boström <daniel.bostrom <at> maximatecc.com> writes:

I created a vcan interface, built and started the socketcand daemon on

the

Quoted 2 lines

Ubuntu vm and finally installed Kayak on Windows. I had to edit socketcand.conf a bit but now CAN messages sent using cansend from

Ubuntu

Quoted 1 line

show up in Kayak. I think this is a great start, thanks again for the

help.

Quoted 7 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-can" in the body of a message to majordomo <at> vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

Unfortunately when I tried the same setup today and use sendcan in Ubuntu Kayak does not show the message when I check the raw view. BusStatistics is however updated each time I send a message. I also noticed I am unable to send a message from Kayak and see it in Ubuntu using candump. Does anyone have an idea why it is not working anymore?

#7 lore raw
Quoted 2 lines · Daniel Boström <daniel.bostrom <at> maximatecc.com> writes:

Unfortunately when I tried the same setup today and use sendcan in

Ubuntu

Quoted 2 lines

Kayak does not show the message when I check the raw view. BusStatistics is however updated each time I send a message. I also noticed I am

unable

Quoted 9 lines

to send a message from Kayak and see it in Ubuntu using candump. Does anyone have an idea why it is not working anymore?

--
To unsubscribe from this list: send the line "unsubscribe linux-can" in the body of a message to majordomo <at> vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

Ignore this post, I did not read the Kayak tutorial carefully, it works now.