kytos / topology

Kytos Main Topology Network Application (NApp)
https://napps.kytos.io/kytos/topology
MIT License
0 stars 19 forks source link

Port down event does not deactivate the port #166

Open italovalcy opened 3 years ago

italovalcy commented 3 years ago

When Kytos receives a port down event, it deactivates any possible link using that interface, however it does not deactivate the interface itself.

Steps to reproduce:

  1. Start kytos: kytosd -E
  2. Start mininet: mn --topo linear,2 --controller=remote,ip=127.0.0.1
  3. Check if all interfaces and links are enabled:
    mininet> sh curl -s http://127.0.0.1:8181/api/kytos/topology/v3/interfaces | jq -r '.interfaces[].active'
    true
    true
    true
    true
    true
    true
    mininet> sh curl -s http://127.0.0.1:8181/api/kytos/topology/v3/links | jq -r '.links[].active'
    true
  4. Disable the NNI link sw1-sw2:
    mininet> sh ip link set down s1-eth2
  5. Check the links / interfaces again:
    mininet> sh curl -s http://127.0.0.1:8181/api/kytos/topology/v3/links | jq -r '.links[].active'
    mininet> sh curl -s http://127.0.0.1:8181/api/kytos/topology/v3/interfaces | jq -r '.interfaces[].active'

Expected output:

mininet> sh curl -s http://127.0.0.1:8181/api/kytos/topology/v3/links | jq -r '.links[].active'
false
mininet> sh curl -s http://127.0.0.1:8181/api/kytos/topology/v3/interfaces | jq -r '.interfaces[].active'
true
false
true
true
false
true

Actual output:

mininet> sh curl -s http://127.0.0.1:8181/api/kytos/topology/v3/links | jq -r '.links[].active'
false
mininet> sh curl -s http://127.0.0.1:8181/api/kytos/topology/v3/interfaces | jq -r '.interfaces[].active'
true
true
true
true
true
true

I believe there are missing calls to activate / deactivate methods on interface.link_up./ interface.link_down events:

diff --git a/main.py b/main.py
index 70c7f28..9a2b8e2 100644
--- a/main.py
+++ b/main.py
@@ -589,6 +589,7 @@ class Main(KytosNApp):  # pylint: disable=too-many-public-methods
         The event notifies that an interface's link was changed to 'up'.
         """
         interface = event.content['interface']
+        interface.activate()
         self.handle_link_up(interface)

     @listen_to('kytos/maintenance.end_switch')
@@ -638,6 +639,7 @@ class Main(KytosNApp):  # pylint: disable=too-many-public-methods
         """
         interface = event.content['interface']
         self.handle_link_down(interface)
+        interface.deactivate()

     @listen_to('kytos/maintenance.start_switch')
     def handle_switch_maintenance_start(self, event):