Skip to content

API reference ​

The complete jp4 public surface as of v1.5, organized into categories. Each entry links to the standard Javadoc HTML for the class. The Javadoc itself lives at /api/javadoc/ and is generated from the source by the standard javadoc tool — the authoritative source of truth for every method signature, return type, exception list, and @since tag.

For task-oriented guidance see Cookbook and Guides. For deeper background on cross-cutting topics see In-depth concepts.

Client lifecycle ​

ClassWhat it does
P4SwitchSingle client connection to one P4Runtime device. The main entry class for every jp4 program.
ConnectorFluent builder for opening a P4Switch connection: address, deviceId, electionId, reconnectPolicy, primary or secondary role.
ReconnectPolicyAuto-reconnect configuration — noRetry() (default) or exponentialBackoff(initial, max, retries).
ElectionIdUnsigned 128-bit P4Runtime election id (low + high pair). of(long) shorthand for low-only ids.
MastershipStatusSealed parent for the Acquired / Lost events delivered to onMastershipChange listeners.
MastershipStatus.AcquiredRecord signaling this client became primary; carries ourElectionId.
MastershipStatus.LostRecord signaling this client is not primary; carries previousElectionId (nullable) and currentPrimaryElectionId (nullable).

Pipeline ​

ClassWhat it does
PipelineBound pipeline view exposing the parsed P4Info plus the device-config descriptor.
P4InfoSchema wrapper over p4.config.v1.P4Info — name index for tables, actions, fields, entities, controller-metadata.
DeviceConfigSealed parent for the two device-config variants.
DeviceConfig.Bmv2BMv2-flavoured JSON device config; fromFile(Path) and fromBytes(byte[]) factories.
DeviceConfig.RawBytes-only escape hatch for non-BMv2 targets.
PipelineActionVerb selector for SetForwardingPipelineConfig (default VERIFY_AND_COMMIT).

Schema accessors (sub-types of P4Info) ​

ClassWhat it does
TableInfoResolved table metadata: id, match fields, action set, size.
MatchFieldInfoMatch field metadata: name, kind, bit width.
MatchFieldInfo.KindEnum: EXACT / LPM / TERNARY / RANGE / OPTIONAL.
ActionInfoResolved action metadata: id, parameter list.
ActionParamInfoAction parameter metadata: name, bit width.
CounterInfo / UnitCounter declaration with unit (BYTES / PACKETS / BOTH / UNSPECIFIED).
MeterInfo / UnitMeter declaration with unit (BYTES / PACKETS / UNSPECIFIED).
RegisterInfoRegister declaration: id, name, size.
ActionProfileInfoAction profile declaration with table-id set the profile is referenced from.
PacketMetadataInfocontroller_packet_metadata field declaration.

Match types ​

ClassWhat it does
MatchSealed parent; static lpm(cidr) and exact(value) shorthands.
Match.ExactExact-match key (value).
Match.LpmLongest-prefix-match key (value, prefixLen).
Match.TernaryTernary key (value, mask).
Match.RangeRange key (low, high).
Match.OptionalOptional key (value; null-safe wildcard).

Entity records ​

Records carrying typed data for each P4Runtime entity type.

ClassWhat it does
TableEntryTable entry record; in(name) builder entry point.
TableEntryBuilderFluent builder for TableEntry — match, action, priority, idleTimeoutNs.
ActionInstanceNamed action with parameter map; reachable from TableEntry.action(), ActionProfileMember.action().
ActionBuilderFluent builder for the .action(name).param(name, value) chain.
CounterEntryOne counter cell — name, index, packetCount, byteCount.
CounterDataPer-color packet/byte counter (used by MeterCounterData).
MeterEntryOne meter cell — name, index, config, per-color counter data.
MeterConfigMeter rate config — cir, cburst, pir, pburst, eburst.
MeterCounterDataPer-color cumulative counters (green, yellow, red).
RegisterEntryOne register cell — name, index, serialised P4Data bytes.
ActionProfileMemberAction-profile member — profile name, member id, action.
ActionProfileGroupAction-profile group — profile name, group id, max size, weighted members.
WeightedMemberGroup member — id, weight, nullable watch port.
MulticastGroupEntryMulticast group — id, replicas, metadata.
CloneSessionEntryClone session — id, replicas, classOfService, packetLengthBytes.
ReplicaPer-port fan-out slot — nullable port, instance, backup-replica list.
BackupReplicaBackup replica — non-null port, instance.

