Re: [pox-dev] Using connection object at my component in POX
Dear Murphy: Thanks. Now I add some extra events and named it as Fail_server_invoke.py like below: from pox.core import core import pox.openflow.libopenflow_01 as of from pox.lib.revent.revent import EventMixin log = core.getLogger() class define_event(EventMixin): _eventMixin_events = set([raise_fail]) class Fail_server_invoke(object): def __init__(self, intervals): self.connections = set()# Attribute self.interval = intervals define_event.addListeners(self) #Add Listener log.debug( - ) log.debug( Fail_server_invoke_class wait for raise_fail event ) log.debug( - ) def _handle_raise_fail (self, event): log.debug(Server failed) But I got some problems when I use another component to add following lines in launch function. core.registerNew( Fail_server_invoke, interval) define_event.raiseEvent(raise_fail(Generic)) And I also import the module Fail_server_invoke like below: from Fail_server_invoke import * The error message is 'NameError: name 'raise_fail' is not defined', but I already define 'raise_fail' in Fail_server_invoke.py Thanks for helping. Best Regards, Sophia 2013/3/30 Murphy McCauley murphy.mccau...@gmail.com On Mar 29, 2013, at 11:40 PM, chenli wrote: 1. The meaning for registering Is core.registerNew(Mycomponent) the function to register to core object, and we can use the methods in core which defined in /pox/pox/core.py ? If I register the Mycomponent to core, the other components can communicate with Mycomponent by core object? I think the answer here is yes. One of the purposes of the core object is to provide a rendezvous point for component instances. This allows a number of things, not all of which are really used extensively at this point: 1) It means you often just need to import core instead of a whole bunch of modules. 2) Multiple components that all implement the same interface can register under the same name and other components can find the active one. 3) It's not always clear where long-lived objects should be. One option is as a global variable of some module. core is a (possibly) more structured alternative which (among other things) hopefully encourages components to be capable of being instantiated more than once. (In practice, this is rarely true so far.) 2. The code section for raising ConnectionUp event And the second problem , I want to know where is the raiseEvent which raise ConnectionUp event happened. In other words, maybe it looks like core.openflow.raiseEvent(ConnectionUp). I'm not sure why it's helpful to know exactly where this event is raised, but it's in openflow.of_01 along with the rest of the stuff specific to communicating with OpenFlow 1.0 switches (not counting the stuff related to the OpenFlow protocol itself which is in libopenflow_01). It's slightly more complicated than just raising it on core.openflow. Connection objects are owned by an OpenFlowNexus. core.openflow is the default nexus, but there can be others. So the actual ConnectionUp event is raised on whichever nexus the Connection belongs to. -- Murphy
Re: [pox-dev] Using connection object at my component in POX
On Apr 1, 2013, at 3:46 AM, chenli wrote: Thanks. Now I add some extra events and named it as Fail_server_invoke.py like below: from pox.core import core import pox.openflow.libopenflow_01 as of from pox.lib.revent.revent import EventMixin log = core.getLogger() class define_event(EventMixin): _eventMixin_events = set([raise_fail]) class Fail_server_invoke(object): def __init__(self, intervals): self.connections = set()# Attribute self.interval = intervals define_event.addListeners(self) #Add Listener log.debug( - ) log.debug( Fail_server_invoke_class wait for raise_fail event ) log.debug( - ) def _handle_raise_fail (self, event): log.debug(Server failed) But I got some problems when I use another component to add following lines in launch function. core.registerNew( Fail_server_invoke, interval) define_event.raiseEvent(raise_fail(Generic)) Events are published from objects, not classes. define_event is a class -- you need an instance of it. Is there just one, or will there be an instance of it per server or something? In any case, you need an instance, and then you need to call addListeners and raiseEvent on the instance, not a class. And I also import the module Fail_server_invoke like below: from Fail_server_invoke import * The error message is 'NameError: name 'raise_fail' is not defined', but I already define 'raise_fail' in Fail_server_invoke.py Hard to say what the problem is here without the code and/or a stack trace. Hope that helps. -- Murphy
Re: [pox-dev] Using connection object at my component in POX
Dear Murphy, Thank you very much. I already see the example in forwarding(l2_learning.py) now, and using Listener to wait until ConnectionUp happened. I'd want to ask some questions about POX programs. 1. The meaning for registering Is core.registerNew(Mycomponent) the function to register to core object, and we can use the methods in core which defined in /pox/pox/core.py ? If I register the Mycomponent to core, the other components can communicate with Mycomponent by core object? 2. The code section for raising ConnectionUp event And the second problem , I want to know where is the raiseEvent which raise ConnectionUp event happened. In other words, maybe it looks like core.openflow.raiseEvent(ConnectionUp). Thanks for your helping. 2013/3/29 Murphy McCauley murphy.mccau...@gmail.com On Mar 28, 2013, at 12:28 PM, chenli wrote: I want to get connection object to send the ofp_flow_mod object. I already see the Communicating with a Datapath(Switch) section which in POX Wiki. And I also create a class to get the connection object which saved in connections attribute. But I'd want to know how to use the instance for My_class which created at the component? I tried it at the component I wrote like below. from pox.core import core import pox.openflow.libopenflow_01 as of from pox.lib.recoco import Timer import time # class c_class (object): def __init__(self): self.connections = set()# Attribute core.openflow.addListeners(self) #Add Listener def _handle_ConnectionUp (self, event): self.connections.add(event.connection) # def launch(): c_object = c_class() #Get instance msg = of.ofp_flow_mod() msg.match.dl_type = 0x0800 msg.match.nw_src = 192.168.1.6 msg.actions.append(of.ofp_action_output(port = 24)) c_objcet.connections.send(msg) But I got the error message NameError: global name 'c_objcet' is not defined. Well, the immediate cause of this is that the object you created is c_object, not c_objcet. Can someone help me or give me an example? You've got some additional problems here. The minor one is that c_object.connections is a plain set -- it doesn't have a send() method. If you want each connected switch to install the flow, you have to use a loop: for con in c_object.connections: con.send(msg) It's not clear to me that this is what you actually want to do, though. If you have more than one switch, the flow is probably going to be different for each one, since the port probably won't always be 24. If this *is* really what you want to do, core.openflow.connections always has all the connections -- there's no need to keep your own set. The bigger problem here is more conceptual. At the time of launch(), no switches will have connected yet, so there's nobody to send the flow to. There are a couple ways around this, but the easiest is probably to just wait until you see a ConnectionUp from a switch, and *then* send the ofp_flow_mods you want. I'd suggest you read some of the examples in the forwarding package. Hope that helps. -- Murphy
Re: [pox-dev] Using connection object at my component in POX
On Mar 29, 2013, at 11:40 PM, chenli wrote: 1. The meaning for registering Is core.registerNew(Mycomponent) the function to register to core object, and we can use the methods in core which defined in /pox/pox/core.py ? If I register the Mycomponent to core, the other components can communicate with Mycomponent by core object? I think the answer here is yes. One of the purposes of the core object is to provide a rendezvous point for component instances. This allows a number of things, not all of which are really used extensively at this point: 1) It means you often just need to import core instead of a whole bunch of modules. 2) Multiple components that all implement the same interface can register under the same name and other components can find the active one. 3) It's not always clear where long-lived objects should be. One option is as a global variable of some module. core is a (possibly) more structured alternative which (among other things) hopefully encourages components to be capable of being instantiated more than once. (In practice, this is rarely true so far.) 2. The code section for raising ConnectionUp event And the second problem , I want to know where is the raiseEvent which raise ConnectionUp event happened. In other words, maybe it looks like core.openflow.raiseEvent(ConnectionUp). I'm not sure why it's helpful to know exactly where this event is raised, but it's in openflow.of_01 along with the rest of the stuff specific to communicating with OpenFlow 1.0 switches (not counting the stuff related to the OpenFlow protocol itself which is in libopenflow_01). It's slightly more complicated than just raising it on core.openflow. Connection objects are owned by an OpenFlowNexus. core.openflow is the default nexus, but there can be others. So the actual ConnectionUp event is raised on whichever nexus the Connection belongs to. -- Murphy