Skip to content

Commit

Permalink
pylibschc.rules: allow for Uncompressed Rule to be unset
Browse files Browse the repository at this point in the history
  • Loading branch information
miri64 committed Feb 15, 2023
1 parent 9ab308b commit 7d2ba0e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pylibschc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
__copyright__ = "Copyright 2023 Freie Universität Berlin"
__license__ = "GPLv3"
__email__ = "[email protected]"
__version__ = "0.0.1b0"
__version__ = "0.0.1b1"
2 changes: 1 addition & 1 deletion pylibschc/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ class Device(BaseModel):
duty_cycle: conint(ge=0x00000000, le=0xFFFFFFFF)
"""The duty cycle in milliseconds of the device. Must be 0
< :attr:`Device.duty_cycle` ≤ :math:`(2^{32} - 1)`."""
uncompressed_rule: UncompressedRule
uncompressed_rule: UncompressedRule = None
"""The rule for an uncompressed packet on this device. Must not contain any
duplicate rule IDs (i.e., same value of same bit width) with
:attr:`Device.compression_rules` or :attr:`Device.fragmentation_rules`."""
Expand Down
14 changes: 14 additions & 0 deletions tests/test_compressor.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ def reset_compressor_reassembler():
pylibschc.compressor.CompressorDecompressor._inner = None


def test_compressor_reassembler_no_uncompressed_rule(test_rules):
test_rules.devices[0].uncompressed_rule = None
config = test_rules.deploy()
device = config.devices[0]
direction = pylibschc.compressor.Direction.UP
cr = pylibschc.compressor.CompressorDecompressor( # pylint: disable=invalid-name
device=device, direction=direction
)
bit_array = pylibschc.compressor.BitArray(bytes(IPv6()))
res, not_compressed = cr.output(bit_array)
assert res == pylibschc.compressor.CompressionResult.UNCOMPRESSED
assert bytes(IPv6()) == not_compressed.buffer


@pytest.fixture()
def exp_rules(request, test_rules):
config = test_rules.deploy()
Expand Down
10 changes: 10 additions & 0 deletions tests/test_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,16 @@ def test_device_rule_id_duplicates():
)


def test_device_uncompressed_rule_none():
device = pylibschc.rules.Device(
device_id=1,
mtu=500,
duty_cycle=5000,
uncompressed_rule=None,
)
assert device.uncompressed_rule is None


def test_device_c_schc_declaration():
device = pylibschc.rules.Device(
device_id=1,
Expand Down

0 comments on commit 7d2ba0e

Please sign in to comment.