-
Notifications
You must be signed in to change notification settings - Fork 10
API refinement: make RX pipeline zero-copy as a side effect of the OOO reassembly support #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
3f08d0e
Add the RX frame parser
pavel-kirienko de2e14e
Tidy
pavel-kirienko 50ec426
Fix https://github.com/OpenCyphal-Garage/libudpard/issues/36
pavel-kirienko 1fa4132
Extend the frame parser with semantics check and add more test cases
pavel-kirienko 52b826b
Trivial renaming
pavel-kirienko 8037d35
New RX buffer management draft
pavel-kirienko 2558c6a
Implement the small transfer optimization
pavel-kirienko 59a040f
Update comments
pavel-kirienko b79a5de
Split testRxParse into several functions
pavel-kirienko 0dc00a0
Fix invalid memory access in rxParseFrame
pavel-kirienko 988e008
Fix Sonar complaints
pavel-kirienko 18b10d7
Questionable: rename udpardRxService* into udpardRxRPC* because the o…
pavel-kirienko 801ab7f
Add missing parens suggested by Sonar
pavel-kirienko 303e3cb
Add a section on memory management to the header comment
pavel-kirienko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| /// This software is distributed under the terms of the MIT License. | ||
| /// Copyright (C) OpenCyphal Development Team <opencyphal.org> | ||
| /// Copyright Amazon.com Inc. or its affiliates. | ||
| /// SPDX-License-Identifier: MIT | ||
|
|
||
| #include <udpard.c> // NOLINT(bugprone-suspicious-include) | ||
| #include "helpers.h" | ||
| #include <unity.h> | ||
|
|
||
| // Generate reference data using PyCyphal: | ||
| // | ||
| // >>> from pycyphal.transport.udp import UDPFrame | ||
| // >>> from pycyphal.transport import Priority, MessageDataSpecifier, ServiceDataSpecifier | ||
| // >>> frame = UDPFrame(priority=Priority.FAST, transfer_id=0xbadc0ffee0ddf00d, index=12345, end_of_transfer=False, | ||
| // payload=memoryview(b''), source_node_id=2345, destination_node_id=5432, | ||
| // data_specifier=MessageDataSpecifier(7654), user_data=0) | ||
| // >>> list(frame.compile_header_and_payload()[0]) | ||
| // [1, 2, 41, 9, 56, 21, 230, 29, 13, 240, 221, 224, 254, 15, 220, 186, 57, 48, 0, 0, 0, 0, 224, 60] | ||
| static void testRxParseFrameValidMessage(void) | ||
| { | ||
| const byte_t data[] = {1, 2, 41, 9, 255, 255, 230, 29, 13, 240, 221, 224, | ||
| 254, 15, 220, 186, 57, 48, 0, 0, 0, 0, 30, 179, // | ||
| 'a', 'b', 'c'}; | ||
| RxFrame rxf = {0}; | ||
| TEST_ASSERT(rxParseFrame((struct UdpardConstPayload){.data = data, .size = sizeof(data)}, &rxf)); | ||
| TEST_ASSERT_EQUAL_UINT64(UdpardPriorityFast, rxf.meta.priority); | ||
| TEST_ASSERT_EQUAL_UINT64(2345, rxf.meta.src_node_id); | ||
| TEST_ASSERT_EQUAL_UINT64(UDPARD_NODE_ID_UNSET, rxf.meta.dst_node_id); | ||
| TEST_ASSERT_EQUAL_UINT64(7654, rxf.meta.data_specifier); | ||
| TEST_ASSERT_EQUAL_UINT64(0xbadc0ffee0ddf00d, rxf.meta.transfer_id); | ||
| TEST_ASSERT_EQUAL_UINT64(12345, rxf.index); | ||
| TEST_ASSERT_FALSE(rxf.end_of_transfer); | ||
| TEST_ASSERT_EQUAL_UINT64(3, rxf.payload.size); | ||
| TEST_ASSERT_EQUAL_UINT8_ARRAY("abc", rxf.payload.data, 3); | ||
| } | ||
|
|
||
| static void testRxParseFrameValidRPCService(void) | ||
| { | ||
| // frame = UDPFrame(priority=Priority.FAST, transfer_id=0xbadc0ffee0ddf00d, index=6654, end_of_transfer=False, | ||
| // payload=memoryview(b''), source_node_id=2345, destination_node_id=4567, | ||
| // data_specifier=ServiceDataSpecifier(role=ServiceDataSpecifier.Role.REQUEST, service_id=123), user_data=0) | ||
| const byte_t data[] = {1, 2, 41, 9, 215, 17, 123, 192, 13, 240, 221, 224, | ||
| 254, 15, 220, 186, 254, 25, 0, 0, 0, 0, 173, 122, // | ||
| 'a', 'b', 'c'}; | ||
| RxFrame rxf = {0}; | ||
| TEST_ASSERT(rxParseFrame((struct UdpardConstPayload){.data = data, .size = sizeof(data)}, &rxf)); | ||
| TEST_ASSERT_EQUAL_UINT64(UdpardPriorityFast, rxf.meta.priority); | ||
| TEST_ASSERT_EQUAL_UINT64(2345, rxf.meta.src_node_id); | ||
| TEST_ASSERT_EQUAL_UINT64(4567, rxf.meta.dst_node_id); | ||
| TEST_ASSERT_EQUAL_UINT64(123U | DATA_SPECIFIER_SERVICE_NOT_MESSAGE_MASK | | ||
| DATA_SPECIFIER_SERVICE_REQUEST_NOT_RESPONSE_MASK, | ||
| rxf.meta.data_specifier); | ||
| TEST_ASSERT_EQUAL_UINT64(0xbadc0ffee0ddf00d, rxf.meta.transfer_id); | ||
| TEST_ASSERT_EQUAL_UINT64(6654, rxf.index); | ||
| TEST_ASSERT_FALSE(rxf.end_of_transfer); | ||
| TEST_ASSERT_EQUAL_UINT64(3, rxf.payload.size); | ||
| TEST_ASSERT_EQUAL_UINT8_ARRAY("abc", rxf.payload.data, 3); | ||
| } | ||
|
|
||
| static void testRxParseFrameValidMessageAnonymous(void) | ||
| { | ||
| const byte_t data[] = {1, 2, 255, 255, 255, 255, 230, 29, 13, 240, 221, 224, | ||
| 254, 15, 220, 186, 0, 0, 0, 128, 0, 0, 168, 92, // | ||
| 'a', 'b', 'c'}; | ||
| RxFrame rxf = {0}; | ||
| TEST_ASSERT(rxParseFrame((struct UdpardConstPayload){.data = data, .size = sizeof(data)}, &rxf)); | ||
| TEST_ASSERT_EQUAL_UINT64(UdpardPriorityFast, rxf.meta.priority); | ||
| TEST_ASSERT_EQUAL_UINT64(UDPARD_NODE_ID_UNSET, rxf.meta.src_node_id); | ||
| TEST_ASSERT_EQUAL_UINT64(UDPARD_NODE_ID_UNSET, rxf.meta.dst_node_id); | ||
| TEST_ASSERT_EQUAL_UINT64(7654, rxf.meta.data_specifier); | ||
| TEST_ASSERT_EQUAL_UINT64(0xbadc0ffee0ddf00d, rxf.meta.transfer_id); | ||
| TEST_ASSERT_EQUAL_UINT64(0, rxf.index); | ||
| TEST_ASSERT_TRUE(rxf.end_of_transfer); | ||
| TEST_ASSERT_EQUAL_UINT64(3, rxf.payload.size); | ||
| TEST_ASSERT_EQUAL_UINT8_ARRAY("abc", rxf.payload.data, 3); | ||
| } | ||
|
|
||
| static void testRxParseFrameRPCServiceAnonymous(void) | ||
| { | ||
| const byte_t data[] = {1, 2, 255, 255, 215, 17, 123, 192, 13, 240, 221, 224, | ||
| 254, 15, 220, 186, 254, 25, 0, 0, 0, 0, 75, 79, // | ||
| 'a', 'b', 'c'}; | ||
| RxFrame rxf = {0}; | ||
| TEST_ASSERT_FALSE(rxParseFrame((struct UdpardConstPayload){.data = data, .size = sizeof(data)}, &rxf)); | ||
| } | ||
|
|
||
| static void testRxParseFrameRPCServiceBroadcast(void) | ||
| { | ||
| const byte_t data[] = {1, 2, 41, 9, 255, 255, 123, 192, 13, 240, 221, 224, | ||
| 254, 15, 220, 186, 254, 25, 0, 0, 0, 0, 248, 152, // | ||
| 'a', 'b', 'c'}; | ||
| RxFrame rxf = {0}; | ||
| TEST_ASSERT_FALSE(rxParseFrame((struct UdpardConstPayload){.data = data, .size = sizeof(data)}, &rxf)); | ||
| } | ||
|
|
||
| static void testRxParseFrameAnonymousNonSingleFrame(void) | ||
| { // Invalid anonymous message frame because EOT not set (multi-frame anonymous transfers are not allowed). | ||
| const byte_t data[] = {1, 2, 255, 255, 255, 255, 230, 29, 13, 240, 221, 224, | ||
| 254, 15, 220, 186, 0, 0, 0, 0, 0, 0, 147, 6, // | ||
| 'a', 'b', 'c'}; | ||
| RxFrame rxf = {0}; | ||
| TEST_ASSERT_FALSE(rxParseFrame((struct UdpardConstPayload){.data = data, .size = sizeof(data)}, &rxf)); | ||
| } | ||
|
|
||
| static void testRxParseFrameBadHeaderCRC(void) | ||
| { // Bad header CRC. | ||
| const byte_t data[] = {1, 2, 41, 9, 255, 255, 230, 29, 13, 240, 221, 224, | ||
| 254, 15, 220, 186, 57, 48, 0, 0, 0, 0, 30, 180, // | ||
| 'a', 'b', 'c'}; | ||
| RxFrame rxf = {0}; | ||
| TEST_ASSERT_FALSE(rxParseFrame((struct UdpardConstPayload){.data = data, .size = sizeof(data)}, &rxf)); | ||
| } | ||
|
|
||
| static void testRxParseFrameUnknownHeaderVersion(void) | ||
| { | ||
| // >>> from pycyphal.transport.commons.crc import CRC16CCITT | ||
| // >>> list(CRC16CCITT.new(bytes( | ||
| // [0, 2, 41, 9, 56, 21, 230, 29, 13, 240, 221, 224, 254, 15, 220, 186, 57, 48, 0, 0, 0, 0])).value_as_bytes) | ||
| const byte_t data[] = {0, 2, 41, 9, 56, 21, 230, 29, 13, 240, 221, 224, | ||
| 254, 15, 220, 186, 57, 48, 0, 0, 0, 0, 141, 228, // | ||
| 'a', 'b', 'c'}; | ||
| RxFrame rxf = {0}; | ||
| TEST_ASSERT_FALSE(rxParseFrame((struct UdpardConstPayload){.data = data, .size = sizeof(data)}, &rxf)); | ||
| } | ||
|
|
||
| static void testRxParseFrameHeaderWithoutPayload(void) | ||
| { | ||
| const byte_t data[] = {1, 2, 41, 9, 255, 255, 230, 29, 13, 240, 221, 224, | ||
| 254, 15, 220, 186, 57, 48, 0, 0, 0, 0, 30, 179}; | ||
| RxFrame rxf = {0}; | ||
| TEST_ASSERT_FALSE(rxParseFrame((struct UdpardConstPayload){.data = data, .size = sizeof(data)}, &rxf)); | ||
| } | ||
|
|
||
| static void testRxParseFrameEmpty(void) | ||
| { | ||
| RxFrame rxf = {0}; | ||
| TEST_ASSERT_FALSE(rxParseFrame((struct UdpardConstPayload){.data = "", .size = 0}, &rxf)); | ||
| } | ||
|
|
||
| void setUp(void) {} | ||
|
|
||
| void tearDown(void) {} | ||
|
|
||
| int main(void) | ||
| { | ||
| UNITY_BEGIN(); | ||
| RUN_TEST(testRxParseFrameValidMessage); | ||
| RUN_TEST(testRxParseFrameValidRPCService); | ||
| RUN_TEST(testRxParseFrameValidMessageAnonymous); | ||
| RUN_TEST(testRxParseFrameRPCServiceAnonymous); | ||
| RUN_TEST(testRxParseFrameRPCServiceBroadcast); | ||
| RUN_TEST(testRxParseFrameAnonymousNonSingleFrame); | ||
| RUN_TEST(testRxParseFrameBadHeaderCRC); | ||
| RUN_TEST(testRxParseFrameUnknownHeaderVersion); | ||
| RUN_TEST(testRxParseFrameHeaderWithoutPayload); | ||
| RUN_TEST(testRxParseFrameEmpty); | ||
| return UNITY_END(); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.