# Openflow 1.5 #




## 专有名词 ##

- List of Actions:一个action列表。列表中的action可以重复。存在于

    - 流表的Apply-Actions instruction;

    -  packetOut报文中,被交换机立即执行;

- Set of Actions: 集合中action不能重复。存在于

    - 流表中的Write-Actions instructions。

    - group的action-bucket中,按照action-set order顺序执行。

- Action Bucket:group表中的一个action集合。 组表会为每个packet选择一个或多个buckets。

- Action Set: 

    - a set of actions associated with the packet that are accumulated while the packet is processed by each table and that are executed in specified order when the instruction set terminates pipeline processing。

    - 在报文在pipeline中被处理时积累的一个actions集合。当指令集终止了pipeline处理,这些action被按照特定顺序执行。

    

##Openflow Ports##

- Ingress port,如端口,openflow packets are received on an ingress port。


###标准端口 Standard Ports###

- Standard Ports, 包括物理端口、逻辑端口和LOCAL(保留端口 reserved port)。

    - 可被用作ingress and output ports

    - 用于组表

    - 有port counters

    - 有state

    - 有configuration

- Logical Ports

    - 由交换机定义,不与硬件接口一一对应。

    - 可能被非Openflow方法定义,如链路聚合组(link aggregation groups)、tunnels、lookback interfaces。

    - 逻辑端口可能包括报文封装,可能映射到多个物理端口。

    - Thre processing done by the logical port is implementation dependant and must be transparent to Openflow processing and those ports must interact with Openflow processing like Openflow physical ports.

    - 与物理端口的区别在于,与逻辑端口关联的报文可能有一个额外的pipeline filed,叫做Tunnel-ID。当逻辑端口接收到的报文被发送到控制器,这个逻辑端口和下层的物理端口都被上送控制器。

    

###保留端口 Reserved Ports###

- ALL

    - 转发报文时,代表交换机的所有端口。

    - 只能被用作output port。

    - 除了被配置为OFPPC_NO_FWD的所有标准端口。

- CONTROLLER

    - 表示与控制器连接的端口。

    - 可输入输出。

    - 作为输出时,将报文封装成packet-in报文。

    - 作为输入时,this identifier a packet originating from the controller。

- TABLE

    - **是否1.3没有?**

    - 表示Openflow pipeline的开始。

    - 只在packet-out 报文的action列表的output action中有效,代码openflow pipeline的入端口。

- IN_PORT

    - 表示报文的入端口。

    - 可被用作输出端口,表示将报文从入端口输出。

- ANY

    - 当没有设定端口(如port is wildcarded)时在一些openflow 请求时使用。

    - Some OpenFlow resuests contain a reference to a specific port that the request only applies to. Using ANY as the port number in these requests allows that request instance to apply to any and all ports. Can neither be used as an ingress port nor as an output port.

- UNSET

    - **是否1.3没有?**

    - 用于表示在Action-Set中,出端口还没有被设置。只有在使用OXM_OF_ACTSET_OUTPUT的match项,在actionSet中匹配输出端口时使用。

    - 不能作为入端口或出端口。

- LOCAL

    - 表示交换机的本地网络协议栈和管理栈。

    - 可作为入端口或出端口。

    - 允许远程实体使用Openflow网络与交换机交互。

    - With a suitable set of default flow entries, it can be used to implement an in-band controller connection。

    - 可选

- NORMAL

    - 表示使用传统的非openflow pipeline的转发功能。

    - 可以作为输出端口。

    - 如果交换机不支持传统的转发功能,必须声明不支持。

    - 可选

- FLOOD

    - 表示使用传统的交换机的泛洪功能。

    - 只能作为输出端口。

    - 一般,除了入端口和OFPPS_BLOCKED端口

    - 交换机可以使用包的VLAN ID或其他条件选择用于泛洪的端口。

    - 可选

Openflow交换机不支持NORMAL和FLOOD端口。Openflow-hybrid交换机可能支持。


###端口改变###

如果端口被删除了,控制器应该删除这个端口相关的流表。否则如果后续这个端口号被重新使用,可能会出现无法预料的问题。


###Port recirculation###

**1.3是否也有?**


-Logical ports can optionally be used to insert a network service or complex processing in the OpenFlow

switch (see 4.4). Most often, packets sent to logical ports never return to the same OpenFlow switch,

they are either consumed by the logical port or eventually sent over a physical port. In other cases,

packets sent to a logical port are recirculated back to the OpenFlow switch after the logical port

processing.

