Tutorial: IPv4 Forwarding with V1model Architecture

March 16, 2026 · View on GitHub

This example runs a host-to-host UDP forwarding simulation through a single P4 switch using the V1model architecture. It is the baseline benchmark used in Section 5.1 of the paper to compare throughput and simulation time across p4sim, ns-3 bridge, and Mininet/BMv2.


Topology

[ Host 0 (10.1.1.1) ] ──── [ P4 Switch (V1model) ] ──── [ Host 1 (10.1.1.2) ]
  • 2 hosts, 1 P4 switch
  • Link type: CSMA
  • Traffic: UDP OnOff from Host 0 → Host 1

Scripts

FileDescription
p4-v1model-ipv4-forwarding.ccns-3 simulation script
simple_v1model.p4P4 program (V1model architecture)
flowtable_0.txtStatic flow table entries for the switch

How to Run

# Basic run (default: 1 Mbps, P4 switch)
./ns3 run p4-v1model-ipv4-forwarding

# With explicit options
./ns3 run "p4-v1model-ipv4-forwarding --model=0 --pktSize=1000 --appDataRate=10Mbps --pcap=true"

Parameters

ParameterDefaultDescription
model00 = P4 switch, 1 = ns-3 bridge device
pktSize1000Packet size in bytes
appDataRate1MbpsApplication sending rate (e.g., 100Mbps, 1Gbps)
pcapfalseEnable PCAP trace files
runnum1Run index for scripted parameter sweeps

To reproduce the paper benchmark (Section 5.1), sweep appDataRate from 1 Mbps to 10,000 Mbps with both --model=0 (p4sim) and --model=1 (ns-3 bridge) and record the reported throughput and wall-clock time.


Captured Output

(p4dev-python-venv) p4@p4:~/workdir/ns-3-dev-git$ ./ns3 run p4-v1model-ipv4-forwarding
[  0%] Building CXX object contrib/p4sim/CMakeFiles/libp4sim-obj.dir/model/p4-core-v1model.cc.o
[  0%] Linking CXX shared library ../../lib/libns3.39-p4sim-debug.so
[  0%] Building CXX object contrib/p4sim/examples/CMakeFiles/p4-v1model-ipv4-forwarding.dir/p4-v1model-ipv4-forwarding.cc.o
[  0%] Linking CXX executable ns3.39-p4-v1model-ipv4-forwarding-debug
*** Reading topology from file: .../simple_v1model/topo.txt with format: CsmaTopo
*** Host number: 2, Switch number: 1
Node IP and MAC addresses:
Node 0: IP = 10.1.1.1, MAC = 00:00:00:00:00:01
Node 1: IP = 10.1.1.2, MAC = 00:00:00:00:00:03
*** P4 switch configuration: .../simple_v1model/simple_v1model.json, .../flowtable_0.txt
Running simulation...
P4 switch 1 thrift port: 9090
Simulate Running time: 1834ms
Total Running time: 1872ms
Run successfully!
client_start_time: 3.02667  client_stop_time: 5.99733
sink_start_time:   3.03001  sink_stop_time:   5.99801
======================================
Final Simulation Results:
Total Transmitted Bytes: 1114000 bytes in time 2.97067
Total Received Bytes:    1113000 bytes in time 2.968
Final Transmitted Throughput: 3 Mbps
Final Received Throughput:    3 Mbps
======================================

Reading the output

FieldMeaning
Simulate Running timeWall-clock time for the ns-3 event loop — used in Figure 5
Total Running timeIncludes setup and teardown overhead
Final Received ThroughputApplication-layer throughput — used in Figure 4

Near-zero packet loss (1 packet in this run = 0.09%) is expected and acceptable.


PCAP Files (in this directory)

FileInterfaceDescription
p4-v1model-ipv4-forwarding-0-0.pcapHost 0 NICAll packets sent by Host 0
p4-v1model-ipv4-forwarding-1-0.pcapSwitch port 0Packets entering the switch from Host 0
p4-v1model-ipv4-forwarding-1-1.pcapSwitch port 1Packets leaving the switch toward Host 1
p4-v1model-ipv4-forwarding-2-0.pcapHost 1 NICAll packets received by Host 1

Open any PCAP in Wireshark to inspect the IPv4/UDP headers and verify forwarding correctness.


Connection to Paper

Paper sectionFigureHow to reproduce
Section 5.1 — IPv4 ForwardingFigure 4 (throughput)python3 plot/ipv4_forwarding_v1.py
Section 5.1 — IPv4 ForwardingFigure 5 (simulation time)python3 plot/ipv4_time_usage_v1.py