P4状态存储的几个组件

P4语言状态存储的东西

本文来自

http://www.sdnlab.com/17882.html

包头和元数据实例中的数据只能存在对某个数据包解析的过程中,解析下一个数据包的时候,这些实例都会重新初始化。而计数器、计量器和寄存器中的数据在整个流水线中长期存在,所以称之为状态存储。

计数器

计数器附加在每个表项之后,并在完成一次匹配并执行对应的操作后自增一。计数器中定义了7种属性,下图展示了V1.1中计数器的定义方式。

counter_declaration ::=
	counter counter_name{
      type:counter_type;
      [direct_or_static;]
      [instance_count:const_expr;]
      [min_width:const_expr;]
      [saturating;]
	}
	
counter_type ::= bytes | packets | bytes_and_packets
direct_or_static ::= direct_attribute | static_attribute
direct_attribute ::= direct : table_name
static_attribute ::= static : table_name

1)name

计数器名称,指向该计数器,P4编译器中通过名称+索引的方式确定一个计数器实例

2)min_width

编译P4程序时,编译器分配给计数器的大小并不是完全固定的,该属性指定了分配给计数器的最小长度

3)saturating

如果计数器中设定了该属性,则当计数器到达上限时停止计数,否则计数器将清零并重新开始计数

4)direct

如果计数器中设定了该属性,则计数器绑定的匹配-动作表无需指定count动作来更新计数器,计数器会自动更新。若在匹配动作表调用count动作更新计数器,则编译器报错

5)static

如果计数器中设定了该属性,则必须在匹配-动作表中调用count动作更新计数器。

6)instace_count

该属性用以记录计数器实例数,如果计数器设定了direct属性,则无法在计数器中设定该属性;如果计数器中未设定direct属性,则该属性必须设定。

7)type

v1.1中的计数器类型由三种:bytes、packets、bytes_and_packets。

计量器

计量器的定义与计数器类似,计量器中定义了6种属性,下图展示了V1.1中计数器的定义方式。

meter_declaration ::=
	meter meter_name{
      type : meter_type;
      [ result :field_ref; ]
      [ direct_or_static ;]
      [ instance_count : const_expr ;]
	}

meter_type ::= bytes | packets

1)name

计量器名称,指向该计量器。

2)direct

如果计量器中设定了该属性,则计量器绑定的匹配-动作表中无需指定execute_meter动作来更新计量器,计量器会自动更新。若在匹配-动作表中调用execute_meter动作来更新计量器,则编译器报错。

3)static

如果计数器中设定了该属性,则必须在匹配-动作表中调用execute_meter动作来更新计数器。

4)instance_count

该属性用以记录计量器实例数,如果计量器设定了direct属性,则无法在计量器中设定该属性;如果计量器中未设定direct属性,则该属性必须设定。

5)type

v1.1中的计量器类型有两种:bytes、packets.

6)result

v1.1中的计量器的输出结果有三种,分别用三种颜色标记:红色(P4_METER_COLOR_RED)、黄色(P4_METER_COLOR_YELLO)和绿色(P4_METER_COLOR_GREEN),输出结果存在一个2bit长度的字段中。

寄存器

寄存器定了五种属性 下图展示V1.1中寄存器的定义方式

register_declaration ::=
	register register_name {
      width_or_layout :
      [ direct_or_static ;]
      [ instace_count :const_expr ;]
      [ attribute_list ;]
	}

width_or_layout ::= width_declaration | layout_declaration
width_declaration ::= width : const_expr
layout_declaration ::= layout :header_type_name

attribute_list ::= attributes : attr_entry
attr_entry ::= signed | attr_entry ,attr_entry

1)name

寄存器名称,同上

2)width_or_layout

width和layout属性二选一,width为指定一个确定的长度,而layout是直接通过名称引用已定义的包头结构

3)direct_or_static

与计数器和计量器的定义类似,虽然寄存器不能直接在匹配过程中使用,但是作为modify_field动作的数据源,将当前寄存器中的数据复制到数据包的元数据中,并在后续的匹配中使用。

4)instance_count

该属性用以记录寄存器实例数,如果寄存器设定了direct属性,则无法在寄存器中设定该属性;如果寄存器中未设定direct属性,则该属性必须设定。

posted @ 2016-10-04 00:47  考拉小无  阅读(1514)  评论(0)    收藏  举报