blob: 5a28818c6997993580e18a7d3a3603cfa1f45f70 [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
Dan Talayco4f0f4a02010-02-18 15:17:24 -080030 self.default_values[('ofp_packet_out','buffer_id')] = 0xffffffff
Dan Talaycof75360a2010-02-05 22:22:54 -080031 self.struct_default[('ofp_flow_mod',
32 'header')] = ".type = OFPT_FLOW_MOD"
33# 'header')] = ".type = "+str(self.__ofmsg.get_value('OFPT_FLOW_MOD'))
34 ##Macros to exclude
35 self.excluded_macros = ['OFP_ASSERT(EXPR)','OFP_ASSERT(_EXPR)','OFP_ASSERT',
36 'icmp_type','icmp_code','OFP_PACKED',
37 'OPENFLOW_OPENFLOW_H']
38 ##Enforce mapping
39 if GEN_ENUM_VALUES_LIST:
40 self.enforced_maps['ofp_header'] = [ ('type','ofp_type_values') ]
41 elif GEN_ENUM_DICTIONARY:
42 self.enforced_maps['ofp_header'] = \
Dan Talayco411489d2010-02-12 23:03:46 -080043 [ ('type','ofp_type_map.keys()') ]
Dan Talaycof75360a2010-02-05 22:22:54 -080044
45class pythonizer(cpythonize.pythonizer):
46 """Class that pythonize C structures of OpenFlow messages
47
48 (C) Copyright Stanford University
49 Date December 2009
50 Created by ykk
51 """
52 def __init__(self, ofmsg):
53 """Initialize
54 """
55 ofrules = rules(ofmsg)
56 cpythonize.pythonizer.__init__(self, ofmsg, ofrules)
57 ##Reference to OpenFlow message class
58 self.__ofmsg = ofmsg