示例#1
0
    def virtual_members(self):
        virtual_members = []
        if self.ir_class.is_subclassof("of_oxm"):
            value_member = find(lambda m: m.name, self.ir_model_members)
            if value_member:
                oxm_entry = model.oxm_map[self.interface.name]
                virtual_members += [
                    JavaVirtualMember(
                        self, "matchField",
                        java_type.make_match_field_jtype(
                            value_member.java_type.public_type),
                        "MatchField.%s" % oxm_entry.value),
                    JavaVirtualMember(self, "masked", java_type.boolean,
                                      "true" if oxm_entry.masked else "false"),
                ]
            else:
                virtual_members += [
                    JavaVirtualMember(self, "matchField",
                                      java_type.make_match_field_jtype(),
                                      "null"),
                    JavaVirtualMember(self, "masked", java_type.boolean,
                                      "false"),
                ]
        if not find(lambda m: m.name == "version", self.ir_model_members):
            virtual_members.append(
                JavaVirtualMember(
                    self, "version", java_type.of_version,
                    "OFVersion.%s" % self.version.constant_version))

        return tuple(virtual_members)
示例#2
0
    def virtual_members(self):
        virtual_members = []
        if self.ir_class.is_subclassof("of_oxm"):
            value_member = find(lambda m: m.name, self.ir_model_members)
            if value_member:
                oxm_entry = model.oxm_map[self.interface.name]
                virtual_members += [
                    JavaVirtualMember(self, "matchField", java_type.make_match_field_jtype(value_member.java_type.public_type), "MatchField.%s" % oxm_entry.value),
                    JavaVirtualMember(self, "masked", java_type.boolean, "true" if oxm_entry.masked else "false"),
                    ]
            else:
                virtual_members += [
                    JavaVirtualMember(self, "matchField", java_type.make_match_field_jtype(), "null"),
                    JavaVirtualMember(self, "masked", java_type.boolean, "false"),
                 ]
        elif self.ir_class.is_subclassof("of_oxs"):
            value_member = find(lambda m: m.name, self.ir_model_members)
            if value_member:
                oxs_entry = model.oxs_map[self.interface.name]
                virtual_members += [
                    JavaVirtualMember(self, "statField", java_type.make_stat_field_jtype(value_member.java_type.public_type), "StatField.%s" % oxs_entry.value),
                    JavaVirtualMember(self, "masked", java_type.boolean, "true" if oxs_entry.masked else "false"),
                    ]
            else:
                virtual_members += [
                    JavaVirtualMember(self, "statField", java_type.make_stat_field_jtype(), "null"),
                    JavaVirtualMember(self, "masked", java_type.boolean, "false"),
                 ]
        if not find(lambda m: m.name == "version", self.ir_model_members):
            virtual_members.append(JavaVirtualMember(self, "version", java_type.of_version, "OFVersion.%s" % self.version.constant_version))

        return tuple(virtual_members)
示例#3
0
    def virtual_members(self):
        virtual_members = []
        if self.name == "OFOxm":
            virtual_members += [
                    JavaVirtualMember(self, "value", java_type.generic_t),
                    JavaVirtualMember(self, "mask", java_type.generic_t),
                    JavaVirtualMember(self, "matchField", java_type.make_match_field_jtype("T")),
                    JavaVirtualMember(self, "masked", java_type.boolean),
                    JavaVirtualMember(self, "canonical", java_type.make_oxm_jtype("T"))
                   ]
        elif self.ir_class.is_subclassof("of_oxm"):
            value = find(lambda m: m.name=="value", self.ir_model_members)
            if value:
                field_type = java_type.make_match_field_jtype(value.java_type.public_type)
            else:
                field_type = java_type.make_match_field_jtype()

            virtual_members += [
                    JavaVirtualMember(self, "matchField", field_type),
                    JavaVirtualMember(self, "masked", java_type.boolean),
                    JavaVirtualMember(self, "canonical", java_type.make_oxm_jtype(value.java_type.public_type),
                            custom_template=lambda builder: "OFOxm{}_getCanonical.java".format(".Builder" if builder else "")),
                   ]
            if not find(lambda x: x.name == "mask", self.ir_model_members):
                virtual_members.append(
                        JavaVirtualMember(self, "mask", find(lambda x: x.name == "value", self.ir_model_members).java_type))
        elif self.name =="OFErrorMsg":
            virtual_members += [ JavaVirtualMember(self, "data", java_type.error_cause_data) ]

        if not find(lambda m: m.name == "version", self.ir_model_members):
            virtual_members.append(JavaVirtualMember(self, "version", java_type.of_version))

        return tuple(virtual_members)
