-
Notifications
You must be signed in to change notification settings - Fork 74
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
Fix fragmentation #297
Fix fragmentation #297
Changes from all commits
e23e6a5
34361ee
6ab2281
c8a08de
092e60d
2503af1
87bfe0f
84f3a96
33bdef5
b5a063a
24ba9cc
e8a5181
44fb799
6df4e47
5ac84e7
b805d31
cd1aab1
479c173
f5972b0
97a4f8b
2e27793
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -296,8 +296,7 @@ int8_t _z_bytes_val_encode(_z_wbuf_t *wbf, const _z_bytes_t *bs) { | |
int8_t ret = _Z_RES_OK; | ||
|
||
if ((wbf->_expansion_step != 0) && (bs->len > Z_TSID_LENGTH)) { | ||
// ret |= _z_wbuf_wrap_bytes(wbf, bs->start, 0, bs->len); | ||
ret |= _z_wbuf_write_bytes(wbf, bs->start, 0, bs->len); | ||
ret |= _z_wbuf_wrap_bytes(wbf, bs->start, 0, bs->len); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems that this line is being changed frequently. Last time it was from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yah that's one of the whole point of this PR, reverting this change from @p-avital that outlived its usefulness. |
||
} else { | ||
ret |= _z_wbuf_write_bytes(wbf, bs->start, 0, bs->len); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import subprocess | ||
import sys | ||
import time | ||
|
||
# Specify the directory for the binaries | ||
DIR_TESTS = "build/tests" | ||
|
||
def check_output(tx_status, tx_output, rx_status, rx_output): | ||
test_status = 0 | ||
|
||
# Expected tx output & status | ||
z_tx_expected_status = 0 | ||
z_tx_expected_output = "[tx]: Sending packet on test/zenoh-pico-fragment, len: 10000" | ||
# Expected rx output & status | ||
z_rx_expected_status = 0 | ||
z_rx_expected_output = ( | ||
"[rx]: Received packet on test/zenoh-pico-fragment, len: 10000, validity: 1") | ||
|
||
# Check the exit status of tx | ||
if tx_status == z_tx_expected_status: | ||
print("z_tx status valid") | ||
else: | ||
print(f"z_tx status invalid, expected: {z_tx_expected_status}, received: {tx_status}") | ||
test_status = 1 | ||
|
||
# Check output of tx | ||
if z_tx_expected_output in tx_output: | ||
print("z_tx output valid") | ||
else: | ||
print("z_tx output invalid:") | ||
print(f"Expected: \"{z_tx_expected_output}\"") | ||
print(f"Received: \"{tx_output}\"") | ||
test_status = 1 | ||
|
||
# Check the exit status of z_rx | ||
if rx_status == z_rx_expected_status: | ||
print("z_rx status valid") | ||
else: | ||
print(f"z_rx status invalid, expected: {z_rx_expected_status}, received: {rx_status}") | ||
test_status = 1 | ||
|
||
# Check output of z_rx | ||
if z_rx_expected_output in rx_output: | ||
print("z_rx output valid") | ||
else: | ||
print("z_rx output invalid:") | ||
print(f"Expected: \"{z_rx_expected_output}\"") | ||
print(f"Received: \"{rx_output}\"") | ||
test_status = 1 | ||
# Return value | ||
return test_status | ||
|
||
def test_client(): | ||
# Start rx in the background | ||
print("Start rx client") | ||
z_rx_command = f"./{DIR_TESTS}/z_test_fragment_rx" | ||
z_rx_process = subprocess.Popen(z_rx_command, | ||
shell=True, | ||
stdin=subprocess.PIPE, | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, text=True) | ||
# Introduce a delay to ensure rx starts | ||
time.sleep(2) | ||
# Start tx | ||
print("Start tx client") | ||
z_tx_command = f"./{DIR_TESTS}/z_test_fragment_tx" | ||
z_tx_process = subprocess.Popen(z_tx_command, | ||
shell=True, | ||
stdin=subprocess.PIPE, | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
text=True) | ||
# Wait for tx to finish | ||
z_tx_process.wait() | ||
# Wait for rx to receive | ||
time.sleep(1) | ||
print("Stop rx") | ||
if z_rx_process.poll() is None: | ||
# Send "q" command to rx to stop it | ||
z_rx_process.stdin.write("q\n") | ||
z_rx_process.stdin.flush() | ||
# Wait for rx to finish | ||
z_rx_process.wait() | ||
# Check output | ||
return check_output(z_tx_process.returncode, z_tx_process.stdout.read(), | ||
z_rx_process.returncode, z_rx_process.stdout.read()) | ||
|
||
def test_peer(): | ||
# Start rx in the background | ||
print("Start rx peer") | ||
z_rx_command = f"./{DIR_TESTS}/z_test_fragment_rx 1" | ||
z_rx_process = subprocess.Popen(z_rx_command, | ||
shell=True, | ||
stdin=subprocess.PIPE, | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, text=True) | ||
# Introduce a delay to ensure rx starts | ||
time.sleep(2) | ||
# Start tx | ||
print("Start tx peer") | ||
z_tx_command = f"./{DIR_TESTS}/z_test_fragment_tx 1" | ||
z_tx_process = subprocess.Popen(z_tx_command, | ||
shell=True, | ||
stdin=subprocess.PIPE, | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
text=True) | ||
# Wait for tx to finish | ||
z_tx_process.wait() | ||
# Wait for rx to receive | ||
time.sleep(1) | ||
print("Stop rx") | ||
if z_rx_process.poll() is None: | ||
# Send "q" command to rx to stop it | ||
z_rx_process.stdin.write("q\n") | ||
z_rx_process.stdin.flush() | ||
# Wait for rx to finish | ||
z_rx_process.wait() | ||
# Check output | ||
return check_output(z_tx_process.returncode, z_tx_process.stdout.read(), | ||
z_rx_process.returncode, z_rx_process.stdout.read()) | ||
|
||
if __name__ == "__main__": | ||
EXIT_STATUS = 0 | ||
|
||
# Run tests | ||
if test_client() == 1: | ||
EXIT_STATUS = 1 | ||
if test_peer() == 1: | ||
EXIT_STATUS = 1 | ||
# Exit | ||
sys.exit(EXIT_STATUS) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why 128bytes? If there is a reason for it, please document it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's an arbitrary value we decided with @Mallets, that seemed not to big and not to small. The buffer being expandable if needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fragmentation, the
zbuf
is used to copy the header bytes and to append the pointer to the payload so as to have a linear reading of the bytes.128
is a rules of thumb heuristic about the size of memory you need to serialize the header. If more is needed, another block can be allocated straight after and so on an so forth.