loxi-prep: move header fields into the message classes
diff --git a/src/python/oftest/base_tests.py b/src/python/oftest/base_tests.py
index 5c6c9cf..9d905f9 100644
--- a/src/python/oftest/base_tests.py
+++ b/src/python/oftest/base_tests.py
@@ -44,7 +44,7 @@
reply, pkt = self.controller.transact(request)
self.assertTrue(reply is not None,
"Did not complete features_request for handshake")
- if reply.header.version == 1:
+ if reply.version == 1:
self.supported_actions = reply.actions
logging.info("Supported actions: " + hex(self.supported_actions))
except:
diff --git a/src/python/oftest/controller.py b/src/python/oftest/controller.py
index 6fd88f5..cd7bbcf 100644
--- a/src/python/oftest/controller.py
+++ b/src/python/oftest/controller.py
@@ -254,26 +254,26 @@
if hdr.type == ofp.OFPT_ECHO_REQUEST:
self.logger.debug("Responding to echo request")
rep = ofp.message.echo_reply()
- rep.header.xid = hdr.xid
+ rep.xid = hdr.xid
# Ignoring additional data
self.message_send(rep.pack(), zero_xid=True)
continue
# Log error messages
if hdr.type == ofp.OFPT_ERROR:
- if msg.type in ofp.ofp_error_type_map:
- type_str = ofp.ofp_error_type_map[msg.type]
- if msg.type == ofp.OFPET_HELLO_FAILED:
+ 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:
code_map = ofp.ofp_hello_failed_code_map
- elif msg.type == ofp.OFPET_BAD_REQUEST:
+ elif msg.err_type == ofp.OFPET_BAD_REQUEST:
code_map = ofp.ofp_bad_request_code_map
- elif msg.type == ofp.OFPET_BAD_ACTION:
+ elif msg.err_type == ofp.OFPET_BAD_ACTION:
code_map = ofp.ofp_bad_action_code_map
- elif msg.type == ofp.OFPET_FLOW_MOD_FAILED:
+ elif msg.err_type == ofp.OFPET_FLOW_MOD_FAILED:
code_map = ofp.ofp_flow_mod_failed_code_map
- elif msg.type == ofp.OFPET_PORT_MOD_FAILED:
+ elif msg.err_type == ofp.OFPET_PORT_MOD_FAILED:
code_map = ofp.ofp_port_mod_failed_code_map
- elif msg.type == ofp.OFPET_QUEUE_OP_FAILED:
+ elif msg.err_type == ofp.OFPET_QUEUE_OP_FAILED:
code_map = ofp.ofp_queue_op_failed_code_map
else:
code_map = None
@@ -285,7 +285,7 @@
else:
type_str = "unknown"
self.logger.warn("Received error message: xid=%d type=%s (%d) code=%s (%d)",
- hdr.xid, type_str, msg.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
@@ -592,8 +592,8 @@
self.logger.debug("Looking for %s" % ofp.ofp_type_map[exp_msg])
for i in range(len(self.packets)):
msg = self.packets[i][0]
- self.logger.debug("Checking packets[%d] (%s)" % (i, ofp.ofp_type_map[msg.header.type]))
- if msg.header.type == exp_msg:
+ self.logger.debug("Checking packets[%d] (%s)" % (i, ofp.ofp_type_map[msg.type]))
+ if msg.type == exp_msg:
(msg, pkt) = self.packets.pop(i)
return (msg, pkt)
# Not found
@@ -626,21 +626,21 @@
"""
- if not zero_xid and msg.header.xid == 0:
- msg.header.xid = ofutils.gen_xid()
+ if not zero_xid and msg.xid == 0:
+ msg.xid = ofutils.gen_xid()
- self.logger.debug("Running transaction %d" % msg.header.xid)
+ self.logger.debug("Running transaction %d" % msg.xid)
with self.xid_cv:
if self.xid:
self.logger.error("Can only run one transaction at a time")
return (None, None)
- self.xid = msg.header.xid
+ self.xid = msg.xid
self.xid_response = None
self.message_send(msg.pack())
- self.logger.debug("Waiting for transaction %d" % msg.header.xid)
+ self.logger.debug("Waiting for transaction %d" % msg.xid)
ofutils.timed_wait(self.xid_cv, lambda: self.xid_response, timeout=timeout)
if self.xid_response:
@@ -670,8 +670,8 @@
raise Exception("no socket")
#@todo If not string, try to pack
if type(msg) != type(""):
- if msg.header.xid == 0 and not zero_xid:
- msg.header.xid = ofutils.gen_xid()
+ if msg.xid == 0 and not zero_xid:
+ msg.xid = ofutils.gen_xid()
outpkt = msg.pack()
else:
outpkt = msg
diff --git a/src/python/oftest/illegal_message.py b/src/python/oftest/illegal_message.py
index eeb5022..2d0ce7b 100644
--- a/src/python/oftest/illegal_message.py
+++ b/src/python/oftest/illegal_message.py
@@ -6,26 +6,36 @@
ILLEGAL_MESSAGE_TYPE=217
-class illegal_message_type:
+class illegal_message_type(of10.ofp_header):
"""
- Wrapper class for illegal message
+ Wrapper class for illegal_message_type
OpenFlow message header: length, version, xid, type
@arg length: The total length of the message
@arg version: The OpenFlow version (1)
@arg xid: The transaction ID
- @arg type: The message type (OFPT_ECHO_REQUEST=2)
+ @arg type: The message type (ILLEGAL_MESSAGE_TYPE=217)
+ Data members inherited from ofp_header:
+ @arg version
+ @arg type
+ @arg length
+ @arg xid
@arg data: Binary string following message members
- The message type is set to "illegal" and the pack assert
- check for the OF header is disabled
"""
- def __init__(self):
- self.header = of10.ofp_header()
- self.header.type = ILLEGAL_MESSAGE_TYPE
+ def __init__(self, **kwargs):
+ of10.ofp_header.__init__(self)
+ self.version = of10.OFP_VERSION
+ self.type = ILLEGAL_MESSAGE_TYPE
self.data = ""
+ for (k, v) in kwargs.items():
+ if hasattr(self, k):
+ setattr(self, k, v)
+ else:
+ raise NameError("field %s does not exist in %s" % (k, self.__class__))
+
def pack(self):
"""
@@ -34,9 +44,10 @@
@return The packed string which can go on the wire
"""
- self.header.length = len(self)
- packed = self.header.pack(assertstruct=False)
+ self.length = len(self)
+ packed = ""
+ packed += of10.ofp_header.pack(self, assertstruct=False)
packed += self.data
return packed
@@ -49,8 +60,8 @@
@return The remainder of binary_string that was not parsed.
"""
- binary_string = self.header.unpack(binary_string)
+ binary_string = of10.ofp_header.unpack(self, binary_string)
self.data = binary_string
binary_string = ''
return binary_string
@@ -63,8 +74,9 @@
string.
"""
- length = of10.OFP_HEADER_BYTES
+ length = 0
+ length += of10.ofp_header.__len__(self)
length += len(self.data)
return length
@@ -77,12 +89,18 @@
"""
- outstr = prefix + 'illegal_message (' + \
- str(ILLEGAL_MESSAGE_TYPE) + ')\n'
+ outstr = prefix + 'illegal_message (217)\n'
prefix += ' '
outstr += prefix + 'ofp header\n'
- outstr += self.header.show(prefix + ' ')
+ outstr += of10.ofp_header.show(self, prefix)
outstr += prefix + 'data is of length ' + str(len(self.data)) + '\n'
+ ##@todo Fix this circular reference
+ # if len(self.data) > 0:
+ # obj = of_message_parse(self.data)
+ # if obj != None:
+ # outstr += obj.show(prefix)
+ # else:
+ # outstr += prefix + "Unable to parse data\n"
return outstr
def __eq__(self, other):
@@ -93,8 +111,8 @@
"""
if type(self) != type(other): return False
- if not self.header.__eq__(other.header): return False
+ if not of10.ofp_header.__eq__(self, other): return False
if self.data != other.data: return False
return True