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

Reply via email to