[pox-dev] run a method on exit

Murphy McCauley murphy.mccauley at gmail.com
Thu Sep 6 20:03:31 PDT 2012


I'm using the MurphyMc/pox fork, which may or may not make a difference.  It works fine if you quit using Ctrl-D at the interpreter or by Ctrl-C without the interpreter...

$ cat ext/zzz.py
import pox.core

def handler (event):
  print "EVENT", type(event)

pox.core.core.addListener(pox.core.GoingUpEvent, handler)
pox.core.core.addListener(pox.core.GoingDownEvent, handler)
$

$ ./pox.py zzz
POX 0.0.0 / Copyright 2011-2012 James McCauley, et al.
EVENT <class 'pox.core.GoingUpEvent'>
INFO:core:POX 0.0.0 is up.
This program comes with ABSOLUTELY NO WARRANTY.  This program is free software,
and you are welcome to redistribute it under certain conditions.
Type 'help(pox.license)' for details.
Ready.
POX> ^D
INFO:core:Going down...
EVENT <class 'pox.core.GoingDownEvent'>
INFO:core:Down.
$

$ ./pox.py --no-cli zzz
POX 0.0.0 / Copyright 2011-2012 James McCauley, et al.
EVENT <class 'pox.core.GoingUpEvent'>
INFO:core:POX 0.0.0 is up.
^CINFO:core:Going down...
EVENT <class 'pox.core.GoingDownEvent'>
INFO:core:Down.
$

It doesn't work like that if you quit using exit(). 

$ ./pox.py zzz
POX 0.0.0 / Copyright 2011-2012 James McCauley, et al.
EVENT <class 'pox.core.GoingUpEvent'>
INFO:core:POX 0.0.0 is up.
This program comes with ABSOLUTELY NO WARRANTY.  This program is free software,
and you are welcome to redistribute it under certain conditions.
Type 'help(pox.license)' for details.
Ready.
POX> exit()
$

I've pushed a change to MurphyMc/pox so that exit() from the interpreter works as expected, but sys.exit() still exits immediately (I am hesitant to use atexit to change the latter).

For your case, though, you might just want to check core.running -- it's a flag which changes to False when POX is going down.

-- Murphy

On Sep 6, 2012, at 7:23 PM, Masoud Moshref Javadi wrote:

> This is my code:
> ThreadRule is a thread that creates opens a socket. and checks the flag if the flag is false it will stop
> 
> The GoingUpEvent works but the GoingDownEvent does not. So is it even the right way to do cleanup for a pox controller?
> 
> class my_l2_learning (EventMixin):
>   def __init__ (self, port):
>     self.listenTo(core.openflow)
> 
>     self.t = ThreadRule(port)
>     self.t.start()
>     #core.addListener(pox.core.GoingUpEvent, self._handle_GoingUpEvent)
>      core.addListener(pox.core.GoingDownEvent, self._handle_GoingDownEvent)
> 
>   def _handle_GoingDownEvent (self, event):
>         self.t.flag=False
>         print('go down')
>  def _handle_GoingUpEvent (self, event):
>         print ("go up")
> 
> 
> 
> On 9/6/2012 3:04 PM, Murphy McCauley wrote:
>> Can you post the code that you tried?
>> 
>> -- Murphy
>> 
>> On Sep 6, 2012 2:29 PM, "Masoud Moshref Javadi" <moshrefj at usc.edu> wrote:
>> I want to run a method when the controller goes down to close a socket.
>> I tried to register for pox.core.GoingDownEvent but it does not work. Is there any special way to be informed on the exit of pox?
>> 
>> -- 
>> Masoud Moshref Javadi
>> Computer Engineering PhD Student
>> Ming Hsieh Department of Electrical Engineering
>> University of Southern California
>> 
> 
> -- 
> Masoud Moshref Javadi
> Computer Engineering PhD Student
> Ming Hsieh Department of Electrical Engineering
> University of Southern California

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.noxrepo.org/pipermail/pox-dev-noxrepo.org/attachments/20120906/36aec0af/attachment-0002.htm>


More information about the pox-dev mailing list