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 |
Dan Talayco | b9cb548 | 2010-02-09 15:23:12 -0800 | [diff] [blame] | 8 | sys.path.append("../../src/python/oftest/protocol") |
| 9 | from cstruct import * |
| 10 | from class_maps 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 | |
Dan Talayco | b9cb548 | 2010-02-09 15:23:12 -0800 | [diff] [blame] | 15 | from cstruct import * |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 16 | |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 17 | """ |
| 18 | |
| 19 | ################################################################ |
| 20 | # |
| 21 | # Error message subclasses |
| 22 | # |
| 23 | ################################################################ |
| 24 | |
| 25 | # Template for error subclasses |
| 26 | |
| 27 | template = """ |
| 28 | class --TYPE--_error_msg(ofp_error_msg): |
| 29 | \""" |
| 30 | Wrapper class for --TYPE-- error message class |
Dan Talayco | ac1cb81 | 2010-02-06 20:34:18 -0800 | [diff] [blame] | 31 | |
| 32 | Data members inherited from ofp_error_msg: |
| 33 | @arg type |
| 34 | @arg code |
| 35 | @arg data: Binary string following message members |
| 36 | |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 37 | \""" |
| 38 | def __init__(self): |
| 39 | ofp_error_msg.__init__(self) |
| 40 | self.header = ofp_header() |
| 41 | self.header.type = OFPT_ERROR |
| 42 | self.type = --ERROR_NAME-- |
| 43 | self.data = "" |
| 44 | |
| 45 | def pack(self, assertstruct=True): |
| 46 | self.header.length = self.__len__() |
| 47 | packed = ofp_error_msg.pack(self) |
| 48 | packed += self.data |
Dan Talayco | 6d2470b | 2010-02-07 22:59:49 -0800 | [diff] [blame] | 49 | return packed |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 50 | |
| 51 | def unpack(self, binary_string): |
| 52 | binary_string = ofp_error_msg.unpack(self, binary_string) |
| 53 | self.data = binary_string |
Dan Talayco | 6d2470b | 2010-02-07 22:59:49 -0800 | [diff] [blame] | 54 | return "" |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 55 | |
| 56 | def __len__(self): |
| 57 | return OFP_HEADER_BYTES + OFP_ERROR_MSG_BYTES + len(self.data) |
| 58 | |
| 59 | def show(self, prefix=''): |
| 60 | print prefix + "--TYPE--_error_msg" |
| 61 | ofp_error_msg.show(self) |
Dan Talayco | 6d2470b | 2010-02-07 22:59:49 -0800 | [diff] [blame] | 62 | print prefix + "data is of length " + str(len(self.data)) |
| 63 | ##@todo Consider trying to parse the string |
| 64 | |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 65 | """ |
| 66 | |
| 67 | error_types = [ |
| 68 | 'hello_failed', |
| 69 | 'bad_request', |
| 70 | 'bad_action', |
| 71 | 'flow_mod_failed', |
| 72 | 'port_mod_failed', |
| 73 | 'queue_op_failed'] |
| 74 | |
| 75 | for t in error_types: |
| 76 | error_name = "OFPET_" + t.upper() |
| 77 | to_print = re.sub('--TYPE--', t, template) |
| 78 | to_print = re.sub('--ERROR_NAME--', error_name, to_print) |
| 79 | print to_print |