blob: c66eb8fdbf904ee719473253209db8ce044c2df6 [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
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 action wrapper classes
14
15from ofp import *
16
17# This will never happen; done to avoid lint warning
18if __name__ == '__main__':
Dan Talaycoac1cb812010-02-06 20:34:18 -080019 def of_message_parse(msg):
20 print "ERROR: of_msg_parse in action.py called"
21 return None
Dan Talaycof75360a2010-02-05 22:22:54 -080022
23"""
24
25################################################################
26#
27# Action subclasses
28#
29################################################################
30
31action_structs = [
32 'output',
33 'vlan_vid',
34 'vlan_pcp',
35 'dl_addr',
36 'nw_addr',
37 'tp_port',
38 'nw_tos',
39 'vendor_header']
40
41action_types = [
42 'output',
43 'set_vlan_vid',
44 'set_vlan_pcp',
45 'strip_vlan',
46 'set_dl_src',
47 'set_dl_dst',
48 'set_nw_src',
49 'set_nw_dst',
50 'set_nw_tos',
51 'set_tp_src',
52 'set_tp_dst',
53 'enqueue',
54 'vendor'
55]
56action_types.sort()
57
58action_class_map = {
59 'output' : 'ofp_action_output',
60 'set_vlan_vid' : 'ofp_action_vlan_vid',
61 'set_vlan_pcp' : 'ofp_action_vlan_pcp',
62 'strip_vlan' : 'ofp_action_header',
63 'set_dl_src' : 'ofp_action_dl_addr',
64 'set_dl_dst' : 'ofp_action_dl_addr',
65 'set_nw_src' : 'ofp_action_nw_addr',
66 'set_nw_dst' : 'ofp_action_nw_addr',
67 'set_nw_tos' : 'ofp_action_nw_tos',
68 'set_tp_src' : 'ofp_action_tp_port',
69 'set_tp_dst' : 'ofp_action_tp_port',
70 'enqueue' : 'ofp_action_enqueue',
71 'vendor' : 'ofp_action_vendor_header'
72}
73
74template = """
75class action_--TYPE--(--PARENT_TYPE--):
76 \"""
77 Wrapper class for --TYPE-- action object
Dan Talaycoac1cb812010-02-06 20:34:18 -080078
79 --DOC_INFO--
Dan Talaycof75360a2010-02-05 22:22:54 -080080 \"""
81 def __init__(self):
82 --PARENT_TYPE--.__init__(self)
83 self.type = --ACTION_NAME--
84 self.len = self.__len__()
85 def show(self, prefix=''):
86 print prefix + "action_--TYPE--"
87 --PARENT_TYPE--.show(self, prefix)
88"""
89
90if __name__ == '__main__':
91 for (t, parent) in action_class_map.items():
Dan Talaycoac1cb812010-02-06 20:34:18 -080092 if not parent in class_to_members_map.keys():
93 doc_info = "Unknown parent action class: " + parent
94 else:
95 doc_info = "Data members inherited from " + parent + ":\n"
96 for var in class_to_members_map[parent]:
97 doc_info += " @arg " + var + "\n"
Dan Talaycof75360a2010-02-05 22:22:54 -080098 action_name = "OFPAT_" + t.upper()
99 to_print = re.sub('--TYPE--', t, template)
100 to_print = re.sub('--PARENT_TYPE--', parent, to_print)
101 to_print = re.sub('--ACTION_NAME--', action_name, to_print)
Dan Talaycoac1cb812010-02-06 20:34:18 -0800102 to_print = re.sub('--DOC_INFO--', doc_info, to_print)
Dan Talaycof75360a2010-02-05 22:22:54 -0800103 print to_print
104
105 # Generate a list of action classes
106 print "action_class_list = ("
107 prev = None
108 for (t, parent) in action_class_map.items():
109 if prev:
110 print " action_" + prev + ","
111 prev = t
112 print " action_" + prev + ")"