当前位置:网站首页>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
边栏推荐
- How should the team choose the feature branch development mode or trunk development mode?
- Introduction to Robotics II. Forward kinematics, MDH method
- 高性能 低功耗Cortex-A53核心板 | i.MX8M Mini
- regular expression
- Cloud service selection of enterprises: comparative analysis of SaaS, PAAS and IAAs
- 5g era is coming in an all-round way, talking about the past and present life of mobile communication
- Where can I buy cancer insurance? Which product is better?
- 跳出舒适区,5年点工转型自动化测试工程师,我只用了3个月时间
- A thorough understanding of the development of scorecards - the determination of Y (Vintage analysis, rolling rate analysis, etc.)
- The first game of the 11th provincial single chip microcomputer competition of the Blue Bridge Cup
猜你喜欢

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

Homework in Chapter 3 of slam course of dark blue vision -- derivative application of T6 common functions

【IBDFE】基于IBDFE的频域均衡matlab仿真

PR zero foundation introductory guide note 2

蓝桥杯单片机省赛第八届

文档声明与字符编码

蓝桥杯单片机省赛第七届

集成底座方案演示说明

JVM知识点

Analysis of the overall design principle of Nacos configuration center (persistence, clustering, information synchronization)
随机推荐
Where can I buy cancer insurance? Which product is better?
[Li Kou brush questions] 15 Sum of three numbers (double pointer); 17. Letter combination of phone number (recursive backtracking)
Opencv learning example code 3.2.4 LUT
文档声明与字符编码
Analysis of the overall design principle of Nacos configuration center (persistence, clustering, information synchronization)
In wechat applet, the externally introduced JS is used in xwml for judgment and calculation
Recently, the weather has been extremely hot, so collect the weather data of Beijing, Shanghai, Guangzhou and Shenzhen last year, and make a visual map
Vite: scaffold assembly
Pandora IOT development board learning (HAL Library) - Experiment 2 buzzer experiment (learning notes)
The second game of the 12th provincial single chip microcomputer competition of the Blue Bridge Cup
Sorted out an ECS summer money saving secret, this time @ old users come and take it away
Déchirure à la main - tri
Go语言介绍
Visual slam Lecture 3 -- Lie groups and Lie Algebras
【直播回顾】战码先锋首期8节直播完美落幕,下期敬请期待!
Basic syntax of unity script (8) - collaborative program and destruction method
[designmode] builder model
How should the team choose the feature branch development mode or trunk development mode?
Oracle viewing locked tables and unlocking
5G時代全面到來,淺談移動通信的前世今生