def get_type_values(cls, version): """ Returns a map from the name of the type member to its value. """ type_values = {} # Primary wire type if utils.class_is_message(cls): type_values['version'] = 'const.OFP_VERSION' type_values['type'] = util.constant_for_value(version, "ofp_type", util.primary_wire_type(cls, version)) if cls in type_maps.flow_mod_list: type_values['_command'] = util.constant_for_value(version, "ofp_flow_mod_command", type_maps.flow_mod_types[version][cls[8:]]) if cls in type_maps.stats_request_list: type_values['stats_type'] = util.constant_for_value(version, "ofp_stats_types", type_maps.stats_types[version][cls[3:-14]]) if cls in type_maps.stats_reply_list: type_values['stats_type'] = util.constant_for_value(version, "ofp_stats_types", type_maps.stats_types[version][cls[3:-12]]) if type_maps.message_is_extension(cls, version): type_values['experimenter'] = '%#x' % type_maps.extension_to_experimenter_id(cls) type_values['subtype'] = type_maps.extension_message_to_subtype(cls, version) elif utils.class_is_action(cls): type_values['type'] = util.constant_for_value(version, "ofp_action_type", util.primary_wire_type(cls, version)) if type_maps.action_is_extension(cls, version): type_values['experimenter'] = '%#x' % type_maps.extension_to_experimenter_id(cls) type_values['subtype'] = type_maps.extension_action_to_subtype(cls, version) elif utils.class_is_queue_prop(cls): type_values['type'] = util.constant_for_value(version, "ofp_queue_properties", util.primary_wire_type(cls, version)) return type_values
def get_type_values(cls, version): """ Returns a map from the name of the type member to its value. """ type_values = {} # Primary wire type if utils.class_is_message(cls): type_values['version'] = 'const.OFP_VERSION' type_values['type'] = util.constant_for_value(version, "ofp_type", util.primary_wire_type(cls, version)) if cls in type_maps.flow_mod_list: type_values['_command'] = util.constant_for_value(version, "ofp_flow_mod_command", type_maps.flow_mod_types[version][cls[8:]]) if cls in type_maps.stats_request_list: type_values['stats_type'] = util.constant_for_value(version, "ofp_stats_types", type_maps.stats_types[version][cls[3:-14]]) if cls in type_maps.stats_reply_list: type_values['stats_type'] = util.constant_for_value(version, "ofp_stats_types", type_maps.stats_types[version][cls[3:-12]]) if type_maps.message_is_extension(cls, version): type_values['experimenter'] = '%#x' % type_maps.extension_to_experimenter_id(cls) type_values['subtype'] = type_maps.extension_message_to_subtype(cls, version) elif utils.class_is_action(cls): type_values['type'] = util.constant_for_value(version, "ofp_action_type", util.primary_wire_type(cls, version)) if type_maps.action_is_extension(cls, version): type_values['experimenter'] = '%#x' % type_maps.extension_to_experimenter_id(cls) type_values['subtype'] = type_maps.extension_action_to_subtype(cls, version) elif utils.class_is_queue_prop(cls): type_values['type'] = util.constant_for_value(version, "ofp_queue_properties", util.primary_wire_type(cls, version)) elif utils.class_is_hello_elem(cls): type_values['type'] = util.constant_for_value(version, "ofp_hello_elem_type", util.primary_wire_type(cls, version)) elif utils.class_is_oxm(cls): oxm_class = 0x8000 oxm_type = util.primary_wire_type(cls, version) oxm_masked = cls.find('masked') != -1 and 1 or 0 oxm_len = of_g.base_length[(cls, version)] - 4 type_values['type_len'] = '%#x' % (oxm_class << 16 | oxm_type << 8 | \ oxm_masked << 8 | oxm_len) elif cls == "of_match_v2": type_values['type'] = 0 elif cls == "of_match_v3": type_values['type'] = 1 elif utils.class_is_meter_band(cls): type_values['type'] = util.constant_for_value(version, "ofp_meter_band_type", util.primary_wire_type(cls, version)) elif utils.class_is_instruction(cls): type_values['type'] = util.constant_for_value(version, "ofp_instruction_type", util.primary_wire_type(cls, version)) return type_values
def primary_wire_type(cls, version): if cls in type_maps.stats_reply_list: return type_maps.type_val[("of_stats_reply", version)] elif cls in type_maps.stats_request_list: return type_maps.type_val[("of_stats_request", version)] elif cls in type_maps.flow_mod_list: return type_maps.type_val[("of_flow_mod", version)] elif (cls, version) in type_maps.type_val: return type_maps.type_val[(cls, version)] elif type_maps.message_is_extension(cls, version): return type_maps.type_val[("of_experimenter", version)] elif type_maps.action_is_extension(cls, version): return type_maps.type_val[("of_action_experimenter", version)] elif type_maps.action_id_is_extension(cls, version): return type_maps.type_val[("of_action_id_experimenter", version)] elif type_maps.instruction_is_extension(cls, version): return type_maps.type_val[("of_instruction_experimenter", version)] elif type_maps.queue_prop_is_extension(cls, version): return type_maps.type_val[("of_queue_prop_experimenter", version)] elif type_maps.table_feature_prop_is_extension(cls, version): return type_maps.type_val[("of_table_feature_prop_experimenter", version)] else: raise ValueError
def is_extension(self): return type_maps.message_is_extension(self.c_name, -1)
def gen_object_id_to_type(out): out.write(""" /** * Map from object ID to primary wire type * * For messages, this is the header type; in particular for stats, this is * the common stats request/response type. For per-stats types, use the * stats type map. For things like actions, instructions or queue-props, * this gives the "sub type". */ """) for version in of_g.of_version_range: out.write("static const int\nof_object_to_type_map_v%d[OF_OBJECT_COUNT] = {\n" %version) out.write(" -1, /* of_object, not a valid specific type */\n") for j, cls in enumerate(of_g.all_class_order): comma = "" if j < len(of_g.all_class_order) - 1: # Avoid ultimate comma comma = "," if cls in type_maps.stats_reply_list: out.write(" %d%s /* %s */\n" % (type_maps.type_val[("of_stats_reply", version)], comma, cls)) elif cls in type_maps.stats_request_list: out.write(" %d%s /* %s */\n" % (type_maps.type_val[("of_stats_request", version)], comma, cls)) elif cls in type_maps.flow_mod_list: out.write(" %d%s /* %s */\n" % (type_maps.type_val[("of_flow_mod", version)], comma, cls)) elif (cls, version) in type_maps.type_val: out.write(" %d%s /* %s */\n" % (type_maps.type_val[(cls, version)], comma, cls)) elif type_maps.message_is_extension(cls, version): out.write(" %d%s /* %s */\n" % (type_maps.type_val[("of_experimenter", version)], comma, cls)) elif type_maps.action_is_extension(cls, version): out.write(" %d%s /* %s */\n" % (type_maps.type_val[("of_action_experimenter", version)], comma, cls)) elif type_maps.action_id_is_extension(cls, version): out.write(" %d%s /* %s */\n" % (type_maps.type_val[("of_action_id_experimenter", version)], comma, cls)) elif type_maps.instruction_is_extension(cls, version): out.write(" %d%s /* %s */\n" % (type_maps.type_val[("of_instruction_experimenter", version)], comma, cls)) elif type_maps.queue_prop_is_extension(cls, version): out.write(" %d%s /* %s */\n" % (type_maps.type_val[("of_queue_prop_experimenter", version)], comma, cls)) elif type_maps.table_feature_prop_is_extension(cls, version): out.write(" %d%s /* %s */\n" % (type_maps.type_val[("of_table_feature_prop_experimenter", version)], comma, cls)) else: out.write(" -1%s /* %s (invalid) */\n" % (comma, cls)) out.write("};\n\n") out.write(""" /** * Unified map, indexed by wire version which is 1-based. */ const int *const of_object_to_type_map[OF_VERSION_ARRAY_MAX] = { NULL, """) for version in of_g.of_version_range: out.write(" of_object_to_type_map_v%d,\n" % version) out.write(""" }; """)
def gen_object_id_to_type(out): out.write(""" /** * Map from object ID to primary wire type * * For messages, this is the header type; in particular for stats, this is * the common stats request/response type. For per-stats types, use the * stats type map. For things like actions, instructions or queue-props, * this gives the "sub type". */ """) for version in of_g.of_version_range: out.write( "static const int\nof_object_to_type_map_v%d[OF_OBJECT_COUNT] = {\n" % version) out.write(" -1, /* of_object, not a valid specific type */\n") for j, cls in enumerate(of_g.all_class_order): comma = "" if j < len(of_g.all_class_order) - 1: # Avoid ultimate comma comma = "," if cls in type_maps.stats_reply_list: out.write(" %d%s /* %s */\n" % (type_maps.type_val[("of_stats_reply", version)], comma, cls)) elif cls in type_maps.stats_request_list: out.write(" %d%s /* %s */\n" % (type_maps.type_val[("of_stats_request", version)], comma, cls)) elif cls in type_maps.error_msg_list: out.write(" %d%s /* %s */\n" % (type_maps.type_val[("of_error_msg", version)], comma, cls)) elif cls in type_maps.flow_mod_list: out.write( " %d%s /* %s */\n" % (type_maps.type_val[("of_flow_mod", version)], comma, cls)) elif (cls, version) in type_maps.type_val: out.write(" %d%s /* %s */\n" % (type_maps.type_val[(cls, version)], comma, cls)) elif type_maps.message_is_extension(cls, version): out.write(" %d%s /* %s */\n" % (type_maps.type_val[("of_experimenter", version)], comma, cls)) elif type_maps.action_is_extension(cls, version): out.write(" %d%s /* %s */\n" % (type_maps.type_val[("of_action_experimenter", version)], comma, cls)) elif type_maps.action_id_is_extension(cls, version): out.write(" %d%s /* %s */\n" % (type_maps.type_val[("of_action_id_experimenter", version)], comma, cls)) elif type_maps.instruction_is_extension(cls, version): out.write(" %d%s /* %s */\n" % (type_maps.type_val[("of_instruction_experimenter", version)], comma, cls)) elif type_maps.queue_prop_is_extension(cls, version): out.write(" %d%s /* %s */\n" % (type_maps.type_val[("of_queue_prop_experimenter", version)], comma, cls)) elif type_maps.table_feature_prop_is_extension(cls, version): out.write( " %d%s /* %s */\n" % (type_maps.type_val[("of_table_feature_prop_experimenter", version)], comma, cls)) else: out.write(" -1%s /* %s (invalid) */\n" % (comma, cls)) out.write("};\n\n") out.write(""" /** * Unified map, indexed by wire version which is 1-based. */ const int *const of_object_to_type_map[OF_VERSION_ARRAY_MAX] = { NULL, """) for version in of_g.of_version_range: out.write(" of_object_to_type_map_v%d,\n" % version) out.write(""" }; """)