blob: c8f4bf25007e7b034f38889afc6526574c9eae43 [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
Rich Lane6242d9f2013-01-06 17:35:39 -08008sys.path.append("../../src/python/of10")
Dan Talaycob9cb5482010-02-09 15:23:12 -08009from cstruct import *
10from class_maps import class_to_members_map
Dan Talaycof75360a2010-02-05 22:22:54 -080011
12print """
13# Python OpenFlow error wrapper classes
14
Dan Talaycob9cb5482010-02-09 15:23:12 -080015from cstruct import *
Dan Talaycof75360a2010-02-05 22:22:54 -080016
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)
Rich Laneb73808c2013-03-11 15:22:23 -070040 self.version = OFP_VERSION
41 self.type = OFPT_ERROR
42 self.err_type = --ERROR_NAME--
Dan Talaycof75360a2010-02-05 22:22:54 -080043 self.data = ""
44
45 def pack(self, assertstruct=True):
46 self.header.length = self.__len__()
Rich Laneb73808c2013-03-11 15:22:23 -070047 packed = ""
Dan Talayco54a90e92010-02-10 22:39:38 -080048 packed += ofp_error_msg.pack(self)
Dan Talaycof75360a2010-02-05 22:22:54 -080049 packed += self.data
Dan Talayco6d2470b2010-02-07 22:59:49 -080050 return packed
Dan Talaycof75360a2010-02-05 22:22:54 -080051
52 def unpack(self, binary_string):
53 binary_string = ofp_error_msg.unpack(self, binary_string)
54 self.data = binary_string
Dan Talayco6d2470b2010-02-07 22:59:49 -080055 return ""
Dan Talaycof75360a2010-02-05 22:22:54 -080056
57 def __len__(self):
Rich Laneb73808c2013-03-11 15:22:23 -070058 return OFP_ERROR_MSG_BYTES + len(self.data)
Dan Talaycof75360a2010-02-05 22:22:54 -080059
60 def show(self, prefix=''):
Dan Talayco46755fa2010-03-09 21:44:29 -080061 outstr = prefix + "--TYPE--_error_msg\\m"
Dan Talayco46755fa2010-03-09 21:44:29 -080062 outstr += ofp_error_msg.show(self, prefix + ' ')
63 outstr += prefix + "data is of length " + str(len(self.data)) + '\\n'
Dan Talayco6d2470b2010-02-07 22:59:49 -080064 ##@todo Consider trying to parse the string
Dan Talayco46755fa2010-03-09 21:44:29 -080065 return outstr
Dan Talayco6d2470b2010-02-07 22:59:49 -080066
Dan Talayco54a90e92010-02-10 22:39:38 -080067 def __eq__(self, other):
68 if type(self) != type(other): return False
Rich Laneb73808c2013-03-11 15:22:23 -070069 return (ofp_error_msg.__eq__(self, other) and
Dan Talayco54a90e92010-02-10 22:39:38 -080070 self.data == other.data)
71
72 def __ne__(self, other): return not self.__eq__(other)
Dan Talaycof75360a2010-02-05 22:22:54 -080073"""
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