Skip to main content

trippy_core/
lib.rs

1//! Trippy - A network tracing library.
2//!
3//! This crate provides the core network tracing facility used by the
4//! standalone [Trippy](https://trippy.rs) application.
5//!
6//! Note: the public API is not stable and is highly likely to change
7//! in the future.
8//!
9//! # Example
10//!
11//! The following example builds and runs a tracer with default configuration
12//! and prints out the tracing data for each round:
13//!
14//! ```no_run
15//! # fn main() -> anyhow::Result<()> {
16//! # use std::net::IpAddr;
17//! # use std::str::FromStr;
18//! use trippy_core::Builder;
19//!
20//! let addr = IpAddr::from_str("1.1.1.1")?;
21//! Builder::new(addr)
22//!     .build()?
23//!     .run_with(|round| println!("{:?}", round))?;
24//! # Ok(())
25//! # }
26//! ```
27//!
28//! The following example traces using the UDP protocol with the Dublin ECMP
29//! strategy with fixed src and dest ports.  It also operates in unprivileged
30//! mode (only supported on some platforms):
31//!
32//! ```no_run
33//! # fn main() -> anyhow::Result<()> {
34//! # use std::net::IpAddr;
35//! # use std::str::FromStr;
36//! use trippy_core::{Builder, MultipathStrategy, Port, PortDirection, PrivilegeMode, Protocol};
37//!
38//! let addr = IpAddr::from_str("1.1.1.1")?;
39//! Builder::new(addr)
40//!     .privilege_mode(PrivilegeMode::Unprivileged)
41//!     .protocol(Protocol::Udp)
42//!     .multipath_strategy(MultipathStrategy::Dublin)
43//!     .port_direction(PortDirection::FixedBoth(Port(33434), Port(3500)))
44//!     .build()?
45//!     .run_with(|round| println!("{:?}", round))?;
46//! # Ok(())
47//! # }
48//! ```
49//!
50//! # See Also
51//!
52//! - [`Builder`] - Build a [`Tracer`].
53//! - [`Tracer::run`] - Run the tracer on the current thread.
54//! - [`Tracer::run_with`] - Run the tracer with a custom round handler.
55//! - [`Tracer::spawn`] - Run the tracer on a new thread.
56//! - [`Tracer::spawn_with`] - Run the tracer on a new thread with a custom round handler.
57
58mod builder;
59mod config;
60mod constants;
61mod error;
62mod flows;
63mod net;
64mod probe;
65mod state;
66mod strategy;
67mod tracer;
68mod types;
69
70use net::channel::Channel;
71use net::source::SourceAddr;
72
73pub use builder::Builder;
74pub use config::{
75    defaults, IcmpExtensionParseMode, MultipathStrategy, PortDirection, PrivilegeMode, Protocol,
76};
77pub use constants::MAX_TTL;
78pub use error::Error;
79pub use flows::{FlowEntry, FlowId};
80pub use probe::{
81    Extension, Extensions, IcmpPacketType, MplsLabelStack, MplsLabelStackMember, Probe,
82    ProbeComplete, ProbeStatus, UnknownExtension,
83};
84pub use state::{Hop, NatStatus, State};
85pub use strategy::{CompletionReason, Round, Strategy};
86pub use tracer::Tracer;
87pub use types::{
88    Dscp, Ecn, Flags, MaxInflight, MaxRounds, PacketSize, PayloadPattern, Port, RoundId, Sequence,
89    TimeToLive, TraceId, TypeOfService,
90};