Documentation
¶
Index ¶
- Constants
- Variables
- func ClampBatchSize(n uint32) uint32
- func MapLabeler(fullMethod string, req any) metrics.Labels
- func MapStatsToProto(stats mapStats) *fwstatemappb.MapStats
- func NewMetricsFactory(extra ...grpcmetrics.Option) grpcmetrics.Factory
- func ResolveCreateWorkerCount(workerCount uint32, dpWorkerCount func() uint32) (uint16, error)
- func ResolveReadIndex(backward bool, index int64) (int64, error)
- func ValidateMapName(name string) error
- func ValidateWorkerCount(workerCount uint32) error
- type FWStateMap
- type FWStateMapService
- func (m *FWStateMapService) CreateMap(ctx context.Context, req *fwstatemappb.CreateMapRequest) (*fwstatemappb.CreateMapResponse, error)
- func (m *FWStateMapService) DeleteMap(ctx context.Context, req *fwstatemappb.DeleteMapRequest) (*fwstatemappb.DeleteMapResponse, error)
- func (m *FWStateMapService) GetMapStats(ctx context.Context, req *fwstatemappb.GetMapStatsRequest) (*fwstatemappb.GetMapStatsResponse, error)
- func (m *FWStateMapService) InsertLayer(ctx context.Context, req *fwstatemappb.InsertLayerRequest) (*fwstatemappb.InsertLayerResponse, error)
- func (m *FWStateMapService) ListEntries(ctx context.Context, req *fwstatemappb.ListEntriesRequest) (*fwstatemappb.ListEntriesResponse, error)
- func (m *FWStateMapService) ListMaps(ctx context.Context, req *fwstatemappb.ListMapsRequest) (*fwstatemappb.ListMapsResponse, error)
- func (m *FWStateMapService) Metrics(tags ...*commonpb.MetricTag) ([]*commonpb.Metric, error)
- func (m *FWStateMapService) ReclaimDeferred()
- func (m *FWStateMapService) ReclaimStaleLayers(reclaimer MapLayerReclaimer, mapCP cfwstate.MapObjectConfig, now uint64)
- func (m *FWStateMapService) Register(server *grpc.Server)
- func (m *FWStateMapService) ServicesNames() []string
- func (m *FWStateMapService) UnaryServerInterceptor() grpc.UnaryServerInterceptor
- type MapLayerReclaimer
- type MapOption
Constants ¶
const ( // DefaultListEntriesBatchSize is the batch size used when the caller // sends zero in the request. DefaultListEntriesBatchSize uint32 = 100 // MaxListEntriesBatchSize caps the number of entries fetched per // ListEntries round-trip to prevent unbounded allocation under the // service mutex. MaxListEntriesBatchSize uint32 = 10000 )
Variables ¶
var ServiceName = fwstatemappb.FWStateMapService_ServiceDesc.ServiceName
ServiceName is the fully-qualified gRPC service name for the fwstate-map management service, derived from the generated service descriptor.
Functions ¶
func ClampBatchSize ¶
ClampBatchSize returns a batch size that is within the allowed range: zero is replaced with DefaultListEntriesBatchSize, and values above MaxListEntriesBatchSize are clamped to MaxListEntriesBatchSize.
func MapLabeler ¶
MapLabeler extracts the map name from map-scoped requests for gRPC metrics labeling.
func MapStatsToProto ¶
func MapStatsToProto(stats mapStats) *fwstatemappb.MapStats
MapStatsToProto converts bindings-level map stats into the proto form.
The stats describe the active head layer only (fwmap_get_stats walks one layer; only layer_count spans the chain), so the note says so — the values must not be presented as map totals after a rotation.
func NewMetricsFactory ¶
func NewMetricsFactory(extra ...grpcmetrics.Option) grpcmetrics.Factory
NewMetricsFactory returns a grpcmetrics.Factory scoped to the FWStateMapService.
func ResolveCreateWorkerCount ¶
ResolveCreateWorkerCount settles the per-worker sizing for CreateMap and InsertLayer, deriving a zero count from the dataplane's worker count and rejecting an explicit mismatch.
func ResolveReadIndex ¶
ResolveReadIndex rejects negative forward cursors and maps a zero backward cursor to the scan's upper bound.
func ValidateMapName ¶
ValidateMapName rejects names that cannot round-trip through the fixed-size C object registry.
func ValidateWorkerCount ¶
ValidateWorkerCount rejects zero and out-of-range worker_count values.
Types ¶
type FWStateMap ¶
type FWStateMap struct {
// contains filtered or unexported fields
}
FWStateMap manages a standalone named fwstate-map object in shared memory.
func (*FWStateMap) Config ¶
func (m *FWStateMap) Config() *cfwstate.MapObjectConfig
Config returns the underlying map object config handle.
type FWStateMapService ¶
type FWStateMapService struct {
fwstatemappb.UnimplementedFWStateMapServiceServer
// contains filtered or unexported fields
}
FWStateMapService implements the gRPC service for standalone named fwstate-map management.
func NewFWStateMapService ¶
func NewFWStateMapService( agent *ffi.Agent, options ...MapOption, ) *FWStateMapService
NewFWStateMapService creates a new FWStateMapService.
func NewFWStateMapServiceForTest ¶
func NewFWStateMapServiceForTest( barrier func(cfwstate.MapObjectConfig) error, options ...MapOption, ) *FWStateMapService
NewFWStateMapServiceForTest creates an FWStateMapService without a live agent, for exercising stale-layer reclamation and the in-memory map registry.
barrier may be nil when the test does not exercise stale-layer reclamation. A logger is supplied via the options pattern (WithLog); it defaults to a no-op logger when omitted.
func (*FWStateMapService) CreateMap ¶
func (m *FWStateMapService) CreateMap( ctx context.Context, req *fwstatemappb.CreateMapRequest, ) (*fwstatemappb.CreateMapResponse, error)
CreateMap creates a new named fwstate-map for one address family and publishes it to the dataplane.
func (*FWStateMapService) DeleteMap ¶
func (m *FWStateMapService) DeleteMap( ctx context.Context, req *fwstatemappb.DeleteMapRequest, ) (*fwstatemappb.DeleteMapResponse, error)
DeleteMap removes a named fwstate-map.
Deletion is refused at the config level while any published module config — an fwstate or ACL module of any agent on this instance — declares a link to the name: with the object gone, building that module's execution context would fail and wedge every later config change. Updating or deleting the linking module unpins the map, after which deletion succeeds.
func (*FWStateMapService) GetMapStats ¶
func (m *FWStateMapService) GetMapStats( ctx context.Context, req *fwstatemappb.GetMapStatsRequest, ) (*fwstatemappb.GetMapStatsResponse, error)
GetMapStats returns statistics for the single fwtable of a named fwstate-map.
func (*FWStateMapService) InsertLayer ¶
func (m *FWStateMapService) InsertLayer( ctx context.Context, req *fwstatemappb.InsertLayerRequest, ) (*fwstatemappb.InsertLayerResponse, error)
InsertLayer inserts a new layer into the fwtable chain of a named fwstate-map.
The insert and the stale-layer reclamation are separate routines bracketed by config generation updates: the new layer becomes the active head, a first published generation that every worker advanced past waits out inserts still targeting the previous head, expired tails are unlinked, and a second generation gates the release of the unlinked layers. mu stays held across both.
func (*FWStateMapService) ListEntries ¶
func (m *FWStateMapService) ListEntries( ctx context.Context, req *fwstatemappb.ListEntriesRequest, ) (*fwstatemappb.ListEntriesResponse, error)
ListEntries reads one cursor batch of entries from a named fwstate-map's fwtable. The batch protocol is stateless: the request carries the full cursor, and the response's index feeds the next call until has_more is false.
func (*FWStateMapService) ListMaps ¶
func (m *FWStateMapService) ListMaps( ctx context.Context, req *fwstatemappb.ListMapsRequest, ) (*fwstatemappb.ListMapsResponse, error)
ListMaps returns the names of all registered fwstate-map objects, with each map's address family alongside its name.
func (*FWStateMapService) Metrics ¶
Metrics returns the map service's metrics matching tags: gauge series derived from each live map's table statistics, plus the gRPC series its interceptor records.
The gRPC series carry the map service's own service and method labels; the module's metrics RPC aggregates them with the fwstate module metrics so map RPC traffic is reachable from a single endpoint.
func (*FWStateMapService) ReclaimDeferred ¶
func (m *FWStateMapService) ReclaimDeferred()
ReclaimDeferred retries every deferred map object, dropping the ones whose generations have drained and keeping the rest deferred. It is the reclamation handler for this service's superseded objects; the service itself runs it after each successful delete, and anything else may call it at any time.
func (*FWStateMapService) ReclaimStaleLayers ¶
func (m *FWStateMapService) ReclaimStaleLayers( reclaimer MapLayerReclaimer, mapCP cfwstate.MapObjectConfig, now uint64, )
ReclaimStaleLayers waits out in-flight inserts, unlinks expired layers, advances every dataplane worker past a new config generation, then frees the unlinked layers.
The first barrier is the rotation grace period: a worker that loaded the previous head before a layer insert published the new one may still be inside fwtable_insert on that layer, before its deadline is visible. Deciding expiry while such an insert is in flight can unlink the layer as an expired tail; the worker then completes into a layer no reader reaches, silently losing the synchronized state. Publishing a generation and waiting for every worker to advance proves those inserts finished, so the unlink decision sees final deadlines.
UnlinkStaleLayers then atomically moves stale layers from the active chain to the fwtable's stale chain so new walks skip them, but a worker already mid-chain-walk can still be reading a just-unlinked layer. A second barrier proves no in-flight walk can touch the unlinked memory; only then does FreeStaleLayers release it.
If either barrier fails the parked layers stay allocated and are freed by a later round after a successful barrier — a rare leak, never a use-after-free. The caller must hold mu because unlink mutates the shared map head chain. now is real-time nanoseconds, matching the domain the dataplane stamps layer deadlines in.
func (*FWStateMapService) Register ¶
func (m *FWStateMapService) Register(server *grpc.Server)
Register registers the map service on the given gRPC server.
func (*FWStateMapService) ServicesNames ¶
func (m *FWStateMapService) ServicesNames() []string
ServicesNames returns the gRPC service names this controlplane serves.
func (*FWStateMapService) UnaryServerInterceptor ¶
func (m *FWStateMapService) UnaryServerInterceptor() grpc.UnaryServerInterceptor
UnaryServerInterceptor returns the service's gRPC metrics interceptor, or nil when metrics are not configured.
type MapLayerReclaimer ¶
MapLayerReclaimer parks and releases a fwtable's stale layers around the generation barrier.
cfwstate.MapObjectConfig satisfies this interface; the seam lets unit tests record reclamation calls without a live shared-memory handle.
type MapOption ¶
type MapOption func(*mapOptions)
MapOption configures an FWStateMapService.
func WithMetrics ¶
func WithMetrics(factory grpcmetrics.Factory) MapOption
WithMetrics enables collection of gRPC call metrics for the map service using the supplied factory.