SPI and Extensions

The protocol infrastructure uses Java's ServiceLoader mechanism for extensibility. This allows protocol packs, analyzers, and custom backends to be discovered and loaded at runtime.

Specification Lifecycle Services

All configurable components follow the Spec → ResolvedSpec → RuntimeSpec lifecycle with corresponding SPI services:

// Pattern for all domain services
ResolvedSpec resolved = DomainService.resolve(spec, backendContext);
RuntimeSpec runtime = DomainService.build(resolved, streamContext);

PacketPolicyService

Resolves and builds packet policies:

public interface PacketPolicyService {
    
    static ResolvedPacketPolicy resolve(PacketPolicy policy, BackendContext backend);
    static RuntimePacketPolicy build(ResolvedPacketPolicy resolved, StreamContext stream);
}

Usage:

// Typically called internally by frontend
ResolvedPacketPolicy resolved = PacketPolicyService.resolve(
    stack.getPacketPolicy(), 
    backendContext);

RuntimePacketPolicy runtime = PacketPolicyService.build(
    resolved, 
    streamContext);

// Now ready for hot-path operations
Packet packet = runtime.acquire(hdr, data, descriptorType);

ProtocolStackService

Resolves protocol stacks to trees and builds processor instances:

Usage:

Pack-Level Protocol Discovery

Protocols are discovered at the pack (module) level via ProtocolProvider:

Implementing a Protocol Provider

Service Registration

Create file META-INF/services/com.slytechs.sdk.protocol.spi.ProtocolProvider:

Static Lookup Methods

Protocol Configuration Provider

Provides protocol configurations for the ProtocolStack:

Template Discovery

ProtocolTreeService provides named protocol tree templates optimized for different backends:

Available Templates

Template
Description
Use Case

default

Full protocol tree

General purpose

pcap

L2-L4 only, no L5+

jNetPcap

dpdk

Optimized for DPDK backend

jNetWorks with DPDK

ntapi

Optimized for Napatech

jNetWorks with NTAPI

Template Usage

Analyzer Plugins

Analyzers attach to processors and emit tokens. They are discovered via AnalyzerProvider:

Implementing an Analyzer Provider

Service Registration

Create file META-INF/services/com.slytechs.sdk.protocol.spi.AnalyzerProvider:

Bitmask Pruning

Analyzers are only instantiated if their tokens are subscribed:

Heuristics Plugins

Protocol heuristics detect protocols by payload inspection when standard routing (port numbers, protocol fields) is insufficient:

Heuristic Provider

Example: HTTP Detection Heuristic

Backend Context

Backend context provides capabilities and constraints for resolution:

Backend Processor Substitution

Backends can provide optimized processor implementations:

Custom Protocol Pack Example

Complete example of creating a custom protocol pack:

1. Define Protocol Configuration

2. Implement Protocol Provider

3. Implement Processor

4. Register Services

META-INF/services/com.slytechs.sdk.protocol.spi.ProtocolProvider:

5. Use in Application

Last updated