Builder

Struct Builder 

Source
pub struct Builder { /* private fields */ }
Expand description

Build a tracer.

This is a convenience builder to simplify the creation of execution of a tracer.

§Examples

use trippy_core::{Builder, MultipathStrategy, Port, PortDirection, PrivilegeMode, Protocol};

let addr = std::net::IpAddr::from([1, 2, 3, 4]);
let tracer = Builder::new(addr)
    .privilege_mode(PrivilegeMode::Unprivileged)
    .protocol(Protocol::Udp)
    .multipath_strategy(MultipathStrategy::Dublin)
    .port_direction(PortDirection::FixedBoth(Port(33434), Port(3500)))
    .build()?;

§See Also

  • Tracer - A traceroute implementation.

Implementations§

Source§

impl Builder

Source

pub fn new(target_addr: IpAddr) -> Self

Build a tracer builder for a given target.

§Examples

Basic usage:

use trippy_core::Builder;

let addr = std::net::IpAddr::from([1, 1, 1, 1]);
let tracer = Builder::new(addr).build()?;
Source

pub fn source_addr(self, source_addr: Option<IpAddr>) -> Self

Set the source address.

If not set then the source address will be discovered based on the target address and the interface.

§Examples
use std::net::IpAddr;
use trippy_core::Builder;

let addr = IpAddr::from([1, 1, 1, 1]);
let source_addr = IpAddr::from([192, 168, 1, 1]);
let tracer = Builder::new(addr).source_addr(Some(source_addr)).build()?;
Source

pub fn interface<S: Into<String>>(self, interface: Option<S>) -> Self

Set the source interface.

If the source interface is provided it will be used to look up the IPv4 or IPv6 source address.

If not provided the source address will be determined by OS based on the target IPv4 or IPv6 address.

§Examples
use std::net::IpAddr;
use trippy_core::Builder;

let addr = IpAddr::from([1, 1, 1, 1]);
let tracer = Builder::new(addr).interface(Some("eth0")).build()?;
Source

pub fn protocol(self, protocol: Protocol) -> Self

Set the protocol.

§Examples
use std::net::IpAddr;
use trippy_core::{Builder, Protocol};

let addr = IpAddr::from([1, 1, 1, 1]);
let tracer = Builder::new(addr).protocol(Protocol::Udp).build()?;
Source

pub fn trace_identifier(self, trace_id: u16) -> Self

Set the trace identifier.

If not set then 0 will be used as the trace identifier.

use std::net::IpAddr;
use trippy_core::Builder;

let addr = IpAddr::from([1, 1, 1, 1]);
let tracer = Builder::new(addr).trace_identifier(12345).build()?;
Source

pub fn privilege_mode(self, privilege_mode: PrivilegeMode) -> Self

Set the privilege mode.

§Examples
use std::net::IpAddr;
use trippy_core::{Builder, PrivilegeMode};

let addr = IpAddr::from([1, 1, 1, 1]);
let tracer = Builder::new(addr)
    .privilege_mode(PrivilegeMode::Unprivileged)
    .build()?;
Source

pub fn multipath_strategy(self, multipath_strategy: MultipathStrategy) -> Self

Set the multipath strategy.

§Examples
use std::net::IpAddr;
use trippy_core::{Builder, MultipathStrategy};

let addr = IpAddr::from([1, 1, 1, 1]);
let tracer = Builder::new(addr)
    .multipath_strategy(MultipathStrategy::Paris)
    .build()?;
Source

pub fn packet_size(self, packet_size: u16) -> Self

Set the packet size.

§Examples
use std::net::IpAddr;
use trippy_core::Builder;

let addr = IpAddr::from([1, 1, 1, 1]);
let tracer = Builder::new(addr).packet_size(128).build()?;
Source

pub fn payload_pattern(self, payload_pattern: u8) -> Self

Set the payload pattern.

§Examples
use std::net::IpAddr;
use trippy_core::Builder;

let addr = IpAddr::from([1, 1, 1, 1]);
let tracer = Builder::new(addr).payload_pattern(0xff).build()?;
Source

pub fn tos(self, tos: u8) -> Self

Set the type of service.

§Examples
use std::net::IpAddr;
use trippy_core::Builder;

let addr = IpAddr::from([1, 1, 1, 1]);
let tracer = Builder::new(addr).tos(0x1a).build()?;
Source

pub fn icmp_extension_parse_mode( self, icmp_extension_parse_mode: IcmpExtensionParseMode, ) -> Self

Set the ICMP extensions mode.

§Examples
use std::net::IpAddr;
use trippy_core::{Builder, IcmpExtensionParseMode};

let addr = IpAddr::from([1, 1, 1, 1]);
let tracer = Builder::new(addr)
    .icmp_extension_parse_mode(IcmpExtensionParseMode::Enabled)
    .build()?;
Source

pub fn read_timeout(self, read_timeout: Duration) -> Self

Set the read timeout.

§Examples
use std::net::IpAddr;
use std::time::Duration;
use trippy_core::Builder;

