[pox-dev] How to use sendToDPID(dpid,packet) function?

Kavit Shah kavit.shah8 at gmail.com
Fri Jul 5 12:52:48 PDT 2013


Command line with log, my code and screen shot of the wireshrak are
attached in the text and png files.

I am using HP Pro curve switch, i think it supports OF 1.0 spec.


#####################################
#####################################

Important part of my code in the attached file

#####################################
#####################################

Questions:

1) sendToDPID function is not working the way I expect it to work.
According to me if that function works I should see packet out in wireshark.

2) Am I extracting dpid of the switch correctly ?

3) What is the reason for getting an error while switch connects to the POX
controller ?

ERROR:openflow.of_01:[00-16-b9-ce-2f-40|800 1] OpenFlow Error:
[00-16-b9-ce-2f-40|800 1] Error: header:
[00-16-b9-ce-2f-40|800 1] Error:   version: 1
[00-16-b9-ce-2f-40|800 1] Error:   type:    1 (OFPT_ERROR)
[00-16-b9-ce-2f-40|800 1] Error:   length:  20
[00-16-b9-ce-2f-40|800 1] Error:   xid:     7
[00-16-b9-ce-2f-40|800 1] Error: type: OFPET_BAD_REQUEST (1)
[00-16-b9-ce-2f-40|800 1] Error: code: OFPBRC_BAD_TYPE (1)
[00-16-b9-ce-2f-40|800 1] Error: datalen: 8
[00-16-b9-ce-2f-40|800 1] Error: 0000: 01 12 00 08 00 00 00 07
               ........
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.noxrepo.org/pipermail/pox-dev-noxrepo.org/attachments/20130705/59e259b2/attachment-0001.htm>
-------------- next part --------------

############################################################################
Command line:
############################################################################

mininet at mininet-vm:~/pox$ ./pox.py log.level --DEBUG forwarding.AirPlayTest
POX 0.1.0 (betta) / Copyright 2011-2013 James McCauley, et al.
DEBUG:core:POX 0.1.0 (betta) going up...
DEBUG:core:Running on CPython (2.7.3/Sep 26 2012 21:51:14)
DEBUG:core:Platform is Linux-3.5.0-17-generic-x86_64-with-Ubuntu-12.10-quantal
INFO:core:POX 0.1.0 (betta) is up.
DEBUG:openflow.of_01:Listening on 0.0.0.0:6633
INFO:openflow.of_01:[00-16-b9-ce-2f-40|700 2] connected
DEBUG:forwarding.AirPlayTest:Connection [00-16-b9-ce-2f-40|700 2]
DEBUG:forwarding.AirPlayTest:
Swiitch 00-16-b9-ce-2f-40|700 has come up.

DEBUG:forwarding.AirPlayTest:Initializing LearningSwitch, transparent=False
ERROR:openflow.of_01:[00-16-b9-ce-2f-40|700 2] OpenFlow Error:
[00-16-b9-ce-2f-40|700 2] Error: header:
[00-16-b9-ce-2f-40|700 2] Error:   version: 1
[00-16-b9-ce-2f-40|700 2] Error:   type:    1 (OFPT_ERROR)
[00-16-b9-ce-2f-40|700 2] Error:   length:  20
[00-16-b9-ce-2f-40|700 2] Error:   xid:     10
[00-16-b9-ce-2f-40|700 2] Error: type: OFPET_BAD_REQUEST (1)
[00-16-b9-ce-2f-40|700 2] Error: code: OFPBRC_BAD_TYPE (1)
[00-16-b9-ce-2f-40|700 2] Error: datalen: 8
[00-16-b9-ce-2f-40|700 2] Error: 0000: 01 12 00 08 00 00 00 0a                            ........
INFO:openflow.of_01:[00-16-b9-ce-2f-40|800 1] connected
DEBUG:forwarding.AirPlayTest:Connection [00-16-b9-ce-2f-40|800 1]
DEBUG:forwarding.AirPlayTest:
Swiitch 00-16-b9-ce-2f-40|800 has come up.

DEBUG:forwarding.AirPlayTest:Initializing LearningSwitch, transparent=False
ERROR:openflow.of_01:[00-16-b9-ce-2f-40|800 1] OpenFlow Error:
[00-16-b9-ce-2f-40|800 1] Error: header:
[00-16-b9-ce-2f-40|800 1] Error:   version: 1
[00-16-b9-ce-2f-40|800 1] Error:   type:    1 (OFPT_ERROR)
[00-16-b9-ce-2f-40|800 1] Error:   length:  20
[00-16-b9-ce-2f-40|800 1] Error:   xid:     7
[00-16-b9-ce-2f-40|800 1] Error: type: OFPET_BAD_REQUEST (1)
[00-16-b9-ce-2f-40|800 1] Error: code: OFPBRC_BAD_TYPE (1)
[00-16-b9-ce-2f-40|800 1] Error: datalen: 8
[00-16-b9-ce-2f-40|800 1] Error: 0000: 01 12 00 08 00 00 00 07                            ........
DEBUG:forwarding.AirPlayTest:
elements inside a table = 1
DEBUG:forwarding.AirPlayTest:
 1) Found Multicast Packet
