Rnp - A simple layer 4 ping tool for cloud.
Release | Status |
---|---|
Crates.io | |
Github release | |
Nuget packages |
===
)
===
|
| ()
|
=== ) ===
| )
|
)
Why Rnp?
Ping is one of the most frequently used tool for testing network reachability. And yet, we have another one here... So why?
Despite there are numerous ping tools in the market, I wrote RNP for some specific reasons:
- Wide platform support, so we can run it everywhere.
- Wide platform support: Windows/Linux, x86/amd64/arm64.
- Wide machine environment support: Minimum dependencies, such as runtimes like JRE/CLR.
- Be cloud-friendly:
- Support scanning all network paths.
- Nowadays, services and network data paths are mostly redundant. Technologies like load balancer and ECMP are widely used in cloud and modern data center.
- Because of this, if a service, or a network link is having trouble, we will see intermediate packet drop/latency, instead of seeing full connectivity drop. Hence, we need a tool to help us scan all possible network paths and find out the bad links.
- Minimize port usage (Friendly to SNAT).
- Support scanning all network paths.
- Avoid unstable measurements when possible.
- Easy to use.
- ...
To help us achieve the things above, we are implementing our ping in a very specific way.
- TCP connect as ping. Focus on network reachability.
- Why not ICMP ping?
- Unlike TCP, ICMP is lacking of variant, which makes it bad for scanning all possible network paths.
- ICMP is banned in many machines and network for security reasons, so ICMP timeout doesn't really mean it is timeout.
- Why not UDP ping?
- UDP is connectionless, so there is no so-called UDP ping.
- Existing UDP ping tool uses ICMP unreachable message for detecting if a UDP port is reachable or not, which causes 2 problems:
- Implementation usually involves using raw socket, which is really bad for performance, especially in cloud, where the network load could be high.
- Same as ICMP ping. ICMP can be banned, hence UDP ping works doesn't really mean UDP port is open. (And one of the reasons that people ban ICMP is to avoid this UDP port scan.)
- Why not ICMP ping?
- Parallel pings for spray all possible network paths:
- We rotate the source port to make each ping having different tuples to allow them going through different network path.
- Parallel pings with configurable ping intervals can dramatically increase the scanning speed.
- RST instead of FIN by default. Minimize port usage.
- Most of the tcp connect tools follows the regular way to disconnect the TCP connection - the 4-way handshake with FIN packet. This is great for servers, but not for testing.
- The regular disconnect leaves the ports in TIME_WAIT state, and the cloud load balancers have to keep tracking these SNAT ports as well. It can easily cause SNAT port allocation error, which will make the network for your service even worse. You definitely don't want to see this.
- Use Rust as the programming language:
- Rust is a system language with very light-weighted and GC-free runtime, which means no more random lags during our measurements, such as stop-the-world stages in GC.
- Rust has wide range of platform support and produces almost self-contained native binaries, so we can simply copy and run.
- Rust is as fast as C, while also has great support for modern age asynchronous programming. Gems like go-like mpsc channel, async/await, you can find them all in Rust.
- ...
- Friendly result output:
- Besides outputting just like ping, we also provided other ways to show the results, such as very compacted scatter map.
- We also support outputting the result into CSV/JSON/Text files for later analysis or scripting.
Some hard decisions:
- DNS name resolution is intentionally not supported. Using IP address is enforced when using our ping.
- This is because DNS can return different result based on geo-location. This misleads people a lot when collaborating on network issues, because it might end up with different people debugging different issues without even knowing it for long time.
- To get IP from DNS, we can run
nslookup <domain-name>
.
Usage
Ok, let's check some real cases to get started!
The simplest case - regular TCP connect test. Works just like ping.
===
)
)
Now let's make our ping faster by adding -p 10
to spawn 10 workers and -i 0
to remove the intervals we wait between each ping, then run 100 pings. And to avoid abusing our console, we disable the regular output (-q
), enable the result scatter map (-r
) and log the details to a json file for later use (--log-json log.json
).
===
)
===
|
| ()
|
|
|
|
|
|
)
We will see the test will complete almost immediately, and the details will be logged into the json file:
And now, we can see our ping failed on port 19653, then we can start a continuous ping to rerun the bad ports. And we can see a fairly high failure rate on this port as below.
)
Also, we can easily try all failure ports again and see how they look like. Here is an example using powershell, and on non-windows platform, we can easily do the same thing with tools like jq:
# Extract the failure ports
| | | | )
# Retry
)
And rnp will start to rotate the ping within all the specified source ports for testing.
More in help
To see more on this tool, we can try --help
option.
)
Contributes
Thanks a lot in being interested in this project and all contributions are welcomed!
To contribute to the project, please feel free to open issues and discuss. Then submit a pull request for review and merge into main branch.
How to build
Just like the rest of Rust project, simply use cargo
to build it.
To build release version:
To build other targets, such as ARM64 on windows, we can use --target
to specify the target (of course, in this specific case, we need to install the msvc ARM64 toolchain from visual studio).
Resources
- Equal-cost multi-path routing
- AWS NAT gateways and ErrorPortAllocation error
- Azure Load Balancer, SNAT port exhaustion and outbound connectivity troubleshooting
License
Apache-2.0: https://www.apache.org/licenses/LICENSE-2.0