Ejemplo n.º 1
0
 def test_message_type_spec(self) -> None:
     spec = {
         "Test":
         Specification(
             ContextSpec([]),
             PackageSpec(
                 "Test",
                 [
                     ModularInteger("Test.T", Number(256)),
                     MessageSpec(
                         "Test.PDU",
                         [
                             Component(
                                 "Foo",
                                 "T",
                                 [
                                     Then(
                                         "Bar",
                                         UNDEFINED,
                                         UNDEFINED,
                                         And(
                                             Equal(Length("Foo"),
                                                   Number(1)),
                                             LessEqual(
                                                 Variable("Foo"),
                                                 Number(30, 16)),
                                         ),
                                     ),
                                     Then(
                                         "Baz",
                                         condition=And(
                                             Equal(Length("Foo"),
                                                   Number(1)),
                                             Greater(
                                                 Variable("Foo"),
                                                 Number(30, 16)),
                                         ),
                                     ),
                                 ],
                             ),
                             Component("Bar", "T"),
                             Component("Baz", "T"),
                         ],
                     ),
                     MessageSpec(
                         "Test.Simple_PDU",
                         [Component("Bar", "T"),
                          Component("Baz", "T")]),
                     MessageSpec("Test.Empty_PDU", []),
                 ],
             ),
         )
     }
     self.assert_specifications([f"{self.testdir}/message_type.rflx"], spec)
Ejemplo n.º 2
0
    def test_message_type_message(self) -> None:
        simple_structure = [
            Link(INITIAL, Field("Bar")),
            Link(
                Field("Bar"),
                Field("Baz"),
            ),
            Link(Field("Baz"), FINAL),
        ]

        simple_types = {
            Field("Bar"): ModularInteger("Test.T", Number(256)),
            Field("Baz"): ModularInteger("Test.T", Number(256)),
        }

        simple_message = Message("Test.Simple_PDU", simple_structure,
                                 simple_types)

        structure = [
            Link(INITIAL, Field("Foo")),
            Link(
                Field("Foo"),
                Field("Bar"),
                And(Equal(Length("Foo"), Number(1)),
                    LessEqual(Variable("Foo"), Number(30, 16))),
            ),
            Link(
                Field("Foo"),
                Field("Baz"),
                And(Equal(Length("Foo"), Number(1)),
                    Greater(Variable("Foo"), Number(30, 16))),
            ),
            Link(Field("Bar"), Field("Baz")),
            Link(Field("Baz"), FINAL),
        ]

        types = {
            **simple_types,
            **{
                Field("Foo"): ModularInteger("Test.T", Number(256))
            },
        }

        message = Message("Test.PDU", structure, types)

        empty_message = Message("Test.Empty_PDU", [], {})

        self.assert_messages_files([f"{self.testdir}/message_type.rflx"],
                                   [message, simple_message, empty_message])
Ejemplo n.º 3
0
    def test_message_type_pdu(self) -> None:
        t = ModularInteger('T', Number(256))

        initial = InitialNode()
        simple_initial = InitialNode()
        pdu_foo = Node('Foo', t)
        pdu_bar = Node('Bar', t)
        pdu_baz = Node('Baz', t)

        initial.edges = [Edge(pdu_foo, length=Number(1))]
        simple_initial.edges = [Edge(pdu_bar)]
        pdu_foo.edges = [
            Edge(
                pdu_bar,
                And(Equal(Length('Foo'), Number(1)),
                    LessEqual(Value('Foo'), Number(30))), Number(1),
                Number(1)),
            Edge(pdu_baz)
        ]
        pdu_bar.edges = [Edge(pdu_baz)]
        pdu_baz.edges = [Edge(FINAL)]

        pdus = [
            PDU('Test.PDU', initial),
            PDU('Test.Simple_PDU', simple_initial)
        ]

        self.assert_pdus([f'{self.testdir}/message_type.rflx'], pdus)
Ejemplo n.º 4
0
 def test_message_type_spec(self) -> None:
     spec = {
         'Test':
         Specification(
             Context([]),
             Package('Test', [
                 ModularInteger('T', Number(256)),
                 Message('PDU', [
                     Component('null', '', [Then('Foo', None, Number(1))]),
                     Component('Foo', 'T', [
                         Then(
                             'Bar', Number(1), Number(1),
                             And(Equal(Length('Foo'), Number(1)),
                                 LessEqual(Value('Foo'), Number(30)))),
                         Then('Baz')
                     ]),
                     Component('Bar', 'T'),
                     Component('Baz', 'T')
                 ]),
                 Message('Simple_PDU',
                         [Component('Bar', 'T'),
                          Component('Baz', 'T')])
             ]))
     }
     self.assert_specifications([f'{self.testdir}/message_type.rflx'], spec)
