Пример #1
0
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
Пример #2
0
 def class_info(self):
     """ return tuple of (package_prefix, parent_class) for the current JavaOFInterface"""
     # FIXME: This duplicates inheritance information that is now available in the loxi_ir
     # model (note, that the loxi model is on versioned classes). Should check/infer the
     # inheritance information from the versioned lox_ir classes.
     if re.match(r'OFStatsRequest$', self.name):
         return ("", "OFMessage", "T extends OFStatsReply")
     elif re.match(r'OF.+StatsRequest$', self.name):
         return ("", "OFStatsRequest<{}>".format(re.sub(r'Request$', 'Reply', self.name)), None)
     elif re.match(r'OF.+StatsReply$', self.name):
         return ("", "OFStatsReply", None)
     elif re.match(r'OF.+ErrorMsg$', self.name):
         return ("", "OFErrorMsg", None)
     elif re.match(r'OFFlow(Add|Modify(Strict)?|Delete(Strict)?)$', self.name):
         return ("", "OFFlowMod", None)
     elif loxi_utils.class_is_message(self.c_name) and re.match(r'OFBsn.+$', self.name) and self.name != "OFBsnHeader":
         return ("", "OFBsnHeader", None)
     elif loxi_utils.class_is_message(self.c_name) and re.match(r'OFNicira.+$', self.name) and self.name != "OFNiciraHeader":
         return ("", "OFNiciraHeader", None)
     elif self.name == "OFBsnHeader" or self.name =="OFNiciraHeader":
         return ("", "OFExperimenter", None)
     elif re.match(r'OFMatch.*', self.name):
         return ("", "Match", None)
     elif loxi_utils.class_is_message(self.c_name):
         return ("", "OFMessage", None)
     elif loxi_utils.class_is_action(self.c_name):
         if re.match(r'OFActionBsn.+', self.name):
             return ("action", "OFActionBsn", None)
         elif re.match(r'OFActionNicira.+', self.name):
             return ("action", "OFActionNicira", None)
         elif self.name == "OFActionBsn" or self.name == "OFActionNicira":
             return ("action", "OFActionExperimenter", None)
         else:
             return ("action", "OFAction", None)
     elif re.match(r'OFBsnVport.+$', self.name):
         return ("", "OFBsnVport", None)
     elif self.name == "OFOxm":
         return ("oxm", None, "T extends OFValueType<T>")
     elif loxi_utils.class_is_oxm(self.c_name):
         if self.name in model.oxm_map:
             return ("oxm", "OFOxm<%s>" % model.oxm_map[self.name].type_name, None)
         else:
             return ("oxm", "OFOxm", None)
     elif loxi_utils.class_is_instruction(self.c_name):
         return ("instruction", "OFInstruction", None)
     elif loxi_utils.class_is_meter_band(self.c_name):
         return ("meterband", "OFMeterBand", None)
     elif loxi_utils.class_is_queue_prop(self.c_name):
         return ("queueprop", "OFQueueProp", None)
     elif loxi_utils.class_is_hello_elem(self.c_name):
         return ("", "OFHelloElem", None)
     elif loxi_utils.class_is_table_feature_prop(self.c_name):
         return ("", "OFTableFeatureProp", None)
     else:
         return ("", None, None)
Пример #3
0
def gen_all_java(out, name):
    """ Generate all of the java files

    @param out is an open file handle to a file called README
    @param name should be 'README' and is ignored for the java
        driver
    """
    messages = list()
    actions = list()
    instructions = list()
    matches = list()
    stat_types = list()
    queue_prop = list()
    lists = list()
    for cls in of_g.unified:
        print "! Classifying %s" % cls
        if cls in ["of_stats_reply", "of_flow_mod", "of_stats_request"]:
            continue  # doesn't work?!
        if loxi_utils.class_is_stats_message(cls):
            stat_types.append(cls)
        elif loxi_utils.class_is_message(cls):
            messages.append(cls)
        elif loxi_utils.class_is_action(cls):
            actions.append(cls)
        elif loxi_utils.class_is_instruction(cls):
            instructions.append(cls)
        elif loxi_utils.class_is_oxm(cls):
            matches.append(cls)
        elif loxi_utils.class_is_queue_prop(cls):
            queue_prop.append(cls)
        elif loxi_utils.class_is_list(cls):
            lists.append(cls)
        else:
            print "Skipping Unknown class object %s" % str(cls)
    print "Parsed "
    print "  Messages: %d" % len(messages)
    print "  Actions: %d" % len(actions)
    print "  Instructions: %d" % len(instructions)
    print "  OXM matches: %d" % len(matches)
    print "  Stat types: %d" % len(stat_types)
    print "  Queue properties: %d" % len(queue_prop)
    print "  Lists: %d" % len(lists)
    target_dir = "loxi_output/openflowj"
    basedir = "%s/%s/" % (target_dir, lang_java.file_to_subdir_map["base_java"])
    srcdir = "%s/src/main/java/org/openflow/protocol" % basedir
    print "Outputting to %s" % basedir
    if not os.path.exists(basedir):
        os.makedirs(basedir)
    java_utils.copy_prewrite_tree(basedir)
    msgs.create_message_interfaces(messages, srcdir)
    msgs.create_message_by_version(messages, srcdir)
    msgs.create_of_type_enum(messages, srcdir)
    with open("README.java-lang") as readme_src:
        out.writelines(readme_src.readlines())
    out.close()
