Dropping a packets between Two Specific IPv4 addresses - Ryu SDN

32 Views Asked by At

I am trying to figure out how to drop specific packets that are being sent between two hosts (h2 & h3).

When I run the simulation in CORE it appears that the flows are being added to the controller:

I get this in the controller console:

dropIPv4Traffic (h2 to h3): version=None,msg_type=None,msg_len=None,xid=None,OFPFlowMod(buffer_id=4294967295,command=0,cookie=0,cookie_mask=0,flags=0,hard_timeout=0,idle_timeout=0,instructions=[OFPInstructionActions(actions=[],type=5)],match=OFPMatch(oxm_fields={'eth_type': 2048, 'ipv4_src': '10.0.2.1', 'ipv4_dst': '10.0.3.1'}),out_group=0,out_port=0,priority=1,table_id=0)
dropIPv4Traffic (h3 to h2): version=None,msg_type=None,msg_len=None,xid=None,OFPFlowMod(buffer_id=4294967295,command=0,cookie=0,cookie_mask=0,flags=0,hard_timeout=0,idle_timeout=0,instructions=[OFPInstructionActions(actions=[],type=5)],match=OFPMatch(oxm_fields={'eth_type': 2048, 'ipv4_src': '10.0.3.1', 'ipv4_dst': '10

Here is the method that I am attempting to do this in:

  @set_ev_cls(ofp_event.EventOFPSwitchFeatures, CONFIG_DISPATCHER)
    def switch_features_handler(self, ev):
        datapath = ev.msg.datapath
        ofproto = datapath.ofproto
        parser = datapath.ofproto_parser

        # IPv4 addresses of h2 and h3
        h2_ipv4 = '10.0.2.1'
        h3_ipv4 = '10.0.3.1'

        # Drop traffic from h2 to h3
        match = parser.OFPMatch(eth_type=ether_types.ETH_TYPE_IP,
                                ipv4_src=h2_ipv4, ipv4_dst=h3_ipv4)
        instruction = [
            parser.OFPInstructionActions(ofproto.OFPIT_CLEAR_ACTIONS, [])
        ]
        msg = parser.OFPFlowMod(
                                datapath=datapath,
                                priority=1,
                                match=match,
                                instructions=instruction
                                )
        self.logger.info("dropIPv4Traffic (h2 to h3): %s" % str(msg))


        # Drop traffic from h3 to h2
        match = parser.OFPMatch(eth_type=ether_types.ETH_TYPE_IP,
                                ipv4_src=h3_ipv4, ipv4_dst=h2_ipv4)
        instruction = [
            parser.OFPInstructionActions(ofproto.OFPIT_CLEAR_ACTIONS, [])
        ]
        msg = parser.OFPFlowMod(
                                datapath=datapath,
                                priority=1,
                                match=match,
                                instructions=instruction
                                )
        self.logger.info("dropIPv4Traffic (h3 to h2): %s" % str(msg))



        # Add a default flow entry to send unmatched packets to the controller
        match = parser.OFPMatch()
        actions = [parser.OFPActionOutput(ofproto.OFPP_CONTROLLER, ofproto.OFPCML_NO_BUFFER)]
        self.add_flow(datapath, 0, match, actions)

I feel like I might not be setting some params correctly but since I am quite new to Ryu I can't seem to figure it out.

Thanks in advance for your help!

0

There are 0 best solutions below