Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 1 | """This module generate Python code for OpenFlow structs. |
| 2 | |
| 3 | (C) Copyright Stanford University |
| 4 | Date December 2009 |
| 5 | Created by ykk |
| 6 | """ |
| 7 | import cpythonize |
| 8 | from config import * |
| 9 | |
| 10 | class 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 Talayco | 4f0f4a0 | 2010-02-18 15:17:24 -0800 | [diff] [blame] | 30 | self.default_values[('ofp_packet_out','buffer_id')] = 0xffffffff |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 31 | 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 Talayco | 411489d | 2010-02-12 23:03:46 -0800 | [diff] [blame] | 43 | [ ('type','ofp_type_map.keys()') ] |
Dan Talayco | f75360a | 2010-02-05 22:22:54 -0800 | [diff] [blame] | 44 | |
| 45 | class 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 |