# omec-project/upf architecture

> Architecture diagram of the GitHub repository omec-project/upf, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/omec-project/upf
- Repository: https://github.com/omec-project/upf

## Overview

1. **Top-level split: control plane agent vs datapath**
   - The repository implements a 3GPP UPF with two major runtime pieces:
     - `pfcpiface`: a Go control-plane agent that speaks PFCP to the mobile core control plane.
     - BESS-based datapath: the packet-processing plane, built around the external BESS project.
   - The main architectural boundary is between PFCP/session management and packet forwarding. PFCP configures the datapath; the datapath handles user traffic.

2. **Northbound interface to the mobile core**
   - `cmd/pfcpiface/main.go` starts the PFCP agent.
   - The agent talks to SMF/SPGW-C over PFCP for association setup/release, heartbeats, session establishment/modification, and reports.
   - The repo also supports UPF-initiated PFCP association, so the agent can initiate the control connection as well as respond to it.

3. **PFCP message processing pipeline**
   - Inside `pfcpiface`, PFCP messages are parsed into domain objects for rules and session state.
   - The key rule types are PDR, FAR, QER, SDF filters, and PFDs, each with its own parser and session model.
   - This layer is responsible for turning protocol messages into internal session/rule representations before any datapath-specific translation happens.

4. **Session and state management**
   - Session state is maintained separately from the raw PFCP transport handling.
   - Files such as `sessions.go`, `sessions_store.go`, `local_store.go`, `session_pdr.go`, `session_far.go`, and `session_qer.go` indicate a persistent in-memory model for per-UE/per-session configuration.
   - Supporting components include UE IP pool management, F-TEID handling, node identity, and helpers for connection/message correlation.

5. **Datapath abstraction boundary**
   - `pfcpiface/datapath.go` defines the abstraction layer between the PFCP agent and the concrete datapath.
   - This is the key extensibility point: PFCP semantics are translated into a common internal API, then into datapath-specific commands.
   - The README notes that new datapaths can be added by implementing new plugins; the current implementation targets BESS.

6. **BESS southbound integration**
   - `pfcpiface/bess.go` and the generated `pfcpiface/bess_pb/*` protobuf bindings are the southbound control channel to BESS.
   - The PFCP agent programs BESS modules, ports, flows, and service chains through this interface.
   - This is where PFCP session rules become concrete forwarding behavior, QoS enforcement, NAT/routing behavior, and monitoring hooks in the datapath.

7. **Packet-processing capabilities in the datapath**
   - The BESS datapath supports N3/N4/N6/N9 interfaces, IPv4 routing, fragmentation/reassembly, UE NAT, branching/ULCL, DDN notification behavior, QoS rate limiting, and telemetry for per-flow latency/throughput.
   - The `conf/*.bess`, `conf/*.jsonc`, and related config files describe datapath pipelines and deployment variants for different interface counts or runtime modes.
   - This is the layer that actually forwards and transforms user packets; the Go agent does not process user-plane packets directly.

8. **Telemetry and operational visibility**
   - `pfcpiface/metrics` exports Prometheus metrics for PFCP and datapath behavior.
   - `pfcpiface/telemetry.go`, `web_service.go`, and `notifier.go` indicate additional operational surfaces for status/notifications.
   - The `conf/grafana/*` dashboards and `conf/prometheus.yml` show that Prometheus/Grafana are first-class observability dependencies for the system.

9. **Configuration and runtime profiles**
   - `pfcpiface/config.go` and the `conf` directory hold configuration for UPF behavior, datapath selection, port layouts, and simulation/testing profiles.
   - There are multiple BESS/CNDP/packet-generator configuration artifacts, suggesting the repository is organized around deploy-time composition rather than a single fixed topology.
   - `deployments/upf-k8s.yaml` provides a Kubernetes deployment boundary for running the UPF in cluster environments.

10. **Testing and simulation layers**
   - Unit tests live alongside the Go code in `pfcpiface/*_test.go`.
   - `test/integration` contains end-to-end tests that validate PFCP agent behavior against a datapath, with a fake BESS implementation in `pkg/fake_bess` for isolation.
   - `ptf/` is a separate packet-test harness for BESS-UPF, using Python, TRex, and PTF to verify actual packet forwarding behavior.
   - `conf/sim.py`, `conf/gtp_echo.py`, and related scripts support simulation and route-control workflows.

11. **Tooling and build outputs**
   - The project is primarily Go-based, with generated protobufs checked in for the BESS control protocol.
   - Docker is a major packaging boundary: the repo builds at least two images, `pfcpiface` and `bess`.
   - CI, linting, and repository hygiene are managed through GitHub Actions, golangci-lint, pre-commit, and spellcheck configs.

