Renamed files
oft_config ==> config
ofmsg ==> protocol
ofmsg/of_message ==> protocol/parse
ofmsg/ofp ==> protocol/cstruct
ofmsg/ofp_aux ==> protocol/class_maps
diff --git a/tools/munger/Makefile b/tools/munger/Makefile
index 9984cc0..0e40e4e 100644
--- a/tools/munger/Makefile
+++ b/tools/munger/Makefile
@@ -10,7 +10,7 @@
PYLIBOF_DIR = ${TOOLS_DIR}/pylibopenflow
-TARGET_DIR = ${TOP_DIR}/src/python/oftest/ofmsg
+TARGET_DIR = ${TOP_DIR}/src/python/oftest/protocol
# Relative to pyopenflow-pythonize exec location
OF_HEADER = include/openflow.h
@@ -19,17 +19,17 @@
ABS_OF_HEADER = ${PYLIBOF_DIR}/${OF_HEADER}
PYTHONIZE = bin/pyopenflow-pythonize.py
-OFP_GEN_CMD = (cd ${PYLIBOF_DIR} && ${PYTHONIZE} -i ${OF_HEADER} \
- ${TARGET_DIR}/ofp.py)
-OFP_AUX_INFO = ${TARGET_DIR}/ofp_aux.py
+CSTRUCT_GEN_CMD = (cd ${PYLIBOF_DIR} && ${PYTHONIZE} -i ${OF_HEADER} \
+ ${TARGET_DIR}/cstruct.py)
+CSTRUCT_AUX_INFO = ${TARGET_DIR}/class_maps.py
-# Dependencies for ofp.py
-OFP_DEP = ${ABS_OF_HEADER} $(wildcard ${PYLIBOF_DIR}/pylib/*.py)
-OFP_DEP += $(wildcard ${PYLIBOF_DIR}/pylib/of/*.py)
+# Dependencies for cstruct.py
+CSTRUCT_DEP = ${ABS_OF_HEADER} $(wildcard ${PYLIBOF_DIR}/pylib/*.py)
+CSTRUCT_DEP += $(wildcard ${PYLIBOF_DIR}/pylib/of/*.py)
# Generated and other files
-GEN_FILES := $(addprefix ${TARGET_DIR}/,ofp.py message.py error.py action.py)
-OTHER_FILES := $(addprefix ${TARGET_DIR}/,action_list.py of_message.py)
+GEN_FILES := $(addprefix ${TARGET_DIR}/,cstruct.py message.py error.py action.py)
+OTHER_FILES := $(addprefix ${TARGET_DIR}/,action_list.py parse.py)
LINT_SOURCE := ${GEN_FILES} ${OTHER_FILES}
LINT_FILES := $(subst .py,.log,${LINT_SOURCE})
LINT_FILES := $(subst ${TARGET_DIR}/,lint/,${LINT_FILES})
@@ -37,11 +37,11 @@
all: ${GEN_FILES}
# The core OpenFlow libraries generated from openflow.h
-${TARGET_DIR}/ofp.py: ${OFP_DEP}
- ${OFP_GEN_CMD} > ${OFP_AUX_INFO}
+${TARGET_DIR}/cstruct.py: ${CSTRUCT_DEP}
+ ${CSTRUCT_GEN_CMD} > ${CSTRUCT_AUX_INFO}
# General rule like src/message.py comes from scripts/message_gen.py
-${TARGET_DIR}/%.py: scripts/%_gen.py ${TARGET_DIR}/ofp.py
+${TARGET_DIR}/%.py: scripts/%_gen.py ${TARGET_DIR}/cstruct.py
python $< > $@
# The pylint files
@@ -76,7 +76,7 @@
@echo
@echo "Files generated GEN_FILES: ${GEN_FILES}"
@echo
- @echo "Dependencies for ofp.py OFP_DEP: ${OFP_DEP}"
+ @echo "Dependencies for cstruct.py CSTRUCT_DEP: ${CSTRUCT_DEP}"
@echo
@echo "Already created files OTHER_FILES: ${OTHER_FILES}"
@echo
diff --git a/tools/munger/scripts/action_gen.py b/tools/munger/scripts/action_gen.py
index 65a1293..6f9d11a 100644
--- a/tools/munger/scripts/action_gen.py
+++ b/tools/munger/scripts/action_gen.py
@@ -5,14 +5,14 @@
import re
import sys
-sys.path.append("../../src/python/oftest/ofmsg")
-from ofp import *
-from ofp_aux import class_to_members_map
+sys.path.append("../../src/python/oftest/protocol")
+from cstruct import *
+from class_maps import class_to_members_map
print """
# Python OpenFlow action wrapper classes
-from ofp import *
+from cstruct import *
"""
diff --git a/tools/munger/scripts/error_gen.py b/tools/munger/scripts/error_gen.py
index 0a6d241..d82df10 100644
--- a/tools/munger/scripts/error_gen.py
+++ b/tools/munger/scripts/error_gen.py
@@ -5,14 +5,14 @@
import re
import sys
-sys.path.append("../../src/python/oftest/ofmsg")
-from ofp import *
-from ofp_aux import class_to_members_map
+sys.path.append("../../src/python/oftest/protocol")
+from cstruct import *
+from class_maps import class_to_members_map
print """
# Python OpenFlow error wrapper classes
-from ofp import *
+from cstruct import *
"""
diff --git a/tools/munger/scripts/message_gen.py b/tools/munger/scripts/message_gen.py
index 1f93b1c..d56f20b 100644
--- a/tools/munger/scripts/message_gen.py
+++ b/tools/munger/scripts/message_gen.py
@@ -80,14 +80,14 @@
import re
import string
import sys
-sys.path.append("../../src/python/oftest/ofmsg")
-from ofp import *
-from ofp_aux import class_to_members_map
+sys.path.append("../../src/python/oftest/protocol")
+from cstruct import *
+from class_maps import class_to_members_map
message_top_matter = """
# Python OpenFlow message wrapper classes
-from ofp import *
+from cstruct import *
from action_list import action_list
# Define templates for documentation
@@ -327,10 +327,19 @@
if has_string:
_p2('self.data = ""')
- print
- _p1("def pack(self):")
- _p2("self.header.length = len(self)")
- _p2("packed = self.header.pack()")
+ print """
+
+ def pack(self):
+ \"""
+ Pack object into string
+
+ @return The packed string which can go on the wire
+
+ \"""
+ self.header.length = len(self)
+ packed = self.header.pack()
+"""
+
if has_core_members:
_p2("packed += " + parent + ".pack(self)")
if has_list:
@@ -343,9 +352,19 @@
_p2('packed += self.data')
_p2("return packed")
- print
- _p1("def unpack(self, binary_string):")
- _p2("binary_string = self.header.unpack(binary_string)")
+ print """
+ def unpack(self, binary_string):
+ \"""
+ Unpack object from a binary string
+
+ @param binary_string The wire protocol byte string holding the object
+ represented as an array of bytes.
+ @return Typically returns the remainder of binary_string that
+ was not parsed. May give a warning if that string is non-empty
+
+ \"""
+ binary_string = self.header.unpack(binary_string)
+"""
if has_core_members:
_p2("binary_string = " + parent + ".unpack(self, binary_string)")
if has_list:
@@ -369,9 +388,17 @@
_p2("# Fixme: If no self.data, add check for data remaining")
_p2("return binary_string")
- print
- _p1("def __len__(self):")
- _p2("length = OFP_HEADER_BYTES")
+ print """
+ def __len__(self):
+ \"""
+ Return the length of this object once packed into a string
+
+ @return An integer representing the number bytes in the packed
+ string.
+
+ \"""
+ length = OFP_HEADER_BYTES
+"""
if has_core_members:
_p2("length += " + parent + ".__len__(self)")
if has_list:
@@ -384,9 +411,16 @@
_p2("length += len(self.data)")
_p2("return length")
- print
- _p1("##@todo Convert this to __str__")
- _p1("def show(self, prefix=''):")
+ print """
+ ##@todo Convert this to __str__
+ def show(self, prefix=''):
+ \"""
+ Display the contents of the object in a readable manner
+
+ @param prefix Printed at the beginning of each line.
+
+ \"""
+"""
_p2("print prefix + '" + msg + " (" + msg_name + ")'")
_p2("prefix += ' '")
_p2("self.header.show(prefix)")
@@ -410,10 +444,17 @@
_p3("# else:")
_p4('# print prefix + "Unable to parse data"')
- print
- _p1("def __eq__(self, other):")
- _p2("if type(self) != type(other): return False")
- _p2("if not self.header.__eq__(other.header): return False")
+ print """
+ def __eq__(self, other):
+ \"""
+ Return True if self and other hold the same data
+
+ @param other Other object in comparison
+
+ \"""
+ if type(self) != type(other): return False
+ if not self.header.__eq__(other.header): return False
+"""
if has_core_members:
_p2("if not " + parent + ".__eq__(self, other): return False")
if has_string:
@@ -422,9 +463,16 @@
_p2("if self." + list_var + " != other." + list_var + ": return False")
_p2("return True")
- print
- _p1("def __ne__(self, other): return not self.__eq__(other)")
+ print """
+ def __ne__(self, other):
+ \"""
+ Return True if self and other do not hold the same data
+ @param other Other object in comparison
+
+ \"""
+ return not self.__eq__(other)
+ """
################################################################
diff --git a/tools/munger/tests/msg_test.py b/tools/munger/tests/msg_test.py
index b92acae..02a368c 100644
--- a/tools/munger/tests/msg_test.py
+++ b/tools/munger/tests/msg_test.py
@@ -1,9 +1,9 @@
import sys
-sys.path.append('../../../src/python/oftest/ofmsg')
+sys.path.append('../../../src/python/oftest/protocol')
from message import *
from action import *
from error import *
-from ofp_aux import *
+from class_maps import *
header_fields = ['version', 'xid']
fixed_header_fields = ['type', 'length']
@@ -171,6 +171,21 @@
print "End of class pack check"
print
+print
+
+
+print "Testing message parsing"
+print
+for cls in keys:
+ print "Creating class " + ofmsg_names[cls]
+ obj = cls()
+ print ofmsg_names[cls] + " length: " + str(len(obj))
+ obj.show(" ")
+ print
+
+print "End of class generation"
+print
+print
#