kytos-ng / kytos

Kytos SDN Platform. Kytos is designed to be easy to install, use, develop and share Network Apps (NApps).
https://kytos-ng.github.io/
MIT License
3 stars 7 forks source link

Cleanup connection after switch deletion #445

Open Alopalao opened 7 months ago

Alopalao commented 7 months ago

After a switch is deleted, there is a leftover data in controller.connections (switch 00:00:00:00:00:00:00:01 was deleted):

kytos $> controller.connections
Out[3]: 
{('127.0.0.1',
  33734): Connection('127.0.0.1', 33734, None, Switch('00:00:00:00:00:00:00:01'), <ConnectionState.FINISHED: 4>),
 ('127.0.0.1',
  33744): Connection('127.0.0.1', 33744, <asyncio.TransportSocket fd=116, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('127.0.0.1', 6653), raddr=('127.0.0.1', 33744)>, Switch('00:00:00:00:00:00:00:03'), <ConnectionState.ESTABLISHED: 2>),
 ('127.0.0.1',
  33750): Connection('127.0.0.1', 33750, <asyncio.TransportSocket fd=117, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('127.0.0.1', 6653), raddr=('127.0.0.1', 33750)>, Switch('00:00:00:00:00:00:00:02'), <ConnectionState.ESTABLISHED: 2>)}

It is not a problem to keep this data, it is just a leftover. From PR comment.

viniarck commented 7 months ago

Good one. Future note and requirement to be aware:

The main gotcha to be aware though is that it's not desirable to close the socket if a deleted switch conn is still ESTABLISHED, otherwise it'd close the connection with that switch, which in turn, if the network operator hand't remove the controller tcp connection there yet, it would reconnect again, leading to another (undesired) rediscovery.

Ideally, this needs to be clean up but only for non existing switches when they disconnect.