当前位置:网站首页>First acquaintance with P4 language
First acquaintance with P4 language
2022-07-02 03:57:00 【Not fat xiaopangqian】
P4 Way of learning
Record yourself P4 Some simple things learned during the experiment P4 knowledge
Concept
- P4 The full name is Programming Protocol-independent Packet Processor, That is, a language for programming protocol independent packet processors
- The so-called irrelevant to the agreement , That is to realize a new network protocol according to the needs of users
- Define the data surface you want , Then through the southbound agreement (openFlow) Add stream table entry
technological process
- P4 The process is shown in the figure below , When packets enter the switch , First, parse the packet header , then ingress To deal with , Finally, the packet is forwarded
- P4 What I write is how to deal with data packets

Package parsing
- Package parsing is The step of extracting the data we want in the data message
PS:( The engineer reminded me ) What is extracted is extracted later according to the sequence of messages , A pointer points to the position where the message has been extracted - The extracted part , It's wrong to extract again
such as , I had already extracted the packet IPv4 The head of , Contains the purpose IP Address , I want to regard it as four 8 Bit character extraction , You can't write another extraction destination address , I made this mistake
Examples are as follows , demand : Aim IP The address resolves to four 8 Bit characters
The code is as follows :
// modify IPv4 Of header
header ipv4_h {
bit<4> version;
bit<4> ihl;
bit<8> diffserv;
bit<16> total_len;
bit<16> identification;
bit<3> flags;
bit<13> frag_offset;
bit<8> ttl;
bit<8> protocol;
bit<16> hdr_checksum;
ipv4_addr_t src_addr;
// ipv4_addr_t dst_addr;
bit<8> ch1;
bit<8> ch2;
bit<8> ch3;
bit<8> ch4;
}
// Package parsing logic part
parser SwitchIngressParser(
packet_in pkt,
out header_t hdr,
out metadata_t ig_md,
out ingress_intrinsic_metadata_t ig_intr_md) {
// Parser from start The state starts execution and ends , among reject or accept Indicates that the end state has been reached
// transition Indicates a transition to another state
state start {
pkt.extract(ig_intr_md);
pkt.advance(PORT_METADATA_SIZE);
transition parse_ethernet;
}
state parse_ethernet {
pkt.extract(hdr.ethernet);
transition parse_ipv4;
}
// The last statement of the parser state is optional transition sentence , Transfer control to another state , Probably accept perhaps reject
state parse_ipv4 {
pkt.extract(hdr.ipv4);
transition accept;
}
}
Write a table and look it up
- Write a watch , The table includes the following sections
- Table name
- key Value and matching type , The matching types are exact、ternary、lpm Three
- actions, Include all possible action
- Define the default action
- The size of the table
table tableName {
key = {
a : exact; // keyword a Is the exact match
b : ternary; // keyword b yes ternary type
}
actions = {
get_value; // Include all possible actions
}
size=1024; // The size of the table
}
- Look up the table
- A table can only be checked once , A table corresponds to a match-action unit( Match the action unit )
- To find a table multiple times , It needs to be instantiated many times , That is, write multiple tables with different names
- Look up the table in apply Carry out inside
apply {
// To operate
// Look up the table
tableName.apply();
}
- actions
( I feel that I can only assign values …)- Only straight-line Code
- There are no conditional statements or expressions
Package package
Not yet understood …
Other
- switch
about switch sentence , The expression must be t.apply().action_run(), All labels must be table actions t, Or is it default - select
Select expression select Compare the extracted header field with a set of constants
Reference resources
边栏推荐
- 一天上手Aurora 8B/10B IP核(5)----从Framing接口的官方例程学起
- 毕设-基于SSM电影院购票系统
- leetcode-1380. Lucky number in matrix
- 傅里叶级数
- 《动手学深度学习》(二)-- 多层感知机
- The 8th Blue Bridge Cup single chip microcomputer provincial competition
- [ibdfe] matlab simulation of frequency domain equalization based on ibdfe
- Imageai installation
- Go variables and constants
- 【人员密度检测】基于形态学处理和GRNN网络的人员密度检测matlab仿真
猜你喜欢

How should the team choose the feature branch development mode or trunk development mode?
![[yolo3d]: real time detection of end-to-end 3D point cloud input](/img/5e/f17960d302f663db75ad82ae0fd70f.jpg)
[yolo3d]: real time detection of end-to-end 3D point cloud input

The original author is out! Faker. JS has been controlled by the community..

【leetcode】34. Find the first and last positions of elements in a sorted array

Opencv learning example code 3.2.4 LUT

蓝桥杯单片机省赛第十二届第一场

【小技巧】使用matlab GUI以对话框模式读取文件

蓝桥杯单片机省赛第七届

Visual slam Lecture 3 -- Lie groups and Lie Algebras

Demonstration description of integrated base scheme
随机推荐
Interface debugging tool simulates post upload file - apipost
C language: examples of logical operation and judgment selection structure
ImageAI安装
VS2010插件NuGet
The 8th Blue Bridge Cup single chip microcomputer provincial competition
潘多拉 IOT 开发板学习(RT-Thread)—— 实验1 LED 闪烁实验(学习笔记)
蓝桥杯单片机省赛第十二届第二场
leetcode-1380. Lucky number in matrix
集成底座方案演示说明
Oracle common SQL
Which product of anti-cancer insurance is better?
Go language introduction
go 变量与常量
pip 安装第三方库
[untitled]
Jetpack's livedata extension mediatorlivedata
[untitled]
高性能 低功耗Cortex-A53核心板 | i.MX8M Mini
5g era is coming in an all-round way, talking about the past and present life of mobile communication
Basic syntax of unity script (8) - collaborative program and destruction method