示例#4
0
    def virtual_members(self):
        virtual_members = []
        if self.name == "OFOxm":
            virtual_members += [
                    JavaVirtualMember(self, "value", java_type.generic_t),
                    JavaVirtualMember(self, "mask", java_type.generic_t),
                    JavaVirtualMember(self, "matchField", java_type.make_match_field_jtype("T")),
                    JavaVirtualMember(self, "masked", java_type.boolean),
                   ]
        elif self.parent_interface and self.parent_interface.startswith("OFOxm"):
            field_type = java_type.make_match_field_jtype(model.oxm_map[self.name].type_name) \
                if self.name in model.oxm_map \
                else java_type.make_match_field_jtype()

            virtual_members += [
                    JavaVirtualMember(self, "matchField", field_type),
                    JavaVirtualMember(self, "masked", java_type.boolean),
                   ]
            if not find(lambda x: x.name == "mask", self.ir_model_members):
                virtual_members.append(JavaVirtualMember(self, "mask", find(lambda x: x.name == "value", self.ir_model_members).java_type))

        if not find(lambda m: m.name == "version", self.ir_model_members):
            virtual_members.append(JavaVirtualMember(self, "version", java_type.of_version))

        return tuple(virtual_members)
示例#5
0
 def entry_by_c_name(self, name):
     res = find(lambda e: e.c_name == name, self.entries)
     if res:
         return res
     else:
         raise KeyError("Enum %s: no entry with c_name %s" %
                        (self.name, name))
示例#6
0
    def virtual_members(self):
        virtual_members = []
        if self.name == "OFOxm":
            virtual_members += [
                JavaVirtualMember(self, "value", java_type.generic_t),
                JavaVirtualMember(self, "mask", java_type.generic_t),
                JavaVirtualMember(self, "matchField",
                                  java_type.make_match_field_jtype("T")),
                JavaVirtualMember(self, "masked", java_type.boolean),
                JavaVirtualMember(self, "canonical",
                                  java_type.make_oxm_jtype("T"))
            ]
        elif self.ir_class.is_subclassof("of_oxm"):
            value = find(lambda m: m.name == "value", self.ir_model_members)
            if value:
                field_type = java_type.make_match_field_jtype(
                    value.java_type.public_type)
            else:
                field_type = java_type.make_match_field_jtype()

            virtual_members += [
                JavaVirtualMember(self, "matchField", field_type),
                JavaVirtualMember(self, "masked", java_type.boolean),
                JavaVirtualMember(
                    self,
                    "canonical",
                    java_type.make_oxm_jtype(value.java_type.public_type),
                    custom_template=lambda builder: "OFOxm{}_getCanonical.java"
                    .format(".Builder" if builder else "")),
            ]
            if not find(lambda x: x.name == "mask", self.ir_model_members):
                virtual_members.append(
                    JavaVirtualMember(
                        self, "mask",
                        find(lambda x: x.name == "value",
                             self.ir_model_members).java_type))
        elif self.name == "OFErrorMsg":
            virtual_members += [
                JavaVirtualMember(self, "data", java_type.error_cause_data)
            ]

        if not find(lambda m: m.name == "version", self.ir_model_members):
            virtual_members.append(
                JavaVirtualMember(self, "version", java_type.of_version))

        return tuple(virtual_members)
