Skip to content

GitLab

  • Menu
项目 Groups 代码片段
    • 正在加载...
  • 帮助
    • 帮助
    • 支持
    • 社区论坛
    • 提交反馈
  • 登录/注册
  • P p4-learning
  • Project information
    • Project information
    • 动态
    • 标记
    • 成员
  • 仓库
    • 仓库
    • 文件
    • 提交
    • 分支
    • 标签
    • 贡献者
    • 分支图
    • 比较
  • 议题 0
    • 议题 0
    • 列表
    • 看板
    • 服务台
    • 里程碑
  • 合并请求 0
    • 合并请求 0
  • CI/CD
    • CI/CD
    • 流水线
    • 作业
    • 计划
  • Deployments
    • Deployments
    • 环境
    • 发布
  • Monitor
    • Monitor
    • 事件
  • 软件包与镜像库
    • 软件包与镜像库
    • 软件包注册表
    • Infrastructure Registry
  • 分析
    • 分析
    • CI/CD
    • 仓库
    • Value stream
  • Wiki
    • Wiki
  • 代码片段
    • 代码片段
  • 动态
  • 分支图
  • 创建新议题
  • 作业
  • 提交
  • 议题看板
收起侧边栏
  • p4git
  • p4-learning
  • Wiki
  • BMv2 Simple Switch

BMv2 Simple Switch · 变更

页面历史
updated wiki 编辑于 9月 12, 2023 作者: edgar-costa's avatar edgar-costa
Hide whitespace changes
Inline Side-by-side
Showing with 17 addition and 11 deletion
+17 -11
  • BMv2-Simple-Switch.md BMv2-Simple-Switch.md +17 -11
  • 未找到文件。
