def test_resolve_superclass(self): version = ir.OFVersion("1.0", 1) input = fe.OFInput(filename="test.dat", wire_versions=(1,), classes=( fe.OFClass(name="OFMessage", superclass=None, members=(), virtual=True, params={} ), fe.OFClass(name="OFHello", superclass="OFMessage", members=(), virtual=False, params={} ), ), enums=() ) p = ir.build_protocol(version, [ input ]) eq_(2, len(p.classes)) c, c2 = p.classes eq_("OFMessage", c.name) eq_(None, c.superclass) eq_(True, c.virtual) eq_("OFHello", c2.name) eq_(c, c2.superclass) eq_(False, c2.virtual)
def test_enums(self): version = ir.OFVersion("1.0", 1) input = fe.OFInput(filename="test.dat", wire_versions=(1,), classes=(), enums=( fe.OFEnum(name='ofp_flow_wildcards', entries=(fe.OFEnumEntry(name="OFPFW_IN_PORT", value=0x01, params={}), fe.OFEnumEntry(name="OFPFW_DL_VLAN", value=0x2, params={})), params = dict(wire_type="uint32_t", bitmask=True) ), fe.OFEnum(name='ofp_queue_properties', entries=(fe.OFEnumEntry(name="OFPQT_NONE", value=0x00, params={}), fe.OFEnumEntry(name="OFPQT_MIN_RATE", value=0x1, params={})), params = dict(wire_type="uint32_t") ), ) ) p = ir.build_protocol(version, [ input ]) eq_(0, len(p.classes)) eq_(2, len(p.enums)) e = p.enums[0] eq_("ofp_flow_wildcards", e.name) eq_(True, e.is_bitmask) eq_("uint32_t", e.wire_type) eq_(ir.OFEnumEntry(name="OFPFW_IN_PORT", value=0x01, params={}), e.entries[0]) eq_(ir.OFEnumEntry(name="OFPFW_DL_VLAN", value=0x02, params={}), e.entries[1]) e = p.enums[1] eq_("ofp_queue_properties", e.name) eq_(False, e.is_bitmask) eq_("uint32_t", e.wire_type) eq_(ir.OFEnumEntry(name="OFPQT_NONE", value=0x00, params={}), e.entries[0]) eq_(ir.OFEnumEntry(name="OFPQT_MIN_RATE", value=0x01, params={}), e.entries[1])
def test_class_redefined(self): version = ir.OFVersion("1.0", 1) inputs = ( fe.OFInput(filename="test.dat", wire_versions=(1,), classes=( fe.OFClass(name="OFMessage", superclass=None, members=(), virtual=True, params={} ), ), enums=(), ), fe.OFInput(filename="test2.dat", wire_versions=(1,), classes=( fe.OFClass(name="OFMessage", superclass=None, members=(), virtual=True, params={} ), ), enums=() ) ) p = ir.build_protocol(version, inputs)
def test_resolve_superclass(self): version = ir.OFVersion("1.0", 1) input = fe.OFInput( filename="test.dat", wire_versions=(1,), classes=( fe.OFClass(name="OFMessage", superclass="NotFoundSuperClass", members=(), virtual=True, params={}), ), enums=(), ) p = ir.build_protocol(version, [input])
def test_dependency_cycle(self): version = ir.OFVersion("1.0", 1) input = fe.OFInput( filename="test.dat", wire_versions=(1,), classes=( fe.OFClass(name="OFMessage", superclass="OFHeader", members=(), virtual=True, params={}), fe.OFClass(name="OFHeader", superclass="OFMessage", members=(), virtual=True, params={}), ), enums=(), ) p = ir.build_protocol(version, [input])
def test_simple(self): version = ir.OFVersion("1.0", 1) input = fe.OFInput( filename="test.dat", wire_versions=(1,), classes=( fe.OFClass( name="OFMessage", superclass=None, members=( fe.OFDataMember(name="version", oftype="uint32_t"), fe.OFLengthMember(name="length", oftype="uint16_t"), ), virtual=False, params={}, ), ), enums=(), ) p = ir.build_protocol(version, [input]) eq_(1, len(p.classes)) c = p.classes[0] eq_("OFMessage", c.name) eq_(None, c.superclass) eq_(False, c.virtual) eq_({}, c.params) eq_(2, len(c.members)) eq_(p, c.protocol) m1 = c.members[0] ok_(isinstance(m1, ir.OFDataMember)) eq_("version", m1.name) eq_("uint32_t", m1.oftype) eq_(4, m1.length) eq_(True, m1.is_fixed_length) eq_(0, m1.offset) eq_(c, m1.of_class) m2 = c.members[1] ok_(isinstance(m2, ir.OFLengthMember)) eq_("length", m2.name) eq_("uint16_t", m2.oftype) eq_(2, m2.length) eq_(True, m2.is_fixed_length) eq_(4, m2.offset) eq_(c, m2.of_class) eq_(True, c.is_fixed_length) eq_(6, c.length)
def test_resolve_superclass(self): version = ir.OFVersion("1.0", 1) input = fe.OFInput(filename="test.dat", wire_versions=(1,), classes=( fe.OFClass(name="OFMessage", superclass="NotFoundSuperClass", members=(), virtual=True, params={} ), ), enums=() ) p = ir.build_protocol(version, [ input ])
def test_simple(self): version = ir.OFVersion("1.0", 1) input = fe.OFInput(filename="test.dat", wire_versions=(1,), classes=( fe.OFClass(name="OFMessage", superclass=None, members=( fe.OFDataMember(name='version', oftype='uint32_t'), fe.OFLengthMember(name='length', oftype='uint16_t') ), virtual=False, params={} ), ), enums=() ) p = ir.build_protocol(version, [ input ]) eq_(1, len(p.classes)) c = p.classes[0] eq_("OFMessage", c.name) eq_(None, c.superclass) eq_(False, c.virtual) eq_({}, c.params) eq_(2, len(c.members)) eq_(p, c.protocol) m1 = c.members[0] ok_(isinstance(m1, ir.OFDataMember)) eq_("version", m1.name) eq_("uint32_t", m1.oftype) eq_(4, m1.length) eq_(True, m1.is_fixed_length) eq_(0, m1.offset) eq_(c, m1.of_class) m2 = c.members[1] ok_(isinstance(m2, ir.OFLengthMember)) eq_("length", m2.name) eq_("uint16_t", m2.oftype) eq_(2, m2.length) eq_(True, m2.is_fixed_length) eq_(4, m2.offset) eq_(c, m2.of_class) eq_(True, c.is_fixed_length) eq_(6, c.length)
def test_class_redefined(self): version = ir.OFVersion("1.0", 1) inputs = ( fe.OFInput( filename="test.dat", wire_versions=(1,), classes=(fe.OFClass(name="OFMessage", superclass=None, members=(), virtual=True, params={}),), enums=(), ), fe.OFInput( filename="test2.dat", wire_versions=(1,), classes=(fe.OFClass(name="OFMessage", superclass=None, members=(), virtual=True, params={}),), enums=(), ), ) p = ir.build_protocol(version, inputs)
def test_enums(self): version = ir.OFVersion("1.0", 1) input = fe.OFInput( filename="test.dat", wire_versions=(1,), classes=(), enums=( fe.OFEnum( name="ofp_flow_wildcards", entries=( fe.OFEnumEntry(name="OFPFW_IN_PORT", value=0x01, params={}), fe.OFEnumEntry(name="OFPFW_DL_VLAN", value=0x2, params={}), ), params=dict(wire_type="uint32_t", bitmask=True), ), fe.OFEnum( name="ofp_queue_properties", entries=( fe.OFEnumEntry(name="OFPQT_NONE", value=0x00, params={}), fe.OFEnumEntry(name="OFPQT_MIN_RATE", value=0x1, params={}), ), params=dict(wire_type="uint32_t"), ), ), ) p = ir.build_protocol(version, [input]) eq_(0, len(p.classes)) eq_(2, len(p.enums)) e = p.enums[0] eq_("ofp_flow_wildcards", e.name) eq_(True, e.is_bitmask) eq_("uint32_t", e.wire_type) eq_(ir.OFEnumEntry(name="OFPFW_IN_PORT", value=0x01, params={}), e.entries[0]) eq_(ir.OFEnumEntry(name="OFPFW_DL_VLAN", value=0x02, params={}), e.entries[1]) e = p.enums[1] eq_("ofp_queue_properties", e.name) eq_(False, e.is_bitmask) eq_("uint32_t", e.wire_type) eq_(ir.OFEnumEntry(name="OFPQT_NONE", value=0x00, params={}), e.entries[0]) eq_(ir.OFEnumEntry(name="OFPQT_MIN_RATE", value=0x01, params={}), e.entries[1])
def test_resolve_superclass(self): version = ir.OFVersion("1.0", 1) input = fe.OFInput( filename="test.dat", wire_versions=(1,), classes=( fe.OFClass(name="OFMessage", superclass=None, members=(), virtual=True, params={}), fe.OFClass(name="OFHello", superclass="OFMessage", members=(), virtual=False, params={}), ), enums=(), ) p = ir.build_protocol(version, [input]) eq_(2, len(p.classes)) c, c2 = p.classes eq_("OFMessage", c.name) eq_(None, c.superclass) eq_(True, c.virtual) eq_("OFHello", c2.name) eq_(c, c2.superclass) eq_(False, c2.virtual)
def test_dependency_cycle(self): version = ir.OFVersion("1.0", 1) input = fe.OFInput(filename="test.dat", wire_versions=(1,), classes=( fe.OFClass(name="OFMessage", superclass="OFHeader", members=(), virtual=True, params={} ), fe.OFClass(name="OFHeader", superclass="OFMessage", members=(), virtual=True, params={} ), ), enums=() ) p = ir.build_protocol(version, [ input ])