from pox.core import core
import pox.openflow.libopenflow_01 as of
from pox.lib.util import dpidToStr

log = core.getLogger()


def __addFlowmod (event):
  msg = of.ofp_flow_mod()
  msg.actions.append(of.ofp_action_output(port = 1))
  try:
    msg.buffer_id = event.ofp.buffer_id
  except: pass
  event.connection.send(msg)
  log.info("Redirecting all traffic to port 1 %s", dpidToStr(event.dpid))

def __redirectPacket (event):
  msg = of.ofp_packet_out()
  msg.data = event.ofp
  # Add an action to send to the specified port
  action = of.ofp_action_output(port = 1)
  msg.actions.append(action)
  # Send message to switch
  event.connection.send(msg)
  log.info("Packet redirected to port 1")

def _handle_ConnectionUp (event):
  msg = of.ofp_stats_request(body=of.ofp_port_stats_request())
  #event.connection.send(msg)
  #log.info("Port stats request sent")
  __addFlowmod(event)


def _handle_PacketIn (event):
  log.info("Packet in %s %s", str(event), str(event.ofp))
  __redirectPacket(event)

def _handle_PortStats (event):
  log.info("Port stats received")
  for port in event.ofp[0].body:
    log.info("\n%s\n", port.show())

def launch ():
  core.openflow.addListenerByName("ConnectionUp", _handle_ConnectionUp)
  core.openflow.addListenerByName("PacketIn", _handle_PacketIn)
  #core.openflow.addListenerByName("PortStatsReceived",  _handle_PortStats)
  log.info("Testing controller running.")

@@ -94,16 +94,54 @@
 pidToStr
+%0Afrom pox.lib.addresses import EthAddr
 %0A%0Alog = 
@@ -175,16 +175,17 @@
 dFlowmod
+1
  (event)
@@ -427,24 +427,483 @@
 ent.dpid))%0A%0A
+def __addFlowmod2 (event):%0A  msg = of.ofp_flow_mod()%0A  msg.match.dl_dst = EthAddr(%2235:35:35:35:35:35%22)%0A  msg.match.dl_src = EthAddr(%2245:45:45:45:45:45%22)%0A  msg.match.dl_vlan = 1234%0A  msg.match.dl_vlan_pcp = 1%0A  msg.match.dl_type = 0x0806%0A  msg.actions.append(of.ofp_action_output(port = 1))%0A  try:%0A    msg.buffer_id = event.ofp.buffer_id%0A  except: pass%0A  event.connection.send(msg)%0A  log.info(%22Redirecting all traffic to port 1 %25s%22, dpidToStr(event.dpid))%0A%0A  %0A
 def __redire
@@ -1369,16 +1369,17 @@
 dFlowmod
+2
 (event)%0A
@@ -1719,16 +1719,17 @@
 onUp)%0A  
+#
 core.ope

test modifications