Hello Packet Example
This example demonstrates the most basic pipeline in the DOCA target architecture. It consists of:
Match on L2 source MAC address
Action to either forward to a P4 port ID, drop, or no action
The following #includes are required for every DPL program. They define the DOCA target architecture. In particular, they contain things like the default DOCA parser, default headers struct, etc. Note that the symbol names are prefixed with "nv_" and are reserved for NVIDIA DOCA TA usage.
#include <doca_model.p4>
#include <doca_headers.p4>
#include <doca_externs.p4>
#include <doca_parser.p4>
The DOCA TA features a single control, which requires a headers struct and standard metadata. User metadata and packet out metadata, defined by the user, are optional.
control hello_packet(
inout nv_headers_t headers,
in nv_standard_metadata_t std_meta,
inout nv_empty_metadata_t user_meta,
inout nv_empty_metadata_t pkt_out_meta
) {
action drop() {
nv_drop();
}
action forward(bit<32
> port) {
nv_send_to_port(port);
}
table forward_table {
key = {
headers.ethernet.dst_addr : exact;
}
actions = {
drop;
forward;
NoAction;
}
default_action = forward(3
);
const
entries = {
(48w0x001111111111) : forward(1
);
(48w0x002222222222) : forward(2
);
(48w0x00dddddddddd) : drop();
(48w0x00aaaaaaaaaa) : NoAction();
(48w0x00bbbbbbbbbb) : NoAction();
}
}
apply {
forward_table.apply();
}
}
Finally, the main package must be instantiated:
NvDocaPipeline(
nv_fixed_parser(),
hello_packet()
) main;
See below for the complete DPL example.
/*
* SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: LicenseRef-NvidiaProprietary
*
* NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
* property and proprietary rights in and to this material, related
* documentation and any modifications thereto. Any use, reproduction,
* disclosure or distribution of this material and related documentation
* without an express license agreement from NVIDIA CORPORATION or
* its affiliates is strictly prohibited.
*/
#include <doca_model.p4>
#include <doca_headers.p4>
#include <doca_externs.p4>
#include <doca_parser.p4>
/*
* This basic application demonstrates a simple match/action pipeline using NVIDIA
* DOCA Target Architecture.
* - Match on destination MAC address
* - Forward or drop the packet
*/
control hello_packet(
inout nv_headers_t headers,
in nv_standard_metadata_t std_meta,
inout nv_empty_metadata_t user_meta,
inout nv_empty_metadata_t pkt_out_meta
) {
action drop() {
nv_drop();
}
action forward(bit<32> port) {
nv_send_to_port(port);
}
table forward_table {
key = {
headers.ethernet.dst_addr : exact;
}
actions = {
drop;
forward;
NoAction;
}
default_action = forward(3);
const
entries = {
(48w0x001111111111) : forward(1);
(48w0x002222222222) : forward(2);
(48w0x00dddddddddd) : drop();
(48w0x00aaaaaaaaaa) : NoAction();
(48w0x00bbbbbbbbbb) : NoAction();
}
}
apply {
forward_table.apply();
}
}
NvDocaPipeline(
nv_fixed_parser(),
hello_packet()
) main;