jhaws1982 / rustycan4docker

Docker plugin for managing CAN networks (virtual and physical), utilizing vxcan tunnels and CANgw
MIT License
2 stars 2 forks source link

Option to prevent creation of network if host device is non-existant #1

Open postlund opened 9 months ago

postlund commented 9 months ago

First of all, thank for this project. Works really great!

I'm developing software used to visualize some data inside a car by reading data from various CAN buses. For testing and development purposes, I run the same software on my desktop computer by simulating the vehicle buses (i.e. sending CAN frames on virtual CAN buses that replicates the car). In the first case I use physical CAN dongles to connect to the car and in the latter case I just use the virtual devices created by this plugin. My problem is that I easily end up with interface name collisions amongst virtual and physical interfaces, since I sometimes also connect physical CAN dongles to my computer for testing purposes.

So, I have written udev rules that renames my dongles (based on their serial numbers) to specific device names, e.g. vehcan0. This allows me to attach the devices to any USB port, knowing their interface name remains correct from the perspective of my configuration. If I however start a simulation with peer.dev set to vehcan0, the name will of course be occupied by the docker network. So if I attach my physical dongle after that, renaming will fail due to the name already being taken.

For me, an option that prevents the plugin from setting up a network in case the host device is missing (=hard fail) would help out a lot. My configuration would use peer.dev set to sim_vehcan0 if that option is not set (when running simulated), otherwise just set it to vehcan0. This would make sure I never end up in a situation where interface names conflict with one another.

Would such a feature be feasible to implement?

jhaws1982 commented 9 months ago

Yeah, I think a "simulation" option would be easy to implement. If you want to give it a try and submit a PR, I'd be happy to take a look and pull it in!

postlund commented 9 months ago

Sorry for the delay! I'll see if I get some time to take a stab at it (I have never coded rust, so that's new to me). I'll send a PR over once I do!

jhaws1982 commented 9 months ago

Sorry for the delay! I'll see if I get some time to take a stab at it (I have never coded rust, so that's new to me). I'll send a PR over once I do!

Rust was new to me too, but once I got into it and learned the syntax, it wasn't too bad to pick up and I really like it as a language. I started with this: https://docs.rust-embedded.org/book/