blob: 9fce70d5fdfb040b7111d9d2af5445458840aa67 [file] [log] [blame]
Dan Talaycof75360a2010-02-05 22:22:54 -08001#!/usr/bin/python
2#
3# This python script generates error subclasses
4#
5
6import re
Dan Talaycoac1cb812010-02-06 20:34:18 -08007import sys
8sys.path.append("../../src/python/oftest/ofmsg")
9from ofp import *
10from ofp_aux import class_to_members_map
Dan Talaycof75360a2010-02-05 22:22:54 -080011
12print """
13# Python OpenFlow error wrapper classes
14
15from ofp import *
16
17# This will never happen; done to avoid lint warning
18if __name__ == '__main__':
Dan Talaycoac1cb812010-02-06 20:34:18 -080019 def of_message_parse(msg):
20 print "ERROR: of_msg_parse in error.py called"
21 return None
Dan Talaycof75360a2010-02-05 22:22:54 -080022
23"""
24
25################################################################
26#
27# Error message subclasses
28#
29################################################################
30
31# Template for error subclasses
32
33template = """
34class --TYPE--_error_msg(ofp_error_msg):
35 \"""
36 Wrapper class for --TYPE-- error message class
Dan Talaycoac1cb812010-02-06 20:34:18 -080037
38 Data members inherited from ofp_error_msg:
39 @arg type
40 @arg code
41 @arg data: Binary string following message members
42
Dan Talaycof75360a2010-02-05 22:22:54 -080043 \"""
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
75error_types = [
76 'hello_failed',
77 'bad_request',
78 'bad_action',
79 'flow_mod_failed',
80 'port_mod_failed',
81 'queue_op_failed']
82
83for 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