根据 OpenFlow 1.3.5 规范,第 44 页指定以下内容:
如果 cookie_mask 字段包含非 0 值,修改和删除命令也可以通过 cookie 值过滤。此约束是流 mod 的 cookie 字段和流条目的 cookie 值中的 cookie_mask 指定的位必须是平等的。换句话说,(流入口.cookie&流 mod.cookie 掩码)==(流 mod.cookie&流 mod.cookie 掩码)。
现在,使用基于 Ryu python 的控制器,我尝试通过指定流的 cookie 值来删除流,但该过程不成功。
以下代码是我使用的测试示例。
from ryu.base.app_manager import RyuApp
from ryu.controller.dpset import EventDP
from ryu.controller.handler import MAIN_DISPATCHER
from ryu.controller.handler import set_ev_cls
from ryu.ofproto import ofproto_v1_3
from ryu.ofproto import ether, inet
class MPLS_Testing(RyuApp):
OFP_VERSIONS = [ofproto_v1_3.OFP_VERSION]
@set_ev_cls(EventDP, MAIN_DISPATCHER)
def switch_connect_event(self, ev):
ofp_parser = ev.dp.ofproto_parser
ofp = ev.dp.ofproto
datapath_obj = ev.dp
if ev.enter:
datapath_obj.send_msg( # Removes all flows registered in this switch.
ofp_parser.OFPFlowMod(
datapath=datapath_obj,
table_id=ofp.OFPTT_ALL,
command=ofp.OFPFC_DELETE,
out_port=ofp.OFPP_ANY,
out_group=ofp.OFPG_ANY,
)
)
add_label_flow = ofp_parser.OFPFlowMod(
datapath=datapath_obj,
cookie=1,
table_id=0,
command=ofp.OFPFC_ADD,
match=ofp_parser.OFPMatch(
in_port=1
),
instructions=[
ofp_parser.OFPInstructionActions(
ofp.OFPIT_APPLY_ACTIONS,
[
ofp_parser.OFPActionPushMpls(),
ofp_parser.OFPActionSetField(mpls_label=16),
]
),
ofp_parser.OFPInstructionGotoTable(table_id=1),
]
)
datapath_obj.send_msg(add_label_flow)
add_label_flow2 = ofp_parser.OFPFlowMod(
datapath=datapath_obj,
cookie=2,
table_id=1,
command=ofp.OFPFC_ADD,
match=ofp_parser.OFPMatch(
in_port=1
),
instructions=[
ofp_parser.OFPInstructionActions(
ofp.OFPIT_APPLY_ACTIONS,
[
ofp_parser.OFPActionPushMpls(),
ofp_parser.OFPActionSetField(mpls_label=12),
]
),
ofp_parser.OFPInstructionGotoTable(table_id=2),
]
)
datapath_obj.send_msg(add_label_flow2)
# Deletes flow with cookie equal to 2.
datapath_obj.send_msg(
ofp_parser.OFPFlowMod(
cookie=2,
cookie_mask=0xFFFFFFFFFFFFFFFF,
datapath=datapath_obj,
command=ofp.OFPFC_DELETE,
out_port=ofp.OFPP_ANY,
out_group=ofp.OFPG_ANY,
)
)
从表中删除流时,谁能告诉我 OpenVSwitch 2.9 是否支持 cookie 匹配?OpenFlow 1.3.5 规范明确指出,当 cookie_mask 不为零时,Delete 命令也可以使用 cookie 值过滤流。目前,我有点迷失在这里。