from pox.core import core
import pox
log = core.getLogger()

from pox.lib.recoco import Timer,Task,Sleep
from pox.lib.packet.ethernet import ethernet, ETHER_BROADCAST
from pox.lib.packet.ipv4 import ipv4
from pox.lib.packet.arp import arp
from pox.lib.addresses import IPAddr, EthAddr
import pox.lib.packet as pkt

import pox.openflow.libopenflow_01 as of

from pox.lib.revent import *

import time

class my_learning (object):
  def __init__ (self):
    print 'init called'
    core.openflow.addListeners(self)

  def _handle_ConnectionUp (self, event):
    print 'Learning Switch to be called'
    log.debug("Connection %s" % (event.connection,))
    msg = of.ofp_flow_mod()
    match = of.ofp_match()
    match.dl_src=EthAddr("00:11:22:33:44:55")
    match.nw_src=IPAddr("1.1.1.1")
    msg.match=match
    event.connection.send(msg)



def launch ():
  print "calling launch"
  core.registerNew(my_learning)


