faucetsdn / ryu

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

ryu.topology.switches cannot be stopped when observing links #197

Open badcodebuilder opened 4 months ago

badcodebuilder commented 4 months ago

Problem

When running ryu.topology.switches and sending Ctrl+C, it will stuck. Command is here

ryu-manager ryu.topology.switches --observe-links
loading app ryu.topology.switches
loading app ryu.controller.ofp_handler
instantiating app ryu.topology.switches of Switches
instantiating app ryu.controller.ofp_handler of OFPHandler
^C

I analysis the code and find it stuck at https://github.com/faucetsdn/ryu/blob/d6cda4f427ff8de82b94c58aa826824a106014c2/ryu/topology/switches.py#L950

timeout=None makes it wait forever.

My solution

Add event set at the end of link_loophttps://github.com/faucetsdn/ryu/blob/d6cda4f427ff8de82b94c58aa826824a106014c2/ryu/topology/switches.py#L979

            ...
            self.link_event.wait(timeout=self.TIMEOUT_CHECK_PERIOD)
        if not self.lldp_event.is_set():
            self.lldp_event.set()

I do not know if my solution is correct when really being used, because I only test whether it can work or not, I do not connect it to Mininet.