Ejemplo n.º 5
0
    def test_ethernet_spec(self) -> None:
        spec = {
            'Ethernet':
            Specification(
                Context([]),
                Package('Ethernet', [
                    RangeInteger('UINT16', Number(0),
                                 Sub(Pow(Number(2), Number(16)), Number(1)),
                                 Number(16)),
                    ModularInteger('UINT48', Pow(Number(2), Number(48))),
                    Message('Frame', [
                        Component('Destination', 'UINT48'),
                        Component('Source', 'UINT48'),
                        Component('TPID', 'UINT16', [
                            Then('TCI', None, None,
                                 Equal(Value('TPID'), Number(33024))),
                            Then('EtherType', First('TPID'), None,
                                 NotEqual(Value('TPID'), Number(33024)))
                        ]),
                        Component('TCI', 'UINT16'),
                        Component('EtherType', 'UINT16', [
                            Then('Payload', None,
                                 Mul(Value('EtherType'), Number(8)),
                                 LessEqual(Value('EtherType'), Number(1500))),
                            Then(
                                'Payload', None,
                                Sub(Last('Message'), Last('EtherType')),
                                GreaterEqual(Value('EtherType'), Number(1536)))
                        ]),
                        Component('Payload', 'Payload_Array', [
                            Then(
                                'null', None, None,
                                And(
                                    GreaterEqual(
                                        Div(Length('Payload'), Number(8)),
                                        Number(46)),
                                    LessEqual(
                                        Div(Length('Payload'), Number(8)),
                                        Number(1500))))
                        ])
                    ])
                ]))
        }

        self.assert_specifications([f'{self.specdir}/ethernet.rflx'], spec)
Ejemplo n.º 6
0
    def test_ethernet_spec(self) -> None:
        spec = {
            "Ethernet":
            Specification(
                ContextSpec([]),
                PackageSpec(
                    "Ethernet",
                    [
                        ModularInteger("Ethernet.Address",
                                       Pow(Number(2), Number(48))),
                        RangeInteger(
                            "Ethernet.Type_Length",
                            Number(46),
                            Sub(Pow(Number(2), Number(16)), Number(1)),
                            Number(16),
                        ),
                        RangeInteger("Ethernet.TPID", Number(0x8100, 16),
                                     Number(0x8100, 16), Number(16)),
                        ModularInteger("Ethernet.TCI",
                                       Pow(Number(2), Number(16))),
                        MessageSpec(
                            "Ethernet.Frame",
                            [
                                Component("Destination", "Address"),
                                Component("Source", "Address"),
                                Component(
                                    "Type_Length_TPID",
                                    "Type_Length",
                                    [
                                        Then(
                                            "TPID",
                                            First("Type_Length_TPID"),
                                            UNDEFINED,
                                            Equal(Variable("Type_Length_TPID"),
                                                  Number(33024, 16)),
                                        ),
                                        Then(
                                            "Type_Length",
                                            First("Type_Length_TPID"),
                                            UNDEFINED,
                                            NotEqual(
                                                Variable("Type_Length_TPID"),
                                                Number(33024, 16)),
                                        ),
                                    ],
                                ),
                                Component("TPID", "TPID"),
                                Component("TCI", "TCI"),
                                Component(
                                    "Type_Length",
                                    "Type_Length",
                                    [
                                        Then(
                                            "Payload",
                                            UNDEFINED,
                                            Mul(Variable("Type_Length"),
                                                Number(8)),
                                            LessEqual(Variable("Type_Length"),
                                                      Number(1500)),
                                        ),
                                        Then(
                                            "Payload",
                                            UNDEFINED,
                                            Sub(Last("Message"),
                                                Last("Type_Length")),
                                            GreaterEqual(
                                                Variable("Type_Length"),
                                                Number(1536)),
                                        ),
                                    ],
                                ),
                                Component(
                                    "Payload",
                                    "Payload",
                                    [
                                        Then(
                                            "null",
                                            UNDEFINED,
                                            UNDEFINED,
                                            And(
                                                GreaterEqual(
                                                    Div(
                                                        Length("Payload"),
                                                        Number(8)),
                                                    Number(46)),
                                                LessEqual(
                                                    Div(
                                                        Length("Payload"),
                                                        Number(8)),
                                                    Number(1500)),
                                            ),
                                        )
                                    ],
                                ),
                            ],
                        ),
                    ],
                ),
            )
        }

        self.assert_specifications([f"{self.specdir}/ethernet.rflx"], spec)