--Packet recirculation via logical ports is optional, and OpenFlow supports multiple types of port recirculation.


-The simplest recirculation is when a packet sent on a logical port returns back into the

switch via the same logical port. This could be used for a loopback or unidirectional packet processing.

Recirculation can also happen between a port pair, in which a packet sent on a logical port returns back

into the switch via the other logical port of the pair. This could be used to represent tunnel endpoints or

bidirectional packet processing. A port property describes the recirculation relationship between ports

(see 7.2.1.2).


-A switch should protect itself from packet infinite loops when using port recirculation. This mechanism

is implementation-specific and outside the scope of this specification. For example, the switch could

attach an internal recirculation count to each packet, which is incremented for each recirculation, and the

switch drops packets for which the counter is above a switch-defined threshold. Controllers are strongly

encouraged to avoid generating combinations of flow entries that may yield recirculation loops.

Because of the wide range of possible processing, very little can be assumed about the packets recirculated

back into the switch. Recirculated packets go back to the first flow table of the pipeline (see 5.1)

and can be identified by their new input port. The packet headers may have changed, so the match

fields are not guaranteed to be the same. The logical port may do packet fragmentation and reassembly,

so the packets may not match one to one and may have different sizes.


-The Tunnel-ID field and some other pipeline fields associated with the packet may optionally be

preserved through the recirculation and available for matching when returning to the switch, the

pipeline fields that are preserved are indicated via the port match field property (see 7.2.1.2). If a

pipeline field is present in both the OFPPDPT_PIPELINE_OUTPUT property of the output port and the

OFPPDPT_PIPELINE_INPUT property of the return port, then this pipeline field is preserved with the

packet (its value must remain the same).


##Openflow Tables##

