Skip to content

Conversation

benjamin1313
Copy link
Contributor

This allows for specifying a start port and a range up from that to be used when looking for a free port to use with ser2net when creating a networkserialport resource. This can be helpful on networks where access to ports on the network is limited.

Currently this feature is planed for use in a labgrid setup where the exporter and duts are placed on a network separate from the main network the developers are on and there are restrictions on the tcp ports. Being able to specify what port(s) labgrid can use makes it easier to manage and keep track of what ports are open between the two networks.

Checklist

  • Documentation for the feature
  • Tests for the feature
  • PR has been tested
  • Man pages have been regenerated

@benjamin1313 benjamin1313 force-pushed the preferredport-networkserial branch from 6229841 to f72b887 Compare September 24, 2025 14:21
Copy link

codecov bot commented Sep 24, 2025

Codecov Report

❌ Patch coverage is 21.42857% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 45.3%. Comparing base (2daa13d) to head (85b2413).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
labgrid/util/helper.py 23.0% 10 Missing ⚠️
labgrid/remote/exporter.py 0.0% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           master   #1743     +/-   ##
========================================
- Coverage    45.4%   45.3%   -0.1%     
========================================
  Files         172     172             
  Lines       13503   13514     +11     
========================================
+ Hits         6131    6132      +1     
- Misses       7372    7382     +10     
Flag Coverage Δ
3.10 45.3% <21.4%> (-0.1%) ⬇️
3.11 45.3% <21.4%> (-0.1%) ⬇️
3.12 45.3% <21.4%> (-0.1%) ⬇️
3.13 45.3% <21.4%> (-0.1%) ⬇️
3.9 45.4% <21.4%> (-0.1%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

This allows for specifying a start port and a range up from that to be
used when looking for a free port to use with ser2net when creating a
networkserialport resource. This can be helpful on networks where access
to ports on the network is limited.

Signed-off-by: Benjamin B. Frost <benjamin@geanix.com>
@Emantor Emantor force-pushed the preferredport-networkserial branch from f72b887 to 85b2413 Compare September 25, 2025 05:38
Copy link
Member

@Emantor Emantor left a comment

Choose a reason for hiding this comment

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

I think it's usually more common to have a STARTPORT:ENDPORT definition instead of the PORT:RANGE used here, e.g. 4000:5000 instead of 4000:1000. This might also simplify the code, what do you think?

@Bastian-Krause
Copy link
Member

I think this should not be limited to ser2net. If the exporter needs to bind anything else in the future, it could use that range as well. So a more generic name would be good.

I'm not a huge fan of adding more environment variables, a CLI argument for labgrid-exporter would be a better fit. Especially since --isolated exists for similar cases where the exporter/DUT network setup is configured in a special way. So maybe --port-range=4000-5000?

@Bastian-Krause Bastian-Krause changed the title set preferred port for networkserialport exporter: limit ser2net port range Sep 25, 2025
@benjamin1313
Copy link
Contributor Author

I think it's usually more common to have a STARTPORT:ENDPORT definition instead of the PORT:RANGE used here, e.g. 4000:5000 instead of 4000:1000. This might also simplify the code, what do you think?

Yeah I see what you mean and will look into it.

I think this should not be limited to ser2net. If the exporter needs to bind anything else in the future, it could use that range as well. So a more generic name would be good.

Do you mean a global range for everything else that also needs a port?
Where I'm currently working on a Labgrid setup I'm not in charge of the network and I think giving Labgrid a range of ports to use for whatever is going to be a hard sell to the IT department in charge of the network.
Being able specify which ports are needed for what tool, service etc. is preferred.

@Bastian-Krause
Copy link
Member

Letting the exporter bind something is a rather special case. Apart from USBSerialPort/RawSerialPort exports running ser2net, I suppose that would only happen for a new kind of resource (if ever). As long as you don't export such a resource, no new binds will happen.

That being said, maybe it makes more sense (in such a regulated environment) to run ser2net outside labgrid and only export NetworkSerialPorts? If you're worried about misconfigurations, you could even configure your labgrid-exporter.service with SocketBindDeny=any.

@jluebbe
Copy link
Member

jluebbe commented Oct 2, 2025

Please keep in mind that without allocating a new port on acquire, you have the risk that an out of date client connects to the port it knows even if it no longer has a lock.

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.

4 participants