How to create an instance of LearningSwitch class of pox L2_learning component?

272 views Asked by At

I'm developing L2_learning module of pox for my controller.The skeleton of my code is:

class LearningSwitch (object):
  def __init__ (self, connection, transparent):
     self.connection = connection
     self.transparent = transparent
     connection.addListeners(self)

      .
      .
      .
  def flowtable_request (self):
    for connection in core.openflow._connections.values():
     connection.send(of.ofp_stats_request(body=of.ofp_flow_stats_request()))
    log.info("Sent %i flow/port stats request(s)",len(core.openflow._connections))



  def _handle_flowstats_received(self,event):
      .
      .
      .
  def _handle_PacketIn (self, event):
      .
      .
      .
class l2_learning (object):

  def __init__ (self, transparent):
    core.openflow.addListeners(self)
    self.transparent = transparent

  def _handle_ConnectionUp (self, event):
    log.debug("Connection %s" % (event.connection,))
    LearningSwitch(event.connection, self.transparent)


def launch (transparent=False, hold_down=_flood_delay):
  """
   Starts an L2 learning switch.
  """
   try:
     global _flood_delay
     _flood_delay = int(str(hold_down), 10)
     assert _flood_delay >= 0
  except:
     raise RuntimeError("Expected hold-down to be a number")

  core.registerNew(l2_learning, str_to_bool(transparent))

I call the "flowtable_request (self)" function,somewhere in the code.I know that inorder that the " _handle_flowstats_received(self,event)" function works properly, i should add these 2 lines to the end of my code:

c=LearningSwitch(?,?)
core.openflow.addListenerByName("FlowStatsReceived", c._handle_flowstats_received)

but i don't know how to create an instance of the LearningSwitch class! what values i should pass to the "connection" and "transparent" arguments?

Any help would be appreciated.

0

There are 0 answers