How p4lang/behavioral-model works
bmv2 is a C++ reference software switch that interprets compiler-generated P4 JSON to process packets, and provides target variants and control-plane interfaces for development and debugging. The principal workflow is packet reception, parsing, ingress and egress P4 control flow, deparsing, and transmission. The graph also shows configuration loading, target runtimes, and debugging/observation capabilities. Workflow details are evidenced by the sampled simple-router implementation; other target and service wiring is included only where documented or shown in sampled entry points.
Main entry points: simple_switch.cpp Simple switch · server.cpp Thrift runtime · pipeline.cpp P4 pipeline · queue.h Packet queues
Components 20
Packet processing
- Switch core
src/bm_sim/switch.cpp - Packet and PHV
src/bm_sim/packet.cpp - P4 parser
src/bm_sim/parser.cpp - P4 pipeline
src/bm_sim/pipeline.cpp - P4 deparser
src/bm_sim/deparser.cpp - Packet queues
include/bm/bm_sim/queue.h
P4 model
- P4 object loader
src/bm_sim/P4Objects.cpp - Match-action tables
src/bm_sim/match_tables.cpp - Stateful resources
src/bm_sim/stateful.cpp - Multicast replication
src/bm_sim/simple_pre.cpp
Switch targets
- Simple switch
targets/simple_switch/simple_switch.cpp - gRPC switch
targets/simple_switch_grpc/main.cpp - PSA switch
targets/psa_switch/main.cpp - PNA NIC
targets/pna_nic/main.cpp
Control plane
- Thrift runtime
src/bm_runtime/server.cpp - PI runtime
PI/src/pi.cpp
Debugging
- Remote debugger
src/bm_sim/debugger.cpp - Event logger
src/bm_sim/event_logger.cpp
Other components
- Packet ports
- P4 JSON
Connections 22
- Packet ports → Simple switch: delivers packets
- Simple switch → Packet queues: enqueues packets
- Packet queues → Packet and PHV: supplies packets
- Simple switch → P4 parser: parses packets
- P4 parser → Packet and PHV: populates headers
- Simple switch → P4 pipeline: applies control flow
- P4 pipeline → Match-action tables: looks up entries
- Match-action tables → Stateful resources: uses resources
- Simple switch → P4 deparser: deparses packets
- P4 deparser → Packet queues: queues output
- Simple switch → Packet ports: transmits packets
- P4 JSON → P4 object loader: configures model
- P4 object loader → Switch core: loads P4 objects
- Simple switch → Thrift runtime: starts service
- gRPC switch → Thrift runtime: starts service
- PSA switch → Thrift runtime: starts service
- PNA NIC → Thrift runtime: starts service
- Thrift runtime → Switch core: controls switch
- PI runtime → Switch core: implements control API
- Simple switch → Multicast replication: supports multicast
- P4 pipeline → Remote debugger: notifies control flow
- P4 pipeline → Event logger: records events