Search code examples
sdnopenflowryu

Ryu Controller Drop Packet


How do I send a flow entry to drop a package using Ryu? I've learned from tutorials how to send package out flow entry:

  1. I define the action: actions = [ofp_parser.OFPActionOutput(ofp.OFPP_FLOOD)]
  2. Then the entry itself: out = ofp_parser.OFPPacketOut(datapath=dp, buffer_id=msg.buffer_id, in_port=msg.in_port,actions=actions)
  3. Send the message to the switch: dp.send_msg(out)

I'm trying to find the documentation to make this code drop the package instead of flooding, without success. I imagine I'll have to change actions on the first step and fp_parser.OFPPacketOut on the second step. I need someone more experienced on Ryu and developing itself to point me to the right direction. Thank you.


Solution

  • The default disposition of a packet in OpenFlow is to drop the packet. Therefore if you have a Flow Rule that when it matches you want to drop the packet, you should simply have an instruction to CLEAR_ACTIONS and then no other instruction, which means that no other tables will be processed since there is no instruction to process (go to) another table and no actions on it.

    Remember to keep in mind your flow priorities. If you have more than one flow rule that will match the packet, the one with the highest priority will be the one to take effect. So your "drop packet" could be hidden behind a higher priority flow rule.

    Here is some code that I have that will drop all traffic that matches a given EtherType, assuming that no higher priority packet matches. The function is dependent on a couple of instance variables, namely datapath, proto, and parser.

    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