Flow trace queries¶
client.flow_trace exposes the routes Forward's own Search page uses to trace
traffic: the distinct paths a query takes (get_trace_facets), one path in
detail (get_trace), return traffic, behaviours, flows and diffs. Forward
documents none of them and makes no stability promise.
Their request body carries a path query. Build it with forward_sdk.trace
rather than by hand: the builder writes the shapes Forward expects and refuses,
before sending, what Forward would refuse or quietly misread.
from forward_sdk.trace import ChainHop, Endpoint, PathQuery, device, interface
query = PathQuery(
from_=Endpoint(device("edge-1"), headers=[{"ipv4_dst": ["192.0.2.10"], "ip_proto": ["6"]}]),
chain=[ChainHop("through", device("fw-1"))],
to=Endpoint(interface("core-1", "eth1/1")),
)
facets = client.flow_trace.get_trace_facets(body=query.request(max_results=100))
if facets.possible_ip_locations:
... # an address is in several places: name one with subnet_at_device() and ask again
elif facets.total_results is None:
... # timed out: the paths are partial
else:
print(facets.total_results.value, facets.total_results.type)
Tracing each path¶
The facets list the distinct paths; get_trace gives one of them hop by hop.
selections() lists every path of a facets answer, and trace_request()
builds the trace body for one, with the same query:
from forward_sdk.trace import selections
traces = [
client.flow_trace.get_trace(body=query.trace_request(group, path))
for group, path in selections(facets)[:20] # one request per path: cap it
]
Use the snapshot the facets came from for both. A trace of only {timedOut}
means no flow was found for that path. Seen live on fwd.app (2026-11-18): a
query with a through chain hop listed valid, dropped, blackholed and
unreachable paths, and trace_request traced each selected path hop by hop, its
hop count equal to the path's length.
What goes where¶
from_is where traffic enters the network andchainthe hops it must pass. A subnet intoreturned no paths live, even for an address inside the network, while an interface intodid. The Go SDK reads Forward's source astomeaning where traffic leaves the network; that reading is not confirmed. Put an in-network destination in thefrom_headers (ipv4_dst), or name a device or interface into.- The SDK refuses an empty query and an empty header filter, which Forward itself accepts, as the Go SDK does.
- An interface is
"<device> <interface>"with a space. Forward refuses the comma form it uses for port names elsewhere.interface()builds it. - A host or subnet cannot be a chain hop.
app_id,user_id,user_group_idand the layer-7 header fields are allowed only infrom_. The SDK refuses the first three itself and leaves the layer-7 names to Forward's 400.mode=PERMIT_ALLtraces as if ACL drops permitted the traffic. It needs the org property ACL_LESS_ANALYSIS, which is on by default.
What was seen live¶
Forward 26.11, a two-device lab: device, interface and subnet locations, the
interface naming, an empty result as {"value": 0, "type": "EXACT"}, and
ipv6_dst and PERMIT_ALL accepted. Seen since by the forward-skills
tooling (fwdctl, built on the Go SDK) on 26.11, 2026-11-15:
a device chain hop with through narrows the paths and egress is accepted
(and the AutoCon6 workshop's persistent Existential check took a device hop
written with the singular value as well as values, which the SDK sends);
header filters in from_ (ip_proto, tp_dst, an ipv4_dst prefix) narrow;
a device in to returns the paths leaving there; and get_trace with the
same filters traces a searched path hop by hop. Everything else here, including
the other location types and possibleIpLocations, is read from Forward
source. Not confirmed: tracing to the internet, IPv6 results, and what
Forward answers to PERMIT_ALL with ACL_LESS_ANALYSIS off.
Reference¶
forward_sdk.trace ¶
Typed path queries for Forward's flow-trace facets (client.flow_trace).
get_trace_facets and its siblings take the request body Forward's own
Search page sends, whose filters is a PathQuery: where traffic enters the
network (from_), the hops it must pass (chain), where it leaves
(to), and header filters on each. This module builds that object and
refuses, before anything is sent, what Forward would refuse or silently
misread. It mirrors the Go SDK's TracePathQuery (v0.8.27).
PREVIEW, like the routes it feeds: Forward documents none of this and makes no stability promise. What was seen live (Forward 26.11, a two-device lab) is noted as such; the rest is read from Forward source.
from forward_sdk.trace import Endpoint, PathQuery, device, interface
query = PathQuery(
from_=Endpoint(device("edge-1"), headers=[{"ipv4_dst": ["192.0.2.10"], "ip_proto": ["6"]}]),
to=Endpoint(interface("core-1", "eth1/1")),
)
facets = client.flow_trace.get_trace_facets(body=query.request(max_results=100))
total = facets.total_results # None on a timeout or when possible_ip_locations is set
Notes from the live probe:
- An interface is named
"<device> <interface>"with a space; the comma form Forward uses for port names elsewhere is a 400.interface()builds it. - A
subnet()intoreturned no results even for an address inside the network, while an interface intoreturned paths. The Go SDK reads the source astomeaning where traffic leaves the network (not confirmed). Put an in-network destination infrom_headers (ipv4_dst) or name a device or interface into. - No results is
totalResults {"value": 0, "type": "EXACT"}. ipv6_dstandmode=PERMIT_ALLwere accepted; neither produced results to check in the lab.
Location
dataclass
¶
Endpoint
dataclass
¶
A from_ or to clause: a location and optional header filters.
Each header filter maps Forward's lower-case field names to the values they
may take, for example {"ipv4_dst": ["192.0.2.0/24"], "tp_dst": ["443"]}.
ChainHop
dataclass
¶
A hop the traffic must pass. Source only.
through is anywhere along the path; ingress and egress enter or leave there.
PathQuery
dataclass
¶
The Search page's query, as filters of a flow-trace request.
At least one of from_, to and chain is required (a mode alone is
not a query). mode is None or :data:PERMIT_ALL. The SDK also
refuses two things Forward itself accepts, as Go does: an empty query and an
empty header filter.
to_api ¶
to_api() -> dict[str, Any]
The PathQuery object; raises ValueError for anything Forward would refuse.
trace_request ¶
trace_request(
group: TracePathGroup,
path: TracePathFacet,
*,
max_results: int | None = None,
max_duration_seconds: int | None = None,
) -> dict[str, Any]
A body for client.flow_trace.get_trace: this query, with one path selected.
group and path come from the facets answer to this same query
(see :func:selections), so a query with a chain, a to location,
headers or PERMIT_ALL can be traced hop by hop as well as counted.
Mirrors the Go SDK's TraceFor (v0.8.38). Seen live on fwd.app with a
through chain hop: the traced hops match the selected path.
request ¶
request(
*,
max_results: int | None = None,
max_duration_seconds: int | None = None,
**extra: Any,
) -> dict[str, Any]
A whole request body for get_trace_facets (and the other trace routes).
max_results caps the flows examined (1..10000, Forward's default
5000); max_duration_seconds is the time budget (1..300, default 30).
Anything else, such as selectedFacets for get_trace, passes
through unchanged.
host ¶
host(*names: str) -> Location
Hosts by name (HostFilter). Not allowed as a chain hop. Source only.
device ¶
device(*names: str) -> Location
Devices by name (DeviceFilter). Allowed everywhere; seen live.
interface ¶
interface(
device_name: str, interface_name: str
) -> Location
One interface of one device, sent as "<device> <interface>" (seen live).
A blank part is refused when the query is built.
interface_values ¶
interface_values(*values: str) -> Location
Interfaces by Forward's own "<device> <interface>" strings.
device_vrf ¶
device_vrf(device_name: str, vrf_name: str) -> Location
One VRF of one device (DeviceVrfFilter). Source only.
security_zone ¶
security_zone(device_name: str, zone: str) -> Location
A security zone of one device (SecurityZoneFilter). Source only.
subnet ¶
subnet(cidr: str) -> Location
An address or prefix (SubnetLocationFilter). Not allowed as a chain hop.
In to it returned nothing live even for an in-network address; see the
module notes. Forward refuses loopback prefixes (source).
subnet_at_device ¶
subnet_at_device(cidr: str, device_name: str) -> Location
An address or prefix resolved on one device, when it is in several places. Source only.
selection ¶
selection(
group: TracePathGroup, path: TracePathFacet
) -> dict[str, Any]
The selectedFacets and limit that pick one path of a facets answer for get_trace.
The path's behaviorSample goes back as Forward sent it (left out when
there is none), and limit is 100, as the GUI and the Go SDK send. A path
with no hops or a group with no trace type is refused, as Go does, rather
than left to fail on the server.
selections ¶
selections(
facets: TraceFacetsResponse,
) -> list[tuple[TracePathGroup, TracePathFacet]]
Every (group, path) pair a facets answer lists, in Forward's order.
Trace each with query.trace_request(group, path); that is the Go SDK's
ExplainQuery as a loop, one request per path, so slice the list to cap
it as Go's ExplainLimit does::
facets = client.flow_trace.get_trace_facets(body=query.request())
traces = [
client.flow_trace.get_trace(body=query.trace_request(group, path))
for group, path in selections(facets)
]