faucetsdn / ryu

Ryu component-based software defined networking framework
https://ryu-sdn.org
Apache License 2.0
1.51k stars 1.16k forks source link

Flow removed message doesn't work (mininet+ryu controller in ubuntu20.10) #149

Closed plushao666 closed 2 years ago

plushao666 commented 3 years ago

Flow removed message:When flow entries time out or are deleted, the switch notifies controller with this message. I write the following example to my ryu app. And the ryu controller can't detect the flow removed message from switches, when the flow entries timeout or are deleted by hand. Plz tell me what the problem is......

    @set_ev_cls(ofp_event.EventOFPFlowRemoved, MAIN_DISPATCHER)
    def flow_removed_handler(self, ev):
        msg = ev.msg
        dp = msg.datapath
        ofp = dp.ofproto

        if msg.reason == ofp.OFPRR_IDLE_TIMEOUT:
            reason = 'IDLE TIMEOUT'
        elif msg.reason == ofp.OFPRR_HARD_TIMEOUT:
            reason = 'HARD TIMEOUT'
        elif msg.reason == ofp.OFPRR_DELETE:
            reason = 'DELETE'
        elif msg.reason == ofp.OFPRR_GROUP_DELETE:
            reason = 'GROUP DELETE'
        else:
            reason = 'unknown'

        self.logger.debug('OFPFlowRemoved received: '
                          'cookie=%d priority=%d reason=%s table_id=%d '
                          'duration_sec=%d duration_nsec=%d '
                          'idle_timeout=%d hard_timeout=%d '
                          'packet_count=%d byte_count=%d match.fields=%s',
                          msg.cookie, msg.priority, reason, msg.table_id,
                          msg.duration_sec, msg.duration_nsec,
                          msg.idle_timeout, msg.hard_timeout,
                          msg.packet_count, msg.byte_count, msg.match)
plushao666 commented 2 years ago

Because you should add flags when add a flow entry. mod = parser.OFPFlowMod(datapath=datapath, priority=0, match=match, instructions=inst, flags=ofproto.OFPFF_SEND_FLOW_REM)