blob: 7dff087d04f907946270e7e41de77948ec4deaba [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
7
8print """
9# Python OpenFlow error wrapper classes
10
11from ofp import *
12
13# This will never happen; done to avoid lint warning
14if __name__ == '__main__':
15 def of_message_parse(msg): return None
16
17"""
18
19################################################################
20#
21# Error message subclasses
22#
23################################################################
24
25# Template for error subclasses
26
27template = """
28class --TYPE--_error_msg(ofp_error_msg):
29 \"""
30 Wrapper class for --TYPE-- error message class
31 \"""
32 def __init__(self):
33 ofp_error_msg.__init__(self)
34 self.header = ofp_header()
35 self.header.type = OFPT_ERROR
36 self.type = --ERROR_NAME--
37 self.data = ""
38
39 def pack(self, assertstruct=True):
40 self.header.length = self.__len__()
41 packed = ofp_error_msg.pack(self)
42 packed += self.data
43
44 def unpack(self, binary_string):
45 binary_string = ofp_error_msg.unpack(self, binary_string)
46 self.data = binary_string
47 return []
48
49 def __len__(self):
50 return OFP_HEADER_BYTES + OFP_ERROR_MSG_BYTES + len(self.data)
51
52 def show(self, prefix=''):
53 print prefix + "--TYPE--_error_msg"
54 ofp_error_msg.show(self)
55 print prefix + "data is of length " + len(self.data)
56 obj = of_message_parse(self.data)
57 if obj != None:
58 obj.show()
59 else:
60 print prefix + "Unable to parse data"
61"""
62
63error_types = [
64 'hello_failed',
65 'bad_request',
66 'bad_action',
67 'flow_mod_failed',
68 'port_mod_failed',
69 'queue_op_failed']
70
71for t in error_types:
72 error_name = "OFPET_" + t.upper()
73 to_print = re.sub('--TYPE--', t, template)
74 to_print = re.sub('--ERROR_NAME--', error_name, to_print)
75 print to_print