BMv2-Simple-Switch.md
查看页面@ 56c33f59
......@@ -138,13 +138,13 @@ is hashed using the `algo` algorithm and stored in the `checksum` field of your
- `void update_checksum_with_payload<T, O>(in bool condition, in T data, inout O checksum, HashAlgorithm algo)`: same than `update_checksum` but includes the packet payload after `data`.
- `void resubmit<T>(in T data)`: resubmits the original packet to the parser. It can be applied only at the ingress. At the end of the ingress the `original` packet (modifications will not be present) will be submitted again to the parser, however all the fields added in the `data` parameter will keep the value they had at the end of ingress from the `original` packet. If multiple resubmit actions get executed on one packet, only the field list from the last resubmit action is used, and only one packet is resubmitted.
- `void void resubmit_preserving_field_list(bit<8> index)`: resubmits the original packet to the parser. It can be applied only at the ingress. At the end of the ingress the `original` packet (modifications will not be present) will be submitted again to the parser, however the user metadata fields that are tagged with @field_list(index) will be sent to the parser together with the packet. If multiple resubmit actions get executed on one packet, only the field list from the last resubmit action is used, and only one packet is resubmitted.
- `void recirculate<T>(in T data)`: recirculates the modified packet to the ingress. It can be applied only at the egress. This function marks the packet to be recirculated after egress deparsing, meaning that all the changes made to the packet will be kept in the recirculated one. Similarly to resubmit, some metadata fields can be kept using the `data` parameter.
- `void recirculate_preserving_field_list(bit<8> index)`: recirculates the modified packet to the ingress. It can be applied only at the egress. This function marks the packet to be recirculated after egress deparsing, meaning that all the changes made to the packet will be kept in the recirculated one. Similarly to resubmit, some metadata fields can be kept using the `index` parameter. The user metadata fields that are tagged with @field_list(index) will besent to the parser together with the packet.
- `void clone(in CloneType type, in bit<32> session)`: this functions allows you to create packet clones. For more information see its specific section [below](#cloning-packets).
- `void clone3<T>(in CloneType type, in bit<32> session, in T data)`: same than `clone` but allows you to copy some metadata fields to the cloned packet.
- `void clone_preserving_field_list(in CloneType type, in bit<32> session, bit<8> index)`: same than `clone` but allows you to copy some metadata fields to the cloned packet. The mechanism to decide which fields are copied is the same than with recirculate and resubmit, you can indicate that by tagging fields with the right `index`. he user metadata fields that are tagged with @field_list(index) will besent to the parser together with the packet.
- `void truncate(in bit<32> length)`: function that allows you to truncate packets at the egress. The packet will only keep the amount of bytes you specify in the `length` parameter. It can be executed at the ingress or egress, however it will only have effect during deparsing.
......@@ -207,12 +207,12 @@ Finally, once you have programmed the replication engine and added multicast gro
### Cloning Packets
Cloning/mirroring packets is a very common switch feature. Cloning is used in order to create packet replicas and send them somewhere else. This can be used for monitoring, to send data to a control plane, etc.
Cloning/mirroring packets is a very common feature in programmable switches. Cloning is used to create packet replicas and send them somewhere else. This can be used for monitoring, to send data to a control plane, etc.
The *Simple Switch* provides two `extern` functions that can be used to clone packets:
* `clone(in CloneType type, in bit<32> session)`
* `clone3<T>(in CloneType type, in bit<32> session, in T data)`
* `clone_preserving_field_list(in CloneType type, in bit<32> session, bit<8> index)`
1. The first parameter in both externs is the type, *Simple Switch* allows two types `CloneType.I2E`, and `CloneType.E2E`. The first type can be used to send a copy of the original packet to the egress pipeline, the later sends a copy of the egress packet to the buffer mechanism.
......@@ -222,8 +222,14 @@ The *Simple Switch* provides two `extern` functions that can be used to clone pa
mirroring_add <session> <output_port>
```
3. When using `clone3` you can add as a third parameter a metadata `struct`. When a packet is cloned all its metadata fields are reset to the default value (usually `0`). When using `clone3` you can tell the switch to copy some metadata values so the cloned packet will be able to access them.
3. When using `clone_preserving_field_list` you get an extra parameter `bit<8> index`. This is needed because when a packet is cloned all its metadata fields are reset to the default value (usually `0`). The index can be used to notify the switch which metadata fields have to be perserved in the new cloned packet. To do that, the programmer can tag metadata fields with 1 or multiple indexes as shown below. For more information, refer to the comments in [v1model.p4](https://github.com/p4lang/p4c/blob/main/p4include/v1model.p4).
```
@field_list(1)
bit<32> x;
```
Note that the `@field_list` annotation is only supported for user-defined metadata fields. It is not supported for parsed packet header fields, nor for standard metadata fields. If you wish to preserve any of these other values, you should copy their values to user-defined metadata fields that have the `@field_list` annotation on them.
For example, lets say we want to send a copy of every packet to a controller that is listening at port number `7`, to do what we would:
......@@ -277,7 +283,7 @@ Receiving digested packets is not trivial, since the switch adds some control he
*Simple Switch* allows the use of multiple queues per output port. However, in order to use them you will need to do some small modifications.
1. Uncomment `#define SSWITCH_PRIORITY_QUEUEING_ON` in the `bmv2/targets/simple_switch/simple_switch.h` file.
1. Run the `simple_switch` with `--priority-queues <num>`.
2. Add this two metadata fields to the `v1model.p4` file:
```
......@@ -294,7 +300,7 @@ Receiving digested packets is not trivial, since the switch adds some control he
cp v1model.p4 /usr/local/share/p4c/p4include/
````
4. Recompile the BMv2, so that multiple queues are added.
You can find a working example in the `exercises/multiqueueing` in this repository.
By default you will have 8 strict priority queues, being 0 the highest priority and 7 the lowest. Packets in a higher priority queue will always be transmitted before than packets in a lower priority queue. To select the queue you want to use for your packets you need to set the `standard_metadata.priority` field to `0-7`. If needed you can individually configure the rate and the length of each queue. In order to do that you will have to modify the `simple_switch` code. If you want to do this ask and we can show you how to do it.
......@@ -308,9 +314,9 @@ In order to understand how things are executed you have to check the [`simple_sw
In this section we will show what happens to packets after all the logic from the ingress control has been executed.
1. If `clone` or `clone3` were called, the packet will be cloned to the `egress_port` you specified using the mirroring
1. If `clone` or `clone_preserving_field_list` were called, the packet will be cloned to the `egress_port` you specified using the mirroring
id (for more information see the [cloning section](#cloning-packets)). This copies the ingress packet to egress pipeline without
all the ingress control modifications. If `clone3` action is used, the packet will also preserve the metadata fields specified. Finally, it
all the ingress control modifications. If `clone_preserving_field_list` action is used, the packet will also preserve the metadata fields specified. Finally, it
will get the `standard_metadata.instance_type` modified to the corresponding value.
2. If there was a call to `digest` the switch will send a control plane message with the specified fields to the controller.
......@@ -328,7 +334,7 @@ the other can not happen. Furthermore, the order in which we show them here matt
In this section we will show what happens to packets after all the logic from the egress control has been executed.
1. If `clone` or `clone3` were called in the egress pipeline, the packet will be cloned to the `egress_port` you specified using the mirroring id (for more information see the [cloning section](#cloning-packets)). This will send a copy of the egress packet to the egress control block, with the egress metadata unless specified with `clone3`.
1. If `clone` or `clone_preserving_field_list` were called in the egress pipeline, the packet will be cloned to the `egress_port` you specified using the mirroring id (for more information see the [cloning section](#cloning-packets)). This will send a copy of the egress packet to the egress control block, with the egress metadata unless specified with `clone_preserving_field_list`.
2. Now we will show some actions that are mutually exclusive, thus if one occurs the other can not happen. Furthermore, the order in which we show them here matter. Only the first true condition is executed by the switch.
......
克隆仓库

P4-Learning Documentation

  • Getting Started
  • Migrate to the new version
  • BMv2 Simple Switch
  • Control Plane
  • Debugging and Troubleshooting
  • Scapy
  • FAQ

沪ICP备19002739号