Пример #4
0
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
Пример #5
0
 def class_info(self):
     """ return tuple of (package_prefix, parent_class) for the current JavaOFInterface"""
     # FIXME: This duplicates inheritance information that is now available in the loxi_ir
     # model (note, that the loxi model is on versioned classes). Should check/infer the
     # inheritance information from the versioned lox_ir classes.
     if re.match(r'OFStatsRequest$', self.name):
         return ("", "OFMessage", "T extends OFStatsReply")
     elif self.ir_class.is_subclassof('of_stats_request'):
         if self.ir_class.is_subclassof('of_bsn_stats_request'):
             return ("", "OFBsnStatsRequest", None)
         elif self.ir_class.is_subclassof('of_experimenter_stats_request'):
             return ("", "OFExperimenterStatsRequest", None)
         else:
             return ("", "OFStatsRequest<{}>".format(re.sub(r'Request$', 'Reply', self.name)), None)
     elif self.ir_class.is_subclassof('of_stats_reply'):
         if self.ir_class.is_subclassof('of_bsn_stats_reply'):
             return ("", "OFBsnStatsReply", None)
         elif self.ir_class.is_subclassof('of_experimenter_stats_reply'):
             return ("", "OFExperimenterStatsReply", None)
         else:
             return ("", "OFStatsReply", None)
     elif self.ir_class.is_subclassof('of_error_msg'):
         return ("errormsg", "OFErrorMsg", None)
     elif self.ir_class.is_subclassof('of_flow_mod'):
         return ("", "OFFlowMod", None)
     elif self.ir_class.is_subclassof('of_group_mod'):
         return ("", "OFGroupMod", None)
     elif self.ir_class.is_subclassof('of_bsn_header'):
         return ("", "OFBsnHeader", None)
     elif self.ir_class.is_subclassof('of_nicira_header'):
         return ("", "OFNiciraHeader", None)
     elif self.ir_class.is_subclassof('of_experimenter'):
         return ("", "OFExperimenter", None)
     elif re.match(r'OFMatch.*', self.name):
         return ("", "Match", None)
     elif self.ir_class.is_message:
         return ("", "OFMessage", None)
     elif self.ir_class.is_action:
         if self.ir_class.is_subclassof('of_action_bsn'):
             return ("action", "OFActionBsn", None)
         elif self.ir_class.is_subclassof('of_action_nicira'):
             return ("action", "OFActionNicira", None)
         elif self.ir_class.is_subclassof('of_action_experimenter'):
             return ("action", "OFActionExperimenter", None)
         else:
             return ("action", "OFAction", None)
     elif self.ir_class.is_instanceof("of_action_id"):
         if self.ir_class.is_subclassof('of_action_id_bsn'):
             return ("actionid", "OFActionIdBsn", None)
         elif self.ir_class.is_subclassof('of_action_id_nicira'):
             return ("actionid", "OFActionIdNicira", None)
         elif self.ir_class.is_subclassof('of_action_id_experimenter'):
             return ("actionid", "OFActionIdExperimenter", None)
         else:
             return ("actionid", "OFActionId", None)
     elif self.ir_class.is_instruction:
         if self.ir_class.is_subclassof('of_instruction_bsn'):
             return ("instruction", "OFInstructionBsn", None)
         elif self.ir_class.is_subclassof('of_instruction_experimenter'):
             return ("instruction", "OFInstructionExperimenter", None)
         else:
             return ("instruction", "OFInstruction", None)
     elif self.ir_class.is_instanceof('of_instruction_id'):
         if self.ir_class.is_subclassof('of_instruction_id_bsn'):
             return ("instructionid", "OFInstructionIdBsn", None)
         elif self.ir_class.is_subclassof('of_instruction_id_experimenter'):
             return ("instructionid", "OFInstructionIdExperimenter", None)
         else:
             return ("instructionid", "OFInstructionId", None)
     elif re.match(r'OFBsnVport.+$', self.name):
         return ("", "OFBsnVport", None)
     elif self.name == "OFOxm":
         return ("oxm", None, "T extends OFValueType<T>")
     elif loxi_utils.class_is_oxm(self.c_name):
         if self.member_by_name("value") is not None:
             return ("oxm", "OFOxm<%s>" % self.member_by_name("value").java_type.public_type, None)
         else:
             return ("oxm", "OFOxm", None)
     elif loxi_utils.class_is_instruction(self.c_name):
         return ("instruction", "OFInstruction", None)
     elif loxi_utils.class_is_meter_band(self.c_name):
         return ("meterband", "OFMeterBand", None)
     elif loxi_utils.class_is_queue_prop(self.c_name):
         return ("queueprop", "OFQueueProp", None)
     elif loxi_utils.class_is_hello_elem(self.c_name):
         return ("", "OFHelloElem", None)
     elif loxi_utils.class_is_table_feature_prop(self.c_name):
         return ("", "OFTableFeatureProp", None)
     elif loxi_utils.class_is_bsn_tlv(self.c_name):
         return ("bsntlv", "OFBsnTlv", None)
     else:
         return ("", None, None)