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 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(""" }; """)