kytos-ng / topology

Kytos Main Topology Network Application (NApp)
https://kytos-ng.github.io/api/topology.html
MIT License
0 stars 7 forks source link

feat: add support for auto (safe) interface deletion and a new endpoint to delete a disabled intf #191

Closed viniarck closed 5 months ago

viniarck commented 6 months ago

This is a feature request from @italovalcy.

Context:

Requirements:

To hard delete: The interface should be removed on a switch switch.remove_interface(intf), and then remove from the DB in the switches.interfaces[] collection it should be pulled from the array, and removed from interface_details.

The priority and target will still be defined.

Side note, this following script has been used recently to hard delete a non existing disabled interface (it was also filtering for not active due to special case in prod):

topology = controller.napps[("kytos", "topology")]
dpid = "00:00:00:00:00:20:00:01"
port_no = 1000
switch = controller.switches[dpid]
intf = switch.get_interface_by_port_no(port_no)

print(f"found intf {intf}")

if intf and not intf.is_enabled() and not intf.is_active() and not topology._get_link_from_interface(intf):
    switch_before = switch.as_dict()
    switch.remove_interface(intf)
    upserted = topology.topo_controller.upsert_switch(switch.id, switch.as_dict())
    print(f"upserted switch {upserted} before={switch_before}")

    res = topology.topo_controller.db.interface_details.find_one_and_delete({"_id": intf.id})
    print(f"db.interface_details deleted: {res}")

if not switch.get_interface_by_port_no(port_no):
    print(f"intf {intf} deleted")
else:
    print(f"intf {intf} NOT deleted")
Alopalao commented 5 months ago

About VLAN usage, of_lldp uses all the interfaces of a switch or none of them. This would mean that currently to delete an interface, first it is needed to disable its switch to de-allocate all the VLANS from the switch interfaces. This behavior it is not a blocker but it would require more work from the user. Because, the switch and its component would need to be enabled once the interface is deleted.

Found a partly of_lldp issue related to what was explained. Flows would only be installed in NNIs and allocate the respective VLAN.

viniarck commented 5 months ago

@Alopalao, good observation, maybe we can in the meantime ignore allocated vlans and only rely on the flows in the DB? At the end of the day, the allocated vlans are primarily for validation purposes, in this case as you know it's ensuring that nobody will allocate a vlan that interferes with reserved of_lldp, but in practice as you mentioned there's no flow matching on a particular interface yet, and as far as deletion is concerned it cares about specific flows associated with an interface.

Potentially, in the meantime, you could:

Let me know if you can see a simpler idea that wouldn't create tech debt.