8000 Add support for P4 Language · Issue #3890 · PrismJS/prism · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add support for P4 Language #3890

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
zhh2001 opened this issue Apr 14, 2025 · 0 comments
Open

Add support for P4 Language #3890

zhh2001 opened this issue Apr 14, 2025 · 0 comments

Comments

@zhh2001
Copy link
zhh2001 commented Apr 14, 2025

Language
P4, Programming Protocol-independent Packet Processors, https://p4.org
P4(Programming Protocol-independent Packet Processors) is a programming language for controlling packet forwarding planes in networking devices, such as routers and switches. In contrast to a general purpose language such as C or Python, P4 is a domain-specific language with a number of constructs optimized for network data forwarding. P4 is distributed as open-source, permissively licensed code, and is maintained by the P4 Project (formerly the P4 Language Consortium), a not-for-profit organization hosted by the Open Networking Foundation.

Additional resources
Just like the P4 language syntax highlighting provided by Github:

#include <core.p4>

typedef bit<16> etherType_t;
typedef bit<48> macAddr_t;

const etherType_t TYPE_IPV4 = 16w0x0800;

header ethernet_t {
    macAddr_t   dstAddr;
    macAddr_t   srcAddr;
    etherType_t etherType;
}

struct headers {
    ethernet_t ethernet;
}

register<bit<32>, bit<1>>(8) statistical_data;

action drop() {
    mark_to_drop(standard_metadata);
}

table ipv4_lpm {
    key = {
        hdr.ipv4.dstAddr: lpm;
    }
    actions = {
        ipv4_forward;
        drop;
        NoAction;
    }
    size = 1024;
    default_action = NoAction();
}

// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant
0