DEBUG:forwarding.AirPlayTest:
elements inside a table = 1
DEBUG:forwarding.AirPlayTest:
 1) Found Multicast Packet
DEBUG:forwarding.AirPlayTest:
elements inside a table = 2
DEBUG:forwarding.AirPlayTest:
 1) Found Multicast Packet
DEBUG:forwarding.AirPlayTest:
 2) Found multicast IPv4
 src_ip = 192.168.101.2
dst_ip = 224.0.0.251

DEBUG:forwarding.AirPlayTest:
 3)Found multicast DNS Packet because of dst_ip

DEBUG:forwarding.AirPlayTest:
 4) From pair_db table
src_mac = 98:D6:BB:2B:57:F2
dst_mac = 00:16:CB:8A:A8:7E
From packet_in
 packet_mac = 00:16:CB:8A:A8:7E

DEBUG:forwarding.AirPlayTest:
5)Either src_mac or dst_mac's match has been found with packet_mac in pair_db table src_mac = 98:D6:BB:2B:57:F2
 dst_mac = 00:16:CB:8A:A8:7E
 packet_mac = 00:16:CB:8A:A8:7E

DEBUG:forwarding.AirPlayTest:
7) switch_DPID =197032581304037184
DEBUG:forwarding.AirPlayTest:
elements inside a table = 2
DEBUG:forwarding.AirPlayTest:
 1) Found Multicast Packet
DEBUG:forwarding.AirPlayTest:
elements inside a table = 2
DEBUG:forwarding.AirPlayTest:
 1) Found Multicast Packet
DEBUG:forwarding.AirPlayTest:
 2) Found multicast IPv4
 src_ip = 192.168.101.2
dst_ip = 224.0.0.251

DEBUG:forwarding.AirPlayTest:
 3)Found multicast DNS Packet because of dst_ip

DEBUG:forwarding.AirPlayTest:
 4) From pair_db table
src_mac = 98:D6:BB:2B:57:F2
dst_mac = 00:16:CB:8A:A8:7E
From packet_in
 packet_mac = 00:16:CB:8A:A8:7E

DEBUG:forwarding.AirPlayTest:
5)Either src_mac or dst_mac's match has been found with packet_mac in pair_db table src_mac = 98:D6:BB:2B:57:F2
 dst_mac = 00:16:CB:8A:A8:7E
 packet_mac = 00:16:CB:8A:A8:7E

DEBUG:forwarding.AirPlayTest:
7) switch_DPID =197032581304037184
DEBUG:forwarding.AirPlayTest:
elements inside a table = 2
DEBUG:forwarding.AirPlayTest:
 1) Found Multicast Packet
DEBUG:forwarding.AirPlayTest:
elements inside a table = 2
DEBUG:forwarding.AirPlayTest:
 1) Found Multicast Packet
DEBUG:forwarding.AirPlayTest:
elements inside a table = 2
DEBUG:forwarding.AirPlayTest:
 1) Found Multicast Packet
^CINFO:core:Going down...
INFO:openflow.of_01:[00-16-b9-ce-2f-40|800 1] disconnected
INFO:openflow.of_01:[00-16-b9-ce-2f-40|700 2] disconnected
INFO:core:Down.


#################################################################
Component: pox/pox/fprwarding/AirPlayTest.py
#################################################################

from pox.core import core
from pox.lib.util import str_to_dpid, dpid_to_str, str_to_bool

import pox.openflow.libopenflow_01 as of
import pox.lib.packet as packet
import time

log = core.getLogger()

# We don't want to flood immediately when a switch connects.
# Can be overriden on commandline.
_flood_delay = 0

##############################################################################
##############################################################################
table = set([])
pairdb = {"98:D6:BB:2B:57:F2":"00:16:CB:8A:A8:7E"}
class GlobeLearningTable(object): 
  def __init__(self, mac, port, dpid):
    self.mac = mac
	self.port = port
    self.dpid = dpid
  def __hash__(self):
        return hash((self.mac, self.port, self.dpid))
  def __eq__(self, other):
        if not isinstance(other, type(self)): return NotImplemented
        return self.mac == other.mac and self.port == other.port and self.dpid == other.dpid
  def add(self):
    global table
    if self not in table:
      table.add(self)
##################################################################################
##################################################################################