![](http://i.imgur.com/W3SAZ20.png)

一个Openflow交换机必须有至少一个ingress flow table,可以有多个流表。


Openflow交换机的流表被顺序排序,从0开始。Pipeline处理有两个阶段:ingress processing和egress processing。在第一个egress table声明两个阶段的分离。所有表序号小于第一个egress table的表都是ingress table。


如果ingress processing的输出时将报文转发到一个输出端口,那么交换机可能根据输出端口的状态执行egress processing。Egress processing是可选的,交换机可能不支持任意的egress tables,可能没有被配置使用。如果没有有效的egress table 作为第一个first egress table(7.3.2),那么报文必须配输出端口处理,多数情况下报文被转发出去。如果有egress table,继续进行处理。


如果报文没有匹配的流表项,这就是table miss。接下来的行动就靠表配置了(5.4)。table-miss 流表项的指令可以灵活地设置如何处理这些报文。可以丢表包、转发到另一个流表或上送到控制器。


有时报文不会被流表或Pipeline完全处理。比如没有table miss流表项,报文就被丢弃。如果TTL无效,包可能被上送到控制器。


###Pipeline Consistency###


##Flow Tables and Flow entries##


- Flags, alter the way flow entries are managed, for example the flag OFPFF_SEND_FLOW_REM triggers flow removed messages for that flow entry.表示交换机需要如何管理流表项。

- 流表项由match项和优先级共同识别。The match fields and priority taken together identify a unique flow entry in a specific flow table。没有match项且优先级为0的流表项,被称为table-miss流表项。


##Matching ##

- 如果有多条优先级相同的流表匹配某一报文,没有明确定义选择哪条流表项。This case can only arise when a controller writer never sets the OFPFF_CHECK_OVERLAP bit on flow mod messages and adds overlapping entries。

- 如果交换机配置包含OFPC_FRAG_REASM标签,那么IP报文必须在被重新组装后才能被流表处理。


##Instructions##

- Apply-Actions action(s),

    - 立即执行特定的某些action,不改变action set。

    - 可被用于在两个流表之间改变包,或执行某个类型的多个actions。

    - 可选

- Clear-Actions

    - 将action set中的所有actions立即删除。

    - 可选

- Write-Actions action(s)

    - 向当前action set添加一些actions。

    - 如果某一类型的action已经存在于action set,则覆盖。

    - 如果对于某个域的set-field action存在,则覆盖。

    - 必须

- Write-Metadata metadata / mask

    - 写入masked metadata value into the metadata field。

    - mask用于选择修改元数据的那些比特。

    - 可选

- Stas-Trigger stas thresholds

    - 如果一个流表的统计数据超过阈值,则向控制器上报。

    - 可选

- Goto-Table next-table-id

    - 声明下一个流表的id。

    - 必须比当前流表的id大。最后一个流表项不能指定下一流表。

    - 如果只有一个流表,不需要指定下一流表。

    


一个流表的InstractionSet中,一种instruction最多一个。Experimenter的instructions由experimenter-id和experiment-type识别,所以instruction set中,可能存在多个experimenter instruction,但由experimenter-id和experimenter-type标识的experimenter instruction不能重复。


instruction执行的顺序有上述列表指定。实际上,唯一的约束是,clear-actions在write-actions前执行,apply-actions在write-metadata前,goto-table最后。


##Action Set##

- 如果一个流表项的instruction set没有Goto-Table instruction,那么pipeline处理流程结束,action set中的actions被执行。

- action set中一种action最多一个。set-field action由目标field类型识别,一个field type只能有一个set-field action处理。each field can only be set once.

- copy-field action因为race conditions所以未被定义,不建议实现。

- 如果某一类型的action存在于action set中,再添加相同类型的action,则会覆盖。

- 如果需要多个相同类型的action,如push multiple MPLS lables or pop multiple MPLS lables, 应该使用Apply-Actions。

- 对于egress processing的action set有一个限制,output action和group action不能被添加到egress action-set中。egress processing的action set在egress processing开始时被初始化,带有一个指向当前输出端口的output actions。

- 下面列出了action的执行顺序。如果action set包含一个group action, 那么组表中相应的action bucket中的actions也按照下列顺序被执行。交换机可能根据Apply-Actions指令中的action列表执行action。

    - copy TTL inwards,

    - pop, apply all tag pop actions to the packet

    - push-MPLS

    - push-PBB

    - push-VLAN

    - copy TTL outwards

    - decrement TTL

    - set, apply all set-fiels actions

    - qos, apply all QoS actions, such as meter and set_queue to the packet.

    - group, if a group action is specified, apply the actions of the relevant group bucket(s) in the order specified by this list.

    - output, if no group action is specified, forward the packet on the port specified by the output action.

    

如果没有ouput action 也没有group action,则这个包被丢掉。如果没有group action, output action指向一个不存在的端口,包被丢掉。


对组表的执行可能是循环的,一个组表的bucket可能执行另一个组表。


对于output action,在ingress 和egress的处理是不同的。

- 在ingress处理过程中,如果action set包含一个output action或 group action将报文转发到一个端口,那么这个包必须在这个端口上开始egress 处理。如果output action指向ALL,那么将拷贝包,在所有端口上开始egress处理。

- 在egress处理中的action set包括一个output action,那么这个包必须退出egress处理,然后被端口处理。大多数情况下,包被端口转发。


##List of Actions##

Apply-Actions指令和Packet-Out报文都包括一个acion列表。这些action的执行顺序按照这个List中的排列顺序。


如果包含一个outpur action,那么此时的报文被拷贝发送到端口。


当Apply-Actions中的actions被执行完,继续进行pipeline处理,报文的action set中的action不被改变。


##Actions##


- Output port_no,转发到某个端口,必须。

- Group group_id,转到某个组表,必须。

- Drop,当一个报文的action sets没有output action 或group action,这个包必须被丢掉。

- Set-Queue queue_id,为包设置queue id。当包被转发到一个端口,queue id决定包被放在哪个队列上。转发行为由队列的配置决定,用于提供Qos。可选。

- Meter meter_id,将包转至某个meter。meter表处理完后,包可能被丢弃(基于meter表的配置和状态)。如果交换机支持Meter必报,那么必须支持这个action,还可以支持multiple meter actions在list of actions和action set中。

- Push-Tag/Pop-Tag ethertype,交换机可能支持对标签进行Push和pop。

    - 新push的标签应该总是在最外面。should always be inserted as the outermost tag in the outermost valid location for that tag。

    - 当多个Push action被添加到包的action set,根据action set rules,1、MPLS,2、PBB,3VLAN。

    - 当list of actions包含多个push actions, 按照列表中的顺序被应用到包上。

    ![](http://i.imgur.com/uPt7KOR.png)

- Set-Field field_type value。不同的Set-Field actions由他们的field type区分,作用是修改包中相应头field的值。

    - 总是应用于最外边的header,除非field type声明。如set VLAN ID总是设置最外边VLAN标签的ID。

- Copy-Field src_field_type dst_field_type。

    - 用于在任意头部或pipeline fields之间拷贝数据。特别是从头部header field拷贝到 a packet register pipeline field或从a packet register pipeline field 到头部。有时从头部拷贝到另一个头部域。

    - 交换机可能不支持所有的组合。

-  Change-TTL ttl.




加油!