loxi-prep: change parse_header to return a tuple
diff --git a/src/python/oftest/controller.py b/src/python/oftest/controller.py
index 88e0ffb..f26b2d4 100644
--- a/src/python/oftest/controller.py
+++ b/src/python/oftest/controller.py
@@ -167,6 +167,8 @@
Currently filters packet in messages
@return Boolean, True if packet should be dropped
"""
+ # XXX didn't actually check for packet-in...
+ return False
# Add check for packet in and rate limit
if self.filter_packet_in:
# If we were dropping packets, report number dropped
@@ -203,33 +205,28 @@
# Process each of the OF msgs inside the pkt
offset = 0
while offset < len(pkt):
+ if offset + 8 > len(pkt):
+ break
+
# Parse the header to get type
- hdr = ofp.message.parse_header(pkt[offset:])
- if not hdr or hdr.length == 0:
- self.logger.error("Could not parse header")
- self.logger.error("pkt len %d." % len(pkt))
- if hdr:
- self.logger.error("hdr len %d." % hdr.length)
- self.logger.error("%s" % hex_dump_buffer(pkt[:200]))
- self.shutdown()
- return
+ hdr_version, hdr_type, hdr_length, hdr_xid = ofp.message.parse_header(pkt[offset:])
# Extract the raw message bytes
- if (offset + hdr.length) > len(pkt):
+ if (offset + hdr_length) > len(pkt):
break
- rawmsg = pkt[offset : offset + hdr.length]
- offset += hdr.length
+ rawmsg = pkt[offset : offset + hdr_length]
+ offset += hdr_length
- if self.filter_packet(rawmsg, hdr):
- continue
+ #if self.filter_packet(rawmsg, hdr):
+ # continue
- self.logger.debug("Msg in: buf len %d. hdr.type %s. hdr.len %d hdr.version %d hdr.xid %d" %
- (len(pkt), ofp.ofp_type_map[hdr.type], hdr.length, hdr.version, hdr.xid))
- if hdr.version < ofp.OFP_VERSION:
+ self.logger.debug("Msg in: buf len %d. hdr_type %s. hdr_len %d hdr_version %d hdr_xid %d" %
+ (len(pkt), ofp.ofp_type_map[hdr_type], hdr_length, hdr_version, hdr_xid))
+ if hdr_version < ofp.OFP_VERSION:
self.logger.error("Switch only supports up to OpenFlow version %d (OFTest version is %d)",
- hdr.version, ofp.OFP_VERSION)
+ hdr_version, ofp.OFP_VERSION)
print "Switch only supports up to OpenFlow version %d (OFTest version is %d)" % \
- (hdr.version, ofp.OFP_VERSION)
+ (hdr_version, ofp.OFP_VERSION)
self.disconnect()
return
@@ -242,8 +239,8 @@
with self.sync:
# Check if transaction is waiting
with self.xid_cv:
- if self.xid and hdr.xid == self.xid:
- self.logger.debug("Matched expected XID " + str(hdr.xid))
+ if self.xid and hdr_xid == self.xid:
+ self.logger.debug("Matched expected XID " + str(hdr_xid))
self.xid_response = (msg, rawmsg)
self.xid = None
self.xid_cv.notify()
@@ -251,16 +248,16 @@
# Check if keep alive is set; if so, respond to echo requests
if self.keep_alive:
- if hdr.type == ofp.OFPT_ECHO_REQUEST:
+ if hdr_type == ofp.OFPT_ECHO_REQUEST:
self.logger.debug("Responding to echo request")
rep = ofp.message.echo_reply()
- rep.xid = hdr.xid
+ rep.xid = hdr_xid
# Ignoring additional data
self.message_send(rep.pack())
continue
# Log error messages
- if hdr.type == ofp.OFPT_ERROR:
+ if hdr_type == ofp.OFPT_ERROR:
if msg.err_type in ofp.ofp_error_type_map:
type_str = ofp.ofp_error_type_map[msg.err_type]
if msg.err_type == ofp.OFPET_HELLO_FAILED:
@@ -285,18 +282,18 @@
else:
type_str = "unknown"
self.logger.warn("Received error message: xid=%d type=%s (%d) code=%s (%d)",
- hdr.xid, type_str, msg.err_type, code_str, msg.code)
+ hdr_xid, type_str, msg.err_type, code_str, msg.code)
# Now check for message handlers; preference is given to
# handlers for a specific packet
handled = False
- if hdr.type in self.handlers.keys():
- handled = self.handlers[hdr.type](self, msg, rawmsg)
+ if hdr_type in self.handlers.keys():
+ handled = self.handlers[hdr_type](self, msg, rawmsg)
if not handled and ("all" in self.handlers.keys()):
handled = self.handlers["all"](self, msg, rawmsg)
if not handled: # Not handled, enqueue
- self.logger.debug("Enqueuing pkt type " + ofp.ofp_type_map[hdr.type])
+ self.logger.debug("Enqueuing pkt type " + ofp.ofp_type_map[hdr_type])
with self.packets_cv:
if len(self.packets) >= self.max_pkts:
self.packets.pop(0)