blob: 0a6d2419a288a67af883a55366e217231fba802e [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
Dan Talaycof75360a2010-02-05 22:22:54 -080017"""
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
Dan Talaycoac1cb812010-02-06 20:34:18 -080031
32 Data members inherited from ofp_error_msg:
33 @arg type
34 @arg code
35 @arg data: Binary string following message members
36
Dan Talaycof75360a2010-02-05 22:22:54 -080037 \"""
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 Talayco6d2470b2010-02-07 22:59:49 -080049 return packed
Dan Talaycof75360a2010-02-05 22:22:54 -080050
51 def unpack(self, binary_string):
52 binary_string = ofp_error_msg.unpack(self, binary_string)
53 self.data = binary_string
Dan Talayco6d2470b2010-02-07 22:59:49 -080054 return ""
Dan Talaycof75360a2010-02-05 22:22:54 -080055
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 Talayco6d2470b2010-02-07 22:59:49 -080062 print prefix + "data is of length " + str(len(self.data))
63 ##@todo Consider trying to parse the string
64
Dan Talaycof75360a2010-02-05 22:22:54 -080065"""
66
67error_types = [
68 'hello_failed',
69 'bad_request',
70 'bad_action',
71 'flow_mod_failed',
72 'port_mod_failed',
73 'queue_op_failed']
74
75for 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