blob: 512a567949ea2811050b4e7af1419bffa37327fe [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
Rich Lane8fbfd662013-03-11 15:30:44 -070042 self.xid = None
Rich Laneb73808c2013-03-11 15:22:23 -070043 self.err_type = --ERROR_NAME--
Dan Talaycof75360a2010-02-05 22:22:54 -080044 self.data = ""
45
46 def pack(self, assertstruct=True):
47 self.header.length = self.__len__()
Rich Laneb73808c2013-03-11 15:22:23 -070048 packed = ""
Dan Talayco54a90e92010-02-10 22:39:38 -080049 packed += ofp_error_msg.pack(self)
Dan Talaycof75360a2010-02-05 22:22:54 -080050 packed += self.data
Dan Talayco6d2470b2010-02-07 22:59:49 -080051 return packed
Dan Talaycof75360a2010-02-05 22:22:54 -080052
53 def unpack(self, binary_string):
54 binary_string = ofp_error_msg.unpack(self, binary_string)
55 self.data = binary_string
Dan Talayco6d2470b2010-02-07 22:59:49 -080056 return ""
Dan Talaycof75360a2010-02-05 22:22:54 -080057
58 def __len__(self):
Rich Laneb73808c2013-03-11 15:22:23 -070059 return OFP_ERROR_MSG_BYTES + len(self.data)
Dan Talaycof75360a2010-02-05 22:22:54 -080060
61 def show(self, prefix=''):
Dan Talayco46755fa2010-03-09 21:44:29 -080062 outstr = prefix + "--TYPE--_error_msg\\m"
Dan Talayco46755fa2010-03-09 21:44:29 -080063 outstr += ofp_error_msg.show(self, prefix + ' ')
64 outstr += prefix + "data is of length " + str(len(self.data)) + '\\n'
Dan Talayco6d2470b2010-02-07 22:59:49 -080065 ##@todo Consider trying to parse the string
Dan Talayco46755fa2010-03-09 21:44:29 -080066 return outstr
Dan Talayco6d2470b2010-02-07 22:59:49 -080067
Dan Talayco54a90e92010-02-10 22:39:38 -080068 def __eq__(self, other):
69 if type(self) != type(other): return False
Rich Laneb73808c2013-03-11 15:22:23 -070070 return (ofp_error_msg.__eq__(self, other) and
Dan Talayco54a90e92010-02-10 22:39:38 -080071 self.data == other.data)
72
73 def __ne__(self, other): return not self.__eq__(other)
Dan Talaycof75360a2010-02-05 22:22:54 -080074"""
75
76error_types = [
77 'hello_failed',
78 'bad_request',
79 'bad_action',
80 'flow_mod_failed',
81 'port_mod_failed',
82 'queue_op_failed']
83
84for t in error_types:
85 error_name = "OFPET_" + t.upper()
86 to_print = re.sub('--TYPE--', t, template)
87 to_print = re.sub('--ERROR_NAME--', error_name, to_print)
88 print to_print