示例#7
0
def create_ofinput(ast):

    """
    Create an OFInput from an AST

    @param ast An AST as returned by loxi_front_end.parser.parse

    @returns An OFInput object
    """
    ctx = FrontendCtx(set())
    ofinput = OFInput(wire_versions=set(), classes=[], enums=[])

    for decl_ast in ast:
        if decl_ast[0] == 'struct':
            # 0: "struct"
            # 1: name
            # 2: potentially list of [param_name, param_value]
            # 3: super_class or None
            # 4: list of members
            superclass = decl_ast[3]
            members = [create_member(m_ast, ctx) for m_ast in decl_ast[4]]

            discriminators = [ m for m in members if isinstance(m, OFDiscriminatorMember) ]
            if len(discriminators) > 1:
                raise InputError("%s: Cannot support more than one discriminator by class - got %s" %
                        (decl_ast[1], repr(discriminators)))
            ofclass = OFClass(name=decl_ast[1], members=members, superclass=superclass,
                    virtual = len(discriminators) > 0,
                    params = { param: value for param, value in decl_ast[2] })
            ofinput.classes.append(ofclass)
        if decl_ast[0] == 'enum':
            # 0: "enum"
            # 1: name
            # 2: potentially list of [param_name, param_value]
            # 3: list of [constant_name, constant_value]+
            enum = OFEnum(name=decl_ast[1],
                    entries=[OFEnumEntry(name=x[0], value=x[2], params={param:value for param, value in x[1] }) for x in decl_ast[3]],
                    params = { param: value for param, value in decl_ast[2] }
                    )
            ofinput.enums.append(enum)
        elif decl_ast[0] == 'metadata':
            if decl_ast[1] == 'version':
                if decl_ast[2] == 'any':
                    ofinput.wire_versions.update(of_g.wire_ver_map.keys())
                elif int(decl_ast[2]) in of_g.supported_wire_protos:
                    ofinput.wire_versions.add(int(decl_ast[2]))
                else:
                    raise InputError("Unrecognized wire protocol version %r" % decl_ast[2])
                found_wire_version = True

    if not ofinput.wire_versions:
        raise InputError("Missing #version metadata")

    for used_enum in ctx.used_enums:
        if not find(lambda e: e.name == used_enum, ofinput.enums):
            raise Exception("Undeclared enum used in OFInput: {}".format(used_enum))

    return ofinput
示例#8
0
 def entry_by_version_value(self, version, value):
     res = find(
         lambda e: e.values[version] == value
         if version in e.values else False, self.entries)
     if res:
         return res
     else:
         raise KeyError("Enum %s: no entry with version %s, value %s" %
                        (self.name, version, value))
示例#9
0
def lookup_ir_wiretype(oftype, version):
    """ if of is a reference to an enum in ir, resolve it to the wiretype
        declared in that enum. Else return oftype """
    enums = loxi_globals.ir[version].enums
    enum = find(lambda e: e.name == oftype, enums)
    if enum and 'wire_type' in enum.params:
        return enum.params['wire_type']
    else:
        return oftype
示例#10
0
def lookup_ir_wiretype(oftype, version):
    """ if of is a reference to an enum in ir, resolve it to the wiretype
        declared in that enum. Else return oftype """
    enums = of_g.ir[version].enums
    enum = find(lambda e: e.name == oftype, enums)
    if enum and 'wire_type' in enum.params:
        return enum.params['wire_type']
    else:
        return oftype
示例#11
0
    def virtual_members(self):
        virtual_members = []
        if self.interface.parent_interface and self.interface.parent_interface.startswith("OFOxm"):
            if self.interface.name in model.oxm_map:
                oxm_entry = model.oxm_map[self.interface.name]
                virtual_members += [
                    JavaVirtualMember(self, "matchField", java_type.make_match_field_jtype(oxm_entry.type_name), "MatchField.%s" % oxm_entry.value),
                    JavaVirtualMember(self, "masked", java_type.boolean, "true" if oxm_entry.masked else "false"),
                   ]
            else:
                virtual_members += [
                    JavaVirtualMember(self, "matchField", java_type.make_match_field_jtype(), "null"),
                    JavaVirtualMember(self, "masked", java_type.boolean, "false"),
                   ]

        if not find(lambda m: m.name == "version", self.ir_model_members):
            virtual_members.append(JavaVirtualMember(self, "version", java_type.of_version, "OFVersion.%s" % self.version.constant_version))

        return tuple(virtual_members)