class LearningSwitch (object):

  def __init__ (self, connection,transparent):
    self.connection = connection
    self.transparent = transparent
    self.macToPort = {}
    connection.addListeners(self)
    self.hold_down_expired = _flood_delay == 0
    log.debug("Initializing LearningSwitch, transparent=%s",
              str(self.transparent))

  def _handle_PacketIn (self, event):
    
    def flood (message = None):
      """ Floods the packet """
      msg = of.ofp_packet_out()
      if time.time() - self.connection.connect_time >= _flood_delay:
        # Only flood if we've been connected for a little while...

        if self.hold_down_expired is False:
          # Oh yes it is!
          self.hold_down_expired = True
          log.info("%s: Flood hold-down expired -- flooding",
              dpid_to_str(event.dpid))

        if message is not None: log.debug(message)
        # log.debug("%i: flood %s -> %s", event.dpid,packet.src,packet.dst)
        # OFPP_FLOOD is optional; on some switches you may need to change
        # this to OFPP_ALL.
        msg.actions.append(of.ofp_action_output(port = of.OFPP_FLOOD))
      else:
        pass
        #log.info("Holding down flood for %s", dpid_to_str(event.dpid))
      msg.data = event.ofp
      msg.in_port = event.port
      self.connection.send(msg)

    def drop (duration = None):
      """
      Drops this packet and optionally installs a flow to continue
      dropping similar ones for a while
      """
      if duration is not None:
        if not isinstance(duration, tuple):
          duration = (duration,duration)
        msg = of.ofp_flow_mod()
        msg.match = of.ofp_match.from_packet(packet)
        msg.idle_timeout = duration[0]
        msg.hard_timeout = duration[1]
        msg.buffer_id = event.ofp.buffer_id
        self.connection.send(msg)
      elif event.ofp.buffer_id is not None:
        msg = of.ofp_packet_out()
        msg.buffer_id = event.ofp.buffer_id
        msg.in_port = event.port
        self.connection.send(msg)
    
	packet = event.parsed
    
    if not self.transparent: # 2
      if packet.type == packet.LLDP_TYPE or packet.dst.isBridgeFiltered():
        drop() # 2a
        return
        
    
	self.macToPort[packet.src] = event.port # 1
    
    ###########################################################################
	###########################################################################
	dpid = event.dpid
	# Mac address of device is converted into uppercase string    
    # creating l2 table for individual switch & global learning table  
    packet_src = str(packet.src)
    packet_mac = packet_src.upper()
    entry = GlobeLearningTable(packet_mac, event.port, dpid)
    entry.add()
      
    if packet.dst.isMulticast(): # 1)
      log.debug("\n 1) Found Multicast Packet")
      
      ip_packet = packet.find('ipv4')
      if ip_packet is not None:  # 2)
        ip_packet = packet.payload
        src_ip = ip_packet.srcip
        dst_ip = ip_packet.dstip
        log.debug("\n 2) Found multicast IPv4 \n src_ip = %s\ndst_ip = %s\n",str(src_ip),str(dst_ip))

        if dst_ip == "224.0.0.251" or dst_ip == "224.0.0.252": # 3)
          log.debug("\n 3)Found multicast DNS Packet because of dst_ip  \n")
       
          for src_mac,dst_mac in pairdb.iteritems(): # 4)
            log.debug("\n 4) From pair_db table \nsrc_mac = %s \ndst_mac = %s \nFrom packet_in \n packet_mac = %s\n",str(src_mac),str(dst_mac),packet_mac)
                  
            if src_mac == packet_mac or dst_mac == packet_mac : # 5) Needs testing for 5) 6) 7)
              log.debug("\n5)Either src_mac or dst_mac's match has been found with packet_mac in pair_db table src_mac = %s\n dst_mac = %s\n packet_mac = %s \n",str(src_mac),str(dst_mac),str(packet_mac))
              
              for obj in table : # 6)
                 if obj.mac == src_mac: # 7)
                   core.openflow.sendToDPID(dpid, packet)
				  #core.openflow.sendToDPID(obj.dpid, packet)---> Tried this as well
				   
    ################################################################################# 
    #################################################################################  
    
	else:
      if packet.dst not in self.macToPort: # 4
        log.debug("Port for %s unknown -- flooding" % (packet.dst,)) 
        flood() # 4a
      else:
        port = self.macToPort[packet.dst]
        if port == event.port: # 5
          # 5a
          log.warning("Same port for packet from %s -> %s on %s.%s.  Drop."
              % (packet.src, packet.dst, dpid_to_str(event.dpid), port))
          drop(10)
          return
        # 6
        log.debug("installing flow for %s.%i -> %s.%i" %
                  (packet.src, event.port, packet.dst, port))
        msg = of.ofp_flow_mod()
        msg.match = of.ofp_match.from_packet(packet, event.port)
        msg.idle_timeout = 10
        msg.hard_timeout = 30
        msg.actions.append(of.ofp_action_output(port = port))
        msg.data = event.ofp # 6a
        self.connection.send(msg)
    
class l2_learning (object):
  """
  Waits for OpenFlow switches to connect and makes them learning switches.
  """
  def __init__ (self, transparent):
    core.openflow.addListeners(self)
    self.transparent = transparent

  def _handle_ConnectionUp (self, event):
    log.debug("Connection %s" % (event.connection,))
    log.debug("\nSwiitch %s has come up.\n",dpid_to_str(event.dpid))
    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")

  # page no 12-13 of pox wiki explains core.registerNew()---> Registering Components
  core.registerNew(l2_learning, str_to_bool(transparent))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sendToDPID_wireshark.png
Type: image/png
Size: 144085 bytes
Desc: not available
URL: <http://lists.noxrepo.org/pipermail/pox-dev-noxrepo.org/attachments/20130705/59e259b2/attachment-0001.png>


More information about the pox-dev mailing list