0

我正在为我的控制器开发 pox 的 L2_learning 模块。我的代码框架是:

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))

我在代码中的某处调用“flowtable_request (self)”函数。我知道为了“_handle_flowstats_received(self,event)”函数正常工作,我应该将这两行添加到我的代码末尾:

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

但我不知道如何创建 LearningSwitch 类的实例!我应该将什么值传递给“连接”和“透明”参数?

任何帮助,将不胜感激。

4

0 回答 0