let addr = IpAddr::from([1, 1, 1, 1]);
let tracer = Builder::new(addr)
    .read_timeout(Duration::from_millis(50))
    .build()?;
Source

pub fn tcp_connect_timeout(self, tcp_connect_timeout: Duration) -> Self

Set the TCP connect timeout.

§Examples
use std::net::IpAddr;
use std::time::Duration;
use trippy_core::Builder;

let addr = IpAddr::from([1, 1, 1, 1]);
let tracer = Builder::new(addr)
    .tcp_connect_timeout(Duration::from_millis(100))
    .build()?;
Source

pub fn max_rounds(self, max_rounds: Option<usize>) -> Self

Set the maximum number of rounds.

If set to None then the tracer will run indefinitely, otherwise it will stop after the given number of rounds.

§Examples
use std::net::IpAddr;
use trippy_core::Builder;

let addr = IpAddr::from([1, 1, 1, 1]);
let tracer = Builder::new(addr).max_rounds(Some(10)).build()?;
Source

pub fn first_ttl(self, first_ttl: u8) -> Self

Set the first ttl.

§Examples
use std::net::IpAddr;
use trippy_core::Builder;

let addr = IpAddr::from([1, 1, 1, 1]);
let tracer = Builder::new(addr).first_ttl(2).build()?;
Source

pub fn max_ttl(self, max_ttl: u8) -> Self

Set the maximum ttl.

§Examples
use std::net::IpAddr;
use trippy_core::Builder;

let addr = IpAddr::from([1, 1, 1, 1]);
let tracer = Builder::new(addr).max_ttl(16).build()?;
Source

pub fn grace_duration(self, grace_duration: Duration) -> Self

Set the grace duration.

§Examples
use std::net::IpAddr;
use std::time::Duration;
use trippy_core::Builder;

let addr = IpAddr::from([1, 1, 1, 1]);
let tracer = Builder::new(addr)
    .grace_duration(Duration::from_millis(100))
    .build()?;
Source

pub fn max_inflight(self, max_inflight: u8) -> Self

Set the max number of probes in flight at any given time.

§Examples
use std::net::IpAddr;
use trippy_core::Builder;

let addr = IpAddr::from([1, 1, 1, 1]);
let tracer = Builder::new(addr).max_inflight(22).build()?;
Source

pub fn initial_sequence(self, initial_sequence: u16) -> Self

Set the initial sequence number.

§Examples
use std::net::IpAddr;
use trippy_core::Builder;

let addr = IpAddr::from([1, 1, 1, 1]);
let tracer = Builder::new(addr).initial_sequence(35000).build()?;
Source

pub fn port_direction(self, port_direction: PortDirection) -> Self

Set the port direction.

§Examples
use std::net::IpAddr;
use trippy_core::{Builder, Port, PortDirection};

let addr = IpAddr::from([1, 1, 1, 1]);
let tracer = Builder::new(addr)
    .port_direction(PortDirection::FixedDest(Port(8080)))
    .build()?;
Source

pub fn min_round_duration(self, min_round_duration: Duration) -> Self

Set the minimum round duration.

§Examples
use std::net::IpAddr;
use std::time::Duration;
use trippy_core::Builder;

let addr = IpAddr::from([1, 1, 1, 1]);
let tracer = Builder::new(addr)
    .min_round_duration(Duration::from_millis(500))
    .build()?;
Source

pub fn max_round_duration(self, max_round_duration: Duration) -> Self

Set the maximum round duration.

§Examples
use std::net::IpAddr;
use std::time::Duration;
use trippy_core::Builder;

let addr = IpAddr::from([1, 1, 1, 1]);
let tracer = Builder::new(addr)
    .max_round_duration(Duration::from_millis(1500))
    .build()?;
Source

pub fn max_samples(self, max_samples: usize) -> Self

Set the maximum number of samples to record.

§Examples
use std::net::IpAddr;
use trippy_core::Builder;

let addr = IpAddr::from([1, 1, 1, 1]);
let tracer = Builder::new(addr).max_samples(256).build()?;
Source

pub fn max_flows(self, max_flows: usize) -> Self

Set the maximum number of flows to record.

§Examples
use std::net::IpAddr;
use trippy_core::Builder;

let addr = IpAddr::from([1, 1, 1, 1]);
let tracer = Builder::new(addr).max_flows(64).build()?;
Source

pub fn drop_privileges(self, drop_privileges: bool) -> Self

Drop privileges after connection is established.

§Examples
use std::net::IpAddr;
use trippy_core::Builder;

let addr = IpAddr::from([1, 1, 1, 1]);
let tracer = Builder::new(addr).drop_privileges(true).build()?;
Source

pub fn build(self) -> Result<Tracer, Error>

Build the Tracer.

§Examples
use std::net::IpAddr;
use trippy_core::Builder;

let addr = IpAddr::from([1, 1, 1, 1]);
let tracer = Builder::new(addr).build()?;
§Errors

This function will return Error::BadConfig if the configuration is invalid.

Trait Implementations§

Source§

impl Debug for Builder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Builder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more