blob: 65a12938cbba71920e58e2bca0e2dfe8859b0f08 [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
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=''):
80 print prefix + "action_--TYPE--"
81 --PARENT_TYPE--.show(self, prefix)
82"""
83
84if __name__ == '__main__':
85 for (t, parent) in action_class_map.items():
Dan Talaycoac1cb812010-02-06 20:34:18 -080086 if not parent in class_to_members_map.keys():
87 doc_info = "Unknown parent action class: " + parent
88 else:
89 doc_info = "Data members inherited from " + parent + ":\n"
90 for var in class_to_members_map[parent]:
91 doc_info += " @arg " + var + "\n"
Dan Talaycof75360a2010-02-05 22:22:54 -080092 action_name = "OFPAT_" + t.upper()
93 to_print = re.sub('--TYPE--', t, template)
94 to_print = re.sub('--PARENT_TYPE--', parent, to_print)
95 to_print = re.sub('--ACTION_NAME--', action_name, to_print)
Dan Talaycoac1cb812010-02-06 20:34:18 -080096 to_print = re.sub('--DOC_INFO--', doc_info, to_print)
Dan Talaycof75360a2010-02-05 22:22:54 -080097 print to_print
98
99 # Generate a list of action classes
100 print "action_class_list = ("
101 prev = None
102 for (t, parent) in action_class_map.items():
103 if prev:
104 print " action_" + prev + ","
105 prev = t
106 print " action_" + prev + ")"