[pox-dev] Listener for Flow Removal

Lincoln Thurlow lthurlow at soe.ucsc.edu
Sun Feb 24 19:12:28 PST 2013


Murphy et al,

I am working on creating a listener for flow removal on the switch.  I am using l2_learning.py and William Emmanuel Yu's flow_stats.py.

I would like to make it such that when a flow timeout occurs, that the switch will send the flow statistics to the controller before removing the flow from the table.

I am unsure if I add my listener to the switch class or to core as neither appeared to work, it makes me think that my handling of a FlowRemoved event is incorrect.

Any help would be appreciated.  Thank you.

## Modified flow_stats.py
  def _handle_FlowRemoved(self, event):
    connection.send(of.ofp_stats_request(body=of.ofp_flow_stats_request()))

  def _handle_FlowStatsReceived (self, event):
    stats = flow_stats_to_list(event.stats)
    log.info("FlowStatsReceived from %s: %s", 
      dpidToStr(event.connection.dpid), stats)

    # Get number of bytes/packets in flows
    pbytes = 0
    flows = 0
    packet = 0
    for f in event.stats:
      pbytes += f.byte_count
      packet += f.packet_count
      flows += 1
    log.info("Web traffic from %s: %s bytes (%s packets) over %s flows", 
      dpidToStr(event.connection.dpid), pbytes, packet, flows)

## From l2_learning.py
def launch (transparent=False, hold_down=_flood_delay):
  from pox.lib.recoco import Timer
  """
  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))


More information about the pox-dev mailing list