blob: 797860da9bf6e214d9e84e23294d89beedf466dd [file] [log] [blame]
Dan Talaycof75360a2010-02-05 22:22:54 -08001"""This module generate Python code for OpenFlow structs.
2
3(C) Copyright Stanford University
4Date December 2009
5Created by ykk
6"""
7import cpythonize
8from config import *
9
10class rules(cpythonize.rules):
11 """Class that specify rules for pythonization of OpenFlow messages
12
13 (C) Copyright Stanford University
14 Date December 2009
15 Created by ykk
16 """
17 def __init__(self, ofmsg):
18 """Initialize rules
19 """
20 cpythonize.rules.__init__(self)
21 ##Reference to ofmsg
22 self.__ofmsg = ofmsg
23 ##Default values for members
24 self.default_values[('ofp_header','version')] = self.__ofmsg.get_value('OFP_VERSION')
25 self.default_values[('ofp_switch_config',\
26 'miss_send_len')] = self.__ofmsg.get_value('OFP_DEFAULT_MISS_SEND_LEN')
27 for x in ['ofp_flow_mod','ofp_flow_expired','ofp_flow_stats']:
28 self.default_values[(x,'priority')] = self.__ofmsg.get_value('OFP_DEFAULT_PRIORITY')
29 #Default values for struct
30 self.struct_default[('ofp_flow_mod',
31 'header')] = ".type = OFPT_FLOW_MOD"
32# 'header')] = ".type = "+str(self.__ofmsg.get_value('OFPT_FLOW_MOD'))
33 ##Macros to exclude
34 self.excluded_macros = ['OFP_ASSERT(EXPR)','OFP_ASSERT(_EXPR)','OFP_ASSERT',
35 'icmp_type','icmp_code','OFP_PACKED',
36 'OPENFLOW_OPENFLOW_H']
37 ##Enforce mapping
38 if GEN_ENUM_VALUES_LIST:
39 self.enforced_maps['ofp_header'] = [ ('type','ofp_type_values') ]
40 elif GEN_ENUM_DICTIONARY:
41 self.enforced_maps['ofp_header'] = \
Dan Talayco411489d2010-02-12 23:03:46 -080042 [ ('type','ofp_type_map.keys()') ]
Dan Talaycof75360a2010-02-05 22:22:54 -080043
44class pythonizer(cpythonize.pythonizer):
45 """Class that pythonize C structures of OpenFlow messages
46
47 (C) Copyright Stanford University
48 Date December 2009
49 Created by ykk
50 """
51 def __init__(self, ofmsg):
52 """Initialize
53 """
54 ofrules = rules(ofmsg)
55 cpythonize.pythonizer.__init__(self, ofmsg, ofrules)
56 ##Reference to OpenFlow message class
57 self.__ofmsg = ofmsg