Commit fb9d8722 authored by Andreas Schmidt's avatar Andreas Schmidt

Add MTU as socket property to be defined at creation.

parent d8ad1570
Pipeline #2358 passed with stages
in 1 minute and 30 seconds
......@@ -5,7 +5,7 @@ host = sys.argv[1]
port = int(sys.argv[2])
localport = int(sys.argv[3])
s = prrt.PrrtSocket(("127.0.1.1", localport))
s = prrt.PrrtSocket(("127.0.1.1", localport), mtu=150)
s.connect((host, port))
for i in range(10):
......
......@@ -119,7 +119,7 @@ cdef extern from "proto/socket.h":
ctypedef prrtSocket PrrtSocket
cdef PrrtSocket* PrrtSocket_create(const uint32_t target_delay)
cdef PrrtSocket* PrrtSocket_create(const uint32_t mtu, const uint32_t target_delay)
bint PrrtSocket_bind(PrrtSocket *sock_ptr, const_char *ipAddress, const uint16_t port)
int PrrtSocket_close(const PrrtSocket *sock_ptr)
int PrrtSocket_connect(PrrtSocket *sock_ptr, const_char *host, const uint16_t port)
......
......@@ -50,12 +50,12 @@ struct timespec abstime_from_now(prrtTimedelta_t wait_time) {
return deadline;
}
PrrtSocket *PrrtSocket_create(prrtTimedelta_t target_delay_us) {
PrrtSocket *PrrtSocket_create(prrtByteCount_t mtu, prrtTimedelta_t target_delay_us) {
assert(sizeof(float) == 4);
PrrtSocket *s = (PrrtSocket *) calloc(1, sizeof(PrrtSocket));
check_mem(s);
s->mtu = mtu;
s->isHardwareTimestamping = false;
s->interfaceName = NULL;
......@@ -219,6 +219,10 @@ int PrrtSocket_connect(PrrtSocket *s, const char *host, const uint16_t port) {
}
int PrrtSocket_send(PrrtSocket *s, const uint8_t *data, const size_t data_len) {
if (data_len > s->mtu) {
PERROR("Data to be sent (%d bytes) is too long, as MTU is %d.\n", data_len, s->mtu);
return -1;
}
XlapTimestampPlaceholder tsph;
XlapTimestampPlaceholderInitialize(&tsph);
XlapTimeStampClock(&tsph, ts_any_packet, 0, PrrtSendStart);
......@@ -425,8 +429,10 @@ int PrrtSocket_close(PrrtSocket *s) {
uint32_t PrrtSocket_get_sock_opt(PrrtSocket *s, const char *name) {
if (strcmp(name, "targetdelay") == 0) {
return PrrtApplicationConstraints_get_target_delay(s->applicationConstraints);
} else if (strcmp(name, "mtu") == 0) {
return s->mtu;
} else {
PERROR("Unknwon property %s", name);
PERROR("Unknown property %s\n", name);
return 0;
}
}
......
......@@ -78,10 +78,11 @@ typedef struct prrtSocket {
char *interfaceName;
atomic_bool isThreadPinning;
prrtByteCount_t mtu;
} PrrtSocket;
PrrtSocket *PrrtSocket_create(prrtTimedelta_t target_delay_us);
PrrtSocket *PrrtSocket_create(prrtByteCount_t mtu, prrtTimedelta_t target_delay_us);
bool PrrtSocket_enable_hardware_timestamping(PrrtSocket *s, const char * interface_name);
......
......@@ -92,6 +92,9 @@ cdef extern from "util/mpsc_queue.c":
cdef sockaddr_to_addr_and_port(sockaddr_in addr):
return (cprrt.PrrtSocket_inet_ntoa(&addr.sin_addr).decode("utf8"), cprrt.PrrtSocket_ntohs(addr.sin_port))
class PayloadTooBigException(Exception):
pass
class PrrtCodingConfiguration:
def __init__(self, n, k, n_cycle=None):
if n < k:
......@@ -118,10 +121,10 @@ class PrrtCodingConfiguration:
cdef class PrrtSocket:
cdef cprrt.PrrtSocket* _c_socket
def __cinit__(self, address, target_delay = 1, thread_pinning = False):
def __cinit__(self, address, mtu = 1500, target_delay = 1, thread_pinning = False):
host, port = address
target_delay_us = target_delay * 1000**2
self._c_socket = cprrt.PrrtSocket_create(target_delay_us)
self._c_socket = cprrt.PrrtSocket_create(mtu, target_delay_us)
if thread_pinning:
cprrt.PrrtSocket_enable_thread_pinning(self._c_socket)
cprrt.PrrtSocket_bind(self._c_socket, host.encode("utf8"), port)
......@@ -182,7 +185,12 @@ cdef class PrrtSocket:
cprrt.PrrtSocket_connect(self._c_socket, encodedHost, port)
def send(self, data):
cprrt.PrrtSocket_send(self._c_socket, data, len(data))
mtu = cprrt.PrrtSocket_get_sock_opt(self._c_socket, "mtu")
data_len = len(data)
if len(data) < mtu:
cprrt.PrrtSocket_send(self._c_socket, data, data_len)
else:
raise PayloadTooBigException("Sending packet of {} bytes on a socket with MTU of {} bytes failed.".format(data_len, mtu))
# Receiving
......
......@@ -97,7 +97,7 @@ int main(int argc, char **argv) {
}
#endif
s = PrrtSocket_create(HALF_TIMESTAMP-1);
s = PrrtSocket_create(1500, HALF_TIMESTAMP - 1);
check(s != NULL, "Could not create socket.");
if(strcmp(arguments.hardwarestamping_interface, "-") != 0) {
......
......@@ -101,7 +101,7 @@ int main(int argc, char **argv) {
#endif
PrrtSocket *s = PrrtSocket_create(10 * 1000 * 1000);
PrrtSocket *s = PrrtSocket_create(1400, 10 * 1000 * 1000);
check(s != NULL, "Socket create failed.");
if(strcmp(arguments.hardwarestamping_interface, "-") != 0) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment