-
Notifications
You must be signed in to change notification settings - Fork 56
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
Add support for custom IP networks #125
Conversation
I don't have free cycles this week to review in detail, but even with the great PR description I'm wondering why turmoil needs to support this? Most of the use cases I encounter actually prefer the string hostnames because it makes debugging a lot easier. Are you trying to test specific logic based on binds? If so, is turmoil the right place to do that? |
I think using The current issue is, that while non Its not so much about the nodes own identity, but rather the IP of incoming requests |
Thanks for the detailed explanation. I will prioritize this PR early next week. |
I think it needs to be checked.
I'm not sure about deep in the application code. What would the non-turmoil equivalent be and how would you switch based on the environment the code is running in? |
Non-turmoil based implementations would likely read the local ip addr from either a config file |
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 is a really useful feature addition, thank you.
I left a comment about the IpNetwork abstraction, which is more for @mcches than you. I think there going to be usecases where we need to mix v4 and v6 even without supporting routing between subnets.
src/ip.rs
Outdated
/// The address layout of the underlying network. | ||
/// | ||
/// The default value is an Ipv4 subnet with addresses | ||
/// in the range `192.168.0.0/16`. | ||
#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
pub enum IpNetwork { | ||
/// An Ipv4 capable network, with a given subnet address range. | ||
V4(Ipv4Network), | ||
/// An Ipv6 capable network, with a given subnet address range. | ||
V6(Ipv6Network), | ||
} |
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 think this is a reasonable, pragmatic change, but it doesn't seem like this is what we really want to end up with. For example, what if I want to have a setup where a single machine has an admin process on it that listens with v4 and creates N processes (in response to API calls) with v6 addresses. I think this is the sort of setup you're aiming to support (is that right?), and so I think there is a design smell here.
I'm not suggesting you change this for this review (again, your change is pragmatic), but we should think about how this plays out and be mindful it's likely to cause maintenance problems.
src/builder.rs
Outdated
@@ -52,8 +52,8 @@ impl Builder { | |||
} | |||
|
|||
/// Which kind of network should be simulated. | |||
pub fn ip_version(&mut self, value: IpVersion) -> &mut Self { | |||
self.ip_version = value; | |||
pub fn ip_network(&mut self, value: impl Into<IpNetwork>) -> &mut Self { |
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 is a breaking change, requiring a version bump, so to echo what @marcbowes said... perhaps we can get closer to the desired state (at least at the public API) with this change to avoid subsequent breaking changes.
I think the core question is, whether turmoil should support mixed Ip traffic in its subnet. Since we most likely want to simulate a mixed Ipv4/Ipv6 subnet with independent address ranges, struct SubnetsCfg {
v4: Ipv4Subnet,
v6: Ipv6Subnet,
}
impl Builder {
fn subnets(&mut self, cfg: SubnetsCfg) { ... }
} would do the job, however this would not work with the current networking implementation. In short, I think the current networking implementation and this desired goal are too different, to create an API now, that However breaking the API now, and that breaking it later a second time seems redundant, so should be try |
It likely requires a full restructuring of I don't have a clear picture, but if you want to take a stab at a proposal that would be great. See #79 (comment). For faster discussion, we could also do this on the tokio discord server. |
I have closed this PR, since the nessecary refactoring exceeds the scope of this PR. |
This PR adds support for custom IP networks instead of just
192.168.0.0/16
orfe80::/64
.Applications may behave differently, based on the bound IP addresses, especially with Ipv6 addresses.
fe80::
link-local-addresses may be treated differently thanffc0::
unicast-local or200x::
unicast-globalin some applications.
Therefore the parameter
IpVersion
(renamed toIpNetwork
) was extended to support custom subnetsas a parameter. Default cfg remains
Ipv4 192.168.0.0./16
.Changes:
IpVersion
renamed toIpNetwork
V4(Ipv4Network)
andV6(Ipv6Network)
Builder::ip_version
renamed toBuilder::ip_network
Open Questions: