noxrepo / pox

The POX network software platform
https://noxrepo.github.io/pox-doc/html/
Apache License 2.0
619 stars 470 forks source link

Does pox blocks linux signal handling? #289

Closed 0x41gawor closed 1 year ago

0x41gawor commented 1 year ago

The following snippet of my controller code does not work

def ctrl_z_handler(signum, frame):
  global networkMonitor
  print "elo"
  networkMonitor.print_delays()

signal.signal(signal.SIGTSTP, ctrl_z_handler)

def launch ():
  global networkMonitor
  networkMonitor.start_time = time.time() * 1000*10 # factor *10 applied to increase the accuracy for short delays (capture tenths of ms)

  core.openflow.addListenerByName("ConnectionUp", _handle_ConnectionUp) # listen for the establishment of a new control channel with a switch, https://noxrepo.github.io/pox-doc/html/#connectionup
  core.openflow.addListenerByName("ConnectionDown", _handle_ConnectionDown)
  core.openflow.addListenerByName("PacketIn", _handle_PacketIn)
  core.openflow.addListenerByName("PortStatsReceived", _handle_portstats_received)

Do you maybe know the possible reason for such issue?

0x41gawor commented 1 year ago

Doesn't work I mean - when I click the ctrl+z with my pox component on the console running nothing happends. Same was with SIGWINCH and SIGINT.

MurphyMc commented 1 year ago

I think you should try a simpler test; this seems to work fine for me. I'm also using the latest POX under Python 3 and it looks like you may be quite a bit out of date.

Minimal example on top of POX halosaur which seems to work as expected:

from pox.core import core
import signal

log = core.getLogger()

def ctrl_z_handler (signum, frame):
  log.warn("Ctrl-Z!")

def launch (): 
  signal.signal(signal.SIGTSTP, ctrl_z_handler)
  log.warn("Launched")

Running the component and pressing Ctrl-Z twice followed by Ctrl-C:

[pox]$ ./pox.py log.level --DEBUG ctrlz
POX 0.8.0 (halosaur) / Copyright 2011-2022 James McCauley, et al.
WARNING:ctrlz:Launched
DEBUG:boot:Not launching of_01
DEBUG:core:POX 0.8.0 (halosaur) going up...
DEBUG:core:Running on CPython (3.10.6/Mar 10 2023 10:55:28)
DEBUG:core:Platform is Linux-5.15.0-60-generic-x86_64-with-glibc2.35
INFO:core:POX 0.8.0 (halosaur) is up.
^ZWARNING:ctrlz:Ctrl-Z!
^ZWARNING:ctrlz:Ctrl-Z!
^CINFO:core:Going down...
INFO:core:Down.