当前位置:网站首页>P4 learning - Basic tunneling
P4 learning - Basic tunneling
2022-07-01 00:40:00 【Sunny_ Fan】
List of articles
One 、 Introduce
In this experiment , It is necessary to compare the results of the last experiment IP Routers add support for basic tunneling protocols . Switch according to purpose IP Address forwarding , Our task is to define a new header type to encapsulate IP Packet and modify the switch code , So that it uses a new tunnel header to determine the destination port to guide forwarding
New header types include :
- agreement ID(protocol ID): Indicates the type of package being encapsulated
- Destination ID(destination ID): For routing
The starting code file is badic_tunnel.p4, It's just based on IP forward , And last time basic_forwading The experiment is similar
About the control plane :
- P4 The program defines a package processing pipeline , But the rules in each table are inserted by the control plane . When a rule matches a packet , Its operation will call... Using the parameters provided by the control plane as part of the rule
- For this exercise , We have provided the necessary static control plane entries . As a starting point Mininet Part of the example ,make run The command will install package handling rules in the table of each switch . These rules are in sC-runtime.json Defined in file ,X The number of the corresponding switch
- Control plan view access myTunnel_exact surface , And the table doesn't exist yet , therefore make run The command does not work with initiator code
- Important note : We use P4Runtime To install the control plane rules , file sX-runtime.json It includes table、keys、actions The name of , If generated together P4Info Defined in the file ( perform make run Search after build/basic.P4Info file ).P4 Add or rename the table in the program 、 key 、 Any modification of the operation is reflected in sC-runtime.json In file
Two 、 Realization
Step one : Realize the basic tunnel
basic_tunnel.p4 A file based on IP Routing implementation of forwarding . Again TODO It's the part we need to modify . Final basic_tunnel.p4 The effect is : The switch can forward based on the custom encapsulated header , Similarly, if it is common IP Packets can also be used normally IP forward
The idea of the solution :
- new header type Name it myTunnel_t, Contains two 16bit Field of :proto_id、dst_id
- myTunnel_t Add header to headers In structure
- Update parser parser, Can be based on etherType extract myTunnel Baotou and ipv4 baotou ,etherType in myTunnel Baotou is 0x1212. If myTunnel after proto_id=TYPE_IPv4(0x0800), Parser parser Should be able to identify and extract ipv4 baotou
- Define a new action Name it myTunnel_forward, Here the knowledge is simple to set the exit number provided by the control plane (i.e.egress_spec field of the standard_metadata bus)
- Define a new table Name it myTunnel_exact, matching myTunnel In Baotou dst_id Field . If there are matching packets ,table Should be able to call myTunnel_forward action, Otherwise, call drop action
- to update apply, If myTunnel Baotou is available , stay MyIngress The control module applies the newly defined myTunnel_exact table; If ipv4 Baotou is available , Just call ipv4_Ipm table
- Update the inverse parser deparser, Fill in... In order ethernet、myTunnel、ipv4 baotou , Note that the inverse parser will fill in only when the header is available , If the parser sets the implied significant bit when extracting , Then there is no need to check the validity of the header
- Add static... To the switch rule, So that the switch can operate in accordance with dst_id forward . Refer to the topology , Configure interfaces and settings IDs, In this step, you need to add forwarding rules to sX-runtime.json file (X Represents the switch number )
Step two : perform
function sudo make run, compile basic_tunnel.p4, start-up mininet, Configure according to topology diagram switch and host
open h1 and h2 Terminal
Each host contains a small, based on python Messaging clients and servers . stay h2 Of xterm in , Start the server :./recieve.py
First , We will test no tunnel . stay h1 Of xterm in , towards h2 Send a message :./send.py 10.0.2.2 “P4 is cool”
The bag should be in h2 receive . If you check the received packet , You should see that it consists of an Ethernet header 、IP Headlines 、TCP The header and message consist of . If you change your purpose IP Address ( For example, try sending to 10.0.3.3), Then the news should not be h2 receive , And will be h3 receive . Now we use the tunnel to test . stay h1 Of xterm in , towards h2 Send a message :./send.py 10.0.2.2 “P4 is cool” --dst_id 2
The bag should be in h2 receive . If you check the received packet , You should see that it consists of an Ethernet header 、 tunnel header 、IP Headlines 、TCP The header and message consist of . stay h1 Of xterm in , Send a message :./send.py 10.0.3.3 “P4 is cool” --dst_id 2
The bag should be in h2 receive , Even if it's time to IP The address is h3 The address of . This is because when MyTunnel When the head is in the bag , The switch is no longer in use IP Header for routing . type exit or Ctrl-D To leave every xterm and Mininet Command line .
Python Scapy Not in itself myTunnel Head type , So we provide a program named myTunnel_header.py The file of , It adds pairs to our new custom header Scapy Support for
In the real network environment, it is usually : When a packet enters the network, it will be marked tunnel encapsulation , And then peel off when you leave the network tunnel encapsulation . How to modify P4 The code makes our experiment closer to the current network ?
On the first switch entering the network , We should be for myTunnel Baotou has a purpose IP and dst_id Mapping . Set a significant bit at the same time , So that in the inverse parser (deparser) Data packets can be filled during processing .
At the last switch leaving the network , according to dst_id After the field finds the out interface , We also need to remove myTunnel baotou .
边栏推荐
- Can JDBC based on openjdk connect to MySQL?
- Gateway service gateway
- To tell you the truth, ThreadLocal is really not an advanced thing
- Length of the longest integrable subarray
- CMU15445 (Fall 2019) 之 Project#1 - Buffer Pool 详解
- 解决 error MSB8031: Building an MFC project for a non-Unicode character set is deprecated.
- New trend of embedded software development: Devops
- 女朋友说:你要搞懂了MySQL三大日志,我就让你嘿嘿嘿!
- Wechat official account development (1) introduction to wechat official account
- 给按钮的边框和文字设置不同的背景色
猜你喜欢
C language file operation for conquering C language
CTF tool (1) -- archpr -- including installation / use process
[UML] UML class diagram
Confirm() method of window
2022-2028 global ultra high purity electrolytic iron powder industry research and trend analysis report
2022-2028 global ethylene oxide scrubber industry research and trend analysis report
NE555波形发生器手把手教程之NE555内部结构(一)
2022-2028 global mobile scanning radiology room industry survey and trend analysis report
2022-2028 global weight loss ginger tea industry research and trend analysis report
IFLYTEK active competition summary! (12)
随机推荐
The programmer's girlfriend gave me a fatigue driving test
女朋友说:你要搞懂了MySQL三大日志,我就让你嘿嘿嘿!
2022-2028 global rampant travel industry research and trend analysis report
Operation record of reinitialization instance of Dameng database
IBL预计算的疑问终于解开了
Oracle临时表详解
"Experience" my understanding of user growth "new users"
Solving the weird problem that the query conditions affect the value of query fields in MySQL query
剑指 Offer 18. 删除链表的节点
MySQL variables, stored procedures and functions
Kubernetes ---- pod configuration container start command
Multi graph explanation of resource preemption in yarn capacity scheduling
JS bubble sort and select sort
2022-2028 global capsule shell industry research and trend analysis report
Redis - how to understand publishing and subscribing
A detailed explanation of the implementation principle of go Distributed Link Tracking
What is the fastest way to import data from HDFS to Clickhouse? Spark is imported through JDBC or HDFS
Wechat official account development (1) introduction to wechat official account
MySQL index test
魔王冷饭||#101 魔王解惑数量多与质量;员工管理;高考志愿填报;游戏架构设计