Table
table是p4的匹配——动作表,定义了匹配字段(key)、动作(action)和一些其他相关属性。
其处理数据包的流程:
- Key construction.建立其匹配字段
- Key lookup in a lookup table.The result of key lookup is an "action". 数据包中去匹配table中的key中的字段,并获得要执行的"action"。
- Action execution.执行动作。
key
key由一个个表单对组成(e:m),其中e是对应数据包中匹配的字段,而m是一个match_kind常数用来表示匹配的算法。
例如:
1 key = { 2 hdr.ipv4.dstAddr:lpm; 3 }
这个就是以ipv4头的目的地址作为匹配字段,采用的是lpm(最长前缀字段)匹配方式。
p416 core现在提供三种默认的match_kind。
1 match_kind{ 2 lpm,//最长前缀字段 3 ternary,//三元匹配 4 exact//完全匹配 5 }
Action
table中的action list是列举了该table支持的action类型。用于action的匹配。
其他属性
p416提供了一些预设的其他属性:
- default_action:当table miss的时候执行的动作。
- counters:计数器
- size:table大小
- impl