如何创建一个LearningSwitch类的pox L2_learning组件的实例?

时间:2016-12-17 09:42:14

标签: python sdn pox

我正在为我的控制器开发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类的实例!我应该传递给“连接”和“透明”参数的值是什么?

任何帮助都将不胜感激。

0 个答案:

没有答案