12. **How the data flow should look in a diagram**
   - Control-plane flow: SMF/SPGW-C → PFCP over N4 → `pfcpiface` → session/rule state → datapath adapter → BESS control plane.
   - User-plane flow: UE traffic → BESS datapath interfaces → BESS forwarding/NAT/QoS/routing pipeline → external network.
   - Observability flow: PFCP/datapath metrics → Prometheus → Grafana dashboards.
   - Test/validation flow: Go unit/integration tests and PTF/TRex tests validate the PFCP agent and datapath separately and together.

Main entry points: [`pfcpiface/pfcpiface.go`](https://github.com/omec-project/upf/blob/main/pfcpiface/pfcpiface.go) (PFCP core), [`pfcpiface/bess.go`](https://github.com/omec-project/upf/blob/main/pfcpiface/bess.go) (BESS control), [`conf/up4.bess`](https://github.com/omec-project/upf/blob/main/conf/up4.bess) (BESS pipeline), [`pfcpiface/metrics/prometheus.go`](https://github.com/omec-project/upf/blob/main/pfcpiface/metrics/prometheus.go) (Metrics)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_control["Control plane"]
  node_cmd_main["pfcpiface main<br/>Go entrypoint<br/>[main.go]"]
  node_pfcpiface_core["PFCP core<br/>Go service<br/>[pfcpiface.go]"]
  node_pfcp_messages["PFCP messages<br/>Parser/model layer<br/>[messages.go]"]
  node_pfcp_sessions[("Session store<br/>State management<br/>[sessions.go]")]
  node_rule_parsers["Rule parsers<br/>PFCP rule parsing<br/>[parse_pdr.go]"]
  node_rule_state[("Rule state<br/>Session model<br/>[session_pdr.go]")]
  node_upf_model["UPF model<br/>Domain helpers<br/>[upf.go]"]
end

subgraph group_datapath["Datapath"]
  node_datapath_api["Datapath API<br/>Interface boundary<br/>[datapath.go]"]
  node_bess_ctrl["BESS control<br/>Southbound adapter<br/>[bess.go]"]
  node_bess_proto["BESS protos<br/>Generated bindings<br/>[bess_msg.pb.go]"]
  node_bess_pipeline["BESS pipeline<br/>Packet pipeline<br/>[up4.bess]"]
end

subgraph group_ops["Observability"]
  node_metrics_layer["Metrics<br/>Prometheus export<br/>[prometheus.go]"]
  node_telemetry_layer["Telemetry<br/>Operational hooks<br/>[telemetry.go]"]
  node_grafana_conf["Dashboards<br/>Monitoring config<br/>[upf-custom.json]"]
end

subgraph group_test["Validation"]
  node_fake_bess["Fake BESS<br/>Test double<br/>[fake_bess.go]"]
  node_integration_tests["Integration tests<br/>Go test suite<br/>[basic_test.go]"]
  node_ptf_harness["PTF harness<br/>Packet test suite<br/>[check_rules.py]"]
end

subgraph group_tooling["Build & deploy"]
  node_conf_runtime["Runtime config<br/>Deployment config<br/>[upf.jsonc]"]
  node_deploy_k8s["K8s deploy<br/>Deployment manifest<br/>[upf-k8s.yaml]"]
  node_sim_tools["Sim tools<br/>Python utilities<br/>[sim.py]"]
end

node_cmd_main -->|"starts"| node_pfcpiface_core
node_pfcpiface_core -->|"parses"| node_pfcp_messages
node_pfcp_messages -->|"extracts rules"| node_rule_parsers
node_rule_parsers -->|"builds"| node_rule_state
node_pfcpiface_core -->|"stores"| node_pfcp_sessions
node_pfcp_sessions -->|"uses"| node_upf_model
node_pfcpiface_core -->|"targets"| node_datapath_api
node_datapath_api -->|"implements"| node_bess_ctrl
node_bess_ctrl -->|"RPCs"| node_bess_proto
node_bess_ctrl -->|"programs"| node_bess_pipeline
node_bess_pipeline -->|"configured by"| node_conf_runtime
node_pfcpiface_core -->|"exports"| node_metrics_layer
node_telemetry_layer -->|"feeds"| node_metrics_layer
node_grafana_conf -->|"visualizes"| node_metrics_layer
node_deploy_k8s -->|"deploys"| node_conf_runtime
node_integration_tests -->|"isolates"| node_fake_bess
node_integration_tests -->|"verifies"| node_pfcpiface_core
node_ptf_harness -->|"validates"| node_bess_pipeline
node_sim_tools -->|"drives"| node_conf_runtime
node_pfcpiface_core -->|"reports"| node_telemetry_layer

click node_cmd_main "https://github.com/omec-project/upf/blob/main/cmd/pfcpiface/main.go"
click node_pfcpiface_core "https://github.com/omec-project/upf/blob/main/pfcpiface/pfcpiface.go"
click node_pfcp_messages "https://github.com/omec-project/upf/blob/main/pfcpiface/messages.go"
click node_pfcp_sessions "https://github.com/omec-project/upf/blob/main/pfcpiface/sessions.go"
click node_rule_parsers "https://github.com/omec-project/upf/blob/main/pfcpiface/parse_pdr.go"
click node_rule_state "https://github.com/omec-project/upf/blob/main/pfcpiface/session_pdr.go"
click node_datapath_api "https://github.com/omec-project/upf/blob/main/pfcpiface/datapath.go"
click node_bess_ctrl "https://github.com/omec-project/upf/blob/main/pfcpiface/bess.go"
click node_bess_proto "https://github.com/omec-project/upf/blob/main/pfcpiface/bess_pb/bess_msg.pb.go"
click node_upf_model "https://github.com/omec-project/upf/blob/main/pfcpiface/upf.go"
click node_metrics_layer "https://github.com/omec-project/upf/blob/main/pfcpiface/metrics/prometheus.go"
click node_telemetry_layer "https://github.com/omec-project/upf/blob/main/pfcpiface/telemetry.go"
click node_grafana_conf "https://github.com/omec-project/upf/blob/main/conf/grafana/upf-custom.json"
click node_conf_runtime "https://github.com/omec-project/upf/blob/main/conf/upf.jsonc"
click node_bess_pipeline "https://github.com/omec-project/upf/blob/main/conf/up4.bess"
click node_deploy_k8s "https://github.com/omec-project/upf/blob/main/deployments/upf-k8s.yaml"
click node_fake_bess "https://github.com/omec-project/upf/blob/main/pkg/fake_bess/fake_bess.go"
click node_integration_tests "https://github.com/omec-project/upf/blob/main/test/integration/basic_test.go"
click node_ptf_harness "https://github.com/omec-project/upf/blob/main/ptf/tests/unary/check_rules.py"
click node_sim_tools "https://github.com/omec-project/upf/blob/main/conf/sim.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cmd_main,node_pfcpiface_core,node_pfcp_messages,node_pfcp_sessions,node_rule_parsers,node_rule_state,node_upf_model toneBlue
class node_datapath_api,node_bess_ctrl,node_bess_proto,node_bess_pipeline toneAmber
class node_metrics_layer,node_telemetry_layer,node_grafana_conf toneMint
class node_fake_bess,node_integration_tests,node_ptf_harness toneRose
class node_conf_runtime,node_deploy_k8s,node_sim_tools toneIndigo
```

## Components

### Control plane

PFCP agent and session management

- [pfcpiface main](https://github.com/omec-project/upf/blob/main/cmd/pfcpiface/main.go): Go entrypoint · Starts the PFCP agent runtime. · `cmd/pfcpiface/main.go`
- [PFCP core](https://github.com/omec-project/upf/blob/main/pfcpiface/pfcpiface.go): Go service · Top-level PFCP control-plane orchestration. · `pfcpiface/pfcpiface.go`
- [PFCP messages](https://github.com/omec-project/upf/blob/main/pfcpiface/messages.go): Parser/model layer · Parses PFCP messages into domain objects. · `pfcpiface/messages.go`
- [Session store](https://github.com/omec-project/upf/blob/main/pfcpiface/sessions.go): State management · Maintains per-session and per-UE PFCP state. · `pfcpiface/sessions.go`
- [Rule parsers](https://github.com/omec-project/upf/blob/main/pfcpiface/parse_pdr.go): PFCP rule parsing · Parses PDR, FAR, QER, SDF, and PFD inputs. · `pfcpiface/parse_pdr.go`
- [Rule state](https://github.com/omec-project/upf/blob/main/pfcpiface/session_pdr.go): Session model · Represents session-local PDR/FAR/QER state. · `pfcpiface/session_pdr.go`
- [UPF model](https://github.com/omec-project/upf/blob/main/pfcpiface/upf.go): Domain helpers · UPF identity, F-TEID, IP pools, and node/session helpers. · `pfcpiface/upf.go`

### Datapath

BESS integration and packet forwarding pipeline

- [Datapath API](https://github.com/omec-project/upf/blob/main/pfcpiface/datapath.go): Interface boundary · Abstracts datapath operations behind a common API. · `pfcpiface/datapath.go`
- [BESS control](https://github.com/omec-project/upf/blob/main/pfcpiface/bess.go): Southbound adapter · Programs the BESS datapath from PFCP intent. · `pfcpiface/bess.go`
- [BESS protos](https://github.com/omec-project/upf/blob/main/pfcpiface/bess_pb/bess_msg.pb.go): Generated bindings · Checked-in protobuf bindings for BESS RPCs. · `pfcpiface/bess_pb/bess_msg.pb.go`
- [BESS pipeline](https://github.com/omec-project/upf/blob/main/conf/up4.bess): Packet pipeline · Datapath pipeline definitions for interfaces and forwarding behavior. · `conf/up4.bess`

### Observability

Metrics, telemetry, and dashboards

- [Metrics](https://github.com/omec-project/upf/blob/main/pfcpiface/metrics/prometheus.go): Prometheus export · Exports PFCP and datapath metrics. · `pfcpiface/metrics/prometheus.go`
- [Telemetry](https://github.com/omec-project/upf/blob/main/pfcpiface/telemetry.go): Operational hooks · Status, notifications, and web-facing operational surfaces. · `pfcpiface/telemetry.go`
- [Dashboards](https://github.com/omec-project/upf/blob/main/conf/grafana/upf-custom.json): Monitoring config · Prometheus datasource and Grafana dashboard definitions. · `conf/grafana/upf-custom.json`

### Validation

Unit, integration, and packet-level testing

- [Fake BESS](https://github.com/omec-project/upf/blob/main/pkg/fake_bess/fake_bess.go): Test double · In-memory BESS replacement for integration tests. · `pkg/fake_bess/fake_bess.go`
- [Integration tests](https://github.com/omec-project/upf/blob/main/test/integration/basic_test.go): Go test suite · End-to-end PFCP and datapath validation. · `test/integration/basic_test.go`
- [PTF harness](https://github.com/omec-project/upf/blob/main/ptf/tests/unary/check_rules.py): Packet test suite · Python/TRex/PTF packet-forwarding validation. · `ptf/tests/unary/check_rules.py`

### Build & deploy

Packaging, configuration, and runtime profiles

- [Runtime config](https://github.com/omec-project/upf/blob/main/conf/upf.jsonc): Deployment config · UPF and datapath configuration profiles. · `conf/upf.jsonc`
- [K8s deploy](https://github.com/omec-project/upf/blob/main/deployments/upf-k8s.yaml): Deployment manifest · Containerized UPF deployment in Kubernetes. · `deployments/upf-k8s.yaml`
- [Sim tools](https://github.com/omec-project/upf/blob/main/conf/sim.py): Python utilities · Simulation and route-control scripts. · `conf/sim.py`

## Connections

- pfcpiface main → PFCP core: starts · Entrypoint launches the PFCP control agent.
- PFCP core → PFCP messages: parses · PFCP transport is decoded into internal message objects.
- PFCP messages → Rule parsers: extracts rules · Rule-specific parsers derive PDR/FAR/QER/SDF/PFD state.
- Rule parsers → Rule state: builds · Parsed rules become session-local state models.
- PFCP core → Session store: stores · Sessions are created, modified, and released in state.
- Session store → UPF model: uses · Session state depends on UE/IP/F-TEID/node helpers.
- PFCP core → Datapath API: targets · Control-plane actions are translated into datapath operations.
- Datapath API → BESS control: implements · Current concrete datapath implementation is BESS.
- BESS control → BESS protos: RPCs · BESS programming uses generated protobuf service bindings.
- BESS control → BESS pipeline: programs · PFCP intent becomes packet-forwarding pipeline state.
- BESS pipeline → Runtime config: configured by · Deployment/runtime profiles parameterize the datapath pipeline.
- PFCP core → Metrics: exports · PFCP and datapath behavior is exported as metrics.
- Telemetry → Metrics: feeds · Telemetry hooks surface operational data through metrics.
- Dashboards → Metrics: visualizes · Dashboards consume Prometheus metrics.
- K8s deploy → Runtime config: deploys · Kubernetes manifests bind runtime configuration into the deployment.
- Integration tests → Fake BESS: isolates · Integration tests use a fake BESS implementation.
- Integration tests → PFCP core: verifies · Tests exercise PFCP agent behavior end to end.
- PTF harness → BESS pipeline: validates · Packet tests validate actual forwarding behavior.
- Sim tools → Runtime config: drives · Simulation scripts use the runtime configuration profiles.
- PFCP core → Telemetry: reports · Operational notifications and web surfaces come from the control plane.
