blob: 490fa541a49a9419a200f1bde498be87ef4e9466 [file] [log] [blame]
Dan Talaycof75360a2010-02-05 22:22:54 -08001#!/usr/bin/python
2#
3# This python script generates action subclasses
4#
5
6import re
Dan Talaycoac1cb812010-02-06 20:34:18 -08007import sys
Dan Talaycod7e2dbe2010-02-13 21:51:15 -08008sys.path.append("../../src/python/oftest")
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 action 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# Action subclasses
22#
23################################################################
24
25action_structs = [
26 'output',
27 'vlan_vid',
28 'vlan_pcp',
29 'dl_addr',
30 'nw_addr',
31 'tp_port',
32 'nw_tos',
33 'vendor_header']
34
35action_types = [
36 'output',
37 'set_vlan_vid',
38 'set_vlan_pcp',
39 'strip_vlan',
40 'set_dl_src',
41 'set_dl_dst',
42 'set_nw_src',
43 'set_nw_dst',
44 'set_nw_tos',
45 'set_tp_src',
46 'set_tp_dst',
47 'enqueue',
48 'vendor'
49]
50action_types.sort()
51
52action_class_map = {
53 'output' : 'ofp_action_output',
54 'set_vlan_vid' : 'ofp_action_vlan_vid',
55 'set_vlan_pcp' : 'ofp_action_vlan_pcp',
56 'strip_vlan' : 'ofp_action_header',
57 'set_dl_src' : 'ofp_action_dl_addr',
58 'set_dl_dst' : 'ofp_action_dl_addr',
59 'set_nw_src' : 'ofp_action_nw_addr',
60 'set_nw_dst' : 'ofp_action_nw_addr',
61 'set_nw_tos' : 'ofp_action_nw_tos',
62 'set_tp_src' : 'ofp_action_tp_port',
63 'set_tp_dst' : 'ofp_action_tp_port',
64 'enqueue' : 'ofp_action_enqueue',
65 'vendor' : 'ofp_action_vendor_header'
66}
67
68template = """
69class action_--TYPE--(--PARENT_TYPE--):
70 \"""
71 Wrapper class for --TYPE-- action object
Dan Talaycoac1cb812010-02-06 20:34:18 -080072
73 --DOC_INFO--
Dan Talaycof75360a2010-02-05 22:22:54 -080074 \"""
75 def __init__(self):
76 --PARENT_TYPE--.__init__(self)
77 self.type = --ACTION_NAME--
78 self.len = self.__len__()
79 def show(self, prefix=''):
Dan Talayco46755fa2010-03-09 21:44:29 -080080 outstr += prefix + "action_--TYPE--\\n"
81 outstr += --PARENT_TYPE--.show(self, prefix)
82 return outstr
Dan Talaycof75360a2010-02-05 22:22:54 -080083"""
84
85if __name__ == '__main__':
86 for (t, parent) in action_class_map.items():
Dan Talaycoac1cb812010-02-06 20:34:18 -080087 if not parent in class_to_members_map.keys():
88 doc_info = "Unknown parent action class: " + parent
89 else:
90 doc_info = "Data members inherited from " + parent + ":\n"
91 for var in class_to_members_map[parent]:
92 doc_info += " @arg " + var + "\n"
Dan Talaycof75360a2010-02-05 22:22:54 -080093 action_name = "OFPAT_" + t.upper()
94 to_print = re.sub('--TYPE--', t, template)
95 to_print = re.sub('--PARENT_TYPE--', parent, to_print)
96 to_print = re.sub('--ACTION_NAME--', action_name, to_print)
Dan Talaycoac1cb812010-02-06 20:34:18 -080097 to_print = re.sub('--DOC_INFO--', doc_info, to_print)
Dan Talaycof75360a2010-02-05 22:22:54 -080098 print to_print
99
100 # Generate a list of action classes
101 print "action_class_list = ("
102 prev = None
103 for (t, parent) in action_class_map.items():
104 if prev:
105 print " action_" + prev + ","
106 prev = t
107 print " action_" + prev + ")"