示例#12
0
    def virtual_members(self):
        if self.name == "OFOxm":
            return (
                    JavaVirtualMember(self, "value", java_type.generic_t),
                    JavaVirtualMember(self, "mask", java_type.generic_t),
                    JavaVirtualMember(self, "matchField", java_type.make_match_field_jtype("T")),
                    JavaVirtualMember(self, "masked", java_type.boolean),
                   )
        elif self.parent_interface and self.parent_interface.startswith("OFOxm"):
            field_type = java_type.make_match_field_jtype(model.oxm_map[self.name].type_name) \
                if self.name in model.oxm_map \
                else java_type.make_match_field_jtype()

            return (
                    JavaVirtualMember(self, "matchField", field_type),
                    JavaVirtualMember(self, "masked", java_type.boolean),
                   ) \
                   + \
                   (
                           ( JavaVirtualMember(self, "mask", find(lambda x: x.name == "value", self.ir_model_members).java_type), ) if not find(lambda x: x.name == "mask", self.ir_model_members) else
                    ()
                   )
        else:
            return ()
示例#13
0
 def discriminator(self):
     return find(lambda m: isinstance(m, OFDiscriminatorMember), self.ir_class.members)
示例#14
0
def lookup_ir_enum(oftype, version):
    """ if oftype is a reference to an enum in ir,
        return the value-name mapping; otherwise return None """
    enums = loxi_globals.ir[version].enums
    return find(lambda e: e.name == oftype, enums)
示例#15
0
 def member_by_name(self, name):
     return find(lambda m: m.name == name, self.members)
示例#16
0
 def enum_by_name(self, name):
     res = find(lambda e: e.name == name, self.enums)
     if not res:
         raise KeyError("Could not find enum with name %s" % name)
     return res
示例#17
0
 def interface_by_name(self, name):
     return find(lambda i: erase_type_annotation(i.name) == erase_type_annotation(name), self.interfaces)
示例#18
0
文件: ir.py 项目: abakagamze/loxigen
 def enum_by_name(self, name):
     return find(lambda enum: enum.name == name, self.enums)
示例#19
0
 def entry_by_version_value(self, version, value):
     res = find(lambda e: e.values[version] == value if version in e.values else False, self.entries)
     if res:
         return res
     else:
         raise KeyError("Enum %s: no entry with version %s, value %s" % (self.name, version, value))
示例#20
0
文件: ir.py 项目: nick-bsn/loxigen
 def has_type_members(self):
     return find(lambda m: isinstance(m, OFTypeMember),
                 self.members) is not None
示例#21
0
文件: ir.py 项目: nick-bsn/loxigen
 def discriminator(self):
     return find(lambda m: type(m) == OFDiscriminatorMember, self.members)
示例#22
0
文件: ir.py 项目: nick-bsn/loxigen
 def enum_by_name(self, name):
     return find(lambda enum: enum.name == name, self.enums)
示例#23
0
文件: ir.py 项目: abakagamze/loxigen
 def member_by_name(self, name):
     return find(lambda m: hasattr(m, "name") and m.name == name, self.members)
示例#24
0
 def superclass(self):
     return find(lambda c: c.version == self.version and c.c_name == self.ir_class.superclass, model.all_classes)
示例#25
0
 def masked_enum_group(self):
     group = find(lambda g: self.name in g.members, model.masked_enum_groups[self.enum.name])
     return group
示例#26
0
文件: ir.py 项目: abakagamze/loxigen
 def discriminator(self):
     return find(lambda m: type(m) == OFDiscriminatorMember, self.members)
示例#27
0
文件: ir.py 项目: abakagamze/loxigen
 def class_by_name(self, name):
     return find(lambda ofclass: ofclass.name == name, self.classes)
示例#28
0
文件: ir.py 项目: nick-bsn/loxigen
 def member_by_name(self, name):
     return find(lambda m: hasattr(m, "name") and m.name == name,
                 self.members)
示例#29
0
文件: ir.py 项目: abakagamze/loxigen
 def length_member(self):
     return find(lambda m: type(m) == OFLengthMember, self.members)
示例#30
0
文件: ir.py 项目: nick-bsn/loxigen
 def length_member(self):
     return find(lambda m: type(m) == OFLengthMember, self.members)
示例#31
0
文件: ir.py 项目: abakagamze/loxigen
 def has_type_members(self):
     return find(lambda m: isinstance(m, OFTypeMember), self.members) is not None
示例#32
0
文件: ir.py 项目: nick-bsn/loxigen
 def class_by_name(self, name):
     return find(lambda ofclass: ofclass.name == name, self.classes)
示例#33
0
 def entry_by_c_name(self, name):
     res = find(lambda e: e.c_name == name, self.entries)
     if res:
         return res
     else:
         raise KeyError("Enum %s: no entry with c_name %s" % (self.name, name))