Read queries ​

Typed query builders for each entity-read family. All seven share the same shape: a server-side filter, a where(Predicate) client-side filter, and five terminals (all / one / stream / allAsync / oneAsync).

ClassServer-side filter
ReadQueryTable reads: match(field, MatchKind)
CounterReadQueryindex(long)
MeterReadQueryindex(long)
RegisterReadQueryindex(long)
ActionProfileMemberReadQuerymemberId(long)
ActionProfileGroupReadQuerygroupId(long)
MulticastGroupReadQuerygroupId(long)
CloneSessionReadQuerysessionId(long)

Stream messages ​

Records delivered to onPacketIn / onDigest / onIdleTimeout / onPacketDropped listeners, plus the outbound PacketOut builder.

ClassWhat it does
PacketInInbound packet — payload, controller-metadata field accessors (metadata(name), metadataInt(name), metadataLong(name)).
PacketOutOutbound packet record.
PacketOut.BuilderFluent builder — payload(...), metadata(name, value).
DigestEventInbound DigestList — name, list id, per-entry payloads, timestamp, digest id.
DigestConfigOutbound DigestEntry.Config — maxTimeout, maxListSize, ackTimeout.
IdleTimeoutEventInbound IdleTimeoutNotification — list of expired TableEntrys, timestamp.
DropEventInternal drop event — reason, timestamp, parsed PacketIn (if any), message.
DropEvent.ReasonEnum: SUBSCRIBER_LAG / QUEUE_FULL / FILTERED.

Batch operations ​

ClassWhat it does
BatchBuilderMulti-update batch — insert(e) / modify(e) / delete(e) / execute().
WriteResultResult of BatchBuilder.execute() — submitted count, per-update failures.
UpdateFailureOne per rejected update — batch index, error code, message.

Exceptions ​

All extend P4RuntimeException; the hierarchy maps to where the failure happened.

ClassWhat it signals
P4RuntimeExceptionSealed parent.
P4ConnectionExceptionTransport / mastership / closed-switch failures.
P4ArbitrationLostSpecialised — primary denied (connect or re-claim).
P4PipelineExceptionP4Info / device-config / schema problems.
P4OperationExceptionDevice-side rejection of a Write or Read RPC.
ErrorCodeEnum mirroring the gRPC canonical codes (OK / INVALID_ARGUMENT / NOT_FOUND / ALREADY_EXISTS / UNIMPLEMENTED / ...).
OperationTypeEnum on P4OperationException — INSERT / MODIFY / DELETE / READ.

Value types ​

Small primitive wrappers used across the API.

ClassWhat it does
BytesCanonical-bytestring container; of(byte[]) constructor, equals/hashCode aware of the leading-zero convention.
Mac48-bit MAC address; fromBytes(byte[]) and ZERO constant.
Ip4IPv4 address; of(String) parses dotted-quad, toBytes() returns 4-byte.
Ip6IPv6 address; of(String) parses colon-hex, toBytes() returns 16-byte.
ElectionIdUnsigned 128-bit id; see Client lifecycle.

Authoritative reference ​

Everything above links to the standard Javadoc, which is generated from the source by the javadoc tool with the project's standard tag conventions (@since 1.0.0 / @since 1.5.0 markers indicate when each class or method was added; @implNote for non-normative implementation details). For the Maven Central jar coordinate see the Quick start.

Released under the Apache License 2.0.