当前位置:网站首页>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
边栏推荐
- 【人员密度检测】基于形态学处理和GRNN网络的人员密度检测matlab仿真
- [yolo3d]: real time detection of end-to-end 3D point cloud input
- leetcode-1380. Lucky number in matrix
- It took me only 3 months to jump out of the comfort zone and become an automated test engineer for 5 years
- Vite: scaffold assembly
- Haute performance et faible puissance Cortex - A53 Core Board | i.mx8m mini
- Oracle viewing locked tables and unlocking
- 高性能 低功耗Cortex-A53核心板 | i.MX8M Mini
- Influence of air resistance on the trajectory of table tennis
- Homework in Chapter 3 of slam course of dark blue vision -- derivative application of T6 common functions
猜你喜欢
蓝桥杯单片机第六届温度记录器
Get started with Aurora 8b/10b IP core in one day (5) -- learn from the official routine of framing interface
手撕——排序
The 9th Blue Bridge Cup single chip microcomputer provincial competition
First acquaintance with string+ simple usage (II)
The original author is out! Faker. JS has been controlled by the community..
Interface debugging tool simulates post upload file - apipost
Failed to upgrade schema, error: “file does not exist
蓝桥杯单片机省赛第九届
[yolo3d]: real time detection of end-to-end 3D point cloud input
随机推荐
傅里叶级数
[untitled]
2022-07-01: at the annual meeting of a company, everyone is going to play a game of giving bonuses. There are a total of N employees. Each employee has construction points and trouble points. They nee
Is the product of cancer prevention medical insurance safe?
Wpviewpdf Delphi and Net PDF viewing component
蓝桥杯单片机省赛第五届
【leetcode】34. Find the first and last positions of elements in a sorted array
0 foundation how to learn automated testing? Follow these seven steps step by step and you will succeed
Homework in Chapter 3 of slam course of dark blue vision -- derivative application of T6 common functions
VS2010 plug-in nuget
Oracle 常用SQL
Welcome the winter vacation multi school league game 2 partial solution (B, C, D, F, G, H)
Lost a few hairs, and finally learned - graph traversal -dfs and BFS
NLog use
高性能 低功耗Cortex-A53核心板 | i.MX8M Mini
JVM knowledge points
Fingertips life Chapter 4 modules and packages
go 包的使用
SQL Yiwen get window function
Go variables and constants