记住记住你的流程优先级。如果有多个流规则与数据包匹配,则具有最高优先级的流规则将生效。因此,您的“丢弃数据包”可能隐藏在更高优先级的流规则后面。
下面是我的一些代码,假设没有更高优先级的数据包匹配,它将丢弃与给定以太网类型匹配的所有流量。函数依赖于两个实例变量,即
数据通路
,
原型
和
解析器
.
def dropEthType(self,
match_eth_type = 0x0800):
parser = self.parser
proto = self.proto
match = parser.OFPMatch(eth_type = match_eth_type)
instruction = [
parser.OFPInstructionActions(proto.OFPIT_CLEAR_ACTIONS, [])
]
msg = parser.OFPFlowMod(self.datapath,
table_id = OFDPA_FLOW_TABLE_ID_ACL_POLICY,
priority = 1,
command = proto.OFPFC_ADD,
match = match,
instructions = instruction
)
self._log("dropEthType : %s" % str(msg))
reply = api.send_msg(self.ryuapp, msg)
if reply:
raise Exception