Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | # |
| 3 | # This python script generates error subclasses |
| 4 | # |
| 5 | |
| 6 | import re |
Dan Talayco | ac1cb81 | 2010-02-06 20:34:18 -0800 | [diff] [blame] | 7 | import sys |
| 8 | sys.path.append("../../src/python/oftest/ofmsg") |
| 9 | from ofp import * |
| 10 | from ofp_aux import class_to_members_map |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 11 | |
| 12 | print """ |
| 13 | # Python OpenFlow error wrapper classes |
| 14 | |
| 15 | from ofp import * |
| 16 | |
| 17 | # This will never happen; done to avoid lint warning |
| 18 | if __name__ == '__main__': |
Dan Talayco | ac1cb81 | 2010-02-06 20:34:18 -0800 | [diff] [blame] | 19 | def of_message_parse(msg): |
| 20 | print "ERROR: of_msg_parse in error.py called" |
| 21 | return None |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 22 | |
| 23 | """ |
| 24 | |
| 25 | ################################################################ |
| 26 | # |
| 27 | # Error message subclasses |
| 28 | # |
| 29 | ################################################################ |
| 30 | |
| 31 | # Template for error subclasses |
| 32 | |
| 33 | template = """ |
| 34 | class --TYPE--_error_msg(ofp_error_msg): |
| 35 | \""" |
| 36 | Wrapper class for --TYPE-- error message class |
Dan Talayco | ac1cb81 | 2010-02-06 20:34:18 -0800 | [diff] [blame] | 37 | |
| 38 | Data members inherited from ofp_error_msg: |
| 39 | @arg type |
| 40 | @arg code |
| 41 | @arg data: Binary string following message members |
| 42 | |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 43 | \""" |
| 44 | def __init__(self): |
| 45 | ofp_error_msg.__init__(self) |
| 46 | self.header = ofp_header() |
| 47 | self.header.type = OFPT_ERROR |
| 48 | self.type = --ERROR_NAME-- |
| 49 | self.data = "" |
| 50 | |
| 51 | def pack(self, assertstruct=True): |
| 52 | self.header.length = self.__len__() |
| 53 | packed = ofp_error_msg.pack(self) |
| 54 | packed += self.data |
| 55 | |
| 56 | def unpack(self, binary_string): |
| 57 | binary_string = ofp_error_msg.unpack(self, binary_string) |
| 58 | self.data = binary_string |
| 59 | return [] |
| 60 | |
| 61 | def __len__(self): |
| 62 | return OFP_HEADER_BYTES + OFP_ERROR_MSG_BYTES + len(self.data) |
| 63 | |
| 64 | def show(self, prefix=''): |
| 65 | print prefix + "--TYPE--_error_msg" |
| 66 | ofp_error_msg.show(self) |
| 67 | print prefix + "data is of length " + len(self.data) |
| 68 | obj = of_message_parse(self.data) |
| 69 | if obj != None: |
| 70 | obj.show() |
| 71 | else: |
| 72 | print prefix + "Unable to parse data" |
| 73 | """ |
| 74 | |
| 75 | error_types = [ |
| 76 | 'hello_failed', |
| 77 | 'bad_request', |
| 78 | 'bad_action', |
| 79 | 'flow_mod_failed', |
| 80 | 'port_mod_failed', |
| 81 | 'queue_op_failed'] |
| 82 | |
| 83 | for t in error_types: |
| 84 | error_name = "OFPET_" + t.upper() |
| 85 | to_print = re.sub('--TYPE--', t, template) |
| 86 | to_print = re.sub('--ERROR_NAME--', error_name, to_print) |
| 87 | print to_print |