Skip to content

Commit

Permalink
Enable definition of implicit size without size aspect
Browse files Browse the repository at this point in the history
Ref. #736
  • Loading branch information
treiher committed Dec 21, 2021
1 parent 4c9e567 commit 8650862
Show file tree
Hide file tree
Showing 30 changed files with 1,476 additions and 664 deletions.
10 changes: 3 additions & 7 deletions doc/Language-Reference.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ A message type specifies the message format of a protocol. A message is represen

A message can be parameterized. Message parameters can be used in conditions and aspects and enable the definition of message formats that depend on prior negotiation. Only scalar types are allowed for parameters.

The field type `Opaque` represents an unconstrained sequence of bytes. The size of opaque fields must be always defined by a size aspect. Opaque fields and sequence fields must be byte aligned. The size of a message must be a multiple of 8 bit.
The field type `Opaque` represents an unconstrained sequence of bytes. The size of opaque fields and sequence fields must be defined by a size aspect, if another field can follow. If no size aspect is given, the field size is implicitly defined by the available space (defined by the outer message when parsing or by the written data when serializing). Opaque fields and sequence fields must be byte aligned. The size of a message must be a multiple of 8 bit.

A checksum aspect specifies which parts of a message is covered by a checksum. The definition of the checksum calculation is not part of the specification. Code based on the message specification must provide a function which is able to verify a checksum using the specified checksum elements. A checksum element can be a field value, a field size or a range of fields. The point where a checksum should be checked during parsing or generated during serialization must be defined for each checksum. For this purpose the `Valid_Checksum` attribute is added to a condition. All message parts on which the checksum depends have to be known at this point.

Expand All @@ -206,9 +206,7 @@ type Frame is
if Type_Length_TPID >= 1536 and Type_Length_TPID /= 16#8100#;
TPID : TPID;
TCI : TCI;
Ether_Type : Ether_Type
then Payload
with Size => Message'Last - Ether_Type'Last;
Ether_Type : Ether_Type;
Payload : Opaque
then null
if Payload'Size / 8 >= 46 and Payload'Size / 8 <= 1500;
Expand Down Expand Up @@ -1575,9 +1573,7 @@ package Ethernet is
if Type_Length_TPID >= 1536 and Type_Length_TPID /= 16#8100#;
TPID : TPID;
TCI : TCI;
Ether_Type : Ether_Type
then Payload
with Size => Message'Last - Ether_Type'Last;
Ether_Type : Ether_Type;
Payload : Opaque
then null
if Payload'Size / 8 >= 46 and Payload'Size / 8 <= 1500;
Expand Down
2 changes: 1 addition & 1 deletion examples/specs
Submodule specs updated 37 files
+10 −5 icmpv6.rflx
+5 −1 ipv6.rflx
+5 −11 tcp.rflx
+5 −9 tests/test_specs.py
+0 −738 tests/test_validation_tool.py
+0 −5 tests/validation_tool/checksum_attribute_not_dict.py
+0 −17 tests/validation_tool/checksum_message.rflx
+ tests/validation_tool/checksum_message/invalid/sample_1_invalid.raw
+ tests/validation_tool/checksum_message/valid/sample_1.raw
+0 −1 tests/validation_tool/checksum_message/valid/sample_2.raw
+0 −9 tests/validation_tool/checksum_message_checksum_function.py
+0 −88 tests/validation_tool/ethernet.rflx
+ tests/validation_tool/ethernet/frame/invalid/ethernet_802.3_invalid_length.raw
+ tests/validation_tool/ethernet/frame/invalid/ethernet_invalid_too_long.raw
+0 −1 tests/validation_tool/ethernet/frame/invalid/ethernet_invalid_too_short.raw
+ tests/validation_tool/ethernet/frame/invalid/ethernet_undefined.raw
+ tests/validation_tool/ethernet/frame/valid/802.3-LLC-CDP.raw
+ tests/validation_tool/ethernet/frame/valid/EII-802.1AD-802.1Q-IPv4.raw
+ tests/validation_tool/ethernet/frame/valid/EII-802.1Q-802.1Q-IPv4-ICMP.raw
+ tests/validation_tool/ethernet/frame/valid/EII-802.1Q-LLC-CDP.raw
+ tests/validation_tool/ethernet/frame/valid/EII-802.1Q-LLC-STP.raw
+ tests/validation_tool/ethernet/frame/valid/ethernet_802.3.raw
+ tests/validation_tool/ethernet/frame/valid/ethernet_double_vlan_tag.raw
+ tests/validation_tool/ethernet/frame/valid/ethernet_ipv4_udp.raw
+ tests/validation_tool/ethernet/frame/valid/ethernet_vlan_tag.raw
+0 −9 tests/validation_tool/in_ethernet.rflx
+0 −7 tests/validation_tool/invalid_checksum_field.py
+0 −68 tests/validation_tool/ipv4.rflx
+0 −8 tests/validation_tool/message_not_in_package.py
+0 −5 tests/validation_tool/missing_checksum_callable.py
+0 −5 tests/validation_tool/missing_checksum_func_dict.py
+0 −2 tests/validation_tool/missing_checksum_functions_attrib.py
+0 −5 tests/validation_tool/missing_key.py
+0 −644 tests/validation_tool/protocol_numbers.rflx
+0 −185 tests/validation_tool/valid_full_output_negative.json
+0 −185 tests/validation_tool/valid_full_output_positive.json
+0 −508 tools/validate_spec.py
7 changes: 4 additions & 3 deletions rflx/generator/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ def field_condition_call(
else []
),
),
*([size] if size_dependent_condition(message) else []),
*([size] if size_dependent_condition(message, field) else []),
],
)

Expand Down Expand Up @@ -831,11 +831,12 @@ def contains_function_name(
return f"{sdu_name.flat}_In_{pdu_name.flat}_{field}"


def size_dependent_condition(message: model.Message) -> bool:
def size_dependent_condition(message: model.Message, field: model.Field = None) -> bool:
field_sizes = {expr.Size(f.name) for f in message.fields}
links = message.outgoing(field) if field else message.structure
return any(
size in field_sizes
for link in message.structure
for link in links
for size in link.condition.findall(lambda x: isinstance(x, expr.Size))
)

Expand Down
13 changes: 10 additions & 3 deletions rflx/generator/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,9 @@ def specification(field: Field) -> ProcedureSpecification:
Precondition(
AndThen(
*self.setter_preconditions(f),
*self.composite_setter_field_condition_precondition(message, f),
*self.composite_setter_field_condition_precondition(
message, f, empty=True
),
*self.composite_setter_preconditions(f),
Equal(
Call(
Expand Down Expand Up @@ -1204,10 +1206,15 @@ def composite_setter_postconditions(field: Field) -> List[Expr]:
]

@staticmethod
def composite_setter_field_condition_precondition(message: Message, field: Field) -> List[Expr]:
def composite_setter_field_condition_precondition(
message: Message, field: Field, empty: bool = False
) -> List[Expr]:
return [
common.field_condition_call(
message, field, Variable("Data"), Call(const.TYPES_TO_BIT_LENGTH, [Length("Data")])
message,
field,
Variable("Data"),
None if empty else Call(const.TYPES_TO_BIT_LENGTH, [Length("Data")]),
),
]

Expand Down
Loading

0 comments on commit 8650862

Please sign in to comment.